Search in sources :

Example 16 with Problem

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

the class EventTypeControllerTest method whenDeleteEventTypeThatHasSubscriptionsThenConflict.

@Test
public void whenDeleteEventTypeThatHasSubscriptionsThenConflict() throws Exception {
    final EventType eventType = buildDefaultEventType();
    when(eventTypeRepository.findByNameO(eventType.getName())).thenReturn(Optional.of(eventType));
    when(subscriptionRepository.listSubscriptions(eq(ImmutableSet.of(eventType.getName())), eq(Optional.empty()), anyInt(), anyInt())).thenReturn(ImmutableList.of(mock(Subscription.class)));
    final Problem expectedProblem = Problem.valueOf(Response.Status.CONFLICT, "Can't remove event type " + eventType.getName() + ", as it has subscriptions");
    deleteEventType(eventType.getName()).andExpect(status().isConflict()).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 17 with Problem

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

the class EventTypeControllerTest method whenEventTypeSchemaJsonIsMalformedThen422.

@Test
public void whenEventTypeSchemaJsonIsMalformedThen422() throws Exception {
    final EventType eventType = buildDefaultEventType();
    eventType.getSchema().setSchema("invalid-json");
    final Problem expectedProblem = new InvalidEventTypeException("schema must be a valid json: Unexpected token 'invalid' on line 1, char 1").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 18 with Problem

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

the class EventTypeControllerTest method invalidEventTypeSchemaJsonSchemaThen422.

@Test
public void invalidEventTypeSchemaJsonSchemaThen422() throws Exception {
    final EventType eventType = buildDefaultEventType();
    final String jsonSchemaString = Resources.toString(Resources.getResource("sample-invalid-json-schema.json"), Charsets.UTF_8);
    eventType.getSchema().setSchema(jsonSchemaString);
    final Problem expectedProblem = new InvalidEventTypeException("schema must be a valid json-schema").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) Matchers.containsString(org.hamcrest.Matchers.containsString) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 19 with Problem

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

the class PostSubscriptionControllerTest method whenMoreThanAllowedEventTypeThenUnprocessableEntity.

@Test
public void whenMoreThanAllowedEventTypeThenUnprocessableEntity() throws Exception {
    when(subscriptionService.getExistingSubscription(any())).thenThrow(new NoSubscriptionException("", null));
    when(subscriptionService.createSubscription(any())).thenThrow(new TooManyPartitionsException("msg"));
    final SubscriptionBase subscriptionBase = builder().buildSubscriptionBase();
    final Problem expectedProblem = Problem.valueOf(UNPROCESSABLE_ENTITY, "msg");
    checkForProblem(postSubscription(subscriptionBase), expectedProblem);
}
Also used : SubscriptionBase(org.zalando.nakadi.domain.SubscriptionBase) TooManyPartitionsException(org.zalando.nakadi.exceptions.runtime.TooManyPartitionsException) NoSubscriptionException(org.zalando.nakadi.exceptions.runtime.NoSubscriptionException) Problem(org.zalando.problem.Problem) TestUtils.invalidProblem(org.zalando.nakadi.utils.TestUtils.invalidProblem) Test(org.junit.Test)

Example 20 with Problem

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

the class PostSubscriptionControllerTest method whenEventTypesIsEmptyThenUnprocessableEntity.

@Test
public void whenEventTypesIsEmptyThenUnprocessableEntity() throws Exception {
    final SubscriptionBase subscriptionBase = builder().withEventTypes(ImmutableSet.of()).buildSubscriptionBase();
    final Problem expectedProblem = invalidProblem("event_types", "must contain at least one element");
    checkForProblem(postSubscription(subscriptionBase), expectedProblem);
}
Also used : SubscriptionBase(org.zalando.nakadi.domain.SubscriptionBase) Problem(org.zalando.problem.Problem) 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