View Javadoc

1   /*
2    * $Id: HttpPollingFunctionalTestCase.java 22525 2011-07-22 09:39:16Z 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.transport.http.functional;
12  
13  import static org.junit.Assert.assertEquals;
14  import static org.junit.Assert.assertNotNull;
15  
16  import java.util.Arrays;
17  import java.util.Collection;
18  
19  import org.junit.Rule;
20  import org.junit.Test;
21  import org.junit.runners.Parameterized.Parameters;
22  import org.mule.api.MuleEventContext;
23  import org.mule.api.MuleMessage;
24  import org.mule.module.client.MuleClient;
25  import org.mule.tck.AbstractServiceAndFlowTestCase;
26  import org.mule.tck.functional.EventCallback;
27  import org.mule.tck.functional.FunctionalTestComponent;
28  import org.mule.tck.junit4.rule.DynamicPort;
29  
30  public class HttpPollingFunctionalTestCase extends AbstractServiceAndFlowTestCase
31  {
32  
33      @Rule
34      public DynamicPort dynamicPort = new DynamicPort("port1");
35  
36      public HttpPollingFunctionalTestCase(ConfigVariant variant, String configResources)
37      {
38          super(variant, configResources);
39      }
40  
41      @Parameters
42      public static Collection<Object[]> parameters()
43      {
44          return Arrays.asList(new Object[][]{{ConfigVariant.SERVICE, "mule-http-polling-config-service.xml"},
45              {ConfigVariant.FLOW, "mule-http-polling-config-flow.xml"}});
46      }
47  
48      @Test
49      public void testPollingHttpConnector() throws Exception
50      {
51          FunctionalTestComponent ftc = getFunctionalTestComponent("polled");
52          assertNotNull(ftc);
53          ftc.setEventCallback(new EventCallback()
54          {
55              public void eventReceived(MuleEventContext context, Object component) throws Exception
56              {
57                  assertEquals("The Accept header should be set on the incoming message", "application/xml",
58                      context.getMessage().<String> getInboundProperty("Accept"));
59              }
60          });
61          MuleClient client = new MuleClient(muleContext);
62          MuleMessage result = client.request("vm://toclient", RECEIVE_TIMEOUT);
63          assertNotNull(result.getPayload());
64          assertEquals("foo", result.getPayloadAsString());
65      }
66  
67  }