Search in sources :

Example 1 with FaultyAggregate

use of io.spine.server.aggregate.given.aggregate.FaultyAggregate in project core-java by SpineEventEngine.

the class AggregateShould method propagate_RuntimeException_when_handler_throws.

@Test
public void propagate_RuntimeException_when_handler_throws() {
    ModelTests.clearModel();
    final FaultyAggregate faultyAggregate = new FaultyAggregate(ID, true, false);
    final Command command = Given.ACommand.createProject();
    try {
        dispatchCommand(faultyAggregate, env(command.getMessage()));
        failNotThrows();
    } catch (RuntimeException e) {
        // We need it for checking.
        @SuppressWarnings("ThrowableResultOfMethodCallIgnored") final Throwable cause = getRootCause(e);
        assertTrue(cause instanceof IllegalStateException);
        assertEquals(FaultyAggregate.BROKEN_HANDLER, cause.getMessage());
    }
}
Also used : Command(io.spine.core.Command) AggregateMessageDispatcher.dispatchCommand(io.spine.server.aggregate.AggregateMessageDispatcher.dispatchCommand) FaultyAggregate(io.spine.server.aggregate.given.aggregate.FaultyAggregate) Test(org.junit.Test)

Example 2 with FaultyAggregate

use of io.spine.server.aggregate.given.aggregate.FaultyAggregate in project core-java by SpineEventEngine.

the class AggregateShould method propagate_RuntimeException_when_applier_throws.

@Test
public void propagate_RuntimeException_when_applier_throws() {
    ModelTests.clearModel();
    final FaultyAggregate faultyAggregate = new FaultyAggregate(ID, false, true);
    final Command command = Given.ACommand.createProject();
    try {
        dispatchCommand(faultyAggregate, env(command.getMessage()));
        failNotThrows();
    } catch (RuntimeException e) {
        @SuppressWarnings("ThrowableResultOfMethodCallIgnored") final Throwable // because we need it for checking.
        cause = getRootCause(e);
        assertTrue(cause instanceof IllegalStateException);
        assertEquals(FaultyAggregate.BROKEN_APPLIER, cause.getMessage());
    }
}
Also used : Command(io.spine.core.Command) AggregateMessageDispatcher.dispatchCommand(io.spine.server.aggregate.AggregateMessageDispatcher.dispatchCommand) FaultyAggregate(io.spine.server.aggregate.given.aggregate.FaultyAggregate) Test(org.junit.Test)

Example 3 with FaultyAggregate

use of io.spine.server.aggregate.given.aggregate.FaultyAggregate in project core-java by SpineEventEngine.

the class AggregateShould method propagate_RuntimeException_when_play_raises_exception.

@Test
public void propagate_RuntimeException_when_play_raises_exception() {
    ModelTests.clearModel();
    final FaultyAggregate faultyAggregate = new FaultyAggregate(ID, false, true);
    try {
        final Event event = event(projectCreated(ID, getClass().getSimpleName()), 1);
        final AggregateTransaction tx = AggregateTransaction.start(faultyAggregate);
        ((Aggregate) faultyAggregate).play(AggregateStateRecord.newBuilder().addEvent(event).build());
        tx.commit();
        failNotThrows();
    } catch (RuntimeException e) {
        @SuppressWarnings("ThrowableResultOfMethodCallIgnored") final Throwable // because we need it for checking.
        cause = getRootCause(e);
        assertTrue(cause instanceof IllegalStateException);
        assertEquals(FaultyAggregate.BROKEN_APPLIER, cause.getMessage());
    }
}
Also used : Event(io.spine.core.Event) FaultyAggregate(io.spine.server.aggregate.given.aggregate.FaultyAggregate) IntAggregate(io.spine.server.aggregate.given.aggregate.IntAggregate) AmishAggregate(io.spine.server.aggregate.given.aggregate.AmishAggregate) TaskAggregate(io.spine.server.aggregate.given.aggregate.TaskAggregate) TestAggregate(io.spine.server.aggregate.given.aggregate.TestAggregate) UserAggregate(io.spine.server.aggregate.given.aggregate.UserAggregate) FaultyAggregate(io.spine.server.aggregate.given.aggregate.FaultyAggregate) Test(org.junit.Test)

Aggregations

FaultyAggregate (io.spine.server.aggregate.given.aggregate.FaultyAggregate)3 Test (org.junit.Test)3 Command (io.spine.core.Command)2 AggregateMessageDispatcher.dispatchCommand (io.spine.server.aggregate.AggregateMessageDispatcher.dispatchCommand)2 Event (io.spine.core.Event)1 AmishAggregate (io.spine.server.aggregate.given.aggregate.AmishAggregate)1 IntAggregate (io.spine.server.aggregate.given.aggregate.IntAggregate)1 TaskAggregate (io.spine.server.aggregate.given.aggregate.TaskAggregate)1 TestAggregate (io.spine.server.aggregate.given.aggregate.TestAggregate)1 UserAggregate (io.spine.server.aggregate.given.aggregate.UserAggregate)1