SendSoapMessageAction extends SendMessageAction implements TestAction { public List<SoapAttachment> getAttachments() { return attachments; } SendSoapMessageAction(SendSoapMessageBuilder<?, ?> builder); List<SoapAttachment> getAttachments(); boolean getMtomEnabled(); static final String CID_MARKER; }
@Test @SuppressWarnings("rawtypes") public void testSoapMessageWithMtomAttachmentDataTest() throws Exception { PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder(); messageBuilder.setPayloadData("<TestRequest><Text>cid:mtomText@citrusframework.org</Text></TestRequest>"); SoapAttachment attachment = new SoapAttachment(); attachment.setContentId("mtomText@citrusframework.org"); attachment.setContentType("text/xml"); attachment.setContent("<TestAttachment><Message>Hello World!</Message></TestAttachment>"); reset(webServiceEndpoint, producer); when(webServiceEndpoint.createProducer()).thenReturn(producer); doAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { SoapMessage soapMessage = ((SoapMessage)invocation.getArguments()[0]); Assert.assertTrue(soapMessage.isMtomEnabled()); Assert.assertEquals(soapMessage.getPayload(String.class), "<TestRequest><Text><xop:Include xmlns:xop=\"http: Assert.assertEquals(soapMessage.getAttachments().size(), 1L); SoapAttachment constructedAttachment = ((SoapMessage)invocation.getArguments()[0]).getAttachments().get(0); Assert.assertEquals(constructedAttachment.getContentId(), "mtomText@citrusframework.org"); Assert.assertEquals(constructedAttachment.getContentType(), "text/xml"); Assert.assertEquals(constructedAttachment.getContent(), "<TestAttachment><Message>Hello World!</Message></TestAttachment>"); Assert.assertEquals(constructedAttachment.getCharsetName(), "UTF-8"); return null; } }).when(producer).send(any(Message.class), any(TestContext.class)); when(webServiceEndpoint.getActor()).thenReturn(null); SendSoapMessageAction soapMessageAction = new SendSoapMessageAction.Builder() .endpoint(webServiceEndpoint) .mtomEnabled(true) .message(messageBuilder) .attachment(attachment) .build(); soapMessageAction.execute(context); }
@Test @SuppressWarnings("rawtypes") public void testSoapMessageWithMtomInlineBase64BinaryAttachmentDataTest() throws Exception { PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder(); messageBuilder.setPayloadData("<TestRequest><Image>cid:mtomImage</Image></TestRequest>"); SoapAttachment attachment = new SoapAttachment(); attachment.setMtomInline(true); attachment.setEncodingType(SoapAttachment.ENCODING_BASE64_BINARY); attachment.setContentId("mtomImage"); attachment.setContentType("image/png"); attachment.setContent("IMAGE_DATA"); reset(webServiceEndpoint, producer); when(webServiceEndpoint.createProducer()).thenReturn(producer); doAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { SoapMessage soapMessage = ((SoapMessage)invocation.getArguments()[0]); Assert.assertTrue(soapMessage.isMtomEnabled()); Assert.assertEquals(soapMessage.getPayload(String.class), "<TestRequest><Image>SU1BR0VfREFUQQ==</Image></TestRequest>"); Assert.assertEquals(soapMessage.getAttachments().size(), 0L); return null; } }).when(producer).send(any(Message.class), any(TestContext.class)); when(webServiceEndpoint.getActor()).thenReturn(null); SendSoapMessageAction soapMessageAction = new SendSoapMessageAction.Builder() .endpoint(webServiceEndpoint) .mtomEnabled(true) .message(messageBuilder) .attachment(attachment) .build(); soapMessageAction.execute(context); }
@Test @SuppressWarnings("rawtypes") public void testSoapMessageWithMtomInlineHexBinaryAttachmentDataTest() throws Exception { PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder(); messageBuilder.setPayloadData("<TestRequest><Image>cid:mtomImage</Image></TestRequest>"); SoapAttachment attachment = new SoapAttachment(); attachment.setMtomInline(true); attachment.setEncodingType(SoapAttachment.ENCODING_HEX_BINARY); attachment.setContentId("mtomImage"); attachment.setContentType("image/png"); attachment.setContent("IMAGE_DATA"); reset(webServiceEndpoint, producer); when(webServiceEndpoint.createProducer()).thenReturn(producer); doAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { SoapMessage soapMessage = ((SoapMessage)invocation.getArguments()[0]); Assert.assertTrue(soapMessage.isMtomEnabled()); Assert.assertEquals(soapMessage.getPayload(String.class), "<TestRequest><Image>494D4147455F44415441</Image></TestRequest>"); Assert.assertEquals(soapMessage.getAttachments().size(), 0L); return null; } }).when(producer).send(any(Message.class), any(TestContext.class)); when(webServiceEndpoint.getActor()).thenReturn(null); SendSoapMessageAction soapMessageAction = new SendSoapMessageAction.Builder() .endpoint(webServiceEndpoint) .mtomEnabled(true) .message(messageBuilder) .attachment(attachment) .build(); soapMessageAction.execute(context); }
@Test @SuppressWarnings("rawtypes") public void testSoapMessageWithMtomMissingCidAttachmentDataTest() throws Exception { PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder(); messageBuilder.setPayloadData("<TestRequest><Text>mtomText</Text></TestRequest>"); SoapAttachment attachment = new SoapAttachment(); attachment.setContentId("mtomText"); attachment.setContentType("text/xml"); attachment.setContent("<TestAttachment><Message>Hello World!</Message></TestAttachment>"); reset(webServiceEndpoint, producer); when(webServiceEndpoint.createProducer()).thenReturn(producer); doAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { SoapMessage soapMessage = ((SoapMessage)invocation.getArguments()[0]); Assert.assertTrue(soapMessage.isMtomEnabled()); Assert.assertEquals(soapMessage.getPayload(String.class), "<TestRequest><Text>mtomText</Text></TestRequest>"); Assert.assertEquals(soapMessage.getAttachments().size(), 1L); SoapAttachment constructedAttachment = ((SoapMessage)invocation.getArguments()[0]).getAttachments().get(0); Assert.assertEquals(constructedAttachment.getContentId(), "mtomText"); Assert.assertEquals(constructedAttachment.getContentType(), "text/xml"); Assert.assertEquals(constructedAttachment.getContent(), "<TestAttachment><Message>Hello World!</Message></TestAttachment>"); Assert.assertEquals(constructedAttachment.getCharsetName(), "UTF-8"); return null; } }).when(producer).send(any(Message.class), any(TestContext.class)); when(webServiceEndpoint.getActor()).thenReturn(null); SendSoapMessageAction soapMessageAction = new SendSoapMessageAction.Builder() .endpoint(webServiceEndpoint) .mtomEnabled(true) .message(messageBuilder) .attachment(attachment) .build(); soapMessageAction.execute(context); }
@Test @SuppressWarnings("rawtypes") public void testSoapMessageWithMtomInlineMissingCidAttachmentDataTest() throws Exception { PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder(); messageBuilder.setPayloadData("<TestRequest><Image>mtomImage</Image></TestRequest>"); SoapAttachment attachment = new SoapAttachment(); attachment.setMtomInline(true); attachment.setEncodingType(SoapAttachment.ENCODING_BASE64_BINARY); attachment.setContentId("mtomImage"); attachment.setContentType("image/png"); attachment.setContent("IMAGE_DATA"); reset(webServiceEndpoint, producer); when(webServiceEndpoint.createProducer()).thenReturn(producer); doAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { SoapMessage soapMessage = ((SoapMessage)invocation.getArguments()[0]); Assert.assertTrue(soapMessage.isMtomEnabled()); Assert.assertEquals(soapMessage.getPayload(String.class), "<TestRequest><Image>mtomImage</Image></TestRequest>"); Assert.assertEquals(soapMessage.getAttachments().size(), 1L); SoapAttachment constructedAttachment = ((SoapMessage)invocation.getArguments()[0]).getAttachments().get(0); Assert.assertEquals(constructedAttachment.getContentId(), "mtomImage"); Assert.assertEquals(constructedAttachment.getContentType(), "image/png"); Assert.assertEquals(constructedAttachment.getContent(), "IMAGE_DATA"); Assert.assertEquals(constructedAttachment.getCharsetName(), "UTF-8"); return null; } }).when(producer).send(any(Message.class), any(TestContext.class)); when(webServiceEndpoint.getActor()).thenReturn(null); SendSoapMessageAction soapMessageAction = new SendSoapMessageAction.Builder() .endpoint(webServiceEndpoint) .mtomEnabled(true) .message(messageBuilder) .attachment(attachment) .build(); soapMessageAction.execute(context); }
@Test @SuppressWarnings("rawtypes") public void testSoapMessageWithDefaultAttachmentDataTest() throws Exception { PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder(); messageBuilder.setPayloadData("<TestRequest><Message>Hello World!</Message></TestRequest>"); SoapAttachment attachment = new SoapAttachment(); attachment.setContent("<TestAttachment><Message>Hello World!</Message></TestAttachment>"); reset(webServiceEndpoint, producer); when(webServiceEndpoint.createProducer()).thenReturn(producer); doAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { Assert.assertEquals(((SoapMessage)invocation.getArguments()[0]).getAttachments().size(), 1L); SoapAttachment constructedAttachment = ((SoapMessage)invocation.getArguments()[0]).getAttachments().get(0); Assert.assertNull(constructedAttachment.getContentId()); Assert.assertEquals(constructedAttachment.getContentType(), "text/plain"); Assert.assertEquals(constructedAttachment.getContent(), "<TestAttachment><Message>Hello World!</Message></TestAttachment>"); Assert.assertEquals(constructedAttachment.getCharsetName(), "UTF-8"); return null; } }).when(producer).send(any(Message.class), any(TestContext.class)); when(webServiceEndpoint.getActor()).thenReturn(null); SendSoapMessageAction soapMessageAction = new SendSoapMessageAction.Builder() .endpoint(webServiceEndpoint) .message(messageBuilder) .attachment(attachment) .build(); soapMessageAction.execute(context); }
@Test @SuppressWarnings("rawtypes") public void testSoapMessageWithAttachmentDataTest() throws Exception { PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder(); messageBuilder.setPayloadData("<TestRequest><Message>Hello World!</Message></TestRequest>"); SoapAttachment attachment = new SoapAttachment(); attachment.setContentId("myAttachment"); attachment.setContentType("text/xml"); attachment.setContent("<TestAttachment><Message>Hello World!</Message></TestAttachment>"); attachment.setCharsetName("UTF-16"); reset(webServiceEndpoint, producer); when(webServiceEndpoint.createProducer()).thenReturn(producer); doAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { Assert.assertEquals(((SoapMessage)invocation.getArguments()[0]).getAttachments().size(), 1L); SoapAttachment constructedAttachment = ((SoapMessage)invocation.getArguments()[0]).getAttachments().get(0); Assert.assertEquals(constructedAttachment.getContentId(), "myAttachment"); Assert.assertEquals(constructedAttachment.getContentType(), "text/xml"); Assert.assertEquals(constructedAttachment.getContent(), "<TestAttachment><Message>Hello World!</Message></TestAttachment>"); Assert.assertEquals(constructedAttachment.getCharsetName(), "UTF-16"); return null; } }).when(producer).send(any(Message.class), any(TestContext.class)); when(webServiceEndpoint.getActor()).thenReturn(null); SendSoapMessageAction soapMessageAction = new SendSoapMessageAction.Builder() .endpoint(webServiceEndpoint) .message(messageBuilder) .attachment(attachment) .build(); soapMessageAction.execute(context); }
@Test @SuppressWarnings("rawtypes") public void testSoapMessageWithMultipleAttachmentDataTest() throws Exception { PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder(); messageBuilder.setPayloadData("<TestRequest><Message>Hello World!</Message></TestRequest>"); List<SoapAttachment> attachments = new ArrayList<SoapAttachment>(); SoapAttachment attachment = new SoapAttachment(); attachment.setContentId("1stAttachment"); attachment.setContentType("text/xml"); attachment.setContent("<TestAttachment><Message>Hello World1!</Message></TestAttachment>"); attachment.setCharsetName("UTF-8"); attachments.add(attachment); SoapAttachment attachment2 = new SoapAttachment(); attachment2.setContentId("2ndAttachment"); attachment2.setContentType("text/xml"); attachment2.setContent("<TestAttachment><Message>Hello World2!</Message></TestAttachment>"); attachment2.setCharsetName("UTF-16"); attachments.add(attachment2); reset(webServiceEndpoint, producer); when(webServiceEndpoint.createProducer()).thenReturn(producer); doAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { Assert.assertEquals(((SoapMessage)invocation.getArguments()[0]).getAttachments().size(), 2L); SoapAttachment constructedAttachment = ((SoapMessage)invocation.getArguments()[0]).getAttachments().get(0); Assert.assertEquals(constructedAttachment.getContentId(), "1stAttachment"); Assert.assertEquals(constructedAttachment.getContentType(), "text/xml"); Assert.assertEquals(constructedAttachment.getContent(), "<TestAttachment><Message>Hello World1!</Message></TestAttachment>"); Assert.assertEquals(constructedAttachment.getCharsetName(), "UTF-8"); constructedAttachment = ((SoapMessage)invocation.getArguments()[0]).getAttachments().get(1); Assert.assertEquals(constructedAttachment.getContentId(), "2ndAttachment"); Assert.assertEquals(constructedAttachment.getContentType(), "text/xml"); Assert.assertEquals(constructedAttachment.getContent(), "<TestAttachment><Message>Hello World2!</Message></TestAttachment>"); Assert.assertEquals(constructedAttachment.getCharsetName(), "UTF-16"); return null; } }).when(producer).send(any(Message.class), any(TestContext.class)); when(webServiceEndpoint.getActor()).thenReturn(null); SendSoapMessageAction soapMessageAction = new SendSoapMessageAction.Builder() .endpoint(webServiceEndpoint) .message(messageBuilder) .attachment(attachment) .attachment(attachment2) .build(); soapMessageAction.execute(context); }
@Test @SuppressWarnings("rawtypes") public void testSoapMessageWithAttachmentResourceTest() throws Exception { PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder(); messageBuilder.setPayloadData("<TestRequest><Message>Hello World!</Message></TestRequest>"); SoapAttachment attachment = new SoapAttachment(); attachment.setContentResourcePath("classpath:com/consol/citrus/ws/actions/test-attachment.xml"); reset(webServiceEndpoint, producer); when(webServiceEndpoint.createProducer()).thenReturn(producer); doAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { Assert.assertEquals(((SoapMessage)invocation.getArguments()[0]).getAttachments().size(), 1L); SoapAttachment constructedAttachment = ((SoapMessage)invocation.getArguments()[0]).getAttachments().get(0); Assert.assertNull(constructedAttachment.getContentId()); Assert.assertEquals(constructedAttachment.getContentType(), "text/plain"); Assert.assertEquals(constructedAttachment.getContent().trim(), "<TestAttachment><Message>Hello World!</Message></TestAttachment>"); Assert.assertEquals(constructedAttachment.getCharsetName(), "UTF-8"); return null; } }).when(producer).send(any(Message.class), any(TestContext.class)); when(webServiceEndpoint.getActor()).thenReturn(null); SendSoapMessageAction soapMessageAction = new SendSoapMessageAction.Builder() .endpoint(webServiceEndpoint) .message(messageBuilder) .attachment(attachment) .build(); soapMessageAction.execute(context); }
@Test @SuppressWarnings("rawtypes") public void testSoapMessageWithAttachmentDataVariableSupportTest() throws Exception { PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder(); messageBuilder.setPayloadData("<TestRequest><Message>Hello World!</Message></TestRequest>"); context.setVariable("myText", "Hello World!"); SoapAttachment attachment = new SoapAttachment(); attachment.setContent("<TestAttachment><Message>${myText}</Message></TestAttachment>"); reset(webServiceEndpoint, producer); when(webServiceEndpoint.createProducer()).thenReturn(producer); doAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { Assert.assertEquals(((SoapMessage)invocation.getArguments()[0]).getAttachments().size(), 1L); SoapAttachment constructedAttachment = ((SoapMessage)invocation.getArguments()[0]).getAttachments().get(0); Assert.assertNull(constructedAttachment.getContentId()); Assert.assertEquals(constructedAttachment.getContentType(), "text/plain"); Assert.assertEquals(constructedAttachment.getContent(), "<TestAttachment><Message>Hello World!</Message></TestAttachment>"); Assert.assertEquals(constructedAttachment.getCharsetName(), "UTF-8"); return null; } }).when(producer).send(any(Message.class), any(TestContext.class)); when(webServiceEndpoint.getActor()).thenReturn(null); SendSoapMessageAction soapMessageAction = new SendSoapMessageAction.Builder() .endpoint(webServiceEndpoint) .message(messageBuilder) .attachment(attachment) .build(); soapMessageAction.execute(context); }
@Test @SuppressWarnings("rawtypes") public void testSoapMessageWithAttachmentResourceVariablesSupportTest() throws Exception { PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder(); messageBuilder.setPayloadData("<TestRequest><Message>Hello World!</Message></TestRequest>"); context.setVariable("myText", "Hello World!"); SoapAttachment attachment = new SoapAttachment(); attachment.setContentResourcePath("classpath:com/consol/citrus/ws/actions/test-attachment-with-variables.xml"); reset(webServiceEndpoint, producer); when(webServiceEndpoint.createProducer()).thenReturn(producer); doAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { Assert.assertEquals(((SoapMessage)invocation.getArguments()[0]).getAttachments().size(), 1L); SoapAttachment constructedAttachment = ((SoapMessage)invocation.getArguments()[0]).getAttachments().get(0); Assert.assertNull(constructedAttachment.getContentId()); Assert.assertEquals(constructedAttachment.getContentType(), "text/plain"); Assert.assertEquals(constructedAttachment.getContent().trim(), "<TestAttachment><Message>Hello World!</Message></TestAttachment>"); Assert.assertEquals(constructedAttachment.getCharsetName(), "UTF-8"); return null; } }).when(producer).send(any(Message.class), any(TestContext.class)); when(webServiceEndpoint.getActor()).thenReturn(null); SendSoapMessageAction soapMessageAction = new SendSoapMessageAction.Builder() .endpoint(webServiceEndpoint) .message(messageBuilder) .attachment(attachment) .build(); soapMessageAction.execute(context); }