@@ -35,11 +35,14 @@ public class MinimumValidatorTest {
3535
3636 private static ObjectMapper mapper ;
3737 private static ObjectMapper bigDecimalMapper ;
38+ private static ObjectMapper bigIntegerMapper ;
3839
3940 @ Before
4041 public void setUp () {
4142 mapper = new ObjectMapper ();
4243 bigDecimalMapper = new ObjectMapper ().enable (DeserializationFeature .USE_BIG_DECIMAL_FOR_FLOATS );
44+ bigIntegerMapper = new ObjectMapper ().enable (DeserializationFeature .USE_BIG_INTEGER_FOR_INTS );
45+
4346 }
4447
4548 @ Test
@@ -219,6 +222,165 @@ public void longValueOverflowWithInverseEffect() throws IOException {
219222 assertTrue (format ("Expecing no validation errors as minimum %s is lesser than value %s" , minimum , value ), messages .isEmpty ());
220223 }
221224 }
225+ @ Test
226+ public void BigIntegerBothWithinLongRangePositive () throws IOException {
227+ String [][] values = {
228+ // minimum, value
229+ {"10" , "20" }
230+ };
231+
232+ for (String [] aTestCycle : values ) {
233+ String minimum = aTestCycle [0 ];
234+ String value = aTestCycle [1 ];
235+ String schema = format ("{ \" $schema\" :\" http://json-schema.org/draft-04/schema#\" , \" type\" : \" integer\" , \" minimum\" : %s, \" exclusiveMinimum\" : true}" , minimum );
236+
237+ JsonSchema v = factory .getSchema (mapper .readTree (schema ));
238+ JsonNode doc = bigIntegerMapper .readTree (value );
239+
240+ Set <ValidationMessage > messages = v .validate (doc );
241+ assertTrue (format ("Expecting no validation errors as minimum %s is lesser than value %s" , minimum , value ), messages .isEmpty ());
242+ }
243+ }
244+
245+ @ Test
246+ public void BigIntegerBothWithinLongRangeNegative () throws IOException {
247+ String [][] values = {
248+ // minimum, value
249+ {"20" , "10" }
250+ };
251+
252+ for (String [] aTestCycle : values ) {
253+ String minimum = aTestCycle [0 ];
254+ String value = aTestCycle [1 ];
255+ String schema = format ("{ \" $schema\" :\" http://json-schema.org/draft-04/schema#\" , \" type\" : \" integer\" , \" minimum\" : %s, \" exclusiveMinimum\" : true}" , minimum );
256+
257+ JsonSchema v = factory .getSchema (mapper .readTree (schema ));
258+ JsonNode doc = bigIntegerMapper .readTree (value );
259+
260+ Set <ValidationMessage > messages = v .validate (doc );
261+ assertFalse (format ("Expecting validation error with minimum %s and value %s" , minimum , value ), messages .isEmpty ());
262+ }
263+ }
264+
265+ @ Test
266+ public void BigIntegerOverflow () throws IOException {
267+ String [][] values = {
268+ // minimum, value
269+ {"-9223372036854775807" , "-9223372036854775809" }
270+ };
271+
272+ for (String [] aTestCycle : values ) {
273+ String minimum = aTestCycle [0 ];
274+ String value = aTestCycle [1 ];
275+ String schema = format ("{ \" $schema\" :\" http://json-schema.org/draft-04/schema#\" , \" type\" : \" integer\" , \" minimum\" : %s, \" exclusiveMinimum\" : true}" , minimum );
276+
277+ JsonSchema v = factory .getSchema (mapper .readTree (schema ));
278+ JsonNode doc = bigIntegerMapper .readTree (value );
279+
280+ Set <ValidationMessage > messages = v .validate (doc );
281+ assertFalse (format ("Expecing validation error with minimum %s and value %s" , minimum , value ), messages .isEmpty ());
282+ }
283+ }
284+
285+ @ Test
286+ public void BigIntegerNotOverflow () throws IOException {
287+ String [][] values = {
288+ // minimum, value
289+ {"-9223372036854775809" , "-9223372036854775807" }
290+ };
291+
292+ for (String [] aTestCycle : values ) {
293+ String minimum = aTestCycle [0 ];
294+ String value = aTestCycle [1 ];
295+ String schema = format ("{ \" $schema\" :\" http://json-schema.org/draft-04/schema#\" , \" type\" : \" integer\" , \" minimum\" : %s, \" exclusiveMinimum\" : true}" , minimum );
296+
297+ JsonSchema v = factory .getSchema (mapper .readTree (schema ));
298+ JsonNode doc = bigIntegerMapper .readTree (value );
299+
300+ Set <ValidationMessage > messages = v .validate (doc );
301+ assertTrue (format ("Expecting no validation errors as minimum %s is lesser than value %s" , minimum , value ), messages .isEmpty ());
302+ }
303+ }
304+
305+ @ Test
306+ public void BigIntegerBothAboveLongRangePositive () throws IOException {
307+ String [][] values = {
308+ // minimum, value
309+ {"-9223372036854775810" , "-9223372036854775809" }
310+ };
311+
312+ for (String [] aTestCycle : values ) {
313+ String minimum = aTestCycle [0 ];
314+ String value = aTestCycle [1 ];
315+ String schema = format ("{ \" $schema\" :\" http://json-schema.org/draft-04/schema#\" , \" type\" : \" integer\" , \" minimum\" : %s, \" exclusiveMinimum\" : true}" , minimum );
316+
317+ JsonSchema v = factory .getSchema (mapper .readTree (schema ));
318+ JsonNode doc = bigIntegerMapper .readTree (value );
319+
320+ Set <ValidationMessage > messages = v .validate (doc );
321+ assertTrue (format ("Expecting no validation errors as minimum %s is lesser than value %s" , minimum , value ), messages .isEmpty ());
322+ }
323+ }
324+
325+ @ Test
326+ public void BigIntegerBothAboveLongRangeNegative () throws IOException {
327+ String [][] values = {
328+ // minimum, value
329+ {"-9223372036854775809" , "-9223372036854775810" }
330+ };
331+
332+ for (String [] aTestCycle : values ) {
333+ String minimum = aTestCycle [0 ];
334+ String value = aTestCycle [1 ];
335+ String schema = format ("{ \" $schema\" :\" http://json-schema.org/draft-04/schema#\" , \" type\" : \" integer\" , \" minimum\" : %s, \" exclusiveMinimum\" : true}" , minimum );
336+
337+ JsonSchema v = factory .getSchema (mapper .readTree (schema ));
338+ JsonNode doc = bigIntegerMapper .readTree (value );
339+
340+ Set <ValidationMessage > messages = v .validate (doc );
341+ assertFalse (format ("Expecing validation error with minimum %s and value %s" , minimum , value ), messages .isEmpty ());
342+ }
343+ }
344+
345+ @ Test
346+ public void BigIntegerNotOverflowOnLongRangeEdge () throws IOException {
347+ String [][] values = {
348+ // minimum, value
349+ {"-9223372036854775808" , "-9223372036854775808" }
350+ };
351+
352+ for (String [] aTestCycle : values ) {
353+ String minimum = aTestCycle [0 ];
354+ String value = aTestCycle [1 ];
355+ String schema = format ("{ \" $schema\" :\" http://json-schema.org/draft-04/schema#\" , \" type\" : \" integer\" , \" minimum\" : %s, \" exclusiveMinimum\" : false}" , minimum );
356+
357+ JsonSchema v = factory .getSchema (mapper .readTree (schema ));
358+ JsonNode doc = bigIntegerMapper .readTree (value );
359+
360+ Set <ValidationMessage > messages = v .validate (doc );
361+ assertTrue (format ("Expecing no validation errors as minimum %s is lesser than value %s" , minimum , value ), messages .isEmpty ());
362+ }
363+ }
364+
365+ @ Test
366+ public void BigIntegerOverflowOnLongRangeEdge () throws IOException {
367+ String [][] values = {
368+ // minimum, value
369+ {"-9223372036854775809" , "-9223372036854775809" }
370+ };
371+
372+ for (String [] aTestCycle : values ) {
373+ String maximum = aTestCycle [0 ];
374+ String value = aTestCycle [1 ];
375+ String schema = format ("{ \" $schema\" :\" http://json-schema.org/draft-04/schema#\" , \" type\" : \" integer\" , \" maximum\" : %s, \" exclusiveMaximum\" : false}" , maximum );
376+
377+ JsonSchema v = factory .getSchema (mapper .readTree (schema ));
378+ JsonNode doc = bigIntegerMapper .readTree (value );
379+
380+ Set <ValidationMessage > messages = v .validate (doc );
381+ assertTrue (format ("Expecing no validation errors as maximum %s is greater than value %s" , maximum , value ), messages .isEmpty ());
382+ }
383+ }
222384}
223385
224386
0 commit comments