use of io.spine.core.MessageEnvelope 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());
}
Aggregations