View Javadoc

1   /*
2    * $Id: HttpDynamicFunctionalTestCase.java 22518 2011-07-22 07:00:22Z claude.mamo $
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 static org.junit.Assert.assertEquals;
14  
15  import org.mule.api.MuleMessage;
16  import org.mule.module.client.MuleClient;
17  import org.mule.tck.AbstractServiceAndFlowTestCase;
18  import org.mule.tck.junit4.rule.DynamicPort;
19  
20  import java.util.Arrays;
21  import java.util.Collection;
22  import java.util.HashMap;
23  import java.util.Map;
24  
25  import org.junit.Rule;
26  import org.junit.Test;
27  import org.junit.runners.Parameterized.Parameters;
28  
29  public class HttpDynamicFunctionalTestCase extends AbstractServiceAndFlowTestCase
30  {
31      protected static String TEST_REQUEST = "Test Http Request";
32  
33      @Rule
34      public DynamicPort dynamicPort1 = new DynamicPort("port1");
35  
36      @Rule
37      public DynamicPort dynamicPort2 = new DynamicPort("port2");
38  
39      public HttpDynamicFunctionalTestCase(ConfigVariant variant, String configResources)
40      {
41          super(variant, configResources);
42      }
43  
44      @Parameters
45      public static Collection<Object[]> parameters()
46      {
47          return Arrays.asList(new Object[][]{
48              {ConfigVariant.SERVICE, "http-dynamic-functional-test-flow.xml"},
49              {ConfigVariant.FLOW, "http-dynamic-functional-test-service.xml"}
50          });
51      }      
52      
53      @Test
54      public void testSend() throws Exception
55      {
56          MuleClient client = new MuleClient(muleContext);
57  
58          Map<String, Object> props = new HashMap<String, Object>();
59          props.put("port", dynamicPort1.getNumber());
60          props.put("path", "foo");
61  
62          MuleMessage result = client.send("clientEndpoint", TEST_REQUEST, props);
63          assertEquals(TEST_REQUEST + " Received 1", result.getPayloadAsString());
64  
65          props.put("port", dynamicPort2.getNumber());
66          result = client.send("clientEndpoint", TEST_REQUEST, props);
67          assertEquals(TEST_REQUEST + " Received 2", result.getPayloadAsString());
68      }
69  }