Skip to content

Commit 416572e

Browse files
committed
fixes networknt#522 synch the official test suite for draft v4 from schema.org
1 parent 48cba95 commit 416572e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+5303
-3017
lines changed

src/test/java/com/networknt/schema/UriMappingTest.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,15 @@ public class UriMappingTest {
4949
@Test
5050
public void testBuilderUriMappingUri() throws IOException {
5151
URL mappings = ClasspathURLFactory.convert(
52-
this.classpathURLFactory.create("resource:draft4/uri_mapping/uri-mapping.json"));
52+
this.classpathURLFactory.create("resource:draft4/extra/uri_mapping/uri-mapping.json"));
5353
JsonMetaSchema draftV4 = JsonMetaSchema.getV4();
5454
Builder builder = JsonSchemaFactory.builder()
5555
.defaultMetaSchemaURI(draftV4.getUri())
5656
.addMetaSchema(draftV4)
5757
.addUriMappings(getUriMappingsFromUrl(mappings));
5858
JsonSchemaFactory instance = builder.build();
5959
JsonSchema schema = instance.getSchema(this.urlFactory.create(
60-
"https://raw.githubusercontent.com/networknt/json-schema-validator/master/src/test/resources/draft4/uri_mapping/uri-mapping.schema.json"));
60+
"https://raw.githubusercontent.com/networknt/json-schema-validator/master/src/test/resources/draft4/extra/uri_mapping/uri-mapping.schema.json"));
6161
assertEquals(0, schema.validate(mapper.readTree(mappings)).size());
6262
}
6363

@@ -88,7 +88,7 @@ public void testBuilderExampleMappings() throws IOException {
8888
fail("Unexpected exception thrown");
8989
}
9090
URL mappings = ClasspathURLFactory.convert(
91-
this.classpathURLFactory.create("resource:draft4/uri_mapping/invalid-schema-uri.json"));
91+
this.classpathURLFactory.create("resource:draft4/extra/uri_mapping/invalid-schema-uri.json"));
9292
JsonMetaSchema draftV4 = JsonMetaSchema.getV4();
9393
Builder builder = JsonSchemaFactory.builder()
9494
.defaultMetaSchemaURI(draftV4.getUri())
@@ -109,11 +109,11 @@ public void testBuilderExampleMappings() throws IOException {
109109
public void testValidatorConfigUriMappingUri() throws IOException {
110110
JsonSchemaFactory instance = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V4);
111111
URL mappings = ClasspathURLFactory.convert(
112-
this.classpathURLFactory.create("resource:draft4/uri_mapping/uri-mapping.json"));
112+
this.classpathURLFactory.create("resource:draft4/extra/uri_mapping/uri-mapping.json"));
113113
SchemaValidatorsConfig config = new SchemaValidatorsConfig();
114114
config.setUriMappings(getUriMappingsFromUrl(mappings));
115115
JsonSchema schema = instance.getSchema(this.urlFactory.create(
116-
"https://raw.githubusercontent.com/networknt/json-schema-validator/master/src/test/resources/draft4/uri_mapping/uri-mapping.schema.json"),
116+
"https://raw.githubusercontent.com/networknt/json-schema-validator/master/src/test/resources/draft4/extra/uri_mapping/uri-mapping.schema.json"),
117117
config);
118118
assertEquals(0, schema.validate(mapper.readTree(mappings)).size());
119119
}
@@ -146,7 +146,7 @@ public void testValidatorConfigExampleMappings() throws IOException {
146146
fail("Unexpected exception thrown");
147147
}
148148
URL mappings = ClasspathURLFactory.convert(
149-
this.classpathURLFactory.create("resource:draft4/uri_mapping/invalid-schema-uri.json"));
149+
this.classpathURLFactory.create("resource:draft4/extra/uri_mapping/invalid-schema-uri.json"));
150150
config.setUriMappings(getUriMappingsFromUrl(mappings));
151151
JsonSchema schema = instance.getSchema(example, config);
152152
assertEquals(0, schema.validate(mapper.createObjectNode()).size());
@@ -156,10 +156,10 @@ public void testValidatorConfigExampleMappings() throws IOException {
156156
public void testMappingsForRef() throws IOException {
157157
JsonSchemaFactory instance = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V4);
158158
URL mappings = ClasspathURLFactory.convert(
159-
this.classpathURLFactory.create("resource:draft4/uri_mapping/schema-with-ref-mapping.json"));
159+
this.classpathURLFactory.create("resource:draft4/extra/uri_mapping/schema-with-ref-mapping.json"));
160160
SchemaValidatorsConfig config = new SchemaValidatorsConfig();
161161
config.setUriMappings(getUriMappingsFromUrl(mappings));
162-
JsonSchema schema = instance.getSchema(this.classpathURLFactory.create("resource:draft4/uri_mapping/schema-with-ref.json"),
162+
JsonSchema schema = instance.getSchema(this.classpathURLFactory.create("resource:draft4/extra/uri_mapping/schema-with-ref.json"),
163163
config);
164164
assertEquals(0, schema.validate(mapper.readTree("[]")).size());
165165
}

src/test/java/com/networknt/schema/V4JsonSchemaTest.java

Lines changed: 74 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import com.fasterxml.jackson.databind.JsonNode;
2020
import com.fasterxml.jackson.databind.ObjectMapper;
21+
import org.junit.jupiter.api.Disabled;
2122
import org.junit.jupiter.api.Test;
2223

2324
import java.io.IOException;
@@ -40,13 +41,51 @@ public void testLoadingWithId() throws Exception {
4041
JsonSchema schema = factory.getSchema(schemaJson);
4142
}
4243

44+
@Test
45+
@Disabled
46+
public void testFormatDateTimeValidator() throws Exception {
47+
runTestFile("draft4/optional/format/date-time.json");
48+
}
49+
50+
@Test
51+
public void testFormatEmailValidator() throws Exception {
52+
runTestFile("draft4/optional/format/email.json");
53+
}
54+
55+
@Test
56+
public void testFormatHostnameValidator() throws Exception {
57+
runTestFile("draft4/optional/format/hostname.json");
58+
}
59+
60+
@Test
61+
@Disabled
62+
public void testFormatIpv4Validator() throws Exception {
63+
runTestFile("draft4/optional/format/ipv4.json");
64+
}
65+
66+
@Test
67+
@Disabled
68+
public void testFormatIpv6Validator() throws Exception {
69+
runTestFile("draft4/optional/format/ipv6.json");
70+
}
71+
72+
@Test
73+
public void testFormatUnknownValidator() throws Exception {
74+
runTestFile("draft4/optional/format/unknown.json");
75+
}
76+
77+
@Test
78+
public void testFormatUriValidator() throws Exception {
79+
runTestFile("draft4/optional/format/uri.json");
80+
}
81+
4382
@Test
4483
public void testBignumValidator() throws Exception {
4584
runTestFile("draft4/optional/bignum.json");
4685
}
4786

4887
@Test
49-
public void testFormatValidator() throws Exception {
88+
public void testOptionalFormatValidator() throws Exception {
5089
runTestFile("draft4/optional/format.json");
5190
}
5291

@@ -55,6 +94,16 @@ public void testComplexSchema() throws Exception {
5594
runTestFile("draft4/optional/complex.json");
5695
}
5796

97+
@Test
98+
public void testFloatOverflowValidator() throws Exception {
99+
runTestFile("draft4/optional/float-overflow.json");
100+
}
101+
102+
@Test
103+
public void testNonBmpRegexValidator() throws Exception {
104+
runTestFile("draft4/optional/non-bmp-regex.json");
105+
}
106+
58107
@Test
59108
public void testZeroTerminatedFloatsValidator() throws Exception {
60109
runTestFile("draft4/optional/zeroTerminatedFloats.json");
@@ -100,6 +149,22 @@ public void testEnumValidator() throws Exception {
100149
runTestFile("draft4/enum.json");
101150
}
102151

152+
@Test
153+
public void testFormatValidator() throws Exception {
154+
runTestFile("draft4/format.json");
155+
}
156+
157+
@Test
158+
@Disabled
159+
public void testIdValidator() throws Exception {
160+
runTestFile("draft4/id.json");
161+
}
162+
163+
@Test
164+
public void testInfiniteLoopDetectionValidator() throws Exception {
165+
runTestFile("draft4/infinite-loop-detection.json");
166+
}
167+
103168
@Test
104169
public void testItemsValidator() throws Exception {
105170
runTestFile("draft4/items.json");
@@ -207,7 +272,7 @@ public void testTypeValidator() throws Exception {
207272

208273
@Test
209274
public void testUnionTypeValidator() throws Exception {
210-
runTestFile("draft4/union_type.json");
275+
runTestFile("draft4/extra/union_type.json");
211276
}
212277

213278
@Test
@@ -222,17 +287,17 @@ public void testEnumObject() throws Exception {
222287

223288
@Test
224289
public void testIdSchemaWithUrl() throws Exception {
225-
runTestFile("draft4/property.json");
290+
runTestFile("draft4/extra/property.json");
226291
}
227292

228293
@Test
229294
public void testSchemaFromClasspath() throws Exception {
230-
runTestFile("draft4/classpath/schema.json");
295+
runTestFile("draft4/extra/classpath/schema.json");
231296
}
232297

233298
@Test
234299
public void testUUIDValidator() throws Exception {
235-
runTestFile("draft4/uuid.json");
300+
runTestFile("draft4/extra/uuid.json");
236301
}
237302

238303
/**
@@ -241,7 +306,7 @@ public void testUUIDValidator() throws Exception {
241306
@Test
242307
public void testFailFast_AllErrors() throws IOException {
243308
try {
244-
validateFailingFastSchemaFor("product.schema.json", "product-all-errors-data.json");
309+
validateFailingFastSchemaFor("extra/product/product.schema.json", "extra/product/product-all-errors-data.json");
245310
fail("Exception must be thrown");
246311
} catch (JsonSchemaException e) {
247312
final Set<ValidationMessage> messages = e.getValidationMessages();
@@ -255,7 +320,7 @@ public void testFailFast_AllErrors() throws IOException {
255320
@Test
256321
public void testFailFast_OneErrors() throws IOException {
257322
try {
258-
validateFailingFastSchemaFor("product.schema.json", "product-one-error-data.json");
323+
validateFailingFastSchemaFor("extra/product/product.schema.json", "extra/product/product-one-error-data.json");
259324
fail("Exception must be thrown");
260325
} catch (JsonSchemaException e) {
261326
final Set<ValidationMessage> messages = e.getValidationMessages();
@@ -269,7 +334,7 @@ public void testFailFast_OneErrors() throws IOException {
269334
@Test
270335
public void testFailFast_TwoErrors() throws IOException {
271336
try {
272-
validateFailingFastSchemaFor("product.schema.json", "product-two-errors-data.json");
337+
validateFailingFastSchemaFor("extra/product/product.schema.json", "extra/product/product-two-errors-data.json");
273338
fail("Exception must be thrown");
274339
} catch (JsonSchemaException e) {
275340
final Set<ValidationMessage> messages = e.getValidationMessages();
@@ -283,7 +348,7 @@ public void testFailFast_TwoErrors() throws IOException {
283348
@Test
284349
public void testFailFast_NoErrors() throws IOException {
285350
try {
286-
final Set<ValidationMessage> messages = validateFailingFastSchemaFor("product.schema.json", "product-no-errors-data.json");
351+
final Set<ValidationMessage> messages = validateFailingFastSchemaFor("extra/product/product.schema.json", "extra/product/product-no-errors-data.json");
287352
assertTrue(messages.isEmpty());
288353
} catch (JsonSchemaException e) {
289354
fail("Must not get an errors");

0 commit comments

Comments
 (0)