|
|
@@ -51,6 +51,7 @@ public class SchemaTest {
|
|
|
|
|
|
private Schema getNumberSchema() {
|
|
|
Map<String, Tester> tests = new HashMap<>();
|
|
|
+ tests.put("type", TypeTester.fromType("number"));
|
|
|
tests.put("minimum", new NumberTester(d -> d >= 0.0));
|
|
|
tests.put("multipleOf", new NumberTester(d -> Math.abs(d % 0.25) < 1E-7));
|
|
|
tests.put("exclusiveMaximum", new NumberTester(d -> d < 1.0));
|
|
|
@@ -59,6 +60,7 @@ public class SchemaTest {
|
|
|
|
|
|
private Schema getStringSchema() {
|
|
|
Map<String, Tester> tests = new HashMap<>();
|
|
|
+ tests.put("type", TypeTester.fromType("string"));
|
|
|
tests.put("maxLength", new SizeTester(STRING, s -> s <= 30));
|
|
|
tests.put("minLength", new SizeTester(STRING, s -> s >= 10));
|
|
|
tests.put("pattern", j -> j.asText().matches("^https://.*"));
|
|
|
@@ -68,6 +70,7 @@ public class SchemaTest {
|
|
|
|
|
|
private Schema getArraySchema() {
|
|
|
Map<String, Tester> tests = new HashMap<>();
|
|
|
+ tests.put("type", TypeTester.fromType("array"));
|
|
|
tests.put("maxItems", new SizeTester(ARRAY, s -> s <= 3));
|
|
|
tests.put("minItems", new SizeTester(ARRAY, s -> s >= 1));
|
|
|
tests.put("uniqueItems", new UniqueItemTester());
|
|
|
@@ -77,6 +80,7 @@ public class SchemaTest {
|
|
|
|
|
|
private Schema getObjectSchema() {
|
|
|
Map<String, Tester> tests = new HashMap<>();
|
|
|
+ tests.put("type", TypeTester.fromType("object"));
|
|
|
tests.put("maxProperties", new SizeTester(OBJECT, s -> s <= 3));
|
|
|
tests.put("minProperties", new SizeTester(OBJECT, s -> s >= 2));
|
|
|
tests.put("required", json -> json.has("string"));
|
|
|
@@ -86,9 +90,11 @@ public class SchemaTest {
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
- public void testRejectsWrongType() {
|
|
|
+ public void testRejectsWrongTypeOnlyIfHasTypeArg() {
|
|
|
Map<String, Tester> tests = new HashMap<>();
|
|
|
- tests.put("example", FixedTester.ACCEPT);
|
|
|
+ tests.put("minProperties", FixedTester.REJECT);
|
|
|
+ assertThat(new Schema(tests), accepts(NullNode.getInstance()));
|
|
|
+ tests.put("type", TypeTester.fromType("string"));
|
|
|
assertThat(new Schema(tests), not(accepts(NullNode.getInstance())));
|
|
|
}
|
|
|
|