ThingLiveCommandAckRequestSetter extends AbstractCommandAckRequestSetter<ThingCommand<?>> { public static ThingLiveCommandAckRequestSetter getInstance() { return INSTANCE; } private  ThingLiveCommandAckRequestSetter(); static ThingLiveCommandAckRequestSetter getInstance(); @Override boolean isApplicable(final ThingCommand<?> command); @Override @SuppressWarnings({"unchecked", "rawtypes"}) Class<ThingCommand<?>> getMatchedClass();  }
@Test public void tryToApplyNullCommand() { final ThingLiveCommandAckRequestSetter underTest = ThingLiveCommandAckRequestSetter.getInstance(); assertThatNullPointerException() .isThrownBy(() -> underTest.apply(null)) .withMessage("The command must not be null!") .withNoCause(); }
@Test public void removeLiveResponseAckLabelIfNoResponseRequired() { final DittoHeaders dittoHeaders = DittoHeaders.newBuilder() .channel("live") .responseRequired(false) .acknowledgementRequest(AcknowledgementRequest.of(DittoAcknowledgementLabel.LIVE_RESPONSE)) .randomCorrelationId() .build(); final CreateThing command = CreateThing.of(Thing.newBuilder().build(), null, dittoHeaders); final ThingLiveCommandAckRequestSetter underTest = ThingLiveCommandAckRequestSetter.getInstance(); final DittoHeaders expectedHeaders = dittoHeaders.toBuilder() .acknowledgementRequests(Collections.emptyList()) .build(); final CreateThing expectedCommand = command.setDittoHeaders(expectedHeaders); assertThat(underTest.apply(command)).isEqualTo(expectedCommand); }
@Test public void addLiveResponseAckLabelByDefault() { final DittoHeaders dittoHeaders = DittoHeaders.newBuilder() .channel("live") .randomCorrelationId() .build(); final CreateThing command = CreateThing.of(Thing.newBuilder().build(), null, dittoHeaders); final CreateThing expected = command.setDittoHeaders(DittoHeaders.newBuilder(dittoHeaders) .acknowledgementRequest(AcknowledgementRequest.of(DittoAcknowledgementLabel.LIVE_RESPONSE)) .responseRequired(true) .build()); final ThingLiveCommandAckRequestSetter underTest = ThingLiveCommandAckRequestSetter.getInstance(); assertThat(underTest.apply(command)).isEqualTo(expected); }
@Test public void filterOutOtherBuiltInDittoAcknowledgementLabels() { final DittoHeaders dittoHeaders = DittoHeaders.newBuilder() .channel("live") .acknowledgementRequest(AcknowledgementRequest.of(DittoAcknowledgementLabel.TWIN_PERSISTED), AcknowledgementRequest.of(DittoAcknowledgementLabel.LIVE_RESPONSE)) .randomCorrelationId() .build(); final CreateThing command = CreateThing.of(Thing.newBuilder().build(), null, dittoHeaders); final DittoHeaders expectedHeaders = dittoHeaders.toBuilder() .acknowledgementRequest(AcknowledgementRequest.of(DittoAcknowledgementLabel.LIVE_RESPONSE)) .responseRequired(true) .build(); final CreateThing expected = CreateThing.of(Thing.newBuilder().build(), null, expectedHeaders); final ThingLiveCommandAckRequestSetter underTest = ThingLiveCommandAckRequestSetter.getInstance(); assertThat(underTest.apply(command)).isEqualTo(expected); }
@Test public void addsLiveResponseAckLabelToAlreadyRequiredAckLabels() { final AcknowledgementRequest ackRequest1 = AcknowledgementRequest.of(AcknowledgementLabel.of("FOO")); final AcknowledgementRequest ackRequest2 = AcknowledgementRequest.of(AcknowledgementLabel.of("BAR")); final DittoHeaders dittoHeaders = DittoHeaders.newBuilder() .channel("live") .acknowledgementRequest(ackRequest1, ackRequest2) .randomCorrelationId() .responseRequired(true) .build(); final CreateThing command = CreateThing.of(Thing.newBuilder().build(), null, dittoHeaders); final ThingLiveCommandAckRequestSetter underTest = ThingLiveCommandAckRequestSetter.getInstance(); final DittoHeaders expectedHeaders = dittoHeaders.toBuilder() .acknowledgementRequest(ackRequest1, ackRequest2, AcknowledgementRequest.of(DittoAcknowledgementLabel.LIVE_RESPONSE)) .build(); final CreateThing expectedCommand = command.setDittoHeaders(expectedHeaders); assertThat(underTest.apply(command)).isEqualTo(expectedCommand); }
@Test public void notAddingLiveResponseAckLabelToExplicitlyEmptyRequiredAckLabels() { final DittoHeaders dittoHeaders = DittoHeaders.newBuilder() .channel("live") .acknowledgementRequests(Collections.emptyList()) .randomCorrelationId() .responseRequired(true) .build(); final CreateThing command = CreateThing.of(Thing.newBuilder().build(), null, dittoHeaders); final ThingLiveCommandAckRequestSetter underTest = ThingLiveCommandAckRequestSetter.getInstance(); final DittoHeaders expectedHeaders = dittoHeaders.toBuilder() .acknowledgementRequests(Collections.emptyList()) .build(); final CreateThing expectedCommand = command.setDittoHeaders(expectedHeaders); assertThat(underTest.apply(command)).isEqualTo(expectedCommand); }