SoapUI is a useful tool for testing web services. Not only makes it possible to test deployed web services, but it also offers the possibility to mock any “external” service needed by the service you want to test. As a result, you can test your web service independently from any other external service.
The following basic example describes how to test a service that computes the price of a trip (TripPriceService). It invokes one service that returns prices for hotel rooms (HotelPriceService) and one service that returns prices for flights (FlightPriceService).
Formula : price = duration * rooms * getRoomPrice() + adults * getFlightPrice(from, to)
Here are the WSDLs of the three services.
TripPriceService.wsdl
<?xml version='1.0' encoding='UTF-8'?><wsdl:definitions name="TripPriceServiceFacadeService"
targetNamespace="http://trip.price.service" xmlns:ns1="http://cxf.apache.org/bindings/xformat"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://trip.price.service" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<wsdl:types>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="unqualified"
targetNamespace="http://trip.price.service" xmlns:tns="http://trip.price.service" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="getTripPrice" type="tns:getTripPrice" />
<xs:element name="getTripPriceResponse" type="tns:getTripPriceResponse" />
<xs:complexType name="getTripPrice">
<xs:sequence>
<xs:element minOccurs="0" name="trip" type="tns:trip" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="trip">
<xs:sequence>
<xs:element name="adults" type="xs:int" />
<xs:element name="duration" type="xs:int" />
<xs:element minOccurs="0" name="from" type="xs:string" />
<xs:element name="rooms" type="xs:int" />
<xs:element minOccurs="0" name="to" type="xs:string" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="getTripPriceResponse">
<xs:sequence>
<xs:element name="return" type="xs:float" />
</xs:sequence>
</xs:complexType>
<xs:element name="TripPriceServiceException" type="tns:TripPriceServiceException" />
<xs:complexType name="TripPriceServiceException">
<xs:sequence />
</xs:complexType>
</xs:schema>
</wsdl:types>
<wsdl:message name="TripPriceServiceException">
<wsdl:part element="tns:TripPriceServiceException" name="TripPriceServiceException">
</wsdl:part>
</wsdl:message>
<wsdl:message name="getTripPrice">
<wsdl:part element="tns:getTripPrice" name="parameters">
</wsdl:part>
</wsdl:message>
<wsdl:message name="getTripPriceResponse">
<wsdl:part element="tns:getTripPriceResponse" name="parameters">
</wsdl:part>
</wsdl:message>
<wsdl:portType name="ITripPriceServiceFacade">
<wsdl:operation name="getTripPrice">
<wsdl:input message="tns:getTripPrice" name="getTripPrice">
</wsdl:input>
<wsdl:output message="tns:getTripPriceResponse" name="getTripPriceResponse">
</wsdl:output>
<wsdl:fault message="tns:TripPriceServiceException" name="TripPriceServiceException">
</wsdl:fault>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="TripPriceServiceFacadeServiceSoapBinding" type="tns:ITripPriceServiceFacade">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="getTripPrice">
<soap:operation soapAction="" style="document" />
<wsdl:input name="getTripPrice">
<soap:body use="literal" />
</wsdl:input>
<wsdl:output name="getTripPriceResponse">
<soap:body use="literal" />
</wsdl:output>
<wsdl:fault name="TripPriceServiceException">
<soap:fault name="TripPriceServiceException" use="literal" />
</wsdl:fault>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="TripPriceServiceFacadeService">
<wsdl:port binding="tns:TripPriceServiceFacadeServiceSoapBinding" name="TripPriceServiceFacadePort">
<soap:address location="http://localhost:8080/trip-price-0.0.1-SNAPSHOT/webservices/TripPriceService" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
HotelPriceService.wsdl
<?xml version='1.0' encoding='UTF-8'?><wsdl:definitions name="HotelPriceServiceFacadeService"
targetNamespace="http://external.services/hotel" xmlns:ns1="http://cxf.apache.org/bindings/xformat"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://external.services/hotel"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<wsdl:types>
<xs:schema elementFormDefault="unqualified" targetNamespace="http://external.services/hotel"
version="1.0" xmlns:tns="http://external.services/hotel" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="getRoomPrice" type="tns:getRoomPrice" />
<xs:element name="getRoomPriceResponse" type="tns:getRoomPriceResponse" />
<xs:complexType name="getRoomPrice">
<xs:sequence />
</xs:complexType>
<xs:complexType name="getRoomPriceResponse">
<xs:sequence>
<xs:element name="return" type="xs:float" />
</xs:sequence>
</xs:complexType>
</xs:schema>
</wsdl:types>
<wsdl:message name="getRoomPrice">
<wsdl:part element="tns:getRoomPrice" name="parameters">
</wsdl:part>
</wsdl:message>
<wsdl:message name="getRoomPriceResponse">
<wsdl:part element="tns:getRoomPriceResponse" name="parameters">
</wsdl:part>
</wsdl:message>
<wsdl:portType name="IHotelPriceServiceFacade">
<wsdl:operation name="getRoomPrice">
<wsdl:input message="tns:getRoomPrice" name="getRoomPrice">
</wsdl:input>
<wsdl:output message="tns:getRoomPriceResponse" name="getRoomPriceResponse">
</wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="HotelPriceServiceFacadeServiceSoapBinding" type="tns:IHotelPriceServiceFacade">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="getRoomPrice">
<soap:operation soapAction="" style="document" />
<wsdl:input name="getRoomPrice">
<soap:body use="literal" />
</wsdl:input>
<wsdl:output name="getRoomPriceResponse">
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="HotelPriceServiceFacadeService">
<wsdl:port binding="tns:HotelPriceServiceFacadeServiceSoapBinding" name="HotelPriceServiceFacadePort">
<soap:address location="http://localhost:8088/external-services-0.0.1-SNAPSHOT/webservices/HotelPriceService" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
FlightPriceService.wsdl
<?xml version='1.0' encoding='UTF-8'?>
<wsdl:definitions name="FlightPriceServiceFacadeService" targetNamespace="http://external.services/flight"
xmlns:ns1="http://cxf.apache.org/bindings/xformat" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://external.services/flight" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<wsdl:types>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="unqualified"
targetNamespace="http://external.services/flight" xmlns:tns="http://external.services/flight"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="getFlightPrice" type="tns:getFlightPrice" />
<xs:element name="getFlightPriceResponse" type="tns:getFlightPriceResponse" />
<xs:complexType name="getFlightPrice">
<xs:sequence>
<xs:element minOccurs="0" name="from" type="xs:string" />
<xs:element minOccurs="0" name="to" type="xs:string" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="getFlightPriceResponse">
<xs:sequence>
<xs:element name="return" type="xs:float" />
</xs:sequence>
</xs:complexType>
<xs:element name="LocationNotFoundException" type="tns:LocationNotFoundException" />
<xs:complexType name="LocationNotFoundException">
<xs:sequence />
</xs:complexType>
</xs:schema>
</wsdl:types>
<wsdl:message name="LocationNotFoundException">
<wsdl:part element="tns:LocationNotFoundException" name="LocationNotFoundException">
</wsdl:part>
</wsdl:message>
<wsdl:message name="getFlightPrice">
<wsdl:part element="tns:getFlightPrice" name="parameters">
</wsdl:part>
</wsdl:message>
<wsdl:message name="getFlightPriceResponse">
<wsdl:part element="tns:getFlightPriceResponse" name="parameters">
</wsdl:part>
</wsdl:message>
<wsdl:portType name="IFlightPriceServiceFacade">
<wsdl:operation name="getFlightPrice">
<wsdl:input message="tns:getFlightPrice" name="getFlightPrice">
</wsdl:input>
<wsdl:output message="tns:getFlightPriceResponse" name="getFlightPriceResponse">
</wsdl:output>
<wsdl:fault message="tns:LocationNotFoundException" name="LocationNotFoundException">
</wsdl:fault>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="FlightPriceServiceFacadeServiceSoapBinding" type="tns:IFlightPriceServiceFacade">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="getFlightPrice">
<soap:operation soapAction="" style="document" />
<wsdl:input name="getFlightPrice">
<soap:body use="literal" />
</wsdl:input>
<wsdl:output name="getFlightPriceResponse">
<soap:body use="literal" />
</wsdl:output>
<wsdl:fault name="LocationNotFoundException">
<soap:fault name="LocationNotFoundException" use="literal" />
</wsdl:fault>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="FlightPriceServiceFacadeService">
<wsdl:port binding="tns:FlightPriceServiceFacadeServiceSoapBinding" name="FlightPriceServiceFacadePort">
<soap:address location="http://localhost:8088/external-services-0.0.1-SNAPSHOT/webservices/FlightPriceService" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>