ThingSearchCommandAdapter extends AbstractThingAdapter<ThingSearchCommand<?>> { public static ThingSearchCommandAdapter of(final HeaderTranslator headerTranslator) { return new ThingSearchCommandAdapter(requireNonNull(headerTranslator)); } private  ThingSearchCommandAdapter(final HeaderTranslator headerTranslator); static ThingSearchCommandAdapter of(final HeaderTranslator headerTranslator); @Override Adaptable mapSignalToAdaptable(final ThingSearchCommand<?> command, final TopicPath.Channel channel); @Override Set<TopicPath.Criterion> getCriteria(); @Override Set<TopicPath.Action> getActions(); @Override boolean isForResponses(); @Override Set<TopicPath.SearchAction> getSearchActions();  }
@Test public void createSubscriptionFromAdaptable() { final CreateSubscription expected = CreateSubscription.of(TestConstants.FILTER, TestConstants.OPTIONS, null, TestConstants.NAMESPACES, TestConstants.DITTO_HEADERS_V_2_NO_STATUS); final TopicPath topicPath = TopicPath.fromNamespace(TopicPath.ID_PLACEHOLDER) .things() .twin() .search() .subscribe() .build(); final JsonPointer path = JsonPointer.empty(); final Adaptable adaptable = Adaptable.newBuilder(topicPath) .withPayload(Payload.newBuilder(path) .withValue(JsonObject.of(String.format( "{\"filter\": \"%s\", \"options\": \"%s\", \"namespaces\": %s}", TestConstants.FILTER, TestConstants.OPTIONS, NAMESPACES_ARRAY ))) .build()) .withHeaders(TestConstants.DITTO_HEADERS_V_2_NO_STATUS) .build(); final ThingSearchCommand<?> actual = underTest.fromAdaptable(adaptable); assertWithExternalHeadersThat(actual).isEqualTo(expected); }
@Test public void createSubscriptionToAdaptable() { final TopicPath topicPath = TopicPath.fromNamespace(TopicPath.ID_PLACEHOLDER) .things() .twin() .search() .subscribe() .build(); final JsonPointer path = JsonPointer.empty(); final Adaptable expected = Adaptable.newBuilder(topicPath) .withPayload(Payload.newBuilder(path) .withValue(JsonObject.of(String.format( "{\"filter\": \"%s\", \"options\": \"%s\", \"namespaces\": %s}", TestConstants.FILTER, TestConstants.OPTIONS, NAMESPACES_ARRAY ))) .build()) .withHeaders(TestConstants.DITTO_HEADERS_V_2_NO_STATUS) .build(); final CreateSubscription createSubscription = CreateSubscription.of(TestConstants.FILTER, TestConstants.OPTIONS, null, TestConstants.NAMESPACES, TestConstants.DITTO_HEADERS_V_2_NO_STATUS); final Adaptable actual = underTest.toAdaptable(createSubscription, TopicPath.Channel.TWIN); assertWithExternalHeadersThat(actual).isEqualTo(expected); }
@Test public void createSubscriptionFilterOnlyToAdaptable() { final String filter = "exists(attributes/test)"; final CreateSubscription createSubscription = CreateSubscription.of(filter, null, null, null, DittoHeaders.empty()); final Adaptable actual = underTest.toAdaptable(createSubscription); assertThat(actual.getPayload().getValue()).contains(JsonObject.newBuilder() .set("filter", filter) .build()); }
@Test public void createSubscriptionWithFieldsFromAdaptable() { final CreateSubscription expected = CreateSubscription.of(TestConstants.FILTER, TestConstants.OPTIONS, TestConstants.FIELDS, TestConstants.NAMESPACES, TestConstants.DITTO_HEADERS_V_2_NO_STATUS); final TopicPath topicPath = TopicPath.fromNamespace(TopicPath.ID_PLACEHOLDER) .things() .twin() .search() .subscribe() .build(); final JsonPointer path = JsonPointer.empty(); final Adaptable adaptable = Adaptable.newBuilder(topicPath) .withPayload(Payload.newBuilder(path) .withValue(JsonObject.of(String.format( "{\"filter\": \"%s\", \"options\": \"%s\", \"namespaces\": %s}", TestConstants.FILTER, TestConstants.OPTIONS, NAMESPACES_ARRAY ))) .withFields(TestConstants.FIELDS) .build()) .withHeaders(TestConstants.DITTO_HEADERS_V_2_NO_STATUS) .build(); final ThingSearchCommand<?> actual = underTest.fromAdaptable(adaptable); assertWithExternalHeadersThat(actual).isEqualTo(expected); }
@Test public void createSubscriptionWithFieldsToAdaptable() { final TopicPath topicPath = TopicPath.fromNamespace(TopicPath.ID_PLACEHOLDER) .things() .twin() .search() .subscribe() .build(); final JsonPointer path = JsonPointer.empty(); final Adaptable expected = Adaptable.newBuilder(topicPath) .withPayload(Payload.newBuilder(path) .withValue(JsonObject.of(String.format( "{\"filter\": \"%s\", \"options\": \"%s\", \"namespaces\": %s}", TestConstants.FILTER, TestConstants.OPTIONS, NAMESPACES_ARRAY ))) .withFields(TestConstants.FIELDS) .build()) .withHeaders(TestConstants.DITTO_HEADERS_V_2_NO_STATUS) .build(); final CreateSubscription createSubscription = CreateSubscription.of(TestConstants.FILTER, TestConstants.OPTIONS, TestConstants.FIELDS, TestConstants.NAMESPACES, TestConstants.DITTO_HEADERS_V_2_NO_STATUS); final Adaptable actual = underTest.toAdaptable(createSubscription, TopicPath.Channel.TWIN); assertWithExternalHeadersThat(actual).isEqualTo(expected); }
@Test public void requestSubscriptionFromAdaptable() { final RequestFromSubscription expected = RequestFromSubscription.of(TestConstants.SUBSCRIPTION_ID, TestConstants.DEMAND, TestConstants.DITTO_HEADERS_V_2_NO_STATUS); final TopicPath topicPath = TopicPath.fromNamespace(String.join(",", TestConstants.NAMESPACES)) .things() .twin() .search() .request() .build(); final JsonPointer path = JsonPointer.empty(); final Adaptable adaptable = Adaptable.newBuilder(topicPath) .withPayload(Payload.newBuilder(path) .withValue(JsonObject.of(String.format( "{\"subscriptionId\": \"%s\", \"demand\": %s}", TestConstants.SUBSCRIPTION_ID, TestConstants.DEMAND))) .build()) .withHeaders(TestConstants.DITTO_HEADERS_V_2_NO_STATUS) .build(); final ThingSearchCommand actual = underTest.fromAdaptable(adaptable); assertWithExternalHeadersThat(actual).isEqualTo(expected); }
@Test public void requestSubscriptionToAdaptable() { final TopicPath topicPath = TopicPath.fromNamespace("_") .things() .twin() .search() .request() .build(); final JsonPointer path = JsonPointer.empty(); final Adaptable expected = Adaptable.newBuilder(topicPath) .withPayload(Payload.newBuilder(path) .withValue(JsonObject.of(String.format( "{\"subscriptionId\": \"%s\", \"demand\": %s}", TestConstants.SUBSCRIPTION_ID, TestConstants.DEMAND))) .build()) .withHeaders(TestConstants.DITTO_HEADERS_V_2_NO_STATUS) .build(); final RequestFromSubscription requestFromSubscription = RequestFromSubscription.of(TestConstants.SUBSCRIPTION_ID, TestConstants.DEMAND, TestConstants.DITTO_HEADERS_V_2_NO_STATUS); final Adaptable actual = underTest.toAdaptable(requestFromSubscription, TopicPath.Channel.TWIN); assertWithExternalHeadersThat(actual).isEqualTo(expected); }
@Test public void cancelSubscriptionFromAdaptable() { final CancelSubscription expected = CancelSubscription.of(TestConstants.SUBSCRIPTION_ID, TestConstants.DITTO_HEADERS_V_2_NO_STATUS); final TopicPath topicPath = TopicPath.fromNamespace("_") .things() .twin() .search() .cancel() .build(); final JsonPointer path = JsonPointer.empty(); final Adaptable adaptable = Adaptable.newBuilder(topicPath) .withPayload(Payload.newBuilder(path) .withValue(JsonObject.of(String.format( "{\"subscriptionId\": \"%s\"}", TestConstants.SUBSCRIPTION_ID))) .build()) .withHeaders(TestConstants.DITTO_HEADERS_V_2_NO_STATUS) .build(); final ThingSearchCommand actual = underTest.fromAdaptable(adaptable); assertWithExternalHeadersThat(actual).isEqualTo(expected); }
@Test public void cancelSubscriptionToAdaptable() { final TopicPath topicPath = TopicPath.fromNamespace("_") .things() .twin() .search() .cancel() .build(); final JsonPointer path = JsonPointer.empty(); final Adaptable expected = Adaptable.newBuilder(topicPath) .withPayload(Payload.newBuilder(path) .withValue(JsonObject.of(String.format( "{\"subscriptionId\": \"%s\"}", TestConstants.SUBSCRIPTION_ID))) .build()) .withHeaders(TestConstants.DITTO_HEADERS_V_2_NO_STATUS) .build(); final CancelSubscription cancelSubscription = CancelSubscription.of(TestConstants.SUBSCRIPTION_ID, TestConstants.DITTO_HEADERS_V_2_NO_STATUS); final Adaptable actual = underTest.toAdaptable(cancelSubscription, TopicPath.Channel.TWIN); assertWithExternalHeadersThat(actual).isEqualTo(expected); }