SendMessageAction extends AbstractTestAction implements Completable { public List<MessageProcessor> getMessageProcessors() { return messageProcessors; } SendMessageAction(SendMessageActionBuilder<?, ?> builder); @Override void doExecute(final TestContext context); @Override boolean isDisabled(TestContext context); @Override boolean isDone(TestContext context); Endpoint getOrCreateEndpoint(TestContext context); Endpoint getEndpoint(); List<VariableExtractor> getVariableExtractors(); List<MessageProcessor> getMessageProcessors(); MessageContentBuilder getMessageBuilder(); boolean isForkMode(); String getMessageType(); DataDictionary<?> getDataDictionary(); String getEndpointUri();  }
@Test public void testWithExplicitAndGlobalDataDictionary() { PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder(); messageBuilder.setPayloadData("<TestRequest><Message>?</Message></TestRequest>"); final Message controlMessage = new DefaultMessage("<TestRequest><Message>Hello Citrus!</Message></TestRequest>"); DataDictionary<String> dictionary = Mockito.mock(DataDictionary.class); DataDictionary<String> globalDictionary = Mockito.mock(DataDictionary.class); reset(endpoint, producer, endpointConfiguration); when(dictionary.getDirection()).thenReturn(MessageDirection.OUTBOUND); when(globalDictionary.getDirection()).thenReturn(MessageDirection.OUTBOUND); when(dictionary.isGlobalScope()).thenReturn(false); when(globalDictionary.isGlobalScope()).thenReturn(true); doAnswer(invocationOnMock -> { Message message = invocationOnMock.getArgument(0); message.setPayload("<TestRequest><Message>Hello World!</Message></TestRequest>"); return null; }).when(globalDictionary).process(any(Message.class), eq(context)); doAnswer(invocationOnMock -> { Message message = invocationOnMock.getArgument(0); message.setPayload("<TestRequest><Message>Hello Citrus!</Message></TestRequest>"); return null; }).when(dictionary).process(any(Message.class), eq(context)); when(endpoint.createProducer()).thenReturn(producer); when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration); doAnswer(invocation -> { validateMessageToSend(invocation.getArgument(0), controlMessage); return null; }).when(producer).send(any(Message.class), any(TestContext.class)); when(endpoint.getActor()).thenReturn(null); context.getMessageProcessors().setMessageProcessors(Collections.singletonList(globalDictionary)); SendMessageAction sendAction = new SendMessageAction.Builder() .endpoint(endpoint) .message(messageBuilder) .dictionary(dictionary) .build(); sendAction.execute(context); }
@Test public void testWithGlobalDataDictionary() { PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder(); messageBuilder.setPayloadData("<TestRequest><Message>?</Message></TestRequest>"); final Message controlMessage = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>"); DataDictionary<String> inboundDictionary = Mockito.mock(DataDictionary.class); DataDictionary<String> outboundDictionary = Mockito.mock(DataDictionary.class); reset(endpoint, producer, endpointConfiguration); when(inboundDictionary.getDirection()).thenReturn(MessageDirection.INBOUND); when(outboundDictionary.getDirection()).thenReturn(MessageDirection.OUTBOUND); when(inboundDictionary.isGlobalScope()).thenReturn(true); when(outboundDictionary.isGlobalScope()).thenReturn(true); doAnswer(invocationOnMock -> { Message message = invocationOnMock.getArgument(0); message.setPayload("<TestRequest><Message>Hello World!</Message></TestRequest>"); return null; }).when(outboundDictionary).process(any(Message.class), eq(context)); doThrow(new CitrusRuntimeException("Unexpected call of inbound data dictionary")) .when(inboundDictionary).process(any(Message.class), eq(context)); when(endpoint.createProducer()).thenReturn(producer); when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration); doAnswer(invocation -> { validateMessageToSend(invocation.getArgument(0), controlMessage); return null; }).when(producer).send(any(Message.class), any(TestContext.class)); when(endpoint.getActor()).thenReturn(null); context.getMessageProcessors().setMessageProcessors(Arrays.asList(inboundDictionary, outboundDictionary)); SendMessageAction sendAction = new SendMessageAction.Builder() .endpoint(endpoint) .message(messageBuilder) .build(); sendAction.execute(context); }