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.Disabled; 7 import org.junit.jupiter.api.Test; 8 9 import java.io.InputStream; 10 import java.util.Set; 11 12 public class Issue313Test { getJsonSchemaFromStreamContentV7(InputStream schemaContent)13 protected JsonSchema getJsonSchemaFromStreamContentV7(InputStream schemaContent) { 14 JsonSchemaFactory factory = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V7); 15 return factory.getSchema(schemaContent); 16 } 17 getJsonSchemaFromStreamContentV201909(InputStream schemaContent)18 protected JsonSchema getJsonSchemaFromStreamContentV201909(InputStream schemaContent) { 19 JsonSchemaFactory factory = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V201909); 20 return factory.getSchema(schemaContent); 21 } 22 getJsonNodeFromStreamContent(InputStream content)23 protected JsonNode getJsonNodeFromStreamContent(InputStream content) throws Exception { 24 ObjectMapper mapper = new ObjectMapper(); 25 JsonNode node = mapper.readTree(content); 26 return node; 27 } 28 29 @Test 30 @Disabled shouldFailV201909()31 public void shouldFailV201909() throws Exception { 32 String schemaPath = "/schema/issue313-2019-09.json"; 33 String dataPath = "/data/issue313.json"; 34 InputStream schemaInputStream = getClass().getResourceAsStream(schemaPath); 35 JsonSchema schema = getJsonSchemaFromStreamContentV201909(schemaInputStream); 36 InputStream dataInputStream = getClass().getResourceAsStream(dataPath); 37 JsonNode node = getJsonNodeFromStreamContent(dataInputStream); 38 Set<ValidationMessage> errors = schema.validate(node); 39 Assertions.assertEquals(2, errors.size()); 40 } 41 42 @Test shouldFailV7()43 public void shouldFailV7() throws Exception { 44 String schemaPath = "/schema/issue313-v7.json"; 45 String dataPath = "/data/issue313.json"; 46 InputStream schemaInputStream = getClass().getResourceAsStream(schemaPath); 47 JsonSchema schema = getJsonSchemaFromStreamContentV7(schemaInputStream); 48 InputStream dataInputStream = getClass().getResourceAsStream(dataPath); 49 JsonNode node = getJsonNodeFromStreamContent(dataInputStream); 50 Set<ValidationMessage> errors = schema.validate(node); 51 Assertions.assertEquals(2, errors.size()); 52 } 53 54 } 55