Mock response with repetitions in soapui - service

I'm trying to do mock response based on the request.
With a request like that:
<soapenv:Body>
<con:person>
<person>
<name>John</name>
<age>18</age>
</person>
</con:person>
</soapenv:Body>
and a reponse like that
<soapenv:Body>
<con:result>
<person>
<name>?</name>
<age>?</age>
<country>?</country>
<city>?</city>
</person>
</con:result>
</soapenv:Body>
I can use elements from the request to take what i want in database and create the response.
But when i have a request with many person like that
<soapenv:Body>
<con:person>
<person>
<name>John</name>
<age>18</age>
</person>
<person>
<name>Doe</name>
<age>50</age>
</person>
</con:person>
</soapenv:Body>
I don't know how i can take all data from the request and how i can use them to create a response like that:
<soapenv:Body>
<con:result>
<person>
<name>John</name>
<age>18</age>
<country>France</country>
<city>Paris</city>
</person>
<person>
<name>Doe</name>
<age>50</age>
<country>Spain</country>
<city>Madrid</city>
</person>
</con:result>
</soapenv:Body>
With the same number of person in the request and in the response.
I hope i was clear and i thank you for your answers.

I managed to do something similar. First, I defined my mock response object as:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:stac="stackOverflow.question">
<soapenv:Header/>
<soapenv:Body>
<stac:result>
${personElements}
</stac:result>
</soapenv:Body>
</soapenv:Envelope>
I then created the content for ${personElements} using this Groovy script:
import groovy.xml.MarkupBuilder
// An array from which county and city will be drawn randomly
def countryArray = [["Australia", "Perth"],
["Spain", "Madrid"],
["England","London"],
["Brazil", "Rio"]]
def random = new Random()
// create XmlHolder for request content
def holder = new com.eviware.soapui.support.XmlHolder( mockRequest.requestContent )
// Get the name and age values from the request
def requestItems = holder.getNodeValues( "//*:person/*:person/descendant::*")
def writer = new StringWriter()
def personElements = new MarkupBuilder(writer)
// Build the response elements
for (int index = 0; index < requestItems.size() - 1; index += 2) {
personElements.'stac:person'() {
'stac:name'(requestItems[index])
'stac:age'(requestItems[index+1])
// Choose a random county and city from the array
def randomIndex = random.nextInt(countryArray.size())
'stac:country'(countryArray[randomIndex][0])
'stac:city'(countryArray[randomIndex][1])
}
}
// Add the newly created elements to the response
context.personElements = writer.toString()
This gave me a response like:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:stac="stackOverflow.question">
<soapenv:Header/>
<soapenv:Body>
<stac:result>
<stac:person>
<stac:name>Dolly Bonkers</stac:name>
<stac:age>42</stac:age>
<stac:country>Brazil</stac:country>
<stac:city>Rio</stac:city>
</stac:person>
<stac:person>
<stac:name>Mary Poppins</stac:name>
<stac:age>82</stac:age>
<stac:country>England</stac:country>
<stac:city>London</stac:city>
</stac:person>
<stac:person>
<stac:name>Bilbo Baggins</stac:name>
<stac:age>102</stac:age>
<stac:country>Australia</stac:country>
<stac:city>Perth</stac:city>
</stac:person>
<stac:person>
<stac:name>Johnny Hardcase</stac:name>
<stac:age>22</stac:age>
<stac:country>Spain</stac:country>
<stac:city>Madrid</stac:city>
</stac:person>
</stac:result>
</soapenv:Body>
</soapenv:Envelope>
The script just takes random city and country values from a small array but you could come up with something better if you wanted consistent responses for certain names.

Related

Get tickets Instant Flex Pricer Soap Amadeus

I use amadeus Fare_InstantFlexPricer 19.3 for get best ticket of a period time
I am trying to find tickets for a 30 day period
But every attempt I make is wrong and return this error : "No price results found for input combined criteria"
I prepared my request for two destinations and set the date search range to 30 days
My request is code is :
<Fare_InstantFlexPricer
xmlns="http://xml.amadeus.com/FIFPSQ_16_2_1A">
<numberOfUnit>
<unitNumberDetail>
<numberOfUnits>1</numberOfUnits>
<typeOfUnit>PX</typeOfUnit>
</unitNumberDetail>
</numberOfUnit>
<paxReference>
<ptc>ADT</ptc>
<traveller>
<ref>1</ref>
</traveller>
</paxReference>
<fareFamilies>
<familyInformation>
<commercialFamilyDetails>
<commercialFamily>ECONOMY</commercialFamily>
</commercialFamilyDetails>
</familyInformation>
</fareFamilies>
<fareOptions>
<pricingTickInfo>
<pricingTicketing>
<priceType>RU</priceType>
<priceType>RP</priceType>
</pricingTicketing>
</pricingTickInfo>
<conversionRate>
<conversionRateDetail>
<currency>EUR</currency>
</conversionRateDetail>
</conversionRate>
</fareOptions>
<itinerary>
<requestedSegmentRef>
<segRef>1</segRef>
</requestedSegmentRef>
<departureLocalization>
<departurePoint>
<locationId>AMS</locationId>
</departurePoint>
</departureLocalization>
<arrivalLocalization>
<arrivalPointDetails>
<locationId>PAR</locationId>
</arrivalPointDetails>
</arrivalLocalization>
<timeDetails>
<firstDateTimeDetail>
<date>200922</date>
</firstDateTimeDetail>
<rangeOfDate>
<rangeQualifier>P</rangeQualifier>
<dayInterval>30</dayInterval>
</rangeOfDate>
</timeDetails>
</itinerary>
</Fare_InstantFlexPricer>
And Amadeus Response :
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:awsse="http://xml.amadeus.com/2010/06/Session_v3" xmlns:wsa="http://www.w3.org/2005/08/addressing">
<soapenv:Header>
<wsa:To>http://www.w3.org/2005/08/addressing/anonymous</wsa:To>
<wsa:From>
<wsa:Address>https://nodeA3.production.webservices.amadeus.com/1ASIWINSRO</wsa:Address>
</wsa:From>
<wsa:Action>http://webservices.amadeus.com/FIFPSQ_16_2_1A</wsa:Action>
<wsa:MessageID>urn:uuid:1af57d53-d1c6-09b4-9d2d-ffee32d398cf</wsa:MessageID>
<wsa:RelatesTo RelationshipType="http://www.w3.org/2005/08/addressing/reply">uuid:befc9d54-edbc-4506-a2d3-02a387a7bf26</wsa:RelatesTo>
<awsse:Session TransactionStatusCode="End">
<awsse:SessionId>0TJSYQ9SXC</awsse:SessionId>
<awsse:SequenceNumber>1</awsse:SequenceNumber>
<awsse:SecurityToken>24OSN7AYC1GXKVZL5BPL7G4C8</awsse:SecurityToken>
</awsse:Session>
</soapenv:Header>
<soapenv:Body>
<Fare_InstantFlexPricerReply xmlns="http://xml.amadeus.com/FIFPSR_16_2_1A">
<errorMessage>
<applicationError>
<applicationErrorDetail>
<error>118</error>
</applicationErrorDetail>
</applicationError>
<errorMessageText>
<freeTextQualification>
<textSubjectQualifier>1</textSubjectQualifier>
</freeTextQualification>
<description>No price results found for input combined criteria</description>
</errorMessageText>
</errorMessage>
</Fare_InstantFlexPricerReply>
</soapenv:Body>
</soapenv:Envelope>
I have tested many different modes but in all modes this error is returned

parsing soap response using Cypress

Facing issues while parsing this response using cypress,
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header/>
<soapenv:Body>
<p385:summaryOutputArray xmlns:p385="http://dataobject.simulation.com">
<p385:userName>MS</p385:userName>
</p385:summaryOutputArray>
</soapenv:Body>
</soapenv:Envelope>
Using Cypress How to read userName TAG? I can see in the log that whole xml is printed but can't get to the particular tag. Also, while using the function to get to the particular tag to get the value, I am getting null property
Firstly I used this. This is giving error. property reading null
const parser = new DOMParser();
const xmlDOM = parser.parseFromString(quoteResp, 'text/xml');
cy.log('xmlDOM ' + quoteResp.);
cy.wrap(Cypress.$(quoteResp)).then(quoteResp => {
const txt = quoteResp.filter('Body').find('p385:userName').text();
cy.log('value:' + txt);
});
Using this I can see the whole response in logs
then(quoteResp => {cy.log('xmlDOM ' + quoteResp.body);
It's not necessary to wrap the response, just query the xmlDOM like this
const xmlDOM = parser.parseFromString(quoteResp, 'application/xml');
const userName = xmlDOM.querySelector('userName').textContent
expect(userName).to.eq('MS')

Printing SOAP response in Karate DSL

I have this feature file and i get a response correctly. I want to print obtained value from response but somehow I am not able to do that. Tried to research some stuff but I couldnt help myself.
Can anyone help please? Thanks in advance
Feature:
test of soap
Background:
* url 'http://www.dataaccess.com/webservicesserver/numberconversion.wso'
Scenario: soap 1.1
Given request
"""
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://www.dataaccess.com/webservicesserver/">
<soapenv:Header/>
<soapenv:Body>
<web:NumberToDollars>
<web:dNum>10</web:dNum>
</web:NumberToDollars>
</soapenv:Body>
</soapenv:Envelope>
"""
When soap action 'Conversion'
Then status 200
* print '\n', response
#working
* match response /Envelope/Body/NumberToDollarsResponse/NumberToDollarsResult == 'ten dollars'
#not working
* print response.Envelope.Body.NumberToDollarsResponse.NumberToDollarsResult
#not working
* print response /Envelope/Body/NumberToDollarsResponse/NumberToDollarsResult
#not working
* def x = response /Envelope/Body/NumberToDollarsResponse/NumberToDollarsResult
* print x
If you read the docs, print only handles JS on the right-hand-side, not XPath.
For what you want, please do in 2 steps:
* def temp = /Envelope/Body/NumberToDollarsResponse/NumberToDollarsResult
* print temp

Add default namespace to an element within soap body

I have generated a web-service client (JAX-WS) and model from wsdl and xsd. I have problem with namespaces within soap body.
Lets assume we have two classes:
#XmlRootElement(namespace="aNamespace") class A {
#XmlAnyElement(lax = true) Object obj;
}
#XmlRootElement(namespace="bNamespace") class B {...}
The object I want to send is 'a':
A a = new A();
a.obj = new B();
The service I am calling expects either of V1 or V3 requests:
V1
...
<soapenv:Body>
<A xmlns="aNamespace">
<B xmlns="bNamespace">
<B1>...</B1>
<B2>...</B2>
</B>
</A>
</soapenv:Body>
...
V3
...
<soapenv:Body>
<a:A xmlns:a="aNamespace">
<b:B xmlns:b="bNamespace">
<b:B1>...</b:B1>
<b:B2>...</b:B2>
</b:B>
</a:A>
</soapenv:Body>
...
Trying to call the service I see following request generated:
V2
...
<soapenv:Body>
<a:A xmlns:a="aNamespace", xmlns:b="bNamespace">
<b:B>
<b:B1>...</b:B1>
<b:B2>...</b:B2>
</b:B>
</a:A>
</soapenv:Body>
...
And the service returns error.
Can I somehow set a default namespace to B(so that I will see <B xmlns="bNamespace">)?
I solved the problem by marshaling B into DOM object. Then I put the created DOM into A.
B b = new B();
Document bDocument = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
JAXBContext.newInstance(B.class).createMarshaller().marshal(b, bDocument);
A a = new A();
a.obj = bDocument;
It produces some weird result, however the web-service accepts it:
...
<soapenv:Body>
<a:A xmlns:a="aNamespace" xmlns:ab="bNamespace">
<b:B xmlns:b="bNamespace">
<b:B1>...</b:B1>
<b:B2>...</b:B2>
</b:B>
</a:A>
</soapenv:Body>
...

savon soap attributes

Am trying to query netsuite api for currencies. The following soap request works for me in SOAP UI client. But i am having a hard time trying to get the same working with ruby's savon gem version 0.9.7.
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:messages_2012_2.platform.webservices.netsuite.com" xmlns:urn1="urn:core_2012_2.platform.webservices.netsuite.com">
<soapenv:Header>
<urn:passport>
<urn1:email>xxx#abc.com</urn1:email>
<urn1:password>xxx</urn1:password>
<urn1:account>xxx</urn1:account>
</urn:passport>
</soapenv:Header>
<soapenv:Body>
<urn:getAll>
<urn:record recordType="currency"/>
</urn:getAll>
</soapenv:Body>
</soapenv:Envelope>
Basically i am not able to set the attribute on the urn:record element. The following is not working:
response = client.request :urn, :get_all do
soap.body = { "urn:record" => { :attributes! => { "recordType" => "currency" } } }
end
Please advise.
As explained on http://savonrb.com the key in the attributes! hash has to match the XML tag. You want to write something like this:
response = client.request :urn, :get_all do
soap.body = {'urn:record'=>'',
:attributes!=>{'urn:record'=>{'recordType'=>'currency'}}
}
end
Please let us know whether this solves it for you.
Double-check the raw soap request. :get_all may need to be "getAll" to have savon take you literally; it may be changing it to GetAll
In new versioin of savon you can place :attributes in the local context for the operation tag:
#interaction_client.call(:retrieve_interaction, message: message_hash, :attributes => { 'attachmentInfo' => include_attachments.to_s })
In this case, the attachmentInfo attribute will be placed into the main operation tag linked with operation, in this example this would be the ns:RetrieveInteractionRequest tag.
Please note that the syntax does not contains the exclamation mark.