3

Test SAP CPI Mappings using Postman

 11 months ago
source link: https://blogs.sap.com/2023/06/05/test-sap-cpi-mappings-using-postman/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
June 5, 2023 4 minute read

Test SAP CPI Mappings using Postman

0 0 148

Overview

In this blog, we will see how you can use postman, to test the SAP CPI mappings. You can use this approach for testing your groovy/xslt mapping as well if you find it useful.

SAP CPI mapping simulation lacks more functionality where as SAP PO has better one. In SAP CPI there is no way you can save your xml files as instance, generate xml, copy paste, etc. Even in SAP PO, you have to manually to go output and check the result. For verifying output, you have to manually check it, no way to automate it.

Use Case

For illustration purpose let us consider this simple Invoice xml with one field.

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://www.example.org/Shipping/" targetNamespace="http://www.example.org/Shipping/">
    <element name="Invoice" type="tns:Invoice"></element>
    
    <complexType name="Invoice">
    	<sequence maxOccurs="1" minOccurs="1">
    		<element name="ProductType" type="string"></element>
    	</sequence>
    </complexType>
</schema>
<?xml version="1.0" encoding="utf-8"?>
<!-- Created with Liquid Technologies Online Tools 1.0 (https://www.liquid-technologies.com) -->
<ns1:Invoice xmlns:ns1="http://www.example.org/Shipping/">
  <ProductType>Power</ProductType>
</ns1:Invoice>

Mapping Artifact: We have simple transformation which is using fix values to transport input.

Screenshot-2023-05-23-at-12.21.32.png

Simulate Mapping test

Screenshot-2023-05-23-at-12.25.10.png

output xml

<?xml version="1.0" encoding="UTF-8"?>
<ns1:Invoice xmlns:ns1="http://www.example.org/Shipping/">
    <ProductType>P</ProductType>
</ns1:Invoice>

Gas.png

Bio.png

Fuel.png

Problem

We have to run the mapping manually four times to validate all four values. And we have to manually check the values every time we run the mapping. This might sound easy, but any incremental changes, we have to run these tests again manually and check the output by looking at the output xml.

For each simulation test, you have to wait for few secs to get the output.

Loading.png

What if you have more than 1 field is using transform logic and more than 10 fix values to test. Not easy to do it manually.

For the documentation purpose, you have to capture the inputs and outputs and keep it as record. It is cumbersome to do it manually.

Solution

What I need

  1. Automate the mapping simulation test
  2. Automate cross checking output. No need to go to output xml and  check it manually.
  3. Automate capturing input and output

Let us create a separate Iflow to test the mapping. Here is the simple Iflow with https sender adapter.

mapping_iflow.png
Create request in postman for each test case.
Screenshot-2023-05-23-at-15.40.58-1.png
Screenshot-2023-05-23-at-15.42.01.png
Write a test case for checking product type for all types. I have used chatGPT for writing test script as I am new to java script.
Screenshot-2023-05-23-at-15.48.17-1.png
// Parse the XML response
const responseXml = pm.response.text();

// Extract the ProductType value
const productType = responseXml.match(/<ProductType>(.*?)<\/ProductType>/)[1];

// Check the ProductType value
pm.test("Check ProductType Power", () => {
    pm.expect(productType).to.eql("P");
});

Run the collection

Screenshot-2023-05-23-at-15.51.37-1.png

Here you go.

Screenshot-2023-05-23-at-15.53.30.png
Screenshot-2023-05-23-at-15.56.45-1.png
So now we are able to automate mapping test via postman and able to very the output. Creating test scripts should be one time activity, once done, you can run it multiple time.

If you create postman workspace with visibility as team, you should be able to share it with your team.

Screenshot-2023-05-23-at-16.03.40.png

Documentation

For documenting your tests, you can make use of Newman htmlextra for postman. With this you can document it.

Screenshot-2023-05-23-at-16.11.09.png
Screenshot-2023-05-23-at-16.11.18.png
Screenshot-2023-05-23-at-16.12.10.png
Screenshot-2023-05-23-at-16.12.17.png

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK