@Override public SchemaDigest process(final ProcessingReport report, final SchemaContext input) throws ProcessingException { final JsonNode schema = input.getSchema().getNode(); final NodeType type = input.getInstanceType(); final Map<String, JsonNode> map = Maps.newHashMap(buildDigests(schema)); map.keySet().retainAll(typeMap.get(type)); return new SchemaDigest(input, map); }
@Test public void onlyRelevantValidatorsAreBuilt() throws ProcessingException { final Map<String, JsonNode> digests = Maps.newTreeMap(); digests.put(K1, JacksonUtils.nodeFactory().nullNode()); final SchemaDigest digest = new SchemaDigest(null, digests); final ProcessingReport report = mock(ProcessingReport.class); final ValidatorList context = validatorBuilder.process(report, digest); final List<KeywordValidator> list = Lists.newArrayList(context); assertEquals(list.size(), 1); assertSame(list.get(0).getClass(), Keyword1.class); }
@Test public void challengedConstructorRaisesAnException() { final Map<String, JsonNode> digests = Maps.newTreeMap(); digests.put(K1, JacksonUtils.nodeFactory().nullNode()); digests.put(CHALLENGED, JacksonUtils.nodeFactory().nullNode()); final SchemaDigest digest = new SchemaDigest(null, digests); final ProcessingReport report = mock(ProcessingReport.class); try { validatorBuilder.process(report, digest); fail("No exception thrown??"); } catch (ProcessingException ignored) { } }
@Test public void allRelevantValidatorsAreBuilt() throws ProcessingException { final Map<String, JsonNode> digests = Maps.newTreeMap(); digests.put(K1, JacksonUtils.nodeFactory().nullNode()); digests.put(K2, JacksonUtils.nodeFactory().nullNode()); final SchemaDigest digest = new SchemaDigest(null, digests); final ProcessingReport report = mock(ProcessingReport.class); final ValidatorList context = validatorBuilder.process(report, digest); final List<KeywordValidator> list = Lists.newArrayList(context); assertEquals(list.size(), 2); assertSame(list.get(0).getClass(), Keyword1.class); assertSame(list.get(1).getClass(), Keyword2.class); }