c# - SOAPUI check request then mock response -


i have set-up mock soapui project returns mock responses when call endpoint. i'm trying return different mock result depending on requested content is. @ moment when hit endpoint url, returning same response of time.

is possible groovy script @ content of request , send mock response based on content? request soap i'd inspecting xml

here have 2 mock requests. i'm looking @ request details node , type i.e. telephonenumber or postcode , send response based on that. possible check node type i.e telephonenumber, postcode , send response based on that?

post code request

<soapenv:envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:lin="http://llu.webservices.opalonline.co.uk/linecharacteristicsws">    <soapenv:header/>    <soapenv:body>       <lin:getlinecharacteristics>          <lin:request>             <!--optional:-->             <lin:usercredentials>                <!--optional:-->                <lin:username>test</lin:username>                <!--optional:-->                <lin:password>test</lin:password>                <lin:agentid>321</lin:agentid>             </lin:usercredentials>             <lin:requestdetails xsi:type="lin:postcoderequest" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance">                 <lin:postcode>l00 0dd</lin:postcode>             </lin:requestdetails>             <lin:userconsent>yes</lin:userconsent>             <lin:servicetype>smpf</lin:servicetype>          </lin:request>       </lin:getlinecharacteristics>    </soapenv:body> </soapenv:envelope> 

post code response

<soap:envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:xsd="http://www.w3.org/2001/xmlschema">    <soap:body>       <getlinecharacteristicsresponse xmlns="http://llu.webservices.opalonline.co.uk/linecharacteristicsws">          <getlinecharacteristicsresult>             <status>                <haserrors>false</haserrors>                <errors/>             </status>             <responsedetails>                <characteristicsbase xsi:type="linecharacteristicsfortelephonenumber">                   <exchangedetails>                      <cssexchangedistrictcode>lv</cssexchangedistrictcode>                      <exchangecode>lvsim</exchangecode>                      <exchangename>simonswood</exchangename>                      <exchangestate>live</exchangestate>                      <exchangecapacity>g</exchangecapacity>                      <forecastdate>0001-01-01t00:00:00</forecastdate>                      <circuitlinelength>                         <measuretype>circuitestimated</measuretype>                         <length>3549</length>                      </circuitlinelength>                   </exchangedetails>                   <technologymessages>                      <technologymessage>                         <code>llusmpf</code>                         <message>llu installation</message>                      </technologymessage>                   </technologymessages>                   <estimatedspeedinformation>                      <estimatedspeedinformation>                         <estimatedspeedinformationtype>standard</estimatedspeedinformationtype>                         <estimatedannexadownstreamspeed>3647</estimatedannexadownstreamspeed>                         <estimatedannexamaxrange>5519</estimatedannexamaxrange>                         <estimatedannexaminrange>2287</estimatedannexaminrange>                         <minthresholdannexa>1657</minthresholdannexa>                         <estimatedannexmdownstreamspeed>2647</estimatedannexmdownstreamspeed>                         <estimatedannexmupstreamspeed>1000</estimatedannexmupstreamspeed>                      </estimatedspeedinformation>                   </estimatedspeedinformation>                   <telephonenumber>01515481460</telephonenumber>                   <accesslineid>lvaaacj8c2</accesslineid>                   <accesslinestatus>btlive</accesslinestatus>                   <numberrangeholder>bt</numberrangeholder>                   <numberportinginformation>notset</numberportinginformation>                   <workinglinedetails>                      <producttype>pstn single line</producttype>                      <pendingceaseorderindicator>n</pendingceaseorderindicator>                   </workinglinedetails>                </characteristicsbase>             </responsedetails>          </getlinecharacteristicsresult>       </getlinecharacteristicsresponse>    </soap:body> </soap:envelope> 

telephone request

<soapenv:envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:lin="http://llu.webservices.opalonline.co.uk/linecharacteristicsws">    <soapenv:header/>    <soapenv:body>       <lin:getlinecharacteristics>          <lin:request>             <!--optional:-->             <lin:usercredentials>                <!--optional:-->                <lin:username>"test</lin:username>                <!--optional:-->                <lin:password>test</lin:password>                <lin:agentid>111</lin:agentid>             </lin:usercredentials>             <lin:requestdetails xsi:type="lin:telephonenumberrequest" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance">                 <lin:telephonenumber>11111111111</lin:telephonenumber>             </lin:requestdetails>             <lin:userconsent>yes</lin:userconsent>             <lin:servicetype>smpf</lin:servicetype>          </lin:request>       </lin:getlinecharacteristics>    </soapenv:body> </soapenv:envelope> 

telephone response

<soap:envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:xsd="http://www.w3.org/2001/xmlschema">    <soap:body>       <getlinecharacteristicsresponse xmlns="http://llu.webservices.opalonline.co.uk/linecharacteristicsws">          <getlinecharacteristicsresult>             <status>                <haserrors>false</haserrors>                <errors/>             </status>             <responsedetails>                <characteristicsbase xsi:type="linecharacteristicsfortelephonenumber">                   <exchangedetails>                      <cssexchangedistrictcode>lv</cssexchangedistrictcode>                      <exchangecode>lvsim</exchangecode>                      <exchangename>simonswood</exchangename>                      <exchangestate>live</exchangestate>                      <exchangecapacity>g</exchangecapacity>                      <forecastdate>0001-01-01t00:00:00</forecastdate>                      <circuitlinelength>                         <measuretype>circuitestimated</measuretype>                         <length>3549</length>                      </circuitlinelength>                   </exchangedetails>                   <technologymessages>                      <technologymessage>                         <code>llusmpf</code>                         <message>llu installation</message>                      </technologymessage>                   </technologymessages>                   <estimatedspeedinformation>                      <estimatedspeedinformation>                         <estimatedspeedinformationtype>standard</estimatedspeedinformationtype>                         <estimatedannexadownstreamspeed>3647</estimatedannexadownstreamspeed>                         <estimatedannexamaxrange>5519</estimatedannexamaxrange>                         <estimatedannexaminrange>2287</estimatedannexaminrange>                         <minthresholdannexa>1657</minthresholdannexa>                         <estimatedannexmdownstreamspeed>2647</estimatedannexmdownstreamspeed>                         <estimatedannexmupstreamspeed>1000</estimatedannexmupstreamspeed>                      </estimatedspeedinformation>                   </estimatedspeedinformation>                   <telephonenumber>11111111111</telephonenumber>                   <accesslineid>lvaaacj8c2</accesslineid>                   <accesslinestatus>btlive</accesslinestatus>                   <numberrangeholder>bt</numberrangeholder>                   <numberportinginformation>notset</numberportinginformation>                   <workinglinedetails>                      <producttype>pstn single line</producttype>                      <pendingceaseorderindicator>n</pendingceaseorderindicator>                   </workinglinedetails>                </characteristicsbase>             </responsedetails>          </getlinecharacteristicsresult>       </getlinecharacteristicsresponse>    </soap:body> </soap:envelope> 

i can't using headers due webservice i'm trying mock.

this version of groovy script i'm writing

import com.eviware.soapui.support.groovyutils import groovy.xml.xmlutil  def groovyutils = new groovyutils(context) def xmlparser = new xmlparser() def responsecontent  def requestxmlholder = groovyutils.getxmlholder(mockrequest.getrequestcontent()) requestxmlholder.declarenamespace("lin", "http://llu.webservices.opalonline.co.uk/linecharacteristicsws")  log.info(requestxmlholder)  def postcode = requestxmlholder.getnodevalue("//postcode")  log.info(postcode) 

thanks

chris

yes it's possible use different responses based on request contents in soapui mock services.

first of in mockservice generate possible responses. right click on mockoperation , select new mockresponse, make action both responses (in case post code, , telephone responses).

enter image description here

then in mockoperation editor, select dispatch script.

enter image description here

and use groovy script evaluate response service send based on request content, can use follow groovy script:

// parse content of soap request def slurper = new xmlslurper().parsetext(mockrequest.getrequestcontent()) // find example if <telephonenumber> node exists def phone = slurper.'**'.find { it.name() == 'telephonenumber' } if(phone?.size() > 0){     // if there @ least 1 <telephonenumber> return telephoneresponse     return 'telephoneresponse' }  // if no <telephonenumber> found, return postcode return 'postcoderesponse' 

note mockrequest object available @ script context on mock operation. note return in script on mock operation must return string match name of configured response.

hope helps,


Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -