Search in sources :

Example 51 with Problem

use of org.zalando.problem.Problem in project nakadi by zalando.

the class EventStreamControllerTest method whenInvalidCursorsThenPreconditionFailed.

@Test
public void whenInvalidCursorsThenPreconditionFailed() throws Exception {
    final NakadiCursor cursor = NakadiCursor.of(timeline, "0", "000000000000000000");
    when(eventTypeRepository.findByName(TEST_EVENT_TYPE_NAME)).thenReturn(EVENT_TYPE);
    when(timelineService.createEventConsumer(eq(KAFKA_CLIENT_ID), any())).thenThrow(new InvalidCursorException(CursorError.UNAVAILABLE, cursor));
    final StreamingResponseBody responseBody = createStreamingResponseBody(1, 0, 0, 0, 0, "[{\"partition\":\"0\",\"offset\":\"00000000000000000\"}]");
    final Problem expectedProblem = Problem.valueOf(PRECONDITION_FAILED, "offset 000000000000000000 for partition 0 is unavailable");
    assertThat(responseToString(responseBody), TestUtils.JSON_TEST_HELPER.matchesObject(expectedProblem));
}
Also used : NakadiCursor(org.zalando.nakadi.domain.NakadiCursor) StreamingResponseBody(org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody) InvalidCursorException(org.zalando.nakadi.exceptions.InvalidCursorException) Problem(org.zalando.problem.Problem) Test(org.junit.Test)

Example 52 with Problem

use of org.zalando.problem.Problem in project nakadi by zalando.

the class EventStreamControllerTest method whenBatchLimitLowerThan1ThenUnprocessableEntity.

@Test
public void whenBatchLimitLowerThan1ThenUnprocessableEntity() throws NakadiException, IOException {
    when(eventTypeRepository.findByName(TEST_EVENT_TYPE_NAME)).thenReturn(EVENT_TYPE);
    final StreamingResponseBody responseBody = createStreamingResponseBody(0, 0, 0, 0, 0, null);
    final Problem expectedProblem = Problem.valueOf(UNPROCESSABLE_ENTITY, "batch_limit can't be lower than 1");
    assertThat(responseToString(responseBody), TestUtils.JSON_TEST_HELPER.matchesObject(expectedProblem));
}
Also used : StreamingResponseBody(org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody) Problem(org.zalando.problem.Problem) Test(org.junit.Test)

Example 53 with Problem

use of org.zalando.problem.Problem in project nakadi by zalando.

the class EventStreamControllerTest method whenExceptionIsThrownThenInternalServerError.

@Test
public void whenExceptionIsThrownThenInternalServerError() throws NakadiException, IOException {
    when(eventTypeRepository.findByName(TEST_EVENT_TYPE_NAME)).thenThrow(NullPointerException.class);
    final StreamingResponseBody responseBody = createStreamingResponseBody();
    final Problem expectedProblem = Problem.valueOf(INTERNAL_SERVER_ERROR);
    assertThat(responseToString(responseBody), TestUtils.JSON_TEST_HELPER.matchesObject(expectedProblem));
}
Also used : StreamingResponseBody(org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody) Problem(org.zalando.problem.Problem) Test(org.junit.Test)

Example 54 with Problem

use of org.zalando.problem.Problem in project nakadi by zalando.

the class EventTypeControllerTest method whenPostWithEventTypeNameNotSetThenReturn422.

@Test
public void whenPostWithEventTypeNameNotSetThenReturn422() throws Exception {
    final EventType invalidEventType = buildDefaultEventType();
    invalidEventType.setName(null);
    final Problem expectedProblem = invalidProblem("name", "may not be null");
    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) Test(org.junit.Test)

Example 55 with Problem

use of org.zalando.problem.Problem in project nakadi by zalando.

the class EventTypeControllerTest method whenPostWithNoSchemaSchemaThenReturn422.

@Test
public void whenPostWithNoSchemaSchemaThenReturn422() throws Exception {
    final Problem expectedProblem = invalidProblem("schema.schema", "may not be null");
    final String eventType = "{\"category\": \"data\", \"owning_application\": \"blah-app\", " + "\"name\": \"blah-event-type\", \"schema\": { \"type\": \"JSON_SCHEMA\" }}";
    postETAndExpect422WithProblem(eventType, expectedProblem);
}
Also used : 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

Problem (org.zalando.problem.Problem)75 Test (org.junit.Test)47 TestUtils.invalidProblem (org.zalando.nakadi.utils.TestUtils.invalidProblem)32 ResponseEntity (org.springframework.http.ResponseEntity)26 DefaultProblem (org.zalando.problem.DefaultProblem)26 ProblemBuilder (org.zalando.problem.ProblemBuilder)26 ConstraintViolationProblem (org.zalando.problem.spring.web.advice.validation.ConstraintViolationProblem)26 ThrowableProblem (org.zalando.problem.ThrowableProblem)25 EventType (org.zalando.nakadi.domain.EventType)18 TestUtils.buildDefaultEventType (org.zalando.nakadi.utils.TestUtils.buildDefaultEventType)18 NativeWebRequest (org.springframework.web.context.request.NativeWebRequest)14 List (java.util.List)13 Collectors (java.util.stream.Collectors)13 Nonnull (javax.annotation.Nonnull)13 Nullable (javax.annotation.Nullable)13 HttpServletRequest (javax.servlet.http.HttpServletRequest)13 BindingResult (org.springframework.validation.BindingResult)13 MethodArgumentNotValidException (org.springframework.web.bind.MethodArgumentNotValidException)13 ControllerAdvice (org.springframework.web.bind.annotation.ControllerAdvice)13 ExceptionHandler (org.springframework.web.bind.annotation.ExceptionHandler)13