Service Virtualization

Expand all | Collapse all

property set in match script not working in response data in VSI

Jump to Best Answer
  • 1.  property set in match script not working in response data in VSI

    Posted 02-09-2018 10:23 AM

    I have a match script in my VSI like below

     

    String incomingAcctNumValue = incomingRequest.getArguments().get("keyValue_value");

    switch(incomingAcctNumValue)
    {
    case "4800150020014723":
    testExec.setStateValue("acctNum",incomingAcctNumValue);
    testExec.setStateValue("accountId", "00000000058");
    testExec.setStateValue("customerId", "000003544");
    break;
    case "4800150011009815":
    testExec.setStateValue("acctNum",incomingAcctNumValue);
    testExec.setStateValue("accountId","00000000058");
    testExec.setStateValue("customerId", "000003547");
    break;
    case "4800150011009807":
    testExec.setStateValue("acctNum",incomingAcctNumValue);
    testExec.setStateValue("accountId","00000000059");
    testExec.setStateValue("customerId","000003544");
    break;
    default:
    testExec.setStateValue("acctNum",incomingAcctNumValue);
    testExec.setStateValue("accountId","00000000058");
    testExec.setStateValue("customerId","000003546");

    }

     

     

    and i'm calling these property in my response data like

    {{acctNum}}

     

     

     

    but i'm still getting the response as {{acctNum}} instead of the values; 

     

    Please let me know what i'm doing wrong?



  • 2.  Re: property set in match script not working in response data in VSI
    Best Answer

    Posted 02-09-2018 01:24 PM

    Hi Raja,

     

    Your logic is good, please check if you getting exception at:

    String incomingAcctNumValue = incomingRequest.getArguments().get("keyValue_value");

     

    try using :

    String incomingAcctNumValue = incomingRequest.getArguments().get("keyValue_value").toString();

     

    Or you can debug exception by setting properties at different steps in your code:

    try below:

     

    testExec.setStateValue("acctNum","IncomingRequest");

    String incomingAcctNumValue = incomingRequest.getArguments().get("keyValue_value");

     

    testExec.setStateValue("acctNum","Value Read");

    testExec.setStateValue("acctNum",incomingAcctNumValue);

     

     

    Execute the code and check the {{acctNum}} value.  Try similarly at different steps in code and hence you can locate exact issue.

     

    Note: Match script do not handle any exception , it just ignore the Macth Script code if any exception in code. You can see the Error/Warning message in inspection view to check if this is ignored.

     

     

     

    Thanks,

    Dinesh Kumar

     

     



  • 3.  Re: property set in match script not working in response data in VSI

    Posted 02-09-2018 04:27 PM

    When you access the incoming request's argument list, what is the actual value you are supplying "keyValue_value"?

    Also, do you have multiple operations and/or signatures in the VSI?  If so, does every incoming request contain "keyValue_value" as an incoming request argument?

     

    As Dinesh Kumar points out, when you see a property such as {{acctNum}} that has not been substituted the most likely problem is that the property was not found by the getArguments().get("key") method.



  • 4.  Re: property set in match script not working in response data in VSI

    Posted 10-31-2018 02:19 PM

    Dinesh,

    using testExec.setStateValue("key","Value") in match script used to work for me also in the past. But with DevTest 10.2 , I am not able to see the value being changed after testing the virtual service. Everything works fine, except the value is not getting changed. so not able to use it as debugging option from local workstation, Any idea?



  • 5.  Re: property set in match script not working in response data in VSI

    Posted 10-31-2018 03:17 PM

    Are you setting a string value to a property or another property value?  Here is how you can try:

     

    . With a String value:

    testExec.setStateValue("NewPropertyName","Value")

     

    .With a Property value:

    testExec.setStateValue("NewPropertyName",Name OfTheProperty);



  • 6.  Re: property set in match script not working in response data in VSI

    Posted 10-31-2018 03:29 PM

    I tried with both. Below is my JavaScript code. I tried by creating the Key in design time  also. If the key (property) is not defined, the below code does not create the new key TrendDate. The value does not change for key TrendDate after the test execution.

     

    var trenddt = new Date(incomingRequest.getArguments().get("TrendDate"));

    var currdate = new Date();

    testExec.setStateValue("TrendDate","Value");
    testExec.setStateValue("TrendDate1",Log_Value);



  • 7.  Re: property set in match script not working in response data in VSI

    Posted 10-31-2018 04:53 PM

    Could you please open a support ticket?



  • 8.  Re: property set in match script not working in response data in VSI

    Posted 11-02-2018 03:42 PM
      |   view attached

    Created support ticket.

     

     

    Swarup Panja

    DevOps Tools

    Swarup.Panja@BBandT.com<mailto:Swarup.Panja@BBandT.com>