Search in sources :

Example 41 with EventType

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

the class EventTypeControllerTest method whenPostWithEmptyAuthorizationListThen422.

@Test
public void whenPostWithEmptyAuthorizationListThen422() throws Exception {
    final EventType eventType = buildDefaultEventType();
    eventType.setAuthorization(new ResourceAuthorization(ImmutableList.of(), ImmutableList.of(), ImmutableList.of()));
    postEventType(eventType).andExpect(status().isUnprocessableEntity()).andExpect(content().contentType("application/problem+json")).andExpect(content().string(containsString("Field \\\"authorization.admins\\\" must contain at least one attribute"))).andExpect(content().string(containsString("Field \\\"authorization.readers\\\" must contain at least one attribute"))).andExpect(content().string(containsString("Field \\\"authorization.writers\\\" must contain at least one attribute")));
}
Also used : TestUtils.buildDefaultEventType(org.zalando.nakadi.utils.TestUtils.buildDefaultEventType) EventType(org.zalando.nakadi.domain.EventType) ResourceAuthorization(org.zalando.nakadi.domain.ResourceAuthorization) Test(org.junit.Test)

Example 42 with EventType

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

the class EnrichmentTest method enrichAppliesStrategies.

@Test
public void enrichAppliesStrategies() throws Exception {
    final EventType eventType = buildDefaultEventType();
    eventType.getEnrichmentStrategies().add(EnrichmentStrategyDescriptor.METADATA_ENRICHMENT);
    final JSONObject event = new JSONObject();
    final BatchItem batchItem = createBatchItem(event);
    final EnrichmentStrategy strategy = mock(EnrichmentStrategy.class);
    Mockito.doReturn(strategy).when(registry).getStrategy(EnrichmentStrategyDescriptor.METADATA_ENRICHMENT);
    enrichment.enrich(batchItem, eventType);
    verify(strategy, times(1)).enrich(batchItem, eventType);
}
Also used : JSONObject(org.json.JSONObject) EventType(org.zalando.nakadi.domain.EventType) TestUtils.buildDefaultEventType(org.zalando.nakadi.utils.TestUtils.buildDefaultEventType) TestUtils.createBatchItem(org.zalando.nakadi.utils.TestUtils.createBatchItem) BatchItem(org.zalando.nakadi.domain.BatchItem) Test(org.junit.Test)

Example 43 with EventType

use of org.zalando.nakadi.domain.EventType 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)

Example 44 with EventType

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

the class VersionOneConverterTest method testInvalidCursorExceptionOnNotExistentTimeline.

@Test
public void testInvalidCursorExceptionOnNotExistentTimeline() throws Exception {
    final Cursor cursor = new Cursor("1", "001-0002-012345");
    final String eventTypeName = "my_et";
    final Timeline firstTimeline = mock(Timeline.class);
    when(firstTimeline.getOrder()).thenReturn(1);
    final EventType eventType = mock(EventType.class);
    when(eventTypeCache.getTimelinesOrdered(eq(eventTypeName))).thenReturn(Collections.singletonList(firstTimeline));
    try {
        converter.convert(eventTypeName, cursor);
        Assert.fail("Convert should throw exception on invalid cursor");
    } catch (final InvalidCursorException ex) {
        Assert.assertEquals(CursorError.UNAVAILABLE, ex.getError());
    }
}
Also used : Timeline(org.zalando.nakadi.domain.Timeline) EventType(org.zalando.nakadi.domain.EventType) InvalidCursorException(org.zalando.nakadi.exceptions.InvalidCursorException) NakadiCursor(org.zalando.nakadi.domain.NakadiCursor) Cursor(org.zalando.nakadi.view.Cursor) Test(org.junit.Test)

Example 45 with EventType

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

the class SchemaServiceTest method testNonExistingVersionNumber.

@Test
public void testNonExistingVersionNumber() throws Exception {
    final EventType eventType = buildDefaultEventType();
    Mockito.when(schemaRepository.getSchemaVersion(eventType.getName(), eventType.getSchema().getVersion().bump(Version.Level.MINOR).toString())).thenThrow(NoSuchSchemaException.class);
    final Result<EventTypeSchema> result = schemaService.getSchemaVersion(eventType.getName(), eventType.getSchema().getVersion().bump(Version.Level.MINOR).toString());
    Assert.assertFalse(result.isSuccessful());
    Assert.assertEquals(Response.Status.NOT_FOUND, result.getProblem().getStatus());
}
Also used : EventTypeSchema(org.zalando.nakadi.domain.EventTypeSchema) EventType(org.zalando.nakadi.domain.EventType) TestUtils.buildDefaultEventType(org.zalando.nakadi.utils.TestUtils.buildDefaultEventType) Test(org.junit.Test)

Aggregations

EventType (org.zalando.nakadi.domain.EventType)216 Test (org.junit.Test)183 TestUtils.buildDefaultEventType (org.zalando.nakadi.utils.TestUtils.buildDefaultEventType)138 JSONObject (org.json.JSONObject)40 Problem (org.zalando.problem.Problem)21 InternalNakadiException (org.zalando.nakadi.exceptions.InternalNakadiException)18 Matchers.containsString (org.hamcrest.Matchers.containsString)17 JSONArray (org.json.JSONArray)17 EventPublishResult (org.zalando.nakadi.domain.EventPublishResult)17 TestUtils.invalidProblem (org.zalando.nakadi.utils.TestUtils.invalidProblem)17 ThrowableProblem (org.zalando.problem.ThrowableProblem)17 Timeline (org.zalando.nakadi.domain.Timeline)16 NoSuchEventTypeException (org.zalando.nakadi.exceptions.NoSuchEventTypeException)14 EventTypeTestBuilder (org.zalando.nakadi.utils.EventTypeTestBuilder)14 BatchItem (org.zalando.nakadi.domain.BatchItem)12 TestUtils.resourceAsString (org.zalando.nakadi.utils.TestUtils.resourceAsString)12 List (java.util.List)11 Subscription (org.zalando.nakadi.domain.Subscription)11 TestUtils.createBatchItem (org.zalando.nakadi.utils.TestUtils.createBatchItem)11 Collectors (java.util.stream.Collectors)9