Search in sources :

Example 1 with ThrowableProblem

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

the class EventTypeControllerTest method askingForANonExistingEventTypeResultsIn404.

@Test
public void askingForANonExistingEventTypeResultsIn404() throws Exception {
    final String eventTypeName = randomValidEventTypeName();
    when(eventTypeRepository.findByName(anyString())).thenThrow(new NoSuchEventTypeException(String.format("EventType '%s' does not exist.", eventTypeName)));
    final MockHttpServletRequestBuilder requestBuilder = get("/event-types/" + eventTypeName).accept(APPLICATION_JSON);
    final ThrowableProblem expectedProblem = Problem.valueOf(NOT_FOUND, "EventType '" + eventTypeName + "' does not exist.");
    mockMvc.perform(requestBuilder).andExpect(status().is(404)).andExpect(content().contentTypeCompatibleWith("application/problem+json")).andExpect(content().string(matchesProblem(expectedProblem)));
}
Also used : MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) ThrowableProblem(org.zalando.problem.ThrowableProblem) Matchers.containsString(org.hamcrest.Matchers.containsString) Matchers.anyString(org.mockito.Matchers.anyString) NoSuchEventTypeException(org.zalando.nakadi.exceptions.NoSuchEventTypeException) Test(org.junit.Test)

Example 2 with ThrowableProblem

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

the class SubscriptionControllerTest method whenGetNoneExistingSubscriptionThenNotFound.

@Test
public void whenGetNoneExistingSubscriptionThenNotFound() throws Exception {
    final Subscription subscription = builder().build();
    when(subscriptionRepository.getSubscription(subscription.getId())).thenThrow(new NoSuchSubscriptionException("dummy-message"));
    final ThrowableProblem expectedProblem = Problem.valueOf(Response.Status.NOT_FOUND, "dummy-message");
    getSubscription(subscription.getId()).andExpect(status().isNotFound()).andExpect(content().string(TestUtils.JSON_TEST_HELPER.matchesObject(expectedProblem)));
}
Also used : NoSuchSubscriptionException(org.zalando.nakadi.exceptions.NoSuchSubscriptionException) ThrowableProblem(org.zalando.problem.ThrowableProblem) Subscription(org.zalando.nakadi.domain.Subscription) Test(org.junit.Test)

Example 3 with ThrowableProblem

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

the class PartitionsControllerTest method whenListPartitionsForWrongTopicThenNotFound.

@Test
public void whenListPartitionsForWrongTopicThenNotFound() throws Exception {
    final ThrowableProblem expectedProblem = Problem.valueOf(NOT_FOUND, "topic not found");
    mockMvc.perform(get(String.format("/event-types/%s/partitions", UNKNOWN_EVENT_TYPE))).andExpect(status().isNotFound()).andExpect(content().string(TestUtils.JSON_TEST_HELPER.matchesObject(expectedProblem)));
}
Also used : ThrowableProblem(org.zalando.problem.ThrowableProblem) Test(org.junit.Test)

Example 4 with ThrowableProblem

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

the class PartitionsControllerTest method whenListPartitionsAndNakadiExceptionThenServiceUnavaiable.

@Test
public void whenListPartitionsAndNakadiExceptionThenServiceUnavaiable() throws Exception {
    when(timelineService.getActiveTimelinesOrdered(eq(TEST_EVENT_TYPE))).thenThrow(ServiceUnavailableException.class);
    final ThrowableProblem expectedProblem = Problem.valueOf(SERVICE_UNAVAILABLE, null);
    mockMvc.perform(get(String.format("/event-types/%s/partitions", TEST_EVENT_TYPE))).andExpect(status().isServiceUnavailable()).andExpect(content().string(TestUtils.JSON_TEST_HELPER.matchesObject(expectedProblem)));
}
Also used : ThrowableProblem(org.zalando.problem.ThrowableProblem) Test(org.junit.Test)

Example 5 with ThrowableProblem

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

the class PartitionsControllerTest method whenGetPartitionAndNakadiExceptionThenServiceUnavaiable.

@Test
public void whenGetPartitionAndNakadiExceptionThenServiceUnavaiable() throws Exception {
    when(timelineService.getActiveTimelinesOrdered(eq(TEST_EVENT_TYPE))).thenThrow(ServiceUnavailableException.class);
    final ThrowableProblem expectedProblem = Problem.valueOf(SERVICE_UNAVAILABLE, null);
    mockMvc.perform(get(String.format("/event-types/%s/partitions/%s", TEST_EVENT_TYPE, TEST_PARTITION))).andExpect(status().isServiceUnavailable()).andExpect(content().string(TestUtils.JSON_TEST_HELPER.matchesObject(expectedProblem)));
}
Also used : ThrowableProblem(org.zalando.problem.ThrowableProblem) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)7 ThrowableProblem (org.zalando.problem.ThrowableProblem)7 Matchers.containsString (org.hamcrest.Matchers.containsString)1 Matchers.anyString (org.mockito.Matchers.anyString)1 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)1 Subscription (org.zalando.nakadi.domain.Subscription)1 NoSuchEventTypeException (org.zalando.nakadi.exceptions.NoSuchEventTypeException)1 NoSuchSubscriptionException (org.zalando.nakadi.exceptions.NoSuchSubscriptionException)1