Search in sources :

Example 11 with Problem

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

the class EventTypeControllerTest method whenPostWithNoCategoryThenReturn422.

@Test
public void whenPostWithNoCategoryThenReturn422() throws Exception {
    final EventType invalidEventType = buildDefaultEventType();
    final JSONObject jsonObject = new JSONObject(TestUtils.OBJECT_MAPPER.writeValueAsString(invalidEventType));
    jsonObject.remove("category");
    final Problem expectedProblem = invalidProblem("category", "may not be null");
    postETAndExpect422WithProblem(jsonObject.toString(), expectedProblem);
}
Also used : JSONObject(org.json.JSONObject) 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 12 with Problem

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

the class EventTypeControllerTest method whenDeleteEventTypeAndNakadiExceptionThen500.

@Test
public void whenDeleteEventTypeAndNakadiExceptionThen500() throws Exception {
    final String eventTypeName = randomValidEventTypeName();
    final Problem expectedProblem = Problem.valueOf(Response.Status.INTERNAL_SERVER_ERROR, "Failed to delete event type " + eventTypeName);
    doThrow(new InternalNakadiException("dummy message")).when(eventTypeRepository).removeEventType(eventTypeName);
    doReturn(Optional.of(EventTypeTestBuilder.builder().name(eventTypeName).build())).when(eventTypeRepository).findByNameO(eventTypeName);
    deleteEventType(eventTypeName).andExpect(status().isInternalServerError()).andExpect(content().contentType("application/problem+json")).andExpect(content().string(matchesProblem(expectedProblem)));
}
Also used : InternalNakadiException(org.zalando.nakadi.exceptions.InternalNakadiException) 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)

Example 13 with Problem

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

the class EventTypeControllerTest method whenPUTDifferentEventTypeNameThen422.

@Test
public void whenPUTDifferentEventTypeNameThen422() throws Exception {
    final EventType eventType = buildDefaultEventType();
    final String eventTypeName = eventType.getName();
    eventType.setName("event-name-different");
    final Problem expectedProblem = new InvalidEventTypeException("path does not match resource name").asProblem();
    doReturn(eventType).when(eventTypeRepository).findByName(eventTypeName);
    putEventType(eventType, eventTypeName).andExpect(status().isUnprocessableEntity()).andExpect(content().contentType("application/problem+json")).andExpect(content().string(matchesProblem(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) Matchers.containsString(org.hamcrest.Matchers.containsString) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 14 with Problem

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

the class EventTypeControllerTest method whenPostEventTypeWithIncorrectNameThen422.

@Test
public void whenPostEventTypeWithIncorrectNameThen422() throws Exception {
    final List<String> incorrectNames = ImmutableList.of("?", "56mycoolET", "abc^%!", "myET.-abc", "abc._def", "_underscore", "-event", "many..dots", ".firstDot");
    for (final String etName : incorrectNames) {
        final EventType invalidEventType = buildDefaultEventType();
        invalidEventType.setName(etName);
        final Problem expectedProblem = invalidProblem("name", "format not allowed");
        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) Matchers.containsString(org.hamcrest.Matchers.containsString) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 15 with Problem

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

the class EventTypeControllerTest method whenPUTInvalidEventTypeThen422.

@Test
public void whenPUTInvalidEventTypeThen422() throws Exception {
    final EventType invalidEventType = buildDefaultEventType();
    final JSONObject jsonObject = new JSONObject(TestUtils.OBJECT_MAPPER.writeValueAsString(invalidEventType));
    jsonObject.remove("category");
    final Problem expectedProblem = invalidProblem("category", "may not be null");
    putEventType(jsonObject.toString(), invalidEventType.getName()).andExpect(status().isUnprocessableEntity()).andExpect(content().contentType("application/problem+json")).andExpect(content().string(matchesProblem(expectedProblem)));
}
Also used : JSONObject(org.json.JSONObject) 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