mocking - XPATH Dispatch in SoapUI Mock service/ Mock operation -
i new in soapui, , trying understand use of xpath dispatch mock operation in mock service.
here have done far
- created mock service calculator
- added mock operation substract
following sample request operation
<soapenv:envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:cal="http://www.parasoft.com/wsdl/calculator/"> <soapenv:header/> <soapenv:body> <cal:subtract> <cal:x>1</cal:x> <cal:y>1</cal:y> </cal:subtract> </soapenv:body> </soapenv:envelope>
following sample response same
<soapenv:envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:cal="http://www.parasoft.com/wsdl/calculator/"> <soapenv:header/> <soapenv:body> <cal:subtractresponse> <cal:result>?</cal:result> </cal:subtractresponse> </soapenv:body> </soapenv:envelope>
i able understand other dispatch not xpath following have entered in xpath dispatch
declare namespace cal='http://www.parasoft.com/wsdl/calculator/'; declare namespace soapenv='http://schemas.xmlsoap.org/soap/envelope/'; //cal:subtract/cal:x
it observed if have used script dispatch , switch xpath dropdown, script visible in declaration/scripting box/area
following questions:
- is xpath , script dispatch same
- if not, how xpath dispatch work identify response dispatch out of form mockresponses list
kindly me this.
ps: have gone through http://www.soapui.org/soap-mocking/reference/mockoperation.html http://www.soapui.org/soap-mocking/mockoperations-and-responses.html
the soapui documentation mentioned in question right location information. however, information available not complete.
after searching sometime, found details.
initially, got confused between xpath , script dispatch methods.
here additional information looking for:
is xpath , script dispatch same
answer no. both different
if not, how xpath dispatch work identify response dispatch out of form mockresponses list
the following information found in documentation:
xquery - similar query_match not quite powerful; xpath expression applied incoming request , resulting value used selecting mockresponse returned. in our previous example of search results, set xpath expression select search term , create mockresponses named after each expected value. advantage being don’t need add new xpath statements new search criteria, mockresponse.
assume created multiple responses positiveresponse
, negativeresponse
, zeroresponse
subtract operation of mock service.
here sample conditions may want apply on request , dispatch appropriate response. of course, may have many require.
positiveresponse
- if x, y values 10, 5 respectively.negativeresponse
- if x, y values 5, 10 respectively.zeroresponse
- otherwise (this mandatory if none of above satisfy).
here how need write in editor given xpath dispatch mode
declare namespace cal='http://www.parasoft.com/wsdl/calculator/'; if (//cal:subtract/cal:x[. = '10'] , //cal:subtract/cal:y[. = '5']) 'positiveresponse' else if (//cal:subtract/cal:x[. = '5'] , //cal:subtract/cal:y[. = '10']) 'negativeresponse' else 'zeroresponse'
hope aware , differentiate script dispatch mode.
i think confusion created because both script , xpath shows editor of same type. content inside of entirely different. can see message on top of editor log, context, mockrequest availability of variables if select script dispatch mode , vanishes when xpath choosen.
just giving scirpt example in case if interested in it:
def groovyutils = new com.eviware.soapui.support.groovyutils(context) def holder = groovyutils.getxmlholder(mockrequest.requestcontent) def x = holder.getnodevalue("//*:x") int def y = holder.getnodevalue("//*:y") int context.result = x - y
a simple test can (to differentiate between two), copy above script xpath , try testing , soap fault received saying not know
groovyutils
. test confirm xpath , script different.
here may not needed create multiple responses above code can handle dynamic input values , set result
in response. mockreponse subtract operation may below place holder ${result}
.
mockresponse script:
<soapenv:envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:cal="http://www.parasoft.com/wsdl/calculator/"> <soapenv:header/> <soapenv:body> <cal:subtractresponse> <cal:result>${result}</cal:result> </cal:subtractresponse> </soapenv:body> </soapenv:envelope>
hope clarifies.
Comments
Post a Comment