1 package jodd.servlet; 2 3 import java.util.HashMap; 4 import java.io.*; 5 6 import javax.servlet.ServletException; 7 8 import junit.framework.TestCase; 9 10 11 public class TestActionController extends TestCase { 12 13 protected String dataRoot = "modules/testcase/data"; 14 15 public void setUp() { 16 String curDir = System.getProperty("user.dir"); 17 curDir = curDir.replace('\\', '/'); 18 if (curDir.endsWith("/testcase") == true) { 19 dataRoot = "data"; 20 } else if (curDir.endsWith("/modules") == true) { 21 dataRoot = "testcase/data"; 22 } 23 } 24 25 public void testXmlParse() { 26 HashMap dest = new HashMap(); 27 ActionData gad = new ActionData(); 28 try { 29 ActionControllerUtil.parseFile(dest, gad, dataRoot, "actions.xml"); 30 } catch (ServletException sex) { 31 fail("xml parse: " + sex.toString()); 32 } 33 34 assertEquals(8, dest.size()); 35 36 assertEquals("/path1", gad.getForwardPath("gfwd1")); 38 assertEquals("/path2", gad.getForwardPath("gfwd2")); 39 assertFalse(gad.isForwardRedirect("gfwd1")); 40 assertTrue(gad.isForwardRedirect("gfwd2")); 41 42 ActionData ad = (ActionData) dest.get("/action1"); 44 assertEquals("/action1", ad.getPath()); 45 assertEquals("Foo1", ad.getType()); 46 assertEquals(null, ad.getMethod()); 47 48 ad = (ActionData) dest.get("/action2"); 49 assertEquals("/action2", ad.getPath()); 50 assertEquals("Foo2", ad.getType()); 51 assertEquals("met2", ad.getMethod()); 52 53 ad = (ActionData) dest.get("/action3"); 54 assertEquals("/action3", ad.getPath()); 55 assertEquals("Foo3", ad.getType()); 56 assertEquals(null, ad.getMethod()); 57 assertEquals("/path1", ad.getForwardPath("fwd1")); 58 assertFalse(ad.isForwardRedirect("fwd1")); 59 assertEquals("/path2", ad.getForwardPath("fwd2")); 60 assertTrue(ad.isForwardRedirect("fwd2")); 61 62 ad = (ActionData) dest.get("/action4"); 63 assertEquals("/action4", ad.getPath()); 64 assertEquals("Foo4", ad.getType()); 65 assertEquals("met4", ad.getMethod()); 66 assertEquals("/path1", ad.getForwardPath("fwd1")); 67 assertFalse(ad.isForwardRedirect("fwd1")); 68 assertEquals("/path2", ad.getForwardPath("fwd2")); 69 assertTrue(ad.isForwardRedirect("fwd2")); 70 assertEquals("vvv", ad.getParameter("ppp")); 71 72 ad = (ActionData) dest.get("/action5"); 73 assertEquals("/action5", ad.getPath()); 74 assertEquals("Foo5", ad.getType()); 75 assertEquals(null, ad.getMethod()); 76 assertEquals("x", ad.getParameter("mparam")); 77 78 ad = (ActionData) dest.get("/actionA"); 80 assertEquals("/actionA", ad.getPath()); 81 assertEquals("FooJoin", ad.getType()); 82 assertEquals("metjoin", ad.getMethod()); 83 assertEquals("A", ad.getParameter("mparam")); 84 assertEquals("/path1", ad.getForwardPath("fwd1")); 85 assertFalse(ad.isForwardRedirect("fwd1")); 86 assertEquals("/path2", ad.getForwardPath("fwd2")); 87 assertTrue(ad.isForwardRedirect("fwd2")); 88 assertEquals("vvv", ad.getParameter("ppp")); 89 90 ad = (ActionData) dest.get("/actionB"); 91 assertEquals("/actionB", ad.getPath()); 92 assertEquals("FooJoin", ad.getType()); 93 assertEquals("metjoin", ad.getMethod()); 94 assertEquals("B", ad.getParameter("mparam")); 95 assertEquals("/path1", ad.getForwardPath("fwd1")); 96 assertFalse(ad.isForwardRedirect("fwd1")); 97 assertEquals("/path2", ad.getForwardPath("fwd2")); 98 assertTrue(ad.isForwardRedirect("fwd2")); 99 assertEquals("vvv", ad.getParameter("ppp")); 100 101 assertEquals("vvvB", ad.getParameter("pppB")); 102 assertEquals("vvvB2", ad.getParameter("pppB2")); 103 assertEquals("/pathB", ad.getForwardPath("fwdB")); 104 assertFalse(ad.isForwardRedirect("fwdB")); 105 assertEquals("/pathB2", ad.getForwardPath("fwdB2")); 106 assertFalse(ad.isForwardRedirect("fwdB2")); 107 108 ad = (ActionData) dest.get("/actionC"); 109 assertEquals("/actionC", ad.getPath()); 110 assertEquals("FooJoin", ad.getType()); 111 assertEquals("metjoin", ad.getMethod()); 112 assertEquals("C", ad.getParameter("mparam")); 113 assertEquals("/path1", ad.getForwardPath("fwd1")); 114 assertFalse(ad.isForwardRedirect("fwd1")); 115 assertEquals("/path2", ad.getForwardPath("fwd2")); 116 assertTrue(ad.isForwardRedirect("fwd2")); 117 assertEquals("vvv", ad.getParameter("ppp")); 118 } 119 120 } 121 | Popular Tags |