@Test(timeOut = 1000) public void circularReferencingDuringValidationIsDetected() throws IOException, ProcessingException, JsonPointerException { final JsonNode schemaNode = JsonLoader.fromResource("/other/issue102.json"); final JsonSchemaFactory factory = JsonSchemaFactory.byDefault(); final JsonValidator validator = factory.getValidator(); final MessageBundle bundle = MessageBundles.getBundle(JsonSchemaValidationBundle.class); try { validator.validate(schemaNode, JacksonUtils.nodeFactory().nullNode()); fail("No exception thrown!"); } catch (ProcessingException e) { final URI uri = URI.create("#/oneOf/1"); final ProcessingMessage message = e.getProcessingMessage(); final String expectedMessage = bundle.printf("err.common.validationLoop", uri, ""); assertMessage(message) .hasMessage(expectedMessage) .hasField("alreadyVisited", uri) .hasField("instancePointer", JsonPointer.empty().toString()) .hasField("validationPath", Arrays.asList("#", "#/oneOf/1")); } assertTrue(true); }
public JsonSchemaViolationCause(ProcessingException exception) { messages = singletonList(exception.getProcessingMessage()); }
public JsonSchemaViolationCause(ProcessingException exception) { messages = singletonList(exception.getProcessingMessage()); }
private ConnectJsonSchemaValidationResult validate(JsonNode descriptorNode, JsonSchema schema) { ConnectJsonSchemaValidationResult result; try { ListProcessingReport report = (ListProcessingReport) schema.validate(descriptorNode); result = new DescriptorValidationResult(report); } catch (ProcessingException e) { result = new DescriptorValidationResult(true, false, e.getProcessingMessage().asJson().toString(), e.getProcessingMessage().toString()); } return result; }
private ConnectJsonSchemaValidationResult validate(JsonNode descriptorNode, JsonSchema schema) { ConnectJsonSchemaValidationResult result; try { ListProcessingReport report = (ListProcessingReport) schema.validate(descriptorNode); result = new DescriptorValidationResult(report); } catch (ProcessingException e) { result = new DescriptorValidationResult(true, false, e.getProcessingMessage().asJson().toString(), e.getProcessingMessage().toString()); } return result; }
public Set<SwaggerError> validate(JsonDocument document) { final ErrorProcessor processor = new ErrorProcessor(document.getYaml(), schema); final Set<SwaggerError> errors = new HashSet<>(); JsonSchema jsonSchema = null; try { jsonSchema = factory.getJsonSchema(schema); } catch (ProcessingException e) { YEditLog.logException(e); return errors; } try { errors.addAll(processor.processReport(jsonSchema.validate(document.asJson(), true))); } catch (ProcessingException e) { errors.addAll(processor.processMessage(e.getProcessingMessage())); } return errors; }
@Test public void noSuccessfulPredicateAndNoDefaultThrowsException() { when(predicate1.apply(input)).thenReturn(false); when(predicate2.apply(input)).thenReturn(false); final Processor<In, Out> processor = selector.getProcessor(); try { processor.process(report, input); fail("No exception thrown!!"); } catch (ProcessingException e) { verifyZeroInteractions(processor1, processor2); for (final Processor<In, Out> p: otherProcessors) verifyZeroInteractions(p); assertMessage(e.getProcessingMessage()) .hasMessage(BUNDLE.getMessage("processing.noProcessor")); } }
private static ProcessingReport buildReport(final ProcessingReport report, final ProcessingException e) { final ListProcessingReport ret = new ListProcessingReport(LogLevel.DEBUG, LogLevel.NONE); try { ret.fatal(e.getProcessingMessage() .put("info", BUNDLE.getMessage("processing.moreMessages"))); ret.mergeWith(report); } catch (ProcessingException ignored) { // can't happen } return ret; } }
private static ProcessingReport buildReport(final ProcessingReport report, final ProcessingException e) { final ListProcessingReport ret = new ListProcessingReport(LogLevel.DEBUG, LogLevel.NONE); try { ret.fatal(e.getProcessingMessage() .put("info", BUNDLE.getMessage("processing.moreMessages"))); ret.mergeWith(report); } catch (ProcessingException ignored) { // can't happen } return ret; } }
private static ProcessingReport buildReport(final ProcessingReport report, final ProcessingException e) { final ListProcessingReport ret = new ListProcessingReport(LogLevel.DEBUG, LogLevel.NONE); try { ret.fatal(e.getProcessingMessage() .put("info", BUNDLE.getMessage("processing.moreMessages"))); ret.mergeWith(report); } catch (ProcessingException ignored) { // can't happen } return ret; } }
@Test public void innerExceptionClassAndMessageAreReported() { final Exception inner = new Foo(FOO); final ProcessingException exception = new ProcessingException("", inner); final ProcessingMessage message = exception.getProcessingMessage(); assertMessage(message).hasField("exceptionClass", Foo.class.getName()) .hasField("exceptionMessage", inner.getMessage()); }
@Test public void noMatchingKeyAndNoDefaultProcessorThrowsException() { final ProcessorMap<Key, In, Out> processorMap = new ProcessorMap<Key, In, Out>(fn) .addEntry(Key.ONE, processor1).addEntry(Key.TWO, processor2); when(fn.apply(input)).thenReturn(Key.THREE); final Processor<In, Out> processor = processorMap.getProcessor(); try { processor.process(report, input); fail("No exception thrown!!"); } catch (ProcessingException e) { assertMessage(e.getProcessingMessage()) .hasMessage(BUNDLE.getMessage("processing.noProcessor")) .hasField("key", Key.THREE); } }
.validate(content, true); } catch (final ProcessingException e) { return getProcessingMessage(e.getProcessingMessage(), "processingError", keyPrefix);
@Test public void NonAbsoluteURIsAreRefused() { final SchemaLoader loader = new SchemaLoader(); final URI target = URI.create("moo#"); try { loader.get(target); fail("No exception thrown!"); } catch (ProcessingException e) { assertMessage(e.getProcessingMessage()) .hasMessage(BUNDLE.printf("refProcessing.uriNotAbsolute", target)) .hasLevel(LogLevel.FATAL).hasField("uri", target); } }
@Test public void refLoopsAreReported() { final ObjectNode node = JacksonUtils.nodeFactory().objectNode(); node.put("$ref", "#"); final SchemaTree tree = new CanonicalSchemaTree(SchemaKey.anonymousKey(), node); final ValueHolder<SchemaTree> holder = ValueHolder.hold("schema", tree); try { processor.process(report, holder); fail("No exception thrown!"); } catch (ProcessingException e) { assertMessage(e.getProcessingMessage()) .hasMessage(BUNDLE.printf("refProcessing.refLoop", "#")); } }
@Test public void failingOnErrorExitsEarly() throws ProcessingException { @SuppressWarnings("unchecked") final Processor<MessageProvider, MessageProvider> p1 = mock(Processor.class); @SuppressWarnings("unchecked") final Processor<MessageProvider, MessageProvider> p2 = mock(Processor.class); final Processor<MessageProvider, MessageProvider> processor = ProcessorChain.startWith(p1).failOnError().chainWith(p2) .getProcessor(); final MessageProvider input = mock(MessageProvider.class); final ProcessingReport report = new DummyReport(LogLevel.ERROR); try { processor.process(report, input); fail("No exception thrown!!"); } catch (ProcessingException e) { assertMessage(e.getProcessingMessage()) .hasMessage(BUNDLE.getMessage("processing.chainStopped")); } verify(p1).process(same(report), any(MessageProvider.class)); verify(p2, never()).process(any(ProcessingReport.class), any(MessageProvider.class)); }
@Test public void danglingRefsAreReported() { final ObjectNode node = JacksonUtils.nodeFactory().objectNode(); node.put("$ref", "#/a"); final SchemaTree tree = new CanonicalSchemaTree(SchemaKey.anonymousKey(), node); final ValueHolder<SchemaTree> holder = ValueHolder.hold("schema", tree); try { processor.process(report, holder); fail("No exception thrown!"); } catch (ProcessingException e) { assertMessage(e.getProcessingMessage()) .hasMessage(BUNDLE.printf("refProcessing.danglingRef", "#/a")); } } }
@Test public void nonJSONInputShouldBeReportedAsSuch() throws IOException { final URI uri = URI.create("foo://bar"); final InputStream sampleStream = new ByteArrayInputStream("}".getBytes()); when(mock.fetch(any(URI.class))).thenReturn(sampleStream); final LoadingConfiguration cfg = LoadingConfiguration.newBuilder() .addScheme("foo", mock).freeze(); final URIManager manager = new URIManager(cfg); try { manager.getContent(uri); } catch (ProcessingException e) { assertMessage(e.getProcessingMessage()) .hasMessage(BUNDLE.printf("uriManager.uriNotJson", uri)) .hasTextField("parsingMessage").hasLevel(LogLevel.FATAL) .hasField("uri", uri); } }
@Test public void downloaderProblemsShouldBeReportedAsSuch() throws IOException { final URI uri = URI.create("foo://bar"); final Exception foo = new IOException("foo"); when(mock.fetch(any(URI.class))).thenThrow(foo); final LoadingConfiguration cfg = LoadingConfiguration.newBuilder() .addScheme("foo", mock).freeze(); final URIManager manager = new URIManager(cfg); try { manager.getContent(uri); } catch (ProcessingException e) { assertMessage(e.getProcessingMessage()) .hasMessage(BUNDLE.printf("uriManager.uriIOError", uri)) .hasField("uri", uri).hasLevel(LogLevel.FATAL) .hasField("exceptionMessage", "foo"); } }
@Test public void unhandledSchemeShouldBeReportedAsSuch() { final URI uri = URI.create("bar://baz"); final URIManager manager = new URIManager(); try { manager.getContent(uri); } catch (ProcessingException e) { assertMessage(e.getProcessingMessage()) .hasMessage(BUNDLE.printf("refProcessing.unhandledScheme", "bar", uri)) .hasField("scheme", "bar").hasField("uri", uri) .hasLevel(LogLevel.FATAL); } }