Search in sources :

Example 1 with InvalidEventTypeException

use of org.zalando.nakadi.exceptions.InvalidEventTypeException in project nakadi by zalando.

the class EventTypeControllerTest method whenPOSTBusinessEventTypeMetadataThen422.

@Test
public void whenPOSTBusinessEventTypeMetadataThen422() throws Exception {
    final EventType eventType = buildDefaultEventType();
    eventType.getSchema().setSchema("{\"type\": \"object\", \"properties\": {\"metadata\": {\"type\": \"object\"} }}");
    eventType.setCategory(BUSINESS);
    final Problem expectedProblem = new InvalidEventTypeException("\"metadata\" property is reserved").asProblem();
    postETAndExpect422WithProblem(eventType, expectedProblem);
}
Also used : InvalidEventTypeException(org.zalando.nakadi.exceptions.InvalidEventTypeException) TestUtils.buildDefaultEventType(org.zalando.nakadi.utils.TestUtils.buildDefaultEventType) EventType(org.zalando.nakadi.domain.EventType) Problem(org.zalando.problem.Problem) ThrowableProblem(org.zalando.problem.ThrowableProblem) TestUtils.invalidProblem(org.zalando.nakadi.utils.TestUtils.invalidProblem) Test(org.junit.Test)

Example 2 with InvalidEventTypeException

use of org.zalando.nakadi.exceptions.InvalidEventTypeException in project nakadi by zalando.

the class EventTypeControllerTest method whenPOSTInvalidSchemaThen422.

@Test
public void whenPOSTInvalidSchemaThen422() throws Exception {
    final EventType eventType = buildDefaultEventType();
    eventType.getSchema().setSchema("{\"not\": {\"type\": \"object\"} }");
    eventType.setCategory(BUSINESS);
    final Problem expectedProblem = new InvalidEventTypeException("Invalid schema: Invalid schema found in [#]: " + "extraneous key [not] is not permitted").asProblem();
    postETAndExpect422WithProblem(eventType, expectedProblem);
}
Also used : InvalidEventTypeException(org.zalando.nakadi.exceptions.InvalidEventTypeException) TestUtils.buildDefaultEventType(org.zalando.nakadi.utils.TestUtils.buildDefaultEventType) EventType(org.zalando.nakadi.domain.EventType) Problem(org.zalando.problem.Problem) ThrowableProblem(org.zalando.problem.ThrowableProblem) TestUtils.invalidProblem(org.zalando.nakadi.utils.TestUtils.invalidProblem) Test(org.junit.Test)

Example 3 with InvalidEventTypeException

use of org.zalando.nakadi.exceptions.InvalidEventTypeException 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)));
}
Also used : InvalidEventTypeException(org.zalando.nakadi.exceptions.InvalidEventTypeException) TestUtils.buildDefaultEventType(org.zalando.nakadi.utils.TestUtils.buildDefaultEventType) EventType(org.zalando.nakadi.domain.EventType) Problem(org.zalando.problem.Problem) ThrowableProblem(org.zalando.problem.ThrowableProblem) TestUtils.invalidProblem(org.zalando.nakadi.utils.TestUtils.invalidProblem) Matchers.containsString(org.hamcrest.Matchers.containsString) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 4 with InvalidEventTypeException

use of org.zalando.nakadi.exceptions.InvalidEventTypeException 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);
}
Also used : InvalidEventTypeException(org.zalando.nakadi.exceptions.InvalidEventTypeException) TestUtils.buildDefaultEventType(org.zalando.nakadi.utils.TestUtils.buildDefaultEventType) EventType(org.zalando.nakadi.domain.EventType) Problem(org.zalando.problem.Problem) ThrowableProblem(org.zalando.problem.ThrowableProblem) TestUtils.invalidProblem(org.zalando.nakadi.utils.TestUtils.invalidProblem) Test(org.junit.Test)

Example 5 with InvalidEventTypeException

use of org.zalando.nakadi.exceptions.InvalidEventTypeException 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);
}
Also used : InvalidEventTypeException(org.zalando.nakadi.exceptions.InvalidEventTypeException) TestUtils.buildDefaultEventType(org.zalando.nakadi.utils.TestUtils.buildDefaultEventType) EventType(org.zalando.nakadi.domain.EventType) Problem(org.zalando.problem.Problem) ThrowableProblem(org.zalando.problem.ThrowableProblem) TestUtils.invalidProblem(org.zalando.nakadi.utils.TestUtils.invalidProblem) Matchers.containsString(org.hamcrest.Matchers.containsString) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Aggregations

InvalidEventTypeException (org.zalando.nakadi.exceptions.InvalidEventTypeException)8 EventType (org.zalando.nakadi.domain.EventType)7 Test (org.junit.Test)6 TestUtils.buildDefaultEventType (org.zalando.nakadi.utils.TestUtils.buildDefaultEventType)5 TestUtils.invalidProblem (org.zalando.nakadi.utils.TestUtils.invalidProblem)5 Problem (org.zalando.problem.Problem)5 ThrowableProblem (org.zalando.problem.ThrowableProblem)5 Schema (org.everit.json.schema.Schema)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 JSONObject (org.json.JSONObject)2 Matchers.anyString (org.mockito.Matchers.anyString)2 SchemaChange (org.zalando.nakadi.domain.SchemaChange)2 Version (org.zalando.nakadi.domain.Version)2 Lists (com.google.common.collect.Lists)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 BinaryOperator (java.util.function.BinaryOperator)1 Collectors (java.util.stream.Collectors)1