use of org.zalando.problem.Problem in project nakadi by zalando.
the class EventTypeControllerTest method whenDeleteEventTypeThatHasSubscriptionsThenConflict.
@Test
public void whenDeleteEventTypeThatHasSubscriptionsThenConflict() throws Exception {
final EventType eventType = buildDefaultEventType();
when(eventTypeRepository.findByNameO(eventType.getName())).thenReturn(Optional.of(eventType));
when(subscriptionRepository.listSubscriptions(eq(ImmutableSet.of(eventType.getName())), eq(Optional.empty()), anyInt(), anyInt())).thenReturn(ImmutableList.of(mock(Subscription.class)));
final Problem expectedProblem = Problem.valueOf(Response.Status.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)));
}
use of org.zalando.problem.Problem in project nakadi by zalando.
the class EventTypeControllerTest method whenEventTypeSchemaJsonIsMalformedThen422.
@Test
public void whenEventTypeSchemaJsonIsMalformedThen422() throws Exception {
final EventType eventType = buildDefaultEventType();
eventType.getSchema().setSchema("invalid-json");
final Problem expectedProblem = new InvalidEventTypeException("schema must be a valid json: Unexpected token 'invalid' on line 1, char 1").asProblem();
postETAndExpect422WithProblem(eventType, expectedProblem);
}
use of org.zalando.problem.Problem in project nakadi by zalando.
the class EventTypeControllerTest method invalidEventTypeSchemaJsonSchemaThen422.
@Test
public void invalidEventTypeSchemaJsonSchemaThen422() throws Exception {
final EventType eventType = buildDefaultEventType();
final String jsonSchemaString = Resources.toString(Resources.getResource("sample-invalid-json-schema.json"), Charsets.UTF_8);
eventType.getSchema().setSchema(jsonSchemaString);
final Problem expectedProblem = new InvalidEventTypeException("schema must be a valid json-schema").asProblem();
postETAndExpect422WithProblem(eventType, expectedProblem);
}
use of org.zalando.problem.Problem in project nakadi by zalando.
the class PostSubscriptionControllerTest method whenMoreThanAllowedEventTypeThenUnprocessableEntity.
@Test
public void whenMoreThanAllowedEventTypeThenUnprocessableEntity() throws Exception {
when(subscriptionService.getExistingSubscription(any())).thenThrow(new NoSubscriptionException("", null));
when(subscriptionService.createSubscription(any())).thenThrow(new TooManyPartitionsException("msg"));
final SubscriptionBase subscriptionBase = builder().buildSubscriptionBase();
final Problem expectedProblem = Problem.valueOf(UNPROCESSABLE_ENTITY, "msg");
checkForProblem(postSubscription(subscriptionBase), expectedProblem);
}
use of org.zalando.problem.Problem in project nakadi by zalando.
the class PostSubscriptionControllerTest method whenEventTypesIsEmptyThenUnprocessableEntity.
@Test
public void whenEventTypesIsEmptyThenUnprocessableEntity() throws Exception {
final SubscriptionBase subscriptionBase = builder().withEventTypes(ImmutableSet.of()).buildSubscriptionBase();
final Problem expectedProblem = invalidProblem("event_types", "must contain at least one element");
checkForProblem(postSubscription(subscriptionBase), expectedProblem);
}
Aggregations