Service Virtualization

  • 1.  Calling VS model steps based on condition

    Posted Jun 20, 2016 08:00 PM

    Hi , I have been using groovy in VSM whenever needed and it is very useful , now I want to know, how can I invoke any other step in VSM based on particular condition as I define in VSM - execute script step (groovy)? example usually we have script assertion which does it,  like if true call 'some step' if false 'some step'  but I want to define this through groovy so that within in single execute script step I can write all my condition as like switch case and call different nodes(steps) based on condition.



  • 2.  Re: Calling VS model steps based on condition

    Broadcom Employee
    Posted Jun 20, 2016 09:23 PM

    I suggest that you still want the workflow differences (assertions) to be visible in your VSM workflow. As such, you want to set a property in your Groovy step (inside your scripted assertion code as a function / method in your Groovy step) and add standard assertions on that property value to determine your next step.



  • 3.  Re: Calling VS model steps based on condition

    Posted Jun 21, 2016 04:53 AM

    Thanks Rick.Brown , but I don't want this as assertion because If I need to define several rule ,then I end up adding so many scripted assertions , so it would be good to have all code in step like 'Execute Script' step. And another thing is I have other groovy code which is written to do some manipulation, so it would be good for me to use those property to define next step from there...



  • 4.  Re: Calling VS model steps based on condition

    Broadcom Employee
    Posted Jun 21, 2016 06:39 AM

    My thought was to have all your decisions in your scripted step, writing a property value:

     

    if(my Assertion 1 stuff) {

         testExec.setStateValue("assertThis", "value1");

    }

    if(my Assertion 2 stuff) {

         testExec.setStateValue("assertThis", "value2");

    }

    if(my Assertion 3 stuff) {

         testExec.setStateValue("assertThis", "value3");

    }

     

    You would use a set of "Ensure Property Matches Expression" exceptions, so "assertThis=value1" goes to one next step, "assertThis=value2" goes to another, etc.



  • 5.  Re: Calling VS model steps based on condition

    Posted Jun 21, 2016 07:26 PM

    Thanks Rick,..

     

    Bit confused.. are you saying here put it in scripted step as code (as you shown above  example format) or add multiple Ensure Property Matches Expression assertion and use value to match and forward to next step accordingly ?



  • 6.  Re: Calling VS model steps based on condition
    Best Answer

    Broadcom Employee
    Posted Jun 21, 2016 08:04 PM

    "are you saying here put it in scripted step as code" - yes

    "add multiple Ensure Property Matches Expression assertion" - yes

     

    So I'm suggesting that you do both. You stated that you want to have the functionality of multiple scripted assertions, but you want to "have all code in step like 'Execute Script' step". So have all your code in an "Execute Script" step, and each piece of assertion code sets a property value that you can use in simple assertions.

     

    EDIT: like this:

     

    whichAssertion = testExec.getStateValue("assertionNumber");

    switch(whichAssertion) {

        case "1":

            testExec.setStateValue("myAssertion","one");

            break;

        case "2":

            testExec.setStateValue("myAssertion","two");

            break;

        default:

            testExec.setStateValue("myAssertion", "none");

    }

    Screen Shot 2016-06-22 at 01.19.01.png



  • 7.  Re: Calling VS model steps based on condition

    Posted Jan 18, 2017 02:49 PM

    Jagath,

     

    Did Rick's recommendations help you out with this issue?

     

    Regards,

    Reid