CommandOrchestratorImpl implements CommandOrchestrator { @Override public void prepare(BaseTransactionCommand command) { OutboundCommand obc = this.commandMapper(command); obc.setStatus(OutboundCommand.Status.PREPARED); AbstractCommand cmd = this.setCommandSource(obc); txLogger.logTransactionState(txstatus -> log.info( "Transaction {} for Prepared OutboundCommand: {}", txstatus, txLogger.printJsonObject(cmd))); this.receiveCommand( cmd, (meta) -> this.publisher.publishEvent(new OutboundCommandPrepared(obc.buildMeta())) ); } @Autowired  CommandOrchestratorImpl(
        final CommandRepository commandRepository,
        final ApplicationEventPublisher publisher,
        final BubbleCache bubbleCache,
        final ObjectMapper mapper,
        final Environment environment,
        final KermossTxLogger txLogger
    ); @Override void receive(final InboundCommand command); @Override void receive(final OutboundCommand command); @Override void receive(BaseTransactionCommand command); @Override void prepare(BaseTransactionCommand command); @Override void prepare(InboundCommand command); @Override boolean isInboundCommandExist(String refId); @Override boolean isInboundCommandWithStatusExist(String refId, InboundCommand.Status status); @Override Optional<P> retreive(String eventId, Class<P> target);  }
@Test public void testPrepareBaseTransactionCommand() throws JsonProcessingException { final BaseTransactionCommand command = mock(BaseTransactionCommand.class); final AbstractCommand abstractCommand = mock(AbstractCommand.class); ArgumentCaptor<OutboundCommand> commandArgumentCaptor = ArgumentCaptor.forClass(OutboundCommand.class); BubbleMessage message = mock(BubbleMessage.class); when(mockBubbleCache.getBubble(anyString())).thenReturn(Optional.of(message)); when(mockMapper.writeValueAsString(anyString())).thenReturn(PAYLOAD); when(abstractCommand.buildMeta()).thenReturn(mockCommandMeta); when(mockCommandRepository.save(any(AbstractCommand.class))).thenReturn(abstractCommand); when(mockEnvironment.getProperty(same("kermoss.serviceName"), anyString())).thenReturn("source"); commandOrchestratorImplUnderTest.prepare(command); verify(mockCommandRepository).save(commandArgumentCaptor.capture()); OutboundCommand mappedCommand = commandArgumentCaptor.getValue(); verify(mockPublisher).publishEvent(any(OutboundCommandStarted.class)); Assert.assertEquals(mappedCommand.getPayload(), PAYLOAD); Assert.assertEquals(mappedCommand.getSource(), "source"); Assert.assertEquals(mappedCommand.getStatus(), OutboundCommand.Status.PREPARED); verify(mockPublisher).publishEvent(any(OutboundCommandPrepared.class)); }
@Test public void testPrepareInboundCommand() { final InboundCommand command = mock(InboundCommand.class); ArgumentCaptor<InboundCommand> commandArgumentCaptor = ArgumentCaptor.forClass(InboundCommand.class); BubbleMessage message = mock(BubbleMessage.class); when(mockBubbleCache.getBubble(anyString())).thenReturn(Optional.of(message)); when(command.buildMeta()).thenReturn(mockCommandMeta); when(mockCommandRepository.save(any(AbstractCommand.class))).thenReturn(command); doCallRealMethod().when(command).setStatus(InboundCommand.Status.PREPARED); doCallRealMethod().when(command).getStatus(); commandOrchestratorImplUnderTest.prepare(command); verify(mockPublisher).publishEvent(any(InboundCommandStarted.class)); Assert.assertEquals(command.getStatus(), InboundCommand.Status.PREPARED); verify(mockPublisher).publishEvent(any(InboundCommandPrepared.class)); }