Search in sources :

Example 46 with Problem

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

the class CursorsControllerTest method whenNoEventTypeThenUnprocessableEntity.

@Test
public void whenNoEventTypeThenUnprocessableEntity() throws Exception {
    when(cursorsService.commitCursors(any(), any(), any())).thenThrow(new NoSuchEventTypeException("dummy-message"));
    final Problem expectedProblem = Problem.valueOf(UNPROCESSABLE_ENTITY, "dummy-message");
    checkForProblem(postCursors(DUMMY_CURSORS), expectedProblem);
}
Also used : Problem(org.zalando.problem.Problem) TestUtils.invalidProblem(org.zalando.nakadi.utils.TestUtils.invalidProblem) NoSuchEventTypeException(org.zalando.nakadi.exceptions.NoSuchEventTypeException) Test(org.junit.Test)

Example 47 with Problem

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

the class CursorsControllerTest method whenServiceUnavailableExceptionThenServiceUnavailable.

@Test
public void whenServiceUnavailableExceptionThenServiceUnavailable() throws Exception {
    when(cursorsService.commitCursors(any(), any(), any())).thenThrow(new ServiceUnavailableException("dummy-message"));
    final Problem expectedProblem = Problem.valueOf(SERVICE_UNAVAILABLE, "dummy-message");
    checkForProblem(postCursors(DUMMY_CURSORS), expectedProblem);
}
Also used : Problem(org.zalando.problem.Problem) TestUtils.invalidProblem(org.zalando.nakadi.utils.TestUtils.invalidProblem) ServiceUnavailableException(org.zalando.nakadi.exceptions.ServiceUnavailableException) Test(org.junit.Test)

Example 48 with Problem

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

the class CursorsControllerTest method whenNoSubscriptionThenNotFound.

@Test
public void whenNoSubscriptionThenNotFound() throws Exception {
    when(cursorsService.commitCursors(any(), eq(SUBSCRIPTION_ID), any())).thenThrow(new NoSuchSubscriptionException("dummy-message"));
    final Problem expectedProblem = Problem.valueOf(NOT_FOUND, "dummy-message");
    checkForProblem(postCursors(DUMMY_CURSORS), expectedProblem);
}
Also used : NoSuchSubscriptionException(org.zalando.nakadi.exceptions.NoSuchSubscriptionException) Problem(org.zalando.problem.Problem) TestUtils.invalidProblem(org.zalando.nakadi.utils.TestUtils.invalidProblem) Test(org.junit.Test)

Example 49 with Problem

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

the class GzipBodyRequestFilter method reportNotAcceptableError.

private void reportNotAcceptableError(final HttpServletResponse response, final HttpServletRequest request) throws IOException {
    response.setStatus(NOT_ACCEPTABLE.getStatusCode());
    final PrintWriter writer = response.getWriter();
    final Problem problem = Problem.valueOf(NOT_ACCEPTABLE, request.getMethod() + " method doesn't support gzip content encoding");
    writer.write(objectMapper.writeValueAsString(problem));
    writer.close();
}
Also used : Problem(org.zalando.problem.Problem) PrintWriter(java.io.PrintWriter)

Example 50 with Problem

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

the class EventStreamControllerTest method whenStreamLimitLowerThanBatchLimitThenUnprocessableEntity.

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