InfoProviderFactory { public static ConnectionMonitor.InfoProvider forSignal(final Signal<?> signal) { final String correlationId = extractCorrelationId(signal.getDittoHeaders()); final Instant timestamp = Instant.now(); final ThingId thingId = extractThingId(signal); final Supplier<String> payloadSupplier = supplyPayloadFromSignal(signal); return new ImmutableInfoProvider(correlationId, timestamp, thingId, signal.getDittoHeaders(), payloadSupplier, false); } private  InfoProviderFactory(); static ConnectionMonitor.InfoProvider forExternalMessage(final ExternalMessage externalMessage); static ConnectionMonitor.InfoProvider forSignal(final Signal<?> signal); static ConnectionMonitor.InfoProvider forHeaders(final Map<String, String> headers); static ConnectionMonitor.InfoProvider empty();  }
@Test public void forSignal() { final ThingId thingId = ThingId.of("the:thing"); final String correlationId = "theCorrelation"; final DittoHeaders headersWithCorrelationId = DittoHeaders.newBuilder().correlationId(correlationId).build(); final Signal<?> signal = RetrieveThing.of(thingId, headersWithCorrelationId); final Instant before = Instant.now(); final ConnectionMonitor.InfoProvider info = InfoProviderFactory.forSignal(signal); final Instant after = Instant.now(); assertThat(info) .hasThingId(thingId) .hasCorrelationId(correlationId) .hasTimestampBetween(before, after); }
@Test public void forSignalWithHeaders() { final DittoHeaders headers = DittoHeaders.newBuilder() .putHeader("foo", "bar") .putHeader("138", "ditto") .build(); final Signal<?> signal = RetrieveThing.of(ThingId.of("the:thing"), headers); final ConnectionMonitor.InfoProvider info = InfoProviderFactory.forSignal(signal); assertThat(info).hasHeaders(headers); }
@Test public void forSignalWithPayload() { final DittoHeaders headers = DittoHeaders.newBuilder() .putHeader("foo", "bar") .putHeader("138", "ditto") .build(); final Signal<?> signal = RetrieveThing.of(ThingId.of("the:thing"), headers); final String expectedTextPayload = signal.toJsonString(); final ConnectionMonitor.InfoProvider info = InfoProviderFactory.forSignal(signal); assertThat(info).hasPayload(expectedTextPayload); }