Service Virtualization

  • 1.  Random integer number - VSM logic is preferred

    Posted Mar 10, 2018 08:38 PM

    Hi,

     

    I need to generate an 8 digit random number every time and send it in one of the soap response element tag.. so my api takes that random and stores in the database.. because our api automation scripts use that random and fetch the database for other details.. hence this random should not be same if I am redeploying the virtual service... 

     

    So how do I handle this logic.. any regular expression way to mention inside the soap response ? or add groovy logic in VSM ? ..  I never tried logic in match script so dont know how exactly that works but quite good in writing logic in VSM.. so suggest me how to handle in VSM please.. 

     

    thank you



  • 2.  Re: Random integer number - VSM logic is preferred

    Posted Mar 12, 2018 11:11 AM

    The following can be run in a JSR223 step using either Beanshell or Groovy, and will return an 8 digit random number (actually a string of 8 random numbers between 0 and 9) as both the result and in a property named RAND for later use.

     

    Adapt to suit your needs.


    Random rn = new Random();

    String a = new String();

    for (i=0; i<8; i++) {
       a = a + rn.nextInt(10).toString();
    }

    testExec.setStateValue("RAND", a);

    return a;


  • 3.  Re: Random integer number - VSM logic is preferred
    Best Answer

    Posted Mar 12, 2018 11:55 AM

    Hi,

        You can try Random Code Generator Data Set - DevTest Solutions - 9.5 - CA Technologies Documentation 

                                        Thanks,

    Vish



  • 4.  Re: Random integer number - VSM logic is preferred

    Posted Mar 13, 2018 02:09 AM

    Hi, 

     

    As suggested by LearnNow, we have a inbuilt feature called "Random Code Generator" and it is good to use that. 

    I have used this in my project. 

     

    Thanks

    Nikhil



  • 5.  Re: Random integer number - VSM logic is preferred

    Broadcom Employee
    Posted Mar 14, 2018 08:18 PM

    DevTest has inbuilt patterns which can generate random patterns.

     

    For a 8 digit random number, following pattern can be used OOB.

     

    {{fl_randomN=[::DDDDDDDD]}}

     

    String Patterns - DevTest Solutions - 10.2 - CA Technologies Documentation  has a video which has more details for custom pattern creation.