Forum Discussion

mrhaboobi's avatar
mrhaboobi
New Contributor
15 years ago

MockService, Adding XML Nodes to Mock Response.

I'm new to SoapUI and Groovy, so appologies if this is an obvious question.

One of my responses is stubbed out like ( See below ) I can return one or more Validation Faults.. under validation faults i can have a details node and various other things,  im just wondering how i would dynamically add Validation faults to this response.  Essentially i want to add nodes and child nodes to the response.

Again sorry if this is all blindly obvious, some sample code would be greatly appreciated. 



   
     
         s:Sender
     

     
         Invalid UserName Supplied
     

     
         
          ...
         

     

   


4 Replies

  • mrhaboobi's avatar
    mrhaboobi
    New Contributor
    Ok so ive now figured out how to return the correct response.  didnt realise all you had to do was

    Return ""  -- just too simple

    but now im getting confused by the documentation.

    def holder = groovyUtils.getXmlHolder( mockRequest.requestContent )

    why can we access the private property requestContent?   where is an API that lists all these methods that we can call?   Im getting very confused, all i want to do in my script is to log the mockservice and the mock operation that is being called/used.  i cant seem to do anything at this point.  getting very confused.  something as simple as mockOperation.name would seem to be the property i want, but this doesnt work and i cant see what properties i can actually use or reference.


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

    The MockRequest object you have is of the type WsdlMockRequest (Whenever you need to know the type of an object just print the class it to the log, log.info mockRequest.class).

    You can the look up the api for the class on the soapUI website, for instance: WsdlMockRequest.

    The reason you are able to access mockRequest.requestContent is because of Groovy doing some of its magic
    mockRequest.requestContent gets transformed to mockRequest.getRequestContent(), since there is no public field by that name. In Groovy, whenever you have a .getSomething() method, you can just use .something instead.

    As for mockOperation.name, this should work fine (works for me) since WsdlMockOperation inherits from ModelItem, which has a .getName() method. Maybe you can post more of your script and we can see if there is anything else wrong with it?

    Regards,
    Dain
    eviware.com
  • Hi,
    I am using soapUI for webservice testing. I have recently created a mockservice with a number of operations (essentially, these are generated by soapUI mockService wizard).
    I have also modified the response XML against these operations. And everything works fine.

    What I would like to do is to log which operation was invoked (very much similar to what "mrhaboobi" wanted to achieve).

    I have been trying to use onRequest script etc, but not working out 
    Could you please help me, where (& what) should I write to do the job?

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

    Try this as an onRequest script:


    log.info mockRequest.soapAction


    It will cause the following to be logged to the script log whenever a request is sent to the MockService:


    Tue Aug 25 17:13:34 CEST 2009:INFO:http://www.example.org/sample/login


    The date and the operation will obviously be different in your case. Good luck!

    Regards,
    Dain
    eviware.com