Skip to Content

It all started with a basic (yet very important) question:-

Do you test your Groovy scripts?

Or more accurately, How do you test your Groovy scripts?

Because

if(!software.isTestable()) {
  software = null;
}

 

WebUI, SchmebUI

If we leave it to chance, life with SAP Cloud Platform Integration would be colorless like this:-

How do you even work with such an editor in this day and age… let alone test anything on it??

Well, on occasions like this, pardon me, but I would rather take chance into my own hands, and have a bit more color in my life (code completion and on-the-fly syntax check, anyone?):-

 

Ok, Eclipse is Groovier, but how do we test?

Well, before Vadim Klimov took matters into his own hands, we would have had to rely on creating our own versions of Cloud Integration’s libraries using techniques like Reflecting on the Message class by Morten Wittrock.

But fortunately for all of us, Vadim bravely trailblazed the way forward with Dark Side of Groovy Scripting: Behind the Scenes of Cloud Integration Runtime.

Before you even continue, you will really need to read thoroughly the above blog, as that is both prerequisite and key.

You will also need the below:-

Eclipse Neon (What do you mean you don’t have it yet?!)

Groovy Eclipse (Eclipse is Groovier with Groovy)

 

Let the testing begin!

All ready now?

Let’s first create a Groovy Project.

 

After that, let’s play nice and have a decent package for your Groovy scripts. You will need two scripts here:-

  • The Groovy script that will be used in your integration flow
  • The script that will test the above script

For simplicity, I will just copy over the default Groovy script that is generated from Cloud Integration, namely script1.groovy below.

For the other script, I will just create a new Groovy class named GroovyScriptTest.groovy.

 

All good so far? Let’s replace the code in the testing class with the following code. It’s just a very basic logic to showcase the approach. Essentially what it does is:-

  • Load the script to be tested
  • Initialize the message to be passed into the script
  • Execute the script to be tested
  • Display the results via console

Nothing fancy, but I encourage you to at least try to understand what each part does (there’s always Google if you need any help!)

package com.equalize.groovy.testing

import com.sap.gateway.ip.core.customdev.processor.MessageImpl
import com.sap.gateway.ip.core.customdev.util.Message

// Load Groovy Script
GroovyShell shell = new GroovyShell()
def script = shell.parse(new File("src/com/equalize/groovy/testing/script1.groovy"))

// Initialize message with body, header and property
Message msg = new MessageImpl()
msg.setBody(new String("Hello Groovy World"))
msg.setHeader("oldHeader", "MyGroovyHeader")
msg.setProperty("oldProperty", "MyGroovyProperty")

// Execute script
script.processData(msg)

// Display results of script in console
println("Body:\r\n" + msg.getBody())

def displayMaps = { String mapName, Map map ->
	println mapName
	map.each { key, value -> println( key + " = " + value) }
}
displayMaps("Headers:", msg.getHeaders())
displayMaps("Properties:", msg.getProperties())

 

You will now notice some syntax errors in both scripts, the most noticeable one would be for the following elusive class:-

com.sap.gateway.ip.core.customdev.util.Message

Now this is where the fun really begins. Did you bother to read Vadim’s blog? You will need it now. Go hunt for the required JAR file, then add it to the project’s build path.

Once you got all the syntax error sorted, try executing the testing script:-

Right Click > Run As > Groovy Script

Oh no! More errors – looks like some other JAR files are required during runtime. So keep doing the below:-

Hunt, Add, Test, Repeat

Finally, when all is in place, you will be rewarded with the below screen in the console output 🙂

 

Voila! Now, this is how you test your Groovy scripts!

 

Update 20 Oct 2017

Interesting observation – if you head over to (https://help.sap.com/viewer/368c481cd6954bdfa5d0435479fd4eaf/Cloud/en-US/062f7a7e5c374e67b568dddc7b7844a9.html), there is a recently added section detailing how you can add the JAR file for the Message class into your Groovy project 🙂

Another interesting observation is that it does not tell you where to download the file! :p

 

Update 5 Jan 2018

Further interesting observation. The online documentation has been updated with details on how to download the JAR file for the above mentioned elusive class, now termed the Script API Methods.

 

Basically, you just have to get it from the SAP Development Tools page

 

The problem with this approach is that it only gives you a real bare bones JAR file.

 

IMHO, if you want to do any serious development/testing work locally in Eclipse, this JAR file is insufficient and not worth the effort.

To report this post you need to login first.

23 Comments

You must be Logged on to comment or reply to a post.

  1. sapbinary key

    Nice workaround. much needed one. This reminds me stand alone java mapping testing.

    I am not yet into HCI . Had a little chance to play with HCI long back.

     

    message mapping test is available in HCI. It would be nice if SAP does the same with scripts also. and of course changing the colorless editor too.

     

     

    (2) 
  2. Rajesh nimmakayala

    Hi @Eng Swee Yeoh,

     

    It’s a great blog and very useful for us to work on groovy scripts in HCI. I see there is a link provided in SAP Help portal (https://help.sap.com/viewer/368c481cd6954bdfa5d0435479fd4eaf/Cloud/en-US/062f7a7e5c374e67b568dddc7b7844a9.html) detailing how we can add the JAR file for the Message class into your Groovy project but the link to download the jar is missing.

    We are working on Groovy script for our complex logic’s which needs to be tested constantly for achieving the results. Can you please share the link to download jar file for com.sap.gateway.ip.core.customdev.util.Message class ? It will be really helpful.

     

     

    Thanks,

    Rajesh N

    (0) 
    1. Eng Swee Yeoh Post author

       

      Hi Rajesh

       

      You will really need to read the blog properly – as it is really obvious, I won’t spoil the fun for you.

       

      Regards

      Eng Swee

      (1) 
      1. Rajesh nimmakayala

        Hi – Thanks I followed the blog ( https://blogs.sap.com/2017/10/02/dark-side-of-groovy-scripting-behind-the-scenes-of-cloud-integration-runtime/ ) and able to fix it.

         

        Thanks,

        Rajesh N

        (0) 
  3. Rong Wei

    Hi@Eng Swee Yeoh

    Thanks for your post! It’s great that I could do some local test!

    I have to ask a similar question with Rajesh’s.  The com.sap.gateway.ip.core.customdev.util.Message syntax is fixed by import jar file as you suggested, however, I can find no hints for com.sap.gateway.ip.core.customdev.processor.MessageImpl  Seems this class is not in the cloud.integration.script.apis-1.36.1.jar file. Could you advise a bit?

     

    Happy new year~

    Rong

    (1) 
    1. Eng Swee Yeoh Post author

      Hi Rong Wei , shyamalima das ,

       

      Please see the updated section of my blog (at the end). I wouldn’t suggest using the JAR file provided by SAP in the Development Tools page. Instead, please follow the steps listed in this blog (in particular Hunt, Add, Test, Repeat) and also the details from Vadim’s blog.

       

      Regards

      Eng Swee

      (1) 
    1. Eng Swee Yeoh Post author

      You are on the right track, but you probably missed out the Repeat step of “Hunt, Add, Test, Repeat” step. Keep going until you get all the necessary JAR files – there are quite a few of them required.

      (0) 
      1. Maximiliano Colman

        Hi,

        It is not very clear where to hunt, I tried to download the JAR for “org.apache.camel.TypeConversionException”, but it does not exist in CPI :S  , any idea?.

         

        Kind Regards.

        Max.

        (0) 
        1. Eng Swee Yeoh Post author

          Hunt the same way you got the JAR file for the com.sap.gateway.ip.core.customdev.util.Message class.

          If you are not sure where to hunt, how did you get that JAR in the first place?

          (0) 
          1. Maximiliano Colman

            Hi,

            I know how to hunt( identify missing class, run the IFlow in CPI to extract the corresponding JAR and import the JAR in my project, test and repeat), but I can’t identify the missing class ( I thought it was this “org.apache.camel.TypeConversionException”, but I can not download the JAR from CPI, I executed the IFlow for it but it does not return anything), thanks for the replies and your time 😉 .

             

            Kind Regards.

            Max.

            (0) 
            1. Eng Swee Yeoh Post author

              Class org.apache.camel.TypeConversionException is correct, and you should be able to find it in JAR file org.apache.camel.camel-core_2.17.4.sap-09.jar in the current version of the tenant.

               

              (0) 
              1. Maximiliano Colman

                Hi,

                Thanks, but I solved it with CPI libraries from SAP PO 😉

                 

                1. <DISK>:\usr\sap\<SYSID>\J00\j2ee\cluster\bin\ext\com.sap.aii.igw.esb.core.lib\lib\com.sap.gw.rt-camel.components.custom-development-1.35.6.jar
                2. <DISK>:\usr\sap\<SYSID>\J00\j2ee\cluster\bin\ext\com.sap.aii.igw.esb.core.lib\lib\com.sap.aii.igw.esb.core.lib\lib\com.sap.it.public-api-2.8.0.jar
                3. <DISK>:\usr\sap\<SYSID>\J00\j2ee\cluster\bin\ext\com.sap.aii.igw.esb.core.lib\lib\com.sap.gw.rt-script.engine.api-1.35.6.jar
                4. <DISK>:\usr\sap\<SYSID>\J00\j2ee\cluster\bin\ext\com.sap.aii.igw.camel.core.lib\lib\org.apache.camel-camel-core-2.17.4-sap-05.jar
                5. <DISK>:\usr\sap\<SYSID>\J00\j2ee\cluster\bin\ext\com.sap.tc.Logging\sap.com~tc~logging~java~impl.jar
                6. <DISK>:\usr\sap\<SYSID>\J00\j2ee\cluster\bin\ext\com.sap.aii.igw.commons.api.lib\lib\com.sap.it.commons-com.sap.it.commons.logging.slf4j-1.37.0.jar
                7. <DISK>:\usr\sap\<SYSID>\J00\j2ee\cluster\bin\ext\com.sap.aii.igw.commons.api.lib\lib\com.sap.it.commons-com.sap.it.commons-1.37.0.jar
                8. <DISK>:\usr\sap\<SYSID>\J00\j2ee\cluster\bin\ext\com.sap.aii.igw.slf4j.lib\lib\com.sap.aii.igw.slf4j.lib_api.jar
                9. <DISK>:\usr\sap\<SYSID>\J00\j2ee\cluster\bin\ext\com.sap.aii.igw.slf4j.lib\lib\org.slf4j-jcl-over-slf4j-1.7.5.jar
                10. <DISK>:\usr\sap\<SYSID>\J00\j2ee\cluster\bin\ext\com.sap.aii.igw.slf4j.lib\lib\org.slf4j-slf4j-api-1.7.5.jar

                 

                Kind Regards.

                Max.

                 

                (0) 
  4. Tom van Rooijen

    Hi Eng Swee,

     

    Thanks for the journey and forcing us to do the work 🙂

    I think I have all the external libraries loaded in eclipse, 10 in total, all retrieved from CPI.

    Now I get this error:

    Caught: groovy.lang.MissingMethodException: No signature of method: org.codehaus.groovy.runtime.InvokerHelper$1.processData() is applicable for argument types: (com.sap.gateway.ip.core.customdev.processor.MessageImpl) values: [com.sap.gateway.ip.core.customdev.processor.MessageImpl@1a72a540]
    groovy.lang.MissingMethodException: No signature of method: org.codehaus.groovy.runtime.InvokerHelper$1.processData() is applicable for argument types: (com.sap.gateway.ip.core.customdev.processor.MessageImpl) values: [com.sap.gateway.ip.core.customdev.processor.MessageImpl@1a72a540]
    at com.equalize.groovy.testing.GroovyScriptTester.run(GroovyScriptTester.groovy:17)

     

    Is there still something I am missing? Below is what I have now

     

    Thanks!

    Tom

    (0) 
    1. Eng Swee Yeoh Post author

      Hi Tom

       

      I’m glad you enjoyed learning how to fish!

       

      Your libraries look fine, so I don’t think there’s any missing there. Can you show a screenshot of your project structure as well as the code for GroovyScriptTester.groovy?

       

      Regards

      Eng Swee

      (0) 
        1. Tom van Rooijen

          When I try to run it in the groovy console I get this error:

          groovy.lang.MissingMethodException: No signature of method: org.codehaus.groovy.runtime.InvokerHelper$1.processData() is applicable for argument types: (com.sap.gateway.ip.core.customdev.processor.MessageImpl) values: [com.sap.gateway.ip.core.customdev.processor.MessageImpl@47949139]

          at com.equalize.groovy.testing.GroovyScriptTester.run(GroovyScriptTester.groovy:17)

           

          (0) 
  5. Athar Iqbal

    Hi, I have tried pretty much everything, google, blog search and could the package for below import.

    It is not part of SAP API JAR.

    Any help.

    Thanks

    com.sap.gateway.ip.core.customdev.processor.MessageImpl

    (0) 
  6. Athar Iqbal

    The reason I need this JAR is to be able to create a message for testing. Unfortunately there is no other way to test the script in eclipse unless I am able to create a new message and pass it to the function.

    Any help is appreciated.

     

    Thanks

    Athar

    (0) 

Leave a Reply