Service Virtualization

  • 1.  How to modify a DevTest pattern's value in response.

    Posted Jan 24, 2019 05:44 PM

    I'm using the "Credit Card" pattern in a response.

     

    The pattern is set "xxxx-xxxx-xxxx-xxxx", but i need to send the response without dashes.


    In my VSM, I set a Scriptable Data Protocol Filter trying to erase the dashes, but is sending them anyway.

     

     

    What am I missing?



  • 2.  Re: How to modify a DevTest pattern's value in response.

    Broadcom Employee
    Posted Jan 25, 2019 05:22 AM

    The response is a block of data rather than a parameterList, so you can't refer to <Pan> without manipulating the whole response block. I try to keep the response as a block, rather than parsing it as a W3C document, so I usually split the response into three segments; before the block I want to modify, the block I want to modify, after the block I want to modify. Other people perfer to do it in other ways.

     

    My way ends up looking something like this (not syntax checked)

     

    myResponse=lisa_vse_response.getBodyText();

    startPos = myResponse.indexOf("Pan>") + 4;

    endPos = myResponse.indexOf("</ns0:Pan");

    if(endPos < startPos) {

       //Something has gone wrong. Flag an error and abort

    } else {

       prefix = myResponse.substring(0, startPos);

       ccNumber = myResponse.substring(startPos + 1, endPos);

       suffix = myResponse.substring(endPos + 1);

       ccNumber = ccNumber.replace("-","");

       myResponse = prefix + ccNumber + suffix;

    }

    lisa_vse_response.setBody(myResponse);

     

    I think there are various historic examples of doing things like this in this forum, so you will be able to see how other people approach this if you press the search button (magnifying glass at the top right of this window) and search for "lisa_vse_response".

     

    Rick



  • 3.  Re: How to modify a DevTest pattern's value in response.

    Posted Jan 25, 2019 10:43 AM

    Hello Rick!

     

    Thanks for your response.
    I've checked your code and now I understand how to work with Scriptable DPH and responses
    Sadly, it doesn't help me trying to replace the dashes from Credit Card Pattern.

    When you use "lisa_vse_response.getBodyText();", it saves the whole body, but before converting the devtest pattern's expression  into its value.

    So, when you use ccNumber.replace("-","") it's not replacing  "1111-2222-3333-4444" but "{{=[:Credit Card:]}}".

     

    According this, where can I set the filter to modify the pattern's value and not its expression?



  • 4.  Re: How to modify a DevTest pattern's value in response.
    Best Answer

    Broadcom Employee
    Posted Jan 25, 2019 11:15 AM

    So you'll need to expand properties in the response before making the substitution. You do this by using parseInState, immediately after getBodyText.

     

    Something like (again, not syntax checked):

    myResponse = testExec.parseInState(myResponse);



  • 5.  Re: How to modify a DevTest pattern's value in response.

    Posted Jan 28, 2019 07:33 AM

    Sweeeeeeet!

    This is what I needed.

     

    Thank you so much, Rick!