Skip to content

Commit 5f541d4

Browse files
author
Jake Waffle
committed
Fixed some issues in the UriMappingTest class.
1 parent 0a64900 commit 5f541d4

File tree

4 files changed

+23
-16
lines changed

4 files changed

+23
-16
lines changed

src/main/java/com/networknt/schema/uri/ClasspathURLFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public final class ClasspathURLFactory implements URIFactory {
3333
public static final Set<String> SUPPORTED_SCHEMES = Collections.unmodifiableSet(
3434
ClasspathURLStreamHandler.SUPPORTED_SCHEMES);
3535

36-
static URL convert(final URI uri) throws MalformedURLException {
36+
public static URL convert(final URI uri) throws MalformedURLException {
3737
return new URL(null, uri.toString(), STREAM_HANDLER);
3838
}
3939

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

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@
1717
import com.fasterxml.jackson.databind.JsonNode;
1818
import com.fasterxml.jackson.databind.ObjectMapper;
1919
import com.networknt.schema.JsonSchemaFactory.Builder;
20+
import com.networknt.schema.uri.ClasspathURLFactory;
2021
import com.networknt.schema.uri.URLFactory;
2122

2223
public class UriMappingTest {
2324

2425
private final ObjectMapper mapper = new ObjectMapper();
26+
private final ClasspathURLFactory classpathURLFactory = new ClasspathURLFactory();
2527
private final URLFactory urlFactory = new URLFactory();
2628

2729
/**
@@ -32,16 +34,17 @@ public class UriMappingTest {
3234
*/
3335
@Test
3436
public void testBuilderUriMappingUri() throws IOException {
35-
URI mappings = this.urlFactory.create("resource:tests/url_mapping/uri-mapping.json");
37+
URL mappings = ClasspathURLFactory.convert(
38+
this.classpathURLFactory.create("resource:tests/uri_mapping/uri-mapping.json"));
3639
JsonMetaSchema draftV4 = JsonMetaSchema.getDraftV4();
3740
Builder builder = JsonSchemaFactory.builder()
3841
.defaultMetaSchemaURI(draftV4.getUri())
3942
.addMetaSchema(draftV4)
40-
.addUriMappings(getUriMappingsFromUrl(mappings.toURL()));
43+
.addUriMappings(getUriMappingsFromUrl(mappings));
4144
JsonSchemaFactory instance = builder.build();
4245
JsonSchema schema = instance.getSchema(this.urlFactory.create(
4346
"https://raw.githubusercontent.com/networknt/json-schema-validator/master/src/test/resources/tests/uri_mapping/uri-mapping.schema.json"));
44-
assertEquals(0, schema.validate(mapper.readTree(mappings.toURL())).size());
47+
assertEquals(0, schema.validate(mapper.readTree(mappings)).size());
4548
}
4649

4750
/**
@@ -70,12 +73,13 @@ public void testBuilderExampleMappings() throws IOException {
7073
} catch (Exception ex) {
7174
fail("Unexpected exception thrown");
7275
}
73-
URI mappings = this.urlFactory.create("resource:tests/uri_mapping/invalid-schema-uri.json");
76+
URL mappings = ClasspathURLFactory.convert(
77+
this.classpathURLFactory.create("resource:tests/uri_mapping/invalid-schema-uri.json"));
7478
JsonMetaSchema draftV4 = JsonMetaSchema.getDraftV4();
7579
Builder builder = JsonSchemaFactory.builder()
7680
.defaultMetaSchemaURI(draftV4.getUri())
7781
.addMetaSchema(draftV4)
78-
.addUriMappings(getUriMappingsFromUrl(mappings.toURL()));
82+
.addUriMappings(getUriMappingsFromUrl(mappings));
7983
instance = builder.build();
8084
JsonSchema schema = instance.getSchema(example);
8185
assertEquals(0, schema.validate(mapper.createObjectNode()).size());
@@ -90,13 +94,14 @@ public void testBuilderExampleMappings() throws IOException {
9094
@Test
9195
public void testValidatorConfigUriMappingUri() throws IOException {
9296
JsonSchemaFactory instance = JsonSchemaFactory.getInstance();
93-
URI mappings = this.urlFactory.create("resource:tests/uri_mapping/uri-mapping.json");
97+
URL mappings = ClasspathURLFactory.convert(
98+
this.classpathURLFactory.create("resource:tests/uri_mapping/uri-mapping.json"));
9499
SchemaValidatorsConfig config = new SchemaValidatorsConfig();
95-
config.setUriMappings(getUriMappingsFromUrl(mappings.toURL()));
100+
config.setUriMappings(getUriMappingsFromUrl(mappings));
96101
JsonSchema schema = instance.getSchema(this.urlFactory.create(
97102
"https://raw.githubusercontent.com/networknt/json-schema-validator/master/src/test/resources/tests/uri_mapping/uri-mapping.schema.json"),
98103
config);
99-
assertEquals(0, schema.validate(mapper.readTree(mappings.toURL())).size());
104+
assertEquals(0, schema.validate(mapper.readTree(mappings)).size());
100105
}
101106

102107
/**
@@ -126,19 +131,21 @@ public void testValidatorConfigExampleMappings() throws IOException {
126131
} catch (Exception ex) {
127132
fail("Unexpected exception thrown");
128133
}
129-
URI mappings = this.urlFactory.create("resource:tests/uri_mapping/invalid-schema-uri.json");
130-
config.setUriMappings(getUriMappingsFromUrl(mappings.toURL()));
134+
URL mappings = ClasspathURLFactory.convert(
135+
this.classpathURLFactory.create("resource:tests/uri_mapping/invalid-schema-uri.json"));
136+
config.setUriMappings(getUriMappingsFromUrl(mappings));
131137
JsonSchema schema = instance.getSchema(example, config);
132138
assertEquals(0, schema.validate(mapper.createObjectNode()).size());
133139
}
134140

135141
@Test
136142
public void testMappingsForRef() throws IOException {
137143
JsonSchemaFactory instance = JsonSchemaFactory.getInstance();
138-
URI mappings = this.urlFactory.create("resource:tests/uri_mapping/schema-with-ref-mapping.json");
144+
URL mappings = ClasspathURLFactory.convert(
145+
this.classpathURLFactory.create("resource:tests/uri_mapping/schema-with-ref-mapping.json"));
139146
SchemaValidatorsConfig config = new SchemaValidatorsConfig();
140-
config.setUriMappings(getUriMappingsFromUrl(mappings.toURL()));
141-
JsonSchema schema = instance.getSchema(this.urlFactory.create("resource:tests/uri_mapping/schema-with-ref.json"),
147+
config.setUriMappings(getUriMappingsFromUrl(mappings));
148+
JsonSchema schema = instance.getSchema(this.classpathURLFactory.create("resource:tests/uri_mapping/schema-with-ref.json"),
142149
config);
143150
assertEquals(0, schema.validate(mapper.readTree("[]")).size());
144151
}

src/test/resources/tests/uri_mapping/invalid-schema-uri.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
},
66
{
77
"publicURL": "http://example.com/invalid/schema/url",
8-
"localURL": "resource:/tests/url_mapping/example-schema.json"
8+
"localURL": "resource:/tests/uri_mapping/example-schema.json"
99
}
1010
]

src/test/resources/tests/uri_mapping/schema-with-ref-mapping.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
},
66
{
77
"publicURL": "http://example.com/invalid/schema/url",
8-
"localURL": "resource:/tests/url_mapping/example-schema.json"
8+
"localURL": "resource:/tests/uri_mapping/example-schema.json"
99
}
1010
]

0 commit comments

Comments
 (0)