View Javadoc

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