1 17 package examples.cactus; 18 19 import servletunit.struts.CactusStrutsTestCase; 20 21 public class TestCactusLoginAction extends CactusStrutsTestCase { 22 23 public TestCactusLoginAction(String testName) { 24 super(testName); 25 } 26 27 public void testSuccessfulLogin() { 28 29 addRequestParameter("username","deryl"); 30 addRequestParameter("password","radar"); 31 setRequestPathInfo("/login"); 32 actionPerform(); 33 verifyForward("success"); 34 verifyForwardPath("/main/success.jsp"); 35 assertEquals("deryl", getSession().getAttribute("authentication")); 36 verifyNoActionErrors(); 37 } 38 39 public void testFailedLogin() { 40 41 addRequestParameter("username","deryl"); 42 addRequestParameter("password","express"); 43 setRequestPathInfo("/login"); 44 actionPerform(); 45 verifyForward("login"); 46 verifyForwardPath("/login/login.jsp"); 47 verifyInputForward(); 48 verifyActionErrors(new String [] {"error.password.mismatch"}); 49 assertNull(getSession().getAttribute("authentication")); 50 } 51 52 public static void main(String [] args) { 53 junit.textui.TestRunner.run(TestCactusLoginAction.class); 54 } 55 56 } 57 58 | Popular Tags |