View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.module.cxf.issues;
8   
9   import org.mule.api.MuleMessage;
10  import org.mule.module.client.MuleClient;
11  import org.mule.tck.junit4.FunctionalTestCase;
12  import org.mule.tck.junit4.rule.DynamicPort;
13  
14  import java.util.concurrent.CountDownLatch;
15  import java.util.concurrent.TimeUnit;
16  
17  import org.junit.Rule;
18  import org.junit.Test;
19  
20  import static org.junit.Assert.assertTrue;
21  
22  /**
23   * Tests large requests sent to the proxy and back.
24   *
25   * @author lenhag
26   */
27  public class LargeProxyTestCase extends FunctionalTestCase
28  {
29  
30      @Rule
31      public DynamicPort dynamicPort1 = new DynamicPort("port1");
32  
33      @Rule
34      public DynamicPort dynamicPort2 = new DynamicPort("port2");
35  
36      @Override
37      protected String getConfigResources()
38      {
39          return "largeproxytest-config.xml";
40      }
41  
42      @Test
43      public void testLargeMessageWithEchoProxy() throws Exception
44      {
45          int length = 5000;
46          final MuleClient client = new MuleClient(muleContext);
47  
48          StringBuffer b = new StringBuffer();
49          int counter = 1;
50          while (b.length() < length)
51          {
52              // Using a counter to make it easier to see the size
53              b.append(counter).append(" ");
54              counter++;
55          }
56          final String largeString = b.toString().trim();
57  
58          final String msg =
59                  "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" " +
60                          "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" " +
61                          "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" +
62                          "<soap:Body>" +
63                          "<echo xmlns=\"http://simple.component.mule.org/\">" +
64                          "<echo>" + largeString + "</echo>" +
65                          "</echo>" +
66                          "</soap:Body>" +
67                          "</soap:Envelope>";
68  
69          final CountDownLatch latch = new CountDownLatch(100);
70  
71          Runnable runnable = new Runnable()
72          {
73  
74              public void run()
75              {
76                  for (int i = 0; i < 20; i++)
77                  {
78                      try
79                      {
80                          MuleMessage result = client.send("http://localhost:" + dynamicPort1.getNumber() + "/services/EchoProxy", msg, null);
81                          String payloadAsStr = result.getPayloadAsString();
82                          assertTrue("The payload length should never be 0", payloadAsStr.length() != 0);
83                          assertTrue(payloadAsStr.indexOf(largeString) != -1);
84                          latch.countDown();
85                      }
86                      catch (Exception e)
87                      {
88                          e.printStackTrace();
89                      }
90                  }
91              }
92  
93          };
94  
95          for (int j = 0; j < 5; j++)
96          {
97              new Thread(runnable).start();
98          }
99  
100         latch.await(50000, TimeUnit.SECONDS);
101     }
102 
103 }