Forum Discussion

BMCIM's avatar
BMCIM
Occasional Contributor
7 years ago

Date Assertions

Hi

 

My JSON response (rest request) returns a date.  I need to verify the date returned is less than 1/1/1969.

 

How do I do this?

 

All replies are much appreciated.

 

Thanks in advance.

1 Reply

  • PaulMS's avatar
    PaulMS
    Super Contributor

    You can use a script assertion, just change the jsonpath and format as needed.

     

    jsonpath = '$..path[0]'
    format = 'M/d/yyyy'
    
    import static com.jayway.jsonpath.JsonPath.parse
    response = parse(messageExchange.response.contentAsString)
    result = response.read(jsonpath)
    date = Date.parse(format, result)
    assert date < Date.parse(format, '1/1/1969')