Service Virtualization

  • 1.  How to Generate Unique id in one tag in Response

    Posted Sep 13, 2017 10:36 AM

    Hello All,

     

    We got one request. In one MQ stub, for every same request, we have to generate on unique id in one tag in response.

     

    For example,

     for first request, there should be 1 in tag in response. For same second request, it should be 2 or different unique value in tag in response?

     

    Please let us know how we can achieve this? Is it using assertion or filter in VSM?

     

    Please advise.

     

    Cheers..

    Shivam Garg



  • 2.  Re: How to Generate Unique id in one tag in Response

    Broadcom Employee
    Posted Sep 14, 2017 01:36 AM

    Hi Shivam,

     

        I have recently implemented this kind of approach in one of the vsi. Please add below code in match script of vsi file and set the property "randomInt" in response details.

     

    import java.util.Random;
    Random random = new Random();
    int randomInt = random.nextInt();
    String result = String.valueOf(randomInt);
    testExec.setStateValue("randomInt",Result);
    return true;

     

    Thanks & Regards

    Srikanth Gajawada



  • 3.  Re: How to Generate Unique id in one tag in Response

    Posted Sep 14, 2017 02:33 AM

    hello Srikanth,


    Thanks for you reply. As I am understanding , we are generating random number here with java random function. So is there any chances that this function can generate same number for different requests any time?

     

    please advise.

     

    Cheers..



  • 4.  Re: How to Generate Unique id in one tag in Response

    Broadcom Employee
    Posted Sep 14, 2017 03:55 AM

    Shubham, there are very less chances of repeating of the number. Other way you can use is as below:

     

    String s = String.valueOf(System.currentTimeMillis());

    String phone = s.substring(1,11);

    testExec.setStateValue("randomInt",Result);

        This will generate random number based on currentsystem time. Since the time will change for each request, you will get random response.



  • 5.  Re: How to Generate Unique id in one tag in Response

    Broadcom Employee
    Posted Sep 14, 2017 06:00 AM

    An alternative approach to scripting in a match script would be to apply a data set to the Image Selection step in the VSM. There are two data set types that might be useful; "unique" and "random", depending on your requirements for randomisation (UUID style, number of digits, numeric or alphanumeric, etc), which will generate a property that you name.

     

    Generate a random property using one of these data sets and then simply refer to {{whateverYouCalledYourRandomProperty}} in your VSI.



  • 6.  Re: How to Generate Unique id in one tag in Response
    Best Answer

    Posted Sep 14, 2017 09:51 AM

    Hi,

     

    Simple solution which I can suggest for this would be String patterns if you just need Unique values as mentioned in the question

     

    https://docops.ca.com/devtest-solutions/10-1/en/using/using-ca-application-test/using-devtest-workstation-with-ca-application-test/building-test-cases/properties/string-patterns

     

    Thanks,

    Venkatesh Satturi



  • 7.  Re: How to Generate Unique id in one tag in Response

    Broadcom Employee
    Posted Sep 14, 2017 09:58 AM

    You can also use, Random Code Generator Data set or Unique Code Generator Dataset in the Listen step and use the Data set name in your response.

     

    Random Code Generator Data Set - DevTest Solutions - 10.1 - CA Technologies Documentation 

    Unique Code Generator Data Set - DevTest Solutions - 10.1 - CA Technologies Documentation