ThingQueryCommandAdapter extends AbstractThingAdapter<ThingQueryCommand<?>> implements QueryCommandAdapter<ThingQueryCommand<?>> { public static ThingQueryCommandAdapter of(final HeaderTranslator headerTranslator) { return new ThingQueryCommandAdapter(requireNonNull(headerTranslator)); } private  ThingQueryCommandAdapter(final HeaderTranslator headerTranslator); static ThingQueryCommandAdapter of(final HeaderTranslator headerTranslator); @Override Adaptable mapSignalToAdaptable(final ThingQueryCommand<?> command, final TopicPath.Channel channel);  }
@Test public void retrieveThingFromAdaptable() { final RetrieveThing expected = RetrieveThing.of(TestConstants.THING_ID, 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).build()) .withHeaders(TestConstants.HEADERS_V_2) .build(); final ThingQueryCommand<?> actual = underTest.fromAdaptable(adaptable); assertWithExternalHeadersThat(actual).isEqualTo(expected); }
@Test public void retrieveThingToAdaptable() { final TopicPath topicPath = topicPath(TopicPath.Action.RETRIEVE); final JsonPointer path = JsonPointer.empty(); final Adaptable expected = Adaptable.newBuilder(topicPath) .withPayload(Payload.newBuilder(path).build()) .withHeaders(TestConstants.HEADERS_V_2) .build(); final RetrieveThing retrieveThing = RetrieveThing.of(TestConstants.THING_ID, TestConstants.HEADERS_V_2_NO_CONTENT_TYPE); final Adaptable actual = underTest.toAdaptable(retrieveThing, channel); final JsonifiableAdaptable jsonifiableAdaptable = ProtocolFactory.wrapAsJsonifiableAdaptable(actual); final JsonObject jsonObject = jsonifiableAdaptable.toJson(); assertWithExternalHeadersThat(actual).isEqualTo(expected); }
@Test public void retrieveAclFromAdaptable() { final RetrieveAcl expected = RetrieveAcl.of(TestConstants.THING_ID, TestConstants.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).build()) .withHeaders(TestConstants.HEADERS_V_1) .build(); final ThingQueryCommand<?> actual = underTest.fromAdaptable(adaptable); assertWithExternalHeadersThat(actual).isEqualTo(expected); }
@Test public void retrieveAclToAdaptable() { final TopicPath topicPath = topicPath(TopicPath.Action.RETRIEVE); final JsonPointer path = JsonPointer.of("/acl"); final Adaptable expected = Adaptable.newBuilder(topicPath) .withPayload(Payload.newBuilder(path).build()) .withHeaders(TestConstants.HEADERS_V_1) .build(); final RetrieveAcl retrieveAcl = RetrieveAcl.of(TestConstants.THING_ID, TestConstants.HEADERS_V_1_NO_CONTENT_TYPE); final Adaptable actual = underTest.toAdaptable(retrieveAcl, channel); assertWithExternalHeadersThat(actual).isEqualTo(expected); }
@Test public void retrieveAclEntryFromAdaptable() { final RetrieveAclEntry expected = RetrieveAclEntry .of(TestConstants.THING_ID, TestConstants.AUTHORIZATION_SUBJECT, TestConstants.DITTO_HEADERS_V_1); final TopicPath topicPath = topicPath(TopicPath.Action.RETRIEVE); final JsonPointer path = JsonPointer.of("/acl/" + TestConstants.AUTHORIZATION_SUBJECT); final Adaptable adaptable = Adaptable.newBuilder(topicPath) .withPayload(Payload.newBuilder(path).build()) .withHeaders(TestConstants.HEADERS_V_1) .build(); final ThingQueryCommand<?> actual = underTest.fromAdaptable(adaptable); assertWithExternalHeadersThat(actual).isEqualTo(expected); }
@Test public void retrieveAclEntryToAdaptable() { final TopicPath topicPath = topicPath(TopicPath.Action.RETRIEVE); final JsonPointer path = JsonPointer.of("/acl/" + TestConstants.AUTHORIZATION_SUBJECT); final Adaptable expected = Adaptable.newBuilder(topicPath) .withPayload(Payload.newBuilder(path).build()) .withHeaders(TestConstants.HEADERS_V_1) .build(); final RetrieveAclEntry retrieveAclEntry = RetrieveAclEntry.of(TestConstants.THING_ID, TestConstants.AUTHORIZATION_SUBJECT, TestConstants.HEADERS_V_1_NO_CONTENT_TYPE); final Adaptable actual = underTest.toAdaptable(retrieveAclEntry, channel); assertWithExternalHeadersThat(actual).isEqualTo(expected); }
@Test public void retrieveAclEntryWithFieldsFromAdaptable() { final JsonFieldSelector selectedFields = JsonFieldSelector.newInstance("READ"); final RetrieveAclEntry expected = RetrieveAclEntry.of(TestConstants.THING_ID, TestConstants.AUTHORIZATION_SUBJECT, selectedFields, TestConstants.DITTO_HEADERS_V_1); final TopicPath topicPath = topicPath(TopicPath.Action.RETRIEVE); final JsonPointer path = JsonPointer.of("/acl/" + TestConstants.AUTHORIZATION_SUBJECT); final Adaptable adaptable = Adaptable.newBuilder(topicPath) .withPayload(Payload.newBuilder(path).withFields(selectedFields).build()) .withHeaders(TestConstants.HEADERS_V_1) .build(); final ThingQueryCommand<?> actual = underTest.fromAdaptable(adaptable); assertWithExternalHeadersThat(actual).isEqualTo(expected); }
@Test public void retrieveAclEntryWithFieldsToAdaptable() { final JsonFieldSelector selectedFields = JsonFieldSelector.newInstance("READ"); final TopicPath topicPath = topicPath(TopicPath.Action.RETRIEVE); final JsonPointer path = JsonPointer.of("/acl/" + TestConstants.AUTHORIZATION_SUBJECT); final Adaptable expected = Adaptable.newBuilder(topicPath) .withPayload(Payload.newBuilder(path).withFields(selectedFields).build()) .withHeaders(TestConstants.HEADERS_V_1) .build(); final RetrieveAclEntry retrieveAclEntry = RetrieveAclEntry.of(TestConstants.THING_ID, TestConstants.AUTHORIZATION_SUBJECT, selectedFields, TestConstants.HEADERS_V_1_NO_CONTENT_TYPE); final Adaptable actual = underTest.toAdaptable(retrieveAclEntry, channel); assertWithExternalHeadersThat(actual).isEqualTo(expected); }
@Test public void retrieveAttributesFromAdaptable() { final RetrieveAttributes expected = RetrieveAttributes.of(TestConstants.THING_ID, TestConstants.DITTO_HEADERS_V_2); final TopicPath topicPath = topicPath(TopicPath.Action.RETRIEVE); final JsonPointer path = JsonPointer.of("/attributes"); final Adaptable adaptable = Adaptable.newBuilder(topicPath) .withPayload(Payload.newBuilder(path).build()) .withHeaders(TestConstants.HEADERS_V_2) .build(); final ThingQueryCommand<?> actual = underTest.fromAdaptable(adaptable); assertWithExternalHeadersThat(actual).isEqualTo(expected); }
@Test public void retrieveAttributesToAdaptable() { final TopicPath topicPath = topicPath(TopicPath.Action.RETRIEVE); final JsonPointer path = JsonPointer.of("/attributes"); final Adaptable expected = Adaptable.newBuilder(topicPath) .withPayload(Payload.newBuilder(path).build()) .withHeaders(TestConstants.HEADERS_V_2) .build(); final RetrieveAttributes retrieveAttributes = RetrieveAttributes.of(TestConstants.THING_ID, TestConstants.HEADERS_V_2_NO_CONTENT_TYPE); final Adaptable actual = underTest.toAdaptable(retrieveAttributes, channel); assertWithExternalHeadersThat(actual).isEqualTo(expected); }
@Test public void retrieveAttributesWithFieldsFromAdaptable() { final JsonFieldSelector selectedFields = JsonFieldSelector.newInstance("foo"); final RetrieveAttributes expected = RetrieveAttributes.of(TestConstants.THING_ID, selectedFields, TestConstants.DITTO_HEADERS_V_2); final TopicPath topicPath = topicPath(TopicPath.Action.RETRIEVE); final JsonPointer path = JsonPointer.of("/attributes"); final Adaptable adaptable = Adaptable.newBuilder(topicPath) .withPayload(Payload.newBuilder(path).withFields(selectedFields).build()) .withHeaders(TestConstants.HEADERS_V_2) .build(); final ThingQueryCommand<?> actual = underTest.fromAdaptable(adaptable); assertWithExternalHeadersThat(actual).isEqualTo(expected); }
@Test public void retrieveAttributesWithFieldsToAdaptable() { final JsonFieldSelector selectedFields = JsonFieldSelector.newInstance("foo"); final TopicPath topicPath = topicPath(TopicPath.Action.RETRIEVE); final JsonPointer path = JsonPointer.of("/attributes"); final Adaptable expected = Adaptable.newBuilder(topicPath) .withPayload(Payload.newBuilder(path).withFields(selectedFields).build()) .withHeaders(TestConstants.HEADERS_V_2) .build(); final RetrieveAttributes retrieveAttributes = RetrieveAttributes.of(TestConstants.THING_ID, selectedFields, TestConstants.HEADERS_V_2_NO_CONTENT_TYPE); final Adaptable actual = underTest.toAdaptable(retrieveAttributes, channel); assertWithExternalHeadersThat(actual).isEqualTo(expected); }
@Test public void retrieveAttributeFromAdaptable() { final RetrieveAttribute expected = RetrieveAttribute.of(TestConstants.THING_ID, TestConstants.ATTRIBUTE_POINTER, TestConstants.DITTO_HEADERS_V_2); 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).build()) .withHeaders(TestConstants.HEADERS_V_2) .build(); final ThingQueryCommand<?> actual = underTest.fromAdaptable(adaptable); assertWithExternalHeadersThat(actual).isEqualTo(expected); }
@Test public void retrieveAttributeToAdaptable() { final TopicPath topicPath = topicPath(TopicPath.Action.RETRIEVE); final JsonPointer path = JsonPointer.of("/attributes" + TestConstants.ATTRIBUTE_POINTER); final Adaptable expected = Adaptable.newBuilder(topicPath) .withPayload(Payload.newBuilder(path).build()) .withHeaders(TestConstants.HEADERS_V_2) .build(); final RetrieveAttribute retrieveAttribute = RetrieveAttribute.of(TestConstants.THING_ID, TestConstants.ATTRIBUTE_POINTER, TestConstants.HEADERS_V_2_NO_CONTENT_TYPE); final Adaptable actual = underTest.toAdaptable(retrieveAttribute, channel); assertWithExternalHeadersThat(actual).isEqualTo(expected); }
@Test public void retrieveDefinitionFromAdaptable() { final RetrieveThingDefinition expected = RetrieveThingDefinition.of(TestConstants.THING_ID, TestConstants.DITTO_HEADERS_V_2); final TopicPath topicPath = topicPath(TopicPath.Action.RETRIEVE); final JsonPointer path = JsonPointer.of("/definition"); final Adaptable adaptable = Adaptable.newBuilder(topicPath) .withPayload(Payload.newBuilder(path).build()) .withHeaders(TestConstants.HEADERS_V_2) .build(); final ThingQueryCommand<?> actual = underTest.fromAdaptable(adaptable); assertWithExternalHeadersThat(actual).isEqualTo(expected); }
@Test public void retrieveDefinitionToAdaptable() { final TopicPath topicPath = topicPath(TopicPath.Action.RETRIEVE); final JsonPointer path = JsonPointer.of("/definition"); final Adaptable expected = Adaptable.newBuilder(topicPath) .withPayload(Payload.newBuilder(path).build()) .withHeaders(TestConstants.HEADERS_V_2) .build(); final RetrieveThingDefinition retrieveDefinition = RetrieveThingDefinition.of(TestConstants.THING_ID, TestConstants.HEADERS_V_2_NO_CONTENT_TYPE); final Adaptable actual = underTest.toAdaptable(retrieveDefinition, channel); assertWithExternalHeadersThat(actual).isEqualTo(expected); }
@Test public void retrieveFeaturesFromAdaptable() { final RetrieveFeatures expected = RetrieveFeatures.of(TestConstants.THING_ID, TestConstants.DITTO_HEADERS_V_2); final TopicPath topicPath = topicPath(TopicPath.Action.RETRIEVE); final JsonPointer path = JsonPointer.of("/features"); final Adaptable adaptable = Adaptable.newBuilder(topicPath) .withPayload(Payload.newBuilder(path).build()) .withHeaders(TestConstants.HEADERS_V_2) .build(); final ThingQueryCommand<?> actual = underTest.fromAdaptable(adaptable); assertWithExternalHeadersThat(actual).isEqualTo(expected); }
@Test public void retrieveFeaturesToAdaptable() { final TopicPath topicPath = topicPath(TopicPath.Action.RETRIEVE); final JsonPointer path = JsonPointer.of("/features"); final Adaptable expected = Adaptable.newBuilder(topicPath) .withPayload(Payload.newBuilder(path).build()) .withHeaders(TestConstants.HEADERS_V_2) .build(); final RetrieveFeatures retrieveFeatures = RetrieveFeatures.of(TestConstants.THING_ID, TestConstants.HEADERS_V_2_NO_CONTENT_TYPE); final Adaptable actual = underTest.toAdaptable(retrieveFeatures, channel); assertWithExternalHeadersThat(actual).isEqualTo(expected); }
@Test public void retrieveFeaturesWithFieldsFromAdaptable() { final JsonFieldSelector selectedFields = JsonFieldSelector.newInstance("foo"); final RetrieveFeatures expected = RetrieveFeatures.of(TestConstants.THING_ID, selectedFields, TestConstants.DITTO_HEADERS_V_2); final TopicPath topicPath = topicPath(TopicPath.Action.RETRIEVE); final JsonPointer path = JsonPointer.of("/features"); final Adaptable adaptable = Adaptable.newBuilder(topicPath) .withPayload(Payload.newBuilder(path).withFields(selectedFields).build()) .withHeaders(TestConstants.HEADERS_V_2) .build(); final ThingQueryCommand<?> actual = underTest.fromAdaptable(adaptable); assertWithExternalHeadersThat(actual).isEqualTo(expected); }
@Test public void retrieveFeaturesWithFieldsToAdaptable() { final JsonFieldSelector selectedFields = JsonFieldSelector.newInstance("foo"); final TopicPath topicPath = topicPath(TopicPath.Action.RETRIEVE); final JsonPointer path = JsonPointer.of("/features"); final Adaptable expected = Adaptable.newBuilder(topicPath) .withPayload(Payload.newBuilder(path).withFields(selectedFields).build()) .withHeaders(TestConstants.HEADERS_V_2) .build(); final RetrieveFeatures retrieveFeatures = RetrieveFeatures.of(TestConstants.THING_ID, selectedFields, TestConstants.HEADERS_V_2_NO_CONTENT_TYPE); final Adaptable actual = underTest.toAdaptable(retrieveFeatures, channel); assertWithExternalHeadersThat(actual).isEqualTo(expected); }
@Test public void retrieveFeatureFromAdaptable() { final RetrieveFeature expected = RetrieveFeature.of(TestConstants.THING_ID, TestConstants.FEATURE_ID, TestConstants.DITTO_HEADERS_V_2); final TopicPath topicPath = topicPath(TopicPath.Action.RETRIEVE); final JsonPointer path = JsonPointer.of("/features/" + TestConstants.FEATURE_ID); final Adaptable adaptable = Adaptable.newBuilder(topicPath) .withPayload(Payload.newBuilder(path).build()) .withHeaders(TestConstants.HEADERS_V_2) .build(); final ThingQueryCommand<?> actual = underTest.fromAdaptable(adaptable); assertWithExternalHeadersThat(actual).isEqualTo(expected); }
@Test public void retrieveFeatureToAdaptable() { final TopicPath topicPath = topicPath(TopicPath.Action.RETRIEVE); final JsonPointer path = JsonPointer.of("/features/" + TestConstants.FEATURE_ID); final Adaptable expected = Adaptable.newBuilder(topicPath) .withPayload(Payload.newBuilder(path).build()) .withHeaders(TestConstants.HEADERS_V_2) .build(); final RetrieveFeature retrieveFeature = RetrieveFeature.of(TestConstants.THING_ID, TestConstants.FEATURE_ID, TestConstants.HEADERS_V_2_NO_CONTENT_TYPE); final Adaptable actual = underTest.toAdaptable(retrieveFeature, channel); assertWithExternalHeadersThat(actual).isEqualTo(expected); }
@Test public void retrieveFeatureDefinitionFromAdaptable() { final RetrieveFeatureDefinition expected = RetrieveFeatureDefinition.of(TestConstants.THING_ID, TestConstants.FEATURE_ID, TestConstants.DITTO_HEADERS_V_2); final TopicPath topicPath = topicPath(TopicPath.Action.RETRIEVE); final JsonPointer path = JsonPointer.of("/features/" + TestConstants.FEATURE_ID + "/definition"); final Adaptable adaptable = Adaptable.newBuilder(topicPath) .withPayload(Payload.newBuilder(path).build()) .withHeaders(TestConstants.HEADERS_V_2) .build(); final ThingQueryCommand<?> actual = underTest.fromAdaptable(adaptable); assertWithExternalHeadersThat(actual).isEqualTo(expected); }
@Test public void retrieveFeatureDefinitionToAdaptable() { final TopicPath topicPath = topicPath(TopicPath.Action.RETRIEVE); final JsonPointer path = JsonPointer.of("/features/" + TestConstants.FEATURE_ID + "/definition"); final Adaptable expected = Adaptable.newBuilder(topicPath) .withPayload(Payload.newBuilder(path).build()) .withHeaders(TestConstants.HEADERS_V_2) .build(); final RetrieveFeatureDefinition retrieveFeatureDefinition = RetrieveFeatureDefinition.of(TestConstants.THING_ID, TestConstants.FEATURE_ID, TestConstants.HEADERS_V_2_NO_CONTENT_TYPE); final Adaptable actual = underTest.toAdaptable(retrieveFeatureDefinition, channel); assertWithExternalHeadersThat(actual).isEqualTo(expected); }
@Test public void retrieveFeaturePropertiesFromAdaptable() { final RetrieveFeatureProperties expected = RetrieveFeatureProperties.of(TestConstants.THING_ID, TestConstants.FEATURE_ID, TestConstants.DITTO_HEADERS_V_2); final TopicPath topicPath = topicPath(TopicPath.Action.RETRIEVE); final JsonPointer path = JsonPointer.of("/features/" + TestConstants.FEATURE_ID + "/properties"); final Adaptable adaptable = Adaptable.newBuilder(topicPath) .withPayload(Payload.newBuilder(path).build()) .withHeaders(TestConstants.HEADERS_V_2) .build(); final ThingQueryCommand<?> actual = underTest.fromAdaptable(adaptable); assertWithExternalHeadersThat(actual).isEqualTo(expected); }
@Test public void retrieveFeaturePropertiesToAdaptable() { final TopicPath topicPath = topicPath(TopicPath.Action.RETRIEVE); final JsonPointer path = JsonPointer.of("/features/" + TestConstants.FEATURE_ID + "/properties"); final Adaptable expected = Adaptable.newBuilder(topicPath) .withPayload(Payload.newBuilder(path).build()) .withHeaders(TestConstants.HEADERS_V_2) .build(); final RetrieveFeatureProperties retrieveFeatureProperties = RetrieveFeatureProperties.of(TestConstants.THING_ID, TestConstants.FEATURE_ID, TestConstants.HEADERS_V_2_NO_CONTENT_TYPE); final Adaptable actual = underTest.toAdaptable(retrieveFeatureProperties, channel); assertWithExternalHeadersThat(actual).isEqualTo(expected); }
@Test public void retrieveFeaturePropertiesWithFieldsFromAdaptable() { final JsonFieldSelector selectedFields = JsonFieldSelector.newInstance("foo"); final RetrieveFeatureProperties expected = RetrieveFeatureProperties.of(TestConstants.THING_ID, TestConstants.FEATURE_ID, selectedFields, TestConstants.DITTO_HEADERS_V_2); final TopicPath topicPath = topicPath(TopicPath.Action.RETRIEVE); final JsonPointer path = JsonPointer.of("/features/" + TestConstants.FEATURE_ID + "/properties"); final Adaptable adaptable = Adaptable.newBuilder(topicPath) .withPayload(Payload.newBuilder(path).withFields(selectedFields).build()) .withHeaders(TestConstants.HEADERS_V_2) .build(); final ThingQueryCommand<?> actual = underTest.fromAdaptable(adaptable); assertWithExternalHeadersThat(actual).isEqualTo(expected); }
@Test public void retrieveFeaturePropertiesWithFieldsToAdaptable() { final JsonFieldSelector selectedFields = JsonFieldSelector.newInstance("foo"); final TopicPath topicPath = topicPath(TopicPath.Action.RETRIEVE); final JsonPointer path = JsonPointer.of("/features/" + TestConstants.FEATURE_ID + "/properties"); final Adaptable expected = Adaptable.newBuilder(topicPath) .withPayload(Payload.newBuilder(path).withFields(selectedFields).build()) .withHeaders(TestConstants.HEADERS_V_2) .build(); final RetrieveFeatureProperties retrieveFeatureProperties = RetrieveFeatureProperties .of(TestConstants.THING_ID, TestConstants.FEATURE_ID, selectedFields, TestConstants.HEADERS_V_2_NO_CONTENT_TYPE); final Adaptable actual = underTest.toAdaptable(retrieveFeatureProperties, channel); assertWithExternalHeadersThat(actual).isEqualTo(expected); }
@Test public void retrieveFeaturePropertyFromAdaptable() { final RetrieveFeatureProperty expected = RetrieveFeatureProperty.of(TestConstants.THING_ID, TestConstants.FEATURE_ID, TestConstants.FEATURE_PROPERTY_POINTER, TestConstants.DITTO_HEADERS_V_2); final TopicPath topicPath = topicPath(TopicPath.Action.RETRIEVE); final JsonPointer path = JsonPointer.of( "/features/" + TestConstants.FEATURE_ID + "/properties" + TestConstants.FEATURE_PROPERTY_POINTER); final Adaptable adaptable = Adaptable.newBuilder(topicPath) .withPayload(Payload.newBuilder(path) .build()) .withHeaders(TestConstants.HEADERS_V_2) .build(); final ThingQueryCommand<?> actual = underTest.fromAdaptable(adaptable); assertWithExternalHeadersThat(actual).isEqualTo(expected); }
@Test public void retrieveFeaturePropertyToAdaptable() { final TopicPath topicPath = topicPath(TopicPath.Action.RETRIEVE); final JsonPointer path = JsonPointer.of( "/features/" + TestConstants.FEATURE_ID + "/properties" + TestConstants.FEATURE_PROPERTY_POINTER); final Adaptable expected = Adaptable.newBuilder(topicPath) .withPayload(Payload.newBuilder(path).build()) .withHeaders(TestConstants.HEADERS_V_2) .build(); final RetrieveFeatureProperty retrieveFeatureProperty = RetrieveFeatureProperty.of(TestConstants.THING_ID, TestConstants.FEATURE_ID, TestConstants.FEATURE_PROPERTY_POINTER, TestConstants.HEADERS_V_2_NO_CONTENT_TYPE); final Adaptable actual = underTest.toAdaptable(retrieveFeatureProperty, channel); assertWithExternalHeadersThat(actual).isEqualTo(expected); }