KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > atlassian > seraph > auth > TestDefaultAuthenticator


1 package com.atlassian.seraph.auth;
2
3 import junit.framework.TestCase;
4 import com.atlassian.seraph.config.SecurityConfigImpl;
5 import com.atlassian.seraph.config.ConfigurationException;
6 import com.atlassian.seraph.interceptor.LogoutInterceptor;
7 import com.atlassian.seraph.interceptor.Interceptor;
8 import com.mockobjects.dynamic.Mock;
9 import com.mockobjects.dynamic.C;
10
11 import javax.servlet.http.HttpServletRequest JavaDoc;
12 import javax.servlet.http.HttpSession JavaDoc;
13 import javax.servlet.http.HttpServletResponse JavaDoc;
14
15 public class TestDefaultAuthenticator extends TestCase
16 {
17     public TestDefaultAuthenticator(String JavaDoc string)
18     {
19         super(string);
20     }
21
22     public void testLogout() throws ConfigurationException, AuthenticatorException
23     {
24         // mocks
25
Mock logoutInterceptor = new Mock(LogoutInterceptor.class);
26         Mock request = new Mock(HttpServletRequest JavaDoc.class);
27         Mock response = new Mock(HttpServletResponse JavaDoc.class);
28         Mock session = new Mock(HttpSession JavaDoc.class);
29
30         SecurityConfigImpl config = SecurityConfigImpl.getInstance("test-seraph-config.xml");
31
32         // expectations
33
HttpServletRequest JavaDoc requestProxy = (HttpServletRequest JavaDoc)request.proxy();
34         HttpServletResponse JavaDoc responseProxy = (HttpServletResponse JavaDoc)response.proxy();
35         request.expectAndReturn("getSession", session.proxy());
36         request.expectAndReturn("getSession", session.proxy());
37         request.expectAndReturn("getContextPath", "");
38
39         session.expect("setAttribute", C.args(C.eq(DefaultAuthenticator.LOGGED_IN_KEY), C.IS_NULL));
40         session.expect("setAttribute", C.args(C.eq(DefaultAuthenticator.LOGGED_OUT_KEY), C.eq(Boolean.TRUE)));
41
42         logoutInterceptor.expect("beforeLogout", C.ANY_ARGS);
43         logoutInterceptor.expect("afterLogout", C.ANY_ARGS);
44         config.addInterceptor((Interceptor)logoutInterceptor.proxy());
45
46         // do test!
47
Authenticator auth = config.getAuthenticator();
48         auth.logout(requestProxy, null);
49
50         // verify everything
51
request.verify();
52         response.verify();
53         session.verify();
54         logoutInterceptor.verify();
55     }
56 }
57
Popular Tags