Service Virtualization

Expand all | Collapse all

Magic Dates Format Clarification

Jump to Best Answer
  • 1.  Magic Dates Format Clarification

    Posted 01-29-2018 01:22 PM

    Hi all,

     

    I have a date in my VS response that is in the following format:

     

    2017-12-20T12:59      i.e.    yyyy-MM-dd'T'hh:MM    format

     

    I want this date value to be four hours and 35 mins ahead of the incoming request time.

     

    How do I specify it in my response using doDateDeltaFromCurrent?

     

    Joel Nesmith, abrsh01, gadpr08

     

    Thanks in advance

    Mallik



  • 2.  Re: Magic Dates Format Clarification
    Best Answer

    Posted 01-29-2018 03:03 PM

    Hi Mallik,

     

    {{=doDateDeltaFromCurrent("yyyy-MM-dd:hh:mm:ss","270M");/*2012-08-14:09:01:03*/}} can try this and in place of offset mention what is required

     

    Best Regards,

    Venkat Yedida

    +46768790331



  • 3.  Re: Magic Dates Format Clarification

    Posted 02-01-2018 12:29 PM

    Hi,

     

    I have so many different dateTime formats, only date formats and only time formats, in the response. So, I gave up the method of using doDateDelta in response.

     

    Now, I'm trying to use match script to create my required properties, and use these properties in my matching VS response wherever required.

    I tried the following but it doesnt work. I'm not seeing any property being set in Events tab after the execution. Also, I'm using this property "Abc" in response, but it's not getting substituted to its value.

     

    string schedDepDateTime1 = "2008";
    testExec.setStateValue("Abc", schedDepDateTime1);

     

    How do i do this?

     

    Thanks,

    Mallik



  • 4.  Re: Magic Dates Format Clarification

    Posted 01-30-2018 12:44 PM

    Provided Sample VSM/ SI in  Support Ticket  00948139. 

     

    Thanks

     

    Shiney 



  • 5.  Re: Magic Dates Format Clarification

    Posted 02-01-2018 01:10 PM

    Hi,

     

    I have so many different dateTime formats, only date formats and only time formats, in the response. So, I gave up the method of using doDateDelta in response.

     

    Now, I'm trying to use match script to create my required properties, and use these properties in my matching VS response wherever required.

    I tried the following but it doesnt work. I'm not seeing any property being set in Events tab after the execution. Also, I'm using this property "Abc" in response, but it's not getting substituted to its value.

     

    string schedDepDateTime1 = "2008";
    testExec.setStateValue("Abc", schedDepDateTime1);

     

    How do i do this?

     

    Thanks,

    Mallik



  • 6.  Re: Magic Dates Format Clarification

    Posted 02-01-2018 04:08 PM

    If the 4 hrs, 35 minutes is based on the date/time the transaction hits the service, I would recommend adding a date/time filter in the VSI selection step in the model rather than trying to do it in a Matches script.

    Then in the VSI, use {{Abc}} as the magic string property.

    If the time is based off one or more of the dates on the incoming request payload, you might need to develop a script that gets the value of the date/time, formats it, and then adds the time. After doing this, you can set it in "Abc" for magic stringing.

    The challenge in doing this in the Matches Script is that the VSI may not be firing on transaction where you placed the script and you don't want to copy / paste Matches scripts into other transactions.

    If the particular response does not use {{Abc}} then no date will be included in the response.



  • 7.  Re: Magic Dates Format Clarification

    Posted 02-02-2018 09:57 AM

    Thanks Jo,

     

    I was able to write the following script in match script section and get my desired results now:

     

    import java.text.SimpleDateFormat;
    import java.text.DateFormat;
    import java.util.Date;

     

    public static final long HOUR = 3600*1000; // in milli-seconds.

    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm");
    Date currentDateTime = new Date();

     

    // For Flight1 in search results
    Date schedDepDateTime1 = new Date(currentDateTime.getTime() + 4 * HOUR);
    Date schedArrDateTime1 = new Date(currentDateTime.getTime() + 5 * HOUR);
    String schedDepDate1 = dateFormat.format(schedDepDateTime1).substring(0,10);
    String schedDepTime1 = dateFormat.format(schedDepDateTime1).substring(11);

    testExec.setStateValue("SchedDepDateTime1", dateFormat.format(schedDepDateTime1));
    testExec.setStateValue("SchedArrDateTime1", dateFormat.format(schedArrDateTime1));
    testExec.setStateValue("SchedDepDate1", schedDepDate1);
    testExec.setStateValue("SchedDepTime1", schedDepTime1);

     

    And then, I'm using these properties in my VS response.



  • 8.  Re: Magic Dates Format Clarification

    Posted 02-02-2018 07:09 PM

    OK, good to know, and it seems to work for your example. 

    However,... 

    What is Match Script doing with the incomingRequest, sourceRequest, and after setting the date, does the code execute defaultMatcher.matches(); ?

     

    My fear about using the Match Script for non-matching logic is that

    a) defects are hard to find if you don't think to look in the Match Script in the VSI and

    b) one can insert unexpected behavior without knowing it which results in a) or response selection issues.

     

    Anyone using Match Scripts MUST recognize that Match Scripts pay no attention to the match style tolerance and argument comparison operators. Control in the Match Script is ultimately the responsibility of the logic in the script. Errors in Match Script logic can cause erroneous responses (e.g., responses that do not truly match the incoming request) to be sent to the consumer.