|
1 | 1 | package com.networknt.schema; |
2 | 2 |
|
3 | | -import com.fasterxml.jackson.databind.ObjectMapper; |
4 | | -import com.networknt.schema.dialect.BasicDialectRegistry; |
5 | | -import com.networknt.schema.dialect.Dialect; |
6 | | -import com.networknt.schema.dialect.Dialects; |
7 | | - |
8 | | -import org.junit.jupiter.api.Test; |
| 3 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
9 | 4 |
|
10 | 5 | import java.io.IOException; |
11 | 6 | import java.io.InputStream; |
12 | | -import java.net.URL; |
13 | 7 |
|
14 | | -import static org.junit.jupiter.api.Assertions.assertEquals; |
| 8 | +import org.junit.jupiter.api.Test; |
| 9 | + |
| 10 | +import com.fasterxml.jackson.databind.ObjectMapper; |
15 | 11 |
|
16 | | -class UrnTest |
17 | | -{ |
18 | | - private final ObjectMapper mapper = new ObjectMapper(); |
| 12 | +class UrnTest { |
| 13 | + private final ObjectMapper mapper = new ObjectMapper(); |
19 | 14 |
|
20 | | - /** |
21 | | - * Validate that a JSON URI Mapping file containing the URI Mapping schema is |
22 | | - * schema valid. |
23 | | - * |
24 | | - * @throws IOException if unable to parse the mapping file |
25 | | - */ |
26 | | - @Test |
27 | | - void testURNToURI() throws Exception { |
28 | | - InputStream urlTestData = UrnTest.class.getResourceAsStream("/draft7/urn/test.json"); |
29 | | - InputStream is = null; |
30 | | - try { |
31 | | - is = new URL("https://raw.githubusercontent.com/francesc79/json-schema-validator/feature/urn-management/src/test/resources/draft7/urn/urn.schema.json").openStream(); |
32 | | - Dialect draftV7 = Dialects.getDraft7(); |
33 | | - SchemaRegistry.Builder builder = SchemaRegistry.builder() |
34 | | - .defaultDialectId(draftV7.getId()) |
35 | | - .dialectRegistry(new BasicDialectRegistry(draftV7)) |
36 | | - .schemaIdResolvers(schemaIdResolvers -> schemaIdResolvers.add(value -> AbsoluteIri.of(String.format("resource:draft7/urn/%s.schema.json", value.toString()))) |
37 | | - ); |
38 | | - SchemaRegistry instance = builder.build(); |
39 | | - Schema schema = instance.getSchema(is); |
40 | | - assertEquals(0, schema.validate(mapper.readTree(urlTestData)).size()); |
41 | | - } catch( Exception e) { |
42 | | - e.printStackTrace(); |
43 | | - } |
44 | | - finally { |
45 | | - if (is != null) { |
46 | | - is.close(); |
47 | | - } |
| 15 | + /** |
| 16 | + * Validate that a JSON URI Mapping file containing the URI Mapping schema is |
| 17 | + * schema valid. |
| 18 | + * |
| 19 | + * @throws IOException if unable to parse the mapping file |
| 20 | + */ |
| 21 | + @Test |
| 22 | + void testURNToURI() throws Exception { |
| 23 | + InputStream urlTestData = UrnTest.class.getResourceAsStream("/draft7/urn/test.json"); |
| 24 | + SchemaRegistry schemaRegistry = SchemaRegistry.withDefaultDialect(SpecificationVersion.DRAFT_7, |
| 25 | + builder -> builder.schemaIdResolvers(schemaIdResolvers -> schemaIdResolvers.add(value -> { |
| 26 | + return AbsoluteIri.of(String.format("%s.schema.json", value.toString())); |
| 27 | + }))); |
| 28 | + Schema schema = schemaRegistry.getSchema(SchemaLocation.of("classpath:/draft7/urn/urn")); |
| 29 | + assertEquals(0, schema.validate(mapper.readTree(urlTestData)).size()); |
48 | 30 | } |
49 | | - } |
50 | 31 | } |
0 commit comments