I have set-up a mock SOAPUI project that returns mock responses when I call the endpoint. What I'm trying to do is return a different mock result depending on the requested content is. At the moment when I hit the endpoint URL, it is returning the same response all of the time.
Is it possible with a groovy script to look at the content of the request and send a mock response based on its content? The request is SOAP so i'd be inspecting XML
Here I have two mock requests. What I'm looking at is the Request details node and what type it is i.e. TelephoneNumber or PostCode and then send the response based on that. Is it possible to check for the node type i.e TelephoneNumber, PostCode and send a 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 do this using the headers due to the Webservice that I'm trying to mock.
this is a version of the 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