KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > inversoft > verge > mvc > view > jsp > form > test > ATeiTest


1 /*
2  * Copyright (c) 2003, Inversoft
3  *
4  * This software is distribuable under the GNU Lesser General Public License.
5  * For more information visit gnu.org.
6  */

7 package com.inversoft.verge.mvc.view.jsp.form.test;
8
9
10 import javax.servlet.ServletException JavaDoc;
11 import javax.servlet.jsp.tagext.TagData JavaDoc;
12 import javax.servlet.jsp.tagext.VariableInfo JavaDoc;
13
14 import com.inversoft.junit.JspTestCase;
15 import com.inversoft.verge.config.VergeConfigConstants;
16 import com.inversoft.verge.config.servlet.ConfigServlet;
17 import com.inversoft.verge.mvc.view.jsp.form.ATei;
18
19
20 /**
21  * <p>
22  * This class has the tests for the anchor tag extra info
23  * </p>
24  *
25  * @author Brian Pontarelli
26  * @since 2.0
27  * @version 2.0
28  */

29 public class ATeiTest extends JspTestCase {
30
31     /**
32      * Constructor for ATeiTest.
33      *
34      * @param name The name of the test to run
35      */

36     public ATeiTest(String JavaDoc name) {
37         super(name);
38         setLocal(true);
39     }
40
41
42     /**
43      * Tests the tag extra info
44      */

45     public void testWithForm() {
46         if (isLocal()) {
47             getContext().setInitParameter(VergeConfigConstants.CONTEXT_PARAM,
48                 "src/com/inversoft/verge/mvc/view/jsp/form/test/test-config.xml");
49         }
50
51         ConfigServlet cs = new ConfigServlet();
52         try {
53             cs.init(createConfig("ConfigServlet"));
54         } catch (ServletException JavaDoc se) {
55             fail(se.toString());
56         }
57
58         ATei tei = new ATei();
59         Object JavaDoc[][] params = {{"form", "testForm"}, {"action", "testAction"}};
60         TagData JavaDoc data = new TagData JavaDoc(params);
61         assertTrue(tei.isValid(data));
62
63         VariableInfo JavaDoc[] infos = tei.getVariableInfo(data);
64         assertEquals(1, infos.length);
65         assertEquals("User", infos[0].getVarName());
66         assertEquals(VariableInfo.NESTED, infos[0].getScope());
67     }
68
69     /**
70      * Tests the tag extra info fails if there is no form
71      */

72     public void testWithoutForm() {
73         if (isLocal()) {
74             getContext().setInitParameter(VergeConfigConstants.CONTEXT_PARAM,
75                 "src/com/inversoft/verge/mvc/view/jsp/form/test/test-config.xml");
76         }
77
78         ConfigServlet cs = new ConfigServlet();
79         try {
80             cs.init(createConfig("ConfigServlet"));
81         } catch (ServletException JavaDoc se) {
82             fail(se.toString());
83         }
84
85         ATei tei = new ATei();
86         Object JavaDoc[][] params = new Object JavaDoc[][]{{"action", "globalAction1"}};
87         TagData JavaDoc data = new TagData JavaDoc(params);
88         assertTrue(tei.isValid(data));
89
90         try {
91             tei.getVariableInfo(data);
92         } catch (IllegalArgumentException JavaDoc iae) {
93             fail(iae.toString());
94         }
95     }
96
97     /**
98      * Tests the tag extra info fails if there is no form
99      */

100     public void testActionFailure() {
101         if (isLocal()) {
102             getContext().setInitParameter(VergeConfigConstants.CONTEXT_PARAM,
103                 "src/com/inversoft/verge/mvc/view/jsp/form/test/test-config.xml");
104         }
105
106         ConfigServlet cs = new ConfigServlet();
107         try {
108             cs.init(createConfig("ConfigServlet"));
109         } catch (ServletException JavaDoc se) {
110             fail(se.toString());
111         }
112
113         ATei tei = new ATei();
114         Object JavaDoc[][] params = null;
115         TagData JavaDoc data = new TagData JavaDoc(params);
116         assertFalse(tei.isValid(data));
117
118         try {
119             tei.getVariableInfo(data);
120         } catch (IllegalArgumentException JavaDoc iae) {
121             // This is supposed to happen
122
fail("Should not have failed without form");
123         }
124     }
125
126     /**
127      * Tests the tag extra info fails if there is no form
128      */

129     public void testFormFailure() {
130         if (isLocal()) {
131             getContext().setInitParameter(VergeConfigConstants.CONTEXT_PARAM,
132                 "src/com/inversoft/verge/mvc/view/jsp/form/test/test-config.xml");
133         }
134
135         ConfigServlet cs = new ConfigServlet();
136         try {
137             cs.init(createConfig("ConfigServlet"));
138         } catch (ServletException JavaDoc se) {
139             fail(se.toString());
140         }
141
142         ATei tei = new ATei();
143         Object JavaDoc[][] params = null;
144         TagData JavaDoc data = new TagData JavaDoc(params);
145         assertFalse(tei.isValid(data));
146
147         try {
148             tei.getVariableInfo(data);
149         } catch (IllegalArgumentException JavaDoc iae) {
150             // This is supposed to happen
151
fail("Should not have failed without form");
152         }
153     }
154
155     /**
156      * Tests the tag extra info fails if there is no form
157      */

158     public void testFormActionFailure() {
159         if (isLocal()) {
160             getContext().setInitParameter(VergeConfigConstants.CONTEXT_PARAM,
161                 "src/com/inversoft/verge/mvc/view/jsp/form/test/test-config.xml");
162         }
163
164         ConfigServlet cs = new ConfigServlet();
165         try {
166             cs.init(createConfig("ConfigServlet"));
167         } catch (ServletException JavaDoc se) {
168             fail(se.toString());
169         }
170
171         ATei tei = new ATei();
172         Object JavaDoc[][] params = {{"form", "badForm"}, {"action", "badAction"}};
173         TagData JavaDoc data = new TagData JavaDoc(params);
174         assertFalse(tei.isValid(data));
175
176         try {
177             tei.getVariableInfo(data);
178             fail("This should have failed");
179         } catch (IllegalArgumentException JavaDoc iae) {
180             // This is supposed to happen
181
}
182
183         params = new Object JavaDoc[][]{{"form", "testForm"}, {"action", "badAction"}};
184         data = new TagData JavaDoc(params);
185         assertFalse(tei.isValid(data));
186
187         try {
188             tei.getVariableInfo(data);
189         } catch (IllegalArgumentException JavaDoc iae) {
190             fail(iae.toString());
191         }
192     }
193 }
Popular Tags