Search in sources :

Example 16 with EventType

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

the class EventTypeControllerTest method whenDeleteEventTypeThenOk.

@Test
public void whenDeleteEventTypeThenOk() throws Exception {
    final EventType eventType = buildDefaultEventType();
    doReturn(eventType).when(eventTypeRepository).findByName(eventType.getName());
    doReturn(Optional.of(eventType)).when(eventTypeRepository).findByNameO(eventType.getName());
    doNothing().when(eventTypeRepository).removeEventType(eventType.getName());
    final Multimap<TopicRepository, String> topicsToDelete = ArrayListMultimap.create();
    topicsToDelete.put(topicRepository, "topic");
    doReturn(topicsToDelete).when(timelineService).deleteAllTimelinesForEventType(eventType.getName());
    deleteEventType(eventType.getName()).andExpect(status().isOk()).andExpect(content().string(""));
    verify(eventTypeRepository, times(1)).removeEventType(eventType.getName());
    verify(timelineService, times(1)).deleteAllTimelinesForEventType(eventType.getName());
}
Also used : TestUtils.buildDefaultEventType(org.zalando.nakadi.utils.TestUtils.buildDefaultEventType) EventType(org.zalando.nakadi.domain.EventType) TopicRepository(org.zalando.nakadi.repository.TopicRepository) Matchers.containsString(org.hamcrest.Matchers.containsString) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 17 with EventType

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

the class EventTypeControllerTest method whenPUTthenWarning.

@Test
public void whenPUTthenWarning() throws Exception {
    final EventType eventType = buildDefaultEventType();
    eventType.setPartitionStrategy(PartitionStrategy.RANDOM_STRATEGY);
    postEventType(eventType).andExpect(status().isCreated());
    final EventType updatedEventType = EventTypeTestBuilder.builder().name(eventType.getName()).partitionStrategy(PartitionStrategy.USER_DEFINED_STRATEGY).createdAt(eventType.getCreatedAt()).build();
    doReturn(eventType).when(eventTypeRepository).findByName(any());
    putEventType(updatedEventType, eventType.getName()).andExpect(header().string("Warning", "299 nakadi \"I am warning you\""));
}
Also used : TestUtils.buildDefaultEventType(org.zalando.nakadi.utils.TestUtils.buildDefaultEventType) EventType(org.zalando.nakadi.domain.EventType) Test(org.junit.Test)

Example 18 with EventType

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

the class EventTypeControllerTest method whenPOSTBusinessEventTypeMetadataThen422.

@Test
public void whenPOSTBusinessEventTypeMetadataThen422() throws Exception {
    final EventType eventType = buildDefaultEventType();
    eventType.getSchema().setSchema("{\"type\": \"object\", \"properties\": {\"metadata\": {\"type\": \"object\"} }}");
    eventType.setCategory(BUSINESS);
    final Problem expectedProblem = new InvalidEventTypeException("\"metadata\" property is reserved").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 19 with EventType

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

the class EventTypeControllerTest method whenPostOptionsRetentionTimeExist.

@Test
public void whenPostOptionsRetentionTimeExist() throws Exception {
    final EventType defaultEventType = buildDefaultEventType();
    defaultEventType.getOptions().setRetentionTime(TOPIC_RETENTION_TIME_MS);
    postEventType(defaultEventType).andExpect(status().is2xxSuccessful());
    final ArgumentCaptor<EventTypeBase> eventTypeCaptor = ArgumentCaptor.forClass(EventTypeBase.class);
    verify(eventTypeRepository, times(1)).saveEventType(eventTypeCaptor.capture());
    assertEquals(TOPIC_RETENTION_TIME_MS, eventTypeCaptor.getValue().getOptions().getRetentionTime().longValue());
}
Also used : TestUtils.buildDefaultEventType(org.zalando.nakadi.utils.TestUtils.buildDefaultEventType) EventType(org.zalando.nakadi.domain.EventType) EventTypeBase(org.zalando.nakadi.domain.EventTypeBase) Test(org.junit.Test)

Example 20 with EventType

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

the class EventTypeControllerTest method whenPostOptionsRetentionTimeSmallerThanMin.

@Test
public void whenPostOptionsRetentionTimeSmallerThanMin() throws Exception {
    final EventType defaultEventType = buildDefaultEventType();
    defaultEventType.getOptions().setRetentionTime(86399999L);
    postEventType(defaultEventType).andExpect(status().is4xxClientError()).andExpect(content().string(new StringContains("Field \\\"options.retention_time\\\" can not be less than 86400000")));
}
Also used : TestUtils.buildDefaultEventType(org.zalando.nakadi.utils.TestUtils.buildDefaultEventType) EventType(org.zalando.nakadi.domain.EventType) StringContains(org.hamcrest.core.StringContains) 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