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");
}
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"));
}
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))));
}
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());
}
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);
}
Aggregations