How to use getContent method of com.consol.citrus.ws.message.SoapAttachment class

Best Citrus code snippet using com.consol.citrus.ws.message.SoapAttachment.getContent

Source:SendSoapMessageActionTest.java Github

copy

Full Screen

...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();...

Full Screen

Full Screen

Source:ReceiveSoapMessageActionTest.java Github

copy

Full Screen

...67 @Override68 public Object answer(InvocationOnMock invocation) throws Throwable {69 Assert.assertEquals(((List<SoapAttachment>)invocation.getArguments()[1]).size(), 1L);70 SoapAttachment soapAttachment = ((List<SoapAttachment>)invocation.getArguments()[1]).get(0);71 Assert.assertEquals(soapAttachment.getContent(), "TestAttachment!");72 Assert.assertNull(soapAttachment.getContentId());73 Assert.assertEquals(soapAttachment.getContentType(), "text/plain");74 return null;75 }76 }).when(attachmentValidator).validateAttachment((SoapMessage)any(), any(List.class));77 when(endpoint.getActor()).thenReturn(null);78 79 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();80 validationContexts.add(validationContext);81 soapMessageAction.setValidationContexts(validationContexts);82 soapMessageAction.execute(context);83 }84 @Test85 public void testSoapMessageWithAttachmentDataTest() throws Exception {86 ReceiveSoapMessageAction soapMessageAction = new ReceiveSoapMessageAction();87 soapMessageAction.setEndpoint(endpoint);88 soapMessageAction.setAttachmentValidator(attachmentValidator);89 soapMessageAction.addValidator(new DomXmlMessageValidator());90 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();91 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();92 soapMessageAction.setMessageBuilder(controlMessageBuilder);93 controlMessageBuilder.setPayloadData("<TestRequest><Message>Hello World!</Message></TestRequest>");94 SoapAttachment attachment = new SoapAttachment();95 attachment.setContentId("myAttachment");96 attachment.setContentType("text/xml");97 attachment.setContent("<TestAttachment><Message>Hello World!</Message></TestAttachment>");98 attachment.setCharsetName("UTF-16");99 soapMessageAction.setAttachments(Collections.singletonList(attachment));100 Message controlMessage = new SoapMessage("<TestRequest><Message>Hello World!</Message></TestRequest>");101 reset(endpoint, consumer, endpointConfiguration, attachmentValidator);102 when(endpoint.createConsumer()).thenReturn(consumer);103 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);104 when(endpointConfiguration.getTimeout()).thenReturn(5000L);105 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(controlMessage);106 doAnswer(new Answer() {107 @Override108 public Object answer(InvocationOnMock invocation) throws Throwable {109 Assert.assertEquals(((List<SoapAttachment>)invocation.getArguments()[1]).size(), 1L);110 SoapAttachment soapAttachment = ((List<SoapAttachment>)invocation.getArguments()[1]).get(0);111 Assert.assertEquals(soapAttachment.getContent(), "<TestAttachment><Message>Hello World!</Message></TestAttachment>");112 Assert.assertEquals(soapAttachment.getContentId(), "myAttachment");113 Assert.assertEquals(soapAttachment.getContentType(), "text/xml");114 Assert.assertEquals(soapAttachment.getCharsetName(), "UTF-16");115 return null;116 }117 }).when(attachmentValidator).validateAttachment((SoapMessage)any(), (List)any());118 when(endpoint.getActor()).thenReturn(null);119 120 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();121 validationContexts.add(validationContext);122 soapMessageAction.setValidationContexts(validationContexts);123 soapMessageAction.execute(context);124 }125 @Test126 public void testSoapMessageWithMultipleAttachmentDataTest() throws Exception {127 ReceiveSoapMessageAction soapMessageAction = new ReceiveSoapMessageAction();128 soapMessageAction.setEndpoint(endpoint);129 soapMessageAction.setAttachmentValidator(attachmentValidator);130 soapMessageAction.addValidator(new DomXmlMessageValidator());131 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();132 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();133 soapMessageAction.setMessageBuilder(controlMessageBuilder);134 controlMessageBuilder.setPayloadData("<TestRequest><Message>Hello World!</Message></TestRequest>");135 List<SoapAttachment> attachments = new ArrayList<SoapAttachment>();136 SoapAttachment attachment = new SoapAttachment();137 attachment.setContentId("1stAttachment");138 attachment.setContentType("text/xml");139 attachment.setContent("<TestAttachment><Message>Hello World1!</Message></TestAttachment>");140 attachment.setCharsetName("UTF-8");141 attachments.add(attachment);142 SoapAttachment attachment2 = new SoapAttachment();143 attachment2.setContentId("2ndAttachment");144 attachment2.setContentType("text/xml");145 attachment2.setContent("<TestAttachment><Message>Hello World2!</Message></TestAttachment>");146 attachment2.setCharsetName("UTF-16");147 attachments.add(attachment2);148 soapMessageAction.setAttachments(attachments);149 Message controlMessage = new SoapMessage("<TestRequest><Message>Hello World!</Message></TestRequest>");150 reset(endpoint, consumer, endpointConfiguration, attachmentValidator);151 when(endpoint.createConsumer()).thenReturn(consumer);152 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);153 when(endpointConfiguration.getTimeout()).thenReturn(5000L);154 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(controlMessage);155 doAnswer(new Answer() {156 @Override157 public Object answer(InvocationOnMock invocation) throws Throwable {158 Assert.assertEquals(((List<SoapAttachment>)invocation.getArguments()[1]).size(), 2L);159 SoapAttachment soapAttachment = ((List<SoapAttachment>)invocation.getArguments()[1]).get(0);160 Assert.assertEquals(soapAttachment.getContent(), "<TestAttachment><Message>Hello World1!</Message></TestAttachment>");161 Assert.assertEquals(soapAttachment.getContentId(), "1stAttachment");162 Assert.assertEquals(soapAttachment.getContentType(), "text/xml");163 Assert.assertEquals(soapAttachment.getCharsetName(), "UTF-8");164 soapAttachment = ((List<SoapAttachment>)invocation.getArguments()[1]).get(1);165 Assert.assertEquals(soapAttachment.getContent(), "<TestAttachment><Message>Hello World2!</Message></TestAttachment>");166 Assert.assertEquals(soapAttachment.getContentId(), "2ndAttachment");167 Assert.assertEquals(soapAttachment.getContentType(), "text/xml");168 Assert.assertEquals(soapAttachment.getCharsetName(), "UTF-16");169 return null;170 }171 }).when(attachmentValidator).validateAttachment((SoapMessage)any(), (List)any());172 when(endpoint.getActor()).thenReturn(null);173 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();174 validationContexts.add(validationContext);175 soapMessageAction.setValidationContexts(validationContexts);176 soapMessageAction.execute(context);177 }178 179 @Test180 public void testSoapMessageWithEmptyAttachmentContentTest() throws Exception {181 ReceiveSoapMessageAction soapMessageAction = new ReceiveSoapMessageAction();182 soapMessageAction.setEndpoint(endpoint);183 soapMessageAction.setAttachmentValidator(attachmentValidator);184 soapMessageAction.addValidator(new DomXmlMessageValidator());185 186 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();187 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();188 soapMessageAction.setMessageBuilder(controlMessageBuilder);189 controlMessageBuilder.setPayloadData("<TestRequest><Message>Hello World!</Message></TestRequest>");190 SoapAttachment attachment = new SoapAttachment();191 attachment.setContentId("myAttachment");192 attachment.setContent("");193 soapMessageAction.setAttachments(Collections.singletonList(attachment));194 Message controlMessage = new SoapMessage("<TestRequest><Message>Hello World!</Message></TestRequest>");195 reset(endpoint, consumer, endpointConfiguration, attachmentValidator);196 when(endpoint.createConsumer()).thenReturn(consumer);197 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);198 when(endpointConfiguration.getTimeout()).thenReturn(5000L);199 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(controlMessage);200 doAnswer(new Answer() {201 @Override202 public Object answer(InvocationOnMock invocation) throws Throwable {203 Assert.assertEquals(((List<SoapAttachment>)invocation.getArguments()[1]).size(), 1L);204 SoapAttachment soapAttachment = ((List<SoapAttachment>)invocation.getArguments()[1]).get(0);205 Assert.assertEquals(soapAttachment.getContent(), "");206 Assert.assertEquals(soapAttachment.getContentId(), "myAttachment");207 Assert.assertEquals(soapAttachment.getContentType(), "text/plain");208 Assert.assertEquals(soapAttachment.getCharsetName(), "UTF-8");209 return null;210 }211 }).when(attachmentValidator).validateAttachment((SoapMessage)any(), (List) any());212 when(endpoint.getActor()).thenReturn(null);213 214 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();215 validationContexts.add(validationContext);216 soapMessageAction.setValidationContexts(validationContexts);217 soapMessageAction.execute(context);218 }219 220 @Test221 public void testSoapMessageWithNoAttachmentExpected() throws Exception {222 ReceiveSoapMessageAction soapMessageAction = new ReceiveSoapMessageAction();223 soapMessageAction.setEndpoint(endpoint);224 soapMessageAction.setAttachmentValidator(attachmentValidator);225 226 soapMessageAction.addValidator(new DomXmlMessageValidator());227 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();228 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();229 soapMessageAction.setMessageBuilder(controlMessageBuilder);230 controlMessageBuilder.setPayloadData("<TestRequest><Message>Hello World!</Message></TestRequest>");231 232 Message controlMessage = new SoapMessage("<TestRequest><Message>Hello World!</Message></TestRequest>");233 reset(endpoint, consumer, endpointConfiguration, attachmentValidator);234 when(endpoint.createConsumer()).thenReturn(consumer);235 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);236 when(endpointConfiguration.getTimeout()).thenReturn(5000L);237 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(controlMessage);238 when(endpoint.getActor()).thenReturn(null);239 240 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();241 validationContexts.add(validationContext);242 soapMessageAction.setValidationContexts(validationContexts);243 soapMessageAction.execute(context);244 }245 246 @Test247 public void testSoapMessageWithAttachmentResourceTest() throws Exception {248 ReceiveSoapMessageAction soapMessageAction = new ReceiveSoapMessageAction();249 soapMessageAction.setEndpoint(endpoint);250 soapMessageAction.setAttachmentValidator(attachmentValidator);251 soapMessageAction.addValidator(new DomXmlMessageValidator());252 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();253 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();254 soapMessageAction.setMessageBuilder(controlMessageBuilder);255 controlMessageBuilder.setPayloadData("<TestRequest><Message>Hello World!</Message></TestRequest>");256 SoapAttachment attachment = new SoapAttachment();257 attachment.setContentId("myAttachment");258 attachment.setContentType("text/xml");259 attachment.setContentResourcePath("classpath:com/consol/citrus/ws/actions/test-attachment.xml");260 soapMessageAction.setAttachments(Collections.singletonList(attachment));261 Message controlMessage = new SoapMessage("<TestRequest><Message>Hello World!</Message></TestRequest>");262 reset(endpoint, consumer, endpointConfiguration, attachmentValidator);263 when(endpoint.createConsumer()).thenReturn(consumer);264 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);265 when(endpointConfiguration.getTimeout()).thenReturn(5000L);266 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(controlMessage);267 doAnswer(new Answer() {268 @Override269 public Object answer(InvocationOnMock invocation) throws Throwable {270 Assert.assertEquals(((List<SoapAttachment>)invocation.getArguments()[1]).size(), 1L);271 SoapAttachment soapAttachment = ((List<SoapAttachment>)invocation.getArguments()[1]).get(0);272 Assert.assertEquals(soapAttachment.getContent(), "<TestAttachment><Message>Hello World!</Message></TestAttachment>");273 Assert.assertEquals(soapAttachment.getContentId(), "myAttachment");274 Assert.assertEquals(soapAttachment.getContentType(), "text/xml");275 Assert.assertEquals(soapAttachment.getCharsetName(), "UTF-8");276 return null;277 }278 }).when(attachmentValidator).validateAttachment((SoapMessage)any(), (List) any());279 when(endpoint.getActor()).thenReturn(null);280 281 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();282 validationContexts.add(validationContext);283 soapMessageAction.setValidationContexts(validationContexts);284 soapMessageAction.execute(context);285 }286 287 @Test288 public void testSoapMessageWithAttachmentResourceVariablesSupportTest() throws Exception {289 ReceiveSoapMessageAction soapMessageAction = new ReceiveSoapMessageAction();290 soapMessageAction.setEndpoint(endpoint);291 soapMessageAction.setAttachmentValidator(attachmentValidator);292 soapMessageAction.addValidator(new DomXmlMessageValidator());293 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();294 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();295 soapMessageAction.setMessageBuilder(controlMessageBuilder);296 controlMessageBuilder.setPayloadData("<TestRequest><Message>Hello World!</Message></TestRequest>");297 298 context.setVariable("myText", "Hello World!");299 SoapAttachment attachment = new SoapAttachment();300 attachment.setContentId("myAttachment");301 attachment.setContentType("text/xml");302 attachment.setContentResourcePath("classpath:com/consol/citrus/ws/actions/test-attachment-with-variables.xml");303 soapMessageAction.setAttachments(Collections.singletonList(attachment));304 Message controlMessage = new SoapMessage("<TestRequest><Message>Hello World!</Message></TestRequest>");305 reset(endpoint, consumer, endpointConfiguration, attachmentValidator);306 when(endpoint.createConsumer()).thenReturn(consumer);307 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);308 when(endpointConfiguration.getTimeout()).thenReturn(5000L);309 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(controlMessage);310 doAnswer(new Answer() {311 @Override312 public Object answer(InvocationOnMock invocation) throws Throwable {313 Assert.assertEquals(((List<SoapAttachment>)invocation.getArguments()[1]).size(), 1L);314 SoapAttachment soapAttachment = ((List<SoapAttachment>)invocation.getArguments()[1]).get(0);315 Assert.assertEquals(soapAttachment.getContent(), "<TestAttachment><Message>Hello World!</Message></TestAttachment>");316 Assert.assertEquals(soapAttachment.getContentId(), "myAttachment");317 Assert.assertEquals(soapAttachment.getContentType(), "text/xml");318 Assert.assertEquals(soapAttachment.getCharsetName(), "UTF-8");319 return null;320 }321 }).when(attachmentValidator).validateAttachment((SoapMessage)any(), (List) any());322 when(endpoint.getActor()).thenReturn(null);323 324 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();325 validationContexts.add(validationContext);326 soapMessageAction.setValidationContexts(validationContexts);327 soapMessageAction.execute(context);328 }329 330 @Test331 public void testSoapMessageWithAttachmentDataVariablesSupportTest() throws Exception {332 ReceiveSoapMessageAction soapMessageAction = new ReceiveSoapMessageAction();333 soapMessageAction.setEndpoint(endpoint);334 soapMessageAction.setAttachmentValidator(attachmentValidator);335 soapMessageAction.addValidator(new DomXmlMessageValidator());336 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();337 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();338 soapMessageAction.setMessageBuilder(controlMessageBuilder);339 controlMessageBuilder.setPayloadData("<TestRequest><Message>Hello World!</Message></TestRequest>");340 341 context.setVariable("myText", "Hello World!");342 SoapAttachment attachment = new SoapAttachment();343 attachment.setContentId("myAttachment");344 attachment.setContentType("text/xml");345 attachment.setContent("<TestAttachment><Message>${myText}</Message></TestAttachment>");346 soapMessageAction.setAttachments(Collections.singletonList(attachment));347 Message controlMessage = new SoapMessage("<TestRequest><Message>Hello World!</Message></TestRequest>");348 reset(endpoint, consumer, endpointConfiguration, attachmentValidator);349 when(endpoint.createConsumer()).thenReturn(consumer);350 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);351 when(endpointConfiguration.getTimeout()).thenReturn(5000L);352 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(controlMessage);353 doAnswer(new Answer() {354 @Override355 public Object answer(InvocationOnMock invocation) throws Throwable {356 Assert.assertEquals(((List<SoapAttachment>)invocation.getArguments()[1]).size(), 1L);357 SoapAttachment soapAttachment = ((List<SoapAttachment>)invocation.getArguments()[1]).get(0);358 Assert.assertEquals(soapAttachment.getContent(), "<TestAttachment><Message>Hello World!</Message></TestAttachment>");359 Assert.assertEquals(soapAttachment.getContentId(), "myAttachment");360 Assert.assertEquals(soapAttachment.getContentType(), "text/xml");361 Assert.assertEquals(soapAttachment.getCharsetName(), "UTF-8");362 return null;363 }364 }).when(attachmentValidator).validateAttachment((SoapMessage)any(), (List) any());365 when(endpoint.getActor()).thenReturn(null);366 367 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();368 validationContexts.add(validationContext);369 soapMessageAction.setValidationContexts(validationContexts);370 soapMessageAction.execute(context);371 }372}...

Full Screen

Full Screen

Source:SoapAttachmentTest.java Github

copy

Full Screen

...33 private Attachment attachment = Mockito.mock(Attachment.class);34 @Test35 public void testFromAttachment() throws Exception {36 reset(attachment);37 when(attachment.getContentId()).thenReturn("mail");38 when(attachment.getContentType()).thenReturn("text/plain");39 when(attachment.getInputStream()).thenReturn(new StaticTextDataSource("This is mail text content!", "text/plain", "UTF-8", "mail").getInputStream());40 SoapAttachment soapAttachment = SoapAttachment.from(attachment);41 Assert.assertEquals(soapAttachment.getContentId(), "mail");42 Assert.assertEquals(soapAttachment.getContentType(), "text/plain");43 Assert.assertEquals(soapAttachment.getContent(), "This is mail text content!");44 Assert.assertEquals(soapAttachment.getCharsetName(), Charset.defaultCharset().displayName());45 Assert.assertNotNull(soapAttachment.getDataHandler());46 Assert.assertEquals(soapAttachment.getSize(), 26L);47 }48 @Test49 public void testFromBinaryAttachment() throws Exception {50 reset(attachment);51 when(attachment.getContentId()).thenReturn("img");52 when(attachment.getContentType()).thenReturn("application/octet-stream");53 when(attachment.getDataHandler()).thenReturn(new DataHandler(new StaticTextDataSource("This is img text content!", "application/octet-stream", "UTF-8", "img")));54 SoapAttachment soapAttachment = SoapAttachment.from(attachment);55 Assert.assertEquals(soapAttachment.getContentId(), "img");56 Assert.assertEquals(soapAttachment.getContentType(), "application/octet-stream");57 Assert.assertEquals(soapAttachment.getContent(), Base64.encodeBase64String("This is img text content!".getBytes(Charset.forName("UTF-8"))));58 Assert.assertEquals(soapAttachment.getCharsetName(), Charset.defaultCharset().displayName());59 Assert.assertNotNull(soapAttachment.getDataHandler());60 Assert.assertEquals(soapAttachment.getSize(), 25L);61 soapAttachment.setEncodingType(SoapAttachment.ENCODING_BASE64_BINARY);62 Assert.assertEquals(soapAttachment.getContent(), Base64.encodeBase64String("This is img text content!".getBytes(Charset.forName("UTF-8"))));63 soapAttachment.setEncodingType(SoapAttachment.ENCODING_HEX_BINARY);64 Assert.assertEquals(soapAttachment.getContent(), Hex.encodeHexString("This is img text content!".getBytes(Charset.forName("UTF-8"))).toUpperCase());65 }66 @Test67 public void testFileResourceTextContent() throws Exception {68 SoapAttachment soapAttachment = new SoapAttachment();69 soapAttachment.setContentResourcePath("classpath:com/consol/citrus/ws/actions/test-attachment.xml");70 soapAttachment.setContentType("text/xml");71 Assert.assertEquals(soapAttachment.getContent(), "<TestAttachment><Message>Hello World!</Message></TestAttachment>");72 Assert.assertNotNull(soapAttachment.getDataHandler());73 Assert.assertEquals(soapAttachment.getSize(), 64L);74 }75 @Test76 public void testFileResourceBinaryContent() throws Exception {77 String imageUrl = "/com/consol/citrus/ws/actions/test-attachment.png";78 SoapAttachment soapAttachment = new SoapAttachment();79 soapAttachment.setContentResourcePath("classpath:" + imageUrl);80 soapAttachment.setContentType("image/png");81 String attachmentContent = soapAttachment.getContent();82 byte[] resourceContent = Files.readAllBytes(Paths.get(getClass().getResource(imageUrl).toURI()));83 Assert.assertEquals(attachmentContent, Base64.encodeBase64String(resourceContent));84 Assert.assertEquals(soapAttachment.getSize(), resourceContent.length);85 }86 private class StaticTextDataSource implements DataSource {87 private final String content;88 private final String contentType;89 private final String charsetName;90 private final String contentId;91 private StaticTextDataSource(String content, String contentType, String charsetName, String contentId) {92 this.content = content;93 this.contentType = contentType;94 this.charsetName = charsetName;95 this.contentId = contentId;96 }97 @Override98 public InputStream getInputStream() throws IOException {99 return new ByteArrayInputStream(content.getBytes(charsetName));100 }101 @Override102 public String getContentType() {103 return contentType;104 }105 @Override106 public String getName() {107 return contentId;108 }109 @Override110 public OutputStream getOutputStream() throws IOException {111 throw new UnsupportedOperationException();112 }113 }114}...

Full Screen

Full Screen

getContent

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.ws.message;2import com.consol.citrus.exceptions.CitrusRuntimeException;3import com.consol.citrus.message.Message;4import com.consol.citrus.testng.AbstractTestNGUnitTest;5import org.testng.Assert;6import org.testng.annotations.Test;7import javax.activation.DataHandler;8import javax.activation.DataSource;9import javax.mail.util.ByteArrayDataSource;10import java.io.IOException;11import java.io.InputStream;12public class SoapAttachmentTest extends AbstractTestNGUnitTest {13 public void testSoapAttachment() throws IOException {14 DataSource dataSource = new ByteArrayDataSource("test", "text/plain");15 DataHandler dataHandler = new DataHandler(dataSource);16 SoapAttachment soapAttachment = new SoapAttachment("id1", dataHandler);17 Assert.assertEquals(soapAttachment.getContent(), "test");18 }19 public void testSoapAttachmentMessage() throws IOException {20 DataSource dataSource = new ByteArrayDataSource("test", "text/plain");21 DataHandler dataHandler = new DataHandler(dataSource);22 SoapAttachment soapAttachment = new SoapAttachment("id1", dataHandler);23 Message message = new Message(soapAttachment);24 Assert.assertEquals(message.getPayload(String.class), "test");25 }26 public void testSoapAttachmentInputStream() throws IOException {27 DataSource dataSource = new ByteArrayDataSource("test", "text/plain");28 DataHandler dataHandler = new DataHandler(dataSource);29 SoapAttachment soapAttachment = new SoapAttachment("id1", dataHandler);30 Message message = new Message(soapAttachment);31 try (InputStream is = message.getPayload(InputStream.class)) {32 byte[] bytes = new byte[is.available()];33 is.read(bytes);34 Assert.assertEquals(new String(bytes), "test");35 }36 }37 @Test(expectedExceptions = CitrusRuntimeException.class)38 public void testSoapAttachmentInputStreamError() throws IOException {39 DataSource dataSource = new ByteArrayDataSource("test", "text/plain");40 DataHandler dataHandler = new DataHandler(dataSource);41 SoapAttachment soapAttachment = new SoapAttachment("id1", dataHandler);42 Message message = new Message(soapAttachment);43 try (InputStream is = message.getPayload(InputStream.class)) {44 byte[] bytes = new byte[is.available()];45 is.read(bytes);46 Assert.assertEquals(new String(bytes), "test");47 is.read(bytes);48 }49 }50}51package com.consol.citrus.ws.message;52import com.consol.c

Full Screen

Full Screen

getContent

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.ws.actions;2import com.consol.citrus.exceptions.ValidationException;3import com.consol.citrus.testng.AbstractTestNGUnitTest;4import com.consol.citrus.validation.context.ValidationContext;5import com.consol.citrus.ws.message.SoapAttachment;6import org.mockito.Mockito;7import org.springframework.core.io.ClassPathResource;8import org.springframework.core.io.Resource;9import org.springframework.ws.soap.SoapMessage;10import org.springframework.ws.soap.SoapMessageFactory;11import org.springframework.ws.soap.SoapPart;12import org.springframework.ws.soap.attachment.Attachment;13import org.springframework.ws.soap.attachment.AttachmentContentResolver;14import org.springframework.ws.soap.attachment.AttachmentException;15import org.testng.Assert;16import org.testng.annotations.Test;17import javax.xml.transform.Source;18import javax.xml.transform.stream.StreamSource;19import java.io.IOException;20import java.io.InputStream;21import java.util.Collections;22import static org.mockito.Mockito.*;23public class ReceiveSoapAttachmentActionTest extends AbstractTestNGUnitTest {24 private SoapMessageFactory messageFactory = Mockito.mock(SoapMessageFactory.class);25 private SoapMessage message = Mockito.mock(SoapMessage.class);26 private SoapPart soapPart = Mockito.mock(SoapPart.class);27 private AttachmentContentResolver attachmentContentResolver = Mockito.mock(AttachmentContentResolver.class);28 public void testReceiveAttachment() throws IOException, AttachmentException {29 Resource resource = new ClassPathResource("com/consol/citrus/ws/actions/test-attachment.xml", ReceiveSoapAttachmentActionTest.class);30 when(messageFactory.createWebServiceMessage()).thenReturn(message);31 when(message.getSoapPart()).thenReturn(soapPart);32 when(soapPart.getAttachmentContentResolver()).thenReturn(attachmentContentResolver);33 when(soapPart.getAttachments()).thenReturn(Collections.singletonList(new Attachment() {34 public String getContentId() {35 return "cid:attachment";36 }37 public String getContentType() {38 return "text/xml";39 }40 public String getContentTransferEncoding() {41 return null;42 }43 public InputStream getInputStream() throws AttachmentException {44 return resource.getInputStream();45 }46 public Source getSource() throws AttachmentException {47 return new StreamSource(resource.getInputStream());48 }49 }));50 ReceiveSoapAttachmentAction action = new ReceiveSoapAttachmentAction();51 action.setMessageFactory(messageFactory);52 action.setAttachmentId("cid:

Full Screen

Full Screen

getContent

Using AI Code Generation

copy

Full Screen

1SoapAttachment attachment = new SoapAttachment();2String content = attachment.getContent();3SoapAttachment attachment = new SoapAttachment();4String contentType = attachment.getContentType();5SoapAttachment attachment = new SoapAttachment();6String fileName = attachment.getFileName();7SoapAttachment attachment = new SoapAttachment();8Map<String, String> headers = attachment.getHeaders();9SoapAttachment attachment = new SoapAttachment();10attachment.setFileName("test.txt");11SoapAttachment attachment = new SoapAttachment();12Map<String, String> headers = new HashMap<String, String>();13attachment.setHeaders(headers);14SoapAttachment attachment = new SoapAttachment();15attachment.setContentType("text/xml");16SoapAttachment attachment = new SoapAttachment();17attachment.setContent("test");18SoapAttachment attachment = new SoapAttachment();19String toString = attachment.toString();20SoapAttachment attachment = new SoapAttachment();21int hashCode = attachment.hashCode();22SoapAttachment attachment = new SoapAttachment();23boolean equals = attachment.equals(new Object());

Full Screen

Full Screen

getContent

Using AI Code Generation

copy

Full Screen

1SoapAttachment soapAttachment = new SoapAttachment();2soapAttachment.setContent("some content");3assertEquals(soapAttachment.getContent(), "some content");4SoapAttachment soapAttachment = new SoapAttachment();5soapAttachment.setContentType("some content type");6assertEquals(soapAttachment.getContentType(), "some content type");7SoapAttachment soapAttachment = new SoapAttachment();8soapAttachment.setHeader("some header");9assertEquals(soapAttachment.getHeader(), "some header");10SoapAttachment soapAttachment = new SoapAttachment();11soapAttachment.setHeaders("some headers");12assertEquals(soapAttachment.getHeaders(), "some headers");13SoapAttachment soapAttachment = new SoapAttachment();14soapAttachment.setContentId("some content id");15assertEquals(soapAttachment.getContentId(), "some content id");16SoapAttachment soapAttachment = new SoapAttachment();17soapAttachment.setCharset("some charset");18assertEquals(soapAttachment.getCharset(), "some charset");19SoapAttachment soapAttachment = new SoapAttachment();20SoapAttachment soapAttachment1 = soapAttachment.getSoapAttachment();21assertEquals(soapAttachment1, soapAttachment);22SoapAttachment soapAttachment = new SoapAttachment();23SoapAttachment soapAttachment1 = SoapAttachment.getSoapAttachment(soapAttachment);24assertEquals(soapAttachment1, soapAttachment);25SoapAttachment soapAttachment = new SoapAttachment();26SoapAttachment soapAttachment1 = new SoapAttachment();27assertTrue(soapAttachment.equals(soapAttachment1));

Full Screen

Full Screen

getContent

Using AI Code Generation

copy

Full Screen

1SoapAttachment attachment = new SoapAttachment();2attachment.setContent("Hello World!");3assertEquals("Hello World!", attachment.getContent());4SoapAttachment attachment = new SoapAttachment();5attachment.setContentType("text/plain");6assertEquals("text/plain", attachment.getContentType());7SoapAttachment attachment = new SoapAttachment();8attachment.setHeaders(new HashMap<String, String>());9assertEquals(new HashMap<String, String>(), attachment.getHeaders());10SoapAttachment attachment = new SoapAttachment();11attachment.setInputStream(new ByteArrayInputStream("Hello World!".getBytes()));12assertEquals(new ByteArrayInputStream("Hello World!".getBytes()), attachment.getInputStream());13SoapAttachment attachment = new SoapAttachment();14attachment.setName("test");15assertEquals("test", attachment.getName());16SoapAttachment attachment = new SoapAttachment();17attachment.setTransferEncoding("binary");18assertEquals("binary", attachment.getTransferEncoding());19SoapAttachment attachment = new SoapAttachment();20attachment.setXml(new DefaultXmlMessage("<test>Hello World!</test>"));21assertEquals(new DefaultXmlMessage("<test>Hello World!</test>"), attachment.getXml());22SoapAttachment attachment = new SoapAttachment();23attachment.setMtomEnabled(true);24assertTrue(attachment.isMtomEnabled());25SoapAttachment attachment = new SoapAttachment();26attachment.setMtomEnabled(true);27assertTrue(attachment.isMtomEnabled());28SoapAttachment attachment = new SoapAttachment();

Full Screen

Full Screen

getContent

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.ws.message;2import java.io.IOException;3import java.util.ArrayList;4import java.util.List;5import javax.xml.soap.SOAPException;6import org.springframework.core.io.ClassPathResource;7import org.springframework.core.io.Resource;8import org.springframework.ws.soap.SoapMessage;9import org.springframework.ws.soap.SoapMessageFactory;10import org.springframework.ws.soap.saaj.SaajSoapMessageFactory;11import org.springframework.ws.soap.saaj.SaajSoapMessageFactoryUtils;12import org.springframework.ws.soap.saaj.SaajUtils;13import com.consol.citrus.exceptions.CitrusRuntimeException;14import com.consol.citrus.ws.message.SoapAttachment;15public class SoapAttachmentTest {16public static void main(String[] args) throws SOAPException, IOException {17 SoapMessageFactory messageFactory = new SaajSoapMessageFactory();18 SoapMessage message = messageFactory.createWebServiceMessage();19 SaajUtils.getSaajMessage(message).getSOAPBody().addTextNode("Hello");20 List<SoapAttachment> attachments = new ArrayList<SoapAttachment>();21 Resource resource = new ClassPathResource("com/consol/citrus/ws/message/attachment.txt");22 SoapAttachment attachment = new SoapAttachment();23 attachment.setContent(resource.getInputStream());24 attachment.setContentType("text/plain");25 attachment.setContentId("attachment1");26 attachments.add(attachment);27 SaajSoapMessageFactoryUtils.addAttachments(message, attachments);28 SoapAttachment soapAttachment = SaajSoapMessageFactoryUtils.getAttachment(message, "attachment1");29 System.out.println(soapAttachment.getContent());30}31}

Full Screen

Full Screen

getContent

Using AI Code Generation

copy

Full Screen

1SoapAttachment soapAttachment = new SoapAttachment();2soapAttachment.setContent("someContent");3assertEquals(soapAttachment.getContent(),"someContent");4SoapAttachment soapAttachment = new SoapAttachment();5soapAttachment.setContentType("someContent");6assertEquals(soapAttachment.getContentType(),"someContent");7SoapAttachment soapAttachment = new SoapAttachment();8soapAttachment.setFileName("someContent");9assertEquals(soapAttachment.getFileName(),"someContent");10SoapAttachment soapAttachment = new SoapAttachment();11soapAttachment.setHeaders(headers);12assertEquals(soapAttachment.getHeaders(),headers);13SoapAttachment soapAttachment = new SoapAttachment();14soapAttachment.setSoapAttachment(soapAttachment);15assertEquals(soapAttachment.getSoapAttachment(),soapAttachment);16SoapAttachment soapAttachment = new SoapAttachment();17soapAttachment.setSoapAttachment(soapAttachment);18assertEquals(soapAttachment.getSoapAttachment(),soapAttachment);19SoapAttachment soapAttachment = new SoapAttachment();20soapAttachment.setSoapAttachment(soapAttachment);21assertEquals(soapAttachment.getSoapAttachment(),soapAttachment);22SoapAttachment soapAttachment = new SoapAttachment();23soapAttachment.setSoapAttachment(soapAttachment);24assertEquals(soapAttachment.getSoapAttachment(),soapAttachment);25SoapAttachment soapAttachment = new SoapAttachment();26soapAttachment.setSoapAttachment(soapAttachment);27assertEquals(soapAttachment.getSoapAttachment(),soapAttachment);28SoapAttachment soapAttachment = new SoapAttachment();29soapAttachment.setSoapAttachment(soapAttachment);30assertEquals(soapAttachment.getSoapAttachment(),soapAttachment);

Full Screen

Full Screen

getContent

Using AI Code Generation

copy

Full Screen

1public void testGetContent() {2 SoapAttachment soapAttachment = new SoapAttachment();3 soapAttachment.setContent("content");4 assertEquals("content", soapAttachment.getContent());5}6public void testGetContentType() {7 SoapAttachment soapAttachment = new SoapAttachment();8 soapAttachment.setContentType("content-type");9 assertEquals("content-type", soapAttachment.getContentType());10}11public void testGetHeaders() {12 SoapAttachment soapAttachment = new SoapAttachment();13 soapAttachment.getHeaders().put("header", "value");14 assertEquals("value", soapAttachment.getHeaders().get("header"));15}16public void testGetHeader() {17 SoapAttachment soapAttachment = new SoapAttachment();18 soapAttachment.getHeaders().put("header", "value");19 assertEquals("value", soapAttachment.getHeader("header"));20}21public void testGetHeaderNames() {22 SoapAttachment soapAttachment = new SoapAttachment();23 soapAttachment.getHeaders().put("header", "value");24 assertEquals("header", soapAttachment.getHeaderNames().next());25}26public void testGetHeaderValues() {27 SoapAttachment soapAttachment = new SoapAttachment();28 soapAttachment.getHeaders().put("header", "value");29 assertEquals("value", soapAttachment.getHeaderValues("header").next());30}31public void testGetHeaderValues() {32 SoapAttachment soapAttachment = new SoapAttachment();33 soapAttachment.getHeaders().put("header", "value");34 assertEquals("value", soapAttachment.getHeaderValues("header").next());35}

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