01: // StrutsTestCase - a JUnit extension for testing Struts actions
02: // within the context of the ActionServlet.
03: // Copyright (C) 2002 Deryl Seale
04: //
05: // This library is free software; you can redistribute it and/or
06: // modify it under the terms of the Apache Software License as
07: // published by the Apache Software Foundation; either version 1.1
08: // of the License, or (at your option) any later version.
09: //
10: // This library is distributed in the hope that it will be useful,
11: // but WITHOUT ANY WARRANTY; without even the implied warranty of
12: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13: // Apache Software Foundation Licens for more details.
14: //
15: // You may view the full text here: http://www.apache.org/LICENSE.txt
16:
17: package servletunit.struts.tests;
18:
19: import servletunit.struts.MockStrutsTestCase;
20: import examples.LoginForm;
21:
22: public class TestSetActionForm extends MockStrutsTestCase {
23:
24: public TestSetActionForm(String testName) {
25: super (testName);
26: }
27:
28: public void setUp() throws Exception {
29: super .setUp();
30: setServletConfigFile("/WEB-INF/web.xml");
31: }
32:
33: public void testNonModuleSetActionForm() {
34: LoginForm form = new LoginForm();
35: form.setUsername("deryl");
36: form.setPassword("radar");
37: setRequestPathInfo("/login");
38: setActionForm(form);
39: actionPerform();
40: verifyNoActionErrors();
41: verifyForward("success");
42: verifyForwardPath("/main/success.jsp");
43: }
44:
45: public void testSetActionForm() {
46: ComplexForm form = new ComplexForm();
47: form.setUsername("deryl");
48: form.setPassword("radar");
49: form.setComplexObject(new Object());
50: setRequestPathInfo("test", "/testSetActionForm");
51: setActionForm(form);
52: actionPerform();
53: verifyForward("success");
54: verifyForwardPath("/test/main/success.jsp");
55: verifyNoActionErrors();
56: }
57:
58: public void testFormReset() {
59: ComplexForm form = new ComplexForm();
60: form.setUsername("deryl");
61: form.setPassword("radar");
62: form.setComplexObject(new Object());
63: setRequestPathInfo("test", "/testSetActionForm");
64: addRequestParameter("test.reset", "true");
65: setActionForm(form);
66: actionPerform();
67: verifyForward("login");
68: verifyForwardPath("/login/login.jsp");
69: verifyActionErrors(new String[] { "error.password.mismatch" });
70: }
71:
72: public void testSetActionFormBeforeSettingRequestPathFails() {
73: ComplexForm form = new ComplexForm();
74: form.setUsername("deryl");
75: form.setPassword("radar");
76: form.setComplexObject(new Object());
77: try {
78: setActionForm(form);
79: } catch (IllegalStateException ise) {
80: return;
81: }
82: fail("should have thrown IllegalStateException");
83: }
84:
85: public static void main(String[] args) {
86: junit.textui.TestRunner.run(TestSetActionForm.class);
87: }
88:
89: }
|