1
2
3
4
5
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
51
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 }