@@ -124,7 +124,7 @@ public void validate_shouldNotReturnAnErrorMessage_givenAFormatOfDateTimeAndAStr
124
124
125
125
@ Test
126
126
public void validate_shouldReturnAnErrorMessage_givenAFormatOfDateTimeAndAStringValueThatIsNotAValidIso8601DateTime () throws Exception {
127
- String invalidDateTime = "2011-May-10T165 :11:17z " ;
127
+ String invalidDateTime = "2011-05-44T11 :11:17Z " ;
128
128
SimpleTypeSchema schema = new SimpleTypeSchema ();
129
129
schema .setType (SimpleType .STRING );
130
130
schema .setFormat ("date-time" );
@@ -138,6 +138,22 @@ public void validate_shouldReturnAnErrorMessage_givenAFormatOfDateTimeAndAString
138
138
assertTrue (result .get (0 ).getMessage ().contains ("date-time" ));
139
139
}
140
140
141
+ @ Test
142
+ public void validate_shouldReturnAnErrorMessage_givenAFormatOfDateTimeAndAStringValueThatIsAnAlmostValidIso8601DateTime () throws Exception {
143
+ String invalidDateTime = "2011-May-10T165:11:17z" ;
144
+ SimpleTypeSchema schema = new SimpleTypeSchema ();
145
+ schema .setType (SimpleType .STRING );
146
+ schema .setFormat ("date-time" );
147
+ JsonNode nodeToValidate = new TextNode (invalidDateTime );
148
+
149
+ List <ErrorMessage > result = schema .validate (nodeToValidate );
150
+
151
+ assertEquals (1 , result .size ());
152
+ assertEquals ("" , result .get (0 ).getLocation ());
153
+ assertTrue (result .get (0 ).getMessage ().contains (invalidDateTime ));
154
+ assertTrue (result .get (0 ).getMessage ().contains ("date-time" ));
155
+ }
156
+
141
157
@ Test
142
158
public void setFormat_shouldThrowAnException_whenTypeIsNotStringAndFormatIsDateTime () throws Exception {
143
159
SimpleTypeSchema schema = new SimpleTypeSchema ();
@@ -178,6 +194,22 @@ public void validate_shouldReturnAnErrorMessage_givenAFormatOfDateAndAStringValu
178
194
assertTrue (result .get (0 ).getMessage ().contains ("date" ));
179
195
}
180
196
197
+ @ Test
198
+ public void validate_shouldReturnAnErrorMessage_givenAFormatOfDateAndAStringValueThatIsAlmostAValidDate () throws Exception {
199
+ String invalidDate = "2011-05-44" ;
200
+ SimpleTypeSchema schema = new SimpleTypeSchema ();
201
+ schema .setType (SimpleType .STRING );
202
+ schema .setFormat ("date" );
203
+ JsonNode nodeToValidate = new TextNode (invalidDate );
204
+
205
+ List <ErrorMessage > result = schema .validate (nodeToValidate );
206
+
207
+ assertEquals (1 , result .size ());
208
+ assertEquals ("" , result .get (0 ).getLocation ());
209
+ assertTrue ( result .get (0 ).getMessage ().contains (invalidDate ));
210
+ assertTrue (result .get (0 ).getMessage ().contains ("date" ));
211
+ }
212
+
181
213
@ Test
182
214
public void validate_shouldReturnAnErrorMessage_givenAFormatOfDateAndAStringValueThatIsAFullDateTime () throws Exception {
183
215
String invalidDate = "2011-05-10T11:47:16Z" ;
@@ -234,6 +266,22 @@ public void validate_shouldReturnAnErrorMessage_givenAFormatOfTimeAndAStringValu
234
266
assertTrue (result .get (0 ).getMessage ().contains ("time" ));
235
267
}
236
268
269
+ @ Test
270
+ public void validate_shouldReturnAnErrorMessage_givenAFormatOfTimeAndAStringValueThatIsAlmostAValidTime () throws Exception {
271
+ String invalidTime = "13:75:47" ;
272
+ SimpleTypeSchema schema = new SimpleTypeSchema ();
273
+ schema .setType (SimpleType .STRING );
274
+ schema .setFormat ("time" );
275
+ JsonNode nodeToValidate = new TextNode (invalidTime );
276
+
277
+ List <ErrorMessage > result = schema .validate (nodeToValidate );
278
+
279
+ assertEquals (1 , result .size ());
280
+ assertEquals ("" , result .get (0 ).getLocation ());
281
+ assertTrue (result .get (0 ).getMessage ().contains (invalidTime ));
282
+ assertTrue (result .get (0 ).getMessage ().contains ("time" ));
283
+ }
284
+
237
285
@ Test
238
286
public void validate_shouldReturnAnErrorMessage_givenAFormatOfTimeAndAStringValueThatHasExtraInformationAfterTheValidTime () throws Exception {
239
287
String invalidTime = "11:47:16-blah" ;
0 commit comments