View Javadoc

1   /*
2    * $Id: SecureHttpPollingFunctionalTestCase.java 22485 2011-07-21 08:26:15Z 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  package org.mule.module.spring.security;
11  
12  import static org.junit.Assert.assertEquals;
13  import static org.junit.Assert.assertNotNull;
14  import static org.junit.Assert.assertTrue;
15  
16  import java.util.Arrays;
17  import java.util.Collection;
18  import java.util.concurrent.TimeUnit;
19  
20  import org.junit.Test;
21  import org.junit.runners.Parameterized.Parameters;
22  import org.mule.api.MuleMessage;
23  import org.mule.api.context.notification.SecurityNotificationListener;
24  import org.mule.context.notification.SecurityNotification;
25  import org.mule.module.client.MuleClient;
26  import org.mule.tck.AbstractServiceAndFlowTestCase;
27  import org.mule.transport.http.HttpConnector;
28  import org.mule.util.concurrent.Latch;
29  
30  public class SecureHttpPollingFunctionalTestCase extends AbstractServiceAndFlowTestCase
31  {
32      public SecureHttpPollingFunctionalTestCase(ConfigVariant variant, String configResources)
33      {
34          super(variant, configResources);
35      }
36  
37      @Parameters
38      public static Collection<Object[]> parameters()
39      {
40          return Arrays.asList(new Object[][]{
41              {ConfigVariant.SERVICE, "secure-http-polling-server-service.xml,secure-http-polling-client-service.xml"},
42              {ConfigVariant.FLOW, "secure-http-polling-server-flow.xml,secure-http-polling-client-flow.xml"}
43              });
44      }
45  
46      @Test
47      public void testPollingHttpConnectorSentCredentials() throws Exception
48      {
49          final Latch latch = new Latch();
50          muleContext.registerListener(new SecurityNotificationListener<SecurityNotification>()
51          {
52              @Override
53              public void onNotification(SecurityNotification notification)
54              {
55                  latch.countDown();
56              }
57          });
58          MuleClient client = new MuleClient(muleContext);
59          MuleMessage result = client.request("vm://toclient", 5000);
60          assertNotNull(result);
61          assertEquals("foo", result.getPayloadAsString());
62  
63          result = client.request("vm://toclient2", 1000);
64          //This seems a little odd that we forward the exception to the outbound endpoint, but I guess users
65          // can just add a filter
66          assertNotNull(result);
67          final int status = result.getInboundProperty(HttpConnector.HTTP_STATUS_PROPERTY, 0);
68          assertEquals(401, status);
69          assertTrue(latch.await(1000, TimeUnit.MILLISECONDS));
70      }
71  }