API Migration Use case

Image alt text

 

Background

Suppose a monolithic architecture services needs to migrated to microservices architecture. There are numerous apis for that and many apis data are inter-dependent. Data between the services/apis are exchanged.

Requirements

So to ensure that the microservices apis has data and keys same as of monolithic one and code is capable to intelligent, then there comes numerous scenarios and testcases corresponding to the scenarios.

Challenges

It becomes difficult to manually check all the scenarios or automate from scratch using python or java scripts.

Why Gempyp

Even if you use Python/Java Frameworks to automate the scenarios, you won’t be able to achieve the level of ease of automation, the time saved while automation, performance metrics of the apis, intelligent inter-dependency handling between testcases, data passing between testcases and many more.

As per our data,

Project 1:

Count of Legacy APIs – 150
Count of Current APIs – 200
Total Testcases – 1453
Time Taken to write first testcase – 5 mins
Time Taken to automate the all testcases using Gempyp – 120 hours.

How do we achieve the automation:

API 1: Login API
API 2: Suite API
API 3: Testcase API

Each api has multiple positive and negative scenarios and data is exchanged between them.

<data>
    <suite>
        <project-name>ProjectWithAccess</project-name>
        <report-name>MicroService Migration</report-name>
        <environment>ENV.environment</environment>
        <dev>https://dev.baseUrl.com</dev>
        <beta>https://beta.baseUrl.com</beta>
        <prod>https://prod.baseUrl.com</prod>
        <mode>optimize</mode>
        <threads>4</threads>
        <jewel-user>jewelUserName</jewel-user>
        <jewel-bridge-token>JewelBridgeToken</jewel-bridge-token>
    </suite>

    <testcases>

        <!-- login with correct credentials -->
        <testcase>
            <name>Login with correct credentials</name>
            <category>login</category>
            <TYPE>PYPREST</TYPE>
            <method>POST</method>
            <headers>{"Content-Type":"application/json"}</headers>
            <body>{"username": "dummyUser", "password": "dummyPassword"}</body>
            <api>/login</api>
            <expected-status-code>200</expected-status-code>
            <key_check>keys are response.token,response.username</key_check>
            <post_variables>set $[#SUITE.auth]=$[#response.token];set $[#SUITE.username]=$[#response.username]</post_variables>
            <timeout>90000</timeout>
            <run-flag>Y</run-flag>
        </testcase>

        <testcase>
            <name>Login with incorrect credentials</name>
            <category>login</category>
            <TYPE>PYPREST</TYPE>
            <method>POST</method>
            <headers>{"Content-Type":"application/json"}</headers>
            <body>{"username": "dummyUser", "password": "incorrectDummyPassword"}</body>
            <api>/login</api>
            <expected-status-code>443</expected-status-code>
            <timeout>90000</timeout>
            <run-flag>Y</run-flag>
        </testcase>

        <testcase>
            <name>Create suite with correct data</name>
            <category>suite-controller</category>
            <TYPE>PYPREST</TYPE>
            <method>POST</method>
            <headers>{"Authorization":"$[#SUITE.auth]", "Content-Type":"application/json}                                      </headers>            <body>{
                "dummyBodyKey": "dummyBodyValue"
              }</body>
            <api>/suite</api>
            <expected-status-code>201</expected-status-code>
            <key_check>keys are response.data.s_id</key_check>
            <post_variables>set $[#SUITE.var1]=$[#response.key1]</post_variables>
            <run-flag>Y</run-flag>
            <dependency>Login</dependency>
        </testcase>

        <testcase>
            <name>Create suite with incorrect keys</name>
            <category>suite-controller</category>
            <TYPE>PYPREST</TYPE>
            <method>POST</method>
            <headers>{"Authorization":"$[#SUITE.auth]", "Content-Type":"application/json"}</headers>
            <body>{
                "absentBodyKey": "dummyBodyValue"
              }</body>
            <api>/suite</api>
            <expected-status-code>404</expected-status-code>
            <run-flag>Y</run-flag>
            <dependency>Login</dependency>
        </testcase>

        <testcase>
            <name>Create suite with incorrect credential</name>
            <category>suite-controller</category>
            <TYPE>PYPREST</TYPE>
            <method>POST</method>
            <headers>{"Authorization":"incorrectCredential", "Content-Type":"application/json"}</headers>
            <body>{
                "dummyBodyKey": "dummyBodyValue"
              }</body>
            <api>/suite</api>
            <expected-status-code>404</expected-status-code>
            <run-flag>Y</run-flag>
            <dependency>Login</dependency>
        </testcase>

        <testcase>
            <name>Create testcase with correct data</name>
            <category>test-controller</category>
            <TYPE>PYPREST</TYPE>
            <method>POST</method>
            <headers>{"Authorization":"$[#SUITE.auth]", "Content-Type":"application/json"}</headers>
            <body>{
                "dummyBodyKey": "dummyBodyValue"
              }</body>
            <api>/test</api>
            <expected-status-code>201</expected-status-code>
            <key_check>keys are response.key2</key_check>
            <post_variables>set $[#SUITE.var2]=$[#response.key2]</post_variables>
            <run-flag>Y</run-flag>
            <dependency>Login,Create suite with correct data</dependency>
        </testcase>

        <testcase>
            <name>Create testcase with incorrect keys</name>
            <category>test-controller</category>
            <TYPE>PYPREST</TYPE>
            <method>POST</method>
            <headers>{"Authorization":"$[#SUITE.auth]", "Content-Type":"application/json"}</headers>
            <body>{
                "absentBodyKey": "dummyBodyValue"
              }</body>
            <api>/test</api>
            <expected-status-code>404</expected-status-code>
            <run-flag>Y</run-flag>
            <dependency>Login,Create suite with correct data</dependency>
        </testcase>

        <testcase>
            <name>Create testcase with incorrect credential</name>
            <category>test-controller</category>
            <TYPE>PYPREST</TYPE>
            <method>POST</method>
            <headers>{"Authorization":"incorrectCredential", "Content-Type":"application/json"}</headers>
            <body>{
                "dummyBodyKey": "dummyBodyValue"
              }</body>
            <api>/test</api>
            <expected-status-code>404</expected-status-code>
            <run-flag>Y</run-flag>
            <dependency>Login,Create suite with correct data</dependency>
        </testcase>
    </testcases>
</data>

Deep diving into features :

1. To achieve inter-dependency between testcases, we use <dependency> tag. 
2. To pass data between testcases we create a suite variable(using <post-variables> tag) and use that variable in other testcases.