Search in sources :

Example 1 with Subscription

use of org.zalando.nakadi.domain.Subscription in project nakadi by zalando.

the class EventTypeServiceTest method testFailToDeleteEventType.

@Test
public void testFailToDeleteEventType() throws Exception {
    final EventType eventType = buildDefaultEventType();
    doThrow(new InternalNakadiException("Can't delete event tye")).when(eventTypeRepository).removeEventType(eventType.getName());
    doReturn(Optional.of(eventType)).when(eventTypeRepository).findByNameO(eventType.getName());
    final Multimap<TopicRepository, String> topicsToDelete = mock(Multimap.class);
    doReturn(new ArrayList<Subscription>()).when(subscriptionDbRepository).listSubscriptions(ImmutableSet.of(eventType.getName()), Optional.empty(), 0, 1);
    doReturn(topicsToDelete).when(timelineService).deleteAllTimelinesForEventType(eventType.getName());
    try {
        eventTypeService.delete(eventType.getName());
    } catch (final EventTypeDeletionException e) {
        // check that topics are not deleted in Kafka
        verifyZeroInteractions(topicsToDelete);
        return;
    }
    fail("Should have thrown an EventTypeDeletionException");
}
Also used : InternalNakadiException(org.zalando.nakadi.exceptions.InternalNakadiException) TestUtils.buildDefaultEventType(org.zalando.nakadi.utils.TestUtils.buildDefaultEventType) EventType(org.zalando.nakadi.domain.EventType) EventTypeDeletionException(org.zalando.nakadi.exceptions.runtime.EventTypeDeletionException) TopicRepository(org.zalando.nakadi.repository.TopicRepository) Matchers.anyString(org.mockito.Matchers.anyString) Subscription(org.zalando.nakadi.domain.Subscription) Test(org.junit.Test)

Example 2 with Subscription

use of org.zalando.nakadi.domain.Subscription in project nakadi by zalando.

the class PostSubscriptionControllerTest method whenSubscriptionCreationDisabledThenReturnExistentSubscription.

@Test
public void whenSubscriptionCreationDisabledThenReturnExistentSubscription() throws Exception {
    final SubscriptionBase subscriptionBase = builder().buildSubscriptionBase();
    final Subscription existingSubscription = new Subscription("123", new DateTime(DateTimeZone.UTC), subscriptionBase);
    existingSubscription.setReadFrom(SubscriptionBase.InitialPosition.BEGIN);
    when(subscriptionService.getExistingSubscription(any())).thenReturn(existingSubscription);
    when(featureToggleService.isFeatureEnabled(DISABLE_SUBSCRIPTION_CREATION)).thenReturn(true);
    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) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 3 with Subscription

use of org.zalando.nakadi.domain.Subscription in project nakadi by zalando.

the class SubscriptionControllerTest method whenGetSubscriptionThenOk.

@Test
public void whenGetSubscriptionThenOk() throws Exception {
    final Subscription subscription = builder().build();
    when(subscriptionRepository.getSubscription(subscription.getId())).thenReturn(subscription);
    getSubscription(subscription.getId()).andExpect(status().isOk()).andExpect(content().string(sameJSONAs(TestUtils.OBJECT_MAPPER.writeValueAsString(subscription))));
}
Also used : Subscription(org.zalando.nakadi.domain.Subscription) Test(org.junit.Test)

Example 4 with Subscription

use of org.zalando.nakadi.domain.Subscription in project nakadi by zalando.

the class SubscriptionControllerTest method whenGetSubscriptionNoEventTypesThenStatEmpty.

@Test
@SuppressWarnings("unchecked")
public void whenGetSubscriptionNoEventTypesThenStatEmpty() throws Exception {
    final Subscription subscription = builder().withEventType("myET").build();
    when(subscriptionRepository.getSubscription(subscription.getId())).thenReturn(subscription);
    when(zkSubscriptionClient.getZkSubscriptionNodeLocked()).thenReturn(Optional.of(new ZkSubscriptionNode(Collections.emptyList(), Collections.emptyList())));
    when(eventTypeRepository.findByName("myET")).thenThrow(NoSuchEventTypeException.class);
    getSubscriptionStats(subscription.getId()).andExpect(status().isNotFound());
}
Also used : Subscription(org.zalando.nakadi.domain.Subscription) ZkSubscriptionNode(org.zalando.nakadi.service.subscription.zk.ZkSubscriptionNode) Test(org.junit.Test)

Example 5 with Subscription

use of org.zalando.nakadi.domain.Subscription in project nakadi by zalando.

the class SubscriptionControllerTest method mockGetFromRepoSubscriptionWithOwningApp.

private void mockGetFromRepoSubscriptionWithOwningApp(final String subscriptionId, final String owningApplication) throws NoSuchSubscriptionException, ServiceUnavailableException {
    final Subscription subscription = RandomSubscriptionBuilder.builder().withId(subscriptionId).withOwningApplication(owningApplication).build();
    when(subscriptionRepository.getSubscription(subscriptionId)).thenReturn(subscription);
}
Also used : Subscription(org.zalando.nakadi.domain.Subscription)

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