How to use answer method of com.consol.citrus.ws.actions.SendSoapMessageActionTest class

Best Citrus code snippet using com.consol.citrus.ws.actions.SendSoapMessageActionTest.answer

Source:SendSoapMessageActionTest.java Github

copy

Full Screen

...54 reset(webServiceEndpoint, producer);55 when(webServiceEndpoint.createProducer()).thenReturn(producer);56 doAnswer(new Answer() {57 @Override58 public Object answer(InvocationOnMock invocation) throws Throwable {59 SoapMessage soapMessage = ((SoapMessage)invocation.getArguments()[0]);60 Assert.assertTrue(soapMessage.isMtomEnabled());61 Assert.assertEquals(soapMessage.getPayload(String.class), "<TestRequest><Text><xop:Include xmlns:xop=\"http://www.w3.org/2004/08/xop/include\" href=\"cid:mtomText%40citrusframework.org\"/></Text></TestRequest>");62 Assert.assertEquals(soapMessage.getAttachments().size(), 1L);63 SoapAttachment constructedAttachment = ((SoapMessage)invocation.getArguments()[0]).getAttachments().get(0);64 Assert.assertEquals(constructedAttachment.getContentId(), "mtomText@citrusframework.org");65 Assert.assertEquals(constructedAttachment.getContentType(), "text/xml");66 Assert.assertEquals(constructedAttachment.getContent(), "<TestAttachment><Message>Hello World!</Message></TestAttachment>");67 Assert.assertEquals(constructedAttachment.getCharsetName(), "UTF-8");68 return null;69 }70 }).when(producer).send(any(Message.class), any(TestContext.class));71 when(webServiceEndpoint.getActor()).thenReturn(null);72 soapMessageAction.execute(context);73 }74 @Test75 @SuppressWarnings("rawtypes")76 public void testSoapMessageWithMtomInlineBase64BinaryAttachmentDataTest() throws Exception {77 SendSoapMessageAction soapMessageAction = new SendSoapMessageAction();78 soapMessageAction.setEndpoint(webServiceEndpoint);79 soapMessageAction.setMtomEnabled(true);80 PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();81 messageBuilder.setPayloadData("<TestRequest><Image>cid:mtomImage</Image></TestRequest>");82 soapMessageAction.setMessageBuilder(messageBuilder);83 SoapAttachment attachment = new SoapAttachment();84 attachment.setMtomInline(true);85 attachment.setEncodingType(SoapAttachment.ENCODING_BASE64_BINARY);86 attachment.setContentId("mtomImage");87 attachment.setContentType("image/png");88 attachment.setContent("IMAGE_DATA");89 soapMessageAction.setAttachments(Collections.singletonList(attachment));90 reset(webServiceEndpoint, producer);91 when(webServiceEndpoint.createProducer()).thenReturn(producer);92 doAnswer(new Answer() {93 @Override94 public Object answer(InvocationOnMock invocation) throws Throwable {95 SoapMessage soapMessage = ((SoapMessage)invocation.getArguments()[0]);96 Assert.assertTrue(soapMessage.isMtomEnabled());97 Assert.assertEquals(soapMessage.getPayload(String.class), "<TestRequest><Image>SU1BR0VfREFUQQ==</Image></TestRequest>");98 Assert.assertEquals(soapMessage.getAttachments().size(), 0L);99 return null;100 }101 }).when(producer).send(any(Message.class), any(TestContext.class));102 when(webServiceEndpoint.getActor()).thenReturn(null);103 soapMessageAction.execute(context);104 }105 @Test106 @SuppressWarnings("rawtypes")107 public void testSoapMessageWithMtomInlineHexBinaryAttachmentDataTest() throws Exception {108 SendSoapMessageAction soapMessageAction = new SendSoapMessageAction();109 soapMessageAction.setEndpoint(webServiceEndpoint);110 soapMessageAction.setMtomEnabled(true);111 PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();112 messageBuilder.setPayloadData("<TestRequest><Image>cid:mtomImage</Image></TestRequest>");113 soapMessageAction.setMessageBuilder(messageBuilder);114 SoapAttachment attachment = new SoapAttachment();115 attachment.setMtomInline(true);116 attachment.setEncodingType(SoapAttachment.ENCODING_HEX_BINARY);117 attachment.setContentId("mtomImage");118 attachment.setContentType("image/png");119 attachment.setContent("IMAGE_DATA");120 soapMessageAction.setAttachments(Collections.singletonList(attachment));121 reset(webServiceEndpoint, producer);122 when(webServiceEndpoint.createProducer()).thenReturn(producer);123 doAnswer(new Answer() {124 @Override125 public Object answer(InvocationOnMock invocation) throws Throwable {126 SoapMessage soapMessage = ((SoapMessage)invocation.getArguments()[0]);127 Assert.assertTrue(soapMessage.isMtomEnabled());128 Assert.assertEquals(soapMessage.getPayload(String.class), "<TestRequest><Image>494D4147455F44415441</Image></TestRequest>");129 Assert.assertEquals(soapMessage.getAttachments().size(), 0L);130 return null;131 }132 }).when(producer).send(any(Message.class), any(TestContext.class));133 when(webServiceEndpoint.getActor()).thenReturn(null);134 soapMessageAction.execute(context);135 }136 @Test137 @SuppressWarnings("rawtypes")138 public void testSoapMessageWithMtomMissingCidAttachmentDataTest() throws Exception {139 SendSoapMessageAction soapMessageAction = new SendSoapMessageAction();140 soapMessageAction.setEndpoint(webServiceEndpoint);141 soapMessageAction.setMtomEnabled(true);142 PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();143 messageBuilder.setPayloadData("<TestRequest><Text>mtomText</Text></TestRequest>");144 soapMessageAction.setMessageBuilder(messageBuilder);145 SoapAttachment attachment = new SoapAttachment();146 attachment.setContentId("mtomText");147 attachment.setContentType("text/xml");148 attachment.setContent("<TestAttachment><Message>Hello World!</Message></TestAttachment>");149 soapMessageAction.setAttachments(Collections.singletonList(attachment));150 reset(webServiceEndpoint, producer);151 when(webServiceEndpoint.createProducer()).thenReturn(producer);152 doAnswer(new Answer() {153 @Override154 public Object answer(InvocationOnMock invocation) throws Throwable {155 SoapMessage soapMessage = ((SoapMessage)invocation.getArguments()[0]);156 Assert.assertTrue(soapMessage.isMtomEnabled());157 Assert.assertEquals(soapMessage.getPayload(String.class), "<TestRequest><Text>mtomText</Text></TestRequest>");158 Assert.assertEquals(soapMessage.getAttachments().size(), 1L);159 SoapAttachment constructedAttachment = ((SoapMessage)invocation.getArguments()[0]).getAttachments().get(0);160 Assert.assertEquals(constructedAttachment.getContentId(), "mtomText");161 Assert.assertEquals(constructedAttachment.getContentType(), "text/xml");162 Assert.assertEquals(constructedAttachment.getContent(), "<TestAttachment><Message>Hello World!</Message></TestAttachment>");163 Assert.assertEquals(constructedAttachment.getCharsetName(), "UTF-8");164 return null;165 }166 }).when(producer).send(any(Message.class), any(TestContext.class));167 when(webServiceEndpoint.getActor()).thenReturn(null);168 soapMessageAction.execute(context);169 }170 @Test171 @SuppressWarnings("rawtypes")172 public void testSoapMessageWithMtomInlineMissingCidAttachmentDataTest() throws Exception {173 SendSoapMessageAction soapMessageAction = new SendSoapMessageAction();174 soapMessageAction.setEndpoint(webServiceEndpoint);175 soapMessageAction.setMtomEnabled(true);176 PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();177 messageBuilder.setPayloadData("<TestRequest><Image>mtomImage</Image></TestRequest>");178 soapMessageAction.setMessageBuilder(messageBuilder);179 SoapAttachment attachment = new SoapAttachment();180 attachment.setMtomInline(true);181 attachment.setEncodingType(SoapAttachment.ENCODING_BASE64_BINARY);182 attachment.setContentId("mtomImage");183 attachment.setContentType("image/png");184 attachment.setContent("IMAGE_DATA");185 soapMessageAction.setAttachments(Collections.singletonList(attachment));186 reset(webServiceEndpoint, producer);187 when(webServiceEndpoint.createProducer()).thenReturn(producer);188 doAnswer(new Answer() {189 @Override190 public Object answer(InvocationOnMock invocation) throws Throwable {191 SoapMessage soapMessage = ((SoapMessage)invocation.getArguments()[0]);192 Assert.assertTrue(soapMessage.isMtomEnabled());193 Assert.assertEquals(soapMessage.getPayload(String.class), "<TestRequest><Image>mtomImage</Image></TestRequest>");194 Assert.assertEquals(soapMessage.getAttachments().size(), 1L);195 SoapAttachment constructedAttachment = ((SoapMessage)invocation.getArguments()[0]).getAttachments().get(0);196 Assert.assertEquals(constructedAttachment.getContentId(), "mtomImage");197 Assert.assertEquals(constructedAttachment.getContentType(), "image/png");198 Assert.assertEquals(constructedAttachment.getContent(), "IMAGE_DATA");199 Assert.assertEquals(constructedAttachment.getCharsetName(), "UTF-8");200 return null;201 }202 }).when(producer).send(any(Message.class), any(TestContext.class));203 when(webServiceEndpoint.getActor()).thenReturn(null);204 soapMessageAction.execute(context);205 }206 @Test207 @SuppressWarnings("rawtypes")208 public void testSoapMessageWithMtomInlineInvalidEncodingTypeAttachmentDataTest() throws Exception {209 SendSoapMessageAction soapMessageAction = new SendSoapMessageAction();210 soapMessageAction.setEndpoint(webServiceEndpoint);211 soapMessageAction.setMtomEnabled(true);212 PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();213 messageBuilder.setPayloadData("<TestRequest><Image>cid:mtomImage</Image></TestRequest>");214 soapMessageAction.setMessageBuilder(messageBuilder);215 SoapAttachment attachment = new SoapAttachment();216 attachment.setMtomInline(true);217 attachment.setEncodingType("md5");218 attachment.setContentId("mtomImage");219 attachment.setContentType("image/png");220 attachment.setContent("IMAGE_DATA");221 soapMessageAction.setAttachments(Collections.singletonList(attachment));222 reset(webServiceEndpoint, producer);223 when(webServiceEndpoint.getActor()).thenReturn(null);224 try {225 soapMessageAction.execute(context);226 Assert.fail("Missing exception due to invalid attachment encoding type");227 } catch (CitrusRuntimeException e) {228 Assert.assertEquals(e.getMessage(), "Unsupported encoding type 'md5' for SOAP attachment: cid:mtomImage - choose one of base64Binary or hexBinary");229 }230 }231 @Test232 @SuppressWarnings("rawtypes")233 public void testSoapMessageWithDefaultAttachmentDataTest() throws Exception {234 SendSoapMessageAction soapMessageAction = new SendSoapMessageAction();235 soapMessageAction.setEndpoint(webServiceEndpoint);236 PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();237 messageBuilder.setPayloadData("<TestRequest><Message>Hello World!</Message></TestRequest>");238 SoapAttachment attachment = new SoapAttachment();239 attachment.setContent("<TestAttachment><Message>Hello World!</Message></TestAttachment>");240 soapMessageAction.setAttachments(Collections.singletonList(attachment));241 242 soapMessageAction.setMessageBuilder(messageBuilder);243 244 reset(webServiceEndpoint, producer);245 when(webServiceEndpoint.createProducer()).thenReturn(producer);246 doAnswer(new Answer() {247 @Override248 public Object answer(InvocationOnMock invocation) throws Throwable {249 Assert.assertEquals(((SoapMessage)invocation.getArguments()[0]).getAttachments().size(), 1L);250 SoapAttachment constructedAttachment = ((SoapMessage)invocation.getArguments()[0]).getAttachments().get(0);251 Assert.assertNull(constructedAttachment.getContentId());252 Assert.assertEquals(constructedAttachment.getContentType(), "text/plain");253 Assert.assertEquals(constructedAttachment.getContent(), "<TestAttachment><Message>Hello World!</Message></TestAttachment>");254 Assert.assertEquals(constructedAttachment.getCharsetName(), "UTF-8");255 return null;256 }257 }).when(producer).send(any(Message.class), any(TestContext.class));258 when(webServiceEndpoint.getActor()).thenReturn(null);259 soapMessageAction.execute(context);260 }261 262 @Test263 @SuppressWarnings("rawtypes")264 public void testSoapMessageWithAttachmentDataTest() throws Exception {265 SendSoapMessageAction soapMessageAction = new SendSoapMessageAction();266 soapMessageAction.setEndpoint(webServiceEndpoint);267 268 PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();269 messageBuilder.setPayloadData("<TestRequest><Message>Hello World!</Message></TestRequest>");270 271 soapMessageAction.setMessageBuilder(messageBuilder);272 SoapAttachment attachment = new SoapAttachment();273 attachment.setContentId("myAttachment");274 attachment.setContentType("text/xml");275 attachment.setContent("<TestAttachment><Message>Hello World!</Message></TestAttachment>");276 attachment.setCharsetName("UTF-16");277 soapMessageAction.setAttachments(Collections.singletonList(attachment));278 reset(webServiceEndpoint, producer);279 when(webServiceEndpoint.createProducer()).thenReturn(producer);280 doAnswer(new Answer() {281 @Override282 public Object answer(InvocationOnMock invocation) throws Throwable {283 Assert.assertEquals(((SoapMessage)invocation.getArguments()[0]).getAttachments().size(), 1L);284 SoapAttachment constructedAttachment = ((SoapMessage)invocation.getArguments()[0]).getAttachments().get(0);285 Assert.assertEquals(constructedAttachment.getContentId(), "myAttachment");286 Assert.assertEquals(constructedAttachment.getContentType(), "text/xml");287 Assert.assertEquals(constructedAttachment.getContent(), "<TestAttachment><Message>Hello World!</Message></TestAttachment>");288 Assert.assertEquals(constructedAttachment.getCharsetName(), "UTF-16");289 return null;290 }291 }).when(producer).send(any(Message.class), any(TestContext.class));292 when(webServiceEndpoint.getActor()).thenReturn(null);293 soapMessageAction.execute(context);294 }295 @Test296 @SuppressWarnings("rawtypes")297 public void testSoapMessageWithMultipleAttachmentDataTest() throws Exception {298 SendSoapMessageAction soapMessageAction = new SendSoapMessageAction();299 soapMessageAction.setEndpoint(webServiceEndpoint);300 PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();301 messageBuilder.setPayloadData("<TestRequest><Message>Hello World!</Message></TestRequest>");302 soapMessageAction.setMessageBuilder(messageBuilder);303 List<SoapAttachment> attachments = new ArrayList<SoapAttachment>();304 SoapAttachment attachment = new SoapAttachment();305 attachment.setContentId("1stAttachment");306 attachment.setContentType("text/xml");307 attachment.setContent("<TestAttachment><Message>Hello World1!</Message></TestAttachment>");308 attachment.setCharsetName("UTF-8");309 attachments.add(attachment);310 SoapAttachment attachment2 = new SoapAttachment();311 attachment2.setContentId("2ndAttachment");312 attachment2.setContentType("text/xml");313 attachment2.setContent("<TestAttachment><Message>Hello World2!</Message></TestAttachment>");314 attachment2.setCharsetName("UTF-16");315 attachments.add(attachment2);316 soapMessageAction.setAttachments(attachments);317 reset(webServiceEndpoint, producer);318 when(webServiceEndpoint.createProducer()).thenReturn(producer);319 doAnswer(new Answer() {320 @Override321 public Object answer(InvocationOnMock invocation) throws Throwable {322 Assert.assertEquals(((SoapMessage)invocation.getArguments()[0]).getAttachments().size(), 2L);323 SoapAttachment constructedAttachment = ((SoapMessage)invocation.getArguments()[0]).getAttachments().get(0);324 Assert.assertEquals(constructedAttachment.getContentId(), "1stAttachment");325 Assert.assertEquals(constructedAttachment.getContentType(), "text/xml");326 Assert.assertEquals(constructedAttachment.getContent(), "<TestAttachment><Message>Hello World1!</Message></TestAttachment>");327 Assert.assertEquals(constructedAttachment.getCharsetName(), "UTF-8");328 constructedAttachment = ((SoapMessage)invocation.getArguments()[0]).getAttachments().get(1);329 Assert.assertEquals(constructedAttachment.getContentId(), "2ndAttachment");330 Assert.assertEquals(constructedAttachment.getContentType(), "text/xml");331 Assert.assertEquals(constructedAttachment.getContent(), "<TestAttachment><Message>Hello World2!</Message></TestAttachment>");332 Assert.assertEquals(constructedAttachment.getCharsetName(), "UTF-16");333 return null;334 }335 }).when(producer).send(any(Message.class), any(TestContext.class));336 when(webServiceEndpoint.getActor()).thenReturn(null);337 soapMessageAction.execute(context);338 }339 340 @Test341 @SuppressWarnings("rawtypes")342 public void testSoapMessageWithEmptyAttachmentContentTest() throws Exception {343 SendSoapMessageAction soapMessageAction = new SendSoapMessageAction();344 soapMessageAction.setEndpoint(webServiceEndpoint);345 346 PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();347 messageBuilder.setPayloadData("<TestRequest><Message>Hello World!</Message></TestRequest>");348 349 soapMessageAction.setMessageBuilder(messageBuilder);350 351 reset(webServiceEndpoint, producer);352 when(webServiceEndpoint.createProducer()).thenReturn(producer);353 when(webServiceEndpoint.getActor()).thenReturn(null);354 soapMessageAction.execute(context);355 verify(producer).send(any(Message.class), any(TestContext.class));356 }357 358 @Test359 @SuppressWarnings("rawtypes")360 public void testSoapMessageWithAttachmentResourceTest() throws Exception {361 SendSoapMessageAction soapMessageAction = new SendSoapMessageAction();362 soapMessageAction.setEndpoint(webServiceEndpoint);363 PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();364 messageBuilder.setPayloadData("<TestRequest><Message>Hello World!</Message></TestRequest>");365 SoapAttachment attachment = new SoapAttachment();366 attachment.setContentResourcePath("classpath:com/consol/citrus/ws/actions/test-attachment.xml");367 soapMessageAction.setAttachments(Collections.singletonList(attachment));368 soapMessageAction.setMessageBuilder(messageBuilder);369 370 reset(webServiceEndpoint, producer);371 when(webServiceEndpoint.createProducer()).thenReturn(producer);372 doAnswer(new Answer() {373 @Override374 public Object answer(InvocationOnMock invocation) throws Throwable {375 Assert.assertEquals(((SoapMessage)invocation.getArguments()[0]).getAttachments().size(), 1L);376 SoapAttachment constructedAttachment = ((SoapMessage)invocation.getArguments()[0]).getAttachments().get(0);377 Assert.assertNull(constructedAttachment.getContentId());378 Assert.assertEquals(constructedAttachment.getContentType(), "text/plain");379 Assert.assertEquals(constructedAttachment.getContent(), "<TestAttachment><Message>Hello World!</Message></TestAttachment>");380 Assert.assertEquals(constructedAttachment.getCharsetName(), "UTF-8");381 return null;382 }383 }).when(producer).send(any(Message.class), any(TestContext.class));384 when(webServiceEndpoint.getActor()).thenReturn(null);385 soapMessageAction.execute(context);386 }387 388 @Test389 @SuppressWarnings("rawtypes")390 public void testSoapMessageWithAttachmentDataVariableSupportTest() throws Exception {391 SendSoapMessageAction soapMessageAction = new SendSoapMessageAction();392 soapMessageAction.setEndpoint(webServiceEndpoint);393 PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();394 messageBuilder.setPayloadData("<TestRequest><Message>Hello World!</Message></TestRequest>");395 396 context.setVariable("myText", "Hello World!");397 SoapAttachment attachment = new SoapAttachment();398 attachment.setContent("<TestAttachment><Message>${myText}</Message></TestAttachment>");399 soapMessageAction.setAttachments(Collections.singletonList(attachment));400 soapMessageAction.setMessageBuilder(messageBuilder);401 402 reset(webServiceEndpoint, producer);403 when(webServiceEndpoint.createProducer()).thenReturn(producer);404 doAnswer(new Answer() {405 @Override406 public Object answer(InvocationOnMock invocation) throws Throwable {407 Assert.assertEquals(((SoapMessage)invocation.getArguments()[0]).getAttachments().size(), 1L);408 SoapAttachment constructedAttachment = ((SoapMessage)invocation.getArguments()[0]).getAttachments().get(0);409 Assert.assertNull(constructedAttachment.getContentId());410 Assert.assertEquals(constructedAttachment.getContentType(), "text/plain");411 Assert.assertEquals(constructedAttachment.getContent(), "<TestAttachment><Message>Hello World!</Message></TestAttachment>");412 Assert.assertEquals(constructedAttachment.getCharsetName(), "UTF-8");413 return null;414 }415 }).when(producer).send(any(Message.class), any(TestContext.class));416 when(webServiceEndpoint.getActor()).thenReturn(null);417 soapMessageAction.execute(context);418 }419 420 @Test421 @SuppressWarnings("rawtypes")422 public void testSoapMessageWithAttachmentResourceVariablesSupportTest() throws Exception {423 SendSoapMessageAction soapMessageAction = new SendSoapMessageAction();424 soapMessageAction.setEndpoint(webServiceEndpoint);425 PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();426 messageBuilder.setPayloadData("<TestRequest><Message>Hello World!</Message></TestRequest>");427 428 context.setVariable("myText", "Hello World!");429 SoapAttachment attachment = new SoapAttachment();430 attachment.setContentResourcePath("classpath:com/consol/citrus/ws/actions/test-attachment-with-variables.xml");431 soapMessageAction.setAttachments(Collections.singletonList(attachment));432 soapMessageAction.setMessageBuilder(messageBuilder);433 434 reset(webServiceEndpoint, producer);435 when(webServiceEndpoint.createProducer()).thenReturn(producer);436 doAnswer(new Answer() {437 @Override438 public Object answer(InvocationOnMock invocation) throws Throwable {439 Assert.assertEquals(((SoapMessage)invocation.getArguments()[0]).getAttachments().size(), 1L);440 SoapAttachment constructedAttachment = ((SoapMessage)invocation.getArguments()[0]).getAttachments().get(0);441 Assert.assertNull(constructedAttachment.getContentId());442 Assert.assertEquals(constructedAttachment.getContentType(), "text/plain");443 Assert.assertEquals(constructedAttachment.getContent(), "<TestAttachment><Message>Hello World!</Message></TestAttachment>");444 Assert.assertEquals(constructedAttachment.getCharsetName(), "UTF-8");445 return null;446 }447 }).when(producer).send(any(Message.class), any(TestContext.class));448 when(webServiceEndpoint.getActor()).thenReturn(null);449 soapMessageAction.execute(context);450 }451 452 @Test453 @SuppressWarnings("rawtypes")454 public void testSoapMessageWithHeaderContentTest() throws Exception {455 SendSoapMessageAction soapMessageAction = new SendSoapMessageAction();456 soapMessageAction.setEndpoint(webServiceEndpoint);457 PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();458 messageBuilder.setPayloadData("<TestRequest><Message>Hello World!</Message></TestRequest>");459 460 messageBuilder.getHeaderData().add("<TestHeader><operation>soapOperation</operation></TestHeader>");461 462 soapMessageAction.setMessageBuilder(messageBuilder);463 reset(webServiceEndpoint, producer);464 when(webServiceEndpoint.createProducer()).thenReturn(producer);465 doAnswer(new Answer() {466 @Override467 public Object answer(InvocationOnMock invocation) throws Throwable {468 Message constructedMessage = (Message)invocation.getArguments()[0];469 Assert.assertEquals(constructedMessage.getHeaderData().size(), 1L);470 Assert.assertEquals(constructedMessage.getHeaderData().get(0),471 "<TestHeader><operation>soapOperation</operation></TestHeader>");472 return null;473 }474 }).when(producer).send(any(Message.class), any(TestContext.class));475 when(webServiceEndpoint.getActor()).thenReturn(null);476 soapMessageAction.execute(context);477 }478 @Test479 @SuppressWarnings("rawtypes")480 public void testSoapMessageWithMultipleHeaderContentTest() throws Exception {481 SendSoapMessageAction soapMessageAction = new SendSoapMessageAction();482 soapMessageAction.setEndpoint(webServiceEndpoint);483 PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();484 messageBuilder.setPayloadData("<TestRequest><Message>Hello World!</Message></TestRequest>");485 messageBuilder.getHeaderData().add("<TestHeader><operation>soapOperation1</operation></TestHeader>");486 messageBuilder.getHeaderData().add("<TestHeader><operation>soapOperation2</operation></TestHeader>");487 soapMessageAction.setMessageBuilder(messageBuilder);488 reset(webServiceEndpoint, producer);489 when(webServiceEndpoint.createProducer()).thenReturn(producer);490 doAnswer(new Answer() {491 @Override492 public Object answer(InvocationOnMock invocation) throws Throwable {493 Message constructedMessage = (Message)invocation.getArguments()[0];494 Assert.assertEquals(constructedMessage.getHeaderData().size(), 2L);495 Assert.assertEquals(constructedMessage.getHeaderData().get(0),496 "<TestHeader><operation>soapOperation1</operation></TestHeader>");497 Assert.assertEquals(constructedMessage.getHeaderData().get(1),498 "<TestHeader><operation>soapOperation2</operation></TestHeader>");499 return null;500 }501 }).when(producer).send(any(Message.class), any(TestContext.class));502 when(webServiceEndpoint.getActor()).thenReturn(null);503 soapMessageAction.execute(context);504 }505 506 @Test507 @SuppressWarnings("rawtypes")508 public void testSoapMessageWithHeaderResourceTest() throws Exception {509 SendSoapMessageAction soapMessageAction = new SendSoapMessageAction();510 soapMessageAction.setEndpoint(webServiceEndpoint);511 PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();512 messageBuilder.setPayloadData("<TestRequest><Message>Hello World!</Message></TestRequest>");513 514 messageBuilder.getHeaderResources().add("classpath:com/consol/citrus/ws/actions/test-header-resource.xml");515 516 soapMessageAction.setMessageBuilder(messageBuilder);517 518 reset(webServiceEndpoint, producer);519 when(webServiceEndpoint.createProducer()).thenReturn(producer);520 doAnswer(new Answer() {521 @Override522 public Object answer(InvocationOnMock invocation) throws Throwable {523 Message constructedMessage = (Message)invocation.getArguments()[0];524 Assert.assertEquals(constructedMessage.getHeaderData().size(), 1L);525 Assert.assertEquals(constructedMessage.getHeaderData().get(0),526 "<TestHeader><operation>soapOperation</operation></TestHeader>");527 return null;528 }529 }).when(producer).send(any(Message.class), any(TestContext.class));530 when(webServiceEndpoint.getActor()).thenReturn(null);531 soapMessageAction.execute(context);532 }533 534 @Test535 @SuppressWarnings("rawtypes")536 public void testSoapMessageWithHeaderContentVariableSupportTest() throws Exception {537 SendSoapMessageAction soapMessageAction = new SendSoapMessageAction();538 soapMessageAction.setEndpoint(webServiceEndpoint);539 PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();540 messageBuilder.setPayloadData("<TestRequest><Message>Hello World!</Message></TestRequest>");541 542 context.setVariable("operation", "soapOperation");543 544 messageBuilder.getHeaderData().add("<TestHeader><operation>${operation}</operation></TestHeader>");545 546 soapMessageAction.setMessageBuilder(messageBuilder);547 reset(webServiceEndpoint, producer);548 when(webServiceEndpoint.createProducer()).thenReturn(producer);549 doAnswer(new Answer() {550 @Override551 public Object answer(InvocationOnMock invocation) throws Throwable {552 Message constructedMessage = (Message)invocation.getArguments()[0];553 Assert.assertEquals(constructedMessage.getHeaderData().size(), 1L);554 Assert.assertEquals(constructedMessage.getHeaderData().get(0),555 "<TestHeader><operation>soapOperation</operation></TestHeader>");556 return null;557 }558 }).when(producer).send(any(Message.class), any(TestContext.class));559 when(webServiceEndpoint.getActor()).thenReturn(null);560 soapMessageAction.execute(context);561 }562 563 @Test564 @SuppressWarnings("rawtypes")565 public void testSoapMessageWithHeaderResourceVariableSupportTest() throws Exception {566 SendSoapMessageAction soapMessageAction = new SendSoapMessageAction();567 soapMessageAction.setEndpoint(webServiceEndpoint);568 PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();569 messageBuilder.setPayloadData("<TestRequest><Message>Hello World!</Message></TestRequest>");570 571 context.setVariable("operation", "soapOperation");572 573 messageBuilder.getHeaderResources().add("classpath:com/consol/citrus/ws/actions/test-header-resource-with-variables.xml");574 575 soapMessageAction.setMessageBuilder(messageBuilder);576 reset(webServiceEndpoint, producer);577 when(webServiceEndpoint.createProducer()).thenReturn(producer);578 doAnswer(new Answer() {579 @Override580 public Object answer(InvocationOnMock invocation) throws Throwable {581 Message constructedMessage = (Message)invocation.getArguments()[0];582 Assert.assertEquals(constructedMessage.getHeaderData().size(), 1L);583 Assert.assertEquals(constructedMessage.getHeaderData().get(0),584 "<TestHeader><operation>soapOperation</operation></TestHeader>");585 return null;586 }587 }).when(producer).send(any(Message.class), any(TestContext.class));588 when(webServiceEndpoint.getActor()).thenReturn(null);589 soapMessageAction.execute(context);590 }591}...

Full Screen

Full Screen

answer

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.ws.actions;2import static com.consol.citrus.actions.EchoAction.Builder.echo;3import static com.consol.citrus.actions.SendMessageAction.Builder.withMessage;4import static com.consol.citrus.actions.SoapActionBuilder.soap;5import static com.consol.citrus.actions.ValidateSoapMessageAction.Builder.validateSoapMessage;6import static com.consol.citrus.container.Assert.Builder.assertException;7import static com.consol.citrus.container.Sequence.Builder.sequential;8import static com.consol.citrus.container.Wait.Builder.waitFor;9import static com.consol.citrus.ws.actions.SendSoa

Full Screen

Full Screen

answer

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.ws.actions;2import com.consol.citrus.annotations.CitrusTest;3import com.consol.citrus.dsl.junit.JUnit4CitrusTestRunner;4import com.consol.citrus.dsl.testng.TestNGCitrusTestRunner;5import com.consol.citrus.message.MessageType;6import com.consol.citrus.testng.CitrusParameters;7import org.testng.annotations.Test;8public class SendSoapMessageActionTest extends JUnit4CitrusTestRunner {9 public void sendSoapMessage() {10 variable("messageId", "citrus:randomNumber(10)");11 variable("operation", "echoOperation");12 send("webServiceClient")13 .soap()14 .messageType(MessageType.PLAINTEXT)15 "</ns0:echoOperation>");16 receive("webServiceServer")17 .soap()18 "</ns0:echoOperationResponse>");19 send("webServiceClient")20 .soap()21 .messageType(MessageType.PLAINTEXT)22 .extractFromHeader("citrus_jms_messageId", "messageId");23 receive("webServiceServer")24 .soap()25 .header("citrus_jms_correlationId", "${messageId}")26 .header("citrus_soap_action", "${operation}");27 send("webServiceClient")28 .soap()29 .messageType(MessageType.PLAINTEXT)

Full Screen

Full Screen

answer

Using AI Code Generation

copy

Full Screen

1import com.consol.citrus.annotations.CitrusTest;2import com.consol.citrus.dsl.junit.JUnit4CitrusTestDesigner;3import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;4import com.consol.citrus.message.MessageType;5import com.consol.citrus.ws.actions.SendSoapMessageAction;6import com.consol.citrus.ws.client.WebServiceClient;7import com.consol.citrus.ws.message.SoapMessage;8import com.consol.citrus.ws.validation.SoapAttachmentValidator;9import com.consol.citrus.ws.validation.SoapFaultDetailValidator;10import com.consol.citrus.ws.validation.SoapFaultValidator;11import com.consol.citrus.ws.validation.SoapHeaderValidator;12import com.consol.citrus.ws.validation.SoapMessageValidator;13import com.consol.citrus.ws.validation.SoapPayloadXpathMessageValidator;14import com.consol.citrus.ws.validation.SoapSchemaValidationContext;15import com.consol.citrus.ws.validation.SoapSchemaValidator;16import com.consol.citrus.ws.validation.SoapSoapActionValidator;17import com.consol.citrus.ws.validation.SoapValidationContext;18import com.consol.citrus.ws.validation.SoapValidationContextValidationProcessor;19import com.consol.citrus.ws.validation.SoapValidator;20import com.consol.citrus.ws.validation.SoapValidatorRegistry;21import com.consol.citrus.ws.validation.SoapXpathMessageValidationContext;22import com.consol.citrus.ws.validation.SoapXpathMessageValidator;23import com.consol.citrus.ws.validation.SoapXpathPayloadValidationContext;24import com.consol.citrus.ws.validation.SoapXpathPayloadValidator;25import com.consol.citrus.ws.validation.SoapXpathValidationContext;26import com.consol.citrus.ws.validation.SoapXpathValidator;27import org.easymock.EasyMock;28import org.springframework.beans.factory.annotation.Autowired;29import org.springframework.core.io.ClassPathResource;30import org.springframework.core.io.Resource;31import org.springframework.ws.WebServiceMessage;32import org.springframework.ws.soap.SoapMessageFactory;33import org.springframework.ws.soap.SoapVersion;34import org.springframework.ws.soap.saaj.SaajSoapMessageFactory;35import org.springframework.xml.validation.XmlValidator;36import org.testng.annotations.Test;37import javax.xml.namespace.QName;38import javax.xml.transform.Source;

Full Screen

Full Screen

answer

Using AI Code Generation

copy

Full Screen

1public void testSendSoapMessage() {2 MockEndpoint messageEndpoint = getMockEndpoint("mock:soapMessage");3 messageEndpoint.expectedMessageCount(1);4 messageEndpoint.expectedHeaderReceived("operation", "echo");5 messageEndpoint.expectedHeaderReceived("citrus_soap_action", "urn:echo");6 messageEndpoint.expectedHeaderReceived("citrus_soap_version", "1.1");7 messageEndpoint.expectedHeaderReceived("citrus_soap_fault", "false");8 messageEndpoint.expectedHeaderReceived("citrus_soap_fault_code", "Server");9 messageEndpoint.expectedHeaderReceived("citrus_soap_fault_string", "Server Error");10 messageEndpoint.expectedHeaderReceived("citrus_soap_fault_actor", "Server");11 messageEndpoint.expectedHeaderReceived("citrus_soap_fault_detail", "Server Error");12 messageEndpoint.expectedHeaderReceived("citrus_soap_fault_reason", "Server Error");13 messageEndpoint.expectedHeaderReceived("citrus_soap_fault_role", "Server");14 messageEndpoint.expectedHeaderReceived("citrus_soap_fault_subcode", "Server");15 messageEndpoint.expectedHeaderReceived("citrus_soap_fault_value", "Server");16 messageEndpoint.expectedHeaderReceived("citrus_soap_fault_reason_text", "Server Error");17 messageEndpoint.expectedHeaderReceived("citrus_soap_fault_reason_lang", "en");18 messageEndpoint.expectedHeaderReceived("citrus_soap_fault_node", "Server");19 messageEndpoint.expectedHeaderReceived("citrus_soap_fault_role", "Server");

Full Screen

Full Screen

answer

Using AI Code Generation

copy

Full Screen

1 .soap()2 .message()3 .messageType("mySoapMessageType")4 .answer()5 .validator(new MySoapMessageValidator());6 .soap()7 .message()8 .messageType("mySoapMessageType")9 .answer()10 .validator(new MySoapMessageValidator())11 .endpoint("mySoapMessageReplyEndpoint");12 .soap()13 .message()14 .messageType("mySoapMessageType")15 .answer()16 .validator(new MySoapMessageValidator())17 .endpoint("mySoapMessageReplyEndpoint")18 .timeout(5000L);19 .soap()20 .message()21 .messageType("mySoapMessageType")22 .answer()23 .validator(new MySoapMessageValidator())24 .endpoint("mySoapMessageReplyEndpoint")25 .timeout(5000L)26 .selector(new MySoapMessageSelector());27 .soap()28 .message()29 .messageType("mySoapMessageType")30 .body("<ns0:my

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