use of org.zalando.problem.Problem in project nakadi by zalando.
the class EventTypeControllerTest method whenPostWithNoCategoryThenReturn422.
@Test
public void whenPostWithNoCategoryThenReturn422() throws Exception {
final EventType invalidEventType = buildDefaultEventType();
final JSONObject jsonObject = new JSONObject(TestUtils.OBJECT_MAPPER.writeValueAsString(invalidEventType));
jsonObject.remove("category");
final Problem expectedProblem = invalidProblem("category", "may not be null");
postETAndExpect422WithProblem(jsonObject.toString(), expectedProblem);
}
use of org.zalando.problem.Problem in project nakadi by zalando.
the class EventTypeControllerTest method whenDeleteEventTypeAndNakadiExceptionThen500.
@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)));
}
use of org.zalando.problem.Problem in project nakadi by zalando.
the class EventTypeControllerTest method whenPUTDifferentEventTypeNameThen422.
@Test
public void whenPUTDifferentEventTypeNameThen422() throws Exception {
final EventType eventType = buildDefaultEventType();
final String eventTypeName = eventType.getName();
eventType.setName("event-name-different");
final Problem expectedProblem = new InvalidEventTypeException("path does not match resource name").asProblem();
doReturn(eventType).when(eventTypeRepository).findByName(eventTypeName);
putEventType(eventType, eventTypeName).andExpect(status().isUnprocessableEntity()).andExpect(content().contentType("application/problem+json")).andExpect(content().string(matchesProblem(expectedProblem)));
}
use of org.zalando.problem.Problem in project nakadi by zalando.
the class EventTypeControllerTest method whenPostEventTypeWithIncorrectNameThen422.
@Test
public void whenPostEventTypeWithIncorrectNameThen422() throws Exception {
final List<String> incorrectNames = ImmutableList.of("?", "56mycoolET", "abc^%!", "myET.-abc", "abc._def", "_underscore", "-event", "many..dots", ".firstDot");
for (final String etName : incorrectNames) {
final EventType invalidEventType = buildDefaultEventType();
invalidEventType.setName(etName);
final Problem expectedProblem = invalidProblem("name", "format not allowed");
postETAndExpect422WithProblem(invalidEventType, expectedProblem);
}
}
use of org.zalando.problem.Problem in project nakadi by zalando.
the class EventTypeControllerTest method whenPUTInvalidEventTypeThen422.
@Test
public void whenPUTInvalidEventTypeThen422() throws Exception {
final EventType invalidEventType = buildDefaultEventType();
final JSONObject jsonObject = new JSONObject(TestUtils.OBJECT_MAPPER.writeValueAsString(invalidEventType));
jsonObject.remove("category");
final Problem expectedProblem = invalidProblem("category", "may not be null");
putEventType(jsonObject.toString(), invalidEventType.getName()).andExpect(status().isUnprocessableEntity()).andExpect(content().contentType("application/problem+json")).andExpect(content().string(matchesProblem(expectedProblem)));
}
Aggregations