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