Search in sources :

Example 21 with EventType

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

the class EventTypeControllerTest method whenUpdateEventTypeAndTimelineWaitTimeoutThen503.

@Test
public void whenUpdateEventTypeAndTimelineWaitTimeoutThen503() throws Exception {
    when(timelineSync.workWithEventType(any(), anyLong())).thenThrow(new TimeoutException());
    final EventType eventType = buildDefaultEventType();
    final Problem expectedProblem = Problem.valueOf(SERVICE_UNAVAILABLE, "Event type is currently in maintenance, please repeat request");
    putEventType(eventType, eventType.getName(), "nakadi").andExpect(status().isServiceUnavailable()).andExpect(content().string(matchesProblem(expectedProblem)));
}
Also used : TestUtils.buildDefaultEventType(org.zalando.nakadi.utils.TestUtils.buildDefaultEventType) EventType(org.zalando.nakadi.domain.EventType) Problem(org.zalando.problem.Problem) ThrowableProblem(org.zalando.problem.ThrowableProblem) TestUtils.invalidProblem(org.zalando.nakadi.utils.TestUtils.invalidProblem) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.Test)

Example 22 with EventType

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

the class EventTypeControllerTest method whenPOSTInvalidSchemaThen422.

@Test
public void whenPOSTInvalidSchemaThen422() throws Exception {
    final EventType eventType = buildDefaultEventType();
    eventType.getSchema().setSchema("{\"not\": {\"type\": \"object\"} }");
    eventType.setCategory(BUSINESS);
    final Problem expectedProblem = new InvalidEventTypeException("Invalid schema: Invalid schema found in [#]: " + "extraneous key [not] is not permitted").asProblem();
    postETAndExpect422WithProblem(eventType, expectedProblem);
}
Also used : InvalidEventTypeException(org.zalando.nakadi.exceptions.InvalidEventTypeException) TestUtils.buildDefaultEventType(org.zalando.nakadi.utils.TestUtils.buildDefaultEventType) EventType(org.zalando.nakadi.domain.EventType) Problem(org.zalando.problem.Problem) ThrowableProblem(org.zalando.problem.ThrowableProblem) TestUtils.invalidProblem(org.zalando.nakadi.utils.TestUtils.invalidProblem) Test(org.junit.Test)

Example 23 with EventType

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

the class EventTypeControllerTest method whenPUTWithInvalidEnrichmentStrategyThen422.

@Test
public void whenPUTWithInvalidEnrichmentStrategyThen422() throws Exception {
    final EventTypeTestBuilder builder = EventTypeTestBuilder.builder();
    builder.enrichmentStrategies(Lists.newArrayList(EnrichmentStrategyDescriptor.METADATA_ENRICHMENT));
    final EventType original = builder.build();
    builder.enrichmentStrategies(new ArrayList<>());
    final EventType update = builder.build();
    doReturn(original).when(eventTypeRepository).findByName(any());
    putEventType(update, update.getName()).andExpect(status().isUnprocessableEntity()).andExpect(content().contentType("application/problem+json"));
}
Also used : TestUtils.buildDefaultEventType(org.zalando.nakadi.utils.TestUtils.buildDefaultEventType) EventType(org.zalando.nakadi.domain.EventType) EventTypeTestBuilder(org.zalando.nakadi.utils.EventTypeTestBuilder) Test(org.junit.Test)

Example 24 with EventType

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

the class EventTypeControllerTest method whenCreateSuccessfullyThen201.

@Test
public void whenCreateSuccessfullyThen201() throws Exception {
    final EventType et = buildDefaultEventType();
    final Timeline timeline = buildTimelineWithTopic("topic1");
    when(timelineService.createDefaultTimeline(anyString(), anyInt(), anyLong())).thenReturn(timeline);
    doReturn(et).when(eventTypeRepository).saveEventType(any(EventType.class));
    postEventType(et).andExpect(status().isCreated()).andExpect(content().string(""));
    verify(eventTypeRepository, times(1)).saveEventType(any(EventType.class));
    verify(timelineService, times(1)).createDefaultTimeline(anyString(), anyInt(), anyLong());
}
Also used : Timeline(org.zalando.nakadi.domain.Timeline) TestUtils.buildDefaultEventType(org.zalando.nakadi.utils.TestUtils.buildDefaultEventType) EventType(org.zalando.nakadi.domain.EventType) Test(org.junit.Test)

Example 25 with EventType

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

the class EventTypeControllerTest method whenPUTEventTypeWithWrongPartitionKeyFieldsThen422.

@Test
public void whenPUTEventTypeWithWrongPartitionKeyFieldsThen422() throws Exception {
    final EventType eventType = EventTypeTestBuilder.builder().partitionKeyFields(Collections.singletonList("blabla")).build();
    doReturn(eventType).when(eventTypeRepository).findByName(eventType.getName());
    putEventType(eventType, eventType.getName()).andExpect(status().isUnprocessableEntity()).andExpect(content().contentType("application/problem+json"));
}
Also used : 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