Service Virtualization

 View Only
  • 1.  Custom response with parameters

    Posted Nov 25, 2016 12:29 PM

       Hi there,

     

     I had some question regarding the body response for a REST call. It is written we can you {{ }} to replace parameters. For instance,

    {{= request_URLPARAMETER0}} will be replace in the response if written like that in the body response.

    My question is : how can we use conditions in {{ }} ? I couldnt figure out the syntax (on wiki they say : }} can execute arbitrary Java code and even generate realistic "everyday" data such as a valid credit card number {{=[:Credit Card:]. (Magic Strings - DevTest Solutions - 8.0.1 - CA Technologies Documentation).

     

    I'd like to do something like that

    <foo>{{if (request_URLPARAM == 1) { print("case1") } else { print("case2") }</foo>

    but my goal is more something like

    if (param == 1) {

       <foo1>bar1</foo1>

    } else {

       <foo2><foo3>bar2</foo3></foo2>

    }

    because I have 70 possible values for my param, and in the body response i have 50 objects which are attached to one value, so I can easily say "this(these) one(s) should be sent for value XX", etc...

     

    Thanks in advance, I don't know if I'm clear,

    Lambert.



  • 2.  Re: Custom response with parameters
    Best Answer

    Posted Nov 30, 2016 01:57 AM

    You should look at either the "Match Script" tab in the VSI file or to add a scripted dataset for the VSI Selector step in your VSM file.

     

    May I ask if you are able to use devtest 9.5.1? They have data-driven virtual service, Data-Driven Virtual Services - DevTest Solutions - 9.5 - CA Technologies Documentation, which may help you for the number of scenarios and variables that you have. 



  • 3.  Re: Custom response with parameters

    Broadcom Employee
    Posted Dec 09, 2016 05:08 PM

    Hi,

     

    If you want to modify the VSI response based on some code then you can write the code in between {{.... }} tags.

     

    For example:

    {{ if (param == 1) { <foo1>bar1</foo1>} else {<foo2><foo3>bar2</foo3></foo2>} }}



  • 4.  Re: Custom response with parameters

    Posted Dec 09, 2016 05:14 PM

    Hi thanks for the response, that's what I hoped for  I'll try it on thursday (can't before) and I'll update my comment !