Search in sources :

Example 1 with Problem

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

the class EventStreamControllerTest method whenNakadiExceptionIsThrownThenServiceUnavailable.

@Test
public void whenNakadiExceptionIsThrownThenServiceUnavailable() throws NakadiException, IOException {
    when(eventTypeRepository.findByName(TEST_EVENT_TYPE_NAME)).thenThrow(ServiceUnavailableException.class);
    final StreamingResponseBody responseBody = createStreamingResponseBody();
    final Problem expectedProblem = Problem.valueOf(SERVICE_UNAVAILABLE);
    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 2 with Problem

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

the class EventStreamControllerTest method whenWrongCursorsFormatThenBadRequest.

@Test
public void whenWrongCursorsFormatThenBadRequest() throws NakadiException, IOException {
    when(eventTypeRepository.findByName(TEST_EVENT_TYPE_NAME)).thenReturn(EVENT_TYPE);
    final StreamingResponseBody responseBody = createStreamingResponseBody(0, 0, 0, 0, 0, "cursors_with_wrong_format");
    final Problem expectedProblem = Problem.valueOf(BAD_REQUEST, "incorrect syntax of X-nakadi-cursors header");
    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 3 with Problem

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

the class EventStreamControllerTest method testAccessDenied.

@Test
public void testAccessDenied() throws Exception {
    Mockito.doThrow(AccessDeniedException.class).when(authorizationValidator).authorizeStreamRead(any());
    when(eventTypeRepository.findByName(TEST_EVENT_TYPE_NAME)).thenReturn(EVENT_TYPE);
    Mockito.doThrow(mockAccessDeniedException()).when(authorizationValidator).authorizeStreamRead(any());
    final StreamingResponseBody responseBody = createStreamingResponseBody(0, 0, 0, 0, 0, null);
    final Problem expectedProblem = Problem.valueOf(FORBIDDEN, "Access on READ some-type:some-name denied");
    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 4 with Problem

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

the class EventStreamControllerTest method whenTopicNotExistsThenTopicNotFound.

@Test
public void whenTopicNotExistsThenTopicNotFound() throws IOException, NakadiException {
    when(eventTypeRepository.findByName(TEST_EVENT_TYPE_NAME)).thenThrow(NoSuchEventTypeException.class);
    final StreamingResponseBody responseBody = createStreamingResponseBody();
    final Problem expectedProblem = Problem.valueOf(NOT_FOUND, "topic not found");
    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 5 with Problem

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

the class EventStreamControllerTest method whenStreamTimeoutLowerThanBatchTimeoutThenUnprocessableEntity.

@Test
public void whenStreamTimeoutLowerThanBatchTimeoutThenUnprocessableEntity() throws NakadiException, IOException {
    when(eventTypeRepository.findByName(TEST_EVENT_TYPE_NAME)).thenReturn(EVENT_TYPE);
    final StreamingResponseBody responseBody = createStreamingResponseBody(0, 0, 20, 10, 0, null);
    final Problem expectedProblem = Problem.valueOf(UNPROCESSABLE_ENTITY, "stream_timeout can't be lower than batch_flush_timeout");
    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)

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