Forum Discussion

Anonymous's avatar
Anonymous
15 years ago

groovy call web service and (bug ?) assertion

Hello,

I have a (dynamic) groovy script. This script calls a Webservice : testRunner.runTestStepByName(GeneralWebService).

With the GeneralWebService teststep, I have put 4 assertions (there is a groovy script assertions).

When the script runs, the first call at the webservice launch several time the groovy assertion. Why several time ?

BUT (and bug ?) at the second call of the webservice the groovy assertion is never called.

Is it normal ? Is it a bug ? Can/must I reset the assetions status of the Webservice teststep ? (How to do that).

Of course, I can write a new  teststep in order to call the groovy assertion, but how to do the other assertions (xpath, valid response, ....).

Thanks,
PHL.

5 Replies

  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hello,

    I know that the assertions may be called more than once if for instance you have the Request panel open at the time you run the TestCase. So if you have a TestCase that runs a Request twice, the assertion will be called twice if the Request is closed, but 4 times if it is opened.

    If the assetion isn't being called at all for any run of the Request, then that may be a bug indeed. Would it be possible for you to attach your project so that we can take a look?

    Regards,
    Dain
    eviware.com
  • Anonymous's avatar
    Anonymous
    Thanks, here is my project :

    1) My axis service : Request : integer i => Response integer -i

    import org.apache.log4j.Logger ;

    public class Ping
    {
        private static final Logger log = Logger.getLogger(Ping.class) ;

        public int ping(int val)
        {  log.info("Appel de ping avec "+val) ; return -val ; }

    } // End of Ping

    2) The main groovy script

    String buildMessage(int v)
    {  String res =
      ""+
      "
    "+
      ""+
      "  "+
      "      \n"+v+"\n"+
      " 
    "+
      ""+
      "
    " ;

      return res ;

    } // End of buildMessage

    void callWs(String msg , int i)
    {
      def request2 = testRunner.testCase.getTestStepByName("ping") ;
      def prop2    = request2.getProperty("request") ;
     
      log.info(msg+i) ;
      String  Rqt = buildMessage(i) ;

      prop2.setValue(Rqt) ;

    // Call
        testRunner.runTestStepByName("ping") ;

    }

    String readResponse()
    { // Read the anwser
      def groovyUtils  = new com.eviware.soapui.support.GroovyUtils( context ) ;
      def holder = groovyUtils.getXmlHolder("ping#Response") ;
      String x =  holder.getNodeValue("//ns1:pingResponse[1]/pingReturn[1]") ;
      return x ;
    }
    callWs("Appel n° 1/1 ",1) ;    log.info("Retour de 1 "+readResponse()) ;
    callWs("Appel n° 2/4 ",4) ;    log.info("Retour de 2 "+readResponse()) ;
    callWs("Appel n° 3/400 ",400) ; log.info("Retour de 3 "+readResponse()) ;
    callWs("Appel n° 4/8 ",8) ;    log.info("Retour de 4 "+readResponse()) ;
    testRunner.gotoStepByName("End") ;

    3) The groovy assertion of the ping request


      def groovyUtils  = new com.eviware.soapui.support.GroovyUtils( context ) ;
      def holder = groovyUtils.getXmlHolder(messageExchange.responseContent) ;
      x =  holder.getNodeValue("//ns1:pingResponse[1]/pingReturn[1]") ;

      i = Integer.parseInt(x,10) ;

      //log.info("Assert 2 i "+(2*i)) ;

      int min = -1000 ;
      if ((min < i) && (i < 0))
      { assert true ; }
      else
      { assert false ; }


    4) Soapui trace and serveur trace when min = - 1000

    soapui trace :

    Tue Jan 19 10:24:38 CET 2010:INFO:Appel n° 1/1 1
    Tue Jan 19 10:24:39 CET 2010:INFO:Retour de 1 -1
    Tue Jan 19 10:24:39 CET 2010:INFO:Appel n° 2/4 4
    Tue Jan 19 10:24:39 CET 2010:INFO:Retour de 2 -4
    Tue Jan 19 10:24:39 CET 2010:INFO:Appel n° 3/400 400
    Tue Jan 19 10:24:39 CET 2010:INFO:Retour de 3 -400
    Tue Jan 19 10:24:39 CET 2010:INFO:Appel n° 4/8 8
    Tue Jan 19 10:24:40 CET 2010:INFO:Retour de 4 -8
    Tue Jan 19 10:24:40 CET 2010:INFO:Step End. Au revoir

    Axis server trace :
    - Appel de ping avec 1
    - Appel de ping avec 4
    - Appel de ping avec 400
    - Appel de ping avec 8

    Every things are OK : 4 calls => 4 requests => 4 responses.

    5) Soapui trace and serveur trace when min = - 10

    soapui trace :
    Tue Jan 19 10:28:35 CET 2010:INFO:Appel n° 1/1 1
    Tue Jan 19 10:28:36 CET 2010:INFO:Retour de 1 -1
    Tue Jan 19 10:28:36 CET 2010:INFO:Appel n° 2/4 4
    Tue Jan 19 10:28:36 CET 2010:INFO:Retour de 2 -4
    Tue Jan 19 10:28:36 CET 2010:INFO:Appel n° 3/400 400
    Tue Jan 19 10:28:37 CET 2010:INFO:Retour de 3 -400 => Assertion FALSE
    Tue Jan 19 10:28:37 CET 2010:INFO:Appel n° 4/8 8
    Tue Jan 19 10:28:37 CET 2010:INFO:Retour de 4 -400 => Expected -8

    Axis server trace :
    - Appel de ping avec 1
    - Appel de ping avec 4
    - Appel de ping avec 400

    This is not what I want : 4 calls => 3 requests => 3 responses.

    soapui bug or not?

    6) How to solve?

    It seems that a false assertion "locks" the ping wsdl test step. So each call to this step, after a false assertion, does not send the request and does not compute again the assertion (according the new received data). Nevertheless, when I laung again the test, the ping setp is "reset", so the first and the second call are OK.

    [s:394fiiaz]Disable and enable the ping step[/s:394fiiaz] : Does not work.

    How to "reset" the ping step ?

    Must I delete and create the ping step at each call? How to do that? How to add the : SOAP response, No SOAP Fault, Schema Compliance, Groovy script ?
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Thanks, could you also please use the  "Attach" option when writing a new post here to attach the actual project file from soapUI? That way we can easily reproduce the issue and debug it.

    Regards,
    Dain
    eviware.com
  • Anonymous's avatar
    Anonymous
    I have test again the project.

    case 1 : no fails on error
    It works! I have the expected behavior.

    case 2 : fails on error (standard behavior) :
    When the assertion is false, the testStep fails, so soapui goes to the "stop on error state". So normally, the testcase must stop. But in my case, I have called the webservice, so the caller groovy script continue to run, but the other steps can be effective due to the  "stop on error state".

    So for my point of view is not a soapui bug, but a special usage of soapui.

    Thanks,
    PHL.