Search in sources :

Example 31 with Subscription

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));
}
Also used : Matchers.isEmptyOrNullString(org.hamcrest.Matchers.isEmptyOrNullString) Subscription(org.zalando.nakadi.domain.Subscription) Test(org.junit.Test)

Example 32 with Subscription

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));
}
Also used : Subscription(org.zalando.nakadi.domain.Subscription) Test(org.junit.Test)

Example 33 with Subscription

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"));
}
Also used : SubscriptionBase(org.zalando.nakadi.domain.SubscriptionBase) NoSubscriptionException(org.zalando.nakadi.exceptions.runtime.NoSubscriptionException) Subscription(org.zalando.nakadi.domain.Subscription) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 34 with Subscription

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"));
}
Also used : SubscriptionBase(org.zalando.nakadi.domain.SubscriptionBase) Subscription(org.zalando.nakadi.domain.Subscription) NoEventTypeException(org.zalando.nakadi.exceptions.runtime.NoEventTypeException) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 35 with Subscription

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);
}
Also used : PaginationLinks(org.zalando.nakadi.domain.PaginationLinks) Subscription(org.zalando.nakadi.domain.Subscription) PaginationWrapper(org.zalando.nakadi.domain.PaginationWrapper) Test(org.junit.Test)

Aggregations

Subscription (org.zalando.nakadi.domain.Subscription)55 Test (org.junit.Test)40 NakadiTestUtils.createSubscription (org.zalando.nakadi.webservice.utils.NakadiTestUtils.createSubscription)21 EventType (org.zalando.nakadi.domain.EventType)15 SubscriptionBase (org.zalando.nakadi.domain.SubscriptionBase)12 Matchers.isEmptyString (org.hamcrest.Matchers.isEmptyString)11 List (java.util.List)10 SubscriptionCursorWithoutToken (org.zalando.nakadi.view.SubscriptionCursorWithoutToken)9 TestStreamingClient (org.zalando.nakadi.webservice.utils.TestStreamingClient)9 ImmutableList (com.google.common.collect.ImmutableList)8 Collectors (java.util.stream.Collectors)8 SubscriptionCursor (org.zalando.nakadi.view.SubscriptionCursor)8 ItemsWrapper (org.zalando.nakadi.domain.ItemsWrapper)7 PaginationLinks (org.zalando.nakadi.domain.PaginationLinks)7 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)6 IOException (java.io.IOException)6 Optional (java.util.Optional)6 PaginationWrapper (org.zalando.nakadi.domain.PaginationWrapper)6 SubscriptionEventTypeStats (org.zalando.nakadi.domain.SubscriptionEventTypeStats)6 NakadiTestUtils.createEventType (org.zalando.nakadi.webservice.utils.NakadiTestUtils.createEventType)5