1 17 package servletunit.struts.tests.cactus; 18 19 import servletunit.struts.CactusStrutsTestCase; 20 import junit.framework.AssertionFailedError; 21 22 public class TestMessageAction extends CactusStrutsTestCase { 23 24 public TestMessageAction(String testName) { 25 super(testName); 26 } 27 28 public void testNoMessages() { 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 verifyNoActionMessages(); 37 } 38 39 public void testMessageExists() { 40 setRequestPathInfo("test","/testActionMessages"); 41 actionPerform(); 42 verifyForward("success"); 43 verifyActionMessages(new String [] {"test.message"}); 44 } 45 46 public void testMessageExistsExpectedNone() { 47 setRequestPathInfo("test","/testActionMessages"); 48 actionPerform(); 49 verifyForward("success"); 50 try { 51 verifyNoActionMessages(); 52 } catch (AssertionFailedError afe) { 53 return; 54 } 55 fail("Expected an AssertionFailedError!"); 56 } 57 58 public void testMessageMismatch() { 59 setRequestPathInfo("test","/testActionMessages"); 60 actionPerform(); 61 verifyForward("success"); 62 try { 63 verifyActionMessages(new String [] {"error.password.mismatch"}); 64 } catch (AssertionFailedError afe) { 65 return; 66 } 67 fail("Expected an AssertionFailedError!"); 68 } 69 70 public void testExpectedMessagesNoneExist() { 71 addRequestParameter("username","deryl"); 72 addRequestParameter("password","radar"); 73 setRequestPathInfo("/login"); 74 actionPerform(); 75 verifyForward("success"); 76 verifyForwardPath("/main/success.jsp"); 77 assertEquals("deryl",getSession().getAttribute("authentication")); 78 try { 79 verifyActionMessages(new String [] {"test.message"}); 80 } catch (AssertionFailedError afe) { 81 return; 82 } 83 fail("Expected AssertionFailedError!"); 84 } 85 86 public static void main(String [] args) { 87 junit.textui.TestRunner.run(TestMessageAction.class); 88 } 89 90 91 } 92 93 | Popular Tags |