Search in sources :

Example 61 with Problem

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

the class EventTypeControllerTest method whenPostEventTypeWithTooLongNameThen422.

@Test
public void whenPostEventTypeWithTooLongNameThen422() throws Exception {
    final EventType invalidEventType = buildDefaultEventType();
    invalidEventType.setName(TestUtils.randomValidStringOfLength(256));
    final Problem expectedProblem = invalidProblem("name", "the length of the name must be >= 1 and <= 255");
    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 62 with Problem

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

the class ExceptionHandlingTest method testIllegalClientIdException.

@Test
public void testIllegalClientIdException() {
    final ExceptionHandling exceptionHandling = new ExceptionHandling();
    final NativeWebRequest mockedRequest = Mockito.mock(NativeWebRequest.class);
    Mockito.when(mockedRequest.getHeader(Matchers.any())).thenReturn("");
    final ResponseEntity<Problem> problemResponseEntity = exceptionHandling.handleIllegalClientIdException(new IllegalClientIdException("You don't have access to this event type"), mockedRequest);
    Assert.assertEquals(problemResponseEntity.getStatusCode(), HttpStatus.FORBIDDEN);
    Assert.assertEquals(problemResponseEntity.getBody().getDetail().get(), "You don't have access to this event type");
}
Also used : Problem(org.zalando.problem.Problem) NativeWebRequest(org.springframework.web.context.request.NativeWebRequest) IllegalClientIdException(org.zalando.nakadi.exceptions.IllegalClientIdException) Test(org.junit.Test)

Example 63 with Problem

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

the class PostSubscriptionControllerTest method whenEventTypeDoesNotExistThenUnprocessableEntity.

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

Example 64 with Problem

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

the class PostSubscriptionControllerTest method whenCreateSubscriptionWithEmptyConsumerGroupThenUnprocessableEntity.

@Test
public void whenCreateSubscriptionWithEmptyConsumerGroupThenUnprocessableEntity() throws Exception {
    final SubscriptionBase subscriptionBase = builder().withConsumerGroup("").buildSubscriptionBase();
    final Problem expectedProblem = invalidProblem("consumer_group", "must contain at least one character");
    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)

Example 65 with Problem

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

the class PostSubscriptionControllerTest method whenOwningApplicationIsNullThenUnprocessableEntity.

@Test
public void whenOwningApplicationIsNullThenUnprocessableEntity() throws Exception {
    final SubscriptionBase subscriptionBase = builder().withOwningApplication(null).buildSubscriptionBase();
    final Problem expectedProblem = invalidProblem("owning_application", "may not be null");
    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