Search in sources :

Example 6 with EventType

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());
}
Also used : EventPublishResult(org.zalando.nakadi.domain.EventPublishResult) JSONObject(org.json.JSONObject) TestUtils.buildDefaultEventType(org.zalando.nakadi.utils.TestUtils.buildDefaultEventType) EventType(org.zalando.nakadi.domain.EventType) JSONArray(org.json.JSONArray) Test(org.junit.Test)

Example 7 with EventType

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());
}
Also used : AccessDeniedException(org.zalando.nakadi.exceptions.runtime.AccessDeniedException) TestUtils.buildDefaultEventType(org.zalando.nakadi.utils.TestUtils.buildDefaultEventType) EventType(org.zalando.nakadi.domain.EventType) Test(org.junit.Test)

Example 8 with EventType

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());
}
Also used : EventPublishResult(org.zalando.nakadi.domain.EventPublishResult) TestUtils.buildDefaultEventType(org.zalando.nakadi.utils.TestUtils.buildDefaultEventType) EventType(org.zalando.nakadi.domain.EventType) JSONArray(org.json.JSONArray) TestUtils.createBatchItem(org.zalando.nakadi.utils.TestUtils.createBatchItem) BatchItem(org.zalando.nakadi.domain.BatchItem) ArrayList(java.util.ArrayList) BatchItemResponse(org.zalando.nakadi.domain.BatchItemResponse) Test(org.junit.Test)

Example 9 with EventType

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);
}
Also used : EventPublishResult(org.zalando.nakadi.domain.EventPublishResult) TestUtils.buildDefaultEventType(org.zalando.nakadi.utils.TestUtils.buildDefaultEventType) EventType(org.zalando.nakadi.domain.EventType) Test(org.junit.Test)

Example 10 with EventType

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()));
}
Also used : JSONObject(org.json.JSONObject) TestUtils.buildDefaultEventType(org.zalando.nakadi.utils.TestUtils.buildDefaultEventType) EventType(org.zalando.nakadi.domain.EventType) 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