本文整理汇总了Java中org.zalando.problem.Problem.valueOf方法的典型用法代码示例。如果您正苦于以下问题:Java Problem.valueOf方法的具体用法?Java Problem.valueOf怎么用?Java Problem.valueOf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.zalando.problem.Problem
的用法示例。
在下文中一共展示了Problem.valueOf方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: whenDeleteEventTypeAndNakadiExceptionThen500
import org.zalando.problem.Problem; //导入方法依赖的package包/类
@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)));
}
示例2: whenTimelineCreationFailsRemoveEventTypeFromRepositoryAnd500
import org.zalando.problem.Problem; //导入方法依赖的package包/类
@Test
public void whenTimelineCreationFailsRemoveEventTypeFromRepositoryAnd500() throws Exception {
final EventType et = buildDefaultEventType();
doThrow(TopicCreationException.class).when(timelineService)
.createDefaultTimeline(anyString(), anyInt(), anyLong());
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(anyString(), anyInt(), anyLong());
verify(eventTypeRepository, times(1)).removeEventType(et.getName());
}
示例3: whenStreamTimeoutLowerThanBatchTimeoutThenUnprocessableEntity
import org.zalando.problem.Problem; //导入方法依赖的package包/类
@Test
public void whenStreamTimeoutLowerThanBatchTimeoutThenUnprocessableEntity() throws NakadiException, IOException {
when(eventTypeRepository.findByName(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");
assertThat(responseToString(responseBody), TestUtils.JSON_TEST_HELPER.matchesObject(expectedProblem));
}
示例4: whenGetWithGzipEncodingThenNotAcceptable
import org.zalando.problem.Problem; //导入方法依赖的package包/类
@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);
}
示例5: whenNoSubscriptionThenNotFound
import org.zalando.problem.Problem; //导入方法依赖的package包/类
@Test
public void whenNoSubscriptionThenNotFound() throws Exception {
when(cursorsService.commitCursors(any(), eq(SUBSCRIPTION_ID), any()))
.thenThrow(new NoSuchSubscriptionException("dummy-message"));
final Problem expectedProblem = Problem.valueOf(NOT_FOUND, "dummy-message");
checkForProblem(postCursors(DUMMY_CURSORS), expectedProblem);
}
示例6: whenInvalidCursorsThenPreconditionFailed
import org.zalando.problem.Problem; //导入方法依赖的package包/类
@Test
public void whenInvalidCursorsThenPreconditionFailed() throws Exception {
final NakadiCursor cursor = NakadiCursor.of(timeline, "0", "000000000000000000");
when(eventTypeRepository.findByName(TEST_EVENT_TYPE_NAME)).thenReturn(EVENT_TYPE);
when(timelineService.createEventConsumer(eq(KAFKA_CLIENT_ID), any()))
.thenThrow(new InvalidCursorException(CursorError.UNAVAILABLE, cursor));
final StreamingResponseBody responseBody = createStreamingResponseBody(1, 0, 0, 0, 0,
"[{\"partition\":\"0\",\"offset\":\"00000000000000000\"}]");
final Problem expectedProblem = Problem.valueOf(PRECONDITION_FAILED,
"offset 000000000000000000 for partition 0 is unavailable");
assertThat(responseToString(responseBody), TestUtils.JSON_TEST_HELPER.matchesObject(expectedProblem));
}
示例7: whenServiceUnavailableExceptionThenServiceUnavailable
import org.zalando.problem.Problem; //导入方法依赖的package包/类
@Test
public void whenServiceUnavailableExceptionThenServiceUnavailable() throws Exception {
when(cursorsService.commitCursors(any(), any(), any()))
.thenThrow(new ServiceUnavailableException("dummy-message"));
final Problem expectedProblem = Problem.valueOf(SERVICE_UNAVAILABLE, "dummy-message");
checkForProblem(postCursors(DUMMY_CURSORS), expectedProblem);
}
示例8: whenInvalidCursorExceptionThenUnprocessableEntity
import org.zalando.problem.Problem; //导入方法依赖的package包/类
@Test
public void whenInvalidCursorExceptionThenUnprocessableEntity() throws Exception {
when(cursorsService.commitCursors(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);
}
示例9: whenListPartitionsAndNakadiExceptionThenServiceUnavaiable
import org.zalando.problem.Problem; //导入方法依赖的package包/类
@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)));
}
示例10: testAccessDenied
import org.zalando.problem.Problem; //导入方法依赖的package包/类
@Test
public void testAccessDenied() throws Exception {
Mockito.doThrow(AccessDeniedException.class).when(authorizationValidator)
.authorizeStreamRead(any());
when(eventTypeRepository.findByName(TEST_EVENT_TYPE_NAME)).thenReturn(EVENT_TYPE);
Mockito.doThrow(mockAccessDeniedException()).when(authorizationValidator).authorizeStreamRead(any());
final StreamingResponseBody responseBody = createStreamingResponseBody(0, 0, 0, 0, 0, null);
final Problem expectedProblem = Problem.valueOf(FORBIDDEN, "Access on READ some-type:some-name denied");
assertThat(responseToString(responseBody), TestUtils.JSON_TEST_HELPER.matchesObject(expectedProblem));
}
示例11: whenBatchLimitLowerThan1ThenUnprocessableEntity
import org.zalando.problem.Problem; //导入方法依赖的package包/类
@Test
public void whenBatchLimitLowerThan1ThenUnprocessableEntity() throws Exception {
final StreamingResponseBody responseBody = controller.streamEvents("abc", 0, 0, null, 10, null, null,
requestMock, responseMock, FULL_ACCESS_CLIENT);
final Problem expectedProblem = Problem.valueOf(UNPROCESSABLE_ENTITY, "batch_limit can't be lower than 1");
assertThat(responseToString(responseBody), jsonHelper.matchesObject(expectedProblem));
}
示例12: whenGetPartitionForWrongTopicThenNotFound
import org.zalando.problem.Problem; //导入方法依赖的package包/类
@Test
public void whenGetPartitionForWrongTopicThenNotFound() throws Exception {
when(eventTypeRepositoryMock.findByName(UNKNOWN_EVENT_TYPE)).thenThrow(NoSuchEventTypeException.class);
final ThrowableProblem expectedProblem = Problem.valueOf(NOT_FOUND, "topic not found");
mockMvc.perform(
get(String.format("/event-types/%s/partitions/%s", UNKNOWN_EVENT_TYPE, TEST_PARTITION)))
.andExpect(status().isNotFound())
.andExpect(content().string(TestUtils.JSON_TEST_HELPER.matchesObject(expectedProblem)));
}
示例13: whenTopicNotExistsThenTopicNotFound
import org.zalando.problem.Problem; //导入方法依赖的package包/类
@Test
public void whenTopicNotExistsThenTopicNotFound() throws IOException, NakadiException {
when(eventTypeRepository.findByName(TEST_EVENT_TYPE_NAME)).thenThrow(NoSuchEventTypeException.class);
final StreamingResponseBody responseBody = createStreamingResponseBody();
final Problem expectedProblem = Problem.valueOf(NOT_FOUND, "topic not found");
assertThat(responseToString(responseBody), TestUtils.JSON_TEST_HELPER.matchesObject(expectedProblem));
}
示例14: whenWrongCursorsFormatThenBadRequest
import org.zalando.problem.Problem; //导入方法依赖的package包/类
@Test
public void whenWrongCursorsFormatThenBadRequest() throws NakadiException, IOException {
when(eventTypeRepository.findByName(TEST_EVENT_TYPE_NAME)).thenReturn(EVENT_TYPE);
final StreamingResponseBody responseBody = createStreamingResponseBody(0, 0, 0, 0, 0,
"cursors_with_wrong_format");
final Problem expectedProblem = Problem.valueOf(BAD_REQUEST, "incorrect syntax of X-nakadi-cursors header");
assertThat(responseToString(responseBody), TestUtils.JSON_TEST_HELPER.matchesObject(expectedProblem));
}
示例15: whenUpdateEventTypeAndTimelineWaitTimeoutThen503
import org.zalando.problem.Problem; //导入方法依赖的package包/类
@Test
public void whenUpdateEventTypeAndTimelineWaitTimeoutThen503() throws Exception {
when(timelineSync.workWithEventType(any(), anyLong())).thenThrow(new TimeoutException());
final EventType eventType = buildDefaultEventType();
final Problem expectedProblem = Problem.valueOf(SERVICE_UNAVAILABLE,
"Event type is currently in maintenance, please repeat request");
putEventType(eventType, eventType.getName(), "nakadi")
.andExpect(status().isServiceUnavailable())
.andExpect(content().string(matchesProblem(expectedProblem)));
}