@Test public void noFormatInSchemaIsANoOp() throws ProcessingException { final ObjectNode schema = FACTORY.objectNode(); final SchemaTree tree = new CanonicalSchemaTree(SchemaKey.anonymousKey(), schema); final SchemaContext context = new SchemaContext(tree, NodeType.NULL); final ValidatorList in = new ValidatorList(context, Collections.<KeywordValidator>emptyList()); final ValidatorList out = processor.process(report, in); assertTrue(Lists.newArrayList(out).isEmpty()); verifyZeroInteractions(report); }
@Test public void nonPresentKeywordDoesNotTriggerBuild() throws ProcessingException { final ObjectNode node = FACTORY.objectNode(); node.put(K1, K1); final SchemaTree schemaTree = new CanonicalSchemaTree(SchemaKey.anonymousKey(), node); final SchemaContext context = new SchemaContext(schemaTree, NodeType.NULL); final ProcessingReport report = mock(ProcessingReport.class); schemaDigester.process(report, context); verify(digester1).digest(node); verify(digester2, never()).digest(any(JsonNode.class)); } }
@Test public void attributeIsBeingAskedWhatIsSupports() throws ProcessingException { final ObjectNode schema = FACTORY.objectNode(); schema.put("format", FMT); final SchemaTree tree = new CanonicalSchemaTree(SchemaKey.anonymousKey(), schema); final SchemaContext context = new SchemaContext(tree, NodeType.NULL); final ValidatorList in = new ValidatorList(context, Collections.<KeywordValidator>emptyList()); processor.process(report, in); verify(attribute).supportedTypes(); }
@Test( dataProvider = "unsupported", dependsOnMethods = "attributeIsBeingAskedWhatIsSupports" ) public void unsupportedTypeDoesNotTriggerValidatorBuild(final JsonNode node) throws ProcessingException { final ObjectNode schema = FACTORY.objectNode(); schema.put("format", FMT); final SchemaTree tree = new CanonicalSchemaTree(SchemaKey.anonymousKey(), schema); final SchemaContext context = new SchemaContext(tree, NodeType.getNodeType(node)); final ValidatorList in = new ValidatorList(context, Collections.<KeywordValidator>emptyList()); final ValidatorList out = processor.process(report, in); final List<KeywordValidator> validators = Lists.newArrayList(out); assertTrue(validators.isEmpty()); } }
@Test(dataProvider = "sampleData") public void onlyRelevantDigestsAreBuilt(final JsonNode node) throws ProcessingException { final NodeType type = NodeType.getNodeType(node); final SchemaTree tree = new CanonicalSchemaTree(SchemaKey.anonymousKey(), schema); final SchemaContext context = new SchemaContext(tree, type); final ProcessingReport report = mock(ProcessingReport.class); final SchemaDigest digest = schemaDigester.process(report, context); verify(digester1).digest(schema); verify(digester2).digest(schema); final Map<String,JsonNode> digests = digest.getDigests(); if (TYPES1.contains(type)) assertSame(digests.get(K1), digest1); else assertFalse(digests.containsKey(K1)); if (TYPES2.contains(type)) assertSame(digests.get(K2), digest2); else assertFalse(digests.containsKey(K2)); }
@Test( dataProvider = "supported", dependsOnMethods = "attributeIsBeingAskedWhatIsSupports" ) public void supportedNodeTypesTriggerAttributeBuild(final JsonNode node) throws ProcessingException { final ObjectNode schema = FACTORY.objectNode(); schema.put("format", FMT); final SchemaTree tree = new CanonicalSchemaTree(SchemaKey.anonymousKey(), schema); final JsonTree instance = new SimpleJsonTree(node); final FullData data = new FullData(tree, instance); final SchemaContext context = new SchemaContext(data); final ValidatorList in = new ValidatorList(context, Collections.<KeywordValidator>emptyList()); final ValidatorList out = processor.process(report, in); final List<KeywordValidator> validators = Lists.newArrayList(out); assertEquals(validators.size(), 1); @SuppressWarnings("unchecked") final Processor<FullData, FullData> p = mock(Processor.class); validators.get(0).validate(p, report, BUNDLE, data); verify(attribute).validate(report, BUNDLE, data); }
@Test public void unknownFormatAttributesAreReportedAsWarnings() throws ProcessingException { final ObjectNode schema = FACTORY.objectNode(); schema.put("format", "foo"); final SchemaTree tree = new CanonicalSchemaTree(SchemaKey.anonymousKey(), schema); final SchemaContext context = new SchemaContext(tree, NodeType.NULL); final ValidatorList in = new ValidatorList(context, Collections.<KeywordValidator>emptyList()); final ArgumentCaptor<ProcessingMessage> captor = ArgumentCaptor.forClass(ProcessingMessage.class); final ValidatorList out = processor.process(report, in); assertTrue(Lists.newArrayList(out).isEmpty()); verify(report).warn(captor.capture()); final ProcessingMessage message = captor.getValue(); assertMessage(message) .hasMessage(BUNDLE.printf("warn.format.notSupported", "foo")) .hasField("domain", "validation").hasField("keyword", "format") .hasField("attribute", "foo"); }
@Override public ValidatorList process(final ProcessingReport report, final SchemaContext input) throws ProcessingException { final ValueHolder<SchemaTree> in = ValueHolder.hold("schema", input.getSchema()); /* * We have to go through an intermediate report. If we re-enter this * function with a report already telling there is an error, we don't * want to wrongly report that the schema is invalid. */ final ProcessingReport r = new ListProcessingReport(report); final ValueHolder<SchemaTree> out = resolver.process(r, in); report.mergeWith(r); if (!r.isSuccess()) return null; final SchemaContext output = new SchemaContext(out.getValue(), input.getInstanceType()); return builder.process(report, output); }
final SchemaContext context = new SchemaContext(input);