Soap UI Mocking not working when using default namespace.

The Soap UI mocking does not work in case of default namespace.

The below is the mock response. Its using implicit soap ui response object – ${#MockResponse#Request#//v1:testRequest/v1:Header/v1:ChainID/text()}

So its echoing back whatever it received in request. 

<soapenv:Envelope xmlns:soapenv=”http://schemas.xmlsoap.org/soap/envelope/&#8221; xmlns:v1=”http://www.mycompany.com/testService/v1&#8243; >
<soapenv:Header/>
<soapenv:Body>
<v1:testResponse>
<v1:Header>
<v1:ChainID>${#MockResponse#Request#//v1:testRequest/v1:Header/v1:ChainID/text()}</v1:ChainID>
<v1:StoreID>${storeId}</v1:StoreID>
<v1:TxType>?</v1:TxType>
</v1:Header>
</v1:testResponse>
</soapenv:Body>
</soapenv:Envelope>

This work (i see the chain id being echoed back)  if my request looks like this. This request is using namespace prefix.

<soapenv:Envelope xmlns:soapenv=”http://schemas.xmlsoap.org/soap/envelope/&#8221; xmlns:v1=”http://www.mycompany.com/testService/v1&#8243;>
<soapenv:Header/>
<soapenv:Body>
<v1:testRequest>
<v1:Header>
<v1:ChainID>123</v1:ChainID>
<v1:StoreID>123</v1:StoreID>
<v1:TxType>TWO</v1:TxType>
</v1:Header>
</v1:testRequest>
</soapenv:Body>
</soapenv:Envelope>

It does not work if request (i do not see the chain id being echoed back)  looks something like this. This is using default namespace instead of prefix. This is valid request as well.

<soapenv:Envelope xmlns:soapenv=”http://schemas.xmlsoap.org/soap/envelope/”&gt;
<soapenv:Header/>
<soapenv:Body>
<testRequest xmlns=”http://www.mycompany.com/testService/v1&#8243;>
<Header>
<ChainID>123</ChainID>
<StoreID>123</StoreID>
<TxType>TWO</TxType>
</Header>
</testRequest>
</soapenv:Body>
</soapenv:Envelope>

In my case this request is generate by third party product, there is not way to force it to use the namespace prefix.

So i had to find work around in soapui itself.

I am using groovy script in mock response. After this change it works for both request.

<soapenv:Envelope xmlns:soapenv=”http://schemas.xmlsoap.org/soap/envelope/&#8221; xmlns:v1=”http://www.mycompany.com/testService/v1″&gt;
<soapenv:Header/>
<soapenv:Body>
<v1:testResponse>
<v1:Header>
<!–
<v1:ChainID>${#MockResponse#Request#//v1:testRequest/v1:Header/v1:ChainID/text()}</v1:ChainID>
–>
<v1:ChainID>${chainId}</v1:ChainID>
<v1:StoreID>${storeId}</v1:StoreID>
<v1:TxType>?</v1:TxType>
</v1:Header>
</v1:testResponse>
</soapenv:Body>
</soapenv:Envelope>

def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )

def holder = groovyUtils.getXmlHolder( mockRequest.getRequestContent() )
holder.declareNamespace( ‘v1’, ‘http://www.mycompany.com/testService/v1&#8217;)
context.setProperty(“chainId”, holder.getNodeValue( “//v1:testRequest/v1:Header/v1:ChainID/text()”));
context.setProperty(“storeId”, holder.getNodeValue( “//v1:testRequest/v1:Header/v1:StoreID/text()”));

untitled

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s