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.MuleEventContext;
10  import org.mule.api.MuleMessage;
11  import org.mule.module.client.MuleClient;
12  import org.mule.tck.functional.EventCallback;
13  import org.mule.tck.functional.FunctionalTestComponent;
14  import org.mule.tck.junit4.FunctionalTestCase;
15  import org.mule.tck.junit4.rule.DynamicPort;
16  
17  import org.junit.Rule;
18  import org.junit.Test;
19  
20  import static org.junit.Assert.assertEquals;
21  import static org.junit.Assert.assertNotNull;
22  
23  public class HttpPollingFunctionalTestCase extends FunctionalTestCase
24  {
25  
26      @Rule
27      public DynamicPort dynamicPort = new DynamicPort("port1");
28  
29      @Override
30      protected String getConfigResources()
31      {
32          return "mule-http-polling-config.xml";
33      }
34  
35      @Test
36      public void testPollingHttpConnector() throws Exception
37      {
38          FunctionalTestComponent ftc = getFunctionalTestComponent("polled");
39          assertNotNull(ftc);
40          ftc.setEventCallback(new EventCallback(){
41              public void eventReceived(MuleEventContext context, Object component) throws Exception
42              {
43                  assertEquals("The Accept header should be set on the incoming message", "application/xml", context.getMessage().<String>getInboundProperty("Accept"));
44              }
45          });
46          MuleClient client = new MuleClient(muleContext);
47          MuleMessage result = client.request("vm://toclient", RECEIVE_TIMEOUT);
48          assertNotNull(result.getPayload());
49          assertEquals("foo", result.getPayloadAsString());
50      }
51  
52  }