View Javadoc

1   /*
2    * $Id: SoapAttachmentsFunctionalTestCase.java 20297 2010-11-22 18:49:18Z aperepel $
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.transport.AbstractConnector;
21  import org.mule.transport.soap.axis.AxisMessageDispatcher;
22  
23  import javax.activation.DataHandler;
24  
25  public class SoapAttachmentsFunctionalTestCase extends DynamicPortTestCase
26  {
27      private static final int SEND_COUNT = 5;
28      
29      private int callbackCount = 0;
30  
31      protected String getConfigResources()
32      {
33          return "axis-soap-attachments.xml";
34      }
35  
36      public void testSend() throws Exception
37      {
38          sendTestData(SEND_COUNT);
39          assertEquals(SEND_COUNT, callbackCount);
40      }
41  
42      protected void sendTestData(int iterations) throws Exception
43      {
44          OutboundEndpoint ep = muleContext.getRegistry().lookupEndpointBuilder("client").buildOutboundEndpoint();
45  
46          AxisMessageDispatcher client = new AxisMessageDispatcher(ep);
47          client.initialise();
48          for (int i = 0; i < iterations; i++)
49          {
50              MuleMessage msg = new DefaultMuleMessage("testPayload", muleContext);
51              msg.addOutboundAttachment("testAttachment", new DataHandler(new StringDataSource("foo")));
52              DefaultMuleSession session = new DefaultMuleSession(msg, ((AbstractConnector) ep.getConnector()).getSessionHandler(), muleContext);
53              DefaultMuleEvent event = new DefaultMuleEvent(msg, ep, session);
54              MuleMessage result = client.process(event).getMessage();
55              assertNotNull(result);
56              assertNotNull(result.getPayload());
57              assertEquals(result.getPayloadAsString(), "Done");
58              callbackCount++;
59          }
60      }
61  
62      @Override
63      protected int getNumPortsToFind()
64      {
65          return 1;
66      }
67  }