CommandOrchestratorImpl implements CommandOrchestrator { OutboundCommand commandMapper(BaseTransactionCommand baseTransactionCommand){ BubbleMessage bubbleMessage = bubbleCache.getBubble(baseTransactionCommand.getId()).get(); String payload = null; try { payload = mapper.writeValueAsString(baseTransactionCommand.getPayload()); } catch (JsonProcessingException e) { throw new DecoderException(e.getMessage()); } return OutboundCommand.builder() .additionalHeaders(baseTransactionCommand.getHeader()) .payload(payload) .subject(baseTransactionCommand.getSubject()) .destination(baseTransactionCommand.getDestination()) .gTX(bubbleMessage.getGLTX()) .pGTX(bubbleMessage.getPGTX()) .fLTX(bubbleMessage.getFLTX()) .lTX(bubbleMessage.getLTX()) .trace(bubbleMessage.getTraceId()) .build(); } @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 testCommandMapper() throws JsonProcessingException { final BaseTransactionCommand baseTransactionCommand = mock(BaseTransactionCommand.class); final BubbleMessage bubbleMessage = mock(BubbleMessage.class); final String payload= "somepayload"; when(mockBubbleCache.getBubble(baseTransactionCommand.getId())).thenReturn(Optional.of(bubbleMessage)); when(mockMapper.writeValueAsString(baseTransactionCommand.getPayload())).thenReturn(payload); final OutboundCommand result = commandOrchestratorImplUnderTest.commandMapper(baseTransactionCommand); assertEquals(payload, result.getPayload()); }
@Test(expected = DecoderException.class) public void testCommandMapperWhenEsception() throws JsonProcessingException { final BaseTransactionCommand baseTransactionCommand = mock(BaseTransactionCommand.class); final BubbleMessage bubbleMessage = mock(BubbleMessage.class); final JsonProcessingException exception = mock(JsonProcessingException.class); when(mockBubbleCache.getBubble(baseTransactionCommand.getId())).thenReturn(Optional.of(bubbleMessage)); when(mockMapper.writeValueAsString(baseTransactionCommand.getPayload())).thenThrow(exception); final OutboundCommand result = commandOrchestratorImplUnderTest.commandMapper(baseTransactionCommand); }