17
17
import com .fasterxml .jackson .databind .JsonNode ;
18
18
import com .fasterxml .jackson .databind .ObjectMapper ;
19
19
import com .networknt .schema .JsonSchemaFactory .Builder ;
20
+ import com .networknt .schema .uri .ClasspathURLFactory ;
20
21
import com .networknt .schema .uri .URLFactory ;
21
22
22
23
public class UriMappingTest {
23
24
24
25
private final ObjectMapper mapper = new ObjectMapper ();
26
+ private final ClasspathURLFactory classpathURLFactory = new ClasspathURLFactory ();
25
27
private final URLFactory urlFactory = new URLFactory ();
26
28
27
29
/**
@@ -32,16 +34,17 @@ public class UriMappingTest {
32
34
*/
33
35
@ Test
34
36
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" ));
36
39
JsonMetaSchema draftV4 = JsonMetaSchema .getDraftV4 ();
37
40
Builder builder = JsonSchemaFactory .builder ()
38
41
.defaultMetaSchemaURI (draftV4 .getUri ())
39
42
.addMetaSchema (draftV4 )
40
- .addUriMappings (getUriMappingsFromUrl (mappings . toURL () ));
43
+ .addUriMappings (getUriMappingsFromUrl (mappings ));
41
44
JsonSchemaFactory instance = builder .build ();
42
45
JsonSchema schema = instance .getSchema (this .urlFactory .create (
43
46
"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 ());
45
48
}
46
49
47
50
/**
@@ -70,12 +73,13 @@ public void testBuilderExampleMappings() throws IOException {
70
73
} catch (Exception ex ) {
71
74
fail ("Unexpected exception thrown" );
72
75
}
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" ));
74
78
JsonMetaSchema draftV4 = JsonMetaSchema .getDraftV4 ();
75
79
Builder builder = JsonSchemaFactory .builder ()
76
80
.defaultMetaSchemaURI (draftV4 .getUri ())
77
81
.addMetaSchema (draftV4 )
78
- .addUriMappings (getUriMappingsFromUrl (mappings . toURL () ));
82
+ .addUriMappings (getUriMappingsFromUrl (mappings ));
79
83
instance = builder .build ();
80
84
JsonSchema schema = instance .getSchema (example );
81
85
assertEquals (0 , schema .validate (mapper .createObjectNode ()).size ());
@@ -90,13 +94,14 @@ public void testBuilderExampleMappings() throws IOException {
90
94
@ Test
91
95
public void testValidatorConfigUriMappingUri () throws IOException {
92
96
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" ));
94
99
SchemaValidatorsConfig config = new SchemaValidatorsConfig ();
95
- config .setUriMappings (getUriMappingsFromUrl (mappings . toURL () ));
100
+ config .setUriMappings (getUriMappingsFromUrl (mappings ));
96
101
JsonSchema schema = instance .getSchema (this .urlFactory .create (
97
102
"https://raw.githubusercontent.com/networknt/json-schema-validator/master/src/test/resources/tests/uri_mapping/uri-mapping.schema.json" ),
98
103
config );
99
- assertEquals (0 , schema .validate (mapper .readTree (mappings . toURL () )).size ());
104
+ assertEquals (0 , schema .validate (mapper .readTree (mappings )).size ());
100
105
}
101
106
102
107
/**
@@ -126,19 +131,21 @@ public void testValidatorConfigExampleMappings() throws IOException {
126
131
} catch (Exception ex ) {
127
132
fail ("Unexpected exception thrown" );
128
133
}
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 ));
131
137
JsonSchema schema = instance .getSchema (example , config );
132
138
assertEquals (0 , schema .validate (mapper .createObjectNode ()).size ());
133
139
}
134
140
135
141
@ Test
136
142
public void testMappingsForRef () throws IOException {
137
143
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" ));
139
146
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" ),
142
149
config );
143
150
assertEquals (0 , schema .validate (mapper .readTree ("[]" )).size ());
144
151
}
0 commit comments