View Javadoc

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