SendFeatureMessage extends AbstractMessageCommand<T, SendFeatureMessage<T>> implements WithFeatureId { @Deprecated public static <T> SendFeatureMessage<T> of(final String thingId, final String featureId, final Message<T> message, final DittoHeaders dittoHeaders) { return of(ThingId.of(thingId), featureId, message, dittoHeaders); } private  SendFeatureMessage(final ThingId thingId,
            final String featureId,
            final Message<T> message,
            final DittoHeaders dittoHeaders); @Deprecated static SendFeatureMessage<T> of(final String thingId,
            final String featureId,
            final Message<T> message,
            final DittoHeaders dittoHeaders); static SendFeatureMessage<T> of(final ThingId thingId,
            final String featureId,
            final Message<T> message,
            final DittoHeaders dittoHeaders); static SendFeatureMessage<?> fromJson(final String jsonString, final DittoHeaders dittoHeaders); static SendFeatureMessage<?> fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders); @Override String getFeatureId(); @Override SendFeatureMessage setDittoHeaders(final DittoHeaders dittoHeaders); @SuppressWarnings("squid:S109") @Override int hashCode(); @SuppressWarnings("squid:MethodCyclomaticComplexity") @Override boolean equals(@Nullable final Object obj); @Override String toString(); static final String NAME; static final String TYPE; }
@Test(expected = org.eclipse.ditto.model.things.ThingIdInvalidException.class) public void tryCreateWithNullThingIdString() { SendFeatureMessage.of((String) null, FEATURE_ID, MESSAGE, DITTO_HEADERS); }
@Test(expected = NullPointerException.class) public void tryCreateWithNullThingId() { SendFeatureMessage.of((ThingId) null, FEATURE_ID, MESSAGE, DITTO_HEADERS); }
@Test(expected = NullPointerException.class) public void tryCreateWithNullFeatureId() { SendFeatureMessage.of(THING_ID, null, MESSAGE, DITTO_HEADERS); }
@Test(expected = NullPointerException.class) public void tryCreateWithNullMessage() { SendFeatureMessage.of(THING_ID, FEATURE_ID, null, DITTO_HEADERS); }
@Test(expected = NullPointerException.class) public void tryCreateWithNullDittoHeaders() { SendFeatureMessage.of(THING_ID, FEATURE_ID, MESSAGE, null); }
@Test public void tryToCreateInstanceWithNonMatchingThingId() { final ThingId notMatchingThingId = ThingId.of(THING_ID.getNamespace(), THING_ID.getName() + "-nomatch"); assertThatExceptionOfType(ThingIdInvalidException.class) .isThrownBy(() -> SendFeatureMessage.of(notMatchingThingId, FEATURE_ID, MESSAGE, DITTO_HEADERS)) .withMessageContaining("-nomatch") .withNoCause(); }
@Test public void tryToCreateInstanceWithMissingFeatureId() { final MessageHeaders messageHeaders = MessageHeaders.newBuilder(MessageDirection.TO, THING_ID, SUBJECT) .contentType(CONTENT_TYPE) .build(); final Message<Object> message = MessagesModelFactory.newMessageBuilder(messageHeaders) .payload(JsonFactory.newObject(KNOWN_RAW_PAYLOAD_STR)) .build(); assertThatExceptionOfType(FeatureIdInvalidException.class) .isThrownBy(() -> SendFeatureMessage.of(THING_ID, FEATURE_ID, message, DITTO_HEADERS)) .withMessage("The Message did not contain a feature ID at all! Expected was feature ID <%s>.", FEATURE_ID) .withNoCause(); }
@Test public void tryToCreateInstanceWithNonMatchingFeatureId() { final String expectedFeatureId = FEATURE_ID + "-nomatch"; assertThatExceptionOfType(FeatureIdInvalidException.class) .isThrownBy(() -> SendFeatureMessage.of(THING_ID, expectedFeatureId, MESSAGE, DITTO_HEADERS)) .withMessage("The Message contained feature ID <%s>. Expected was feature ID <%s>.", FEATURE_ID, expectedFeatureId) .withNoCause(); }
@Test public void tryCreateValidMessage() { SendFeatureMessage.of(THING_ID, FEATURE_ID, MESSAGE, DITTO_HEADERS); }
@Test public void toJsonReturnsExpected() { final SendFeatureMessage<?> underTest = SendFeatureMessage.of(THING_ID, FEATURE_ID, MESSAGE, TestConstants.EMPTY_DITTO_HEADERS); final JsonObject actualJson = underTest.toJson(FieldType.regularOrSpecial()); assertThat(actualJson).isEqualTo(KNOWN_JSON); }