1   /*
2    * $Id: SoapAttachmentsFunctionalTestCase.java 11343 2008-03-13 10:58:26Z tcarlson $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.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.DefaultMuleSession;
16  import org.mule.api.MuleMessage;
17  import org.mule.api.endpoint.OutboundEndpoint;
18  import org.mule.tck.FunctionalTestCase;
19  import org.mule.transport.AbstractConnector;
20  import org.mule.transport.soap.axis.AxisMessageDispatcher;
21  
22  import java.io.File;
23  
24  import javax.activation.DataHandler;
25  import javax.activation.FileDataSource;
26  
27  public class SoapAttachmentsFunctionalTestCase extends FunctionalTestCase
28  {
29      private static final int SEND_COUNT = 5;
30      
31      private int callbackCount = 0;
32  
33      protected String getConfigResources()
34      {
35          return "axis-soap-attachments.xml";
36      }
37  
38      public void testSend() throws Exception
39      {
40          sendTestData(SEND_COUNT);
41          assertEquals(SEND_COUNT, callbackCount);
42      }
43  
44      protected void sendTestData(int iterations) throws Exception
45      {
46          OutboundEndpoint ep = muleContext.getRegistry().lookupEndpointFactory().getOutboundEndpoint(
47              "axis:http://localhost:60198/mule/services/testComponent?method=receiveMessageWithAttachments");
48  
49          AxisMessageDispatcher client = new AxisMessageDispatcher(ep);
50          for (int i = 0; i < iterations; i++)
51          {
52              MuleMessage msg = new DefaultMuleMessage("testPayload");
53              File tempFile = File.createTempFile("test", ".att");
54              tempFile.deleteOnExit();
55              msg.addAttachment("testAttachment", new DataHandler(new FileDataSource(tempFile)));
56              DefaultMuleSession session = new DefaultMuleSession(msg, ((AbstractConnector) ep.getConnector()).getSessionHandler(), muleContext);
57              DefaultMuleEvent event = new DefaultMuleEvent(msg, ep, session, true);
58              MuleMessage result = client.send(event);
59              assertNotNull(result);
60              assertNotNull(result.getPayload());
61              assertEquals(result.getPayloadAsString(), "Done");
62              callbackCount++;
63          }
64      }
65  }