1   /*
2    * $Id: SoapAttachmentsFunctionalTestCase.java 7976 2007-08-21 14:26:13Z dirk.olmes $
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.providers.soap.axis.functional;
12  
13  import org.mule.MuleManager;
14  import org.mule.config.PoolingProfile;
15  import org.mule.impl.ImmutableMuleEndpoint;
16  import org.mule.impl.MuleEvent;
17  import org.mule.impl.MuleMessage;
18  import org.mule.impl.MuleSession;
19  import org.mule.impl.endpoint.MuleEndpointURI;
20  import org.mule.impl.model.seda.SedaModel;
21  import org.mule.providers.AbstractConnector;
22  import org.mule.providers.soap.axis.AxisConnector;
23  import org.mule.providers.soap.axis.AxisMessageDispatcher;
24  import org.mule.tck.functional.AbstractProviderFunctionalTestCase;
25  import org.mule.umo.UMOMessage;
26  import org.mule.umo.endpoint.MalformedEndpointException;
27  import org.mule.umo.endpoint.UMOEndpointURI;
28  import org.mule.umo.endpoint.UMOImmutableEndpoint;
29  import org.mule.umo.model.UMOModel;
30  import org.mule.umo.provider.UMOConnector;
31  
32  import java.io.File;
33  
34  import javax.activation.DataHandler;
35  import javax.activation.FileDataSource;
36  
37  public class SoapAttachmentsFunctionalTestCase extends AbstractProviderFunctionalTestCase
38  {
39  
40      // @Override
41      protected void doSetUp() throws Exception
42      {
43          manager = MuleManager.getInstance();
44          // Make sure we are running synchronously
45          MuleManager.getConfiguration().setSynchronous(true);
46          MuleManager.getConfiguration().getPoolingProfile().setInitialisationPolicy(
47              PoolingProfile.INITIALISE_ONE);
48  
49          UMOModel model = new SedaModel();
50          model.setName("main");
51          manager.registerModel(model);
52          callbackCalled = false;
53          callbackCount = 0;
54          connector = createConnector();
55      }
56  
57      protected UMOEndpointURI getInDest()
58      {
59          try
60          {
61              return new MuleEndpointURI("axis:http://localhost:60198/mule/services");
62          }
63          catch (MalformedEndpointException e)
64          {
65              fail(e.getMessage());
66              return null;
67          }
68      }
69  
70      protected UMOEndpointURI getOutDest()
71      {
72          return null;
73      }
74  
75      protected UMOConnector createConnector() throws Exception
76      {
77          AxisConnector connector = new AxisConnector();
78          connector.setName("testAxis");
79          connector.getDispatcherThreadingProfile().setDoThreading(false);
80          return connector;
81      }
82  
83      // @Override
84      public void testSend() throws Exception
85      {
86          descriptor = getTestDescriptor("testComponent", SoapAttachmentsFunctionalTestComponent.class
87              .getName());
88  
89          initialiseComponent(descriptor, null);
90          // Start the server
91          MuleManager.getInstance().start();
92  
93          sendTestData(5);
94  
95          afterInitialise();
96  
97          receiveAndTestResults();
98      }
99  
100     protected void sendTestData(int iterations) throws Exception
101     {
102         UMOImmutableEndpoint ep = new ImmutableMuleEndpoint(
103             "axis:http://localhost:60198/mule/services/testComponent?method=receiveMessageWithAttachments",
104             false);
105 
106         AxisMessageDispatcher client = new AxisMessageDispatcher(ep);
107         for (int i = 0; i < iterations; i++)
108         {
109             UMOMessage msg = new MuleMessage("testPayload");
110             File tempFile = File.createTempFile("test", ".att");
111             tempFile.deleteOnExit();
112             msg.addAttachment("testAttachment", new DataHandler(new FileDataSource(tempFile)));
113             MuleSession session = new MuleSession(msg, ((AbstractConnector) ep.getConnector()).getSessionHandler());
114             MuleEvent event = new MuleEvent(msg, ep, session, true);
115             UMOMessage result = client.send(event);
116             assertNotNull(result);
117             assertNotNull(result.getPayload());
118             assertEquals(result.getPayloadAsString(), "Done");
119             callbackCount++;
120         }
121     }
122 
123     protected void receiveAndTestResults() throws Exception
124     {
125         assertEquals(5, callbackCount);
126     }
127 }