Service Virtualization

  • 1.  Need help with the approach

    Posted Oct 24, 2018 05:58 AM

    Hi All

     

    We need to test below scenario. Can someone help out with the approach that we can follow for it.

    1.Create a Payment (A payment id will be generated say PID123456)

    2.We instantly make a get call for this payment ID and its status come up as Sent.

    3.After certain duration the payment id status changes to Delivered

     

    Objective: Find out the time taken to change the payment status from Sent to Delivered.

     

    Note:

    1.The response we get for get call is in JSON format and doesn't have any key related to time

    2.Devtest Version :10.2.4

     

     

    Thanks and Regards

    Yugain Sharma



  • 2.  Re: Need help with the approach

    Broadcom Employee
    Posted Oct 24, 2018 07:15 AM

    Hi,

     

    I think a lot depends on the accuracy of the measurement that is acceptable for your testing.

     

    If this is black-box testing, meaning you can only find out through that particular interface ( you can only do GET call and get the status) then you can only get an approximation. Example, use a testcase that:

     

       

    •   REST call “Create a Payment”

          

    •   Add Filter: Timestampfilter; store in property startTime

          

    •   Next “Get payment ID and status”

       

    •   REST call “Get payment ID and status”

          

    •   Add Filter: Timestampfilter; store in property stopTime

          

    •   Add Assertion: if status == send, next = “Wait”

          

    •   Add Assertion: if status <> Delivered, next = “Fail the Test”

          

    •   Next “Calculate Time”

       

    •   Do Nothing – “Wait”

          

    •   Think Time = 5 seconds (example)

          

    •   Next “Get payment ID and status”

       

    •   Execute Script “Calculate Time”

          

    •   Do some java magic to do stoptime – startTime = untilDeliveredTime

          

    •   Assertion? If untilDeliveredTime > ?, next = “Fail the Test”

          

    •   Next = “End the Test”

     

    If you can do whitebox testing there is surely some database inside the System under test where these status changes are recorded and where you could get the exact timestamps?

     

    Cheers,

    Danny



  • 3.  Re: Need help with the approach

    Broadcom Employee
    Posted Oct 24, 2018 07:52 AM

    Assuming your timestampformat is the following “yyyyMMddHHmmss” (precision to seconds, not milliseconds) then the following script would store the time difference (in seconds) in property “untilDeliveredTime”.

     

    The seconds are stored as a long type and not as a String, this allows you to easily test later on if the number of seconds is below some threshold.

     

    import java.text.SimpleDateFormat;

    import java.util.Date;

     

    Date startTime = new SimpleDateFormat("yyyyMMddHHmmss").parse(testExec.getStateValue("startTime"));

    Date stopTime = new SimpleDateFormat("yyyyMMddHHmmss").parse(testExec.getStateValue("stopTime"));

    long seconds = (stopTime.getTime()-startTime.getTime())/1000;

    testExec.setStateObject("untilDeliveredTime", seconds);

     

    Looking at above script and looking back at below approach it I sprobably best to calculate the elapsed time and do the comparison againts some threshold at the same time, so this would become something like:

                    :

    :

     

       

    •   Do Nothing “Calculate Time”

     

          

    •   Do some java magic to do stoptime – startTime = untilDeliveredTime

          

    •   Scripted Assertion:  stoptime – startTime = untilDeliveredTime; If untilDeliveredTime > ?, return False; if False, next = “Fail the Test”

          

    •   Next = “End the Test”

     

    Be aware that if you have the threshold defined as a property in a config file that it will be of type String, and you will have to convert it to long before doing calculations, something like:

     

    Long threshold = Long.parseLong(testExec.getStateValue("threshold"));

     

     

    Cheers,

    Danny



  • 4.  Re: Need help with the approach

    Posted Oct 25, 2018 07:45 AM

    Hi Danny

     

    Thanks for your approach

    Iam geting the below timestamps:

     

    A =2018-10-25T07:18:30-0400

    B= 2018-10-25T07:18:51-0400

     

    C =2018-10-25T11:18:29.535Z

    D =2018-10-25T11:18:49.441Z

     

    now I need to get

    1. difference between A and B

    2.difference between C and D

     

    Regards

    Yugain



  • 5.  Re: Need help with the approach
    Best Answer

    Broadcom Employee
    Posted Oct 25, 2018 09:36 AM

    Hi,

     

    So, these are 2 different timestamp formats, one with milliseconds, one without.

    My assumption is that you know when you are retrieving the first, when the latter.

     

    For

    A =2018-10-25T07:18:30-0400

    B= 2018-10-25T07:18:51-0400

    The difference between A and B

     

    import java.text.SimpleDateFormat;

    import java.util.Date;

     

     

    Date startTime = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX").parse(testExec.getStateValue("startTime"));

    Date stopTime = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX").parse(testExec.getStateValue("stopTime"));

    long seconds = (stopTime.getTime()-startTime.getTime())/1000;

    testExec.setStateObject("untilDeliveredTime", seconds);

     

    For

    C =2018-10-25T11:18:29.535Z

    D =2018-10-25T11:18:49.441Z

     

    The difference between C and D

     

    import java.text.SimpleDateFormat;

    import java.util.Date;

     

     

    Date startTime = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX").parse(testExec.getStateValue("startTime"));

    Date stopTime = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX").parse(testExec.getStateValue("stopTime"));

    long seconds = (stopTime.getTime()-startTime.getTime())/1000;

    testExec.setStateObject("untilDeliveredTime", seconds);

     

    Cheers,

    Danny



  • 6.  Re: Need help with the approach

    Posted Oct 29, 2018 02:45 AM

    Thnx Danny.

    The approach worked out fine for me.

     

    Regards

    Yugain