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());
}
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"));
}
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());
}
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);
}
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);
}
Aggregations