BusinessGlobalTransactionManagerImpl implements BusinessGlobalTransactionManager { @Override public void commit(GlobalTransactionStepDefinition pipeline) { Optional<RequestGlobalTransaction> orgt = globalTransactionMapper.mapTo(pipeline); Optional<GlobalTransaction> gtx = businessGlobalTransactionService.retrieveGlobalTransaction(orgt); gtx.ifPresent(globalTransaction -> { if (globalTransaction.getStatus().equals(GlobalTransaction.GlobalTransactionStatus.STARTED)) { globalTransaction.setStatus(GlobalTransaction.GlobalTransactionStatus.COMITTED); this.globalTransactionRepository.save(globalTransaction); } }); gtx.orElseThrow(() -> new BusinessGlobalTransactionNotFoundException(pipeline)); pipeline.accept(buildInnerGlobalTxStep(gtx)); } @Autowired  BusinessGlobalTransactionManagerImpl(GlobalTransactionRepository globalTransactionRepository,
			CommandOrchestrator commandOrchestrator, ApplicationEventPublisher applicationEventPublisher,
			BubbleCache bubbleCache , BusinessGlobalTransactionService businessGlobalTransactionService , GlobalTransactionMapper globalTransactionMapper, TransactionUtilities utilities); @Override void begin(GlobalTransactionStepDefinition pipeline); @Override void commit(GlobalTransactionStepDefinition pipeline);  }
@Test public void testCommitWhenGlobalTxStarted() { when(mockBusinessGlobalTransactionService.retrieveGlobalTransaction(Optional.of(requestGlobalTransaction))).thenReturn(Optional.of(globalTransaction)); when(globalTransaction.getStatus()).thenReturn(GlobalTransaction.GlobalTransactionStatus.STARTED); businessGlobalTransactionManagerImplUnderTest.commit(pipeline); verify(globalTransaction).setStatus(same(GlobalTransaction.GlobalTransactionStatus.COMITTED)); verify(mockGlobalTransactionRepository).save(same(globalTransaction)); verify(pipeline).accept(any()); }
@Test public void testCommitWhenGlobalTxNotStarted() { when(mockBusinessGlobalTransactionService.retrieveGlobalTransaction(Optional.of(requestGlobalTransaction))).thenReturn(Optional.of(globalTransaction)); when(globalTransaction.getStatus()).thenReturn(GlobalTransaction.GlobalTransactionStatus.COMITTED); businessGlobalTransactionManagerImplUnderTest.commit(pipeline); verify(globalTransaction, never()).setStatus(same(GlobalTransaction.GlobalTransactionStatus.COMITTED)); verify(mockGlobalTransactionRepository, never()).save(same(globalTransaction)); verify(pipeline).accept(any()); }
@Test(expected = BusinessGlobalTransactionNotFoundException.class) public void testCommitWhenGlobalTxNotFound() { when(mockBusinessGlobalTransactionService.retrieveGlobalTransaction(Optional.of(requestGlobalTransaction))).thenReturn(Optional.empty()); businessGlobalTransactionManagerImplUnderTest.commit(pipeline); verify(globalTransaction, never()).setStatus(any()); verify(mockGlobalTransactionRepository, never()).save(any(GlobalTransaction.class)); verify(pipeline, never()).accept(any()); }