@Override public final boolean isSuccess() { return currentLevel.compareTo(LogLevel.ERROR) < 0; }
@Test(dataProvider = "getLogLevels") public void logThresholdIsRespected(final LogLevel logLevel) throws ProcessingException { final AbstractProcessingReport report = spy(new LogThreshold(logLevel)); final ProcessingMessage message = new ProcessingMessage(); // OK, that's ugly, but it works... final int count = LogLevel.NONE.ordinal() - logLevel.ordinal(); report.debug(message); report.info(message); report.warn(message); report.error(message); report.fatal(message); verify(report, times(count)).log(any(LogLevel.class), same(message)); }
private static void validate(CanonicalPath dataPath, JsonNode dataNode, JsonNode schemaNode) { //explicitly allow null schemas if (dataNode == null || dataNode.isNull()) { return; } try { ProcessingReport report = VALIDATOR.validate(schemaNode, dataNode, true); if (!report.isSuccess()) { List<ValidationMessage> messages = new ArrayList<>(); report.forEach((m) -> messages.add(new ValidationMessage(m.getLogLevel().name(), m.toString()))); throw new ValidationException(dataPath, messages, null); } } catch (ProcessingException e) { throw new ValidationException(dataPath, emptyList(), e); } }
@Test public void settingLogThresholdWorks() { final ProcessingMessage msg = new ProcessingMessage(); for (final LogLevel level: LogLevel.values()) { msg.setLogLevel(level); assertMessage(msg).hasLevel(level); } }
@Override public final boolean isSuccess() { return currentLevel.compareTo(LogLevel.ERROR) < 0; }
@Override public final boolean isSuccess() { return currentLevel.compareTo(LogLevel.ERROR) < 0; }
/** * Main dispatch method * * All messages logged go through this method. According to the report * configuration, the message will either be ignored, logged or raise an * exception. * * @param message the message to log * @throws ProcessingException the message's level and report configuration * require that an exception be thrown */ private void dispatch(final ProcessingMessage message) throws ProcessingException { final LogLevel level = message.getLogLevel(); if (level.compareTo(exceptionThreshold) >= 0) throw message.asException(); if (level.compareTo(currentLevel) > 0) currentLevel = level; if (level.compareTo(logLevel) >= 0) log(message); }
/** * Main dispatch method * * <p>All messages logged go through this method. According to the report * configuration, the message will either be ignored, logged or raise an * exception.</p> * * @param message the message to log * @throws ProcessingException the message's level and report configuration * require that an exception be thrown */ protected final void dispatch(final ProcessingMessage message) throws ProcessingException { final LogLevel level = message.getLogLevel(); if (level.compareTo(exceptionThreshold) >= 0) throw message.asException(); if (level.compareTo(currentLevel) > 0) currentLevel = level; if (level.compareTo(logLevel) >= 0) log(level, message); }
/** * Main dispatch method * * <p>All messages logged go through this method. According to the report * configuration, the message will either be ignored, logged or raise an * exception.</p> * * @param message the message to log * @throws ProcessingException the message's level and report configuration * require that an exception be thrown */ protected final void dispatch(final ProcessingMessage message) throws ProcessingException { final LogLevel level = message.getLogLevel(); if (level.compareTo(exceptionThreshold) >= 0) throw message.asException(); if (level.compareTo(currentLevel) > 0) currentLevel = level; if (level.compareTo(logLevel) >= 0) log(level, message); }
/** * Main dispatch method * * <p>All messages logged go through this method. According to the report * configuration, the message will either be ignored, logged or raise an * exception.</p> * * @param message the message to log * @throws ProcessingException the message's level and report configuration * require that an exception be thrown */ protected final void dispatch(final ProcessingMessage message) throws ProcessingException { final LogLevel level = message.getLogLevel(); if (level.compareTo(exceptionThreshold) >= 0) throw message.asException(); if (level.compareTo(currentLevel) > 0) currentLevel = level; if (level.compareTo(logLevel) >= 0) log(level, message); }
@Override public final void mergeWith(final ProcessingReport other) throws ProcessingException { /* * The other report may have no messages, and as such the successful * status won't be overriden: we have to do that instead */ if (!other.isSuccess() && currentLevel.compareTo(LogLevel.ERROR) < 0) currentLevel = LogLevel.ERROR; for (final ProcessingMessage message: other) dispatch(message); }
@Override public final void mergeWith(final ProcessingReport other) throws ProcessingException { /* * The other report may have no messages, and as such the successful * status won't be overriden: we have to do that instead */ if (!other.isSuccess() && currentLevel.compareTo(LogLevel.ERROR) < 0) currentLevel = LogLevel.ERROR; for (final ProcessingMessage message: other) dispatch(message); }
@Override public final void mergeWith(final ProcessingReport other) throws ProcessingException { /* * The other report may have no messages, and as such the successful * status won't be overriden: we have to do that instead */ if (!other.isSuccess() && currentLevel.compareTo(LogLevel.ERROR) < 0) currentLevel = LogLevel.ERROR; for (final ProcessingMessage message: other) dispatch(message); }
private void validateWithSchema(JsonNode model) { createValidator(); try { ProcessingReport report = validator.validate(model); if (report != null) { List<String> msgs = Lists.newArrayList(); report.forEach(msg -> { if (msg.getLogLevel().compareTo(LogLevel.ERROR) >= 0) { String ptr = msg.asJson().at("/instance/pointer").asText(); msgs.add(String.format("At %s: %s", ptr.isEmpty() ? "/" : ptr, msg.getMessage())); } }); if (!msgs.isEmpty()) { throw new RealizationModelParseException(msgs); } } } catch (ProcessingException e) { e.printStackTrace(); } }