BusinessLocalTransactionManagerImpl implements BusinessLocalTransactionManager { @Override public void rollBack( LocalTransactionStepDefinition<? extends BaseTransactionEvent> localTransactionStepDefinition) { Optional<GlobalTransaction> globalTransaction = this.getGlobalTransaction(localTransactionStepDefinition); if (localTransactionStepDefinition.getIn().getClass().equals(ErrorLocalOccured.class)) { List<LocalTransaction> localTransactions = globalTransaction.map(gtx -> getLocalTransaction(gtx.getId(), localTransactionStepDefinition.getMeta().getTransactionName())).get(); if (localTransactions != null) { localTransactions.forEach(ltx -> markAsRollbacked(ltx,localTransactionStepDefinition)); } } else { Optional<LocalTransaction> localTransaction = globalTransaction.map(gtx -> getLocalTransaction(gtx.getId(), localTransactionStepDefinition.getMeta().getTransactionName(), localTransactionStepDefinition.getBusinessKey())).orElseGet(() -> Optional.empty()); localTransaction.ifPresent(ltx -> markAsRollbacked(ltx,localTransactionStepDefinition)); } } BusinessLocalTransactionManagerImpl(GlobalTransactionRepository globalTransactionRepository,
			CommandOrchestrator commandOrchestrator, ApplicationEventPublisher applicationEventPublisher,
			BubbleCache bubbleCache, TransactionUtilities txUtilities); @Override void begin(final LocalTransactionStepDefinition localTransactionStepDefinition); @Override void commit(
			final LocalTransactionStepDefinition<? extends BaseTransactionEvent> localTransactionStepDefinition); @Override void rollBack(
			LocalTransactionStepDefinition<? extends BaseTransactionEvent> localTransactionStepDefinition); @Override Optional<GlobalTransaction> findGlobalTransaction(final String GTX);  }
@Test public void testRollBack() { final LocalTransactionStepDefinition localTransactionStepDefinition = mock(LocalTransactionStepDefinition.class); final GlobalTransaction globalTransaction = mock(GlobalTransaction.class); when(localTransactionStepDefinition.getMeta()).thenReturn(new WorkerMeta("XXX")); doReturn(Optional.of(globalTransaction)).when(businessLocalTransactionManagerImplUnderTest).getGlobalTransaction(localTransactionStepDefinition); LocalTransaction localTransaction = mock(LocalTransaction.class); doNothing().when(businessLocalTransactionManagerImplUnderTest).markAsRollbacked(localTransaction, localTransactionStepDefinition); when(localTransactionStepDefinition.getIn()).thenReturn(new ErrorOccured()); doReturn(Optional.of(localTransaction)).when(businessLocalTransactionManagerImplUnderTest).getLocalTransaction(anyString(),anyString(),Optional.ofNullable(any(ArrayList.class))); businessLocalTransactionManagerImplUnderTest.rollBack(localTransactionStepDefinition); }