@Test
@DirtiesContext
public void testAsyncTransactionalSagaManagerWiring() throws InterruptedException {
// this part should prove correct autowiring of the saga manager
AsyncAnnotatedSagaManager sagaManager = beanFactory.getBean("asyncTransactionalSagaManager",
AsyncAnnotatedSagaManager.class);
assertNotNull(sagaManager);
when(sagaFactory.supports(StubSaga.class)).thenReturn(true);
when(sagaFactory.createSaga(StubSaga.class)).thenReturn(new StubSaga());
String identifier = UUID.randomUUID().toString();
final GenericDomainEventMessage<SimpleEvent> event = new GenericDomainEventMessage<SimpleEvent>(identifier,
(long) 0,
new SimpleEvent(
identifier),
MetaData.emptyInstance());
sagaManager.handle(event);
sagaManager.unsubscribe();
verify(sagaFactory).createSaga(eq(StubSaga.class));
sagaManager.stop();
verify(correlationDataProvider).correlationDataFor(event);
assertEquals("Saga was never stored in the saga repository",
1L, entityManager.createQuery("SELECT count(se) FROM SagaEntry se").getSingleResult());