KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > atlassian > seraph > logout > TestLogoutServlet


1 package com.atlassian.seraph.logout;
2
3 import com.atlassian.seraph.auth.Authenticator;
4 import com.atlassian.seraph.config.SecurityConfig;
5 import com.atlassian.seraph.config.SecurityConfigFactory;
6 import com.mockobjects.dynamic.C;
7 import com.mockobjects.dynamic.Mock;
8 import com.mockobjects.servlet.MockHttpServletRequest;
9 import com.mockobjects.servlet.MockHttpServletResponse;
10 import junit.framework.TestCase;
11
12 import javax.servlet.ServletException JavaDoc;
13 import java.io.IOException JavaDoc;
14
15 public class TestLogoutServlet extends TestCase
16 {
17     private MockHttpServletRequest mockRequest;
18     private MockHttpServletResponse mockResponse;
19     Mock mockSecurityConfig;
20     private LogoutServlet logoutServlet;
21     private Mock mockAuthenticator;
22
23     public TestLogoutServlet()
24     {
25     }
26
27     protected void setUp() throws Exception JavaDoc
28     {
29         super.setUp();
30
31         // Create a project to redirect too
32
mockRequest = new MockHttpServletRequest();
33         mockRequest.setupGetContextPath("/ctx");
34         mockResponse = new MockHttpServletResponse();
35         mockSecurityConfig = new Mock(SecurityConfig.class);
36         mockAuthenticator = new Mock(Authenticator.class);
37         mockAuthenticator.expectAndReturn("logout", C.args(C.isA(MockHttpServletRequest.class), C.isA(MockHttpServletResponse.class)), Boolean.TRUE);
38 // mockAuthenticator.expectAndReturn("logout", C.ANY_ARGS, Boolean.TRUE);
39
// mockAuthenticator.expect("logout", C.args(C.isA(HttpServletRequest.class), C.isA(HttpServletResponse.class)));
40
mockSecurityConfig.expectAndReturn("getAuthenticator", mockAuthenticator.proxy());
41         logoutServlet = new LogoutServlet();
42     }
43
44     public void testInternalLogoutPageCausesRedirectWithNoLogoutCalled() throws IOException JavaDoc, ServletException JavaDoc
45     {
46         SecurityConfigFactory.setSecurityConfig((SecurityConfig) mockSecurityConfig.proxy());
47         logoutServlet.init();
48         mockSecurityConfig.expectAndReturn("getLogoutURL", "/logout.jsp");
49         mockSecurityConfig.expectAndReturn("getLogoutURL", "/logout.jsp");
50         mockResponse.setExpectedRedirect("/ctx/logout.jsp");
51         logoutServlet.service(mockRequest, mockResponse);
52     }
53
54     public void testExternalLogoutPageCausesLogoutAndRedirect() throws IOException JavaDoc, ServletException JavaDoc
55     {
56         SecurityConfigFactory.setSecurityConfig((SecurityConfig) mockSecurityConfig.proxy());
57         logoutServlet.init();
58         mockRequest.setupGetContextPath("/ctx");
59         mockSecurityConfig.expectAndReturn("getLogoutURL", "http://some.external.sso.page/");
60         mockSecurityConfig.expectAndReturn("getLogoutURL", "http://some.external.sso.page/");
61         mockResponse.setExpectedRedirect("http://some.external.sso.page/");
62
63         logoutServlet.service(mockRequest, mockResponse);
64     }
65
66 }
67
Popular Tags