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