0
votes

I am in a pickle. I feel there is a simple solution to what I want to achieve, but I am at a loss to how to go about it.

Basically, I am standing up some mock Soap services. I want to echo back an update call with that which is passed in.

My request looks like this:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <SOAP-ENV:Header xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"/>
   <soap:Body>
      <ns2:setEvents xmlns:ns2="http://example.com/eventingservices" xmlns:ns3="http://example.com/eventing/sdo">
         <setEventsRequest>
            <SystemCode>ABC</SystemCode>
            <Event>
               <EventTypeCode>01</EventTypeCode>
            </Event>
            <Event>
               <EventTypeCode>04</EventTypeCode>
            </Event>
         </setEventsRequest>
      </ns2:SetEvents>
   </soap:Body>
</soap:Envelope>

I then want to simply transfer the list of Events to the response. They have the same attributes as the request.

A typical response, would look like this:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <SOAP-ENV:Header xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"/>
   <soapenv:Body>
      <qu:setEventsResponse xmlns:qu="http:/example.com/eventingServices">
         <setEventsResponse>
            <Event>
               <EventTypeCode>01</EventTypeCode>
            </Event>
            <Event>
               <EventTypeCode>04</EventTypeCode>
            </Event>
         </setEventsResponse>
      </qu:setEventsResponse>
   </soapenv:Body>
</soapenv:Envelope>

I tried using the following Groovy script, replacing the Events in the response with ${events}:

def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
def holder = groovyUtils.getXmlHolder(mockRequest.requestContent)
def events = String.valueOf(holder.getNodeValues("//Event"))

context.setProperty("events", events);

I also tried the above without doing the string of. To no avail.

Please please help me. I'll buy you a beer if I can get this damned thing to work!

1
I am going to test it out today.....I've been out of action for the past few weeks with a newborn! I will keep you posted! - lemoncolly
Hurrah! Victory! Thanks for the input. I owe you that beer... - lemoncolly
congratulations for the newborn :), nice to help you! - albciff

1 Answers

0
votes

I suppose that you have a mock service in SOAPUI configured as follows.

Operation with a response similar to:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <SOAP-ENV:Header xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"/>
   <soapenv:Body>
      <setEventsResponse xmlns="http:/example.com/eventingServices">
         <setEventsResponse>
            ${events}
         </setEventsResponse>
      </setEventsResponse>
   </soapenv:Body>
</soapenv:Envelope>

And on the onRequestScript tab of your mockService you want to have the necessary script to get the <Event> nodes from the request and put it in the response using ${events} property. To do so, I recommend that you can use XmlSlurper as follows:

import groovy.xml.StreamingMarkupBuilder

// parse the request
def reqSlurper = new XmlSlurper().parseText(mockRequest.requestContent)
// find all 'Event' nodes from request
def events = reqSlurper.depthFirst().findAll { it.name() == 'Event' }

// builder to convert the nodes to string
def smb = new StreamingMarkupBuilder() 

// concatenate in the string all "<Event>" nodes from request
def eventAsString = ''
events.each{
    eventAsString += smb.bindNode(it)
}

// set the property to use in the response
context.setProperty("events", eventAsString);

That's all to make it work :).

Additionally note that there are some mistakes in you xmls. The request in your question is not well formed: </ns2:SetEvents> not close <ns2:setEvents> (note uppercase), and if you want that xmlns:ns2="http://example.com/eventingservices" namespace applies to all childs of <SetEvents> you have to add ns2 to all the child nodes or remove the ns2 to make it default for this subtree:<SetEvents xmlns="http://example.com/eventingservices">` (this applies also for your response)

Hope it helps,