1 17 package servletunit.struts.tests.cactus; 18 19 import servletunit.struts.CactusStrutsTestCase; 20 import servletunit.struts.tests.ComplexForm; 21 import examples.LoginForm; 22 23 public class TestSetActionForm extends CactusStrutsTestCase { 24 25 public TestSetActionForm(String testName) { 26 super(testName); 27 } 28 29 public void testNonModuleSetActionForm() { 30 LoginForm form = new LoginForm(); 31 form.setUsername("deryl"); 32 form.setPassword("radar"); 33 setRequestPathInfo("/login"); 34 setActionForm(form); 35 actionPerform(); 36 verifyNoActionErrors(); 37 verifyForward("success"); 38 verifyForwardPath("/main/success.jsp"); 39 } 40 41 public void testSetActionForm() { 42 ComplexForm form = new ComplexForm(); 43 form.setUsername("deryl"); 44 form.setPassword("radar"); 45 form.setComplexObject(new Object ()); 46 setRequestPathInfo("test","/testSetActionForm"); 47 setActionForm(form); 48 actionPerform(); 49 verifyForward("success"); 50 verifyForwardPath("/test/main/success.jsp"); 51 verifyNoActionErrors(); 52 } 53 54 public void testFormReset() { 55 ComplexForm form = new ComplexForm(); 56 form.setUsername("deryl"); 57 form.setPassword("radar"); 58 form.setComplexObject(new Object ()); 59 setRequestPathInfo("test","/testSetActionForm"); 60 addRequestParameter("test.reset","true"); 61 setActionForm(form); 62 actionPerform(); 63 verifyForward("login"); 64 verifyForwardPath("/login/login.jsp"); 65 verifyActionErrors(new String [] {"error.password.mismatch"}); 66 } 67 68 public void testSetActionFormBeforeSettingRequestPathFails() { 69 ComplexForm form = new ComplexForm(); 70 form.setUsername("deryl"); 71 form.setPassword("radar"); 72 form.setComplexObject(new Object ()); 73 try { 74 setActionForm(form); 75 } catch (IllegalStateException ise) { 76 return; 77 } 78 fail("should have thrown IllegalStateException"); 79 } 80 81 public static void main(String [] args) { 82 junit.textui.TestRunner.run(TestSetActionForm.class); 83 } 84 85 86 } 87 88 | Popular Tags |