ImmutableMessageHeaders extends AbstractDittoHeaders implements MessageHeaders { static MessageHeaders of(final DittoHeaders dittoHeaders) { return new ImmutableMessageHeaders(checkNotNull(dittoHeaders, "Ditto Headers")); } private  ImmutableMessageHeaders(final Map<String, String> theDittoHeaders); @Override MessageDirection getDirection(); @Override String getSubject(); @Override ThingId getThingEntityId(); @Override Optional<String> getFeatureId(); @Override Optional<OffsetDateTime> getTimestamp(); @Override Optional<HttpStatusCode> getStatusCode(); @Override String toString();  }
@Test public void createInstanceOfValidHeaderMapWorksAsExpected() { final Map<String, String> initialHeaders = createMapContainingAllKnownHeaders(); final MessageHeaders underTest = MessageHeadersBuilder.of(initialHeaders).build(); assertThat(underTest).isEqualTo(initialHeaders); }
@Test public void createInstanceOfValidHeaderJsonObjectWorksAsExpected() { final Map<String, String> allKnownHeaders = createMapContainingAllKnownHeaders(); final JsonObjectBuilder jsonObjectBuilder = JsonFactory.newObjectBuilder(); allKnownHeaders.forEach(jsonObjectBuilder::set); final JsonObject headersJsonObject = jsonObjectBuilder.build(); final MessageHeaders underTest = MessageHeadersBuilder.of(headersJsonObject).build(); assertThat(underTest).isEqualTo(allKnownHeaders); }
@Test public void getDirectionAlthoughItIsNotSet() { final MessageHeaders underTest = ImmutableMessageHeaders.of(DittoHeaders.empty()); assertThatExceptionOfType(IllegalStateException.class) .isThrownBy(underTest::getDirection) .withMessage("MessageHeaders did not contain a value for key <%s>!", MessageHeaderDefinition.DIRECTION.getKey()) .withNoCause(); }
@Test public void getSubjectAlthoughItIsNotSet() { final MessageHeaders underTest = ImmutableMessageHeaders.of(DittoHeaders.empty()); assertThatExceptionOfType(IllegalStateException.class) .isThrownBy(underTest::getSubject) .withMessage("MessageHeaders did not contain a value for key <%s>!", MessageHeaderDefinition.SUBJECT.getKey()) .withNoCause(); }
@Test public void getThingIdAlthoughItIsNotSet() { final MessageHeaders underTest = ImmutableMessageHeaders.of(DittoHeaders.empty()); assertThatExceptionOfType(IllegalStateException.class) .isThrownBy(underTest::getThingEntityId) .withMessage("MessageHeaders did not contain a value for key <%s>!", MessageHeaderDefinition.THING_ID.getKey()) .withNoCause(); }