View Javadoc

1   /*
2    * $Id: MultipleResourcesTestCase.java 22520 2011-07-22 07:35:40Z justin.calleja $
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.jersey;
12  
13  import static org.junit.Assert.assertEquals;
14  
15  import java.util.Arrays;
16  import java.util.Collection;
17  import java.util.HashMap;
18  import java.util.Map;
19  
20  import org.junit.Test;
21  import org.junit.runners.Parameterized.Parameters;
22  import org.mule.api.MuleMessage;
23  import org.mule.module.client.MuleClient;
24  import org.mule.tck.AbstractServiceAndFlowTestCase;
25  import org.mule.transport.http.HttpConnector;
26  import org.mule.transport.http.HttpConstants;
27  
28  /**
29   * Tests that the jersey:resources component can handle multiple components
30   * correctly.
31   */
32  public class MultipleResourcesTestCase extends AbstractServiceAndFlowTestCase
33  {
34  
35      public MultipleResourcesTestCase(ConfigVariant variant, String configResources)
36      {
37          super(variant, configResources);
38      }
39      
40      @Parameters
41      public static Collection<Object[]> parameters()
42      {
43          return Arrays.asList(new Object[][]{
44              {ConfigVariant.SERVICE, "multiple-resources-conf-service.xml"},
45              {ConfigVariant.FLOW, "multiple-resources-conf-flow.xml"}
46          });
47      }
48  
49      @Test
50      public void testParams() throws Exception
51      {
52          MuleClient client = new MuleClient(muleContext);
53  
54          Map<String, String> props = new HashMap<String, String>();
55          props.put(HttpConnector.HTTP_METHOD_PROPERTY, HttpConstants.METHOD_GET);
56          MuleMessage result = client.send("http://localhost:63081/helloworld/sayHelloWithUri/Dan", "", props);
57          assertEquals((Integer)200, result.getInboundProperty(HttpConnector.HTTP_STATUS_PROPERTY, 0));
58          assertEquals("Hello Dan", result.getPayloadAsString());
59  
60          result = client.send("http://localhost:63081/anotherworld/sayHelloWithUri/Dan", "", props);
61          assertEquals((Integer)200, result.getInboundProperty(HttpConnector.HTTP_STATUS_PROPERTY, 0));
62          assertEquals("Bonjour Dan", result.getPayloadAsString());
63      }
64  
65  }