Search in sources :

Example 36 with Event

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

the class TransactionShould method create_phase_for_an_applied_event.

@Test
public void create_phase_for_an_applied_event() {
    final E entity = createEntity();
    final Transaction<I, E, S, B> tx = createTx(entity);
    final Event event = createEvent(createEventMessage());
    applyEvent(tx, event);
    assertEquals(1, tx.getPhases().size());
    final Phase<I, E, S, B> phase = tx.getPhases().get(0);
    assertTrue(checkPhase(event, phase, true));
}
Also used : Event(io.spine.core.Event) Test(org.junit.Test)

Example 37 with Event

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

the class TransactionShould method not_propagate_changes_to_entity_on_rollback.

@Test
public void not_propagate_changes_to_entity_on_rollback() {
    final E entity = createEntity();
    final Transaction<I, E, S, B> tx = createTx(entity);
    final Event event = createEvent(createEventMessage());
    applyEvent(tx, event);
    final S stateBeforeRollback = entity.getState();
    final Version versionBeforeRollback = entity.getVersion();
    tx.rollback(new RuntimeException("that triggers rollback"));
    final S stateAfterRollback = entity.getState();
    final Version versionAfterRollback = entity.getVersion();
    assertEquals(stateBeforeRollback, stateAfterRollback);
    assertEquals(versionBeforeRollback, versionAfterRollback);
}
Also used : Versions.newVersion(io.spine.core.Versions.newVersion) Version(io.spine.core.Version) Event(io.spine.core.Event) Test(org.junit.Test)

Example 38 with Event

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

the class TransactionShould method set_txEntityVersion_from_EventContext.

@Test
public void set_txEntityVersion_from_EventContext() {
    final E entity = createEntity();
    final Transaction<I, E, S, B> tx = createTx(entity);
    final Event event = createEvent(createEventMessage());
    final Version ctxVersion = event.getContext().getVersion();
    assertNotEquals(tx.getVersion(), ctxVersion);
    applyEvent(tx, event);
    final Version modifiedVersion = tx.getVersion();
    assertEquals(modifiedVersion, tx.getVersion());
}
Also used : Versions.newVersion(io.spine.core.Versions.newVersion) Version(io.spine.core.Version) Event(io.spine.core.Event) Test(org.junit.Test)

Example 39 with Event

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

the class TransactionShould method notify_listener_during_transaction_execution.

@Test
// OK for a test method.
@SuppressWarnings({ "unchecked", "ConstantConditions" })
public void notify_listener_during_transaction_execution() {
    final TransactionListener<I, E, S, B> listener = mock(TransactionListener.class);
    final E entity = createEntity();
    final Transaction<I, E, S, B> tx = createTxWithListener(entity, listener);
    final Event event = createEvent(createEventMessage());
    verifyZeroInteractions(listener);
    applyEvent(tx, event);
    verify(listener).onAfterPhase(argThat(matchesSuccessfulPhaseFor(event)));
}
Also used : Event(io.spine.core.Event) Test(org.junit.Test)

Example 40 with Event

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

the class TransactionShould method propagate_changes_to_entity_applier_methods.

@Test
public void propagate_changes_to_entity_applier_methods() {
    final E entity = createEntity();
    final Transaction<I, E, S, B> tx = createTx(entity);
    final Event event = createEvent(createEventMessage());
    applyEvent(tx, event);
    checkEventReceived(entity, event);
}
Also used : Event(io.spine.core.Event) Test(org.junit.Test)

Aggregations

Event (io.spine.core.Event)115 Test (org.junit.Test)75 Command (io.spine.core.Command)19 EventContext (io.spine.core.EventContext)12 BoundedContext (io.spine.server.BoundedContext)12 GivenEvent (io.spine.server.event.given.EventBusTestEnv.GivenEvent)12 Version (io.spine.core.Version)10 TestEventFactory (io.spine.server.command.TestEventFactory)10 Message (com.google.protobuf.Message)9 EventEnvelope (io.spine.core.EventEnvelope)9 InMemoryTransportFactory (io.spine.server.integration.memory.InMemoryTransportFactory)9 Timestamp (com.google.protobuf.Timestamp)6 Ack (io.spine.core.Ack)6 TenantId (io.spine.core.TenantId)6 Error (io.spine.base.Error)5 AggregateMessageDispatcher.dispatchCommand (io.spine.server.aggregate.AggregateMessageDispatcher.dispatchCommand)5 AggregateTestEnv.newTenantId (io.spine.server.aggregate.given.aggregate.AggregateTestEnv.newTenantId)5 StringValue (com.google.protobuf.StringValue)4 GivenEvent (io.spine.core.given.GivenEvent)4 Duration (com.google.protobuf.Duration)3