Thanks…
Having a challenge with mockito and some sample code resurrecting saga lifecycle.below seems more like infrastructure test to get a saga going vs Saga functionality test…cannot get same instances injected by spring and autowired in the unit test to be same hence get zero invocations and cannot verify…also question is where to do a setCommandBus on saga in the below lifecycle as it may not be possible…any ideas
@Mock CommandBus commandBus;
public test() {
final String randomAssociationValue = UUID.randomUUID().toString();
EventListener listener = mock(EventListener.class);
eventBus.subscribe(listener);
MyEventHandlerSaga saga = new TransactionTemplate(transactionManager)
.execute(new TransactionCallback() {
@Override
public MyEventHandlerSaga doInTransaction(TransactionStatus status) {
eventBus.publish(new StartingEvent(this, randomAssociationValue));
Set actualResult =
repository.find(MyEventHandlerSaga.class,
TestUtils.setOf(new AssociationValue(“association”,
randomAssociationValue)));
assertEquals(1, actualResult.size());
return actualResult.iterator().next();
}
});
ArgumentCaptor argument = ArgumentCaptor.forClass(MyCommand.class);
verify(commandBus).dispatch(argument.capture());//This commandBus is not the same as the one in the Saga and injected via spring hence get zero invocations…Can this Mock commandBus be injected in the above code by setCommandBus method on a Saga…cannot see where to to a setCommandBus on the Saga above…based on the lifecycle and state of the sage in the event publishing lifecycle.
assertEquals(randomAssociationValue, argument.getValue().getId());
}
Any other ideas…any very simple saga test example or insight which intercepts events and generates a command would be very valuable.
Thanks…