Class SoapServiceGSpec


  • public class SoapServiceGSpec
    extends BaseGSpec
    Steps definitions for working with SOAP web services
    Author:
    Jose Fernandez
    • Constructor Detail

      • SoapServiceGSpec

        public SoapServiceGSpec​(CommonG spec)
    • Method Detail

      • setRemoteWSDL

        @Given("^The webservice WSDL is located in \'(.+?)\'$")
        public void setRemoteWSDL​(String remoteWsdlAddress)
                           throws Throwable
        Set URL of remote WSDL

        This step parses the remote WSDL (web service description language) webservice descriptor and obtains the basic parameters to execute future requests (like targetNamespace, Service name, methods available, etc). This is a initialization steps and must be used before trying to execute any remote method

         Example: consider the webservice running at http://www.dneonline.com/calculator.asmx, with a WSDL located
         at http://www.dneonline.com/calculator.asmx?WSDL. The first step before executing any other webservice related step should be:
         
              Given The webservice WSDL is located in 'http://www.dneonline.com/calculator.asmx?WSDL'
         
         
        Parameters:
        remoteWsdlAddress - Remote URL of the WSDL document
        Throws:
        Throwable - Throwable
      • executeWebserviceMethod

        @When("^I execute the method \'(.+?)\' based on \'([^:]+?)\'( with:)?$")
        public void executeWebserviceMethod​(String actionName,
                                            String requestFile,
                                            String foo,
                                            io.cucumber.datatable.DataTable modifications)
                                     throws Throwable
        Executes remote webservice method with parameters

        Executes the remote method in the webservice. A request body must be provided for this operation. There is also the possibility of altering values of the request body before sending providing a datatable. Since the library is capable of using any webservice, it does not know in advance the format of the XML messages that are interchanged between the server and the clients. This is why is necessary to provide the XML request that should be sent when executing a particular method.

        Following the example of the webservice located at http://www.dneonline.com/calculator.asmx, the webservice exposes 4 methods: Add, Divide, Multiply and Subtract. To execute the "Add" method, the following XML message should be sent to the server:

         
         <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <soap:Body>
               <Add xmlns="http://tempuri.org/">
                  <intA>int</intA>
                  <intB>int</intB>
               </Add>
            </soap:Body>
         </soap:Envelope>
         
         
        Notice how the XML format of the request contains the variables intA and intB. The server will read this variables from the request, perform an "Add" and return a result in XML format. The information regarding the format of the XML requests and responses is usually well documented and readily available for consumers. If this is not the case, you should contact the webservice developers for this information

        This request XML message format should be stored in a separate file (for this example, lets save it to schemas/AddRequest.xml) To execute the "Add" method with intA = 1 and intB = 1:

         
              Given The webservice WSDL is located in 'http://www.dneonline.com/calculator.asmx?WSDL'
              When I execute the method 'Add' based on 'schemas/AddRequest.xml' with:
                  | intA | 1 |
                  | intB | 1 |
         
         
        You can provide a datatable containing a set of modifications to be performed on the XML request before it is sent to the server (this is necessary in this particular case). If this is not required, you can use the same step without the datatable:
         
              When I execute the method 'Add' based on 'schemas/AddRequest.xml'
         
         
        Parameters:
        actionName - Remote method to execute. The method name will be translated to the corresponding SOAPAction
        requestFile - File containing the request (XML)
        foo - parameter generated by cucumber because of the optional expression
        modifications - (Optional) a datatable with modifications to perform on the request before sending Example: Assuming the request XML body contains the following tags: <intA>int<intA/> <intB>int<intB/> To alter the value of intA and intB, a datatable like the following should be provided: | intA | 1 | | intB | 1 | And the corresponding values for the given tags in the body will be <intA>1<intA/> <intB>1<intB/>
        Throws:
        Throwable - Throwable
        See Also:
        setRemoteWSDL(String)
      • evaluateWebserviceResponse

        @Then("^The response matches the following cases:$")
        public void evaluateWebserviceResponse​(io.cucumber.datatable.DataTable results)
                                        throws Throwable
        Verifies response of webservice.

        Evaluates the response of the remote webservice against a set of conditions provided by a datatable. Following the previous example, the XML response for the "Add" have the format below:

         
         <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <soap:Body>
               <AddResponse xmlns="http://tempuri.org/">
                  <AddResult>int</AddResult>
               </AddResponse>
            </soap:Body>
         </soap:Envelope>
         
         
        The result of the "Add" operation will be present in the AddResult tag in the XML response. Performing an "Add" method with intA=1 and intB=1, we could expect the AddResult to be 2
         
              Scenario: Execute "Add" operation
                  Given The webservice WSDL is located in 'http://www.dneonline.com/calculator.asmx?WSDL'
                  When I execute the method 'Add' based on 'schemas/AddRequest.xml' with:
                      | intA | 1 |
                      | intB | 1 |
                  Then The response matches the following cases:
                      | AddResult | equal | 2 |
         
         
        It is not necessary to store in a separate file the format of the response as it was done with the request, but is important to know the structure of the XML beforehand so we could know in advance what XML tags to evaluate
        Parameters:
        results - Expected results in a datatable Example: Assuming the response from the webservice (XML response), contains the following XML tag: <AddResult>2<AddResult/> To verify that AddResult tag equals "2", a datatable like the following should be provided: | AddResult | equal | 2 | Suported operations: - equal - not equal - contains - does not contain - length
        Throws:
        Throwable - Throwable
        See Also:
        setRemoteWSDL(String), executeWebserviceMethod(String, String, String, DataTable)