ThingQueryCommandResponseAdapter extends AbstractThingAdapter<ThingQueryCommandResponse<?>> implements QueryCommandResponseAdapter<ThingQueryCommandResponse<?>> { public static ThingQueryCommandResponseAdapter of(final HeaderTranslator headerTranslator) { return new ThingQueryCommandResponseAdapter(requireNonNull(headerTranslator)); } private  ThingQueryCommandResponseAdapter(final HeaderTranslator headerTranslator); static ThingQueryCommandResponseAdapter of(final HeaderTranslator headerTranslator); @Override Adaptable mapSignalToAdaptable(final ThingQueryCommandResponse<?> commandResponse,
            final TopicPath.Channel channel);  }
@Test public void retrieveThingResponseFromAdaptable() { final RetrieveThingResponse expected = RetrieveThingResponse.of(THING_ID, TestConstants.THING, TestConstants.DITTO_HEADERS_V_2); final TopicPath topicPath = topicPath(TopicPath.Action.RETRIEVE); final JsonPointer path = JsonPointer.empty(); final Adaptable adaptable = Adaptable.newBuilder(topicPath) .withPayload(Payload.newBuilder(path) .withStatus(HttpStatusCode.OK) .withValue(TestConstants.THING.toJson()) .build()) .withHeaders(TestConstants.HEADERS_V_2) .build(); final ThingQueryCommandResponse<?> actual = underTest.fromAdaptable(adaptable); assertWithExternalHeadersThat(actual).isEqualTo(expected); }
@Test public void retrieveThingResponseToAdaptable() { final JsonPointer path = JsonPointer.empty(); final TopicPath topicPath = topicPath(TopicPath.Action.RETRIEVE); final Adaptable expected = Adaptable.newBuilder(topicPath) .withPayload(Payload.newBuilder(path) .withStatus(HttpStatusCode.OK) .withValue(TestConstants.THING.toJson()) .build()) .withHeaders(TestConstants.HEADERS_V_2) .build(); final RetrieveThingResponse retrieveThing = RetrieveThingResponse.of(THING_ID, TestConstants.THING, TestConstants.HEADERS_V_2_NO_CONTENT_TYPE); final Adaptable actual = underTest.toAdaptable(retrieveThing, channel); assertWithExternalHeadersThat(actual).isEqualTo(expected); }
@Test public void retrieveAclResponseFromAdaptable() { final RetrieveAclResponse expected = RetrieveAclResponse.of(THING_ID, TestConstants.ACL, DITTO_HEADERS_V_1); final TopicPath topicPath = topicPath(TopicPath.Action.RETRIEVE); final JsonPointer path = JsonPointer.of("/acl"); final Adaptable adaptable = Adaptable.newBuilder(topicPath) .withPayload(Payload.newBuilder(path) .withStatus(HttpStatusCode.OK) .withValue(TestConstants.ACL.toJson()) .build()) .withHeaders(TestConstants.HEADERS_V_1) .build(); final ThingQueryCommandResponse<?> actual = underTest.fromAdaptable(adaptable); assertWithExternalHeadersThat(actual).isEqualTo(expected); }
@Test public void retrieveAclResponseToAdaptable() { final JsonPointer path = JsonPointer.of("/acl"); final TopicPath topicPath = topicPath(TopicPath.Action.RETRIEVE); final Adaptable expected = Adaptable.newBuilder(topicPath) .withPayload(Payload.newBuilder(path) .withStatus(HttpStatusCode.OK) .withValue(TestConstants.ACL.toJson()) .build()) .withHeaders(TestConstants.HEADERS_V_1) .build(); final RetrieveAclResponse retrieveAcl = RetrieveAclResponse.of(THING_ID, TestConstants.ACL, TestConstants.HEADERS_V_1_NO_CONTENT_TYPE); final Adaptable actual = underTest.toAdaptable(retrieveAcl, channel); assertWithExternalHeadersThat(actual).isEqualTo(expected); }
@Test public void retrieveAclEntryResponseFromAdaptable() { final RetrieveAclEntryResponse expected = RetrieveAclEntryResponse.of(THING_ID, TestConstants.ACL_ENTRY, DITTO_HEADERS_V_1); final TopicPath topicPath = topicPath(TopicPath.Action.RETRIEVE); final JsonPointer path = JsonPointer.of("/acl/" + TestConstants.AUTHORIZATION_SUBJECT.getId()); final Adaptable adaptable = Adaptable.newBuilder(topicPath) .withPayload(Payload.newBuilder(path) .withStatus(HttpStatusCode.OK) .withValue(TestConstants.ACL_ENTRY.getPermissions().toJson()) .build()) .withHeaders(TestConstants.HEADERS_V_1) .build(); final ThingQueryCommandResponse<?> actual = underTest.fromAdaptable(adaptable); assertWithExternalHeadersThat(actual).isEqualTo(expected); }
@Test public void retrieveAclEntryResponseToAdaptable() { final JsonPointer path = JsonPointer.of("/acl/" + TestConstants.AUTHORIZATION_SUBJECT.getId()); final TopicPath topicPath = topicPath(TopicPath.Action.RETRIEVE); final Adaptable expected = Adaptable.newBuilder(topicPath) .withPayload(Payload.newBuilder(path) .withStatus(HttpStatusCode.OK) .withValue(TestConstants.ACL_ENTRY.getPermissions().toJson()) .build()) .withHeaders(TestConstants.HEADERS_V_1) .build(); final RetrieveAclEntryResponse retrieveAclEntry = RetrieveAclEntryResponse.of(THING_ID, TestConstants.ACL_ENTRY, TestConstants.HEADERS_V_1_NO_CONTENT_TYPE); final Adaptable actual = underTest.toAdaptable(retrieveAclEntry, channel); assertWithExternalHeadersThat(actual).isEqualTo(expected); }
@Test public void retrieveAttributesResponseFromAdaptable() { final RetrieveAttributesResponse expected = RetrieveAttributesResponse.of(THING_ID, TestConstants.ATTRIBUTES, DITTO_HEADERS_V_1); final TopicPath topicPath = topicPath(TopicPath.Action.RETRIEVE); final JsonPointer path = JsonPointer.of("/attributes"); final Adaptable adaptable = Adaptable.newBuilder(topicPath) .withPayload(Payload.newBuilder(path) .withStatus(HttpStatusCode.OK) .withValue(TestConstants.ATTRIBUTES) .build()) .withHeaders(TestConstants.HEADERS_V_1) .build(); final ThingQueryCommandResponse<?> actual = underTest.fromAdaptable(adaptable); assertWithExternalHeadersThat(actual).isEqualTo(expected); }
@Test public void retrieveAttributesResponseToAdaptable() { final JsonPointer path = JsonPointer.of("/attributes"); final TopicPath topicPath = topicPath(TopicPath.Action.RETRIEVE); final Adaptable expected = Adaptable.newBuilder(topicPath) .withPayload(Payload.newBuilder(path) .withStatus(HttpStatusCode.OK) .withValue(TestConstants.ATTRIBUTES_JSON) .build()) .withHeaders(TestConstants.HEADERS_V_1) .build(); final RetrieveAttributesResponse retrieveAttributes = RetrieveAttributesResponse.of(THING_ID, TestConstants.ATTRIBUTES, TestConstants.HEADERS_V_1_NO_CONTENT_TYPE); final Adaptable actual = underTest.toAdaptable(retrieveAttributes, channel); assertWithExternalHeadersThat(actual).isEqualTo(expected); }
@Test public void retrieveAttributeResponseFromAdaptable() { final RetrieveAttributeResponse expected = RetrieveAttributeResponse.of(THING_ID, TestConstants.ATTRIBUTE_POINTER, TestConstants.ATTRIBUTE_VALUE, DITTO_HEADERS_V_1); final TopicPath topicPath = topicPath(TopicPath.Action.RETRIEVE); final JsonPointer path = JsonPointer.of("/attributes" + TestConstants.ATTRIBUTE_POINTER); final Adaptable adaptable = Adaptable.newBuilder(topicPath) .withPayload(Payload.newBuilder(path) .withStatus(HttpStatusCode.OK) .withValue(TestConstants.ATTRIBUTE_VALUE) .build()) .withHeaders(TestConstants.HEADERS_V_1) .build(); final ThingQueryCommandResponse<?> actual = underTest.fromAdaptable(adaptable); assertWithExternalHeadersThat(actual).isEqualTo(expected); }
@Test public void retrieveAttributeResponseToAdaptable() { final JsonPointer path = JsonPointer.of("/attributes" + TestConstants.ATTRIBUTE_POINTER); final TopicPath topicPath = topicPath(TopicPath.Action.RETRIEVE); final Adaptable expected = Adaptable.newBuilder(topicPath) .withPayload(Payload.newBuilder(path) .withStatus(HttpStatusCode.OK) .withValue(TestConstants.ATTRIBUTE_VALUE) .build()) .withHeaders(TestConstants.HEADERS_V_1) .build(); final RetrieveAttributeResponse retrieveAttribute = RetrieveAttributeResponse.of(THING_ID, TestConstants.ATTRIBUTE_POINTER, TestConstants.ATTRIBUTE_VALUE, TestConstants.HEADERS_V_1_NO_CONTENT_TYPE); final Adaptable actual = underTest.toAdaptable(retrieveAttribute, channel); assertWithExternalHeadersThat(actual).isEqualTo(expected); }
@Test public void retrieveDefinitionResponseFromAdaptable() { final RetrieveThingDefinitionResponse expected = RetrieveThingDefinitionResponse.of(THING_ID, TestConstants.THING_DEFINITION, DITTO_HEADERS_V_1); final TopicPath topicPath = topicPath(TopicPath.Action.RETRIEVE); final JsonPointer path = JsonPointer.of("/definition"); final Adaptable adaptable = Adaptable.newBuilder(topicPath) .withPayload(Payload.newBuilder(path) .withStatus(HttpStatusCode.OK) .withValue(TestConstants.JSON_THING_DEFINITION) .build()) .withHeaders(TestConstants.HEADERS_V_2) .build(); final ThingQueryCommandResponse<?> actual = underTest.fromAdaptable(adaptable); assertWithExternalHeadersThat(actual).isEqualTo(expected); }
@Test public void retrieveDefinitionResponseToAdaptable() { final JsonPointer path = JsonPointer.of("/definition"); final TopicPath topicPath = topicPath(TopicPath.Action.RETRIEVE); final Adaptable expected = Adaptable.newBuilder(topicPath) .withPayload(Payload.newBuilder(path) .withStatus(HttpStatusCode.OK) .withValue(TestConstants.JSON_THING_DEFINITION) .build()) .withHeaders(TestConstants.HEADERS_V_2) .build(); final RetrieveThingDefinitionResponse retrieveDefinition = RetrieveThingDefinitionResponse.of(THING_ID, TestConstants.THING_DEFINITION, TestConstants.HEADERS_V_1_NO_CONTENT_TYPE); final Adaptable actual = underTest.toAdaptable(retrieveDefinition, channel); assertWithExternalHeadersThat(actual).isEqualTo(expected); }
@Test public void retrieveFeaturesResponseFromAdaptable() { final RetrieveFeaturesResponse expected = RetrieveFeaturesResponse.of(THING_ID, TestConstants.FEATURES, DITTO_HEADERS_V_1); final TopicPath topicPath = topicPath(TopicPath.Action.RETRIEVE); final JsonPointer path = JsonPointer.of("/features"); final Adaptable adaptable = Adaptable.newBuilder(topicPath) .withPayload(Payload.newBuilder(path) .withStatus(HttpStatusCode.OK) .withValue(TestConstants.FEATURES.toJson()) .build()) .withHeaders(TestConstants.HEADERS_V_1) .build(); final ThingQueryCommandResponse<?> actual = underTest.fromAdaptable(adaptable); assertWithExternalHeadersThat(actual).isEqualTo(expected); }
@Test public void retrieveFeaturesResponseToAdaptable() { final JsonPointer path = JsonPointer.of("/features"); final TopicPath topicPath = topicPath(TopicPath.Action.RETRIEVE); final Adaptable expected = Adaptable.newBuilder(topicPath) .withPayload(Payload.newBuilder(path) .withStatus(HttpStatusCode.OK) .withValue(TestConstants.FEATURES.toJson()) .build()) .withHeaders(TestConstants.HEADERS_V_1) .build(); final RetrieveFeaturesResponse retrieveFeatures = RetrieveFeaturesResponse.of(THING_ID, TestConstants.FEATURES, TestConstants.HEADERS_V_1_NO_CONTENT_TYPE); final Adaptable actual = underTest.toAdaptable(retrieveFeatures, channel); assertWithExternalHeadersThat(actual).isEqualTo(expected); }
@Test public void retrieveFeatureResponseFromAdaptable() { final RetrieveFeatureResponse expected = RetrieveFeatureResponse.of(THING_ID, FEATURE_ID, TestConstants.FEATURE.toJson(), DITTO_HEADERS_V_1); final TopicPath topicPath = topicPath(TopicPath.Action.RETRIEVE); final JsonPointer path = JsonPointer.of("/features/" + FEATURE_ID); final Adaptable adaptable = Adaptable.newBuilder(topicPath) .withPayload(Payload.newBuilder(path) .withStatus(HttpStatusCode.OK) .withValue(TestConstants.FEATURE.toJson()) .build()) .withHeaders(TestConstants.HEADERS_V_1) .build(); final ThingQueryCommandResponse<?> actual = underTest.fromAdaptable(adaptable); assertWithExternalHeadersThat(actual).isEqualTo(expected); }
@Test public void retrieveFeatureResponseToAdaptable() { final JsonPointer path = JsonPointer.of("/features/" + FEATURE_ID); final TopicPath topicPath = topicPath(TopicPath.Action.RETRIEVE); final Adaptable expected = Adaptable.newBuilder(topicPath) .withPayload(Payload.newBuilder(path) .withStatus(HttpStatusCode.OK) .withValue(TestConstants.FEATURE.toJson()) .build()) .withHeaders(TestConstants.HEADERS_V_1) .build(); final RetrieveFeatureResponse retrieveFeature = RetrieveFeatureResponse.of(THING_ID, FEATURE_ID, TestConstants.FEATURE.toJson(), TestConstants.HEADERS_V_1_NO_CONTENT_TYPE); final Adaptable actual = underTest.toAdaptable(retrieveFeature, channel); assertWithExternalHeadersThat(actual).isEqualTo(expected); }
@Test public void retrieveFeatureDefinitionResponseFromAdaptable() { final RetrieveFeatureDefinitionResponse expected = RetrieveFeatureDefinitionResponse.of(THING_ID, FEATURE_ID, TestConstants.FEATURE_DEFINITION, DITTO_HEADERS_V_1); final TopicPath topicPath = topicPath(TopicPath.Action.RETRIEVE); final JsonPointer path = JsonPointer.of("/features/" + FEATURE_ID + "/definition"); final Adaptable adaptable = Adaptable.newBuilder(topicPath) .withPayload(Payload.newBuilder(path) .withStatus(HttpStatusCode.OK) .withValue(TestConstants.FEATURE_DEFINITION_JSON) .build()) .withHeaders(TestConstants.HEADERS_V_1) .build(); final ThingQueryCommandResponse<?> actual = underTest.fromAdaptable(adaptable); assertWithExternalHeadersThat(actual).isEqualTo(expected); }
@Test public void retrieveFeatureDefinitionResponseToAdaptable() { final JsonPointer path = JsonPointer.of("/features/" + FEATURE_ID + "/definition"); final TopicPath topicPath = topicPath(TopicPath.Action.RETRIEVE); final Adaptable expected = Adaptable.newBuilder(topicPath) .withPayload(Payload.newBuilder(path) .withStatus(HttpStatusCode.OK) .withValue(TestConstants.FEATURE_DEFINITION_JSON) .build()) .withHeaders(TestConstants.HEADERS_V_1) .build(); final RetrieveFeatureDefinitionResponse retrieveFeatureDefinition = RetrieveFeatureDefinitionResponse.of(THING_ID, FEATURE_ID, TestConstants.FEATURE_DEFINITION, TestConstants.HEADERS_V_1_NO_CONTENT_TYPE); final Adaptable actual = underTest.toAdaptable(retrieveFeatureDefinition, channel); assertWithExternalHeadersThat(actual).isEqualTo(expected); }
@Test public void retrieveFeaturePropertiesResponseFromAdaptable() { final RetrieveFeaturePropertiesResponse expected = RetrieveFeaturePropertiesResponse.of(THING_ID, FEATURE_ID, TestConstants.FEATURE_PROPERTIES, DITTO_HEADERS_V_1); final TopicPath topicPath = topicPath(TopicPath.Action.RETRIEVE); final JsonPointer path = JsonPointer.of("/features/" + FEATURE_ID + "/properties"); final Adaptable adaptable = Adaptable.newBuilder(topicPath) .withPayload(Payload.newBuilder(path) .withStatus(HttpStatusCode.OK) .withValue(TestConstants.FEATURE_PROPERTIES) .build()) .withHeaders(TestConstants.HEADERS_V_1) .build(); final ThingQueryCommandResponse<?> actual = underTest.fromAdaptable(adaptable); assertWithExternalHeadersThat(actual).isEqualTo(expected); }
@Test public void retrieveFeaturePropertiesResponseToAdaptable() { final JsonPointer path = JsonPointer.of("/features/" + FEATURE_ID + "/properties"); final TopicPath topicPath = topicPath(TopicPath.Action.RETRIEVE); final Adaptable expected = Adaptable.newBuilder(topicPath) .withPayload(Payload.newBuilder(path) .withStatus(HttpStatusCode.OK) .withValue(TestConstants.FEATURE_PROPERTIES_JSON) .build()) .withHeaders(TestConstants.HEADERS_V_1) .build(); final RetrieveFeaturePropertiesResponse retrieveFeatureProperties = RetrieveFeaturePropertiesResponse.of(THING_ID, FEATURE_ID, TestConstants.FEATURE_PROPERTIES, TestConstants.HEADERS_V_1_NO_CONTENT_TYPE); final Adaptable actual = underTest.toAdaptable(retrieveFeatureProperties, channel); assertWithExternalHeadersThat(actual).isEqualTo(expected); }
@Test public void retrieveFeaturePropertyResponseFromAdaptable() { final RetrieveFeaturePropertyResponse expected = RetrieveFeaturePropertyResponse.of(THING_ID, FEATURE_ID, TestConstants.FEATURE_PROPERTY_POINTER, TestConstants.FEATURE_PROPERTY_VALUE, DITTO_HEADERS_V_1); final TopicPath topicPath = topicPath(TopicPath.Action.RETRIEVE); final JsonPointer path = JsonPointer.of("/features/" + FEATURE_ID + "/properties" + TestConstants.FEATURE_PROPERTY_POINTER); final Adaptable adaptable = Adaptable.newBuilder(topicPath) .withPayload(Payload.newBuilder(path) .withStatus(HttpStatusCode.OK) .withValue(TestConstants.FEATURE_PROPERTY_VALUE) .build()) .withHeaders(TestConstants.HEADERS_V_1) .build(); final ThingQueryCommandResponse<?> actual = underTest.fromAdaptable(adaptable); assertWithExternalHeadersThat(actual).isEqualTo(expected); }
@Test public void retrieveFeaturePropertyResponseToAdaptable() { final JsonPointer path = JsonPointer.of("/features/" + FEATURE_ID + "/properties" + TestConstants.FEATURE_PROPERTY_POINTER); final TopicPath topicPath = topicPath(TopicPath.Action.RETRIEVE); final Adaptable expected = Adaptable.newBuilder(topicPath) .withPayload(Payload.newBuilder(path) .withStatus(HttpStatusCode.OK) .withValue(TestConstants.FEATURE_PROPERTY_VALUE) .build()) .withHeaders(TestConstants.HEADERS_V_1) .build(); final RetrieveFeaturePropertyResponse retrieveFeatureProperty = RetrieveFeaturePropertyResponse.of(THING_ID, FEATURE_ID, TestConstants.FEATURE_PROPERTY_POINTER, TestConstants.FEATURE_PROPERTY_VALUE, TestConstants.HEADERS_V_1_NO_CONTENT_TYPE); final Adaptable actual = underTest.toAdaptable(retrieveFeatureProperty, channel); assertWithExternalHeadersThat(actual).isEqualTo(expected); }