KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > servletunit > struts > tests > cactus > TestSetActionForm


1 // StrutsTestCase - a JUnit extension for testing Struts actions
2
// within the context of the ActionServlet.
3
// Copyright (C) 2002 Deryl Seale
4
//
5
// This library is free software; you can redistribute it and/or
6
// modify it under the terms of the Apache Software License as
7
// published by the Apache Software Foundation; either version 1.1
8
// of the License, or (at your option) any later version.
9
//
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.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 JavaDoc 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 JavaDoc());
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 JavaDoc());
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 JavaDoc[] {"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 JavaDoc());
73         try {
74             setActionForm(form);
75         } catch (IllegalStateException JavaDoc ise) {
76             return;
77         }
78         fail("should have thrown IllegalStateException");
79     }
80
81     public static void main(String JavaDoc[] args) {
82         junit.textui.TestRunner.run(TestSetActionForm.class);
83     }
84
85
86 }
87
88
Popular Tags