View Javadoc

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