|
30 | 30 | import java.util.HashMap; |
31 | 31 | import java.util.List; |
32 | 32 | import java.util.Map; |
| 33 | +import java.util.TimeZone; |
33 | 34 |
|
34 | 35 | import static com.jayway.jsonpath.JsonPath.read; |
35 | 36 | import static org.hamcrest.CoreMatchers.containsString; |
36 | 37 | import static org.hamcrest.CoreMatchers.is; |
37 | 38 | import static org.hamcrest.CoreMatchers.not; |
38 | 39 | import static org.jsmart.zerocode.core.utils.HelperJsonUtils.readJsonPath; |
| 40 | +import static org.jsmart.zerocode.core.utils.DateTimeUtils.parseLocalDateTime; |
39 | 41 | import static org.jsmart.zerocode.core.utils.SmartUtils.checkDigNeeded; |
40 | 42 | import static org.jsmart.zerocode.core.utils.SmartUtils.readJsonAsString; |
41 | 43 | import static org.jsmart.zerocode.core.utils.TokenUtils.getTestCaseTokens; |
@@ -977,6 +979,46 @@ public void testDateAfterBefore_both() throws Exception { |
977 | 979 | assertThat(failedReports.size(), is(0)); |
978 | 980 | } |
979 | 981 |
|
| 982 | + @Test |
| 983 | + public void testDateAfterBefore_withTimeZoneOffsetsAndHttpDate() throws Exception { |
| 984 | + TimeZone defaultTimeZone = TimeZone.getDefault(); |
| 985 | + TimeZone.setDefault(TimeZone.getTimeZone("UTC")); |
| 986 | + try { |
| 987 | + String resolvedAssertions = |
| 988 | + "{\n" |
| 989 | + + " \"status\": 200,\n" |
| 990 | + + " \"body\": {\n" |
| 991 | + + " \"projectDetails\": {\n" |
| 992 | + + " \"startDateTime\": \"$LOCAL.DATETIME.BEFORE:2019-06-15T10:00:00.000Z\",\n" |
| 993 | + + " \"endDateTime\": \"$LOCAL.DATETIME.AFTER:2019-06-15T10:00:00.000Z\",\n" |
| 994 | + + " \"lastModified\": \"$LOCAL.DATETIME.BEFORE:Sat, 06 Jul 2019 17:07:15 GMT\"\n" |
| 995 | + + " }\n" |
| 996 | + + " }\n" |
| 997 | + + "}"; |
| 998 | + |
| 999 | + List<JsonAsserter> asserters = jsonPreProcessor.createJsonAsserters(resolvedAssertions); |
| 1000 | + assertThat(asserters.size(), is(4)); |
| 1001 | + |
| 1002 | + String mockTestResponse = |
| 1003 | + "{\n" |
| 1004 | + + " \"status\": 200,\n" |
| 1005 | + + " \"body\": {\n" |
| 1006 | + + " \"projectDetails\": {\n" |
| 1007 | + + " \"startDateTime\": \"2019-06-15T11:30:00.000+02:00\",\n" |
| 1008 | + + " \"endDateTime\": \"2019-06-15T12:30:00.000+02:00\",\n" |
| 1009 | + + " \"lastModified\": \"Sat, 06 Jul 2019 16:07:15 GMT\"\n" |
| 1010 | + + " }\n" |
| 1011 | + + " }\n" |
| 1012 | + + "}"; |
| 1013 | + |
| 1014 | + List<FieldAssertionMatcher> failedReports = |
| 1015 | + jsonPreProcessor.assertAllAndReturnFailed(asserters, mockTestResponse); |
| 1016 | + assertThat(failedReports.size(), is(0)); |
| 1017 | + } finally { |
| 1018 | + TimeZone.setDefault(defaultTimeZone); |
| 1019 | + } |
| 1020 | + } |
| 1021 | + |
980 | 1022 | @Test |
981 | 1023 | public void testDateAfterBefore_fail_both() throws Exception { |
982 | 1024 | ScenarioSpec scenarioSpec = |
@@ -1018,12 +1060,12 @@ public void testDateAfterBefore_fail_both() throws Exception { |
1018 | 1060 | failedReports.get(0).toString(), |
1019 | 1061 | is( |
1020 | 1062 | "Assertion jsonPath '$.body.projectDetails.startDateTime' with actual value '2017-04-14T11:49:56.000Z' " |
1021 | | - + "did not match the expected value 'Date Before:2016-09-14T09:49:34'")); |
| 1063 | + + "did not match the expected value 'Date Before:" + parseLocalDateTime("2016-09-14T09:49:34.000Z") + "'")); |
1022 | 1064 | assertThat( |
1023 | 1065 | failedReports.get(1).toString(), |
1024 | 1066 | is( |
1025 | 1067 | "Assertion jsonPath '$.body.projectDetails.endDateTime' with actual value '2018-11-12T09:39:34.000Z' " |
1026 | | - + "did not match the expected value 'Date After:2019-09-14T09:49:34'")); |
| 1068 | + + "did not match the expected value 'Date After:" + parseLocalDateTime("2019-09-14T09:49:34.000Z") + "'")); |
1027 | 1069 | } |
1028 | 1070 |
|
1029 | 1071 | @Test |
@@ -1063,7 +1105,7 @@ public void testDateAfterBefore_fail_afterSameDate() throws Exception { |
1063 | 1105 | failedReports.get(0).toString(), |
1064 | 1106 | is( |
1065 | 1107 | "Assertion jsonPath '$.body.projectDetails.startDateTime' with actual value '2015-09-14T09:49:34.000Z' " |
1066 | | - + "did not match the expected value 'Date After:2015-09-14T09:49:34'")); |
| 1108 | + + "did not match the expected value 'Date After:" + parseLocalDateTime("2015-09-14T09:49:34.000Z") + "'")); |
1067 | 1109 | } |
1068 | 1110 |
|
1069 | 1111 | @Test |
@@ -1103,7 +1145,7 @@ public void testDateAfterBefore_fail_beforeSameDate() throws Exception { |
1103 | 1145 | failedReports.get(0).toString(), |
1104 | 1146 | is( |
1105 | 1147 | "Assertion jsonPath '$.body.projectDetails.startDateTime' with actual value '2015-09-14T09:49:34.000Z' " |
1106 | | - + "did not match the expected value 'Date Before:2015-09-14T09:49:34'")); |
| 1148 | + + "did not match the expected value 'Date Before:" + parseLocalDateTime("2015-09-14T09:49:34.000Z") + "'")); |
1107 | 1149 | } |
1108 | 1150 |
|
1109 | 1151 | @Test |
|
0 commit comments