SubscriptionEventAdapter extends AbstractThingAdapter<SubscriptionEvent<?>> { public static SubscriptionEventAdapter of(final HeaderTranslator headerTranslator, final ErrorRegistry<?> errorRegistry) { return new SubscriptionEventAdapter(checkNotNull(headerTranslator, "headerTranslator"), checkNotNull(errorRegistry, "errorRegistry")); } private  SubscriptionEventAdapter(final HeaderTranslator headerTranslator,
            final ErrorRegistry<?> errorRegistry); static SubscriptionEventAdapter of(final HeaderTranslator headerTranslator,
            final ErrorRegistry<?> errorRegistry); @Override Set<TopicPath.Criterion> getCriteria(); @Override Set<TopicPath.Action> getActions(); @Override boolean isForResponses(); @Override Set<TopicPath.SearchAction> getSearchActions();  }
@Test public void subscriptioncreatedFromAdaptable() { final TopicPath topicPath = TopicPath.fromNamespace("_") .things() .twin() .search() .generated() .build(); final JsonPointer path = JsonPointer.empty(); final SubscriptionCreated expected = SubscriptionCreated.of(TestConstants.SUBSCRIPTION_ID, TestConstants.DITTO_HEADERS_V_2_NO_STATUS); 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 SubscriptionEvent<?> actual = underTest.fromAdaptable(adaptable); assertWithExternalHeadersThat(actual).isEqualTo(expected); }
@Test public void subscriptionCreatedToAdaptable() { final TopicPath topicPath = TopicPath.fromNamespace("_") .things() .twin() .search() .generated() .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 SubscriptionCreated subscriptionCreated = SubscriptionCreated.of(TestConstants.SUBSCRIPTION_ID, TestConstants.DITTO_HEADERS_V_2_NO_STATUS); final Adaptable actual = underTest.toAdaptable(subscriptionCreated, TopicPath.Channel.TWIN); assertWithExternalHeadersThat(actual).isEqualTo(expected); }
@Test public void subscriptionCompleteFromAdaptable() { final TopicPath topicPath = TopicPath.fromNamespace("_") .things() .twin() .search() .complete() .build(); final JsonPointer path = JsonPointer.empty(); final SubscriptionComplete expected = SubscriptionComplete.of(TestConstants.SUBSCRIPTION_ID, TestConstants.DITTO_HEADERS_V_2); final Adaptable adaptable = Adaptable.newBuilder(topicPath) .withPayload(Payload.newBuilder(path) .withValue(JsonObject.of( String.format("{\"subscriptionId\": \"%s\"}", TestConstants.SUBSCRIPTION_ID))) .withRevision(TestConstants.REVISION) .build()) .withHeaders(TestConstants.HEADERS_V_2) .build(); final SubscriptionEvent<?> actual = underTest.fromAdaptable(adaptable); assertWithExternalHeadersThat(actual).isEqualTo(expected); }
@Test public void subscriptionCompleteToAdaptable() { final TopicPath topicPath = TopicPath.fromNamespace("_") .things() .twin() .search() .complete() .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 SubscriptionComplete subscriptionComplete = SubscriptionComplete.of(TestConstants.SUBSCRIPTION_ID, TestConstants.DITTO_HEADERS_V_2_NO_STATUS); final Adaptable actual = underTest.toAdaptable(subscriptionComplete, TopicPath.Channel.TWIN); assertWithExternalHeadersThat(actual).isEqualTo(expected); }
@Test public void subscriptionFailedFromAdaptable() { final TopicPath topicPath = TopicPath.fromNamespace("_") .things() .twin() .search() .failed() .build(); final JsonPointer path = JsonPointer.empty(); final SubscriptionProtocolErrorException error = SubscriptionProtocolErrorException.newBuilder() .message("Mock error") .build(); final SubscriptionFailed expected = SubscriptionFailed.of(TestConstants.SUBSCRIPTION_ID, error, TestConstants.DITTO_HEADERS_V_2_NO_STATUS); final Adaptable adaptable = Adaptable.newBuilder(topicPath) .withPayload(Payload.newBuilder(path) .withValue(JsonObject.of(String.format("{\"subscriptionId\": \"%s\", \"error\": %s}", TestConstants.SUBSCRIPTION_ID, error.toJson()))) .build()) .withHeaders(TestConstants.DITTO_HEADERS_V_2_NO_STATUS) .build(); final SubscriptionEvent<?> actual = underTest.fromAdaptable(adaptable); assertWithExternalHeadersThat(actual).isEqualTo(expected); }
@Test public void subscriptionFailedToAdaptable() { final TopicPath topicPath = TopicPath.fromNamespace("_") .things() .twin() .search() .failed() .build(); final JsonPointer path = JsonPointer.empty(); final Adaptable expected = Adaptable.newBuilder(topicPath) .withPayload(Payload.newBuilder(path) .withValue(JsonObject.of(String.format("{\"subscriptionId\": \"%s\", \"error\": %s}", TestConstants.SUBSCRIPTION_ID, TestConstants.EXCEPTION.toJson()))) .build()) .withHeaders(TestConstants.DITTO_HEADERS_V_2_NO_STATUS) .build(); final SubscriptionFailed subscriptionFailed = SubscriptionFailed.of(TestConstants.SUBSCRIPTION_ID, TestConstants.EXCEPTION, TestConstants.DITTO_HEADERS_V_2_NO_STATUS); final Adaptable actual = underTest.toAdaptable(subscriptionFailed, TopicPath.Channel.TWIN); assertWithExternalHeadersThat(actual).isEqualTo(expected); }
@Test public void subscriptionHasNextFromAdaptable() { final TopicPath topicPath = TopicPath.fromNamespace("_") .things() .twin() .search() .hasNext() .build(); final SubscriptionHasNextPage expected = SubscriptionHasNextPage.of(TestConstants.SUBSCRIPTION_ID, TestConstants.ITEMS, TestConstants.DITTO_HEADERS_V_2_NO_STATUS); final JsonPointer path = JsonPointer.empty(); final Adaptable adaptable = Adaptable.newBuilder(topicPath) .withPayload(Payload.newBuilder(path) .withValue(JsonObject.of(String.format("{\"subscriptionId\": \"%s\", \"items\": %s}", TestConstants.SUBSCRIPTION_ID, TestConstants.ITEMS))) .build()) .withHeaders(TestConstants.DITTO_HEADERS_V_2_NO_STATUS) .build(); final SubscriptionEvent<?> actual = underTest.fromAdaptable(adaptable); assertWithExternalHeadersThat(actual).isEqualTo(expected); }
@Test public void subscriptionHasNextToAdaptable() { final TopicPath topicPath = TopicPath.fromNamespace("_") .things() .twin() .search() .hasNext() .build(); final JsonPointer path = JsonPointer.empty(); final Adaptable expected = Adaptable.newBuilder(topicPath) .withPayload(Payload.newBuilder(path) .withValue(JsonObject.of(String.format("{\"subscriptionId\": \"%s\", \"items\": %s}", TestConstants.SUBSCRIPTION_ID, TestConstants.ITEMS))) .build()) .withHeaders(TestConstants.DITTO_HEADERS_V_2_NO_STATUS) .build(); final SubscriptionHasNextPage subscriptionHasNextPage = SubscriptionHasNextPage.of(TestConstants.SUBSCRIPTION_ID, TestConstants.ITEMS, TestConstants.DITTO_HEADERS_V_2_NO_STATUS); final Adaptable actual = underTest.toAdaptable(subscriptionHasNextPage, TopicPath.Channel.TWIN); assertWithExternalHeadersThat(actual).isEqualTo(expected); }