瀏覽代碼

Add tests that show meta-schema elements are just passed through.

Sam Jaffe 6 年之前
父節點
當前提交
9999ac3e4c

+ 3 - 3
src/main/lombok/org/leumasjaffe/json/schema/factory/SchemaV6Factory.java

@@ -34,10 +34,10 @@ class SchemaV6Factory extends SchemaFactory {
 		case "$id": return Tester.ACCEPT;
 		case "$schema": return Tester.ACCEPT;
 		// case "$ref": ; // TODO Implement reference propagating
-		case "title": return JsonNode::isTextual;
-		case "description": return JsonNode::isTextual;
+		case "title": return Tester.ACCEPT;
+		case "description": return Tester.ACCEPT;
 		case "default": return Tester.ACCEPT;
-		case "examples": return JsonNode::isArray;
+		case "examples": return Tester.ACCEPT;
 		case "multipleOf": return new NumberTester(d -> d % value.asDouble() == 0);
 		case "maximum": return new NumberTester(d -> d <= value.asDouble());
 		case "exclusiveMaximum": return new NumberTester(d -> d < value.asDouble());

+ 62 - 2
src/test/java/org/leumasjaffe/json/schema/factory/SchemaV6FactoryTest.java

@@ -2,13 +2,73 @@ package org.leumasjaffe.json.schema.factory;
 
 import static org.junit.Assert.*;
 
+import java.io.IOException;
+
+import org.junit.Before;
 import org.junit.Test;
+import org.leumasjaffe.json.schema.Tester;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.NullNode;
 
 public class SchemaV6FactoryTest {
+	SchemaV6Factory factory;
+	ObjectMapper mapper;
+	
+	@Before
+	public void setUp() {
+		factory = new SchemaV6Factory();
+		mapper = new ObjectMapper();
+	}
+	
+	public JsonNode readTree(String data) {
+		try {
+			return mapper.readTree(data);
+		} catch (IOException e) {
+			throw new RuntimeException(e);
+		}
+	}
 
 	@Test
-	public void test() {
-		fail("Not yet implemented");
+	public void testIDSchema() {
+		final JsonNode schema = readTree("{ \"$id\": \"test.json\" }");
+		Tester test = factory.createMapping("$id", schema.get("$id"));
+		assertTrue(test.accepts(NullNode.getInstance()));
+	}
+	
+	@Test
+	public void testSchemaSchema() {
+		final JsonNode schema = readTree("{ \"$schema\": \"http://json-schema.org/draft-06/schema#\" }");
+		Tester test = factory.createMapping("$schema", schema.get("$schema"));
+		assertTrue(test.accepts(NullNode.getInstance()));
+	}
+	
+	@Test
+	public void testTitleSchema() {
+		final JsonNode schema = readTree("{ \"title\": \"This is a schema\" }");
+		Tester test = factory.createMapping("title", schema.get("title"));
+		assertTrue(test.accepts(NullNode.getInstance()));
+	}
+	
+	@Test
+	public void testDescriptionSchema() {
+		final JsonNode schema = readTree("{ \"description\": \"This is a schema\" }");
+		Tester test = factory.createMapping("description", schema.get("description"));
+		assertTrue(test.accepts(NullNode.getInstance()));
+	}
+	
+	@Test
+	public void testDefaultSchema() {
+		final JsonNode schema = readTree("{ \"default\": {} }");
+		Tester test = factory.createMapping("default", schema.get("default"));
+		assertTrue(test.accepts(NullNode.getInstance()));
 	}
 
+	@Test
+	public void testExamplesSchema() {
+		final JsonNode schema = readTree("{ \"examples\": [] }");
+		Tester test = factory.createMapping("examples", schema.get("examples"));
+		assertTrue(test.accepts(NullNode.getInstance()));
+	}
 }