Service Virtualization

Expand all | Collapse all

Need to modify & pass a request argument to response JSON

Jump to Best Answer
  • 1.  Need to modify & pass a request argument to response JSON

    Posted 06-19-2018 10:03 AM

    Hi All,

     

    I am trying to create a VS where the response uses one of its JSON element as a request arguements' modified value.

    In my JSON request I am getting particular element with value as 2XXXXXXXXXXX.

     

    In the response JSON we require the to use the same value as magic string in one element and 6XXXXXXXXXXX in another element.

     

    Sample req:

    {
        "Operation": {
            "requestHeader": {
                "activityName": "Operation",
                "senderURI": "Val1",
                "userid": "Val1",
                "security": "security",
                "requestTimestamp": "2016-02-10T07:45:43.38Z",
                "conversationID": "***:2yyyyy-77",
                "requestID": "***:2yyyyy-99"
            },
            "MACAddress": "2XXXXXXXXXXX"
        }
    }

     

    Response:

     

    {
        "Operation": {
            "responseHeader": {
                "activityName": "Operation",
                "businessID": [],
                "messageID": [],
                "activityStatus": "SUCCESS",
                "requestTimestamp": "2016-03-16T17:21:45.634Z",
                "responseTimestamp": "2016-03-16T17:21:45.634Z",
                "conversationID": "***:2yyyyy-77",
                "requestID": "***:2yyyyy-99"
            },
            "success": {
                "MACAddress": "2XXXXXXXXXXX",
                "edVAMACAddress": "6XXXXXXXXXXX",
                "Key": "alphanumerickeyvalue"
            }
        }
    }

     

    Please suggest the approach to be followed to achieve this. Please let me know if any further details are required.

     

    Thanks,

    Sourav.



  • 2.  Re: Need to modify & pass a request argument to response JSON
    Best Answer

    Posted 06-19-2018 02:55 PM

    Hi Sourav, You can do one of the below:

     

    . Create a filter in the Listen step to capture the value of XXXXXXXXXXX from "2XXXXXXXXXXX" and then use that in your VSI response where it 6XXXXXXXXXXX like 6{{FilterName}}. You can use "Create Property Based on Surrounding Values" filter to capture the value from the request. Please refer the documentation on

    Create Property Based on Surrounding Values - DevTest Solutions - 10.3 - CA Technologies Documentation 

    . You can add a scripted assertion and write code to capture the data you are looking and save it into a property and then use that property in the VSI. You can set  the logic of the Scripted assertion to pass always as you are not checking any logic.

    . You can also Scriptable DPH instead of Scripted assertion.

     

    Hope this information helps.

     

    -Prema



  • 3.  Re: Need to modify & pass a request argument to response JSON

    Posted 06-20-2018 06:57 AM

    Hi Prema,

     

    Thanks for the help, I used the option to create a property via correlation and succeeded in achieving the required response.

     

    Thanks,

    Sourav.