Skip to content

Commit df888a8

Browse files
committed
Fix UrnTest
1 parent cde7ca8 commit df888a8

File tree

1 file changed

+21
-40
lines changed

1 file changed

+21
-40
lines changed
Lines changed: 21 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,31 @@
11
package com.networknt.schema;
22

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;
94

105
import java.io.IOException;
116
import java.io.InputStream;
12-
import java.net.URL;
137

14-
import static org.junit.jupiter.api.Assertions.assertEquals;
8+
import org.junit.jupiter.api.Test;
9+
10+
import com.fasterxml.jackson.databind.ObjectMapper;
1511

16-
class UrnTest
17-
{
18-
private final ObjectMapper mapper = new ObjectMapper();
12+
class UrnTest {
13+
private final ObjectMapper mapper = new ObjectMapper();
1914

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());
4830
}
49-
}
5031
}

0 commit comments

Comments
 (0)