You can publish your own web services in a Mendix application. These web services consist of operations. Other applications can call operations of this web service and you can return a result. This result is based on a microflow that will be executed when the web service is called. With SoapUI, you can create (automated) tests for these web services.
This how-to teaches you how to do the following:
Create a SOAP project with SoapUI
Create assertions in SoapUI
Build an automated test using SoapUI
Preparation
Before you start this how-to, make sure you have completed the following prerequisites.
All images, names, and steps in this how-to are based on Studio Pro 9.24. When using other versions, the images and/or names on your screen may be different than the images or names used in this how-to.
Publishing More Microflows as Web Service Operation
In Expose a Web Service, you published the microflow GetCustomers as web service operation. In this document, you will create two more microflows and publish them as web service operations.
Create a microflow that creates a customer and returns a Boolean:
Create a microflow that deletes a customer and returns a Boolean:
Publish both microflows as web service operations of the CustomerWebService as described in How to Expose a Web Service.
Creating a New SOAP Project
In this section, you will create a new SOAP project.
Open SoapUI.
Press Ctrl + N to create a new SOAP project.
Run your app locally in Studio Pro.
Go to http://localhost:8080/ws-doc/.
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 web service, followed by ?wsdl.
Click OK. This will create a new SOAP project in SoapUI.
Building a TestSuite, TestCase, and TestStep
In this section, you will build a TestSuite. A TestSuite contains one or more TestCase. Every TestCase contains one ore more TestSteps.
In SoapUI, press Ctrl + T to create a new TestSuite. You can use the given name `TestSuite 1.
Click OK.
Select TestSuite 1 and press Ctrl + N to create a new TestCase.
Click OK.
Expand TestSuite 1 and TestCase 1.
Right-click Test Steps(0) and select SOAP Request.
Enter Retrieve Customers in the name field.
Click OK.
Select CustomerWebserviceSoap -> GetCustomers.
Click OK.
Click OK.
Open SOAP request Retrieve Customers.
Change the follow value:
<Offset>?</Offset><PageSize>?</PageSize>
into
<Offset>0</Offset><PageSize>10</PageSize>
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:Envelopexmlns: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>
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 section, you will create an assertion that validates the number of customers.
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.
Click the add assertion icon.
Click Property Content.
Click XPath Match.
Enter count(//Customer) in the XPath Expression field.
In step 1.4 of the previous how-to, you added some data. Enter the number of created customers in the Expected Result field. In this example, four customers were created.
Click Save.
Extending Your Test Case
In this section, you will extend your TestCase with multiple test steps and assertions.
Add a new SOAP request to the existing TestCase with the following details:
Field
Value
Specify name for step
Create Customer
Select operation to invoke for request
CustomerWebServiceSoap -> CreateCustomer
Change the request into the following value:
<soapenv:Envelopexmlns: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>
Add a Contains Assertion and enter true in the content field.
Right-click TestStep Retrieve Customers.
Select Clone TestStep.
Change TestStep Name to Retrieve Customers 2.
Click OK.
Open TestStep Retrieve Customers 2.
Click Assertions (2).
Open XPath Match - Unknown.
Change Expected result to 1 + [the number you entered in step 5.6].
Click Save.
Add a new SOAP request to the existing TestCase with the following details:
In the Specify name for step, enter Delete Customer.
In the Select operation to invoke for request field, enter CustomerWebServiceSoap -> DeleteCustomer.
Change the request into the following value:
<soapenv:Envelopexmlns: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>
Running the TestCase
In this section, you will learn how to run the TestCase you created in previous chapters.
Open TestCase TestCase 1.
Click the run this TestCase icon.
Congratulations! You have created your first automated test with SoapUI.