View Javadoc

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