• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.networknt.schema;
2 
3 import com.fasterxml.jackson.databind.ObjectMapper;
4 import org.junit.jupiter.api.Test;
5 
6 import java.io.IOException;
7 import java.io.InputStream;
8 import java.net.URL;
9 
10 import static org.junit.jupiter.api.Assertions.assertEquals;
11 
12 public class UrnTest
13 {
14   private final ObjectMapper mapper = new ObjectMapper();
15 
16   /**
17    * Validate that a JSON URI Mapping file containing the URI Mapping schema is
18    * schema valid.
19    *
20    * @throws IOException if unable to parse the mapping file
21    */
22   @Test
testURNToURI()23   public void testURNToURI() throws Exception {
24     InputStream urlTestData = UrnTest.class.getResourceAsStream("/draft7/urn/test.json");
25     InputStream is = null;
26     try {
27       is = new URL("https://raw.githubusercontent.com/francesc79/json-schema-validator/feature/urn-management/src/test/resources/draft7/urn/urn.schema.json").openStream();
28       JsonMetaSchema draftV7 = JsonMetaSchema.getV7();
29       JsonSchemaFactory.Builder builder = JsonSchemaFactory.builder()
30           .defaultMetaSchemaIri(draftV7.getIri())
31           .metaSchema(draftV7)
32           .schemaMappers(schemaMappers -> schemaMappers.add(value -> AbsoluteIri.of(String.format("resource:draft7/urn/%s.schema.json", value.toString())))
33           );
34       JsonSchemaFactory instance = builder.build();
35       JsonSchema schema = instance.getSchema(is);
36       assertEquals(0, schema.validate(mapper.readTree(urlTestData)).size());
37     } catch( Exception e) {
38       e.printStackTrace();
39     }
40     finally {
41       if (is != null) {
42         is.close();
43       }
44     }
45   }
46 }
47