1   /*
2    * $Id: SecureHttpPollingFunctionalTestCase.java 11983 2008-06-10 15:16:36Z rossmason $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.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  package org.mule.module.acegi;
11  
12  import org.mule.api.MuleMessage;
13  import org.mule.api.context.notification.SecurityNotificationListener;
14  import org.mule.api.context.notification.ServerNotification;
15  import org.mule.module.client.MuleClient;
16  import org.mule.tck.FunctionalTestCase;
17  import org.mule.util.concurrent.Latch;
18  import org.mule.transport.http.HttpConstants;
19  import org.mule.transport.http.HttpConnector;
20  
21  import edu.emory.mathcs.backport.java.util.concurrent.TimeUnit;
22  
23  public class SecureHttpPollingFunctionalTestCase extends FunctionalTestCase
24  {
25  
26      public void testPollingHttpConnectorSentCredentials() throws Exception
27      {
28          final Latch latch = new Latch();
29          muleContext.registerListener(new SecurityNotificationListener()
30          {
31              public void onNotification(ServerNotification notification)
32              {
33                  latch.countDown();
34              }
35          });
36          MuleClient client = new MuleClient();
37          MuleMessage result = client.request("vm://toclient", 5000);
38          assertNotNull(result);
39          assertEquals("foo", result.getPayloadAsString());
40  
41          result = client.request("vm://toclient2", 1000);
42          //This seems a little odd that we forward the exception to the outbound endpoint, but I guess users
43          // can just add a filter
44          assertNotNull(result);
45          assertEquals(401, result.getIntProperty(HttpConnector.HTTP_STATUS_PROPERTY, 0));
46          assertTrue(latch.await(1000, TimeUnit.MILLISECONDS));
47  
48      }
49  
50      protected String getConfigResources()
51      {
52          return "secure-http-polling-server.xml,secure-http-polling-client.xml";
53      }
54      
55  }