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.transport.http.functional;
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.HashMap;
15  import java.util.Map;
16  
17  import org.junit.Rule;
18  import org.junit.Test;
19  
20  import static org.junit.Assert.assertEquals;
21  
22  public class HttpDynamicFunctionalTestCase extends FunctionalTestCase
23  {
24      protected static String TEST_REQUEST = "Test Http Request";
25  
26      @Rule
27      public DynamicPort dynamicPort1 = new DynamicPort("port1");
28  
29      @Rule
30      public DynamicPort dynamicPort2 = new DynamicPort("port2");
31  
32      @Override
33      protected String getConfigResources()
34      {
35          return "http-dynamic-functional-test.xml";
36      }
37  
38      @Test
39      public void testSend() throws Exception
40      {
41          MuleClient client = new MuleClient(muleContext);
42  
43          Map<String, Object> props = new HashMap<String, Object>();
44          props.put("port", dynamicPort1.getNumber());
45          props.put("path", "foo");
46  
47          MuleMessage result = client.send("clientEndpoint", TEST_REQUEST, props);
48          assertEquals(TEST_REQUEST + " Received 1", result.getPayloadAsString());
49  
50          props.put("port", dynamicPort2.getNumber());
51          result = client.send("clientEndpoint", TEST_REQUEST, props);
52          assertEquals(TEST_REQUEST + " Received 2", result.getPayloadAsString());
53      }
54  }