Skip to content

Commit 5e2acbe

Browse files
committed
Fix UrnTest
1 parent b53c313 commit 5e2acbe

File tree

1 file changed

+27
-40
lines changed

1 file changed

+27
-40
lines changed
Lines changed: 27 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,37 @@
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;
159

16-
class UrnTest
17-
{
18-
private final ObjectMapper mapper = new ObjectMapper();
10+
import com.fasterxml.jackson.databind.ObjectMapper;
11+
import com.networknt.schema.dialect.BasicDialectRegistry;
12+
import com.networknt.schema.dialect.Dialect;
13+
import com.networknt.schema.dialect.Dialects;
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+
class UrnTest {
16+
private final ObjectMapper mapper = new ObjectMapper();
17+
18+
/**
19+
* Validate that a JSON URI Mapping file containing the URI Mapping schema is
20+
* schema valid.
21+
*
22+
* @throws IOException if unable to parse the mapping file
23+
*/
24+
@Test
25+
void testURNToURI() throws Exception {
26+
InputStream urlTestData = UrnTest.class.getResourceAsStream("/draft7/urn/test.json");
27+
Dialect draftV7 = Dialects.getDraft7();
28+
SchemaRegistry.Builder builder = SchemaRegistry.builder().defaultDialectId(draftV7.getId())
29+
.dialectRegistry(new BasicDialectRegistry(draftV7))
30+
.schemaIdResolvers(schemaIdResolvers -> schemaIdResolvers.add(value -> {
31+
return AbsoluteIri.of(String.format("%s.schema.json", value.toString()));
32+
}));
33+
SchemaRegistry instance = builder.build();
34+
Schema schema = instance.getSchema(SchemaLocation.of("classpath:/draft7/urn/urn"));
35+
assertEquals(0, schema.validate(mapper.readTree(urlTestData)).size());
4836
}
49-
}
5037
}

0 commit comments

Comments
 (0)