Search in sources :

Example 21 with Version

use of io.spine.core.Version in project core-java by SpineEventEngine.

the class TransactionShould method initialize_from_entity.

@Test
public void initialize_from_entity() {
    final E entity = createEntity();
    final B expectedBuilder = entity.builderFromState();
    final Version expectedVersion = entity.getVersion();
    final LifecycleFlags expectedLifecycleFlags = entity.getLifecycleFlags();
    final Transaction<I, E, S, B> tx = createTx(entity);
    assertNotNull(tx);
    assertEquals(entity, tx.getEntity());
    // Not possible to compare `Message.Builder` instances via `equals`, so trigger `build()`.
    assertEquals(expectedBuilder.build(), tx.getBuilder().build());
    assertEquals(expectedVersion, tx.getVersion());
    assertEquals(expectedLifecycleFlags, tx.getLifecycleFlags());
    assertTrue(tx.isActive());
    assertTrue(tx.getPhases().isEmpty());
}
Also used : Versions.newVersion(io.spine.core.Versions.newVersion) Version(io.spine.core.Version) Test(org.junit.Test)

Example 22 with Version

use of io.spine.core.Version in project core-java by SpineEventEngine.

the class TransactionShould method rollback_automatically_if_phase_failed.

@Test
public void rollback_automatically_if_phase_failed() {
    final E entity = createEntity();
    final S originalState = entity.getState();
    final Version originalVersion = entity.getVersion();
    final Transaction<I, E, S, B> tx = createTx(entity);
    final Event event = createEvent(createEventMessageThatFailsInHandler());
    try {
        applyEvent(tx, event);
        fail("Expected an `Exception` due to a failed phase execution.");
    } catch (final Exception e) {
        checkRollback(entity, originalState, originalVersion);
    }
}
Also used : Versions.newVersion(io.spine.core.Versions.newVersion) Version(io.spine.core.Version) Event(io.spine.core.Event) ValidationException(io.spine.validate.ValidationException) Test(org.junit.Test)

Example 23 with Version

use of io.spine.core.Version in project core-java by SpineEventEngine.

the class TransactionShould method not_allow_injecting_state_if_entity_has_non_zero_version_already.

@Test(expected = IllegalStateException.class)
public void not_allow_injecting_state_if_entity_has_non_zero_version_already() {
    final E entity = createEntity();
    entity.incrementVersion();
    final S newState = createNewState();
    final Version newVersion = someVersion();
    createTxWithState(entity, newState, newVersion);
}
Also used : Versions.newVersion(io.spine.core.Versions.newVersion) Version(io.spine.core.Version) Test(org.junit.Test)

Example 24 with Version

use of io.spine.core.Version in project core-java by SpineEventEngine.

the class TransactionShould method rollback_automatically_if_commit_failed.

@Test
public void rollback_automatically_if_commit_failed() {
    final E entity = createEntity(someViolations());
    final S originalState = entity.getState();
    final Version originalVersion = entity.getVersion();
    final S newState = createNewState();
    final Version version = someVersion();
    final Transaction<I, E, S, B> tx = createTxWithState(entity, newState, version);
    try {
        tx.commit();
        fail("Expected an IllegalStateException due to a failed commit.");
    } catch (IllegalStateException e) {
        checkRollback(entity, originalState, originalVersion);
    }
}
Also used : Versions.newVersion(io.spine.core.Versions.newVersion) Version(io.spine.core.Version) Test(org.junit.Test)

Example 25 with Version

use of io.spine.core.Version in project core-java by SpineEventEngine.

the class EntityQueriesShould method construct_non_empty_queries.

@Test
public void construct_non_empty_queries() {
    final Message someGenericId = Sample.messageOfType(ProjectId.class);
    final Any someId = AnyPacker.pack(someGenericId);
    final EntityId entityId = EntityId.newBuilder().setId(someId).build();
    final EntityIdFilter idFilter = EntityIdFilter.newBuilder().addIds(entityId).build();
    final Version versionValue = Version.newBuilder().setNumber(1).build();
    final BoolValue archivedValue = BoolValue.newBuilder().setValue(true).build();
    final ColumnFilter versionFilter = ColumnFilters.eq(version.name(), versionValue);
    final ColumnFilter archivedFilter = ColumnFilters.eq(archived.name(), archivedValue);
    final CompositeColumnFilter aggregatingFilter = CompositeColumnFilter.newBuilder().addFilter(versionFilter).addFilter(archivedFilter).setOperator(EITHER).build();
    final EntityFilters filters = EntityFilters.newBuilder().setIdFilter(idFilter).addFilter(aggregatingFilter).build();
    final EntityQuery<?> query = createEntityQuery(filters, AbstractVersionableEntity.class);
    assertNotNull(query);
    final Collection<?> ids = query.getIds();
    assertFalse(ids.isEmpty());
    assertSize(1, ids);
    final Object singleId = ids.iterator().next();
    assertEquals(someGenericId, singleId);
    final List<CompositeQueryParameter> values = newArrayList(query.getParameters());
    assertSize(1, values);
    final CompositeQueryParameter singleParam = values.get(0);
    final Collection<ColumnFilter> columnFilters = singleParam.getFilters().values();
    assertEquals(EITHER, singleParam.getOperator());
    assertContains(versionFilter, columnFilters);
    assertContains(archivedFilter, columnFilters);
}
Also used : CompositeColumnFilter(io.spine.client.CompositeColumnFilter) Message(com.google.protobuf.Message) EntityIdFilter(io.spine.client.EntityIdFilter) EntityFilters(io.spine.client.EntityFilters) BoolValue(com.google.protobuf.BoolValue) ColumnFilter(io.spine.client.ColumnFilter) CompositeColumnFilter(io.spine.client.CompositeColumnFilter) Any(com.google.protobuf.Any) EntityId(io.spine.client.EntityId) Version(io.spine.core.Version) Test(org.junit.Test)

Aggregations

Version (io.spine.core.Version)41 Test (org.junit.Test)33 GivenVersion (io.spine.core.given.GivenVersion)16 Customer (io.spine.test.commandservice.customer.Customer)13 Any (com.google.protobuf.Any)11 Versions.newVersion (io.spine.core.Versions.newVersion)11 TenantAwareTest (io.spine.server.tenant.TenantAwareTest)11 Event (io.spine.core.Event)10 CustomerId (io.spine.test.commandservice.customer.CustomerId)10 Map (java.util.Map)7 Maps.newHashMap (com.google.common.collect.Maps.newHashMap)6 Query (io.spine.client.Query)5 Topic (io.spine.client.Topic)5 QueryResponse (io.spine.client.QueryResponse)4 ProjectId (io.spine.test.projection.ProjectId)4 Message (com.google.protobuf.Message)3 Timestamp (com.google.protobuf.Timestamp)3 EntityStateUpdate (io.spine.client.EntityStateUpdate)3 EntityRecord (io.spine.server.entity.EntityRecord)3 Project (io.spine.test.aggregate.Project)3