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