Service Virtualization

  • 1.  Arithmetic Operation in VSI

    Posted Sep 17, 2017 11:09 PM

    I would like to perform some arithmetic operations in the VSI response, anybody can advise if its do-able? Example below with bold elements in question. I am using v9.5.1

     

    <Date>16/09/2017</Date>

    <Usage>{{AvgUsage}}</Usage>

    <TotalUsage>{{AvgUsage}}</TotalUsage>

    <Date>17/09/2017</Date>

    <Usage>{{AvgUsage}}</Usage>

    <TotalUsage>{{AvgUsage}}*2</TotalUsage>

    <Date>18/09/2017</Date>

    <Usage>{{AvgUsage}}</Usage>

    <TotalUsage>{{AvgUsage}}*3</TotalUsage>



  • 2.  Re: Arithmetic Operation in VSI
    Best Answer

    Posted Sep 17, 2017 11:32 PM

    Ah, I found the answer to it. Taking the idea from the documentation, Property Expressions - DevTest Solutions - 8.0 - CA Technologies Documentation 

     

    I replace the values as below and it works.

     

    <Date>16/09/2017</Date>

    <Usage>{{AvgUsage}}</Usage>

    <TotalUsage>{{AvgUsage}}</TotalUsage>

    <Date>17/09/2017</Date>

    <Usage>{{AvgUsage}}</Usage>

    <TotalUsage>{{Test=AvgUsage*2}}</TotalUsage>

    <Date>18/09/2017</Date>

    <Usage>{{AvgUsage}}</Usage>

    <TotalUsage>{{Test=AvgUsage*3}}</TotalUsage>



  • 3.  Re: Arithmetic Operation in VSI

    Broadcom Employee
    Posted Sep 18, 2017 10:50 AM

    The expression needs to be {{Test=AvgUsage*2}} or {{Test=AvgUsage*3}} only if the value of AvgUsage*2 or AvgUsage*3 is needed in a later part of the workflow - which is available via the property named Test

     

    Otherwise {{=AvgUsage*2}} and {{=AvgUsage*3}} would suffice.



  • 4.  Re: Arithmetic Operation in VSI

    Posted Sep 18, 2017 09:19 PM

    Thanks!



  • 5.  Re: Arithmetic Operation in VSI

    Posted Sep 17, 2017 11:43 PM

    You can do like

     

    {{=(4)*5}} and this evaluates to 20

     

    So in your response you can do

     

    {{=(testExec.getStateValue("AvgUsage"))*3}}



  • 6.  Re: Arithmetic Operation in VSI

    Broadcom Employee
    Posted Sep 17, 2017 11:52 PM

    Hi Eric,

        This can be doable by adding a logic in match script as mentioned below

     

    String AvgUsage = incomingRequest.getArguments().get("AvgUsage");

    int TotalUsage= Integer.parseInt(AvgUsage)*2;

    testExce.setStateValue("TotalUsage",Integer.toString(TotalUsage));

     

    Thanks 

    Srikanth



  • 7.  Re: Arithmetic Operation in VSI

    Posted Sep 18, 2017 09:17 PM

    Hi Srikanth,

     

    Will that affect the image response selection? The experience I have with using match script is that it will tend to interfere with the matching, and wrong response will sometimes be selected.

     

    That is why I am using the operations within the message XML itself, instead of using the match script. Maybe we can discuss a bit more on this offline?

     

    Thanks and Regards,
    Eric Song



  • 8.  Re: Arithmetic Operation in VSI

    Posted Sep 18, 2017 09:07 AM

    Eric,

     

    Did Mark's and Srikanth's recommendations help you out with this issue?



  • 9.  Re: Arithmetic Operation in VSI

    Broadcom Employee
    Posted Sep 19, 2017 04:00 AM

    It looks like this question touches on the subject of keeping count in a virtual service, at least in some of the techniques needed for arithmetic operations.

    So you want to keep count in a virtual service?