SendFeatureMessageResponse extends AbstractMessageCommandResponse<T, SendFeatureMessageResponse<T>> implements WithFeatureId { @Deprecated public static <T> SendFeatureMessageResponse<T> of(final String thingId, final String featureId, final Message<T> message, final HttpStatusCode responseStatusCode, final DittoHeaders dittoHeaders) { return of(ThingId.of(thingId), featureId, message, responseStatusCode, dittoHeaders); } private  SendFeatureMessageResponse(final ThingId thingId,
            final String featureId,
            final Message<T> message,
            final HttpStatusCode responseStatusCode,
            final DittoHeaders dittoHeaders); @Override SendFeatureMessageResponse setDittoHeaders(final DittoHeaders dittoHeaders); @Deprecated static SendFeatureMessageResponse<T> of(final String thingId,
            final String featureId,
            final Message<T> message,
            final HttpStatusCode responseStatusCode,
            final DittoHeaders dittoHeaders); static SendFeatureMessageResponse<T> of(final ThingId thingId,
            final String featureId,
            final Message<T> message,
            final HttpStatusCode responseStatusCode,
            final DittoHeaders dittoHeaders); static SendFeatureMessageResponse<?> fromJson(final String jsonString, final DittoHeaders dittoHeaders); static SendFeatureMessageResponse<?> fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders); @Override String getFeatureId(); @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 public void validatesThatFeatureIDIsPresentInMessageHeaders() { final String featureId = "foo"; final ThingId thingId = ThingId.generateRandom(); final String subject = "bar"; final MessageHeaders messageHeadersWithoutFeatureId = MessageHeaders.newBuilder(MessageDirection.TO, thingId, subject).build(); final Message<Object> message = Message.newBuilder(messageHeadersWithoutFeatureId).build(); final DittoHeaders dittoHeaders = DittoHeaders.empty(); assertThatExceptionOfType(FeatureIdInvalidException.class) .isThrownBy(() -> SendFeatureMessageResponse.of(thingId, featureId, message, HttpStatusCode.MULTI_STATUS, dittoHeaders)) .withMessage("The Message did not contain a feature ID at all! Expected was feature ID <foo>."); }
@Test public void validatesThatFeatureIDIsEqualInHeadersAndWrappingCommand() { final String featureId = "foo"; final ThingId thingId = ThingId.generateRandom(); final String subject = "bar"; final MessageHeaders messageHeadersWithDifferentFeatureId = MessageHeaders.newBuilder(MessageDirection.TO, thingId, subject) .featureId("bumlux") .build(); final Message<Object> message = Message.newBuilder(messageHeadersWithDifferentFeatureId).build(); final DittoHeaders dittoHeaders = DittoHeaders.empty(); assertThatExceptionOfType(FeatureIdInvalidException.class) .isThrownBy(() -> SendFeatureMessageResponse.of(thingId, featureId, message, HttpStatusCode.MULTI_STATUS, dittoHeaders)) .withMessage("The Message contained feature ID <bumlux>. Expected was feature ID <foo>."); }
@Test public void instantiatingAFeatureMessageResponseWorksWithEqualFeatureIds() { final String featureId = "foo"; final ThingId thingId = ThingId.generateRandom(); final String subject = "bar"; final MessageHeaders messageHeadersWithDifferentFeatureId = MessageHeaders.newBuilder(MessageDirection.TO, thingId, subject) .featureId("foo") .build(); final Message<Object> message = Message.newBuilder(messageHeadersWithDifferentFeatureId).build(); final DittoHeaders dittoHeaders = DittoHeaders.empty(); assertThatCode(() -> SendFeatureMessageResponse.of(thingId, featureId, message, HttpStatusCode.MULTI_STATUS, dittoHeaders)) .doesNotThrowAnyException(); }