KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > magnolia > cms > servlets > PropertyInitializerTest


1 /**
2  *
3  * Magnolia and its source-code is licensed under the LGPL.
4  * You may copy, adapt, and redistribute this file for commercial or non-commercial use.
5  * When copying, adapting, or redistributing this document in keeping with the guidelines above,
6  * you are required to provide proper attribution to obinary.
7  * If you reproduce or distribute the document without making any substantive modifications to its content,
8  * please use the following attribution line:
9  *
10  * Copyright 1993-2006 obinary Ltd. (http://www.obinary.com) All rights reserved.
11  *
12  */

13 package info.magnolia.cms.servlets;
14
15 import junit.framework.TestCase;
16 import static org.easymock.EasyMock.*;
17
18 import javax.servlet.ServletContext JavaDoc;
19
20 /**
21  * TODO : we should also handle the cases when servletContext.getRealPath() returns null - see javadoc
22  *
23  * @author gjoseph
24  * @version $Revision: $ ($Author: $)
25  */

26 public class PropertyInitializerTest extends TestCase {
27     private ServletContext JavaDoc servletContext;
28     private PropertyInitializer propInit;
29
30     protected void setUp() throws Exception JavaDoc {
31         super.setUp();
32         servletContext = createStrictMock(ServletContext JavaDoc.class);
33         propInit = new PropertyInitializer();
34     }
35
36     protected void tearDown() throws Exception JavaDoc {
37         super.tearDown();
38         verify(servletContext);
39     }
40
41     public void testInitRootPathJustWorks() {
42         expectServletContextRealPath("/foo/bar");
43         assertEquals("/foo/bar", propInit.initRootPath(servletContext));
44     }
45
46     public void testInitRootPathStripsTrailingSlash() {
47         expectServletContextRealPath("/foo/bar/");
48         assertEquals("/foo/bar", propInit.initRootPath(servletContext));
49     }
50
51     public void testInitRootPathTranslatesBackslashes() {
52         expectServletContextRealPath("\\foo\\bar");
53         assertEquals("/foo/bar", propInit.initRootPath(servletContext));
54     }
55
56     public void testInitRootPathTranslatesBackslashesAndStripsTrailingSlash() {
57         expectServletContextRealPath("\\foo\\bar\\");
58         assertEquals("/foo/bar", propInit.initRootPath(servletContext));
59     }
60
61     public void testInitWebappNameJustWorks() {
62         expectServletContextRealPath("/foo/bar");
63         final String JavaDoc rootPath = propInit.initRootPath(servletContext);
64         assertEquals("bar", propInit.initWebappName(rootPath));
65     }
66
67     public void testInitWebappNameWorksWithTrailingSlashes() {
68         expectServletContextRealPath("/foo/bar/");
69         final String JavaDoc rootPath = propInit.initRootPath(servletContext);
70         assertEquals("bar", propInit.initWebappName(rootPath));
71     }
72
73     public void testInitWebappNameWorksWithBackslashes() {
74         expectServletContextRealPath("\\foo\\bar");
75         final String JavaDoc rootPath = propInit.initRootPath(servletContext);
76         assertEquals("bar", propInit.initWebappName(rootPath));
77     }
78
79     public void testInitWebappNameWorksWithTrailingSlashesAndBackslashes() {
80         expectServletContextRealPath("\\foo\\bar\\");
81         final String JavaDoc rootPath = propInit.initRootPath(servletContext);
82         assertEquals("bar", propInit.initWebappName(rootPath));
83     }
84
85     private void expectServletContextRealPath(String JavaDoc returnedPath) {
86         expect(servletContext.getRealPath("")).andReturn(returnedPath);
87         replay(servletContext);
88     }
89 }
90
Popular Tags