AcknowledgementsAdapter implements Adapter<Acknowledgements> { @Override public Adaptable toAdaptable(final Acknowledgements acknowledgements, final TopicPath.Channel channel) { return Adaptable.newBuilder(getTopicPath(acknowledgements, channel)) .withPayload(getPayload(acknowledgements)) .withHeaders(getExternalHeaders(acknowledgements.getDittoHeaders())) .build(); } private  AcknowledgementsAdapter(final HeaderTranslator headerTranslator); @Override Acknowledgements fromAdaptable(final Adaptable adaptable); @Override Adaptable toAdaptable(final Acknowledgements acknowledgements, final TopicPath.Channel channel); @Override Set<TopicPath.Group> getGroups(); @Override Set<TopicPath.Channel> getChannels(); @Override Set<TopicPath.Criterion> getCriteria(); @Override Set<TopicPath.Action> getActions(); @Override boolean isForResponses(); @Override boolean requiresSubject();  }
@Test public void acknowledgementsContaining1ToAdaptable() { final Acknowledgements acknowledgements = ThingAcknowledgementsFactory.newAcknowledgements( Collections.singletonList(KNOWN_ACK_2_ERROR), KNOWN_HEADERS); final Adaptable expected = Adaptable.newBuilder(topicPathMyCustomAck) .withPayload(Payload.newBuilder(JsonPointer.empty()) .withStatus(KNOWN_STATUS_2) .withValue(JsonObject.newBuilder() .set(KNOWN_CUSTOM_LABEL_2, JsonObject.newBuilder() .set("status", KNOWN_STATUS_2.toInt()) .set("headers", KNOWN_HEADERS_2.toJson()) .build()) .build()) .build()) .build(); final Adaptable actual = underTest.toAdaptable(acknowledgements); assertWithExternalHeadersThat(actual).isEqualTo(expected); }
@Test public void acknowledgementsContaining2successAndErrorToAdaptable() { final Acknowledgements acknowledgements = ThingAcknowledgementsFactory.newAcknowledgements( Arrays.asList(KNOWN_ACK_SUCCESS, KNOWN_ACK_2_ERROR), KNOWN_HEADERS); final Adaptable expected = Adaptable.newBuilder(topicPathMyCustomAck) .withPayload(Payload.newBuilder(JsonPointer.empty()) .withStatus(HttpStatusCode.FAILED_DEPENDENCY) .withValue(JsonObject.newBuilder() .set(KNOWN_CUSTOM_LABEL, JsonObject.newBuilder() .set("status", KNOWN_STATUS.toInt()) .set("payload", KNOWN_PAYLOAD) .set("headers", KNOWN_HEADERS.toJson()) .build()) .set(KNOWN_CUSTOM_LABEL_2, JsonObject.newBuilder() .set("status", KNOWN_STATUS_2.toInt()) .set("headers", KNOWN_HEADERS_2.toJson()) .build()) .build() ).build() ).build(); final Adaptable actual = underTest.toAdaptable(acknowledgements); assertWithExternalHeadersThat(actual).isEqualTo(expected); }
@Test public void acknowledgementsContaining2bothSuccessToAdaptable() { final Acknowledgements acknowledgements = ThingAcknowledgementsFactory.newAcknowledgements( Arrays.asList(KNOWN_ACK_SUCCESS, KNOWN_ACK_3_SUCCESS), KNOWN_HEADERS); final Adaptable expected = Adaptable.newBuilder(topicPathMyCustomAck) .withPayload(Payload.newBuilder(JsonPointer.empty()) .withStatus(HttpStatusCode.OK) .withValue(JsonObject.newBuilder() .set(KNOWN_CUSTOM_LABEL, JsonObject.newBuilder() .set("status", KNOWN_STATUS.toInt()) .set("payload", KNOWN_PAYLOAD) .set("headers", KNOWN_HEADERS.toJson()) .build()) .set(KNOWN_CUSTOM_LABEL_3, JsonObject.newBuilder() .set("status", KNOWN_STATUS_3.toInt()) .set("payload", KNOWN_PAYLOAD_3) .set("headers", KNOWN_HEADERS_3.toJson()) .build()) .build() ).build() ).build(); final Adaptable actual = underTest.toAdaptable(acknowledgements); assertWithExternalHeadersThat(actual).isEqualTo(expected); }
@Test public void acknowledgementsContaining3ToAdaptable() { final Acknowledgements acknowledgements = ThingAcknowledgementsFactory.newAcknowledgements( Arrays.asList(KNOWN_ACK_SUCCESS, KNOWN_ACK_2_ERROR, KNOWN_ACK_3_SUCCESS), KNOWN_HEADERS); final Adaptable expected = Adaptable.newBuilder(topicPathMyCustomAck) .withPayload(Payload.newBuilder(JsonPointer.empty()) .withStatus(HttpStatusCode.FAILED_DEPENDENCY) .withValue(JsonObject.newBuilder() .set(KNOWN_CUSTOM_LABEL, JsonObject.newBuilder() .set("status", KNOWN_STATUS.toInt()) .set("payload", KNOWN_PAYLOAD) .set("headers", KNOWN_HEADERS.toJson()) .build()) .set(KNOWN_CUSTOM_LABEL_2, JsonObject.newBuilder() .set("status", KNOWN_STATUS_2.toInt()) .set("headers", KNOWN_HEADERS_2.toJson()) .build()) .set(KNOWN_CUSTOM_LABEL_3, JsonObject.newBuilder() .set("status", KNOWN_STATUS_3.toInt()) .set("payload", KNOWN_PAYLOAD_3) .set("headers", KNOWN_HEADERS_3.toJson()) .build()) .build() ).build() ).build(); final Adaptable actual = underTest.toAdaptable(acknowledgements); assertWithExternalHeadersThat(actual).isEqualTo(expected); }