@Test
@DirtiesContext
public void testSagaManagerWiring() {
// this part should prove correct autowiring of the saga manager
SagaManager sagaManager = beanFactory.getBean("sagaManager", SagaManager.class);
assertNotNull(sagaManager);
// This type is found using component scanning
when(sagaFactory.supports(StubSaga.class)).thenReturn(true);
when(sagaFactory.createSaga(any(Class.class))).thenAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
return ((Class) invocation.getArguments()[0]).newInstance();
}
});
String identifier = UUID.randomUUID().toString();
final GenericDomainEventMessage<SimpleEvent> event = new GenericDomainEventMessage<SimpleEvent>(identifier,
(long) 0,
new SimpleEvent(
identifier),
MetaData.emptyInstance());
sagaManager.handle(event);
verify(correlationDataProvider, times(2)).correlationDataFor(event);
verify(sagaFactory).createSaga(StubSaga.class);
}