Search in sources :

Example 56 with EventType

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

the class PartitionResolverTest method whenValidateWithKnownPartitionStrategyThenOk.

@Test
public void whenValidateWithKnownPartitionStrategyThenOk() throws Exception {
    final EventType eventType = buildDefaultEventType();
    eventType.setPartitionStrategy(RANDOM_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 57 with EventType

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

the class CategoryChangeConstraintTest method cannotChangeCategory.

@Test
public void cannotChangeCategory() throws Exception {
    final EventTypeTestBuilder builder = new EventTypeTestBuilder();
    final EventType oldET = builder.category(EventCategory.BUSINESS).build();
    final EventType newET = builder.category(EventCategory.DATA).build();
    final SchemaEvolutionConstraint constraint = new CategoryChangeConstraint();
    assertThat(constraint.validate(oldET, newET), isPresent());
}
Also used : EventType(org.zalando.nakadi.domain.EventType) EventTypeTestBuilder(org.zalando.nakadi.utils.EventTypeTestBuilder) Test(org.junit.Test)

Example 58 with EventType

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

the class SchemaEvolutionServiceTest method compatibilityModeMigrationAllowedChanges.

@Test
public void compatibilityModeMigrationAllowedChanges() throws Exception {
    final EventTypeTestBuilder builder = EventTypeTestBuilder.builder().compatibilityMode(CompatibilityMode.FORWARD);
    final EventType oldEventType = builder.build();
    final EventType newEventType = builder.compatibilityMode(CompatibilityMode.COMPATIBLE).build();
    Mockito.doReturn(Optional.empty()).when(evolutionConstraint).validate(oldEventType, newEventType);
    final List<SchemaChange.Type> allowedChanges = Lists.newArrayList(DESCRIPTION_CHANGED, TITLE_CHANGED, PROPERTIES_ADDED, REQUIRED_ARRAY_EXTENDED, ADDITIONAL_PROPERTIES_CHANGED, ADDITIONAL_ITEMS_CHANGED);
    final List<SchemaChange.Type> notAllowedChanges = Lists.newArrayList(ID_CHANGED, SCHEMA_REMOVED, TYPE_CHANGED, NUMBER_OF_ITEMS_CHANGED, PROPERTY_REMOVED, DEPENDENCY_ARRAY_CHANGED, DEPENDENCY_SCHEMA_CHANGED, COMPOSITION_METHOD_CHANGED, ATTRIBUTE_VALUE_CHANGED, ENUM_ARRAY_CHANGED, SUB_SCHEMA_CHANGED, DEPENDENCY_SCHEMA_REMOVED, REQUIRED_ARRAY_CHANGED);
    allowedChanges.forEach(changeType -> {
        Mockito.doReturn(MINOR).when(forwardChanges).get(any());
        Mockito.doReturn(Lists.newArrayList(new SchemaChange(changeType, "#/"))).when(schemaDiff).collectChanges(any(), any());
        final EventType eventType;
        try {
            eventType = service.evolve(oldEventType, newEventType);
            assertThat(eventType.getSchema().getVersion(), is(equalTo(new Version("1.1.0"))));
        } catch (final InvalidEventTypeException e) {
            fail();
        }
    });
    notAllowedChanges.forEach(changeType -> {
        Mockito.doReturn(Lists.newArrayList(new SchemaChange(changeType, "#/"))).when(schemaDiff).collectChanges(any(), any());
        try {
            service.evolve(oldEventType, newEventType);
            fail();
        } catch (final InvalidEventTypeException e) {
        }
    });
}
Also used : EventType(org.zalando.nakadi.domain.EventType) InvalidEventTypeException(org.zalando.nakadi.exceptions.InvalidEventTypeException) EventType(org.zalando.nakadi.domain.EventType) Version(org.zalando.nakadi.domain.Version) SchemaChange(org.zalando.nakadi.domain.SchemaChange) EventTypeTestBuilder(org.zalando.nakadi.utils.EventTypeTestBuilder) Test(org.junit.Test)

Example 59 with EventType

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

the class SchemaEvolutionServiceTest method whenIncompatibleModeAllowMajorChanges.

@Test
public void whenIncompatibleModeAllowMajorChanges() throws Exception {
    final EventTypeTestBuilder builder = EventTypeTestBuilder.builder().compatibilityMode(CompatibilityMode.NONE);
    final EventType oldEventType = builder.build();
    final EventType newEventType = builder.build();
    Mockito.doReturn(Optional.empty()).when(evolutionConstraint).validate(oldEventType, newEventType);
    Mockito.doReturn(MAJOR).when(forwardChanges).get(any());
    Mockito.doReturn(Lists.newArrayList(new SchemaChange(TITLE_CHANGED, "#/"))).when(schemaDiff).collectChanges(any(), any());
    final EventType eventType = service.evolve(oldEventType, newEventType);
    assertThat(eventType.getSchema().getVersion(), is(equalTo(new Version("2.0.0"))));
    verify(evolutionConstraint).validate(oldEventType, newEventType);
}
Also used : EventType(org.zalando.nakadi.domain.EventType) Version(org.zalando.nakadi.domain.Version) SchemaChange(org.zalando.nakadi.domain.SchemaChange) EventTypeTestBuilder(org.zalando.nakadi.utils.EventTypeTestBuilder) Test(org.junit.Test)

Example 60 with EventType

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

the class SchemaEvolutionServiceTest method whenPatchChangesBumpVersion.

@Test
public void whenPatchChangesBumpVersion() throws Exception {
    final EventTypeTestBuilder builder = EventTypeTestBuilder.builder();
    final EventType oldEventType = builder.build();
    final EventType newEventType = builder.build();
    Mockito.doReturn(Optional.empty()).when(evolutionConstraint).validate(oldEventType, newEventType);
    Mockito.doReturn(PATCH).when(compatibleChanges).get(any());
    Mockito.doReturn(Lists.newArrayList(new SchemaChange(TITLE_CHANGED, "#/"))).when(schemaDiff).collectChanges(any(), any());
    final EventType eventType = service.evolve(oldEventType, newEventType);
    assertThat(eventType.getSchema().getVersion(), is(equalTo(new Version("1.0.1"))));
    verify(evolutionConstraint).validate(oldEventType, newEventType);
}
Also used : EventType(org.zalando.nakadi.domain.EventType) Version(org.zalando.nakadi.domain.Version) SchemaChange(org.zalando.nakadi.domain.SchemaChange) EventTypeTestBuilder(org.zalando.nakadi.utils.EventTypeTestBuilder) 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