Java Code Examples for org.zalando.problem.Problem#valueOf()
The following examples show how to use
org.zalando.problem.Problem#valueOf() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EventTypeControllerTest.java From nakadi with MIT License | 6 votes |
@Test public void whenTimelineCreationFailsRemoveEventTypeFromRepositoryAnd500() throws Exception { final EventType et = TestUtils.buildDefaultEventType(); doThrow(TopicCreationException.class).when(timelineService) .createDefaultTimeline(any(), anyInt()); when(eventTypeRepository.saveEventType(any())).thenReturn(et); 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(any(), anyInt()); verify(eventTypeRepository, times(1)).removeEventType(et.getName()); }
Example 2
Source File: EventTypeControllerTest.java From nakadi with MIT License | 6 votes |
@Test public void whenDeleteEventTypeThatHasSubscriptionsThenConflict() throws Exception { final EventType eventType = TestUtils.buildDefaultEventType(); when(eventTypeCache.getEventTypeIfExists(eventType.getName())).thenReturn(Optional.of(eventType)); when(featureToggleService.isFeatureEnabled(Feature.DELETE_EVENT_TYPE_WITH_SUBSCRIPTIONS)).thenReturn(false); final Subscription mockSubscription = mock(Subscription.class); when(mockSubscription.getConsumerGroup()).thenReturn("def"); when(mockSubscription.getOwningApplication()).thenReturn("asdf"); when(subscriptionRepository .listSubscriptions(eq(ImmutableSet.of(eventType.getName())), eq(Optional.empty()), anyInt(), anyInt())) .thenReturn(ImmutableList.of(mockSubscription)); final Problem expectedProblem = Problem.valueOf(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))); }
Example 3
Source File: EventStreamControllerTest.java From nakadi with MIT License | 5 votes |
@Test public void whenNakadiExceptionIsThrownThenServiceUnavailable() throws IOException { when(eventTypeCache.getEventType(TEST_EVENT_TYPE_NAME)) .thenThrow(ServiceTemporarilyUnavailableException.class); final StreamingResponseBody responseBody = createStreamingResponseBody(); final Problem expectedProblem = Problem.valueOf(SERVICE_UNAVAILABLE); MatcherAssert.assertThat(responseToString(responseBody), JSON_TEST_HELPER.matchesObject(expectedProblem)); }
Example 4
Source File: PartitionsControllerTest.java From nakadi with MIT License | 5 votes |
@Test public void whenGetPartitionAndNakadiExceptionThenServiceUnavaiable() throws Exception { Mockito.when(timelineService.getActiveTimelinesOrdered(eq(TEST_EVENT_TYPE))) .thenThrow(ServiceTemporarilyUnavailableException.class); final ThrowableProblem expectedProblem = Problem.valueOf(SERVICE_UNAVAILABLE, ""); 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))); }
Example 5
Source File: CursorsControllerTest.java From nakadi with MIT License | 5 votes |
@Test public void whenSubscriptionConsumptionBlockedThenAccessDeniedOnPostCommit() throws Exception { Mockito.when(eventStreamChecks.isSubscriptionConsumptionBlocked(anyString(), any())).thenReturn(true); final Problem expectedProblem = Problem.valueOf(FORBIDDEN, "Application or subscription is blocked"); checkForProblem( postCursorsString("{\"items\":[{\"offset\":\"0\",\"partition\":\"0\",\"cursor_token\":\"x\"," + "\"event_type\":\"et\"}]}"), expectedProblem); }
Example 6
Source File: EventTypeControllerTest.java From nakadi with MIT License | 5 votes |
@Test public void whenDeleteEventTypeAndTimelineWaitTimeoutThen503() throws Exception { when(timelineSync.workWithEventType(any(), anyLong())).thenThrow(new TimeoutException()); final EventType eventType = TestUtils.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))); }
Example 7
Source File: PartitionsControllerTest.java From nakadi with MIT License | 5 votes |
@Test public void whenGetPartitionForWrongPartitionThenNotFound() throws Exception { Mockito.when(eventTypeCacheMock.getEventType(TEST_EVENT_TYPE)).thenReturn(EVENT_TYPE); Mockito.when(topicRepositoryMock.topicExists(eq(EVENT_TYPE.getName()))).thenReturn(true); Mockito.when(topicRepositoryMock.loadPartitionStatistics( eq(TIMELINE), eq(UNKNOWN_PARTITION))) .thenReturn(Optional.empty()); final ThrowableProblem expectedProblem = Problem.valueOf(NOT_FOUND, "partition not found"); mockMvc.perform( get(String.format("/event-types/%s/partitions/%s", TEST_EVENT_TYPE, UNKNOWN_PARTITION))) .andExpect(status().isNotFound()) .andExpect(content().string(TestUtils.JSON_TEST_HELPER.matchesObject(expectedProblem))); }
Example 8
Source File: CompressedEventPublishingAT.java From nakadi with MIT License | 5 votes |
@Test public void whenGetWithGzipEncodingThenNotAcceptable() throws IOException { final Problem expectedProblem = Problem.valueOf(NOT_ACCEPTABLE, "GET method doesn't support gzip content encoding"); given() .header(CONTENT_ENCODING, "gzip") .get("/event-types") .then() .body(JSON_HELPER.matchesObject(expectedProblem)) .statusCode(HttpStatus.SC_NOT_ACCEPTABLE); }
Example 9
Source File: EventStreamControllerTest.java From nakadi with MIT License | 5 votes |
@Test public void whenExceptionIsThrownThenInternalServerError() throws IOException { when(eventTypeCache.getEventType(TEST_EVENT_TYPE_NAME)).thenThrow(NullPointerException.class); final StreamingResponseBody responseBody = createStreamingResponseBody(); final Problem expectedProblem = Problem.valueOf(INTERNAL_SERVER_ERROR); MatcherAssert.assertThat(responseToString(responseBody), JSON_TEST_HELPER.matchesObject(expectedProblem)); }
Example 10
Source File: PostSubscriptionControllerTest.java From nakadi with MIT License | 5 votes |
@Test public void whenEventTypeDoesNotExistThenUnprocessableEntity() throws Exception { final SubscriptionBase subscriptionBase = RandomSubscriptionBuilder.builder().buildSubscriptionBase(); when(subscriptionService.getExistingSubscription(any())).thenThrow(new NoSuchSubscriptionException("", null)); when(subscriptionService.createSubscription(any())).thenThrow(new NoSuchEventTypeException("msg")); final Problem expectedProblem = Problem.valueOf(UNPROCESSABLE_ENTITY, "msg"); checkForProblem(postSubscription(subscriptionBase), expectedProblem); }
Example 11
Source File: SubscriptionControllerTest.java From nakadi with MIT License | 5 votes |
@Test public void whenGetSubscriptionAndExceptionThenServiceUnavailable() throws Exception { when(subscriptionRepository.getSubscription(any())) .thenThrow(new ServiceTemporarilyUnavailableException("dummy message")); final Problem expectedProblem = Problem.valueOf(SERVICE_UNAVAILABLE, "dummy message"); checkForProblem(getSubscription("dummyId"), expectedProblem); }
Example 12
Source File: CursorsControllerTest.java From nakadi with MIT License | 5 votes |
@Test public void whenServiceUnavailableExceptionThenServiceUnavailable() throws Exception { when(cursorsService.commitCursors(any(), any(), any(), any())) .thenThrow(new ServiceTemporarilyUnavailableException("dummy-message")); final Problem expectedProblem = Problem.valueOf(SERVICE_UNAVAILABLE, "dummy-message"); checkForProblem(postCursors(DUMMY_CURSORS), expectedProblem); }
Example 13
Source File: EventStreamControllerTest.java From nakadi with MIT License | 5 votes |
@Test public void whenBatchLimitLowerThan1ThenUnprocessableEntity() throws IOException { when(eventTypeCache.getEventType(TEST_EVENT_TYPE_NAME)).thenReturn(EVENT_TYPE); final StreamingResponseBody responseBody = createStreamingResponseBody(0, 0, 0, 0, 0, null); final Problem expectedProblem = Problem.valueOf(UNPROCESSABLE_ENTITY, "batch_limit can't be lower than 1"); MatcherAssert.assertThat(responseToString(responseBody), JSON_TEST_HELPER.matchesObject(expectedProblem)); }
Example 14
Source File: EventStreamControllerTest.java From nakadi with MIT License | 5 votes |
@Test public void whenStreamTimeoutLowerThanBatchTimeoutThenUnprocessableEntity() throws IOException { when(eventTypeCache.getEventType(TEST_EVENT_TYPE_NAME)).thenReturn(EVENT_TYPE); final StreamingResponseBody responseBody = createStreamingResponseBody(0, 0, 20, 10, 0, null); final Problem expectedProblem = Problem.valueOf(UNPROCESSABLE_ENTITY, "stream_timeout can't be lower than batch_flush_timeout"); MatcherAssert.assertThat(responseToString(responseBody), JSON_TEST_HELPER.matchesObject(expectedProblem)); }
Example 15
Source File: CursorsControllerTest.java From nakadi with MIT License | 5 votes |
@Test public void whenSubscriptionConsumptionBlockedThenAccessDeniedOnPatchCommit() throws Exception { Mockito.when(eventStreamChecks.isSubscriptionConsumptionBlocked(anyString(), any())).thenReturn(true); final Problem expectedProblem = Problem.valueOf(FORBIDDEN, "Application or subscription is blocked"); checkForProblem( patchCursorsString("{\"items\":[{\"offset\":\"0\",\"partition\":\"0\",\"cursor_token\":\"x\"," + "\"event_type\":\"et\"}]}"), expectedProblem); }
Example 16
Source File: SubscriptionControllerTest.java From nakadi with MIT License | 5 votes |
@Test public void whenListSubscriptionsAndExceptionThenServiceUnavailable() throws Exception { when(subscriptionRepository.listSubscriptions(any(), any(), anyInt(), anyInt())) .thenThrow(new ServiceTemporarilyUnavailableException("dummy message")); final Problem expectedProblem = Problem.valueOf(SERVICE_UNAVAILABLE, "dummy message"); checkForProblem(getSubscriptions(), expectedProblem); }
Example 17
Source File: CursorsControllerTest.java From nakadi with MIT License | 5 votes |
@Test public void whenInvalidCursorExceptionThenUnprocessableEntity() throws Exception { when(cursorsService.commitCursors(any(), any(), any(), any())) .thenThrow((new InvalidCursorException(CursorError.NULL_PARTITION, new SubscriptionCursor(null, null, null, null)))); final Problem expectedProblem = Problem.valueOf(UNPROCESSABLE_ENTITY, "partition must not be null"); checkForProblem(postCursors(DUMMY_CURSORS), expectedProblem); }
Example 18
Source File: GzipBodyRequestFilter.java From nakadi with MIT License | 5 votes |
private void reportNotAcceptableError(final HttpServletResponse response, final HttpServletRequest request) throws IOException { response.setStatus(NOT_ACCEPTABLE.getStatusCode()); final PrintWriter writer = response.getWriter(); final Problem problem = Problem.valueOf(NOT_ACCEPTABLE, request.getMethod() + " method doesn't support gzip content encoding"); writer.write(objectMapper.writeValueAsString(problem)); writer.close(); }
Example 19
Source File: FeignClientSampleFallBackFactory.java From loc-framework with MIT License | 5 votes |
@Override public FeignClientSample create(Throwable throwable) { return () -> { log.error("错误:{}", throwable.getMessage(), throwable); return Problem.valueOf(Status.BAD_REQUEST); }; }
Example 20
Source File: SubscriptionControllerTest.java From nakadi with MIT License | 4 votes |
@Test public void whenListSubscriptionsWithNegativeOffsetThenBadRequest() throws Exception { final Problem expectedProblem = Problem.valueOf(BAD_REQUEST, "'offset' parameter can't be lower than 0"); checkForProblem(getSubscriptions(ImmutableSet.of("et"), "app", -5, 10), expectedProblem); }