private ProcessingMessage collectSyntaxErrors(final ProcessingReport report) { /* * OK, that's for issue #99 but that's ugly nevertheless. * * We want syntax error messages to appear in the exception text. */ final String msg = syntaxMessages.getMessage("core.invalidSchema"); final ArrayNode arrayNode = JacksonUtils.nodeFactory().arrayNode(); JsonNode node; for (final ProcessingMessage message: report) { node = message.asJson(); if ("syntax".equals(node.path("domain").asText())) arrayNode.add(node); } final StringBuilder sb = new StringBuilder(msg); sb.append("\nSyntax errors:\n"); sb.append(JacksonUtils.prettyPrint(arrayNode)); return new ProcessingMessage().setMessage(sb.toString()); } }
protected final ProcessingMessage newMsg(final FullData data, final MessageBundle bundle, final String key) { return data.newMessage().put("domain", "validation") .put("keyword", keyword).setMessage(bundle.getMessage(key)) .setExceptionProvider(EXCEPTION_PROVIDER); }
@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); }
@BeforeMethod public void initEnvironment() { if (validator == null) return; final ObjectNode schema = FACTORY.objectNode(); schema.put("extends", FACTORY.objectNode()); final SchemaTree tree = new CanonicalSchemaTree(SchemaKey.anonymousKey(), schema); final JsonTree instance = new SimpleJsonTree(FACTORY.nullNode()); data = new FullData(tree, instance); report = mock(ProcessingReport.class); msg = new ProcessingMessage().setMessage(FOO); }
private static String buildMessage(final String key, final JsonNode params, final JsonNode data) { final ProcessingMessage message = new ProcessingMessage() .setMessage(BUNDLE.getMessage(key)); if (params != null) { String name; JsonNode value; for (final JsonNode node: params) { name = node.textValue(); value = data.get(name); message.putArgument(name, valueToArgument(value)); } } return message.getMessage(); }
private ProcessingMessage validationLoopMessage(final FullData input) { final ArrayNode node = JacksonUtils.nodeFactory().arrayNode(); for (final SchemaURI uri: schemaURIs) node.add(uri.toString()); return input.newMessage() .put("domain", "validation") .setMessage(errmsg) .putArgument("alreadyVisited", new SchemaURI(input.getSchema())) .putArgument("instancePointer", pointer.toString()) .put("validationPath", node); } }
private static String buildMessage(final String key, final JsonNode params, final JsonNode data) { final ProcessingMessage message = new ProcessingMessage() .setMessage(BUNDLE.getMessage(key)); if (params != null) { String name; JsonNode value; for (final JsonNode node: params) { name = node.textValue(); value = data.get(name); message.putArgument(name, valueToArgument(value)); } } return message.getMessage(); }
/** * Return a new message for this format attribute * * @param data the validation context * @param key key in the format bundle message * @return a new message */ protected final ProcessingMessage newMsg(final FullData data, final MessageBundle bundle, final String key) { return data.newMessage().put("domain", "validation") .put("keyword", "format").put("attribute", fmt) .setMessage(bundle.getMessage(key)) .put("value", data.getInstance().getNode()); } }
/** * Build a {@link JsonSchema} instance * * @param schema the schema * @param pointer the pointer into the schema * @return a new {@link JsonSchema} * @throws ProcessingException resolving the pointer against the schema * leads to a {@link MissingNode} * @throws NullPointerException the schema or pointer is null */ JsonSchema buildJsonSchema(final JsonNode schema, final JsonPointer pointer) throws ProcessingException { final SchemaTree tree = loader.load(schema).setPointer(pointer); if (tree.getNode().isMissingNode()) throw new JsonReferenceException(new ProcessingMessage() .setMessage(BUNDLE.getMessage("danglingRef"))); return new JsonSchemaImpl(processor, tree, reportProvider); }
/** * Build a {@link JsonSchema} instance * * @param uri the URI to load the schema from * @return a {@link JsonSchema} * @throws ProcessingException invalid URI, or URI did not resolve to a * JSON Schema * @throws NullPointerException URI is null */ JsonSchema buildJsonSchema(final String uri) throws ProcessingException { final JsonRef ref = JsonRef.fromString(uri); if (!ref.isLegal()) throw new JsonReferenceException(new ProcessingMessage() .setMessage(BUNDLE.getMessage("illegalJsonRef"))); final SchemaTree tree = loader.get(ref.getLocator()).setPointer(ref.getPointer()); if (tree.getNode().isMissingNode()) throw new JsonReferenceException(new ProcessingMessage() .setMessage(BUNDLE.getMessage("danglingRef"))); return new JsonSchemaImpl(processor, tree, reportProvider); }
public ProcessingException(final String message) { this(new ProcessingMessage().setMessage(message) .setLogLevel(LogLevel.FATAL)); }
public ProcessingException(final String message) { this(new ProcessingMessage().setMessage(message) .setLogLevel(LogLevel.FATAL)); }
public ProcessingException(final String message, final Throwable e) { processingMessage = new ProcessingMessage().setLogLevel(LogLevel.FATAL) .setMessage(message).put("exceptionClass", e.getClass().getName()) .put("exceptionMessage", e.getMessage()); }
public ProcessingException(final String message, final Throwable e) { processingMessage = new ProcessingMessage().setLogLevel(LogLevel.FATAL) .setMessage(message).put("exceptionClass", e.getClass().getName()) .put("exceptionMessage", e.getMessage()); }
private ProcessingMessage newMsg(final SchemaTree tree, final String key) { return new ProcessingMessage().put("schema", tree) .put("domain", "syntax").setMessage(bundle.getMessage(key)); }
@Override public void checkSyntax(final Collection<JsonPointer> pointers, final MessageBundle bundle, final ProcessingReport report, final SchemaTree tree) throws ProcessingException { report.error(new ProcessingMessage().setMessage(ERRMSG)); } });
@Test public void argumentsShowUpInMessage() { final ProcessingMessage message = new ProcessingMessage() .setMessage("Hello %s!").putArgument("greeted", "world"); assertEquals(message.getMessage(), "Hello world!"); }
@Test public void missingFormatArgumentsCausesFormatItselfToBeReturned() { final String format = "%s%s"; final ProcessingMessage message = new ProcessingMessage() .setMessage(format).putArgument("arg1", 1); assertEquals(message.getMessage(), format); }
@Test public void msgMethodSetsMessageField() { final ProcessingMessage msg = new ProcessingMessage().setMessage("foo"); assertMessage(msg).hasMessage("foo"); }
@Test public void processingExceptionMessageIsSameAsProcessingMessage() { final ProcessingMessage message = new ProcessingMessage() .setMessage(FOO); final ProcessingException exception = new ProcessingException(message); assertEquals(exception.getMessage(), message.toString()); }