BusinessGlobalTransactionServiceImpl implements BusinessGlobalTransactionService { GlobalTransaction startNewGlobalTransaction(RequestGlobalTransaction rgt) { String traceId = null; if (rgt.getGTX() != null) { throw new BusinessGlobalTransactionInstableException(rgt); } traceId = trace(rgt); GlobalTransaction globalTransaction = GlobalTransaction.create(rgt.getName(), traceId); if (this.isSynchronizedVote(rgt)) { globalTransaction.setStatus(GlobalTransaction.GlobalTransactionStatus.PREPARED); } else { globalTransaction.setStatus(GlobalTransaction.GlobalTransactionStatus.STARTED); } globalTransaction.setParent(rgt.getParent()); return globalTransaction; } BusinessGlobalTransactionServiceImpl(); @Autowired  BusinessGlobalTransactionServiceImpl(GlobalTransactionRepository globalTransactionRepository,
												Tracer tracer,
												ApplicationEventPublisher publisher); @Override Optional<GlobalTransaction> findGlobalTransaction(final String id); @Override GlobalTransaction participateToGlobalTransaction(Optional<RequestGlobalTransaction> orgt); @Override Optional<GlobalTransaction> retrieveGlobalTransaction(Optional<RequestGlobalTransaction> orgt);  }
@Test(expected = BusinessGlobalTransactionInstableException.class) public void testStartGlobalTransactionWhenGTXNotNull() { final RequestGlobalTransaction rgt = mock(RequestGlobalTransaction.class); when(rgt.getGTX()).thenReturn(anyString()); businessGlobalTransactionServiceImplUnderTest.startNewGlobalTransaction(rgt); }
@Test public void testStartGlobalTransactionWhenSynchronizedVote() { final RequestGlobalTransaction rgt = mock(RequestGlobalTransaction.class); final InboundCommand command = mock(InboundCommand.class); final String traceId = "traceId"; final String name = "trxname"; final String parent = "parent"; final GlobalTransaction globalTransaction = mock(GlobalTransaction.class); setupStartTrx(rgt, command, traceId, name, parent, globalTransaction); when(command.getStatus()).thenReturn(InboundCommand.Status.PREPARED); GlobalTransaction result = businessGlobalTransactionServiceImplUnderTest.startNewGlobalTransaction(rgt); verify(globalTransaction).setStatus(same(GlobalTransaction.GlobalTransactionStatus.PREPARED)); verify(globalTransaction).setParent(same(parent)); assertEquals(result, globalTransaction); }
@Test public void testStartGlobalTransactionWhenNotSynchronizedVote() { final RequestGlobalTransaction rgt = mock(RequestGlobalTransaction.class); final InboundCommand command = mock(InboundCommand.class); final String traceId = "traceId"; final String name = "trxname"; final String parent = "parent"; final GlobalTransaction globalTransaction = mock(GlobalTransaction.class); setupStartTrx(rgt, command, traceId, name, parent, globalTransaction); when(command.getStatus()).thenReturn(InboundCommand.Status.STARTED); GlobalTransaction result = businessGlobalTransactionServiceImplUnderTest.startNewGlobalTransaction(rgt); verify(globalTransaction).setStatus(same(GlobalTransaction.GlobalTransactionStatus.STARTED)); verify(globalTransaction).setParent(same(parent)); assertEquals(result, globalTransaction); }