AcknowledgementsAdapter implements Adapter<Acknowledgements> { @Override public Acknowledgements fromAdaptable(final Adaptable adaptable) { checkNotNull(adaptable, "adaptable"); final ThingId thingId = getThingId(adaptable); return ThingAcknowledgementsFactory.newAcknowledgements( thingId, gatherContainedAcknowledgements(adaptable, thingId), getStatusCodeOrThrow(adaptable), adaptable.getDittoHeaders() ); } 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 acknowledgementsContaining1FromAdaptable() { final Adaptable adaptable = Adaptable.newBuilder(topicPathMyCustomAck) .withHeaders(KNOWN_HEADERS) .withPayload(Payload.newBuilder(JsonPointer.empty()) .withStatus(HttpStatusCode.CREATED) .withValue(JsonObject.newBuilder() .set(KNOWN_CUSTOM_LABEL, JsonObject.newBuilder() .set("status", KNOWN_STATUS.toInt()) .set("payload", KNOWN_PAYLOAD) .build()) .build()) .build()) .build(); final Acknowledgements expected = ThingAcknowledgementsFactory.newAcknowledgements( Collections.singletonList(KNOWN_ACK_SUCCESS.setDittoHeaders(DittoHeaders.empty())), KNOWN_HEADERS); final Acknowledgements actual = underTest.fromAdaptable(adaptable); assertWithExternalHeadersThat(actual).isEqualTo(expected); }
@Test public void acknowledgementsContaining2successAndErrorFromAdaptable() { final Adaptable adaptable = Adaptable.newBuilder(topicPathMyCustomAck) .withHeaders(KNOWN_HEADERS) .withPayload(Payload.newBuilder(JsonPointer.empty()) .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() ) .withStatus(HttpStatusCode.FAILED_DEPENDENCY) .build()) .build(); final Acknowledgements expected = ThingAcknowledgementsFactory.newAcknowledgements( Arrays.asList(KNOWN_ACK_SUCCESS, KNOWN_ACK_2_ERROR), KNOWN_HEADERS); final Acknowledgements actual = underTest.fromAdaptable(adaptable); assertWithExternalHeadersThat(actual).isEqualTo(expected); }
@Test public void acknowledgementsContaining2bothSuccessFromAdaptable() { final Adaptable adaptable = Adaptable.newBuilder(topicPathMyCustomAck) .withHeaders(KNOWN_HEADERS) .withPayload(Payload.newBuilder(JsonPointer.empty()) .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() ) .withStatus(HttpStatusCode.OK) .build()) .build(); final Acknowledgements expected = ThingAcknowledgementsFactory.newAcknowledgements( Arrays.asList(KNOWN_ACK_SUCCESS, KNOWN_ACK_3_SUCCESS), KNOWN_HEADERS); final Acknowledgements actual = underTest.fromAdaptable(adaptable); assertWithExternalHeadersThat(actual).isEqualTo(expected); }
@Test public void acknowledgementsContaining3FromAdaptable() { final Adaptable adaptable = Adaptable.newBuilder(topicPathMyCustomAck) .withHeaders(KNOWN_HEADERS) .withPayload(Payload.newBuilder(JsonPointer.empty()) .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("payload", JsonValue.of(KNOWN_PAYLOAD_2)) .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() ) .withStatus(HttpStatusCode.FAILED_DEPENDENCY) .build()) .build(); final Acknowledgements expected = ThingAcknowledgementsFactory.newAcknowledgements( Arrays.asList(KNOWN_ACK_SUCCESS, KNOWN_ACK_2_ERROR, KNOWN_ACK_3_SUCCESS), KNOWN_HEADERS); final Acknowledgements actual = underTest.fromAdaptable(adaptable); assertWithExternalHeadersThat(actual).isEqualTo(expected); }