Integrate web API performance monitoring in SoapUI

Server-side applications provide web-based APIs that allow other clients (like mobile or AppMon Clients) to use their functionality. Functional testing of those APIs is typically performed using tools like JMeter or SoapUI. With the Web API Test Category, the performance of those API can also be monitored continuously.

Requirements

Goal

This tutorial shows how to:

  • Create a SoapUI project that tests a web service.
  • Register the functional test with AppMon to retrieve performance metrics.

The tutorial accesses an easyTravel URI (/result.jsf?dest=New+York) where you can find journeys filtered by start date, end date, and location, and get a list of journeys in XML. If you have easyTravel running on your machine you can try to access http://localhost:8080/result.jsf?dest=New+York for a list of journeys to New York. If this call fails, make sure you have easyTravel started and running on port 8080.

Steps

This example uses the System Profile supplied with easyTravel. If you prefer to use your own System Profile, make sure you have the Servlet sensor enabled for the required Agent Group/Tier. Also, you'll have to specify data of your app instead of easyTravel.

Note

Instead of creating test script manually, you can download and use the sample script.

1. Create a request to the easyTravel application

In the SoapUI, click File > New SOAP Project, to create a new project. Set the name as easyTravel-findJourneys.

Create the request to the easyTravel application.

  1. Click Project > New REST service from URI, and set the http://localhost:8080/result.jsf?dest=New+York URI.

  2. Click Submit request to specified endpoint URL icon to verify that the request and the response are correct.

    Tip

    easyTravel must be running at the time.

Now, add this request to the test case.

  1. In the project tree, right-click Request, and select Add to test case from the context menu.
  2. Set the name of the test suite as easyTravel Service.
  3. Set the name of the test case as findJourneys.
  4. Set the name of the request as Request to easyTravel.

Set the success criterion. The request is considered successful, if the response contains the New York text.

  1. Double-click the newly created request in the test case tree. Expand the Assertions pane, and click the Add assertion to this item icon, to add the assertion.

  2. Select Property Content > Contains, and click Add.

  3. Specify content as New York, and click OK.

  4. Click Submit request to specified endpoint URL icon to verify that the request and the response are correct.

    Tip

    easyTravel must be running at the time.

2. Register test run at the AppMon Server via REST

Add a service end point for the AppMon REST service testrun into the project. Click Project > New REST service from URI, and set one of the following URIs, depending on version you're using:

See also REST Interfaces for Test Automation to learn more about REST Interfaces.

In the request pane, change the method to POST.

Specify the JSON body of this request. From the Media Type list, select application/json. This example registers a test run for Web API tests, running on Linux platform:

{
  "platform": "Linux",
  "category": "webapi",
  "additionalMetaData": {}
}

Set up the authentication details.

  1. Click Authorization and Security-related settings.
  2. From the Authorization list, select Add new authorization.
  3. Select the Basic type.
  4. Specify user name and password of a user with sufficient permissions.

Click Submit request to specified endpoint URL icon to verify that the request and the response are correct.

Tip

easyTravel must be running at the time.

In the findJourneys test case, create a new Custom Property to store the unique test run ID sent by the AppMon Server.

  1. Double-click findJourneys test case.
  2. Expand the Properties pane, and click the Add icon.
  3. Set the name of the property as testRunId.

Add the REST call to the test case.

  1. Double-click the findJourneys test case.
  2. In the Test steps tab, right-click Request to easyTravel step, and select Insert step > REST Request from the context menu.
  3. Set the name as Register testRun.
  4. Move the newly created request to the top. Right click and select Move Step Up from the context menu.

Set the success criterion. The request is considered successful, if the response contains the ID of the test run.

  1. Double-click the newly created request in the test case tree. Expand the Assertions pane, and click the Add assertion to this item icon, to add the assertion.
  2. Select Property Content > Contains, and click Add.
  3. Specify content as id, and click OK.

3. Mark the request to the easyTravel application

Extract the test run ID from the request's response and save it into the testRunId property.

  1. In the Test steps tab, right-click the Register testRun step, and select Insert step > REST Request from the context menu.
  2. Set the name as testRun ID Transfer.
  3. Click Add icon, to add the new property.
  4. Set the name as testRunId.
  5. Configure the Source:
    • Source: Register testRun.
    • Property: Response.
    • Path language: JSONPath.
    • Expression: $.id
  6. Configure the Target:
    • Target: findJourneys.
    • Property: testRunId

Mark the request to easyTravel with the test run ID.

  1. In the Test steps tab, right-click testRun ID Transfer step, and select Insert step > Groovy Script from the context menu.
  2. Set the name as Mark Request.
  3. Copy and paste this script:
import com.eviware.soapui.support.types.StringToStringMap
def headers = new StringToStringMap()
headers.put("X-dynaTrace","NA=Find journeys;TR=" + testRunner.testCase.getPropertyValue("testRunId") + ";RC=200")
testRunner.testCase.getTestStepByName("Request to easyTravel").testRequest.setRequestHeaders(headers)

4. Perform tests

You all set. Now, run the test a few times to get some data for the Test Results dashlet in the AppMon Client.

With the dashlet open, adjust the time filter to the last 30 minutes, to make it easier to find the requests you just executed. This screen shot shows the request made, a list of metrics as well as a historic chart of metric values:

Download

Sample SoapUI Project