View Javadoc

1   /*
2    * $Id: HttpPollingWithTransformersFunctionalTestCase.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.assertFalse;
15  import static org.junit.Assert.assertNotNull;
16  import static org.junit.Assert.assertTrue;
17  
18  import java.util.Arrays;
19  import java.util.Collection;
20  import java.util.concurrent.TimeUnit;
21  import java.util.concurrent.atomic.AtomicBoolean;
22  
23  import org.junit.Rule;
24  import org.junit.Test;
25  import org.junit.runners.Parameterized.Parameters;
26  import org.mule.api.MuleMessage;
27  import org.mule.api.context.notification.ServerNotification;
28  import org.mule.module.client.MuleClient;
29  import org.mule.tck.AbstractServiceAndFlowTestCase;
30  import org.mule.tck.functional.FunctionalTestNotificationListener;
31  import org.mule.tck.junit4.rule.DynamicPort;
32  import org.mule.util.concurrent.Latch;
33  
34  public class HttpPollingWithTransformersFunctionalTestCase extends AbstractServiceAndFlowTestCase
35  {
36  
37      @Rule
38      public DynamicPort dynamicPort = new DynamicPort("port1");
39  
40      public HttpPollingWithTransformersFunctionalTestCase(ConfigVariant variant, String configResources)
41      {
42          super(variant, configResources);
43      }
44  
45      @Parameters
46      public static Collection<Object[]> parameters()
47      {
48          return Arrays.asList(new Object[][]{
49              {ConfigVariant.SERVICE, "mule-http-polling-with-transformers-config-service.xml"},
50              {ConfigVariant.FLOW, "mule-http-polling-with-transformers-config-flow.xml"}});
51      }
52  
53      @Test
54      public void testPollingHttpConnector() throws Exception
55      {
56          final Latch latch = new Latch();
57          final AtomicBoolean transformPropagated = new AtomicBoolean(false);
58          muleContext.registerListener(new FunctionalTestNotificationListener()
59          {
60              public void onNotification(ServerNotification notification)
61              {
62                  latch.countDown();
63                  if (notification.getSource().toString().endsWith("toClient-only"))
64                  {
65                      transformPropagated.set(true);
66                  }
67              }
68          }, "polledUMO");
69  
70          MuleClient client = new MuleClient(muleContext);
71          MuleMessage result = client.request("vm://toclient", 50000);
72          assertNotNull(result.getPayload());
73          assertTrue("Callback called", latch.await(1000, TimeUnit.MILLISECONDS));
74          assertEquals("/foo toClient-only", result.getPayloadAsString());
75          // The transform should not have been propagated to the outbound endpoint
76          assertFalse(transformPropagated.get());
77      }
78  
79  }