Search in sources :

Example 1 with SubscriptionValidationService

use of org.zalando.nakadi.service.subscription.SubscriptionValidationService in project nakadi by zalando.

the class SubscriptionValidationServiceTest method setUp.

@Before
public void setUp() throws InternalNakadiException {
    final NakadiSettings nakadiSettings = mock(NakadiSettings.class);
    when(nakadiSettings.getMaxSubscriptionPartitions()).thenReturn(MAX_SUBSCRIPTION_PARTITIONS);
    topicRepository = mock(TopicRepository.class);
    when(topicRepository.listPartitionNames(argThat(isOneOf(topicForET(ET1), topicForET(ET2), topicForET(ET3))))).thenReturn(ImmutableList.of(P0));
    etRepo = mock(EventTypeRepository.class);
    final Map<String, EventType> eventTypes = new HashMap<>();
    for (final String etName : new String[] { ET1, ET2, ET3 }) {
        final EventType eventType = new EventType();
        eventType.setName(etName);
        eventTypes.put(etName, eventType);
    }
    when(etRepo.findByNameO(any())).thenAnswer(invocation -> Optional.ofNullable(eventTypes.get(invocation.getArguments()[0])));
    final TimelineService timelineService = mock(TimelineService.class);
    for (final EventType et : eventTypes.values()) {
        final Timeline timeline = mock(Timeline.class);
        when(timeline.getTopic()).thenReturn(topicForET(et.getName()));
        when(timeline.getEventType()).thenReturn(et.getName());
        when(timelineService.getActiveTimeline(eq(et.getName()))).thenReturn(timeline);
    }
    when(timelineService.getTopicRepository((Timeline) any())).thenReturn(topicRepository);
    when(timelineService.getTopicRepository((EventType) any())).thenReturn(topicRepository);
    cursorConverter = mock(CursorConverter.class);
    subscriptionValidationService = new SubscriptionValidationService(timelineService, etRepo, nakadiSettings, cursorConverter);
    subscriptionBase = new SubscriptionBase();
    subscriptionBase.setEventTypes(ImmutableSet.of(ET1, ET2, ET3));
    subscriptionBase.setReadFrom(SubscriptionBase.InitialPosition.CURSORS);
}
Also used : SubscriptionBase(org.zalando.nakadi.domain.SubscriptionBase) Timeline(org.zalando.nakadi.domain.Timeline) EventType(org.zalando.nakadi.domain.EventType) HashMap(java.util.HashMap) EventTypeRepository(org.zalando.nakadi.repository.EventTypeRepository) TimelineService(org.zalando.nakadi.service.timeline.TimelineService) SubscriptionValidationService(org.zalando.nakadi.service.subscription.SubscriptionValidationService) TopicRepository(org.zalando.nakadi.repository.TopicRepository) NakadiSettings(org.zalando.nakadi.config.NakadiSettings) Before(org.junit.Before)

Aggregations

HashMap (java.util.HashMap)1 Before (org.junit.Before)1 NakadiSettings (org.zalando.nakadi.config.NakadiSettings)1 EventType (org.zalando.nakadi.domain.EventType)1 SubscriptionBase (org.zalando.nakadi.domain.SubscriptionBase)1 Timeline (org.zalando.nakadi.domain.Timeline)1 EventTypeRepository (org.zalando.nakadi.repository.EventTypeRepository)1 TopicRepository (org.zalando.nakadi.repository.TopicRepository)1 SubscriptionValidationService (org.zalando.nakadi.service.subscription.SubscriptionValidationService)1 TimelineService (org.zalando.nakadi.service.timeline.TimelineService)1