1 13 package info.magnolia.cms.servlets; 14 15 import junit.framework.TestCase; 16 import static org.easymock.EasyMock.*; 17 18 import javax.servlet.ServletContext ; 19 20 26 public class PropertyInitializerTest extends TestCase { 27 private ServletContext servletContext; 28 private PropertyInitializer propInit; 29 30 protected void setUp() throws Exception { 31 super.setUp(); 32 servletContext = createStrictMock(ServletContext .class); 33 propInit = new PropertyInitializer(); 34 } 35 36 protected void tearDown() throws Exception { 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 rootPath = propInit.initRootPath(servletContext); 64 assertEquals("bar", propInit.initWebappName(rootPath)); 65 } 66 67 public void testInitWebappNameWorksWithTrailingSlashes() { 68 expectServletContextRealPath("/foo/bar/"); 69 final String rootPath = propInit.initRootPath(servletContext); 70 assertEquals("bar", propInit.initWebappName(rootPath)); 71 } 72 73 public void testInitWebappNameWorksWithBackslashes() { 74 expectServletContextRealPath("\\foo\\bar"); 75 final String rootPath = propInit.initRootPath(servletContext); 76 assertEquals("bar", propInit.initWebappName(rootPath)); 77 } 78 79 public void testInitWebappNameWorksWithTrailingSlashesAndBackslashes() { 80 expectServletContextRealPath("\\foo\\bar\\"); 81 final String rootPath = propInit.initRootPath(servletContext); 82 assertEquals("bar", propInit.initWebappName(rootPath)); 83 } 84 85 private void expectServletContextRealPath(String returnedPath) { 86 expect(servletContext.getRealPath("")).andReturn(returnedPath); 87 replay(servletContext); 88 } 89 } 90 | Popular Tags |