Search in sources :

Example 51 with EventType

use of org.zalando.nakadi.domain.EventType in project nakadi by zalando.

the class JSONSchemaValidationTest method acceptsDefinitionsOnDataChangeEvents.

@Test
public void acceptsDefinitionsOnDataChangeEvents() throws Exception {
    final JSONObject schema = new JSONObject(readFile("product-json-schema.json"));
    final EventType et = EventTypeTestBuilder.builder().name("some-event-type").schema(schema).build();
    et.setCategory(EventCategory.DATA);
    final JSONObject event = new JSONObject(readFile("product-event.json"));
    final Optional<ValidationError> error = EventValidation.forType(et).validate(event);
    assertThat(error, isAbsent());
}
Also used : JSONObject(org.json.JSONObject) EventType(org.zalando.nakadi.domain.EventType) Test(org.junit.Test)

Example 52 with EventType

use of org.zalando.nakadi.domain.EventType in project nakadi by zalando.

the class JSONSchemaValidationTest method validationOfDataChangeEventShouldNotAllowAdditionalFieldsAtTheRootLevelObject.

@Test
public void validationOfDataChangeEventShouldNotAllowAdditionalFieldsAtTheRootLevelObject() {
    final EventType et = EventTypeTestBuilder.builder().name("some-event-type").schema(basicSchema()).build();
    et.setCategory(EventCategory.DATA);
    final JSONObject event = dataChangeEvent();
    event.put("foo", "anything");
    final Optional<ValidationError> error = EventValidation.forType(et).validate(event);
    assertThat(error.get().getMessage(), equalTo("#: extraneous key [foo] is not permitted"));
}
Also used : JSONObject(org.json.JSONObject) EventType(org.zalando.nakadi.domain.EventType) Test(org.junit.Test)

Example 53 with EventType

use of org.zalando.nakadi.domain.EventType in project nakadi by zalando.

the class PartitionResolverTest method whenResolvePartitionWithKnownStrategyThenOk.

@Test
public void whenResolvePartitionWithKnownStrategyThenOk() throws NakadiException {
    final EventType eventType = new EventType();
    eventType.setPartitionStrategy(RANDOM_STRATEGY);
    when(timelineService.getActiveTimeline(eq(eventType))).thenReturn(mock(Timeline.class));
    final JSONObject event = new JSONObject();
    event.put("abc", "blah");
    final String partition = partitionResolver.resolvePartition(eventType, event);
    assertThat(partition, notNullValue());
}
Also used : Timeline(org.zalando.nakadi.domain.Timeline) JSONObject(org.json.JSONObject) EventType(org.zalando.nakadi.domain.EventType) TestUtils.buildDefaultEventType(org.zalando.nakadi.utils.TestUtils.buildDefaultEventType) Test(org.junit.Test)

Example 54 with EventType

use of org.zalando.nakadi.domain.EventType in project nakadi by zalando.

the class PartitionResolverTest method whenValidateWithUserDefinedPartitionStrategyForUndefinedCategoryThenExceptionThrown.

@Test(expected = InvalidEventTypeException.class)
public void whenValidateWithUserDefinedPartitionStrategyForUndefinedCategoryThenExceptionThrown() throws Exception {
    final EventType eventType = buildDefaultEventType();
    eventType.setCategory(UNDEFINED);
    eventType.setPartitionStrategy(USER_DEFINED_STRATEGY);
    partitionResolver.validate(eventType);
}
Also used : EventType(org.zalando.nakadi.domain.EventType) TestUtils.buildDefaultEventType(org.zalando.nakadi.utils.TestUtils.buildDefaultEventType) Test(org.junit.Test)

Example 55 with EventType

use of org.zalando.nakadi.domain.EventType in project nakadi by zalando.

the class PartitionResolverTest method whenValidateWithUnknownPartitionStrategyThenExceptionThrown.

@Test(expected = NoSuchPartitionStrategyException.class)
public void whenValidateWithUnknownPartitionStrategyThenExceptionThrown() throws Exception {
    final EventType eventType = buildDefaultEventType();
    eventType.setPartitionStrategy("unknown_strategy");
    partitionResolver.validate(eventType);
}
Also used : EventType(org.zalando.nakadi.domain.EventType) TestUtils.buildDefaultEventType(org.zalando.nakadi.utils.TestUtils.buildDefaultEventType) Test(org.junit.Test)

Aggregations

EventType (org.zalando.nakadi.domain.EventType)216 Test (org.junit.Test)183 TestUtils.buildDefaultEventType (org.zalando.nakadi.utils.TestUtils.buildDefaultEventType)138 JSONObject (org.json.JSONObject)40 Problem (org.zalando.problem.Problem)21 InternalNakadiException (org.zalando.nakadi.exceptions.InternalNakadiException)18 Matchers.containsString (org.hamcrest.Matchers.containsString)17 JSONArray (org.json.JSONArray)17 EventPublishResult (org.zalando.nakadi.domain.EventPublishResult)17 TestUtils.invalidProblem (org.zalando.nakadi.utils.TestUtils.invalidProblem)17 ThrowableProblem (org.zalando.problem.ThrowableProblem)17 Timeline (org.zalando.nakadi.domain.Timeline)16 NoSuchEventTypeException (org.zalando.nakadi.exceptions.NoSuchEventTypeException)14 EventTypeTestBuilder (org.zalando.nakadi.utils.EventTypeTestBuilder)14 BatchItem (org.zalando.nakadi.domain.BatchItem)12 TestUtils.resourceAsString (org.zalando.nakadi.utils.TestUtils.resourceAsString)12 List (java.util.List)11 Subscription (org.zalando.nakadi.domain.Subscription)11 TestUtils.createBatchItem (org.zalando.nakadi.utils.TestUtils.createBatchItem)11 Collectors (java.util.stream.Collectors)9