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.module.spring.security;
8   
9   import org.mule.api.MuleMessage;
10  import org.mule.api.context.notification.SecurityNotificationListener;
11  import org.mule.context.notification.SecurityNotification;
12  import org.mule.module.client.MuleClient;
13  import org.mule.tck.junit4.FunctionalTestCase;
14  import org.mule.transport.http.HttpConnector;
15  import org.mule.util.concurrent.Latch;
16  
17  import edu.emory.mathcs.backport.java.util.concurrent.TimeUnit;
18  import org.junit.Test;
19  
20  import static org.junit.Assert.assertEquals;
21  import static org.junit.Assert.assertNotNull;
22  import static org.junit.Assert.assertTrue;
23  
24  public class SecureHttpPollingFunctionalTestCase extends FunctionalTestCase
25  {
26  
27      @Override
28      protected String getConfigResources()
29      {
30          return "secure-http-polling-server.xml,secure-http-polling-client.xml";
31      }
32  
33      @Test
34      public void testPollingHttpConnectorSentCredentials() throws Exception
35      {
36          final Latch latch = new Latch();
37          muleContext.registerListener(new SecurityNotificationListener<SecurityNotification>()
38          {
39              public void onNotification(SecurityNotification notification)
40              {
41                  latch.countDown();
42              }
43          });
44          MuleClient client = new MuleClient(muleContext);
45          MuleMessage result = client.request("vm://toclient", 5000);
46          assertNotNull(result);
47          assertEquals("foo", result.getPayloadAsString());
48  
49          result = client.request("vm://toclient2", 1000);
50          //This seems a little odd that we forward the exception to the outbound endpoint, but I guess users
51          // can just add a filter
52          assertNotNull(result);
53          final int status = result.getInboundProperty(HttpConnector.HTTP_STATUS_PROPERTY, 0);
54          assertEquals(401, status);
55          assertTrue(latch.await(1000, TimeUnit.MILLISECONDS));
56      }
57  
58  }