View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.transport.soap.axis.functional;
8   
9   import org.mule.DefaultMuleEvent;
10  import org.mule.DefaultMuleMessage;
11  import org.mule.api.MuleMessage;
12  import org.mule.api.endpoint.OutboundEndpoint;
13  import org.mule.message.ds.StringDataSource;
14  import org.mule.session.DefaultMuleSession;
15  import org.mule.tck.junit4.FunctionalTestCase;
16  import org.mule.tck.junit4.rule.DynamicPort;
17  import org.mule.transport.AbstractConnector;
18  import org.mule.transport.soap.axis.AxisMessageDispatcher;
19  
20  import javax.activation.DataHandler;
21  
22  import org.junit.Rule;
23  import org.junit.Test;
24  
25  import static org.junit.Assert.assertEquals;
26  import static org.junit.Assert.assertNotNull;
27  
28  public class SoapAttachmentsFunctionalTestCase extends FunctionalTestCase
29  {
30      private static final int SEND_COUNT = 5;
31      
32      private int callbackCount = 0;
33  
34      @Rule
35      public DynamicPort dynamicPort = new DynamicPort("port1");
36  
37      @Override
38      protected String getConfigResources()
39      {
40          return "axis-soap-attachments.xml";
41      }
42  
43      @Test
44      public void testSend() throws Exception
45      {
46          sendTestData(SEND_COUNT);
47          assertEquals(SEND_COUNT, callbackCount);
48      }
49  
50      protected void sendTestData(int iterations) throws Exception
51      {
52          OutboundEndpoint ep = muleContext.getRegistry().lookupEndpointBuilder("client").buildOutboundEndpoint();
53  
54          AxisMessageDispatcher client = new AxisMessageDispatcher(ep);
55          client.initialise();
56          for (int i = 0; i < iterations; i++)
57          {
58              MuleMessage msg = new DefaultMuleMessage("testPayload", muleContext);
59              msg.addOutboundAttachment("testAttachment", new DataHandler(new StringDataSource("foo")));
60              DefaultMuleSession session = new DefaultMuleSession(msg, ((AbstractConnector) ep.getConnector()).getSessionHandler(), muleContext);
61              DefaultMuleEvent event = new DefaultMuleEvent(msg, ep, session);
62              MuleMessage result = client.process(event).getMessage();
63              assertNotNull(result);
64              assertNotNull(result.getPayload());
65              assertEquals(result.getPayloadAsString(), "Done");
66              callbackCount++;
67          }
68      }
69  
70  }