IBM Integration PoT Labs Home page

API Connect Test APIs - Generate Tests using SmartGenerator

1. Overview

In this lab, you will explore “Test APIs” feature of IBM API Connect that generates API tests automatically. By using IBM Api Connect TestAPIs capability you can deliver high quality APIs consistently and improve developer productivity with automation and AI powered testing capabilities.
Reference: https://www.ibm.com/products/api-connect/api-testing

You will be using Customer Database Rest API deployed in Lab1 to App Connect Dashboard.

2. App Connect - Download Swagger document

From the Cloud Pak for Integration Platform Navigator, open App Connect Dashboard (student(n)-db).

Click on the Runtimes.
Select customerdatabase Integration Runtime, and click on the API, then “Download the OpenAPI Document” (yaml) as below.
Alt text


Lets adjust the OpenAPI document to conform to the specification that API Connect Test APIs feature is expecting!

Edit the downloaded yaml file.

a) Append the below section above the schema: segement. Make sure it’s aligned propertly.

consumes:
  - application/json
produces:
  - application/json

alt text

b) Make sure the /customers/post: operation is defined before the “get” operation. if not move the “post” operation segment before the “get” segment as below.

alt text

3. Api Connect - Test APIs

From the Cloud Pak for Integration Platform Navigator, open API Connect Manager (apim-demo).

Click on the “Test APIs” tile.

Alt text

Alt text

Click “Add test suite”.

Test Suite name: student(n)-customerdatabase
Description: student(n) customer database test suite.

Alt text

Click Save.

alt text

Click on the Test Suite tile that you just created.

alt text

alt text alt text alt text alt text alt text alt text

xxxx

Alt text

Click on “Tests” Option.

Alt text
Click on <Add> to create a test.

Alt text
Enter customerdatabasev1_test1 and hit continue.

Alt text Click <Template from Specifications> in the bottom middle option.

alt text

Select “Swagger 2.0 YAML”, and click on “drag a file here or click to upload”, select downloaded yaml file (as below).

Alt text Click Save.

Click on the dropdown, and select /customerdb/v1/customers/{customerId} operation.
alt text

Select “Smart Generator” circle as below, and click on the Tick mark on right of the window.
Alt text

That should generate a POST, GET, and DELETE operations as below.
Alt text

Now, add a variable “customerId” in between POST, and GET as below.

Click on the (i) circle on the GET opeartion, and select “add component before”.

Alt text

Click on “Set variable” circle.

Alt text

Set the variable name as customerId, and value as ${payload.id}.

Confirm changes by clicking the Tick mark on top right of the Variable window.

Alt text

Modify the DELETE operation. Set Authorization default secret
alt text Click Edit of Authorization header field, and enter value “secr3t” as below and click the Correct symbol to save.
alt text

Click <Save> button on the top, and then click <Run Test>.

Alt text

Alt text

Take the defaults, and hit <Run Test>, and that should generate a report as below.

Alt text alt text Alt text

Review and Close the Report.

Click on <Save and Exit> button on the top.

Alt text

Alt text

NOW CLICK <Publish> button as below.
Alt text

Click on the Tests option on the top.
Alt text

Click on the 3 dots on the test CustomerDatabasev1_test1 as below, and click Run. You can hit Run few times.
Alt text

Click on the Dashboard on the top.
Alt text

Here you can see the tests that were ran, and results with Graphs.
Alt text

Congratulations !!!