Testing web services using SoapUI

5 minutes to read Download PDF Edit

You can publish your own webservices in a Mendix application. These webservices consist of operations. Other applications can then call operations of this webservice and you can return a result. This result is based on a microflow that will be executed when the webservice is called. With SoapUI you can create (automated) tests for these webservices.

After completing this how-to you will know:

  • How to create a SOAP project with SoapUI.
  • How to create assertions in SoapUI.
  • How to build an automated test using SoapUI.

1. Preparation

Before you can start with this how-to, make sure you have completed the following prerequisites.

SoftwareVersion used in this how-to
Mendix Modeler5.20.0
SoapUI5.2.0

2. Publish more microflows as web service operation

In the how-to Exposing a web service you already published the microflow _GetCustomers _as web service operation. In this chapter you will create two more microflow and publish them as web service operation.

  1. Open the Mendix Modeler.
  2. Open the project you created in the how-to Exposing a web service.
  3. Create a Microflow that creates a customer and returns a boolean. 

  4. Create a Microflow that deletes a customer and returns a boolean.

  5. Publish both microflows as web service operation of the CustomerWebservice as described in chapter 4 of the how-to Exposing a web service.

3. Create a new SOAP project

In this chapter you will create a new SOAP project.

  1. Open SoapUI.
  2. Press CTRL+N to create a new SOAP project.
  3. Run the project locally in the Mendix Modeler.
  4. Go to http://localhost:8080/ws-doc/.
  5. Enter the URL of the WSDL schema in the Initial WSDL field in SoapUI. The Project Name field will automatically be filled with the name of the webservice following by ?wsdl.
  6. Click OK. This will create a new SOAP project in SoapUI.

4. Build a TestSuite, a TestCase and a TestStep

In this chapter you will build a testsuite. A testsuite contains one or more testcases. Every testcase contains one ore more teststeps. 

  1. In SoapUI, press CTRL+T to create a new TestSuite.
  2. Click OK.
  3. Select TestSuite 1 and press CTRL+N to create a new TestCase.
  4. Click OK.
  5. Expand Testuite 1 and TestCase 1.
  6. Right-click Test Steps(0) and select SOAP Request.
  7. Enter _Retrieve Customers_ in the name field.
  8. Click OK.
  9. Select CustomerWebserviceSoap -> GetCustomers.
  10. Click OK.
  11. Click OK.
  12. Open SOAP request Retrieve Customers.  

  13. Change the follow value:

    <Offset>?</Offset>
    <PageSize>?</PageSize>
    

    into

    <Offset>0</Offset>
    <PageSize>10</PageSize>
    
  14. Press ALT+Enter to submit the request.

    The customers you created in the previous how-to will be shown in the response. The response will look like the code below:

    <soap:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tns="http://www.example.com/">
       <soap:Body>
          <tns:GetCustomersResponse>
             <Customer>
                <Name>Jessica D. Rogers</Name>
                <Address>2118 Collins Street</Address>
                <ZipCode>PA 16646</ZipCode>
                <City>Hastings</City>
             </Customer>
             <Customer>
                <Name>Jamie S. Wentz</Name>
                <Address>3269 Village View Drive</Address>
                <ZipCode>MD 20872</ZipCode>
                <City>Damascus</City>
             </Customer>
             <Customer>
                <Name>Blake G. Race</Name>
                <Address>4437 Sunny Glen Lane</Address>
                <ZipCode>OH 44115</ZipCode>
                <City>Cleveland</City>
             </Customer>
             <Customer>
                <Name>Angela L. Dolly</Name>
                <Address>3718 Alpha Avenue</Address>
                <ZipCode>TX 75439</ZipCode>
                <City>Ector</City>
             </Customer>
          </tns:GetCustomersResponse>
       </soap:Body>
    </soap:Envelope>
    

5. Assertions

Assertions are used to validate the message received by a TestStep during execution, usually by comparing parts of the message (or the entire message) to some expected value. In this chapter you will create an assertion that validates the number of customers.

  1. Click Assertions (1). In chapter 3 step 9 the Add SOAP Response Assertion checkbox was checked. That is the first assertion you see in the list, SOAP Response - VALID.
  2. Click the add assertion icon.
  3. Click Property Content.
  4. Click XPath Match.
  5. Enter _count(//Customer)_ in the XPath Expression field.
  6. In step 1.4 of the previous how-to you have added some data. Enter the number of created customers in the Expected Result field. In this example four customers were created.
  7. Click Save.

6. Extend your test case

In this chapter you will extend your test case with multiple test steps and assertions.

  1. Add a new SOAP request to the existing test case with the following details:

    FieldValue
    Specify name for stepCreate Customer
    Select operation to invoke for requestCustomerWebServiceSoap -> CreateCustomer
  2. Change the request into the following value:

    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:exam="http://www.example.com/">
       <soapenv:Header/>
       <soapenv:Body>
          <exam:CreateCustomer>
             <Name>Donald A. Hylton</Name>
             <Address>784 Better Street</Address>
             <City>Kansas City</City>
             <ZipCode>KS 66102</ZipCode>
          </exam:CreateCustomer>
       </soapenv:Body>
    </soapenv:Envelope>
    
  3. Add a Contains Assertion and enter true in the content field.  

  4. Right-click test step Retrieve Customers.

  5. Select Clone TestStep.

  6. Change TestStep Name to Retrieve Customers 2.

  7. Click OK.

  8. Open teststep Retrieve Customers 2.

  9. Click Assertions (2).

  10. Open XPath Match - Unknown.

  11. Change Expected result to 1 + [the number you entered in step 5.6].

  12. Click Save.

  13. Add a new SOAP request to the existing test case with the following details:

    FieldValue
    Specify name for stepDelete Customer
    Select operation to invoke for requestCustomerWebServiceSoap -> DeleteCustomer
  14. Change the request into the following value:

    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:exam="http://www.example.com/">
       <soapenv:Header/>
       <soapenv:Body>
          <exam:DeleteCustomer>
             <Name>Donald A. Hylton</Name>
          </exam:DeleteCustomer>
       </soapenv:Body>
    </soapenv:Envelope>
    

7. Run the test case

In this chapter you will learn how to run the testcase you created in previous chapters.

  1. Open testcase TestCase 1.
  2. Click the run this testcase icon.

Congratulations! You have just created your first automated test with SoapUI.

Learn more about this topic using the following helpful links:

Copyright © Mendix. All rights reserved. | Mendix.com | Terms of Use | Privacy Policy