Search in sources :

Example 31 with EventType

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

the class EventTypeControllerTest method whenPostWithValidAuthorizationThenCreated.

@Test
public void whenPostWithValidAuthorizationThenCreated() throws Exception {
    final EventType eventType = buildDefaultEventType();
    eventType.setAuthorization(new ResourceAuthorization(ImmutableList.of(new ResourceAuthorizationAttribute("type1", "value1")), ImmutableList.of(new ResourceAuthorizationAttribute("type2", "value2")), ImmutableList.of(new ResourceAuthorizationAttribute("type3", "value3"))));
    doReturn(eventType).when(eventTypeRepository).saveEventType(any(EventType.class));
    when(topicRepository.createTopic(anyInt(), any())).thenReturn(randomUUID.toString());
    postEventType(eventType).andExpect(status().isCreated());
}
Also used : TestUtils.buildDefaultEventType(org.zalando.nakadi.utils.TestUtils.buildDefaultEventType) EventType(org.zalando.nakadi.domain.EventType) ResourceAuthorization(org.zalando.nakadi.domain.ResourceAuthorization) ResourceAuthorizationAttribute(org.zalando.nakadi.domain.ResourceAuthorizationAttribute) Test(org.junit.Test)

Example 32 with EventType

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

the class EventTypeControllerTest method whenPUTwithPartitionStrategyChangeFromRandomToHashThenOK.

@Test
public void whenPUTwithPartitionStrategyChangeFromRandomToHashThenOK() throws Exception {
    final EventType eventType = EventTypeTestBuilder.builder().partitionStrategy(PartitionStrategy.RANDOM_STRATEGY).build();
    final EventType randomEventType = EventTypeTestBuilder.builder().name(eventType.getName()).partitionStrategy(PartitionStrategy.HASH_STRATEGY).partitionKeyFields(Collections.singletonList("foo")).createdAt(eventType.getCreatedAt()).build();
    doReturn(eventType).when(eventTypeRepository).findByName(any());
    putEventType(randomEventType, eventType.getName()).andExpect(status().isOk());
}
Also used : TestUtils.buildDefaultEventType(org.zalando.nakadi.utils.TestUtils.buildDefaultEventType) EventType(org.zalando.nakadi.domain.EventType) Test(org.junit.Test)

Example 33 with EventType

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

the class EventTypeControllerTest method whenCreateEventTypeWithUnknownApplicationThen422.

@Test
public void whenCreateEventTypeWithUnknownApplicationThen422() throws Exception {
    doReturn(false).when(applicationService).exists(any());
    final EventType eventType = EventTypeTestBuilder.builder().partitionKeyFields(Collections.singletonList("blabla")).build();
    doReturn(eventType).when(eventTypeRepository).findByName(eventType.getName());
    postEventType(eventType).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)

Example 34 with EventType

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

the class EventTypeControllerTest method whenPUTDifferentEventTypeNameThen422.

@Test
public void whenPUTDifferentEventTypeNameThen422() throws Exception {
    final EventType eventType = buildDefaultEventType();
    final String eventTypeName = eventType.getName();
    eventType.setName("event-name-different");
    final Problem expectedProblem = new InvalidEventTypeException("path does not match resource name").asProblem();
    doReturn(eventType).when(eventTypeRepository).findByName(eventTypeName);
    putEventType(eventType, eventTypeName).andExpect(status().isUnprocessableEntity()).andExpect(content().contentType("application/problem+json")).andExpect(content().string(matchesProblem(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) Matchers.containsString(org.hamcrest.Matchers.containsString) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 35 with EventType

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

the class EventTypeControllerTest method whenPostEventTypeWithIncorrectNameThen422.

@Test
public void whenPostEventTypeWithIncorrectNameThen422() throws Exception {
    final List<String> incorrectNames = ImmutableList.of("?", "56mycoolET", "abc^%!", "myET.-abc", "abc._def", "_underscore", "-event", "many..dots", ".firstDot");
    for (final String etName : incorrectNames) {
        final EventType invalidEventType = buildDefaultEventType();
        invalidEventType.setName(etName);
        final Problem expectedProblem = invalidProblem("name", "format not allowed");
        postETAndExpect422WithProblem(invalidEventType, 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) Matchers.containsString(org.hamcrest.Matchers.containsString) Matchers.anyString(org.mockito.Matchers.anyString) 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