From efa9f7d6b19de5ed2bf4469477a37b3bfaa16cac Mon Sep 17 00:00:00 2001 From: Francis Galiegue Date: Sat, 24 May 2014 10:06:35 +0200 Subject: [PATCH] Make test to reproduce issue #102 Signed-off-by: Francis Galiegue --- .../validation/ValidationProcessorTest.java | 21 +++++++++++-- src/test/resources/other/issue102.json | 30 +++++++++++++++++++ 2 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 src/test/resources/other/issue102.json diff --git a/src/test/java/com/github/fge/jsonschema/processors/validation/ValidationProcessorTest.java b/src/test/java/com/github/fge/jsonschema/processors/validation/ValidationProcessorTest.java index 65af8a23c..f51123c01 100644 --- a/src/test/java/com/github/fge/jsonschema/processors/validation/ValidationProcessorTest.java +++ b/src/test/java/com/github/fge/jsonschema/processors/validation/ValidationProcessorTest.java @@ -24,6 +24,7 @@ import com.fasterxml.jackson.databind.node.JsonNodeFactory; import com.fasterxml.jackson.databind.node.ObjectNode; import com.github.fge.jackson.JacksonUtils; +import com.github.fge.jackson.JsonLoader; import com.github.fge.jackson.NodeType; import com.github.fge.jsonschema.cfg.ValidationConfiguration; import com.github.fge.jsonschema.core.exceptions.ProcessingException; @@ -39,15 +40,18 @@ import com.github.fge.jsonschema.library.Keyword; import com.github.fge.jsonschema.library.Library; import com.github.fge.jsonschema.main.JsonSchemaFactory; +import com.github.fge.jsonschema.main.JsonValidator; import com.github.fge.jsonschema.processors.data.FullData; import com.github.fge.msgsimple.bundle.MessageBundle; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; +import java.io.IOException; import java.util.concurrent.atomic.AtomicInteger; -import static org.mockito.Mockito.*; -import static org.testng.Assert.*; +import static org.mockito.Mockito.mock; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; public final class ValidationProcessorTest { @@ -111,6 +115,19 @@ public void childrenAreExploredOnDemandEvenIfContainerFails() assertEquals(COUNT.get(), 1); } + @Test(timeOut = 1000) + public void circularReferencingDuringValidationIsDetected() + throws IOException, ProcessingException + { + final JsonNode schemaNode + = JsonLoader.fromResource("/other/issue102.json"); + final JsonSchemaFactory factory = JsonSchemaFactory.byDefault(); + final JsonValidator validator = factory.getValidator(); + + validator.validate(schemaNode, JacksonUtils.nodeFactory().nullNode()); + assertTrue(true); + } + public static final class K1Validator extends AbstractKeywordValidator { diff --git a/src/test/resources/other/issue102.json b/src/test/resources/other/issue102.json new file mode 100644 index 000000000..1af9832c3 --- /dev/null +++ b/src/test/resources/other/issue102.json @@ -0,0 +1,30 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "definitions": { + "S": { + "allOf": [ + { + "type": "string", + "enum": ["a"] + }, + { + "oneOf": [ + { + "$ref": "#/definitions/S" + }, + { + "type": "string", + "enum": [""] + } + ] + }, + { + "type": "string", + "enum": ["b"] + } + ], + "additionalItems": false + } + }, + "$ref": "#/definitions/S" +} \ No newline at end of file