@Override public void validate(final ProcessingReport report, final MessageBundle bundle, final FullData data) throws ProcessingException { final JsonNode instance = data.getInstance().getNode(); BigInteger epoch = instance.bigIntegerValue(); if (epoch.signum() == -1) { report.warn(newMsg(data, bundle, "warn.format.epoch.negative") .putArgument("value", instance)); return; } epoch = epoch.divide(ONE_THOUSAND); if (epoch.bitLength() > EPOCH_BITLENGTH) report.warn(newMsg(data, bundle, "warn.format.epoch.overflow") .putArgument("value", instance)); } }
@Override public ValidatorList process(final ProcessingReport report, final ValidatorList input) throws ProcessingException { final SchemaContext context = input.getContext(); final JsonNode node = context.getSchema().getNode().get("format"); if (node == null) return input; final String fmt = node.textValue(); final FormatAttribute attr = attributes.get(fmt); if (attr == null) { report.warn(input.newMessage().put("domain", "validation") .put("keyword", "format") .setMessage(bundle.getMessage("warn.format.notSupported")) .putArgument("attribute", fmt)); return input; } final NodeType type = context.getInstanceType(); if (!attr.supportedTypes().contains(type)) return input; final List<KeywordValidator> validators = Lists.newArrayList(input); validators.add(formatValidator(attr)); return new ValidatorList(context, validators); }
@Test( dependsOnMethods = "retestAttribute", dataProvider = "negativeValues" ) public void userIsWarnedAboutNegativeEpochs(final JsonNode input) throws ProcessingException { final JsonTree tree = new SimpleJsonTree(input); final FullData data = new FullData(SCHEMA_TREE, tree); attribute.validate(report, BUNDLE, data); final ArgumentCaptor<ProcessingMessage> captor = ArgumentCaptor.forClass(ProcessingMessage.class); verify(report, only()).warn(captor.capture()); final ProcessingMessage message = captor.getValue(); assertMessage(message).isFormatMessage(fmt, BUNDLE.printf("warn.format.epoch.negative", input)); }
@Test( dependsOnMethods = "retestAttribute", dataProvider = "overflows" ) public void userIsWarnedAboutPotentialOverflows(final JsonNode input) throws ProcessingException { final JsonTree tree = new SimpleJsonTree(input); final FullData data = new FullData(SCHEMA_TREE, tree); attribute.validate(report, BUNDLE, data); final ArgumentCaptor<ProcessingMessage> captor = ArgumentCaptor.forClass(ProcessingMessage.class); verify(report, only()).warn(captor.capture()); final ProcessingMessage message = captor.getValue(); assertMessage(message) .isFormatMessage(fmt, BUNDLE.printf("warn.format.epoch.overflow", input)); } }
@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 protected void extraChecks(final ProcessingReport report, final MessageBundle bundle, final SchemaTree tree) throws ProcessingException { final JsonNode node = tree.getNode().get(keyword); if (node.isArray() && node.size() == 0) report.warn(newMsg(tree, bundle, "draftv3.extends.emptyArray")); } }
@Override protected void extraChecks(final ProcessingReport report, final MessageBundle bundle, final SchemaTree tree) throws ProcessingException { final JsonNode node = tree.getNode().get(keyword); if (node.isArray() && node.size() == 0) report.warn(newMsg(tree, bundle, "draftv3.extends.emptyArray")); } }
@Override protected void extraChecks(final ProcessingReport report, final MessageBundle bundle, final SchemaTree tree) throws ProcessingException { final JsonNode node = tree.getNode().get(keyword); if (node.isArray() && node.size() == 0) report.warn(newMsg(tree, bundle, "draftv3.extends.emptyArray")); } }
@Override public void validate(final ProcessingReport report, final MessageBundle bundle, final FullData data) throws ProcessingException { final JsonNode instance = data.getInstance().getNode(); final BigDecimal dec = instance.decimalValue(); final BigDecimal converted = BigDecimal.valueOf(dec.doubleValue()); if (dec.compareTo(converted) != 0) { report.warn(newMsg(data, bundle, "warn.format.double.overflow") .put("key", "warn.format.double.overflow") .putArgument("value", instance) .putArgument("converted", converted)); } } }
@Override public void validate(final ProcessingReport report, final MessageBundle bundle, final FullData data) throws ProcessingException { final JsonNode instance = data.getInstance().getNode(); final BigDecimal dec = instance.decimalValue(); final BigDecimal converted = BigDecimal.valueOf(dec.doubleValue()); if (dec.compareTo(converted) != 0) { report.warn(newMsg(data, bundle, "warn.format.double.overflow") .put("key", "warn.format.double.overflow") .putArgument("value", instance) .putArgument("converted", converted)); } } }
report.warn(newMsg(tree, "core.unknownKeywords") .putArgument("ignored", Ordering.natural().sortedCopy(fields)));
report.warn(newMsg(tree, "core.unknownKeywords") .putArgument("ignored", Ordering.natural().sortedCopy(fields)));
@Override public void validate(final ProcessingReport report, final MessageBundle bundle, final FullData data) throws ProcessingException { final JsonNode instance = data.getInstance().getNode(); final float f = instance.floatValue(); final String original = String.valueOf(instance.decimalValue()); final String parsed = String.valueOf(f); if (!original.equals(parsed)) { report.warn(newMsg(data, bundle, "warn.format.float.overflow") .put("key", "warn.format.float.overflow") .putArgument("value", original) .putArgument("converted", parsed)); } } }
@Override public void validate(final ProcessingReport report, final MessageBundle bundle, final FullData data) throws ProcessingException { final JsonNode instance = data.getInstance().getNode(); final float f = instance.floatValue(); final String original = String.valueOf(instance.decimalValue()); final String parsed = String.valueOf(f); if (!original.equals(parsed)) { report.warn(newMsg(data, bundle, "warn.format.float.overflow") .put("key", "warn.format.float.overflow") .putArgument("value", original) .putArgument("converted", parsed)); } } }
@Override public void validate(final ProcessingReport report, final MessageBundle bundle, final FullData data) throws ProcessingException { final JsonNode instance = data.getInstance().getNode(); if (!instance.canConvertToInt()) { report.warn(newMsg(data, bundle, "warn.format.int32.overflow") .put("key", "warn.format.int32.overflow") .putArgument("value", instance)); } } }
@Override public void validate(final ProcessingReport report, final MessageBundle bundle, final FullData data) throws ProcessingException { final JsonNode instance = data.getInstance().getNode(); if (!instance.canConvertToLong()) { report.warn(newMsg(data, bundle, "warn.format.int64.overflow") .put("key", "warn.format.int64.overflow") .putArgument("value", instance)); } } }
@Override public void validate(final ProcessingReport report, final MessageBundle bundle, final FullData data) throws ProcessingException { final JsonNode instance = data.getInstance().getNode(); if (!instance.canConvertToLong()) { report.warn(newMsg(data, bundle, "warn.format.int64.overflow") .put("key", "warn.format.int64.overflow") .putArgument("value", instance)); } } }
@Override public void validate(final ProcessingReport report, final MessageBundle bundle, final FullData data) throws ProcessingException { final JsonNode instance = data.getInstance().getNode(); if (!instance.canConvertToInt()) { report.warn(newMsg(data, bundle, "warn.format.int32.overflow") .put("key", "warn.format.int32.overflow") .putArgument("value", instance)); } } }
report.warn(message); } catch (ProcessingException ignored) { actual++;
@Test public void logLevelIsCorrectlySetInMessages() throws ProcessingException { final ProcessingReport report = new LogThreshold(LogLevel.NONE); final ProcessingMessage message = new ProcessingMessage(); report.debug(message); assertMessage(message).hasLevel(LogLevel.DEBUG); report.info(message); assertMessage(message).hasLevel(LogLevel.INFO); report.warn(message); assertMessage(message).hasLevel(LogLevel.WARNING); report.error(message); assertMessage(message).hasLevel(LogLevel.ERROR); report.fatal(message); assertMessage(message).hasLevel(LogLevel.FATAL); }