use of org.zalando.nakadi.domain.Subscription in project nakadi by zalando.
the class SubscriptionDbRepositoryTest method whenListSubscriptionsByOwningApplicationAndEventTypeThenOk.
@Test
public void whenListSubscriptionsByOwningApplicationAndEventTypeThenOk() throws ServiceUnavailableException {
final String owningApp = TestUtils.randomUUID();
final String owningApp2 = TestUtils.randomUUID();
final List<Subscription> testSubscriptions = ImmutableList.of(RandomSubscriptionBuilder.builder().withOwningApplication(owningApp).withEventType("et1").build(), RandomSubscriptionBuilder.builder().withOwningApplication(owningApp).withEventTypes(ImmutableSet.of("et2", "et1")).build(), RandomSubscriptionBuilder.builder().withOwningApplication(owningApp).withEventType("et1").build(), RandomSubscriptionBuilder.builder().withOwningApplication(owningApp).withEventType("et2").build(), RandomSubscriptionBuilder.builder().withOwningApplication(owningApp).withEventTypes(ImmutableSet.of("et2", "et3")).build(), RandomSubscriptionBuilder.builder().withOwningApplication(owningApp2).withEventType("et1").build(), RandomSubscriptionBuilder.builder().withOwningApplication(owningApp2).withEventType("et2").build());
testSubscriptions.forEach(this::insertSubscriptionToDB);
final List<Subscription> expectedSubscriptions = testSubscriptions.stream().filter(sub -> owningApp.equals(sub.getOwningApplication()) && sub.getEventTypes().contains("et1")).sorted(SUBSCRIPTION_CREATION_DATE_DESC_COMPARATOR).collect(toList());
final List<Subscription> subscriptions = repository.listSubscriptions(ImmutableSet.of("et1"), Optional.of(owningApp), 0, 10);
assertThat(subscriptions, equalTo(expectedSubscriptions));
}
use of org.zalando.nakadi.domain.Subscription in project nakadi by zalando.
the class SubscriptionDbRepositoryTest method whenDeleteSubscriptionThenOk.
@Test
public void whenDeleteSubscriptionThenOk() throws ServiceUnavailableException, NoSuchSubscriptionException {
final Subscription subscription = RandomSubscriptionBuilder.builder().build();
insertSubscriptionToDB(subscription);
repository.deleteSubscription(subscription.getId());
final Integer count = template.queryForObject("SELECT count(*) FROM zn_data.subscription WHERE s_id = ?", Integer.class, subscription.getId());
assertThat("Subscription is removed", count, equalTo(0));
}
use of org.zalando.nakadi.domain.Subscription in project nakadi by zalando.
the class PostSubscriptionControllerTest method whenPostValidSubscriptionThenOk.
@Test
public void whenPostValidSubscriptionThenOk() throws Exception {
final SubscriptionBase subscriptionBase = builder().buildSubscriptionBase();
final Subscription subscription = new Subscription("123", new DateTime(DateTimeZone.UTC), subscriptionBase);
when(subscriptionService.getExistingSubscription(any())).thenThrow(new NoSubscriptionException("", null));
when(subscriptionService.createSubscription(any())).thenReturn(subscription);
postSubscription(subscriptionBase).andExpect(status().isCreated()).andExpect(content().contentTypeCompatibleWith(APPLICATION_JSON)).andExpect(content().string(sameJSONAs(TestUtils.JSON_TEST_HELPER.asJsonString(subscription)))).andExpect(header().string("Location", "/subscriptions/123")).andExpect(header().string("Content-Location", "/subscriptions/123"));
}
use of org.zalando.nakadi.domain.Subscription in project nakadi by zalando.
the class PostSubscriptionControllerTest method whenSubscriptionExistsThenReturnIt.
@Test
public void whenSubscriptionExistsThenReturnIt() throws Exception {
final SubscriptionBase subscriptionBase = builder().buildSubscriptionBase();
final Subscription existingSubscription = new Subscription("123", new DateTime(DateTimeZone.UTC), subscriptionBase);
when(subscriptionService.getExistingSubscription(any())).thenReturn(existingSubscription);
when(subscriptionService.createSubscription(any())).thenThrow(new NoEventTypeException("msg"));
postSubscription(subscriptionBase).andExpect(status().isOk()).andExpect(content().contentTypeCompatibleWith(APPLICATION_JSON)).andExpect(content().string(sameJSONAs(TestUtils.JSON_TEST_HELPER.asJsonString(existingSubscription)))).andExpect(header().string("Location", "/subscriptions/123")).andExpect(header().doesNotExist("Content-Location"));
}
use of org.zalando.nakadi.domain.Subscription in project nakadi by zalando.
the class SubscriptionControllerTest method whenListSubscriptionsWithoutQueryParamsThenOk.
@Test
public void whenListSubscriptionsWithoutQueryParamsThenOk() throws Exception {
final List<Subscription> subscriptions = createRandomSubscriptions(10);
when(subscriptionRepository.listSubscriptions(any(), any(), anyInt(), anyInt())).thenReturn(subscriptions);
final PaginationWrapper subscriptionList = new PaginationWrapper(subscriptions, new PaginationLinks());
getSubscriptions().andExpect(status().isOk()).andExpect(content().string(TestUtils.JSON_TEST_HELPER.matchesObject(subscriptionList)));
verify(subscriptionRepository, times(1)).listSubscriptions(ImmutableSet.of(), Optional.empty(), 0, 20);
}
Aggregations