Service Virtualization

Expand all | Collapse all

Match specific response in vsi against todays date

Jump to Best Answer
  • 1.  Match specific response in vsi against todays date

    Posted 03-22-2018 05:02 AM

    Hi, 

     

    I am trying to match a specific response for a transaction when one of the request parameters is equal to todays date.
    I have tried a property expression like  = doDateDeltaFromCurrent("yyyy-MM-dd","0H"), I have also tried this as a standard = comparison operator. I also tried the following match script but it never seems to get invoked (as far as i can tell):

     

    com.itko.util.ParameterList incomingValue = incomingRequest.getArguments();
    String requestdate = incomingValue.getParameterValue("request_enquiryEndDate");
    String today = doDateDeltaFromCurrent("yyyy-MM-dd","0H");

    if(requestdate.equals.today) {
    return true;
    }

    return false;

    It feels like this should be an easy thing to do but I just cant make it work!! Any ideas?



  • 2.  Re: Match specific response in vsi against todays date
    Best Answer

    Posted 03-22-2018 12:32 PM

    Try this.. 

     

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

     

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    String todate = sdf.format( new Date());
    String incomingDate = "2018-03-22"; // incomingRequest.getArguments().get("request_enquiryEndDate");

     

    if(todate.equals(incomingDate)){
       return true;
    }

    return false;



  • 3.  Re: Match specific response in vsi against todays date

    Posted 03-23-2018 04:34 AM

    Thanks,

     

    That works perfectly if i leave the date hardcoded but if I use:

     

    String incomingDate = incomingRequest.getArguments().get("request_enquiryEndDate");

    Then it doesnt work, so I guess its having trouble getting the parameter from the request, maybe it needs converting ot a string first?



  • 4.  Re: Match specific response in vsi against todays date

    Posted 03-23-2018 09:20 AM

    Hi Rob,

     

    You can try the below. I'm not really sure about the magic dates in the match script. 

     

    import java.util.*;
    import java.text.*;
    String incomingValue = incomingRequest.getArguments().get("request_enquiryEndDate");

    Date date = new Date();
    SimpleDateFormat dmyFormat = new SimpleDateFormat("yyyy-MM-dd");
    String strDate = dmyFormat.format(date);

    if(incomingValue.equalsIgnoreCase(strDate)) {
    // true means these arguments match
    return true;
    }

    // false means no match
    return false;

     

    regards,

    Shivakumar.



  • 5.  Re: Match specific response in vsi against todays date

    Posted 03-23-2018 11:03 AM

    Return type of incomingRequest.getArguments().get("request_enquiryEndDate"); is string by default. make sure that the key request_enquiryEndDate is correct (same as request argument name).