Search in sources :

Example 26 with EventType

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

the class EventTypeControllerTest method whenPostWithNullAuthorizationListThen422.

@Test
public void whenPostWithNullAuthorizationListThen422() throws Exception {
    final EventType eventType = buildDefaultEventType();
    eventType.setAuthorization(new ResourceAuthorization(null, null, null));
    postEventType(eventType).andExpect(status().isUnprocessableEntity()).andExpect(content().contentType("application/problem+json")).andExpect(content().string(containsString("Field \\\"authorization.admins\\\" may not be null"))).andExpect(content().string(containsString("Field \\\"authorization.readers\\\" may not be null"))).andExpect(content().string(containsString("Field \\\"authorization.writers\\\" may not be null")));
}
Also used : TestUtils.buildDefaultEventType(org.zalando.nakadi.utils.TestUtils.buildDefaultEventType) EventType(org.zalando.nakadi.domain.EventType) ResourceAuthorization(org.zalando.nakadi.domain.ResourceAuthorization) Test(org.junit.Test)

Example 27 with EventType

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

the class EventTypeControllerTest method whenPostNullOptions201.

@Test
public void whenPostNullOptions201() throws Exception {
    final EventType eventType = buildDefaultEventType();
    eventType.setOptions(null);
    postEventType(eventType).andExpect(status().isCreated());
    final ArgumentCaptor<EventTypeBase> argument = ArgumentCaptor.forClass(EventTypeBase.class);
    verify(eventTypeRepository).saveEventType(argument.capture());
    assertEquals(TOPIC_RETENTION_TIME_MS, argument.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 28 with EventType

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

the class EventTypeControllerTest method whenPostWithNoCategoryThenReturn422.

@Test
public void whenPostWithNoCategoryThenReturn422() throws Exception {
    final EventType invalidEventType = buildDefaultEventType();
    final JSONObject jsonObject = new JSONObject(TestUtils.OBJECT_MAPPER.writeValueAsString(invalidEventType));
    jsonObject.remove("category");
    final Problem expectedProblem = invalidProblem("category", "may not be null");
    postETAndExpect422WithProblem(jsonObject.toString(), expectedProblem);
}
Also used : JSONObject(org.json.JSONObject) 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 29 with EventType

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

the class EventTypeControllerTest method whenPostWithNullAuthAttributesFieldsThen422.

@Test
public void whenPostWithNullAuthAttributesFieldsThen422() throws Exception {
    final EventType eventType = buildDefaultEventType();
    eventType.setAuthorization(new ResourceAuthorization(ImmutableList.of(new ResourceAuthorizationAttribute("type1", "value1")), ImmutableList.of(new ResourceAuthorizationAttribute(null, "value2")), ImmutableList.of(new ResourceAuthorizationAttribute("type3", null))));
    postEventType(eventType).andExpect(status().isUnprocessableEntity()).andExpect(content().contentType("application/problem+json")).andExpect(content().string(containsString("Field \\\"authorization.readers[0].data_type\\\" may not be null"))).andExpect(content().string(containsString("Field \\\"authorization.writers[0].value\\\" may not be null")));
}
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 30 with EventType

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

the class EventTypeControllerTest method whenPUTwithPartitionStrategyChangeFromRandomToHashAndEmptyKeyThen422.

@Test
public void whenPUTwithPartitionStrategyChangeFromRandomToHashAndEmptyKeyThen422() 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.emptyList()).createdAt(eventType.getCreatedAt()).build();
    doReturn(eventType).when(eventTypeRepository).findByName(any());
    putEventType(randomEventType, eventType.getName()).andExpect(status().isUnprocessableEntity());
}
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