DittoAckRequestsFilter extends AbstractHeaderEntryFilter { public static DittoAckRequestsFilter getInstance() { return INSTANCE; } private  DittoAckRequestsFilter(); static DittoAckRequestsFilter getInstance(); @Override @Nullable String filterValue(final String key, final String value);  }
@Test public void filterValueWithoutMatchingHeaderDefinition() { final String key = "foo"; final String value = "bar"; final DittoAckRequestsFilter underTest = DittoAckRequestsFilter.getInstance(); assertThat(underTest.apply(key, value)).isEqualTo(value); }
@Test public void filterValueWithTwinPersistedOnlyAckRequest() { final DittoHeaderDefinition headerDefinition = DittoHeaderDefinition.REQUESTED_ACKS; final AcknowledgementRequest twinPersistedAckRequest = AcknowledgementRequest.of(DittoAcknowledgementLabel.TWIN_PERSISTED); final JsonArray ackRequestsJsonArray = JsonArray.newBuilder().add(twinPersistedAckRequest.toString()).build(); final DittoAckRequestsFilter underTest = DittoAckRequestsFilter.getInstance(); assertThat(underTest.apply(headerDefinition.getKey(), ackRequestsJsonArray.toString())).isNull(); }
@Test public void filterEmptyStringValue() { final DittoHeaderDefinition headerDefinition = DittoHeaderDefinition.REQUESTED_ACKS; final DittoAckRequestsFilter underTest = DittoAckRequestsFilter.getInstance(); assertThat(underTest.apply(headerDefinition.getKey(), "")).isNull(); }
@Test public void filterValueWithoutDittoInternalRequests() { final DittoHeaderDefinition headerDefinition = DittoHeaderDefinition.REQUESTED_ACKS; final List<AcknowledgementRequest> acknowledgementRequests = Lists.list( AcknowledgementRequest.of(AcknowledgementLabel.of("foo")), AcknowledgementRequest.of(AcknowledgementLabel.of("bar"))); final JsonArray acknowledgementRequestsJsonArray = acknowledgementRequests.stream() .map(AcknowledgementRequest::toString) .map(JsonValue::of) .collect(JsonCollectors.valuesToArray()); final String value = acknowledgementRequestsJsonArray.toString(); final DittoAckRequestsFilter underTest = DittoAckRequestsFilter.getInstance(); assertThat(underTest.apply(headerDefinition.getKey(), value)).isEqualTo(value); }
@Test public void filterValueWithDittoInternalRequests() { final DittoHeaderDefinition headerDefinition = DittoHeaderDefinition.REQUESTED_ACKS; final List<AcknowledgementRequest> allAcknowledgementRequests = Lists.list( AcknowledgementRequest.of(AcknowledgementLabel.of("foo")), AcknowledgementRequest.of(DittoAcknowledgementLabel.TWIN_PERSISTED), AcknowledgementRequest.of(DittoAcknowledgementLabel.LIVE_RESPONSE), AcknowledgementRequest.of(AcknowledgementLabel.of("bar"))); final JsonArray allAcknowledgementRequestsJsonArray = allAcknowledgementRequests.stream() .map(AcknowledgementRequest::toString) .map(JsonValue::of) .collect(JsonCollectors.valuesToArray()); final String value = allAcknowledgementRequestsJsonArray.toString(); final JsonArray externalAcknowledgementRequests = allAcknowledgementRequestsJsonArray.toBuilder() .remove(2) .remove(1) .build(); final String expected = externalAcknowledgementRequests.toString(); final DittoAckRequestsFilter underTest = DittoAckRequestsFilter.getInstance(); assertThat(underTest.apply(headerDefinition.getKey(), value)).isEqualTo(expected); }
@Test public void filterValueWithEmptyAcknowledgementLabel() { final DittoHeaderDefinition headerDefinition = DittoHeaderDefinition.REQUESTED_ACKS; final JsonArray allAcknowledgementRequestsJsonArray = JsonArray.newBuilder() .add("foo", "", "baz") .build(); final String value = allAcknowledgementRequestsJsonArray.toString(); final JsonArray externalAcknowledgementRequests = allAcknowledgementRequestsJsonArray.toBuilder() .remove(1) .build(); final String expected = externalAcknowledgementRequests.toString(); final DittoAckRequestsFilter underTest = DittoAckRequestsFilter.getInstance(); assertThat(underTest.apply(headerDefinition.getKey(), value)).isEqualTo(expected); }