Search in sources :

Example 6 with Problem

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

the class EventTypeControllerTest method whenPersistencyErrorThen500.

@Test
public void whenPersistencyErrorThen500() throws Exception {
    final Problem expectedProblem = Problem.valueOf(Response.Status.INTERNAL_SERVER_ERROR);
    doThrow(InternalNakadiException.class).when(eventTypeRepository).saveEventType(any(EventType.class));
    postEventType(buildDefaultEventType()).andExpect(status().isInternalServerError()).andExpect(content().contentType("application/problem+json")).andExpect(content().string(matchesProblem(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 7 with Problem

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

the class EventTypeControllerTest method eventTypeWithoutSchemaReturns422.

@Test
public void eventTypeWithoutSchemaReturns422() throws Exception {
    final EventType invalidEventType = buildDefaultEventType();
    invalidEventType.setSchema(null);
    final Problem expectedProblem = invalidProblem("schema", "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 8 with Problem

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

the class EventTypeControllerTest method whenPOSTBusinessEventTypeMetadataThen422.

@Test
public void whenPOSTBusinessEventTypeMetadataThen422() throws Exception {
    final EventType eventType = buildDefaultEventType();
    eventType.getSchema().setSchema("{\"type\": \"object\", \"properties\": {\"metadata\": {\"type\": \"object\"} }}");
    eventType.setCategory(BUSINESS);
    final Problem expectedProblem = new InvalidEventTypeException("\"metadata\" property is reserved").asProblem();
    postETAndExpect422WithProblem(eventType, 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) Test(org.junit.Test)

Example 9 with Problem

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

the class EventTypeControllerTest method whenUpdateEventTypeAndTimelineWaitTimeoutThen503.

@Test
public void whenUpdateEventTypeAndTimelineWaitTimeoutThen503() throws Exception {
    when(timelineSync.workWithEventType(any(), anyLong())).thenThrow(new TimeoutException());
    final EventType eventType = buildDefaultEventType();
    final Problem expectedProblem = Problem.valueOf(SERVICE_UNAVAILABLE, "Event type is currently in maintenance, please repeat request");
    putEventType(eventType, eventType.getName(), "nakadi").andExpect(status().isServiceUnavailable()).andExpect(content().string(matchesProblem(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) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.Test)

Example 10 with Problem

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

the class EventTypeControllerTest method whenPOSTInvalidSchemaThen422.

@Test
public void whenPOSTInvalidSchemaThen422() throws Exception {
    final EventType eventType = buildDefaultEventType();
    eventType.getSchema().setSchema("{\"not\": {\"type\": \"object\"} }");
    eventType.setCategory(BUSINESS);
    final Problem expectedProblem = new InvalidEventTypeException("Invalid schema: Invalid schema found in [#]: " + "extraneous key [not] is not permitted").asProblem();
    postETAndExpect422WithProblem(eventType, 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) 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