• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.networknt.schema;
2 
3 import com.fasterxml.jackson.databind.JsonNode;
4 import com.fasterxml.jackson.databind.ObjectMapper;
5 import org.junit.jupiter.api.Assertions;
6 import org.junit.jupiter.api.Test;
7 
8 import java.io.InputStream;
9 import java.util.Set;
10 
11 public class Issue295Test {
getJsonSchemaFromStreamContentV7(InputStream schemaContent)12     protected JsonSchema getJsonSchemaFromStreamContentV7(InputStream schemaContent) {
13         JsonSchemaFactory factory = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V7);
14         return factory.getSchema(schemaContent);
15     }
16 
getJsonNodeFromStreamContent(InputStream content)17     protected JsonNode getJsonNodeFromStreamContent(InputStream content) throws Exception {
18         ObjectMapper mapper = new ObjectMapper();
19         JsonNode node = mapper.readTree(content);
20         return node;
21     }
22 
23     @Test
shouldWorkV7()24     public void shouldWorkV7() throws Exception {
25         String schemaPath = "/schema/issue295-v7.json";
26         String dataPath = "/data/issue295.json";
27         InputStream schemaInputStream = getClass().getResourceAsStream(schemaPath);
28         JsonSchema schema = getJsonSchemaFromStreamContentV7(schemaInputStream);
29         InputStream dataInputStream = getClass().getResourceAsStream(dataPath);
30         JsonNode node = getJsonNodeFromStreamContent(dataInputStream);
31         Set<ValidationMessage> errors = schema.validate(node);
32         Assertions.assertEquals(0, errors.size());
33     }
34 }
35