View Javadoc

1   /*
2    * $Id: SecureHttpPollingFunctionalTestCase.java 19191 2010-08-25 21:05:23Z tcarlson $
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  package org.mule.module.acegi;
11  
12  import org.mule.api.MuleMessage;
13  import org.mule.api.context.notification.SecurityNotificationListener;
14  import org.mule.context.notification.SecurityNotification;
15  import org.mule.module.client.MuleClient;
16  import org.mule.tck.FunctionalTestCase;
17  import org.mule.transport.http.HttpConnector;
18  import org.mule.util.concurrent.Latch;
19  
20  import edu.emory.mathcs.backport.java.util.concurrent.TimeUnit;
21  
22  public class SecureHttpPollingFunctionalTestCase extends FunctionalTestCase
23  {
24  
25      public void testPollingHttpConnectorSentCredentials() throws Exception
26      {
27          final Latch latch = new Latch();
28          muleContext.registerListener(new SecurityNotificationListener<SecurityNotification>()
29          {
30              public void onNotification(SecurityNotification notification)
31              {
32                  latch.countDown();
33              }
34          });
35          MuleClient client = new MuleClient(muleContext);
36          MuleMessage result = client.request("vm://toclient", 5000);
37          assertNotNull(result);
38          assertEquals("foo", result.getPayloadAsString());
39  
40          result = client.request("vm://toclient2", 1000);
41          //This seems a little odd that we forward the exception to the outbound endpoint, but I guess users
42          // can just add a filter
43          assertNotNull(result);
44          int status = result.getInboundProperty(HttpConnector.HTTP_STATUS_PROPERTY, 0);
45          assertEquals(401, status);
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  }