1 17 package servletunit.struts.tests; 18 19 import servletunit.struts.MockStrutsTestCase; 20 import servletunit.ServletContextSimulator; 21 22 import java.io.File ; 23 24 public class TestAbsolutePath extends MockStrutsTestCase { 25 26 String rootPath; 27 28 public TestAbsolutePath(String testName) { 29 super(testName); 30 } 31 32 public void setUp() throws Exception { 33 super.setUp(); 34 rootPath = System.getProperty("basedir"); 35 setServletConfigFile(rootPath + "/src/examples/WEB-INF/web.xml"); 36 } 37 38 public void testSuccessfulLogin() { 39 setConfigFile(rootPath + "/src/examples/WEB-INF/struts-config.xml"); 40 addRequestParameter("username","deryl"); 41 addRequestParameter("password","radar"); 42 setRequestPathInfo("/login"); 43 actionPerform(); 44 verifyForward("success"); 45 verifyForwardPath("/main/success.jsp"); 46 assertEquals("deryl",getSession().getAttribute("authentication")); 47 verifyNoActionErrors(); 48 } 49 50 public void testContextDirectory() { 51 this.setContextDirectory(new File (rootPath + "/src/examples")); 52 setConfigFile("/WEB-INF/struts-config.xml"); 53 addRequestParameter("username","deryl"); 54 addRequestParameter("password","radar"); 55 setRequestPathInfo("/login"); 56 actionPerform(); 57 verifyForward("success"); 58 verifyForwardPath("/main/success.jsp"); 59 assertEquals("deryl",getSession().getAttribute("authentication")); 60 verifyNoActionErrors(); 61 } 62 63 public static void main(String [] args) { 64 junit.textui.TestRunner.run(TestAbsolutePath.class); 65 } 66 67 68 } 69 70 | Popular Tags |