EvictingConnectionLogger implements ConnectionLogger { @Override public void success(final ConnectionMonitor.InfoProvider infoProvider) { success(infoProvider, defaultSuccessMessage); } private  EvictingConnectionLogger(final Builder builder); @Override void success(final ConnectionMonitor.InfoProvider infoProvider); @Override void success(final ConnectionMonitor.InfoProvider infoProvider, final String message,
            final Object... messageArguments); @Override void failure(final ConnectionMonitor.InfoProvider infoProvider,
            @Nullable final DittoRuntimeException dittoRuntimeException); @Override void failure(final ConnectionMonitor.InfoProvider infoProvider, final String message,
            final Object... messageArguments); @Override void exception(final ConnectionMonitor.InfoProvider infoProvider, @Nullable final Exception exception); @Override void exception(final ConnectionMonitor.InfoProvider infoProvider, final String message,
            final Object... messageArguments); @Override void clear(); @Override Collection<LogEntry> getLogs(); @SuppressWarnings("OverlyComplexMethod") @Override boolean equals(@Nullable final Object o); @Override int hashCode(); @Override String toString();  }
@Test public void logTypeAndCategoryAreUsedForLogEntries() { final EvictingConnectionLogger logger = builder().build(); logger.success(INFO_PROVIDER_WITH_THING); final LogEntry entry = getFirstAndOnlyEntry(logger); LogEntryAssertions.assertThat(entry) .hasCategory(CATEGORY) .hasType(TYPE) .hasInfo(INFO_PROVIDER_WITH_THING); }
@Test public void withoutDebugLogEnabled() { final EvictingConnectionLogger logger = builder().build(); final String textPayload = "{\"foo\":\"bar\"}"; final ConnectionMonitor.InfoProvider info = infoProviderWithHeaderAndPayloadDebugLogging(textPayload); logger.success(info); final LogEntry entry = getFirstAndOnlyEntry(logger); LogEntryAssertions.assertThat(entry) .hasMessageNotContainingHeaderKeysOrValues(info.getHeaders()) .hasMessageNotContainingPayload(textPayload); }
@Test public void withDebugLogDisabled() { final EvictingConnectionLogger logger = builder().logHeadersAndPayload().build(); final String textPayload = "{\"foo\":\"bar\"}"; final ConnectionMonitor.InfoProvider info = infoProviderWithDebugLoggingDisabled(textPayload); logger.success(info); final LogEntry entry = getFirstAndOnlyEntry(logger); LogEntryAssertions.assertThat(entry) .hasMessageNotContainingPayload(textPayload) .hasMessageContainingHeaderKeys(info.getHeaders()); }
@Test public void withDebugLogEnabled() { final EvictingConnectionLogger logger = builder().logHeadersAndPayload().build(); final String textPayload = "{\"foo\":\"bar\"}"; final ConnectionMonitor.InfoProvider info = randomInfoProviderWithPayload(textPayload); logger.success(info); final LogEntry entry = getFirstAndOnlyEntry(logger); LogEntryAssertions.assertThat(entry) .hasMessageContainingPayload(textPayload) .hasMessageContainingHeaderValues(info.getHeaders()); }
@Test public void withDebugLogHeaders() { final EvictingConnectionLogger logger = builder().logHeadersAndPayload().build(); final ConnectionMonitor.InfoProvider info = infoProviderWithHeadersDebugLogging(); logger.success(info); final LogEntry entry = getFirstAndOnlyEntry(logger); LogEntryAssertions.assertThat(entry) .hasMessageContainingHeaderValues(info.getHeaders()); }
@Test public void withDebugLogPayload() { final EvictingConnectionLogger logger = builder().logHeadersAndPayload().build(); final String textPayload = "{\"foo\":\"bar\"}"; final ConnectionMonitor.InfoProvider info = infoProviderWithPayloadDebugLogging(textPayload); logger.success(info); final LogEntry entry = getFirstAndOnlyEntry(logger); LogEntryAssertions.assertThat(entry) .hasMessageContainingPayload(textPayload); }
@Test public void withDebugLogHeadersAndPayload() { final EvictingConnectionLogger logger = builder().logHeadersAndPayload().build(); final String textPayload = "{\"foo\":\"bar\"}"; final ConnectionMonitor.InfoProvider info = infoProviderWithHeaderAndPayloadDebugLogging(textPayload); logger.success(info); final LogEntry entry = getFirstAndOnlyEntry(logger); LogEntryAssertions.assertThat(entry) .hasMessageContainingPayload(textPayload) .hasMessageContainingHeaderValues(info.getHeaders()); }
@Test public void addressIsUsedForEntries() { final String address = "an: final EvictingConnectionLogger logger = builder().withAddress(address).build(); logger.success(randomInfoProvider()); LogEntryAssertions.assertThat(getFirstAndOnlyEntry(logger)) .hasAddress(address); }
@Test public void ignoresForbiddenMessageFormatCharacters() { final EvictingConnectionLogger logger = builder().logHeadersAndPayload().build(); final String payloadWithBadCharacters = "{curly brackets and single quotes aren't allowed in MsgFmt}"; final ConnectionMonitor.InfoProvider info = infoProviderWithPayloadDebugLogging(payloadWithBadCharacters); logger.success(info, "any message {0}", "that has at least one argument"); final LogEntry entry = getFirstAndOnlyEntry(logger); LogEntryAssertions.assertThat(entry) .hasMessageContainingPayload(payloadWithBadCharacters); }