KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > atlassian > seraph > util > TestRedirectUtils


1 package com.atlassian.seraph.util;
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.atlassian.seraph.logout.LogoutServlet;
7 import com.mockobjects.dynamic.Mock;
8 import com.mockobjects.servlet.MockHttpServletResponse;
9 import junit.framework.TestCase;
10
11 import javax.servlet.ServletException JavaDoc;
12 import java.io.IOException JavaDoc;
13 import java.net.URLEncoder JavaDoc;
14
15 public class TestRedirectUtils extends TestCase
16 {
17     private LocalMockHttpServletRequest mockRequest;
18     private MockHttpServletResponse mockResponse;
19     Mock mockSecurityConfig;
20     private LogoutServlet logoutServlet;
21     private Mock mockAuthenticator;
22
23     public TestRedirectUtils()
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 LocalMockHttpServletRequest();
33         mockRequest.setupGetContextPath("/ctx");
34
35         mockResponse = new MockHttpServletResponse();
36         mockSecurityConfig = new Mock(SecurityConfig.class);
37         mockAuthenticator = new Mock(Authenticator.class);
38         SecurityConfigFactory.setSecurityConfig((SecurityConfig) mockSecurityConfig.proxy());
39     }
40
41     public void testRelativeLoginURLHasCorrectOSDestinationSet() throws IOException JavaDoc, ServletException JavaDoc
42     {
43         // our login.url parameter in seraph-config.xml.
44
mockSecurityConfig.expectAndReturn("getLoginURL", "/login.jsp?os_destination=${originalurl}");
45         mockRequest.setupGetServletPath("/browse/JRA-123");
46         mockRequest.setupPathInfo(null);
47         mockRequest.setupQueryString(null);
48         mockRequest.setupGetAttribute(null);
49         assertEquals("/ctx/login.jsp?os_destination=%2Fbrowse%2FJRA-123", RedirectUtils.getLoginUrl(mockRequest));
50     }
51
52
53     public void testAbsoluteLoginURLHasCorrectOSDestinationSet() throws IOException JavaDoc, ServletException JavaDoc
54     {
55         // our login.url parameter in seraph-config.xml.
56
mockSecurityConfig.expectAndReturn("getLoginURL", "http://sso.somecompany.com?target=${originalurl}");
57         mockRequest.setupGetAttribute(null);
58         mockRequest.setupQueryString(null);
59
60         final String JavaDoc requestURL = "http://localhost:8080/myapp/browse/JRA-123";
61         mockRequest.setupGetRequestURL(requestURL);
62         assertEquals("http://sso.somecompany.com?target="+URLEncoder.encode(requestURL), RedirectUtils.getLoginUrl(mockRequest));
63     }
64
65
66     public void testRelativeLinkLoginURLHasCorrectOSDestinationSet() throws IOException JavaDoc, ServletException JavaDoc
67     {
68         // our login.url parameter in seraph-config.xml.
69
mockSecurityConfig.expectAndReturn("getLinkLoginURL", "/login.jsp?os_destination=${originalurl}");
70         mockRequest.setupGetServletPath("/browse/JRA-123");
71         mockRequest.setupPathInfo(null);
72         mockRequest.setupQueryString(null);
73         mockRequest.setupGetAttribute(null);
74         assertEquals("/ctx/login.jsp?os_destination=%2Fbrowse%2FJRA-123", RedirectUtils.getLinkLoginURL(mockRequest));
75     }
76
77
78     public void testAbsoluteLinkLoginURLHasCorrectOSDestinationSet() throws IOException JavaDoc, ServletException JavaDoc
79     {
80         // our login.url parameter in seraph-config.xml.
81
mockSecurityConfig.expectAndReturn("getLinkLoginURL", "http://sso.somecompany.com?target=${originalurl}");
82         mockRequest.setupGetAttribute(null);
83         mockRequest.setupQueryString(null);
84
85         final String JavaDoc requestURL = "http://localhost:8080/myapp/browse/JRA-123";
86         mockRequest.setupGetRequestURL(requestURL);
87         assertEquals("http://sso.somecompany.com?target="+URLEncoder.encode(requestURL), RedirectUtils.getLinkLoginURL(mockRequest));
88     }
89
90 }
91
Popular Tags