Service Virtualization

 View Only
  • 1.  how to compare two dates ( received in xml request ) in match script ?

    Posted Aug 12, 2022 10:00 AM
    Hi,

    I trying to compare two dates which received in request(xml) in match script.
    But after running the test case, its showing exception on devtest portal as 'there is an exception occured in match script'
    Could anyone please tell what is wrong in below script?

    My match script :

    String firstDate = incomingrequest.getarguments.get(firstDate);
    String secondDate = incomingrequest.getarguments.get(secondDate);

    DateFormat formatter=new SimpleDateFormat(yyyy-mm-dd);
    Date first= formatter.parse(firstDate);
    Date second= formatter.parse(secondDate);
    if(first.after(second)){
        return true;
    }else {
       return false;
    }


  • 2.  RE: how to compare two dates ( received in xml request ) in match script ?

    Broadcom Employee
    Posted Aug 12, 2022 11:59 AM
    You need to import a couple of classes:
    import java.text.*;
    import java.util.Calendar;

    also you did not pass a correct string passed to SimpleDateFormat method:
    and replace
    DateFormat formatter=new SimpleDateFormat(yyyy-mm-dd);
    with 
    DateFormat formatter=new SimpleDateFormat("yyyy-mm-dd");

    also consider adding a clause to handle if the dates are blank or some other issue and then 
    return defaultMatcher.matches();



    ------------------------------
    Karl M.
    DevOps Capability Specialist
    Broadcom
    ------------------------------



  • 3.  RE: how to compare two dates ( received in xml request ) in match script ?

    Broadcom Employee
    Posted Aug 13, 2022 05:14 AM
    Hi,

    Also, I believe the getarguments is incorrect, it is a method call, from
    the top of my heard it should be:

    incomingrequest.getArguments().get("firstDate")


    Cheers,
    Danny

    --
    This electronic communication and the information and any files transmitted
    with it, or attached to it, are confidential and are intended solely for
    the use of the individual or entity to whom it is addressed and may contain
    information that is confidential, legally privileged, protected by privacy
    laws, or otherwise restricted from disclosure to anyone else. If you are
    not the intended recipient or the person responsible for delivering the
    e-mail to the intended recipient, you are hereby notified that any use,
    copying, distributing, dissemination, forwarding, printing, or copying of
    this e-mail is strictly prohibited. If you received this e-mail in error,
    please return the e-mail to the sender, delete it from your computer, and
    destroy any printed copy of it.




  • 4.  RE: how to compare two dates ( received in xml request ) in match script ?

    Posted Sep 29, 2022 12:31 PM
    Please let us know in case you are still facing any issues

    Thanks

    ------------------------------
    Regards,
    Vaibhav Jain
    Capgemini
    ------------------------------