View Javadoc

1   /*
2    * $Id: HttpDynamicFunctionalTestCase.java 19817 2010-10-04 18:10:39Z dzapata $
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.http.functional;
12  
13  import org.mule.api.MuleEventContext;
14  import org.mule.api.MuleMessage;
15  import org.mule.module.client.MuleClient;
16  import org.mule.tck.DynamicPortTestCase;
17  import org.mule.tck.FunctionalTestCase;
18  import org.mule.tck.functional.EventCallback;
19  import org.mule.tck.functional.FunctionalTestComponent;
20  import org.mule.util.concurrent.Latch;
21  
22  import java.util.HashMap;
23  import java.util.Map;
24  
25  import edu.emory.mathcs.backport.java.util.concurrent.TimeUnit;
26  
27  public class HttpDynamicFunctionalTestCase extends DynamicPortTestCase
28  {
29      protected static String TEST_MESSAGE = "Test Http Request";
30  
31      protected String getConfigResources()
32      {
33          return "http-dynamic-functional-test.xml";
34      }
35  
36      public void testSend() throws Exception
37      {
38          final Latch latch1 = new Latch();
39          final Latch latch2 = new Latch();
40          FunctionalTestComponent tc1 = getFunctionalTestComponent("testComponent1");
41          FunctionalTestComponent tc2 = getFunctionalTestComponent("testComponent2");
42          assertNotNull(tc1);
43          assertNotNull(tc2);
44  
45              tc1.setEventCallback(new EventCallback() {
46                  public void eventReceived(MuleEventContext context, Object component) throws Exception
47                  {
48                      latch1.release();
49                  }
50              });
51              tc2.setEventCallback(new EventCallback(){
52                  public void eventReceived(MuleEventContext context, Object component) throws Exception
53                  {
54                      latch2.release();
55                  }
56              });
57  
58          MuleClient client = new MuleClient(muleContext);
59          Map<String, Object> props = new HashMap<String, Object>();
60          props.put("port", getPorts().get(0));
61          props.put("path", "foo");
62          MuleMessage result = client.send("clientEndpoint", TEST_MESSAGE, props);
63          assertEquals(TEST_MESSAGE + " Received", result.getPayloadAsString());
64  
65          assertTrue(latch1.await(3000, TimeUnit.MILLISECONDS));
66  
67          props.put("port", getPorts().get(1));
68          result = client.send("clientEndpoint", TEST_MESSAGE, props);
69          assertEquals(TEST_MESSAGE + " Received", result.getPayloadAsString());
70  
71          assertTrue(latch2.await(3000, TimeUnit.MILLISECONDS));
72      }
73  
74      @Override
75      protected int getNumPortsToFind()
76      {
77          return 2;
78      }
79  }