Package com.consol.citrus.ws.message

Examples of com.consol.citrus.ws.message.SoapAttachment


        validationContext.setMessageBuilder(controlMessageBuilder);
        controlMessageBuilder.setPayloadData("<TestRequest><Message>Hello World!</Message></TestRequest>");
       
        context.setVariable("myText", "Hello World!");

        SoapAttachment attachment = new SoapAttachment();
        attachment.setContentId("myAttachment");
        attachment.setContentType("text/xml");
        attachment.setContentResourcePath("classpath:com/consol/citrus/ws/actions/test-attachment-with-variables.xml");
        soapMessageAction.setAttachments(Collections.singletonList(attachment));

        Message controlMessage = new SoapMessage("<TestRequest><Message>Hello World!</Message></TestRequest>");

        reset(endpoint, consumer, endpointConfiguration, attachmentValidator);
        expect(endpoint.createConsumer()).andReturn(consumer).anyTimes();
        expect(endpoint.getEndpointConfiguration()).andReturn(endpointConfiguration).anyTimes();
        expect(endpointConfiguration.getTimeout()).andReturn(5000L).anyTimes();

        expect(consumer.receive(anyObject(TestContext.class), anyLong())).andReturn(controlMessage).once();
       
        attachmentValidator.validateAttachment((SoapMessage)anyObject(), (List) anyObject());
        expectLastCall().andAnswer(new IAnswer<Object>() {
            public Object answer() throws Throwable {
                Assert.assertEquals(((List<SoapAttachment>)EasyMock.getCurrentArguments()[1]).size(), 1L);
                SoapAttachment soapAttachment = ((List<SoapAttachment>)EasyMock.getCurrentArguments()[1]).get(0);
                Assert.assertEquals(soapAttachment.getContent(), "<TestAttachment><Message>Hello World!</Message></TestAttachment>");
                Assert.assertEquals(soapAttachment.getContentId(), "myAttachment");
                Assert.assertEquals(soapAttachment.getContentType(), "text/xml");
                Assert.assertEquals(soapAttachment.getCharsetName(), "UTF-8");
                return null;
            }
        });

        expect(endpoint.getActor()).andReturn(null).anyTimes();
View Full Code Here


        verify(saajSoapRequest, soapBody, soapHeader, soapEnvelope, saajMessage);
    }
   
    @Test
    public void testSoapAttachment() throws TransformerException, IOException {
        SoapAttachment attachment = new SoapAttachment();
        attachment.setContentId("attContentId");
        attachment.setContent("This is a SOAP attachment\nwith multi-line");
        attachment.setContentType("plain/text");

        com.consol.citrus.ws.message.SoapMessage testMessage = new com.consol.citrus.ws.message.SoapMessage(requestPayload)
                .addAttachment(attachment);

        SoapRequestMessageCallback callback = new SoapRequestMessageCallback(testMessage, new WebServiceEndpointConfiguration());
       
        reset(soapRequest, soapBody);
       
        expect(soapRequest.getSoapBody()).andReturn(soapBody).once();
        expect(soapBody.getPayloadResult()).andReturn(new StringResult()).once();
       
        expect(soapRequest.addAttachment(eq(attachment.getContentId()), (InputStreamSource)anyObject(), eq(attachment.getContentType()))).andAnswer(new IAnswer<Attachment>() {
            public Attachment answer() throws Throwable {
                InputStreamSource contentStream = (InputStreamSource)EasyMock.getCurrentArguments()[1];
                BufferedReader reader = new BufferedReader(new InputStreamReader(contentStream.getInputStream()));
               
                Assert.assertEquals(reader.readLine(), "This is a SOAP attachment");
View Full Code Here

        validationContext.setMessageBuilder(controlMessageBuilder);
        controlMessageBuilder.setPayloadData("<TestRequest><Message>Hello World!</Message></TestRequest>");
       
        context.setVariable("myText", "Hello World!");

        SoapAttachment attachment = new SoapAttachment();
        attachment.setContentId("myAttachment");
        attachment.setContentType("text/xml");
        attachment.setContent("<TestAttachment><Message>${myText}</Message></TestAttachment>");
        soapMessageAction.setAttachments(Collections.singletonList(attachment));

        Message controlMessage = new SoapMessage("<TestRequest><Message>Hello World!</Message></TestRequest>");

        reset(endpoint, consumer, endpointConfiguration, attachmentValidator);
        expect(endpoint.createConsumer()).andReturn(consumer).anyTimes();
        expect(endpoint.getEndpointConfiguration()).andReturn(endpointConfiguration).anyTimes();
        expect(endpointConfiguration.getTimeout()).andReturn(5000L).anyTimes();

        expect(consumer.receive(anyObject(TestContext.class), anyLong())).andReturn(controlMessage).once();

        attachmentValidator.validateAttachment((SoapMessage)anyObject(), (List) anyObject());
        expectLastCall().andAnswer(new IAnswer<Object>() {
            public Object answer() throws Throwable {
                Assert.assertEquals(((List<SoapAttachment>)EasyMock.getCurrentArguments()[1]).size(), 1L);
                SoapAttachment soapAttachment = ((List<SoapAttachment>)EasyMock.getCurrentArguments()[1]).get(0);
                Assert.assertEquals(soapAttachment.getContent(), "<TestAttachment><Message>Hello World!</Message></TestAttachment>");
                Assert.assertEquals(soapAttachment.getContentId(), "myAttachment");
                Assert.assertEquals(soapAttachment.getContentType(), "text/xml");
                Assert.assertEquals(soapAttachment.getCharsetName(), "UTF-8");
                return null;
            }
        });

        expect(endpoint.getActor()).andReturn(null).anyTimes();
View Full Code Here

     * @param contentType
     * @param content
     * @return
     */
    public ReceiveSoapMessageActionDefinition attachment(String contentId, String contentType, String content) {
        SoapAttachment attachment = new SoapAttachment();
        attachment.setContentId(contentId);
        attachment.setContentType(contentType);
        attachment.setContent(content);

        getAction().getAttachments().add(attachment);

        return this;
    }
View Full Code Here

     * @param contentType
     * @param contentResource
     * @return
     */
    public ReceiveSoapMessageActionDefinition attachment(String contentId, String contentType, Resource contentResource) {
        SoapAttachment attachment = new SoapAttachment();
        attachment.setContentId(contentId);
        attachment.setContentType(contentType);

        try {
            attachment.setContent(FileUtils.readToString(contentResource));
        } catch (IOException e) {
            throw new CitrusRuntimeException("Failed to read attachment content resource", e);
        }

        getAction().getAttachments().add(attachment);
View Full Code Here

     * @param contentType
     * @param content
     * @return
     */
    public SendSoapMessageActionDefinition attachment(String contentId, String contentType, String content) {
        SoapAttachment attachment = new SoapAttachment();
        attachment.setContentId(contentId);
        attachment.setContentType(contentType);
        attachment.setContent(content);

        getAction().getAttachments().add(attachment);
        return this;
    }
View Full Code Here

     * @param contentType
     * @param contentResource
     * @return
     */
    public SendSoapMessageActionDefinition attachment(String contentId, String contentType, Resource contentResource) {
        SoapAttachment attachment = new SoapAttachment();
        attachment.setContentId(contentId);
        attachment.setContentType(contentType);
       
        try {
            attachment.setContent(FileUtils.readToString(contentResource));
        } catch (IOException e) {
            throw new CitrusRuntimeException("Failed to read attachment resource", e);
        }

        getAction().getAttachments().add(attachment);
View Full Code Here

        messageBuilder.setPayloadData("<TestRequest><Message>Hello World!</Message></TestRequest>");

        soapMessageAction.setMessageBuilder(messageBuilder);

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

        soapMessageAction.setAttachments(attachments);

        reset(webServiceEndpoint, producer);

        expect(webServiceEndpoint.createProducer()).andReturn(producer).once();
        producer.send(anyObject(Message.class), anyObject(TestContext.class));
        expectLastCall().andAnswer(new IAnswer<Object>() {
            public Object answer() throws Throwable {
                Assert.assertEquals(((SoapMessage)EasyMock.getCurrentArguments()[0]).getAttachments().size(), 2L);
                SoapAttachment constructedAttachment = ((SoapMessage)EasyMock.getCurrentArguments()[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)EasyMock.getCurrentArguments()[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;
            }
        }).once();
View Full Code Here

        soapMessageAction.setEndpoint(webServiceEndpoint);

        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");
        soapMessageAction.setAttachments(Collections.singletonList(attachment));

        soapMessageAction.setMessageBuilder(messageBuilder);
       
        reset(webServiceEndpoint, producer);

        expect(webServiceEndpoint.createProducer()).andReturn(producer).once();
        producer.send(anyObject(Message.class), anyObject(TestContext.class));
        expectLastCall().andAnswer(new IAnswer<Object>() {
            public Object answer() throws Throwable {
                Assert.assertEquals(((SoapMessage)EasyMock.getCurrentArguments()[0]).getAttachments().size(), 1L);
                SoapAttachment constructedAttachment = ((SoapMessage)EasyMock.getCurrentArguments()[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;
            }
        }).once();
       
View Full Code Here

        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>");
        soapMessageAction.setAttachments(Collections.singletonList(attachment));

        soapMessageAction.setMessageBuilder(messageBuilder);
       
        reset(webServiceEndpoint, producer);

        expect(webServiceEndpoint.createProducer()).andReturn(producer).once();
        producer.send(anyObject(Message.class), anyObject(TestContext.class));
        expectLastCall().andAnswer(new IAnswer<Object>() {
            public Object answer() throws Throwable {
                Assert.assertEquals(((SoapMessage)EasyMock.getCurrentArguments()[0]).getAttachments().size(), 1L);
                SoapAttachment constructedAttachment = ((SoapMessage)EasyMock.getCurrentArguments()[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;
            }
        }).once();
       
View Full Code Here

TOP

Related Classes of com.consol.citrus.ws.message.SoapAttachment

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.