KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jcorporate > expresso > services > controller > tests > DBMaintTests


1 /* ====================================================================
2  * The Jcorporate Apache Style Software License, Version 1.2 05-07-2002
3  *
4  * Copyright (c) 1995-2002 Jcorporate Ltd. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in
15  * the documentation and/or other materials provided with the
16  * distribution.
17  *
18  * 3. The end-user documentation included with the redistribution,
19  * if any, must include the following acknowledgment:
20  * "This product includes software developed by Jcorporate Ltd.
21  * (http://www.jcorporate.com/)."
22  * Alternately, this acknowledgment may appear in the software itself,
23  * if and wherever such third-party acknowledgments normally appear.
24  *
25  * 4. "Jcorporate" and product names such as "Expresso" must
26  * not be used to endorse or promote products derived from this
27  * software without prior written permission. For written permission,
28  * please contact info@jcorporate.com.
29  *
30  * 5. Products derived from this software may not be called "Expresso",
31  * or other Jcorporate product names; nor may "Expresso" or other
32  * Jcorporate product names appear in their name, without prior
33  * written permission of Jcorporate Ltd.
34  *
35  * 6. No product derived from this software may compete in the same
36  * market space, i.e. framework, without prior written permission
37  * of Jcorporate Ltd. For written permission, please contact
38  * partners@jcorporate.com.
39  *
40  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
41  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
42  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
43  * DISCLAIMED. IN NO EVENT SHALL JCORPORATE LTD OR ITS CONTRIBUTORS
44  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
45  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
46  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
47  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
48  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
49  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
50  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51  * SUCH DAMAGE.
52  * ====================================================================
53  *
54  * This software consists of voluntary contributions made by many
55  * individuals on behalf of the Jcorporate Ltd. Contributions back
56  * to the project(s) are encouraged when you make modifications.
57  * Please send them to support@jcorporate.com. For more information
58  * on Jcorporate Ltd. and its products, please see
59  * <http://www.jcorporate.com/>.
60  *
61  * Portions of this software are based upon other open source
62  * products and are subject to their respective licenses.
63  */

64
65 package com.jcorporate.expresso.services.controller.tests;
66
67 import com.jcorporate.expresso.core.controller.ControllerException;
68 import com.jcorporate.expresso.core.controller.ControllerResponse;
69 import com.jcorporate.expresso.core.controller.Input;
70 import com.jcorporate.expresso.core.controller.Transition;
71 import com.jcorporate.expresso.services.controller.DBMaint;
72 import com.jcorporate.expresso.services.test.ControllerTestCase;
73 import com.jcorporate.expresso.services.test.ControllerTestSuite;
74 import junit.framework.TestSuite;
75 import org.apache.cactus.WebRequest;
76
77 /**
78  * Unit tests some of the states for the DBMaint Controller.
79  * This isn't so much of a thorough test as it is a check to make sure
80  * states are displaying properly.
81  *
82  * @author Michael Rimov
83  * @version $Revision: 1.2 $ on $Date: 2004/11/17 20:48:23 $
84  */

85 public class DBMaintTests extends ControllerTestCase {
86
87     /**
88      * Instantiates this controller. All that is needed is call super() with
89      * the testName passed to it as well as the name of the class we're testing.
90      *
91      * @param testName the name of the test
92      * @throws Exception upon error
93      */

94     public DBMaintTests(String JavaDoc testName)
95             throws Exception JavaDoc {
96         super(testName,
97                 com.jcorporate.expresso.services.controller.DBMaint.class);
98     }
99
100     /**
101      * Convenience method so we can test just this class.
102      *
103      * @param args the command line arguments (unused)
104      * @throws Exception upon error
105      */

106     public static void main(String JavaDoc[] args)
107             throws Exception JavaDoc {
108         junit.textui.TestRunner.run(suite());
109     }
110
111     /**
112      * Determines what tests are run in the test suite. We also tell ControllerTestSuite
113      * that we need ExpressoSchema to exist for our tests. We also tell it that
114      * we aren't modifying the underlying database for our own tests so the schema
115      * doesn't necessarily have to be deleted when we're done with it.
116      *
117      * @return instantiated TestSuite object
118      * @throws Exception upon error
119      */

120     public static TestSuite suite()
121             throws Exception JavaDoc {
122         ControllerTestSuite cts = new ControllerTestSuite();
123         cts.addReadOnlySchemaDependency(com.jcorporate.expresso.core.ExpressoSchema.class);
124         cts.addTestSuite(DBMaintTests.class);
125
126         return cts;
127     }
128
129
130     /**
131      * @param theRequest a "hyper" ServletTestRequest that allows us to set URLS,
132      * set cookies, set URL parameters, etc before the request is sent to the
133      * servlet container.
134      * @throws Exception if something went wrong with the Crypto stuff
135      */

136     public void beginPromptState(WebRequest theRequest)
137             throws Exception JavaDoc {
138         super.logIn(theRequest);
139         super.setupParameters("prompt", theRequest);
140     }
141
142     /**
143      * Executed on the server side. All it has to do is call the super's
144      * controllerProcess() to the Controller's State properly executed.
145      *
146      * @throws Exception upon error
147      */

148     public void testPromptState()
149             throws Exception JavaDoc {
150         try {
151             ControllerResponse response = super.controllerProcess();
152             assertTrue("Must have a non-null response", response != null);
153             Input i = response.getInput("SchemaClass");
154             assertTrue("Must have a SchemaClass Input", i != null);
155             assertTrue("Schema Class Input must have valid values", i.getValidValues().size() > 0);
156
157             Transition t = response.getTransition("selDBObj");
158             assertTrue("Must have a transition to next state", t != null);
159             assertTrue("Must transition to this controller",
160                     t.getControllerObject().equals(DBMaint.class.getName()));
161
162             assertTrue("Must transition to appropriate state",
163                     t.getState().equals("selDBObj"));
164         } catch (Exception JavaDoc ex) {
165             ex.printStackTrace();
166             fail("Caught Exception in testPromptState: " + ex.getMessage());
167         }
168     }
169
170
171     /**
172      * Sanity check to make sure that the 'select dbobject' page is working properly
173      *
174      * @param theRequest The Cactus web request
175      * @throws Exception upon error
176      */

177     public void beginSelDBObjState(WebRequest theRequest)
178             throws Exception JavaDoc {
179         super.logIn(theRequest);
180         super.setupParameters("selDBObj", theRequest);
181         theRequest.addParameter("SchemaClass", com.jcorporate.expresso.core.ExpressoSchema.class.getName());
182     }
183
184     /**
185      * Executed on the server side. All it has to do is call the super's
186      * controllerProcess() to the Controller's State properly executed.
187      */

188     public void testSelDBObjState()
189             throws Exception JavaDoc {
190         try {
191             ControllerResponse response = super.controllerProcess();
192             assertTrue("Must have a non-null response", response != null);
193             Input i = response.getInput("dbobj");
194             assertTrue("Must have dbobject input", i != null);
195             assertTrue("Must have valid values", i.getValidValues().size() > 0);
196             verifyAddListSearchButtons(response);
197
198         } catch (Exception JavaDoc ex) {
199             ex.printStackTrace();
200             fail("Caught Exception in testListDBOBjState: " + ex.getMessage());
201         }
202
203     }
204
205
206     /**
207      * Test the "List" state of controller
208      *
209      * @param theRequest the Cactus WebRequest object
210      * @throws Exception upon error
211      */

212     public void beginListDBObjState(WebRequest theRequest)
213             throws Exception JavaDoc {
214         super.logIn(theRequest);
215         super.setupParameters("List", theRequest);
216         theRequest.addParameter("dbobj", com.jcorporate.expresso.services
217
                .dbobj.MimeTypes.class.getName());
218     }
219
220     /**
221      * Executed on the server side. All it has to do is call the super's
222      * controllerProcess() to the Controller's State properly executed.
223      *
224      * @throws Exception upon error
225      */

226     public void testListDBObjState()
227             throws Exception JavaDoc {
228         try {
229             ControllerResponse response = super.controllerProcess();
230             assertTrue("Must have a non-null response", response != null);
231             assertTrue("Must have a Buttons Block", response.getBlock("buttons") != null);
232             assertTrue("Must have a record list block", response.getBlock("recordList") != null);
233         } catch (Exception JavaDoc ex) {
234             ex.printStackTrace();
235             fail("Caught Exception in testListDBOBjState: " + ex.getMessage());
236         }
237
238     }
239
240     /**
241      * Checks to make sure that the Add/List/Search transitions are available.
242      *
243      * @param response the ControllerResponse object we're testing
244      * @throws ControllerException upon error
245      */

246     protected void verifyAddListSearchButtons(ControllerResponse response) throws ControllerException {
247         Transition t = response.getTransition("Add");
248         assertTrue("Must have Add Transition", t != null);
249         assertTrue("Add Must transition to this controller",
250                 t.getControllerObject().equals(DBMaint.class.getName()));
251
252         assertTrue("Add Must transition to appropriate state",
253                 t.getState().equals("Add"));
254
255         t = response.getTransition("List");
256         assertTrue("Must have List Transition", t != null);
257         assertTrue("List Must transition to this controller",
258                 t.getControllerObject().equals(DBMaint.class.getName()));
259
260         assertTrue("List Must transition to appropriate state",
261                 t.getState().equals("List"));
262
263         t = response.getTransition("Search");
264         assertTrue("Must have Search Transition", t != null);
265         assertTrue("Search Must transition to this controller",
266                 t.getControllerObject().equals(DBMaint.class.getName()));
267
268         assertTrue("Search Must transition to appropriate state",
269                 t.getState().equals("Search"));
270
271     }
272
273
274     /**
275      * Test the "Add DBObject" State. Make sure a form displays, and not an
276      * error
277      *
278      * @param theRequest the Cactus WebRequest object
279      * @throws Exception upon error
280      */

281     public void beginAddDBObjState(WebRequest theRequest)
282             throws Exception JavaDoc {
283         super.logIn(theRequest);
284         super.setupParameters("Add", theRequest);
285         theRequest.addParameter("dbobj", com.jcorporate.expresso.services
286
                .dbobj.MimeTypes.class.getName());
287     }
288
289     /**
290      * Executed on the server side. All it has to do is call the super's
291      * controllerProcess() to the Controller's State properly executed.
292      *
293      * @throws Exception upon error
294      */

295     public void testAddDBObjState()
296             throws Exception JavaDoc {
297         ControllerResponse response = super.controllerProcess();
298         assertTrue("Must have a non-null response", response != null);
299
300     }
301
302
303     /**
304      * Test to make sure a search form is appearing properly.
305      *
306      * @param theRequest the Cactus WebRequest object
307      * @throws Exception upon error
308      */

309     public void beginSearchDBObjState(WebRequest theRequest)
310             throws Exception JavaDoc {
311         super.logIn(theRequest);
312         super.setupParameters("Search", theRequest);
313         theRequest.addParameter("dbobj", com.jcorporate.expresso.services
314
                .dbobj.DefaultUserInfo.class.getName());
315     }
316
317     /**
318      * Executed on the server side. All it has to do is call the super's
319      * controllerProcess() to the Controller's State properly executed.
320      *
321      * @throws Exception upon error
322      */

323     public void testSearchDBObjState()
324             throws Exception JavaDoc {
325         ControllerResponse response = super.controllerProcess();
326         assertTrue("Must have a non-null response", response != null);
327
328     }
329
330 }
Popular Tags