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.MuleMessage;
10  import org.mule.api.context.notification.ServerNotification;
11  import org.mule.module.client.MuleClient;
12  import org.mule.tck.functional.FunctionalTestNotificationListener;
13  import org.mule.tck.junit4.FunctionalTestCase;
14  import org.mule.tck.junit4.rule.DynamicPort;
15  import org.mule.util.concurrent.Latch;
16  
17  import edu.emory.mathcs.backport.java.util.concurrent.TimeUnit;
18  import edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicBoolean;
19  import org.junit.Rule;
20  import org.junit.Test;
21  
22  import static org.junit.Assert.assertEquals;
23  import static org.junit.Assert.assertFalse;
24  import static org.junit.Assert.assertNotNull;
25  import static org.junit.Assert.assertTrue;
26  
27  public class HttpPollingWithTransformersFunctionalTestCase extends FunctionalTestCase
28  {
29  
30      @Rule
31      public DynamicPort dynamicPort = new DynamicPort("port1");
32  
33      @Override
34      protected String getConfigResources()
35      {
36          return "mule-http-polling-with-transformers-config.xml";
37      }
38  
39      @Test
40      public void testPollingHttpConnector() throws Exception
41      {
42          final Latch latch = new Latch();
43          final AtomicBoolean transformPropagated = new AtomicBoolean(false);
44          muleContext.registerListener(new FunctionalTestNotificationListener()
45          {
46              public void onNotification(ServerNotification notification)
47              {
48                  latch.countDown();
49                  if(notification.getSource().toString().endsWith("toClient-only"))
50                  {
51                      transformPropagated.set(true);
52                  }
53              }
54          }, "polledUMO");
55  
56          MuleClient client = new MuleClient(muleContext);
57          MuleMessage result = client.request("vm://toclient", 50000);
58          assertNotNull(result.getPayload());
59          assertTrue("Callback called", latch.await(1000, TimeUnit.MILLISECONDS));
60          assertEquals("/foo toClient-only", result.getPayloadAsString());
61          //The transform should not have been propagated to the outbound endpoint
62          assertFalse(transformPropagated.get());
63      }
64  
65  }