Skip to Content
Technical Articles

Testing Parts of Flows in CPI with the Simulation Mode

Firstly, thank you SAP developers for increasing and caring for our productivity! It was a pain point and this feature shows that you are listening.

Update:  Kamlesh Zanje from SAP also posted a blog post explaining the feature: https://blogs.sap.com/2020/04/13/integration-flow-simulation-in-sap-cloud-platform-integration/

Overview

This new feature allows you to test flows without deployment. You can choose the starting point and the ending point for the test. You can define an input exchange with the message body, headers, and properties. Then you can run the flow between two points and check the resulting exchange.

There are new SAP Help pages you should check here.

Example

Here is a sample flow. Content modifier adds a header and Groovy script calculates the sum of two XML fields writing the result back to XML. Note that there are no adapters configured.

The simulation mode doesn’t work while you are editing the flow. First, you should save it and leave the edit mode by clicking “Cancel”

It seems that we will be clicking “Save” then “Cancel” a lot. Maybe the button can be renamed to “Close” to reduce cognitive dissonance?

Click on Simulation Mode. You should see a controller with three buttons. Ignore it for now. Click on the arrow you want to set as the starting point and click on the icon in the middle:

Click on the arrow you want the simulation to stop. Click on the icon in the bottom:

We are ready to prepare the input. Click on the start point:

Prepare the exchange:

Now we can run the simulation! Click the button here:

This feels nice when you don’t have to deploy:

You can see the message content by clicking envelopes at each step!

Here is the example input I have used:

<AddOperation>
    <FirstNumber>3</FirstNumber>
    <SecondNumber>4</SecondNumber>
    <Result></Result>
</AddOperation>

And here is the Groovy script:

import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
import groovy.util.XmlParser;
import groovy.xml.XmlUtil;

def Message processData(Message message) {

    def body = message.getBody(java.lang.String) as String
    def doc = new XmlParser().parseText(body)
    
    println doc.FirstNumber[0].text()
    doc.Result[0].setValue( doc.FirstNumber[0].text().toInteger() +
        doc.SecondNumber[0].text().toInteger())
    
    
    message.setBody(XmlUtil.serialize(doc))
    return message;
    }

Suggestions for more developer happiness

What would happen if we could:

  • store/persist these test run points
  • name or organize them
  • have APIs to run these simulations programmatically

I know these can be hard to implement but I think it can be the killer feature of CPI.

8 Comments
You must be Logged on to comment or reply to a post.
  • Thank you, Fatih!

    As a CPI developer, I liked this feature very much. Previously, If we wanted to make some changes for flows, we had to re-deploy after every change. It takes a lot of time from productivity. This new feature is very useful for CPI developers. Thank you for explaining and showing how we can use the Simulation Mode.

    Regards,

    Sedat

  • Newbie Error ?

    I got:

     

    No signature of method: org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.Calculate01() is applicable for argument types: (com.sap.gateway.ip.core.customdev.processor.MessageImpl) values: [com.sap.gateway.ip.core.customdev.processor.MessageImpl@70ced07b] on the exchange: Exchange[ID-……..]

     

    Please advice

      • Thanks for the feedback Fatih,

        I suspect this can be a bug in the tool – and not in your demo.

        I did not manage to run this without the same error…”No signature of mthod: org….”

         

        Best regards

        Erik

        • Hello Erik,

          You can also share the integration flow as a zip file if you want to further investigate the reason.

          Regards,
          Fatih