How to use PayloadTemplateMessageBuilder method of com.consol.citrus.actions.SendMessageAction class

Best Citrus code snippet using com.consol.citrus.actions.SendMessageAction.PayloadTemplateMessageBuilder

Source:SendMessageTestDesignerTest.java Github

copy

Full Screen

...28import com.consol.citrus.message.MessageType;29import com.consol.citrus.report.TestActionListeners;30import com.consol.citrus.testng.AbstractTestNGUnitTest;31import com.consol.citrus.validation.builder.AbstractMessageContentBuilder;32import com.consol.citrus.validation.builder.PayloadTemplateMessageBuilder;33import com.consol.citrus.validation.builder.StaticMessageContentBuilder;34import com.consol.citrus.validation.json.JsonPathMessageConstructionInterceptor;35import com.consol.citrus.validation.json.JsonPathVariableExtractor;36import com.consol.citrus.validation.xml.XpathMessageConstructionInterceptor;37import com.consol.citrus.validation.xml.XpathPayloadVariableExtractor;38import com.consol.citrus.variable.MessageHeaderVariableExtractor;39import com.consol.citrus.variable.dictionary.DataDictionary;40import com.consol.citrus.variable.dictionary.xml.NodeMappingDataDictionary;41import org.mockito.Mockito;42import org.springframework.context.ApplicationContext;43import org.springframework.core.io.Resource;44import org.springframework.oxm.Marshaller;45import org.springframework.oxm.xstream.XStreamMarshaller;46import org.testng.Assert;47import org.testng.annotations.BeforeClass;48import org.testng.annotations.Test;49import java.io.ByteArrayInputStream;50import java.io.IOException;51import java.util.Collections;52import java.util.HashMap;53import static org.mockito.Mockito.reset;54import static org.mockito.Mockito.when;55/**56 * @author Christoph Deppisch57 */58public class SendMessageTestDesignerTest extends AbstractTestNGUnitTest {59 60 private Endpoint messageEndpoint = Mockito.mock(Endpoint.class);61 private ApplicationContext applicationContextMock = Mockito.mock(ApplicationContext.class);62 private Resource resource = Mockito.mock(Resource.class);63 private XStreamMarshaller marshaller = new XStreamMarshaller();64 @BeforeClass65 public void prepareMarshaller() {66 marshaller.getXStream().processAnnotations(TestRequest.class);67 }68 @Test69 public void testSendBuilderWithMessageInstance() {70 final MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {71 @Override72 public void configure() {73 send(messageEndpoint)74 .message(new DefaultMessage("Foo").setHeader("operation", "foo"))75 .header("additional", "additionalValue");76 }77 };78 builder.configure();79 final TestCase test = builder.getTestCase();80 Assert.assertEquals(test.getActionCount(), 1);81 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);82 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), SendMessageAction.class);83 84 final SendMessageAction action = (SendMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();85 Assert.assertEquals(action.getName(), "send");86 87 Assert.assertEquals(action.getEndpoint(), messageEndpoint);88 Assert.assertEquals(action.getMessageBuilder().getClass(), StaticMessageContentBuilder.class);89 90 final StaticMessageContentBuilder messageBuilder = (StaticMessageContentBuilder) action.getMessageBuilder();91 Assert.assertEquals(messageBuilder.getMessage().getPayload(String.class), "Foo");92 Assert.assertEquals(messageBuilder.getMessage().getHeader("operation"), "foo");93 Assert.assertEquals(messageBuilder.getMessageHeaders().get("additional"), "additionalValue");94 }95 @Test96 public void testSendBuilderWithObjectMessageInstance() {97 final Message message = new DefaultMessage(10).setHeader("operation", "foo");98 final MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {99 @Override100 public void configure() {101 send(messageEndpoint)102 .message(message);103 }104 };105 builder.configure();106 final TestCase test = builder.getTestCase();107 Assert.assertEquals(test.getActionCount(), 1);108 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);109 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), SendMessageAction.class);110 final SendMessageAction action = (SendMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();111 Assert.assertEquals(action.getName(), "send");112 Assert.assertEquals(action.getEndpoint(), messageEndpoint);113 Assert.assertEquals(action.getMessageBuilder().getClass(), StaticMessageContentBuilder.class);114 final StaticMessageContentBuilder messageBuilder = (StaticMessageContentBuilder) action.getMessageBuilder();115 Assert.assertEquals(messageBuilder.getMessage().getPayload(), 10);116 Assert.assertEquals(messageBuilder.getMessageHeaders().size(), 0L);117 Assert.assertEquals(messageBuilder.getMessage().getHeaders().size(), message.getHeaders().size());118 Assert.assertEquals(messageBuilder.getMessage().getHeader(MessageHeaders.ID), message.getHeader(MessageHeaders.ID));119 Assert.assertEquals(messageBuilder.getMessage().getHeader("operation"), "foo");120 final Message constructed = messageBuilder.buildMessageContent(new TestContext(), MessageType.PLAINTEXT.name());121 Assert.assertEquals(constructed.getHeaders().size(), message.getHeaders().size() + 1);122 Assert.assertEquals(constructed.getHeader("operation"), "foo");123 Assert.assertEquals(constructed.getHeader(MessageHeaders.MESSAGE_TYPE), MessageType.PLAINTEXT.name());124 Assert.assertNotEquals(constructed.getHeader(MessageHeaders.ID), message.getHeader(MessageHeaders.ID));125 }126 @Test127 public void testSendBuilderWithObjectMessageInstanceAdditionalHeader() {128 final Message message = new DefaultMessage(10).setHeader("operation", "foo");129 final MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {130 @Override131 public void configure() {132 send(messageEndpoint)133 .message(message)134 .header("additional", "new");135 }136 };137 builder.configure();138 final TestCase test = builder.getTestCase();139 Assert.assertEquals(test.getActionCount(), 1);140 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);141 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), SendMessageAction.class);142 final SendMessageAction action = (SendMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();143 Assert.assertEquals(action.getName(), "send");144 Assert.assertEquals(action.getEndpoint(), messageEndpoint);145 Assert.assertEquals(action.getMessageBuilder().getClass(), StaticMessageContentBuilder.class);146 final StaticMessageContentBuilder messageBuilder = (StaticMessageContentBuilder) action.getMessageBuilder();147 Assert.assertEquals(messageBuilder.getMessage().getPayload(), 10);148 Assert.assertEquals(messageBuilder.getMessageHeaders().size(), 1L);149 Assert.assertEquals(messageBuilder.getMessageHeaders().get("additional"), "new");150 Assert.assertEquals(messageBuilder.getMessage().getHeaders().size(), message.getHeaders().size());151 Assert.assertEquals(messageBuilder.getMessage().getHeader(MessageHeaders.ID), message.getHeader(MessageHeaders.ID));152 Assert.assertEquals(messageBuilder.getMessage().getHeader("operation"), "foo");153 final Message constructed = messageBuilder.buildMessageContent(new TestContext(), MessageType.PLAINTEXT.name());154 Assert.assertEquals(constructed.getHeaders().size(), message.getHeaders().size() + 2);155 Assert.assertEquals(constructed.getHeader("operation"), "foo");156 Assert.assertEquals(constructed.getHeader("additional"), "new");157 Assert.assertEquals(constructed.getHeader(MessageHeaders.MESSAGE_TYPE), MessageType.PLAINTEXT.name());158 }159 @Test160 public void testSendBuilderWithPayloadModel() {161 reset(applicationContextMock);162 when(applicationContextMock.getBean(TestActionListeners.class)).thenReturn(new TestActionListeners());163 when(applicationContextMock.getBeansOfType(SequenceBeforeTest.class)).thenReturn(new HashMap<>());164 when(applicationContextMock.getBeansOfType(SequenceAfterTest.class)).thenReturn(new HashMap<>());165 when(applicationContextMock.getBeansOfType(Marshaller.class)).thenReturn(Collections.singletonMap("marshaller", marshaller));166 when(applicationContextMock.getBean(Marshaller.class)).thenReturn(marshaller);167 final MockTestDesigner builder = new MockTestDesigner(applicationContextMock, context) {168 @Override169 public void configure() {170 send(messageEndpoint)171 .payloadModel(new TestRequest("Hello Citrus!"));172 }173 };174 builder.configure();175 final TestCase test = builder.getTestCase();176 Assert.assertEquals(test.getActionCount(), 1);177 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);178 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), SendMessageAction.class);179 final SendMessageAction action = (SendMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();180 Assert.assertEquals(action.getName(), "send");181 Assert.assertEquals(action.getEndpoint(), messageEndpoint);182 Assert.assertEquals(action.getMessageBuilder().getClass(), PayloadTemplateMessageBuilder.class);183 final PayloadTemplateMessageBuilder messageBuilder = (PayloadTemplateMessageBuilder) action.getMessageBuilder();184 Assert.assertEquals(messageBuilder.getPayloadData(), "<TestRequest><Message>Hello Citrus!</Message></TestRequest>");185 Assert.assertEquals(messageBuilder.getMessageHeaders().size(), 0L);186 }187 @Test188 public void testSendBuilderWithPayloadModelExplicitMarshaller() {189 final MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {190 @Override191 public void configure() {192 send(messageEndpoint)193 .payload(new TestRequest("Hello Citrus!"), marshaller);194 }195 };196 builder.configure();197 final TestCase test = builder.getTestCase();198 Assert.assertEquals(test.getActionCount(), 1);199 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);200 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), SendMessageAction.class);201 final SendMessageAction action = (SendMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();202 Assert.assertEquals(action.getName(), "send");203 Assert.assertEquals(action.getEndpoint(), messageEndpoint);204 Assert.assertEquals(action.getMessageBuilder().getClass(), PayloadTemplateMessageBuilder.class);205 final PayloadTemplateMessageBuilder messageBuilder = (PayloadTemplateMessageBuilder) action.getMessageBuilder();206 Assert.assertEquals(messageBuilder.getPayloadData(), "<TestRequest><Message>Hello Citrus!</Message></TestRequest>");207 Assert.assertEquals(messageBuilder.getMessageHeaders().size(), 0L);208 }209 @Test210 public void testSendBuilderWithPayloadModelExplicitMarshallerName() {211 reset(applicationContextMock);212 when(applicationContextMock.getBean(TestActionListeners.class)).thenReturn(new TestActionListeners());213 when(applicationContextMock.getBeansOfType(SequenceBeforeTest.class)).thenReturn(new HashMap<>());214 when(applicationContextMock.getBeansOfType(SequenceAfterTest.class)).thenReturn(new HashMap<>());215 when(applicationContextMock.containsBean("myMarshaller")).thenReturn(true);216 when(applicationContextMock.getBean("myMarshaller")).thenReturn(marshaller);217 final MockTestDesigner builder = new MockTestDesigner(applicationContextMock, context) {218 @Override219 public void configure() {220 send(messageEndpoint)221 .payload(new TestRequest("Hello Citrus!"), "myMarshaller");222 }223 };224 builder.configure();225 final TestCase test = builder.getTestCase();226 Assert.assertEquals(test.getActionCount(), 1);227 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);228 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), SendMessageAction.class);229 final SendMessageAction action = (SendMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();230 Assert.assertEquals(action.getName(), "send");231 Assert.assertEquals(action.getEndpoint(), messageEndpoint);232 Assert.assertEquals(action.getMessageBuilder().getClass(), PayloadTemplateMessageBuilder.class);233 final PayloadTemplateMessageBuilder messageBuilder = (PayloadTemplateMessageBuilder) action.getMessageBuilder();234 Assert.assertEquals(messageBuilder.getPayloadData(), "<TestRequest><Message>Hello Citrus!</Message></TestRequest>");235 Assert.assertEquals(messageBuilder.getMessageHeaders().size(), 0L);236 }237 238 @Test239 public void testSendBuilderWithPayloadData() {240 final MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {241 @Override242 public void configure() {243 send(messageEndpoint)244 .payload("<TestRequest><Message>Hello World!</Message></TestRequest>");245 }246 };247 builder.configure();248 final TestCase test = builder.getTestCase();249 Assert.assertEquals(test.getActionCount(), 1);250 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);251 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), SendMessageAction.class);252 253 final SendMessageAction action = (SendMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();254 Assert.assertEquals(action.getName(), "send");255 256 Assert.assertEquals(action.getEndpoint(), messageEndpoint);257 Assert.assertEquals(action.getMessageBuilder().getClass(), PayloadTemplateMessageBuilder.class);258 final PayloadTemplateMessageBuilder messageBuilder = (PayloadTemplateMessageBuilder) action.getMessageBuilder();259 Assert.assertEquals(messageBuilder.getPayloadData(), "<TestRequest><Message>Hello World!</Message></TestRequest>");260 Assert.assertEquals(messageBuilder.getMessageHeaders().size(), 0L);261 }262 @Test263 public void testSendBuilderWithPayloadResource() throws IOException {264 final MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {265 @Override266 public void configure() {267 send(messageEndpoint)268 .payload(resource);269 }270 };271 272 reset(resource);273 when(resource.getInputStream()).thenReturn(new ByteArrayInputStream("somePayloadData".getBytes()));274 builder.configure();275 final TestCase test = builder.getTestCase();276 Assert.assertEquals(test.getActionCount(), 1);277 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);278 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), SendMessageAction.class);279 280 final SendMessageAction action = (SendMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();281 Assert.assertEquals(action.getName(), "send");282 283 Assert.assertEquals(action.getEndpoint(), messageEndpoint);284 Assert.assertEquals(action.getMessageBuilder().getClass(), PayloadTemplateMessageBuilder.class);285 286 final PayloadTemplateMessageBuilder messageBuilder = (PayloadTemplateMessageBuilder) action.getMessageBuilder();287 Assert.assertEquals(messageBuilder.getPayloadData(), "somePayloadData");288 Assert.assertEquals(messageBuilder.getMessageHeaders().size(), 0L);289 }290 291 @Test292 public void testSendBuilderWithEndpointName() {293 reset(applicationContextMock);294 when(applicationContextMock.getBean(TestActionListeners.class)).thenReturn(new TestActionListeners());295 when(applicationContextMock.getBeansOfType(SequenceBeforeTest.class)).thenReturn(new HashMap<>());296 when(applicationContextMock.getBeansOfType(SequenceAfterTest.class)).thenReturn(new HashMap<>());297 final MockTestDesigner builder = new MockTestDesigner(applicationContextMock, context) {298 @Override299 public void configure() {300 send("fooMessageEndpoint")301 .payload("<TestRequest><Message>Hello World!</Message></TestRequest>");302 }303 };304 builder.configure();305 final TestCase test = builder.getTestCase();306 Assert.assertEquals(test.getActionCount(), 1);307 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);308 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), SendMessageAction.class);309 310 final SendMessageAction action = (SendMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();311 Assert.assertEquals(action.getName(), "send");312 Assert.assertEquals(action.getEndpointUri(), "fooMessageEndpoint");313 }314 315 @Test316 public void testSendBuilderWithHeaders() {317 final MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {318 @Override319 public void configure() {320 send(messageEndpoint)321 .payload("<TestRequest><Message>Hello World!</Message></TestRequest>")322 .headers(Collections.singletonMap("some", "value"))323 .header("operation", "foo")324 .header("language", "eng");325 }326 };327 builder.configure();328 final TestCase test = builder.getTestCase();329 Assert.assertEquals(test.getActionCount(), 1);330 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);331 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), SendMessageAction.class);332 333 final SendMessageAction action = (SendMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();334 Assert.assertEquals(action.getName(), "send");335 336 Assert.assertEquals(action.getEndpoint(), messageEndpoint);337 Assert.assertEquals(action.getMessageBuilder().getClass(), PayloadTemplateMessageBuilder.class);338 final PayloadTemplateMessageBuilder messageBuilder = (PayloadTemplateMessageBuilder) action.getMessageBuilder();339 Assert.assertEquals(messageBuilder.getPayloadData(), "<TestRequest><Message>Hello World!</Message></TestRequest>");340 Assert.assertEquals(messageBuilder.getMessageHeaders().size(), 3L);341 Assert.assertEquals(messageBuilder.getMessageHeaders().get("some"), "value");342 Assert.assertEquals(messageBuilder.getMessageHeaders().get("operation"), "foo");343 Assert.assertEquals(messageBuilder.getMessageHeaders().get("language"), "eng");344 }345 346 @Test347 public void testSendBuilderWithHeaderData() {348 final MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {349 @Override350 public void configure() {351 send(messageEndpoint)352 .payload("<TestRequest><Message>Hello World!</Message></TestRequest>")353 .header("<Header><Name>operation</Name><Value>foo</Value></Header>");354 355 send(messageEndpoint)356 .message(new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>"))357 .header("<Header><Name>operation</Name><Value>foo</Value></Header>");358 }359 };360 builder.configure();361 final TestCase test = builder.getTestCase();362 Assert.assertEquals(test.getActionCount(), 2);363 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);364 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), SendMessageAction.class);365 Assert.assertEquals(test.getActions().get(1).getClass(), DelegatingTestAction.class);366 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(1)).getDelegate().getClass(), SendMessageAction.class);367 368 SendMessageAction action = (SendMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();369 Assert.assertEquals(action.getName(), "send");370 371 Assert.assertEquals(action.getEndpoint(), messageEndpoint);372 Assert.assertEquals(action.getMessageBuilder().getClass(), PayloadTemplateMessageBuilder.class);373 final PayloadTemplateMessageBuilder messageBuilder = (PayloadTemplateMessageBuilder) action.getMessageBuilder();374 Assert.assertEquals(messageBuilder.getPayloadData(), "<TestRequest><Message>Hello World!</Message></TestRequest>");375 Assert.assertEquals(messageBuilder.getMessageHeaders().size(), 0L);376 Assert.assertEquals(messageBuilder.getHeaderData().size(), 1L);377 Assert.assertEquals(messageBuilder.getHeaderData().get(0), "<Header><Name>operation</Name><Value>foo</Value></Header>");378 Assert.assertEquals(messageBuilder.getHeaderResources().size(), 0L);379 action = (SendMessageAction) ((DelegatingTestAction)test.getActions().get(1)).getDelegate();380 Assert.assertEquals(action.getName(), "send");381 Assert.assertEquals(action.getEndpoint(), messageEndpoint);382 Assert.assertEquals(action.getMessageBuilder().getClass(), StaticMessageContentBuilder.class);383 final StaticMessageContentBuilder staticMessageBuilder = (StaticMessageContentBuilder) action.getMessageBuilder();384 Assert.assertEquals(staticMessageBuilder.getMessage().getPayload(String.class), "<TestRequest><Message>Hello World!</Message></TestRequest>");385 Assert.assertEquals(staticMessageBuilder.getMessageHeaders().size(), 0L);386 Assert.assertEquals(staticMessageBuilder.getHeaderData().size(), 1L);387 Assert.assertEquals(staticMessageBuilder.getHeaderData().get(0), "<Header><Name>operation</Name><Value>foo</Value></Header>");388 Assert.assertEquals(staticMessageBuilder.getHeaderResources().size(), 0L);389 }390 @Test391 public void testSendBuilderWithMultipleHeaderData() {392 final MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {393 @Override394 public void configure() {395 send(messageEndpoint)396 .payload("<TestRequest><Message>Hello World!</Message></TestRequest>")397 .header("<Header><Name>operation</Name><Value>foo1</Value></Header>")398 .header("<Header><Name>operation</Name><Value>foo2</Value></Header>");399 send(messageEndpoint)400 .message(new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>"))401 .header("<Header><Name>operation</Name><Value>foo1</Value></Header>")402 .header("<Header><Name>operation</Name><Value>foo2</Value></Header>");403 }404 };405 builder.configure();406 final TestCase test = builder.getTestCase();407 Assert.assertEquals(test.getActionCount(), 2);408 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);409 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), SendMessageAction.class);410 Assert.assertEquals(test.getActions().get(1).getClass(), DelegatingTestAction.class);411 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(1)).getDelegate().getClass(), SendMessageAction.class);412 SendMessageAction action = (SendMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();413 Assert.assertEquals(action.getName(), "send");414 Assert.assertEquals(action.getEndpoint(), messageEndpoint);415 Assert.assertEquals(action.getMessageBuilder().getClass(), PayloadTemplateMessageBuilder.class);416 final PayloadTemplateMessageBuilder messageBuilder = (PayloadTemplateMessageBuilder) action.getMessageBuilder();417 Assert.assertEquals(messageBuilder.getPayloadData(), "<TestRequest><Message>Hello World!</Message></TestRequest>");418 Assert.assertEquals(messageBuilder.getMessageHeaders().size(), 0L);419 Assert.assertEquals(messageBuilder.getHeaderData().size(), 2L);420 Assert.assertEquals(messageBuilder.getHeaderData().get(0), "<Header><Name>operation</Name><Value>foo1</Value></Header>");421 Assert.assertEquals(messageBuilder.getHeaderData().get(1), "<Header><Name>operation</Name><Value>foo2</Value></Header>");422 Assert.assertEquals(messageBuilder.getHeaderResources().size(), 0L);423 action = (SendMessageAction) ((DelegatingTestAction)test.getActions().get(1)).getDelegate();424 Assert.assertEquals(action.getName(), "send");425 Assert.assertEquals(action.getEndpoint(), messageEndpoint);426 Assert.assertEquals(action.getMessageBuilder().getClass(), StaticMessageContentBuilder.class);427 final StaticMessageContentBuilder staticMessageBuilder = (StaticMessageContentBuilder) action.getMessageBuilder();428 Assert.assertEquals(staticMessageBuilder.getMessage().getPayload(String.class), "<TestRequest><Message>Hello World!</Message></TestRequest>");429 Assert.assertEquals(staticMessageBuilder.getMessageHeaders().size(), 0L);430 Assert.assertEquals(staticMessageBuilder.getHeaderData().size(), 2L);431 Assert.assertEquals(staticMessageBuilder.getHeaderData().get(0), "<Header><Name>operation</Name><Value>foo1</Value></Header>");432 Assert.assertEquals(staticMessageBuilder.getHeaderData().get(1), "<Header><Name>operation</Name><Value>foo2</Value></Header>");433 Assert.assertEquals(staticMessageBuilder.getHeaderResources().size(), 0L);434 }435 436 @Test437 public void testSendBuilderWithHeaderDataResource() throws IOException {438 final MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {439 @Override440 public void configure() {441 send(messageEndpoint)442 .payload("<TestRequest><Message>Hello World!</Message></TestRequest>")443 .header(resource);444 445 send(messageEndpoint)446 .message(new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>"))447 .header(resource);448 }449 };450 451 reset(resource);452 when(resource.getInputStream()).thenReturn(new ByteArrayInputStream("someHeaderData".getBytes()))453 .thenReturn(new ByteArrayInputStream("otherHeaderData".getBytes()));454 builder.configure();455 final TestCase test = builder.getTestCase();456 Assert.assertEquals(test.getActionCount(), 2);457 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);458 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), SendMessageAction.class);459 Assert.assertEquals(test.getActions().get(1).getClass(), DelegatingTestAction.class);460 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(1)).getDelegate().getClass(), SendMessageAction.class);461 462 SendMessageAction action = (SendMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();463 Assert.assertEquals(action.getName(), "send");464 465 Assert.assertEquals(action.getEndpoint(), messageEndpoint);466 Assert.assertEquals(action.getMessageBuilder().getClass(), PayloadTemplateMessageBuilder.class);467 final PayloadTemplateMessageBuilder messageBuilder = (PayloadTemplateMessageBuilder) action.getMessageBuilder();468 Assert.assertEquals(messageBuilder.getPayloadData(), "<TestRequest><Message>Hello World!</Message></TestRequest>");469 Assert.assertEquals(messageBuilder.getMessageHeaders().size(), 0L);470 Assert.assertEquals(messageBuilder.getHeaderData().size(), 1L);471 Assert.assertEquals(messageBuilder.getHeaderData().get(0), "someHeaderData");472 Assert.assertEquals(messageBuilder.getHeaderResources().size(), 0L);473 action = (SendMessageAction) ((DelegatingTestAction)test.getActions().get(1)).getDelegate();474 Assert.assertEquals(action.getName(), "send");475 Assert.assertEquals(action.getEndpoint(), messageEndpoint);476 Assert.assertEquals(action.getMessageBuilder().getClass(), StaticMessageContentBuilder.class);477 final StaticMessageContentBuilder staticMessageBuilder = (StaticMessageContentBuilder) action.getMessageBuilder();478 Assert.assertEquals(staticMessageBuilder.getMessage().getPayload(String.class), "<TestRequest><Message>Hello World!</Message></TestRequest>");479 Assert.assertEquals(staticMessageBuilder.getMessageHeaders().size(), 0L);480 Assert.assertEquals(staticMessageBuilder.getHeaderData().size(), 1L);481 Assert.assertEquals(staticMessageBuilder.getHeaderData().get(0), "otherHeaderData");...

Full Screen

Full Screen

Source:SendMessageActionTest.java Github

copy

Full Screen

...22import com.consol.citrus.exceptions.CitrusRuntimeException;23import com.consol.citrus.message.*;24import com.consol.citrus.messaging.Producer;25import com.consol.citrus.testng.AbstractTestNGUnitTest;26import com.consol.citrus.validation.builder.PayloadTemplateMessageBuilder;27import com.consol.citrus.validation.json.*;28import com.consol.citrus.validation.script.GroovyScriptMessageBuilder;29import com.consol.citrus.validation.xml.*;30import com.consol.citrus.variable.MessageHeaderVariableExtractor;31import com.consol.citrus.variable.VariableExtractor;32import org.mockito.Mockito;33import org.mockito.invocation.InvocationOnMock;34import org.mockito.stubbing.Answer;35import org.testng.Assert;36import org.testng.annotations.Test;37import java.io.UnsupportedEncodingException;38import java.util.*;39import static org.mockito.Mockito.*;40/**41 * @author Christoph Deppisch42 */43public class SendMessageActionTest extends AbstractTestNGUnitTest {44 private Endpoint endpoint = Mockito.mock(Endpoint.class);45 private Producer producer = Mockito.mock(Producer.class);46 private EndpointConfiguration endpointConfiguration = Mockito.mock(EndpointConfiguration.class);47 48 @Test49 @SuppressWarnings("rawtypes")50 public void testSendMessageWithMessagePayloadData() {51 SendMessageAction sendAction = new SendMessageAction();52 sendAction.setEndpoint(endpoint);53 54 TestActor testActor = new TestActor();55 testActor.setName("TESTACTOR");56 57 sendAction.setActor(testActor);58 59 PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();60 messageBuilder.setPayloadData("<TestRequest><Message>Hello World!</Message></TestRequest>");61 62 sendAction.setMessageBuilder(messageBuilder);63 64 final Message controlMessage = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>");65 reset(endpoint, producer, endpointConfiguration);66 when(endpoint.createProducer()).thenReturn(producer);67 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);68 doAnswer(new Answer() {69 @Override70 public Object answer(InvocationOnMock invocation) throws Throwable {71 DomXmlMessageValidator validator = new DomXmlMessageValidator();72 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();73 validator.validateMessage(((Message)invocation.getArguments()[0]), controlMessage, context, validationContext);74 return null;75 }76 }).when(producer).send(any(Message.class), any(TestContext.class));77 when(endpoint.getActor()).thenReturn(null);78 79 sendAction.execute(context);80 }81 82 @Test83 @SuppressWarnings("rawtypes")84 public void testSendMessageWithMessagePayloadResource() {85 SendMessageAction sendAction = new SendMessageAction();86 sendAction.setEndpoint(endpoint);87 88 PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();89 messageBuilder.setPayloadResourcePath("classpath:com/consol/citrus/actions/test-request-payload.xml");90 91 sendAction.setMessageBuilder(messageBuilder);92 93 final Message controlMessage = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>");94 reset(endpoint, producer, endpointConfiguration);95 when(endpoint.createProducer()).thenReturn(producer);96 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);97 doAnswer(new Answer() {98 @Override99 public Object answer(InvocationOnMock invocation) throws Throwable {100 DomXmlMessageValidator validator = new DomXmlMessageValidator();101 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();102 validator.validateMessage(((Message)invocation.getArguments()[0]), controlMessage, context, validationContext);103 return null;104 }105 }).when(producer).send(any(Message.class), any(TestContext.class));106 when(endpoint.getActor()).thenReturn(null);107 108 sendAction.execute(context);109 }110 111 @Test112 @SuppressWarnings("rawtypes")113 public void testSendMessageWithMessageBuilderScriptData() {114 SendMessageAction sendAction = new SendMessageAction();115 sendAction.setEndpoint(endpoint);116 StringBuilder sb = new StringBuilder();117 sb.append("markupBuilder.TestRequest(){\n");118 sb.append("Message('Hello World!')\n");119 sb.append("}");120 121 GroovyScriptMessageBuilder scriptMessageBuidler = new GroovyScriptMessageBuilder();122 scriptMessageBuidler.setScriptData(sb.toString());123 124 sendAction.setMessageBuilder(scriptMessageBuidler);125 126 final Message controlMessage = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>");127 reset(endpoint, producer, endpointConfiguration);128 when(endpoint.createProducer()).thenReturn(producer);129 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);130 doAnswer(new Answer() {131 @Override132 public Object answer(InvocationOnMock invocation) throws Throwable {133 DomXmlMessageValidator validator = new DomXmlMessageValidator();134 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();135 validator.validateMessage(((Message)invocation.getArguments()[0]), controlMessage, context, validationContext);136 return null;137 }138 }).when(producer).send(any(Message.class), any(TestContext.class));139 when(endpoint.getActor()).thenReturn(null);140 141 sendAction.execute(context);142 }143 144 @Test145 @SuppressWarnings("rawtypes")146 public void testSendMessageWithMessageBuilderScriptDataVariableSupport() {147 context.setVariable("text", "Hello World!");148 149 SendMessageAction sendAction = new SendMessageAction();150 sendAction.setEndpoint(endpoint);151 StringBuilder sb = new StringBuilder();152 sb.append("markupBuilder.TestRequest(){\n");153 sb.append("Message('${text}')\n");154 sb.append("}");155 156 GroovyScriptMessageBuilder scriptMessageBuidler = new GroovyScriptMessageBuilder();157 scriptMessageBuidler.setScriptData(sb.toString());158 159 sendAction.setMessageBuilder(scriptMessageBuidler);160 161 final Message controlMessage = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>");162 reset(endpoint, producer, endpointConfiguration);163 when(endpoint.createProducer()).thenReturn(producer);164 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);165 doAnswer(new Answer() {166 @Override167 public Object answer(InvocationOnMock invocation) throws Throwable {168 DomXmlMessageValidator validator = new DomXmlMessageValidator();169 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();170 validator.validateMessage(((Message)invocation.getArguments()[0]), controlMessage, context, validationContext);171 return null;172 }173 }).when(producer).send(any(Message.class), any(TestContext.class));174 when(endpoint.getActor()).thenReturn(null);175 176 sendAction.execute(context);177 }178 179 @Test180 @SuppressWarnings("rawtypes")181 public void testSendMessageWithMessageBuilderScriptResource() {182 SendMessageAction sendAction = new SendMessageAction();183 sendAction.setEndpoint(endpoint);184 185 GroovyScriptMessageBuilder scriptMessageBuidler = new GroovyScriptMessageBuilder();186 scriptMessageBuidler.setScriptResourcePath("classpath:com/consol/citrus/actions/test-request-payload.groovy");187 188 sendAction.setMessageBuilder(scriptMessageBuidler);189 190 final Message controlMessage = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>");191 reset(endpoint, producer, endpointConfiguration);192 when(endpoint.createProducer()).thenReturn(producer);193 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);194 doAnswer(new Answer() {195 @Override196 public Object answer(InvocationOnMock invocation) throws Throwable {197 DomXmlMessageValidator validator = new DomXmlMessageValidator();198 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();199 validator.validateMessage(((Message)invocation.getArguments()[0]), controlMessage, context, validationContext);200 return null;201 }202 }).when(producer).send(any(Message.class), any(TestContext.class));203 when(endpoint.getActor()).thenReturn(null);204 205 sendAction.execute(context);206 }207 208 @Test209 @SuppressWarnings("rawtypes")210 public void testSendMessageWithMessagePayloadDataVariablesSupport() {211 SendMessageAction sendAction = new SendMessageAction();212 sendAction.setEndpoint(endpoint);213 214 PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();215 messageBuilder.setPayloadData("<TestRequest><Message>${myText}</Message></TestRequest>");216 217 sendAction.setMessageBuilder(messageBuilder);218 219 context.setVariable("myText", "Hello World!");220 221 final Message controlMessage = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>");222 reset(endpoint, producer, endpointConfiguration);223 when(endpoint.createProducer()).thenReturn(producer);224 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);225 doAnswer(new Answer() {226 @Override227 public Object answer(InvocationOnMock invocation) throws Throwable {228 DomXmlMessageValidator validator = new DomXmlMessageValidator();229 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();230 validator.validateMessage(((Message)invocation.getArguments()[0]), controlMessage, context, validationContext);231 return null;232 }233 }).when(producer).send(any(Message.class), any(TestContext.class));234 when(endpoint.getActor()).thenReturn(null);235 236 sendAction.execute(context);237 }238 239 @Test240 @SuppressWarnings("rawtypes")241 public void testSendMessageWithMessagePayloadResourceVariablesSupport() {242 SendMessageAction sendAction = new SendMessageAction();243 sendAction.setEndpoint(endpoint);244 PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();245 messageBuilder.setPayloadResourcePath("classpath:com/consol/citrus/actions/test-request-payload-with-variables.xml");246 247 sendAction.setMessageBuilder(messageBuilder);248 249 context.setVariable("myText", "Hello World!");250 251 final Message controlMessage = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>");252 reset(endpoint, producer, endpointConfiguration);253 when(endpoint.createProducer()).thenReturn(producer);254 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);255 doAnswer(new Answer() {256 @Override257 public Object answer(InvocationOnMock invocation) throws Throwable {258 DomXmlMessageValidator validator = new DomXmlMessageValidator();259 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();260 validator.validateMessage(((Message)invocation.getArguments()[0]), controlMessage, context, validationContext);261 return null;262 }263 }).when(producer).send(any(Message.class), any(TestContext.class));264 when(endpoint.getActor()).thenReturn(null);265 266 sendAction.execute(context);267 }268 269 @Test270 @SuppressWarnings("rawtypes")271 public void testSendMessageWithMessagePayloadResourceFunctionsSupport() {272 SendMessageAction sendAction = new SendMessageAction();273 sendAction.setEndpoint(endpoint);274 PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();275 messageBuilder.setPayloadResourcePath("classpath:com/consol/citrus/actions/test-request-payload-with-functions.xml");276 277 sendAction.setMessageBuilder(messageBuilder);278 279 final Message controlMessage = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>");280 reset(endpoint, producer, endpointConfiguration);281 when(endpoint.createProducer()).thenReturn(producer);282 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);283 doAnswer(new Answer() {284 @Override285 public Object answer(InvocationOnMock invocation) throws Throwable {286 DomXmlMessageValidator validator = new DomXmlMessageValidator();287 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();288 validator.validateMessage(((Message)invocation.getArguments()[0]), controlMessage, context, validationContext);289 return null;290 }291 }).when(producer).send(any(Message.class), any(TestContext.class));292 when(endpoint.getActor()).thenReturn(null);293 294 sendAction.execute(context);295 }296 297 @Test298 @SuppressWarnings("rawtypes")299 public void testSendMessageOverwriteMessageElementsXPath() {300 SendMessageAction sendAction = new SendMessageAction();301 sendAction.setEndpoint(endpoint);302 PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();303 messageBuilder.setPayloadData("<TestRequest><Message>?</Message></TestRequest>");304 305 Map<String, String> overwriteElements = new HashMap<String, String>();306 overwriteElements.put("/TestRequest/Message", "Hello World!");307 308 XpathMessageConstructionInterceptor interceptor = new XpathMessageConstructionInterceptor(overwriteElements);309 messageBuilder.add(interceptor);310 311 sendAction.setMessageBuilder(messageBuilder);312 313 final Message controlMessage = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>");314 reset(endpoint, producer, endpointConfiguration);315 when(endpoint.createProducer()).thenReturn(producer);316 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);317 doAnswer(new Answer() {318 @Override319 public Object answer(InvocationOnMock invocation) throws Throwable {320 DomXmlMessageValidator validator = new DomXmlMessageValidator();321 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();322 validator.validateMessage(((Message)invocation.getArguments()[0]), controlMessage, context, validationContext);323 return null;324 }325 }).when(producer).send(any(Message.class), any(TestContext.class));326 when(endpoint.getActor()).thenReturn(null);327 328 sendAction.execute(context);329 }330 @Test331 @SuppressWarnings("rawtypes")332 public void testSendMessageOverwriteMessageElementsJsonPath() {333 SendMessageAction sendAction = new SendMessageAction();334 sendAction.setMessageType(MessageType.JSON.toString());335 sendAction.setEndpoint(endpoint);336 PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();337 messageBuilder.setPayloadData("{ \"TestRequest\": { \"Message\": \"?\" }}");338 Map<String, String> overwriteElements = new HashMap<String, String>();339 overwriteElements.put("$.TestRequest.Message", "Hello World!");340 JsonPathMessageConstructionInterceptor interceptor = new JsonPathMessageConstructionInterceptor(overwriteElements);341 messageBuilder.add(interceptor);342 sendAction.setMessageBuilder(messageBuilder);343 final Message controlMessage = new DefaultMessage("{ \"TestRequest\": { \"Message\": \"Hello World!\" }}");344 reset(endpoint, producer, endpointConfiguration);345 when(endpoint.createProducer()).thenReturn(producer);346 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);347 doAnswer(new Answer() {348 @Override349 public Object answer(InvocationOnMock invocation) throws Throwable {350 JsonTextMessageValidator validator = new JsonTextMessageValidator();351 JsonMessageValidationContext validationContext = new JsonMessageValidationContext();352 validator.validateMessage(((Message)invocation.getArguments()[0]), controlMessage, context, validationContext);353 return null;354 }355 }).when(producer).send(any(Message.class), any(TestContext.class));356 when(endpoint.getActor()).thenReturn(null);357 sendAction.execute(context);358 }359 360 @Test361 @SuppressWarnings("rawtypes")362 public void testSendMessageOverwriteMessageElementsDotNotation() {363 SendMessageAction sendAction = new SendMessageAction();364 sendAction.setEndpoint(endpoint);365 PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();366 messageBuilder.setPayloadData("<TestRequest><Message>?</Message></TestRequest>");367 368 Map<String, String> overwriteElements = new HashMap<String, String>();369 overwriteElements.put("TestRequest.Message", "Hello World!");370 371 XpathMessageConstructionInterceptor interceptor = new XpathMessageConstructionInterceptor(overwriteElements);372 messageBuilder.add(interceptor);373 374 sendAction.setMessageBuilder(messageBuilder);375 376 final Message controlMessage = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>");377 reset(endpoint, producer, endpointConfiguration);378 when(endpoint.createProducer()).thenReturn(producer);379 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);380 doAnswer(new Answer() {381 @Override382 public Object answer(InvocationOnMock invocation) throws Throwable {383 DomXmlMessageValidator validator = new DomXmlMessageValidator();384 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();385 validator.validateMessage(((Message)invocation.getArguments()[0]), controlMessage, context, validationContext);386 return null;387 }388 }).when(producer).send(any(Message.class), any(TestContext.class));389 when(endpoint.getActor()).thenReturn(null);390 391 sendAction.execute(context);392 }393 394 @Test395 @SuppressWarnings("rawtypes")396 public void testSendMessageOverwriteMessageElementsXPathWithNamespace() {397 SendMessageAction sendAction = new SendMessageAction();398 sendAction.setEndpoint(endpoint);399 PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();400 messageBuilder.setPayloadData("<ns0:TestRequest xmlns:ns0=\"http://citrusframework.org/unittest\">" +401 "<ns0:Message>?</ns0:Message></ns0:TestRequest>");402 403 Map<String, String> overwriteElements = new HashMap<String, String>();404 overwriteElements.put("/ns0:TestRequest/ns0:Message", "Hello World!");405 XpathMessageConstructionInterceptor interceptor = new XpathMessageConstructionInterceptor(overwriteElements);406 messageBuilder.add(interceptor);407 408 sendAction.setMessageBuilder(messageBuilder);409 410 final Message controlMessage = new DefaultMessage("<ns0:TestRequest xmlns:ns0=\"http://citrusframework.org/unittest\"><ns0:Message>Hello World!</ns0:Message></ns0:TestRequest>");411 reset(endpoint, producer, endpointConfiguration);412 when(endpoint.createProducer()).thenReturn(producer);413 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);414 doAnswer(new Answer() {415 @Override416 public Object answer(InvocationOnMock invocation) throws Throwable {417 DomXmlMessageValidator validator = new DomXmlMessageValidator();418 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();419 validationContext.setSchemaValidation(false);420 validator.validateMessage(((Message)invocation.getArguments()[0]), controlMessage, context, validationContext);421 return null;422 }423 }).when(producer).send(any(Message.class), any(TestContext.class));424 when(endpoint.getActor()).thenReturn(null);425 426 sendAction.execute(context);427 }428 429 @Test430 @SuppressWarnings("rawtypes")431 public void testSendMessageOverwriteMessageElementsXPathWithDefaultNamespace() {432 SendMessageAction sendAction = new SendMessageAction();433 sendAction.setEndpoint(endpoint);434 PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();435 messageBuilder.setPayloadData("<TestRequest xmlns=\"http://citrusframework.org/unittest\">" +436 "<Message>?</Message></TestRequest>");437 438 Map<String, String> overwriteElements = new HashMap<String, String>();439 overwriteElements.put("/:TestRequest/:Message", "Hello World!");440 XpathMessageConstructionInterceptor interceptor = new XpathMessageConstructionInterceptor(overwriteElements);441 messageBuilder.add(interceptor);442 443 sendAction.setMessageBuilder(messageBuilder);444 445 final Message controlMessage = new DefaultMessage("<TestRequest xmlns=\"http://citrusframework.org/unittest\"><Message>Hello World!</Message></TestRequest>");446 reset(endpoint, producer, endpointConfiguration);447 when(endpoint.createProducer()).thenReturn(producer);448 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);449 doAnswer(new Answer() {450 @Override451 public Object answer(InvocationOnMock invocation) throws Throwable {452 DomXmlMessageValidator validator = new DomXmlMessageValidator();453 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();454 validationContext.setSchemaValidation(false);455 validator.validateMessage(((Message)invocation.getArguments()[0]), controlMessage, context, validationContext);456 return null;457 }458 }).when(producer).send(any(Message.class), any(TestContext.class));459 when(endpoint.getActor()).thenReturn(null);460 461 sendAction.execute(context);462 }463 464 @Test465 @SuppressWarnings("rawtypes")466 public void testSendMessageWithMessageHeaders() {467 SendMessageAction sendAction = new SendMessageAction();468 sendAction.setEndpoint(endpoint);469 PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();470 messageBuilder.setPayloadData("<TestRequest><Message>Hello World!</Message></TestRequest>");471 472 final Map<String, Object> controlHeaders = new HashMap<String, Object>();473 controlHeaders.put("Operation", "sayHello");474 final Message controlMessage = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>", controlHeaders);475 final Map<String, Object> headers = new HashMap<String, Object>();476 headers.put("Operation", "sayHello");477 messageBuilder.setMessageHeaders(headers);478 479 sendAction.setMessageBuilder(messageBuilder);480 reset(endpoint, producer, endpointConfiguration);481 when(endpoint.createProducer()).thenReturn(producer);482 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);483 doAnswer(new Answer() {484 @Override485 public Object answer(InvocationOnMock invocation) throws Throwable {486 DomXmlMessageValidator validator = new DomXmlMessageValidator();487 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();488 validator.validateMessage(((Message)invocation.getArguments()[0]), controlMessage, context, validationContext);489 return null;490 }491 }).when(producer).send(any(Message.class), any(TestContext.class));492 when(endpoint.getActor()).thenReturn(null);493 494 sendAction.execute(context);495 }496 497 @Test498 @SuppressWarnings("rawtypes")499 public void testSendMessageWithHeaderValuesVariableSupport() {500 SendMessageAction sendAction = new SendMessageAction();501 sendAction.setEndpoint(endpoint);502 PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();503 messageBuilder.setPayloadData("<TestRequest><Message>Hello World!</Message></TestRequest>");504 505 context.setVariable("myOperation", "sayHello");506 507 final Map<String, Object> controlHeaders = new HashMap<String, Object>();508 controlHeaders.put("Operation", "sayHello");509 final Message controlMessage = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>", controlHeaders);510 final Map<String, Object> headers = new HashMap<String, Object>();511 headers.put("Operation", "${myOperation}");512 messageBuilder.setMessageHeaders(headers);513 514 sendAction.setMessageBuilder(messageBuilder);515 reset(endpoint, producer, endpointConfiguration);516 when(endpoint.createProducer()).thenReturn(producer);517 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);518 doAnswer(new Answer() {519 @Override520 public Object answer(InvocationOnMock invocation) throws Throwable {521 DomXmlMessageValidator validator = new DomXmlMessageValidator();522 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();523 validator.validateMessage(((Message)invocation.getArguments()[0]), controlMessage, context, validationContext);524 return null;525 }526 }).when(producer).send(any(Message.class), any(TestContext.class));527 when(endpoint.getActor()).thenReturn(null);528 529 sendAction.execute(context);530 }531 532 @Test533 public void testSendMessageWithUnknwonVariableInMessagePayload() {534 SendMessageAction sendAction = new SendMessageAction();535 sendAction.setEndpoint(endpoint);536 PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();537 messageBuilder.setPayloadData("<TestRequest><Message>${myText}</Message></TestRequest>");538 539 sendAction.setMessageBuilder(messageBuilder);540 reset(endpoint, producer, endpointConfiguration);541 when(endpoint.createProducer()).thenReturn(producer);542 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);543 when(endpoint.getActor()).thenReturn(null);544 545 try {546 sendAction.execute(context);547 } catch(CitrusRuntimeException e) {548 Assert.assertEquals(e.getMessage(), "Unknown variable 'myText'");549 return;550 }551 552 Assert.fail("Missing " + CitrusRuntimeException.class + " with unknown variable error message");553 }554 555 @Test556 public void testSendMessageWithUnknwonVariableInHeaders() {557 SendMessageAction sendAction = new SendMessageAction();558 sendAction.setEndpoint(endpoint);559 PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();560 messageBuilder.setPayloadData("<TestRequest><Message>Hello World!</Message></TestRequest>");561 562 final Map<String, Object> headers = new HashMap<String, Object>();563 headers.put("Operation", "${myOperation}");564 messageBuilder.setMessageHeaders(headers);565 566 sendAction.setMessageBuilder(messageBuilder);567 reset(endpoint, producer, endpointConfiguration);568 when(endpoint.createProducer()).thenReturn(producer);569 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);570 when(endpoint.getActor()).thenReturn(null);571 572 try {573 sendAction.execute(context);574 } catch(CitrusRuntimeException e) {575 Assert.assertEquals(e.getMessage(), "Unknown variable 'myOperation'");576 return;577 }578 579 Assert.fail("Missing " + CitrusRuntimeException.class + " with unknown variable error message");580 }581 582 @Test583 @SuppressWarnings("rawtypes")584 public void testSendMessageWithExtractHeaderValues() {585 SendMessageAction sendAction = new SendMessageAction();586 sendAction.setEndpoint(endpoint);587 PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();588 messageBuilder.setPayloadData("<TestRequest><Message>Hello World!</Message></TestRequest>");589 590 final Map<String, Object> controlHeaders = new HashMap<String, Object>();591 controlHeaders.put("Operation", "sayHello");592 final Message controlMessage = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>", controlHeaders);593 final Map<String, Object> headers = new HashMap<String, Object>();594 headers.put("Operation", "sayHello");595 messageBuilder.setMessageHeaders(headers);596 597 sendAction.setMessageBuilder(messageBuilder);598 599 Map<String, String> extractVars = new HashMap<String, String>();600 extractVars.put("Operation", "myOperation");601 extractVars.put(MessageHeaders.ID, "correlationId");602 603 List<VariableExtractor> variableExtractors = new ArrayList<VariableExtractor>();604 MessageHeaderVariableExtractor variableExtractor = new MessageHeaderVariableExtractor();605 variableExtractor.setHeaderMappings(extractVars);606 607 variableExtractors.add(variableExtractor);608 sendAction.setVariableExtractors(variableExtractors);609 reset(endpoint, producer, endpointConfiguration);610 when(endpoint.createProducer()).thenReturn(producer);611 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);612 doAnswer(new Answer() {613 @Override614 public Object answer(InvocationOnMock invocation) throws Throwable {615 DomXmlMessageValidator validator = new DomXmlMessageValidator();616 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();617 validator.validateMessage(((Message)invocation.getArguments()[0]), controlMessage, context, validationContext);618 return null;619 }620 }).when(producer).send(any(Message.class), any(TestContext.class));621 when(endpoint.getActor()).thenReturn(null);622 623 sendAction.execute(context);624 625 Assert.assertNotNull(context.getVariable("myOperation"));626 Assert.assertNotNull(context.getVariable("correlationId"));627 }628 629 @Test630 @SuppressWarnings("rawtypes")631 public void testMissingMessagePayload() {632 SendMessageAction sendAction = new SendMessageAction();633 sendAction.setEndpoint(endpoint);634 reset(endpoint, producer, endpointConfiguration);635 when(endpoint.createProducer()).thenReturn(producer);636 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);637 doAnswer(new Answer() {638 @Override639 public Object answer(InvocationOnMock invocation) throws Throwable {640 DomXmlMessageValidator validator = new DomXmlMessageValidator();641 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();642 validator.validateMessage(((Message)invocation.getArguments()[0]), new DefaultMessage(""), context, validationContext);643 return null;644 }645 }).when(producer).send(any(Message.class), any(TestContext.class));646 when(endpoint.getActor()).thenReturn(null);647 648 sendAction.execute(context);649 }650 651 @Test652 @SuppressWarnings("rawtypes")653 public void testSendMessageWithXmlDeclaration() {654 SendMessageAction sendAction = new SendMessageAction();655 sendAction.setEndpoint(endpoint);656 PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();657 messageBuilder.setPayloadData("<?xml version=\"1.0\" encoding=\"UTF-8\"?><TestRequest><Message>Hello World!</Message></TestRequest>");658 659 sendAction.setMessageBuilder(messageBuilder);660 661 final Message controlMessage = new DefaultMessage("<?xml version=\"1.0\" encoding=\"UTF-8\"?><TestRequest><Message>Hello World!</Message></TestRequest>");662 reset(endpoint, producer, endpointConfiguration);663 when(endpoint.createProducer()).thenReturn(producer);664 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);665 doAnswer(new Answer() {666 @Override667 public Object answer(InvocationOnMock invocation) throws Throwable {668 DomXmlMessageValidator validator = new DomXmlMessageValidator();669 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();670 validator.validateMessage(((Message)invocation.getArguments()[0]), controlMessage, context, validationContext);671 return null;672 }673 }).when(producer).send(any(Message.class), any(TestContext.class));674 when(endpoint.getActor()).thenReturn(null);675 676 sendAction.execute(context);677 }678 679 @Test680 @SuppressWarnings("rawtypes")681 public void testSendMessageWithUTF16Encoding() {682 SendMessageAction sendAction = new SendMessageAction();683 sendAction.setEndpoint(endpoint);684 PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();685 messageBuilder.setPayloadData("<?xml version=\"1.0\" encoding=\"UTF-16\"?><TestRequest><Message>Hello World!</Message></TestRequest>");686 687 sendAction.setMessageBuilder(messageBuilder);688 689 final Message controlMessage = new DefaultMessage("<?xml version=\"1.0\" encoding=\"UTF-16\"?><TestRequest><Message>Hello World!</Message></TestRequest>");690 reset(endpoint, producer, endpointConfiguration);691 when(endpoint.createProducer()).thenReturn(producer);692 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);693 doAnswer(new Answer() {694 @Override695 public Object answer(InvocationOnMock invocation) throws Throwable {696 DomXmlMessageValidator validator = new DomXmlMessageValidator();697 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();698 validator.validateMessage(((Message)invocation.getArguments()[0]), controlMessage, context, validationContext);699 return null;700 }701 }).when(producer).send(any(Message.class), any(TestContext.class));702 when(endpoint.getActor()).thenReturn(null);703 704 sendAction.execute(context);705 }706 707 @Test708 @SuppressWarnings("rawtypes")709 public void testSendMessageWithISOEncoding() {710 SendMessageAction sendAction = new SendMessageAction();711 sendAction.setEndpoint(endpoint);712 PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();713 messageBuilder.setPayloadData("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><TestRequest><Message>Hello World!</Message></TestRequest>");714 715 sendAction.setMessageBuilder(messageBuilder);716 717 final Message controlMessage = new DefaultMessage("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><TestRequest><Message>Hello World!</Message></TestRequest>");718 reset(endpoint, producer, endpointConfiguration);719 when(endpoint.createProducer()).thenReturn(producer);720 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);721 doAnswer(new Answer() {722 @Override723 public Object answer(InvocationOnMock invocation) throws Throwable {724 DomXmlMessageValidator validator = new DomXmlMessageValidator();725 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();726 validator.validateMessage(((Message)invocation.getArguments()[0]), controlMessage, context, validationContext);727 return null;728 }729 }).when(producer).send(any(Message.class), any(TestContext.class));730 when(endpoint.getActor()).thenReturn(null);731 732 sendAction.execute(context);733 }734 735 @Test736 @SuppressWarnings("rawtypes")737 public void testSendMessageWithUnsupportedEncoding() {738 SendMessageAction sendAction = new SendMessageAction();739 sendAction.setEndpoint(endpoint);740 PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();741 messageBuilder.setPayloadData("<?xml version=\"1.0\" encoding=\"MyUnsupportedEncoding\"?><TestRequest><Message>Hello World!</Message></TestRequest>");742 743 sendAction.setMessageBuilder(messageBuilder);744 reset(endpoint, producer, endpointConfiguration);745 when(endpoint.createProducer()).thenReturn(producer);746 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);747 when(endpoint.getActor()).thenReturn(null);748 try {749 sendAction.execute(context);750 } catch (CitrusRuntimeException e) {751 Assert.assertTrue(e.getCause() instanceof UnsupportedEncodingException);752 }753 verify(producer).send(any(Message.class), any(TestContext.class));754 }755 @Test756 @SuppressWarnings("rawtypes")757 public void testSendMessageWithMessagePayloadResourceISOEncoding() {758 SendMessageAction sendAction = new SendMessageAction();759 sendAction.setEndpoint(endpoint);760 PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();761 messageBuilder.setPayloadResourcePath("classpath:com/consol/citrus/actions/test-request-iso-encoding.xml");762 763 sendAction.setMessageBuilder(messageBuilder);764 765 final Message controlMessage = new DefaultMessage("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><TestRequest><Message>Hello World!</Message></TestRequest>");766 reset(endpoint, producer, endpointConfiguration);767 when(endpoint.createProducer()).thenReturn(producer);768 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);769 doAnswer(new Answer() {770 @Override771 public Object answer(InvocationOnMock invocation) throws Throwable {772 DomXmlMessageValidator validator = new DomXmlMessageValidator();773 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();774 validator.validateMessage(((Message)invocation.getArguments()[0]), controlMessage, context, validationContext);775 return null;776 }777 }).when(producer).send(any(Message.class), any(TestContext.class));778 when(endpoint.getActor()).thenReturn(null);779 780 sendAction.execute(context);781 }782 783 @Test784 public void testDisabledSendMessage() {785 TestCase testCase = new TestCase();786 SendMessageAction sendAction = new SendMessageAction();787 sendAction.setEndpoint(endpoint);788 789 TestActor disabledActor = new TestActor();790 disabledActor.setDisabled(true);791 sendAction.setActor(disabledActor);792 793 PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();794 messageBuilder.setPayloadData("<TestRequest><Message>Hello World!</Message></TestRequest>");795 796 sendAction.setMessageBuilder(messageBuilder);797 reset(endpoint, producer, endpointConfiguration);798 when(endpoint.createProducer()).thenReturn(producer);799 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);800 when(endpoint.getActor()).thenReturn(null);801 testCase.addTestAction(sendAction);802 testCase.execute(context);803 }804 805 @Test806 public void testDisabledSendMessageByEndpointActor() {807 TestCase testCase = new TestCase();808 SendMessageAction sendAction = new SendMessageAction();809 sendAction.setEndpoint(endpoint);810 811 TestActor disabledActor = new TestActor();812 disabledActor.setDisabled(true);813 814 PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();815 messageBuilder.setPayloadData("<TestRequest><Message>Hello World!</Message></TestRequest>");816 817 sendAction.setMessageBuilder(messageBuilder);818 reset(endpoint, producer, endpointConfiguration);819 when(endpoint.createProducer()).thenReturn(producer);820 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);821 when(endpoint.getActor()).thenReturn(disabledActor);822 testCase.addTestAction(sendAction);823 testCase.execute(context);824 }825 826}...

Full Screen

Full Screen

Source:SendMessageActionConverter.java Github

copy

Full Screen

...101 action.setDescription(model.getDescription());102 action.setEndpoint(model.getEndpoint() != null ? model.getEndpoint().getName() : model.getEndpointUri());103 action.setFork(model.isForkMode());104 SendModel.Message message = new SendModel.Message();105 if (model.getMessageBuilder() instanceof PayloadTemplateMessageBuilder) {106 PayloadTemplateMessageBuilder messageBuilder = (PayloadTemplateMessageBuilder) model.getMessageBuilder();107 message.setName(messageBuilder.getMessageName());108 message.setData(messageBuilder.getPayloadData());109 if (StringUtils.hasText(messageBuilder.getPayloadResourcePath())) {110 SendModel.Message.Resource messageResource = new SendModel.Message.Resource();111 messageResource.setFile(messageBuilder.getPayloadResourcePath());112 messageResource.setCharset(messageBuilder.getPayloadResourceCharset());113 message.setResource(messageResource);114 }115 }116 if (model.getMessageBuilder() instanceof StaticMessageContentBuilder) {117 StaticMessageContentBuilder messageBuilder = (StaticMessageContentBuilder) model.getMessageBuilder();118 message.setName(messageBuilder.getMessageName());119 message.setData(messageBuilder.getMessage().getPayload(String.class));120 }...

Full Screen

Full Screen

PayloadTemplateMessageBuilder

Using AI Code Generation

copy

Full Screen

1import com.consol.citrus.dsl.builder.SendMessageActionBuilder;2import com.consol.citrus.dsl.builder.PayloadTemplateMessageBuilder;3import com.consol.citrus.dsl.runner.TestRunner;4import com.consol.citrus.dsl.runner.TestRunnerSupport;5public class 4 {6 public static void main(String[] args) {7 TestRunner runner = new TestRunnerSupport();8 PayloadTemplateMessageBuilder builder = new PayloadTemplateMessageBuilder();9 + "<ns0:Text>Hello World!</ns0:Text>" + "</ns0:Request>");10 builder.header("operation", "sayHello");11 SendMessageActionBuilder builder1 = runner.send(builder);12 builder1.messageType("SOAP");13 builder1.endpoint("helloServiceClient");14 }15}16import com.consol.citrus.dsl.builder.SendMessageActionBuilder;17import com.consol.citrus.dsl.builder.PayloadTemplateMessageBuilder;18import com.consol.citrus.dsl.runner.TestRunner;19import com.consol.citrus.dsl.runner.TestRunnerSupport;20public class 5 {21 public static void main(String[] args) {22 TestRunner runner = new TestRunnerSupport();23 PayloadTemplateMessageBuilder builder = new PayloadTemplateMessageBuilder();24 + "<ns0:Text>Hello World!</ns0:Text>" + "</ns0:Request>");25 builder.header("operation", "sayHello");26 SendMessageActionBuilder builder1 = runner.send(builder);27 builder1.messageType("SOAP");28 builder1.endpoint("helloServiceClient");29 }30}31import com.consol.citrus.dsl.builder.SendMessageActionBuilder;32import com.consol.citrus.dsl.builder.PayloadTemplateMessageBuilder;33import com.consol.citrus.dsl.runner.TestRunner;34import com.consol.citrus.dsl.runner.TestRunnerSupport;35public class 6 {36 public static void main(String[] args) {

Full Screen

Full Screen

PayloadTemplateMessageBuilder

Using AI Code Generation

copy

Full Screen

1import com.consol.citrus.annotations.CitrusTest;2import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;3import org.springframework.core.io.ClassPathResource;4import org.testng.annotations.Test;5public class 4 extends TestNGCitrusTestDesigner {6 public void 4() {7 variable("name", "John");8 variable("id", "12345");9 variable("date", "2018-01-01");10 variable("time", "13:00:00");11 variable("amount", "1000");12 variable("currency", "USD");13 variable("status", "true");14 send("queue:inbound")15 .payload("<testRequest>"16 + "<name>${name}</name>"17 + "<id>${id}</id>"18 + "<date>${date}</date>"19 + "<time>${time}</time>"20 + "<amount>${amount}</amount>"21 + "<currency>${currency}</currency>"22 + "<status>${status}</status>"23 + "</testRequest>");24 receive("queue:outbound")25 .payload("<testResponse>"26 + "<name>${name}</name>"27 + "<id>${id}</id>"28 + "<date>${date}</date>"29 + "<time>${time}</time>"30 + "<amount>${amount}</amount>"31 + "<currency>${currency}</currency>"32 + "<status>${status}</status>"33 + "</testResponse>");34 }35}36The payloadTemplate() method is used to send

Full Screen

Full Screen

PayloadTemplateMessageBuilder

Using AI Code Generation

copy

Full Screen

1import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;2import org.testng.annotations.Test;3public class 4 extends TestNGCitrusTestDesigner {4public void 4() {5       .header("SOAPAction", "sayHello")6       .header("Content-Type", "text/xml;charset=UTF-8");7                    <hello:Message>Hello ${user}!</hello:Message>8       .header("Content-Type", "text/xml;charset=UTF-8");9}10}11import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;12import org.testng.annotations.Test;13public class 5 extends TestNGCitrusTestDesigner {14public void 5() {15       .payload(new ClassPathResource("templates/soap-request.xml"))16       .header("SOAPAction", "sayHello")17       .header("Content-Type", "text/xml;charset=UTF-8");18       .payload(new ClassPathResource("templates

Full Screen

Full Screen

PayloadTemplateMessageBuilder

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.samples;2import com.consol.citrus.annotations.CitrusTest;3import com.consol.citrus.dsl.testng.TestNGCitrusTestRunner;4import org.springframework.core.io.ClassPathResource;5import org.testng.annotations.Test;6public class Test4 extends TestNGCitrusTestRunner {7 public void test() {8 variable("name", "John Doe");9 http()10 .client("httpClient")11 .send()12 .post("/service")13 .contentType("text/xml")14 .payload(new ClassPathResource("request4.xml"));15 http()16 .client("httpClient")17 .receive()18 .response(HttpStatus.OK)19 .payload(new ClassPathResource("response4.xml"));20 }21}22 <name>${name}</name>23 <greeting>Hello ${name}</greeting>

Full Screen

Full Screen

PayloadTemplateMessageBuilder

Using AI Code Generation

copy

Full Screen

1public class 4 {2 public static void main(String[] args) {3 Citrus citrus = Citrus.newInstance();4 citrus.getCitrusAnnotations().citrusTest(citrus.getCitrusAnnotations().createTestAnnotationBuilder()5 .name("4")6 .description("code to use PayloadTemplateMessageBuilder method of com.consol.citrus.actions.SendMessageAction class")7 .build(), new TestBehavior() {8 public void execute(CitrusFramework citrusFramework) {9 citrusFramework.getCitrus().run(new TestBehavior() {10 public void execute(CitrusFramework citrusFramework) {11 citrusFramework.getCitrus().run(new TestBehavior() {12 public void execute(CitrusFramework citrusFramework) {13 citrusFramework.getCitrus().run(new TestBehavior() {14 public void execute(CitrusFramework citrusFramework) {15 citrusFramework.getCitrus().run(new TestBehavior() {16 public void execute(CitrusFramework citrusFramework) {17 citrusFramework.getCitrus().run(new TestBehavior() {18 public void execute(CitrusFramework citrusFramework) {19 citrusFramework.getCitrus().run(new TestBehavior() {20 public void execute(CitrusFramework citrusFramework) {21 citrusFramework.getCitrus().run(new TestBehavior() {22 public void execute(CitrusFramework citrusFramework) {23 citrusFramework.getCitrus().run(new TestBehavior() {24 public void execute(CitrusFramework citrusFramework) {25 citrusFramework.getCitrus().run(new TestBehavior() {26 public void execute(CitrusFramework citrusFramework) {27 citrusFramework.getCitrus().run(new TestBehavior() {

Full Screen

Full Screen

PayloadTemplateMessageBuilder

Using AI Code Generation

copy

Full Screen

1public class 4 extends TestCase {2 public void 4() {3 variable("messageId", "4");4 variable("message", "4");5 variable("name", "4");6 variable("age", "4");7 variable("city", "4");8 variable("country", "4");9 variable("id", "4");10 echo("4");11 send("4")

Full Screen

Full Screen

PayloadTemplateMessageBuilder

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.samples;2import com.consol.citrus.dsl.design.TestDesigner;3import com.consol.citrus.dsl.design.TestDesignerBeforeSuiteSupport;4import org.springframework.core.io.ClassPathResource;5public class 4 extends TestDesignerBeforeSuiteSupport {6 protected void configure(TestDesigner designer) {7 designer.http()8 .client("httpClient")9 .send()10 .post()11 .payload(new ClassPathResource("request.xml"))12 .header("operation", "add")13 .header("citrus_http_request_path", "/calculator")14 .header("citrus_http_request_method", "POST")15 .header("citrus_http_version", "HTTP/1.1");16 designer.http()17 .client("httpClient")18 .receive()19 .response(HttpStatus.OK)20 .messageType(MessageType.PLAINTEXT)21 .payload("<result>${result}</result>")22 }23}24package com.consol.citrus.samples;25import com.consol.citrus.dsl.design.TestDesigner;26import com.consol.citrus.dsl.design.TestDesignerBeforeSuiteSupport;27import org.springframework.core.io.ClassPathResource;28public class 5 extends TestDesignerBeforeSuiteSupport {29 protected void configure(TestDesigner designer) {30 designer.http()31 .client("httpClient")32 .send()33 .post()34 .payload(new ClassPathResource("request.xml"))35 .header("operation", "add")36 .header("citrus_http_request_path", "/calculator")37 .header("citrus_http_request_method", "POST")38 .header("citrus_http_version", "HTTP/1.1");39 designer.http()40 .client("httpClient")41 .receive()42 .response(HttpStatus.OK)43 .messageType(MessageType.PLAINTEXT)44 .payload(new PayloadTemplateBuilder()45 .template("<result>${result}</result>")46 .build())47 }48}

Full Screen

Full Screen

PayloadTemplateMessageBuilder

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.samples;2import org.springframework.context.annotation.Bean;3import org.springframework.context.annotation.Configuration;4import org.springframework.context.annotation.Import;5import com.consol.citrus.dsl.builder.SendMessageBuilder;6import com.consol.citrus.dsl.builder.TemplateBuilderSupport;7import com.consol.citrus.dsl.spring.TestRunnerSpringSupport;8import com.consol.citrus.dsl.runner.TestRunner;9import com.consol.citrus.dsl.runner.TestRunnerAfterSuiteSupport;10import com.consol.citrus.dsl.runner.TestRunnerBeforeSuiteSupport;11import com.consol.citrus.dsl.runner.TestRunnerBeforeTestSupport;12import com.consol.citrus.dsl.runner.TestRunnerAfterTestSupport;13import com.consol.citrus.dsl.runner.TestRunnerBeforeGroupsSupport;14import com.consol.citrus.dsl.runner.TestRunnerAfterGroupsSupport;15import com.consol.citrus.dsl.runner.TestRunnerBeforeClassSupport;16import com.consol.citrus.dsl.runner.TestRunnerAfterClassSupport;17import com.consol.citrus.dsl.runner.TestRunnerBeforeMethodSupport;18import com.consol.citrus.dsl.runner.TestRunnerAfterMethodSupport;19import com.consol.citrus.dsl.testng.TestNGCitrusTestRunner;20import com.consol.citrus.dsl.testng.TestNGCitrusTest;21import com.consol.citrus.dsl.testng.TestNGCitrusTestRunnerBuilder;22import com.consol.citrus.dsl.testng.TestNGCitrusTestBuilder;23import com.consol.citrus.dsl.testng.TestNGCitrusTestRunnerBuilderSupport;24import com.consol.citrus.dsl.testng.TestNGCitrusTestBuilderSupport;25import com.consol.citrus.dsl.testng.TestNGCitrusTestRunnerSupport;26import com.consol.citrus.dsl.testng.TestNGCitrusTestSupport;27import com.consol.citrus.dsl.testng.TestNGCitrusXmlTestRunner;28import com.consol.citrus.dsl.testng.TestNGCitrusXmlTest;29import com.consol.citrus.dsl.testng.TestNGCitrusXmlTestRunnerBuilder;30import com.consol.citrus.dsl.testng.TestNGCitrusXmlTestBuilder;31import com.consol.citrus.dsl.testng.TestNGCitrusXmlTestRunnerBuilderSupport;32import com.consol.citrus.dsl.testng.TestNGCitrusXmlTestBuilderSupport;33import com.consol.citrus.dsl.testng.TestNGCitrusXmlTestRunnerSupport;

Full Screen

Full Screen

PayloadTemplateMessageBuilder

Using AI Code Generation

copy

Full Screen

1public class 4 extends TestNGCitrusTestDesigner {2 public void configure() {3 variable("payload", "payload");4 variable("payloadType", "application/json");5 variable("contentType", "application/json");6 variable("httpMethod", "POST");7 variable("httpHeaders", "citrus_http_method=${httpMethod},citrus_http_url=${httpUrl},citrus_http_version=1.1");8 variable("payload", "<Message><Text>Hello World!</Text></Message>");9 variable("payloadType", "application/xml");10 variable("contentType", "application/xml");11 variable("httpMethod", "POST");12 variable("httpHeaders", "citrus_http_method=${httpMethod},citrus_http_url=${httpUrl},citrus_http_version=1.1");13 send(new SendMessageAction.Builder()14 .message(new PayloadTemplateMessageBuilder.Builder()15 .payloadData("${payload}")16 .payloadResourcePath("classpath:com/consol/citrus/actions/payload-template-message-builder-payload.xml")17 .payloadResourceTransformer(new XsltPayloadTransformer.Builder()18 .xsltTemplate("classpath:com/consol/citrus/actions/payload-template-message-builder-payload.xsl")19 .build())20 .contentType("${contentType}")21 .header("citrus_http_method", "${httpMethod}")22 .header("citrus_http_url", "${httpUrl}")23 .header("citrus_http_version", "1.1")24 .build())25 .endpoint(new HttpEndpoint.Builder()26 .requestUrl("${httpUrl}")27 .build())28 .build());29 }30}31public class 5 extends TestNGCitrusTestDesigner {32 public void configure() {33 variable("payload", "payload");34 variable("payloadType", "application/json");35 variable("contentType", "application/json");36 variable("httpMethod", "POST");37 variable("httpHeaders", "citrus_http_method=${httpMethod},citrus_http_url=${httpUrl},citrus_http_version=1

Full Screen

Full Screen

PayloadTemplateMessageBuilder

Using AI Code Generation

copy

Full Screen

1 public void execute(CitrusFramework citrusFramework) {2 citrusFramework.getCitrus().run(new TestBehavior() {3 public void execute(CitrusFramework citrusFramework) {4 citrusFramework.getCitrus().run(new TestBehavior() {5 public void execute(CitrusFramework citrusFramework) {6 citrusFramework.getCitrus().run(new TestBehavior() {7 public void execute(CitrusFramework citrusFramework) {8 citrusFramework.getCitrus().run(new TestBehavior() {9 public void execute(CitrusFramework citrusFramework) {10 citrusFramework.getCitrus().run(new TestBehavior() {11 public void execute(CitrusFramework citrusFramework) {12 citrusFramework.getCitrus().run(new TestBehavior() {13 public void execute(CitrusFramework citrusFramework) {14 citrusFramework.getCitrus().run(new TestBehavior() {15 public void execute(CitrusFramework citrusFramework) {16 citrusFramework.getCitrus().run(new TestBehavior() {

Full Screen

Full Screen

PayloadTemplateMessageBuilder

Using AI Code Generation

copy

Full Screen

1public class 4 extends TestCase {2 public void 4() {3 variable("messageId", "4");4 variable("message", "4");5 variable("name", "4");6 variable("age", "4");7 variable("city", "4");8 variable("country", "4");9 variable("id", "4");10 echo("4");11 send("4")

Full Screen

Full Screen

PayloadTemplateMessageBuilder

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.samples;2import org.springframework.context.annotation.Bean;3import org.springframework.context.annotation.Configuration;4import org.springframework.context.annotation.Import;5import com.consol.citrus.dsl.builder.SendMessageBuilder;6import com.consol.citrus.dsl.builder.TemplateBuilderSupport;7import com.consol.citrus.dsl.spring.TestRunnerSpringSupport;8import com.consol.citrus.dsl.runner.TestRunner;9import com.consol.citrus.dsl.runner.TestRunnerAfterSuiteSupport;10import com.consol.citrus.dsl.runner.TestRunnerBeforeSuiteSupport;11import com.consol.citrus.dsl.runner.TestRunnerBeforeTestSupport;12import com.consol.citrus.dsl.runner.TestRunnerAfterTestSupport;13import com.consol.citrus.dsl.runner.TestRunnerBeforeGroupsSupport;14import com.consol.citrus.dsl.runner.TestRunnerAfterGroupsSupport;15import com.consol.citrus.dsl.runner.TestRunnerBeforeClassSupport;16import com.consol.citrus.dsl.runner.TestRunnerAfterClassSupport;17import com.consol.citrus.dsl.runner.TestRunnerBeforeMethodSupport;18import com.consol.citrus.dsl.runner.TestRunnerAfterMethodSupport;19import com.consol.citrus.dsl.testng.TestNGCitrusTestRunner;20import com.consol.citrus.dsl.testng.TestNGCitrusTest;21import com.consol.citrus.dsl.testng.TestNGCitrusTestRunnerBuilder;22import com.consol.citrus.dsl.testng.TestNGCitrusTestBuilder;23import com.consol.citrus.dsl.testng.TestNGCitrusTestRunnerBuilderSupport;24import com.consol.citrus.dsl.testng.TestNGCitrusTestBuilderSupport;25import com.consol.citrus.dsl.testng.TestNGCitrusTestRunnerSupport;26import com.consol.citrus.dsl.testng.TestNGCitrusTestSupport;27import com.consol.citrus.dsl.testng.TestNGCitrusXmlTestRunner;28import com.consol.citrus.dsl.testng.TestNGCitrusXmlTest;29import com.consol.citrus.dsl.testng.TestNGCitrusXmlTestRunnerBuilder;30import com.consol.citrus.dsl.testng.TestNGCitrusXmlTestBuilder;31import com.consol.citrus.dsl.testng.TestNGCitrusXmlTestRunnerBuilderSupport;32import com.consol.citrus.dsl.testng.TestNGCitrusXmlTestBuilderSupport;33import com.consol.citrus.dsl.testng.TestNGCitrusXmlTestRunnerSupport;

Full Screen

Full Screen

PayloadTemplateMessageBuilder

Using AI Code Generation

copy

Full Screen

1 .send()2 .post("/service")3 .contentType("text/xml")4 .payload(new ClassPathResource("request4.xml"));5 http()6 .client("httpClient")7 .receive()8 .response(HttpStatus.OK)9 .payload(new ClassPathResource("response4.xml"));10 }11}12 <name>${name}</name>13 <greeting>Hello ${name}</greeting>

Full Screen

Full Screen

PayloadTemplateMessageBuilder

Using AI Code Generation

copy

Full Screen

1public class 4 {2 public static void main(String[] args) {3 Citrus citrus = Citrus.newInstance();4 citrus.getCitrusAnnotations().citrusTest(citrus.getCitrusAnnotations().createTestAnnotationBuilder()5 .name("4")6 .description("code to use PayloadTemplateMessageBuilder method of com.consol.citrus.actions.SendMessageAction class")7 .build(), new TestBehavior() {8 public void execute(CitrusFramework citrusFramework) {9 citrusFramework.getCitrus().run(new TestBehavior() {10 public void execute(CitrusFramework citrusFramework) {11 citrusFramework.getCitrus().run(new TestBehavior() {12 public void execute(CitrusFramework citrusFramework) {13 citrusFramework.getCitrus().run(new TestBehavior() {14 public void execute(CitrusFramework citrusFramework) {15 citrusFramework.getCitrus().run(new TestBehavior() {16 public void execute(CitrusFramework citrusFramework) {17 citrusFramework.getCitrus().run(new TestBehavior() {18 public void execute(CitrusFramework citrusFramework) {19 citrusFramework.getCitrus().run(new TestBehavior() {20 public void execute(CitrusFramework citrusFramework) {21 citrusFramework.getCitrus().run(new TestBehavior() {22 public void execute(CitrusFramework citrusFramework) {23 citrusFramework.getCitrus().run(new TestBehavior() {24 public void execute(CitrusFramework citrusFramework) {25 citrusFramework.getCitrus().run(new TestBehavior() {26 public void execute(CitrusFramework citrusFramework) {27 citrusFramework.getCitrus().run(new TestBehavior() {

Full Screen

Full Screen

PayloadTemplateMessageBuilder

Using AI Code Generation

copy

Full Screen

1public class 4 extends TestCase {2 public void 4() {3 variable("messageId", "4");4 variable("message", "4");5 variable("name", "4");6 variable("age", "4");7 variable("city", "4");8 variable("country", "4");9 variable("id", "4");10 echo("4");11 send("4")

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful