1 package com.opensymphony.module.sitemesh.mapper; 2 3 import junit.framework.TestCase; 4 5 public class PathMapperTest extends TestCase { 6 7 private PathMapper pathMapper; 8 9 protected void setUp() throws Exception { 10 super.setUp(); 11 12 pathMapper = new PathMapper(); 13 14 pathMapper.put("exact1", "/myexactfile.html"); 16 pathMapper.put("exact2", "/mydir/myexactfile.html"); 17 pathMapper.put("exact3", "/mydir/myexactfile.jsp"); 18 pathMapper.put("exact4", "/mydir/dodo"); 19 20 pathMapper.put("complex1", "/mydir/*"); 22 pathMapper.put("complex2", "/mydir/otherdir/*.jsp"); 23 pathMapper.put("complex3", "/otherdir/*.??p"); 24 pathMapper.put("complex4", "*.xml"); 25 pathMapper.put("complex5", "/*/admin/*.??ml"); 26 pathMapper.put("complex6", "/*/complexx/a*b.x?tml"); 27 28 pathMapper.put("default", "*"); 30 } 31 32 public void testHardening() throws Exception { 33 PathMapper bad = new PathMapper(); 34 bad.put(null, null); 35 assertNull(bad.get(null)); 36 assertNull(bad.get("")); 37 assertNull(bad.get("/somenonexistingpath")); 38 } 39 40 public void testFindExactKey() throws Exception { 41 assertEquals("exact1", pathMapper.get("/myexactfile.html")); 42 assertEquals("exact2", pathMapper.get("/mydir/myexactfile.html")); 43 assertEquals("exact3", pathMapper.get("/mydir/myexactfile.jsp")); 44 assertEquals("exact4", pathMapper.get("/mydir/dodo")); 45 } 46 47 public void testFindComplexKey() throws Exception { 48 assertEquals("complex1", pathMapper.get("/mydir/")); 49 assertEquals("complex1", pathMapper.get("/mydir/test1.xml")); 50 assertEquals("complex1", pathMapper.get("/mydir/test321.jsp")); 51 assertEquals("complex1", pathMapper.get("/mydir/otherdir")); 52 53 assertEquals("complex2", pathMapper.get("/mydir/otherdir/test321.jsp")); 54 55 assertEquals("complex3", pathMapper.get("/otherdir/test2.jsp")); 56 assertEquals("complex3", pathMapper.get("/otherdir/test2.bpp")); 57 58 assertEquals("complex4", pathMapper.get("/somedir/one/two/some/deep/file/test.xml")); 59 assertEquals("complex4", pathMapper.get("/somedir/321.jsp.xml")); 60 61 assertEquals("complex5", pathMapper.get("/mydir/otherdir/admin/myfile.html")); 62 assertEquals("complex5", pathMapper.get("/mydir/somedir/admin/text.html")); 63 64 assertEquals("complex6", pathMapper.get("/mydir/complexx/a-some-test-b.xctml")); 65 assertEquals("complex6", pathMapper.get("/mydir/complexx/a b.xhtml")); 66 assertEquals("complex6", pathMapper.get("/mydir/complexx/a___b.xhtml")); 67 } 68 69 public void testFindDefaultKey() throws Exception { 70 assertEquals("default", pathMapper.get(null)); 71 assertEquals("default", pathMapper.get("/")); 72 assertEquals("default", pathMapper.get("/*")); 73 assertEquals("default", pathMapper.get("*")); 74 assertEquals("default", pathMapper.get("blah.txt")); 75 assertEquals("default", pathMapper.get("somefilewithoutextension")); 76 assertEquals("default", pathMapper.get("/file_with_underscores-and-dashes.test")); 77 assertEquals("default", pathMapper.get("/tuuuu*/file.with.dots.test.txt")); 78 } 79 } | Popular Tags |