Search in sources :

Example 56 with Problem

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

the class EventTypeControllerTest method whenDeleteEventTypeAndTimelineWaitTimeoutThen503.

@Test
public void whenDeleteEventTypeAndTimelineWaitTimeoutThen503() throws Exception {
    when(timelineSync.workWithEventType(any(), anyLong())).thenThrow(new TimeoutException());
    final EventType eventType = buildDefaultEventType();
    final Problem expectedProblem = Problem.valueOf(SERVICE_UNAVAILABLE, "Event type " + eventType.getName() + " is currently in maintenance, please repeat request");
    deleteEventType(eventType.getName()).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 57 with Problem

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

the class EventTypeControllerTest method whenTimelineCreationFailsRemoveEventTypeFromRepositoryAnd500.

@Test
public void whenTimelineCreationFailsRemoveEventTypeFromRepositoryAnd500() throws Exception {
    final EventType et = buildDefaultEventType();
    doThrow(TopicCreationException.class).when(timelineService).createDefaultTimeline(anyString(), anyInt(), anyLong());
    final Problem expectedProblem = Problem.valueOf(SERVICE_UNAVAILABLE);
    postEventType(et).andExpect(status().isServiceUnavailable()).andExpect(content().contentType("application/problem+json")).andExpect(content().string(matchesProblem(expectedProblem)));
    verify(eventTypeRepository, times(1)).saveEventType(any(EventType.class));
    verify(timelineService, times(1)).createDefaultTimeline(anyString(), anyInt(), anyLong());
    verify(eventTypeRepository, times(1)).removeEventType(et.getName());
}
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 58 with Problem

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

the class EventTypeControllerTest method whenPUTNotExistingEventTypeThen404.

@Test
public void whenPUTNotExistingEventTypeThen404() throws Exception {
    final EventType eventType = buildDefaultEventType();
    final Problem expectedProblem = Problem.valueOf(NOT_FOUND);
    doThrow(NoSuchEventTypeException.class).when(eventTypeRepository).findByName(eventType.getName());
    putEventType(eventType, eventType.getName()).andExpect(status().isNotFound()).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 59 with Problem

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

the class EventTypeControllerTest method whenPostDuplicatedEventTypeReturn409.

@Test
public void whenPostDuplicatedEventTypeReturn409() throws Exception {
    final Problem expectedProblem = Problem.valueOf(Response.Status.CONFLICT, "some-name");
    doThrow(new DuplicatedEventTypeNameException("some-name")).when(eventTypeRepository).saveEventType(any(EventTypeBase.class));
    postEventType(buildDefaultEventType()).andExpect(status().isConflict()).andExpect(content().contentType("application/problem+json")).andExpect(content().string(matchesProblem(expectedProblem)));
}
Also used : DuplicatedEventTypeNameException(org.zalando.nakadi.exceptions.DuplicatedEventTypeNameException) EventTypeBase(org.zalando.nakadi.domain.EventTypeBase) Problem(org.zalando.problem.Problem) ThrowableProblem(org.zalando.problem.ThrowableProblem) TestUtils.invalidProblem(org.zalando.nakadi.utils.TestUtils.invalidProblem) Test(org.junit.Test)

Example 60 with Problem

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

the class EventTypeControllerTest method whenPUTRepoNakadiExceptionThen422.

@Test
public void whenPUTRepoNakadiExceptionThen422() throws Exception {
    final EventType eventType = buildDefaultEventType();
    final Problem expectedProblem = Problem.valueOf(MoreStatus.UNPROCESSABLE_ENTITY);
    doThrow(UnprocessableEntityException.class).when(eventTypeRepository).findByName(eventType.getName());
    putEventType(eventType, eventType.getName()).andExpect(status().isUnprocessableEntity()).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)

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