Search in sources :

Example 1 with FailingAggregateRepository

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

the class AggregateRepositoryShould method log_error_when_event_reaction_fails.

@Test
public void log_error_when_event_reaction_fails() {
    final FailingAggregateRepository repository = new FailingAggregateRepository();
    boundedContext.register(repository);
    final TestEventFactory factory = TestEventFactory.newInstance(getClass());
    // Passing negative float value should cause an exception.
    final EventEnvelope envelope = EventEnvelope.of(factory.createEvent(FloatValue.newBuilder().setValue(-412.0f).build()));
    boundedContext.getEventBus().post(envelope.getOuterObject());
    assertTrue(repository.isErrorLogged());
    final RuntimeException lastException = repository.getLastException();
    assertTrue(lastException instanceof HandlerMethodFailedException);
    final HandlerMethodFailedException methodFailedException = (HandlerMethodFailedException) lastException;
    assertEquals(envelope.getMessage(), methodFailedException.getDispatchedMessage());
    assertEquals(envelope.getEventContext(), methodFailedException.getMessageContext());
    final MessageEnvelope lastErrorEnvelope = repository.getLastErrorEnvelope();
    assertNotNull(lastErrorEnvelope);
    assertTrue(lastErrorEnvelope instanceof EventEnvelope);
    assertEquals(envelope.getMessage(), lastErrorEnvelope.getMessage());
}
Also used : EventEnvelope(io.spine.core.EventEnvelope) FailingAggregateRepository(io.spine.server.aggregate.given.AggregateRepositoryTestEnv.FailingAggregateRepository) TestEventFactory(io.spine.server.command.TestEventFactory) HandlerMethodFailedException(io.spine.server.model.HandlerMethodFailedException) MessageEnvelope(io.spine.core.MessageEnvelope) Test(org.junit.Test)

Example 2 with FailingAggregateRepository

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

the class AggregateRepositoryShould method not_pass_command_rejection_to_onError.

@Test
public void not_pass_command_rejection_to_onError() {
    final FailingAggregateRepository repository = new FailingAggregateRepository();
    boundedContext.register(repository);
    final TestActorRequestFactory requestFactory = TestActorRequestFactory.newInstance(getClass());
    // Passing negative long value to `FailingAggregate` should cause a rejection.
    final CommandEnvelope ce = CommandEnvelope.of(requestFactory.createCommand(UInt64Value.newBuilder().setValue(-100_000_000L).build()));
    boundedContext.getCommandBus().post(ce.getCommand(), StreamObservers.<Ack>noOpObserver());
    assertFalse(repository.isErrorLogged());
}
Also used : TestActorRequestFactory(io.spine.client.TestActorRequestFactory) FailingAggregateRepository(io.spine.server.aggregate.given.AggregateRepositoryTestEnv.FailingAggregateRepository) CommandEnvelope(io.spine.core.CommandEnvelope) Test(org.junit.Test)

Aggregations

FailingAggregateRepository (io.spine.server.aggregate.given.AggregateRepositoryTestEnv.FailingAggregateRepository)2 Test (org.junit.Test)2 TestActorRequestFactory (io.spine.client.TestActorRequestFactory)1 CommandEnvelope (io.spine.core.CommandEnvelope)1 EventEnvelope (io.spine.core.EventEnvelope)1 MessageEnvelope (io.spine.core.MessageEnvelope)1 TestEventFactory (io.spine.server.command.TestEventFactory)1 HandlerMethodFailedException (io.spine.server.model.HandlerMethodFailedException)1