use of org.zalando.nakadi.domain.EventType in project nakadi by zalando.
the class EventPublisherTest method whenEventHasEidThenSetItInTheResponse.
@Test
public void whenEventHasEidThenSetItInTheResponse() throws Exception {
final EventType eventType = buildDefaultEventType();
final JSONObject event = buildBusinessEvent();
final JSONArray batch = new JSONArray(Arrays.asList(event));
mockSuccessfulValidation(eventType);
final EventPublishResult result = publisher.publish(batch.toString(), eventType.getName());
assertThat(result.getResponses().get(0).getEid(), equalTo(event.getJSONObject("metadata").optString("eid")));
verify(topicRepository, times(1)).syncPostBatch(any(), any());
}
use of org.zalando.nakadi.domain.EventType in project nakadi by zalando.
the class EventPublisherTest method whenPublishAuthorizationIsTakenIntoAccount.
@Test(expected = AccessDeniedException.class)
public void whenPublishAuthorizationIsTakenIntoAccount() throws Exception {
final EventType et = buildDefaultEventType();
mockSuccessfulValidation(et);
Mockito.doThrow(new AccessDeniedException(null, null)).when(authzValidator).authorizeEventTypeWrite(Mockito.eq(et));
publisher.publish(buildDefaultBatch(1).toString(), et.getName());
}
use of org.zalando.nakadi.domain.EventType in project nakadi by zalando.
the class EventPublisherTest method whenPartitionFailsThenSubsequentItemsAreAborted.
@Test
public void whenPartitionFailsThenSubsequentItemsAreAborted() throws Exception {
final EventType eventType = buildDefaultEventType();
final JSONArray array = buildDefaultBatch(2);
final List<BatchItem> batch = new ArrayList<>();
batch.add(createBatchItem(array.getJSONObject(0)));
batch.add(createBatchItem(array.getJSONObject(1)));
mockSuccessfulValidation(eventType);
mockFaultPartition();
final EventPublishResult result = publisher.publish(createStringFromBatchItems(batch), eventType.getName());
assertThat(result.getStatus(), equalTo(EventPublishingStatus.ABORTED));
final BatchItemResponse first = result.getResponses().get(0);
assertThat(first.getPublishingStatus(), equalTo(EventPublishingStatus.FAILED));
assertThat(first.getStep(), equalTo(EventPublishingStep.PARTITIONING));
assertThat(first.getDetail(), equalTo("partition error"));
final BatchItemResponse second = result.getResponses().get(1);
assertThat(second.getPublishingStatus(), equalTo(EventPublishingStatus.ABORTED));
assertThat(second.getStep(), equalTo(EventPublishingStep.VALIDATING));
assertThat(second.getDetail(), is(isEmptyString()));
verify(cache, times(2)).getValidator(any());
verify(partitionResolver, times(1)).resolvePartition(any(), any());
}
use of org.zalando.nakadi.domain.EventType in project nakadi by zalando.
the class EventPublisherTest method testWrite.
@Test
public void testWrite() throws Exception {
final EventType eventType = EventTypeTestBuilder.builder().build();
Mockito.when(cache.getEventType(eventType.getName())).thenReturn(eventType);
mockSuccessfulValidation(eventType);
final EventPublishResult result = publisher.publish(buildDefaultBatch(0).toString(), eventType.getName());
Assert.assertEquals(result.getStatus(), EventPublishingStatus.SUBMITTED);
}
use of org.zalando.nakadi.domain.EventType in project nakadi by zalando.
the class EventTypeServiceTest method whenEventTypeCreatedThenKPIEventSubmitted.
@Test
public void whenEventTypeCreatedThenKPIEventSubmitted() throws Exception {
final EventType et = buildDefaultEventType();
eventTypeService.create(et);
checkKPIEventSubmitted(nakadiKpiPublisher, KPI_ET_LOG_EVENT_TYPE, new JSONObject().put("event_type", et.getName()).put("status", "created").put("category", et.getCategory()).put("authz", "disabled").put("compatibility_mode", et.getCompatibilityMode()));
}
Aggregations