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 Issue456Test { 12 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 return mapper.readTree(content); 21 } 22 23 @Test shouldWorkT2()24 public void shouldWorkT2() throws Exception { 25 String schemaPath = "/schema/issue456-v7.json"; 26 String dataPath = "/data/issue456-T2.json"; 27 // String dataT3Path = "/data/issue456-T3.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 @Test shouldWorkT3()37 public void shouldWorkT3() throws Exception { 38 String schemaPath = "/schema/issue456-v7.json"; 39 String dataPath = "/data/issue456-T3.json"; 40 InputStream schemaInputStream = getClass().getResourceAsStream(schemaPath); 41 JsonSchema schema = getJsonSchemaFromStreamContentV7(schemaInputStream); 42 InputStream dataInputStream = getClass().getResourceAsStream(dataPath); 43 JsonNode node = getJsonNodeFromStreamContent(dataInputStream); 44 Set<ValidationMessage> errors = schema.validate(node); 45 Assertions.assertEquals(0, errors.size()); 46 } 47 48 } 49