• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.networknt.schema;
2 
3 import org.junit.jupiter.api.Assertions;
4 import org.junit.jupiter.api.Test;
5 
6 import java.io.IOException;
7 import java.io.InputStream;
8 import java.io.UncheckedIOException;
9 import java.util.Collections;
10 import java.util.Set;
11 
12 public class Issue665Test extends BaseJsonSchemaValidatorTest {
13 
14     @Test
testUrnUriAsLocalRef()15     void testUrnUriAsLocalRef() throws IOException {
16         JsonSchema schema = getJsonSchemaFromClasspath("draft7/urn/issue665.json", SpecVersion.VersionFlag.V7);
17         Assertions.assertNotNull(schema);
18         Assertions.assertDoesNotThrow(schema::initializeValidators);
19         Set<ValidationMessage> messages = schema.validate(getJsonNodeFromStringContent(
20                 "{\"myData\": {\"value\": \"hello\"}}"));
21         Assertions.assertEquals(messages, Collections.emptySet());
22     }
23 
24     @Test
testUrnUriAsLocalRef_ExternalURN()25     void testUrnUriAsLocalRef_ExternalURN() {
26         JsonSchemaFactory factory = JsonSchemaFactory
27                 .builder(JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V7))
28                 .schemaMappers(schemaMappers -> {
29                     schemaMappers.mappings(Collections.singletonMap("urn:data",
30                             "classpath:draft7/urn/issue665_external_urn_subschema.json"));
31                 })
32                 .build();
33 
34         try (InputStream is = Thread.currentThread().getContextClassLoader()
35                 .getResourceAsStream("draft7/urn/issue665_external_urn_ref.json")) {
36             JsonSchema schema = factory.getSchema(is);
37             Assertions.assertNotNull(schema);
38             Assertions.assertDoesNotThrow(schema::initializeValidators);
39             Set<ValidationMessage> messages = schema.validate(getJsonNodeFromStringContent(
40                     "{\"myData\": {\"value\": \"hello\"}}"));
41             Assertions.assertEquals(messages, Collections.emptySet());
42         } catch (IOException e) {
43             throw new UncheckedIOException(e);
44         }
45     }
46 
47 }
48