KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jcorporate > expresso > ext > controller > TestController


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 /**
66  * TestController.java
67  *
68  * Copyright 2000, 2001 Jcorporate Ltd.
69  */

70
71 package com.jcorporate.expresso.ext.controller;
72
73 import com.jcorporate.expresso.core.controller.ControllerException;
74 import com.jcorporate.expresso.core.controller.ControllerRequest;
75 import com.jcorporate.expresso.core.controller.ControllerResponse;
76 import com.jcorporate.expresso.core.controller.DBController;
77 import com.jcorporate.expresso.core.controller.Input;
78 import com.jcorporate.expresso.core.controller.NonHandleableException;
79 import com.jcorporate.expresso.core.controller.Output;
80 import com.jcorporate.expresso.core.controller.State;
81 import com.jcorporate.expresso.core.controller.Transition;
82 import com.jcorporate.expresso.core.db.DBException;
83 import com.jcorporate.expresso.core.dbobj.Schema;
84 import com.jcorporate.expresso.core.dbobj.SecuredDBObject;
85 import com.jcorporate.expresso.core.dbobj.ValidValue;
86 import com.jcorporate.expresso.core.misc.ConfigManager;
87 import com.jcorporate.expresso.services.controller.Registration;
88 import com.jcorporate.expresso.services.dbobj.SchemaList;
89 import junit.framework.AssertionFailedError;
90 import junit.framework.Test;
91 import junit.framework.TestFailure;
92 import junit.framework.TestListener;
93 import junit.framework.TestResult;
94 import junit.framework.TestSuite;
95 import junit.runner.ReloadingTestSuiteLoader;
96 import junit.runner.StandardTestSuiteLoader;
97 import junit.runner.TestSuiteLoader;
98 import org.apache.log4j.Logger;
99
100 import java.io.File JavaDoc;
101 import java.io.FileInputStream JavaDoc;
102 import java.io.IOException JavaDoc;
103 import java.io.InputStream JavaDoc;
104 import java.lang.reflect.Method JavaDoc;
105 import java.text.NumberFormat JavaDoc;
106 import java.util.Enumeration JavaDoc;
107 import java.util.Iterator JavaDoc;
108 import java.util.Properties JavaDoc;
109 import java.util.Vector JavaDoc;
110
111
112 /**
113  * TestController is a controller that can access and run
114  * JUnit unit tests, but from within an Expresso environment (e.g.
115  * with the DBConnection pool, Cache, and other Expresso items
116  * available, and from a servlet (such as ControllerServlet).
117  * This allows tests that require the servlet environment or Expresso
118  * components to be executed.
119  *
120  * @author Michael Nash
121  */

122 public class TestController
123         extends DBController
124         implements TestListener {
125     static final String JavaDoc SUITE_METHODNAME = "suite";
126     static Properties JavaDoc fPreferences;
127     static int fMaxMessage = 200;
128     protected TestSuiteLoader fTestLoader;
129     private static Logger log = Logger.getLogger(TestController.class);
130
131     /**
132      * Default constructor
133      */

134     public TestController() {
135         super();
136         System.setProperty("junit.argv.configDir",
137                 ConfigManager.getConfigDir());
138         System.setProperty("junit.argv.webAppDir",
139                 ConfigManager.getWebAppDir());
140         fTestLoader = new StandardTestSuiteLoader();
141
142         State prompt = new State("prompt", "Prompt for Test to Run");
143         addState(prompt);
144         setInitialState("prompt");
145
146         State runTests = new State("runTests", "Run Tests");
147         runTests.addRequiredParameter("testName");
148         addState(runTests);
149
150         State runAllTests = new State("runAllTests", "Run All Tests");
151         runAllTests.addRequiredParameter("SchemaClass");
152         addState(runAllTests);
153
154         addState(new State("transition2FormTest", "test a transition to a state which requires a form"));
155         addState(new State("transitionTest", "test a transition"));
156         addState(new State("promptTest", "prompt for transitionFromFormTest"));
157         addState(new State("transitionFromFormTest", "test a transition from a form"));
158         this.setSchema(com.jcorporate.expresso.core.ExpressoSchema.class);
159     } /* TestController() */
160
161     /**
162      * Standard method to select the appropriate next state as the
163      * controller moves from state to state.
164      *
165      * @param newState
166      */

167     public ControllerResponse newState(String JavaDoc newState,
168                                        ControllerRequest params)
169             throws ControllerException,
170             NonHandleableException {
171         ControllerResponse myResponse = super.newState(newState, params);
172
173         if (newState.equals("runTests")) {
174             runTestsState(myResponse, params);
175         } else if (newState.equals("runAllTests")) {
176             runAllTestsState(myResponse, params);
177         } else if (newState.equals("prompt")) {
178             promptState(myResponse, params);
179         }
180
181         return myResponse;
182     } /* newState(String) */
183
184
185     /**
186      * @param test
187      * @param t
188      */

189     public synchronized void addError(Test test, Throwable JavaDoc t) {
190         log.info("A test error has occurred");
191         log.error(t);
192     } /* addError(Test, Throwable) */
193
194     /**
195      * @param test
196      * @param t
197      */

198     public synchronized void addFailure(Test test, Throwable JavaDoc t) {
199         log.info("A test failure has occurred");
200         log.error(t);
201     } /* addFailure(Test, Throwable) */
202
203     /**
204      * Creates the TestResult to be used for the test run.
205      *
206      * @return
207      */

208     protected TestResult createTestResult() {
209         return new TestResult();
210     } /* createTestResult() */
211
212     /**
213      * @param suite
214      * @param wait
215      * @return
216      */

217     protected synchronized TestResult doRun(Test suite, boolean wait) {
218         try {
219             TestResult result = createTestResult();
220             result.addListener(this);
221
222             long startTime = System.currentTimeMillis();
223             suite.run(result);
224
225             long endTime = System.currentTimeMillis();
226             long runTime = endTime - startTime;
227             log.info("Time: " + elapsedTimeAsString(runTime));
228             print(result);
229
230             return result;
231         } catch (Exception JavaDoc ee) {
232             log.error(ee);
233         }
234
235         return null;
236     } /* doRun(Test, boolean) */
237
238     /**
239      * @param test
240      */

241     public void endTest(Test test) {
242     } /* endTest(Test) */
243
244     /**
245      * Added since JUnit 3.7
246      */

247     public void addFailure(Test test, AssertionFailedError t) {
248         log.info("A test failure has occurred");
249         log.info(t);
250     }
251
252     /**
253      * Actually execute the selected test(s)
254      */

255     private synchronized void runTestsState(ControllerResponse myResponse,
256                                             ControllerRequest params)
257             throws ControllerException {
258         long startTime = System.currentTimeMillis();
259         TestController aTestRunner = new TestController();
260
261         try {
262             TestResult r = aTestRunner.start(null); /* testToRun */
263
264             if (!r.wasSuccessful()) {
265                 myResponse.addOutput(new Output("Tests Successful"));
266             }
267
268             myResponse.addOutput(new Output("One or more tests failed"));
269         } catch (Exception JavaDoc e) {
270             log.error(e);
271             throw new ControllerException(e);
272         }
273
274         long endTime = System.currentTimeMillis();
275         long runTime = endTime - startTime;
276         myResponse.addOutput(new Output("Total Elapsed Time " + runTime +
277                 " milliseconds"));
278     } /* runTestsState(); */
279
280
281     /**
282      * Execute all available tests for the specified schema class
283      */

284     private synchronized void runAllTestsState(ControllerResponse myResponse,
285                                                ControllerRequest params)
286             throws ControllerException {
287         Schema s = getSchemaObject(params);
288         myResponse.addOutput(new Output("Running all tests in schema " + s.getClass().getName()));
289
290         long startTime = System.currentTimeMillis();
291         int testCount = 0;
292         int succeedCount = 0;
293         int failedCount = 0;
294         Test t = null;
295
296         for (Enumeration JavaDoc et2 = s.getTests(); et2.hasMoreElements();) {
297             t = (Test) et2.nextElement();
298             testCount++;
299
300             TestController aTestRunner = new TestController();
301
302             try {
303                 TestResult r = aTestRunner.start(t.getClass().getName());
304
305                 if (r.wasSuccessful()) {
306                     myResponse.addOutput(new Output("Test " + t.getClass().getName() +
307                             " Successful"));
308                     succeedCount++;
309                 } else {
310                     myResponse.addOutput(new Output("Test " + t.getClass().getName() +
311                             " failed - see the log for details"));
312                     failedCount++;
313                 }
314             } catch (Exception JavaDoc e) {
315                 log.error(e);
316                 throw new ControllerException(e);
317             }
318         } /* for each test */
319
320
321         long endTime = System.currentTimeMillis();
322         long runTime = endTime - startTime;
323         myResponse.addOutput(new Output("All Tests Completed"));
324         myResponse.addOutput(new Output("Total Elapsed Time " + runTime +
325                 " milliseconds"));
326         myResponse.addOutput(new Output("" + testCount + " tests run, " +
327                 succeedCount + " succeeded, " +
328                 failedCount + " failed"));
329     } /* runAllTestsState() */
330
331
332     /**
333      * Instantiate & return the schema class given in the current parameter
334      *
335      * @return A Schema object instantiated from the class named by the
336      * 'SchemaClass' parameter
337      */

338     private Schema getSchemaObject(ControllerRequest params)
339             throws ControllerException {
340         Schema mySchema;
341         String JavaDoc className = params.getParameter("SchemaClass");
342
343         if (className == null) {
344             throw new ControllerException("No parameter 'SchemaClass'," +
345                     " can't read current schema");
346         }
347         try {
348             mySchema = (Schema) Class.forName(params.getParameter("SchemaClass")).newInstance();
349         } catch (IllegalAccessException JavaDoc ie) {
350             throw new ControllerException("Illegal Access " +
351                     "Exception loading Schema class " +
352                     params.getParameter("SchemaClass"),
353                     ie);
354         } catch (InstantiationException JavaDoc ie) {
355             throw new ControllerException("Can't instantiate " +
356                     "Schema class " +
357                     params.getParameter("SchemaClass"),
358                     ie);
359         } catch (ClassNotFoundException JavaDoc se) {
360             throw new ControllerException("Can't find a Schema " +
361                     "class called " +
362                     params.getParameter("SchemaClass"),
363                     se);
364         } catch (Exception JavaDoc eo) {
365             log.error(eo);
366             throw new ControllerException("Exception loading " + "Schema " +
367                     params.getParameter("SchemaClass") +
368                     "- see detailed message in server log",
369                     eo);
370         }
371
372         return mySchema;
373     } /* getSchemaObject() */
374
375
376     /**
377      * Prints failures to the log
378      *
379      * @param result
380      */

381     public synchronized void print(TestResult result) {
382         printHeader(result);
383         printErrors(result);
384         printFailures(result);
385     } /* print(TestResult) */
386
387     /**
388      * Prints the errors to the log
389      *
390      * @param result
391      */

392     public void printErrors(TestResult result) {
393         if (result.errorCount() != 0) {
394             if (result.errorCount() == 1) {
395                 log.info("There was " + result.errorCount() + " error:");
396             } else {
397                 log.info("There were " + result.errorCount() + " errors:");
398             }
399
400             int i = 1;
401
402             for (Enumeration JavaDoc e = result.errors(); e.hasMoreElements(); i++) {
403                 TestFailure failure = (TestFailure) e.nextElement();
404                 log.info(i + ") " + failure.failedTest());
405                 log.info(failure.thrownException());
406             }
407         }
408     } /* printErrors(TestResult) */
409
410     /**
411      * Prints failures to the log
412      *
413      * @param result
414      */

415     public void printFailures(TestResult result) {
416         if (result.failureCount() != 0) {
417             if (result.failureCount() == 1) {
418                 log.info("There was " + result.failureCount() + " failure:");
419             } else {
420                 log.info("There were " + result.failureCount() + " failures:");
421             }
422
423             int i = 1;
424
425             for (Enumeration JavaDoc e = result.failures(); e.hasMoreElements(); i++) {
426                 TestFailure failure = (TestFailure) e.nextElement();
427                 log.info(i + ") " + failure.failedTest());
428
429                 Throwable JavaDoc t = failure.thrownException();
430
431                 if (t.getMessage() != null) {
432                     log.info(" \"" + truncate(t.getMessage()) + "\"");
433                 } else {
434                     log.info(failure.thrownException());
435                 }
436             }
437         }
438     } /* printFailures(TestResult) */
439
440     /**
441      * Prints the header of the report
442      *
443      * @param result
444      */

445     public void printHeader(TestResult result) {
446         if (result.wasSuccessful()) {
447             log.info("OK");
448             log.info(" (" + result.runCount() + " tests)");
449         } else {
450             log.info("FAILURES!!!");
451             log.info("Test Results:");
452             log.info("Run: " + result.runCount() + " Failures: " +
453                     result.failureCount() + " Errors: " +
454                     result.errorCount());
455         }
456     } /* printHeader(TestResult) */
457
458     /**
459      * Runs a suite extracted from a TestCase subclass.
460      *
461      * @param testClass
462      */

463     static public void run(Class JavaDoc testClass) {
464         run(new TestSuite(testClass));
465     } /* run(Class) */
466
467     /**
468      * Runs a single test and collects its results.
469      * This method can be used to start a test run
470      * from your program.
471      * <pre>
472      * public static void main (String[] args) {
473      * test.textui.TestRunner.run(suite());
474      * }
475      * </pre>
476      *
477      * @param suite
478      */

479     static public void run(Test suite) {
480         TestController aTestRunner = new TestController();
481         aTestRunner.doRun(suite, false);
482     } /* run(Test) */
483
484     /**
485      * Starts a test run. Analyzes the command line arguments
486      * and runs the given test suite.
487      *
488      * @param testName
489      * @return
490      */

491     protected synchronized TestResult start(String JavaDoc testName)
492             throws Exception JavaDoc {
493         boolean wait = false;
494
495         try {
496             Test suite = getTest(testName);
497
498             return doRun(suite, wait);
499         } catch (Exception JavaDoc e) {
500             throw new Exception JavaDoc("Could not create and run test suite: " + e);
501         }
502     } /* start(String) */
503
504
505     /**
506      * @param message
507      */

508     protected void runFailed(String JavaDoc message) {
509         log.info(message);
510     } /* runFailed(String) */
511
512     /**
513      * @param test
514      */

515     public synchronized void startTest(Test test) {
516         log.info("Test Started");
517     } /* startTest(Test) */
518
519     /**
520      * Returns the Test corresponding to the given suite. This is
521      * a template method, subclasses override runFailed(), clearStatus().
522      *
523      * @param suiteClassName
524      * @return
525      */

526     public Test getTest(String JavaDoc suiteClassName) {
527         if (suiteClassName.length() <= 0) {
528             clearStatus();
529
530             return null;
531         }
532
533         Class JavaDoc testClass = null;
534
535         try {
536             testClass = loadSuiteClass(suiteClassName);
537         } catch (NoClassDefFoundError JavaDoc e) {
538             runFailed("Class definition \"" + suiteClassName + "\" not found");
539
540             return null;
541         } catch (Exception JavaDoc e) {
542             runFailed("Class \"" + suiteClassName + "\" not found");
543
544             return null;
545         }
546
547         Method JavaDoc suiteMethod = null;
548
549         try {
550             suiteMethod = testClass.getMethod(SUITE_METHODNAME, new Class JavaDoc[0]);
551         } catch (Exception JavaDoc e) {
552
553             // try to extract a test suite automatically
554
clearStatus();
555
556             return new TestSuite(testClass);
557         }
558
559         Test test = null;
560
561         try {
562             test = (Test) suiteMethod.invoke(null, (Object JavaDoc[]) new Class JavaDoc[0]); // static method
563

564             if (test == null) {
565                 return test;
566             }
567         } catch (Exception JavaDoc e) {
568             runFailed("Could not invoke the suite() method");
569
570             return null;
571         }
572
573         clearStatus();
574
575         return test;
576     } /* getTest(String) */
577
578     /**
579      * Returns the formatted string of the elapsed time.
580      *
581      * @param runTime
582      * @return
583      */

584     public String JavaDoc elapsedTimeAsString(long runTime) {
585         return NumberFormat.getInstance().format((double) runTime / 1000);
586     } /* elaspedTimeAsString(long) */
587
588     /**
589      * @param className
590      * @return
591      */

592     public String JavaDoc extractClassName(String JavaDoc className) {
593         if (className.startsWith("Default package for")) {
594             return className.substring(className.lastIndexOf(".") + 1);
595         }
596
597         return className;
598     } /* extractClassName(String) */
599
600     /**
601      * Truncates a String to the maximum length.
602      *
603      * @param s
604      * @return
605      */

606     public static String JavaDoc truncate(String JavaDoc s) {
607         if (s.length() > fMaxMessage) {
608             s = s.substring(0, fMaxMessage) + "...";
609         }
610
611         return s;
612     } /* truncate(String) */
613
614     /**
615      * Returns the loaded Class for a suite name.
616      *
617      * @param suiteClassName
618      * @return
619      */

620     protected Class JavaDoc loadSuiteClass(String JavaDoc suiteClassName)
621             throws ClassNotFoundException JavaDoc {
622         return fTestLoader.load(suiteClassName);
623     } /* loadSuiteClass(String) */
624
625
626     /**
627      * Clears the status message.
628      */

629     protected void clearStatus() { // Belongs in the GUI TestRunner class
630
} /* clearStatus() */
631
632     /**
633      * Returns the loader to be used.
634      *
635      * @return
636      */

637     public static TestSuiteLoader getLoader() {
638         if (getPreference("loading").equals("true") && !inVAJava()) {
639             return new ReloadingTestSuiteLoader();
640         }
641
642         return new StandardTestSuiteLoader();
643     } /* getLoader() */
644
645     /**
646      * @return
647      */

648     private static File JavaDoc getPreferencesFile() {
649         String JavaDoc home = System.getProperty("user.home");
650
651         return new File JavaDoc(home, "junit.properties");
652     } /* getPreferencesFile() */
653
654     /**
655      *
656      */

657     private static void readPreferences() {
658         InputStream JavaDoc is = null;
659
660         try {
661             is = new FileInputStream JavaDoc(getPreferencesFile());
662             fPreferences = new Properties JavaDoc(fPreferences);
663             fPreferences.load(is);
664         } catch (IOException JavaDoc e) {
665             try {
666                 if (is != null) {
667                     is.close();
668                 }
669             } catch (IOException JavaDoc e1) {
670             }
671         }
672     } /* readPreferences() */
673
674     /**
675      * @param key
676      * @return
677      */

678     private static String JavaDoc getPreference(String JavaDoc key) {
679         return fPreferences.getProperty(key);
680     } /* getPreferences(String) */
681
682     /**
683      * @param key
684      * @param dflt
685      * @return
686      */

687     private static int getPreference(String JavaDoc key, int dflt) {
688         String JavaDoc value = getPreference(key);
689         int intValue = dflt;
690
691         if (value == null) {
692             return intValue;
693         }
694         try {
695             intValue = Integer.parseInt(value);
696         } catch (NumberFormatException JavaDoc ne) {
697         }
698
699         return intValue;
700     } /* getPreferences(String, int) */
701
702     /**
703      * @return
704      */

705     public static boolean inVAJava() {
706         try {
707             Class.forName("com.ibm.uvm.tools.DebugSupport");
708         } catch (Exception JavaDoc e) {
709             return false;
710         }
711
712         return true;
713     }
714
715     {
716         fPreferences = new Properties JavaDoc();
717         fPreferences.setProperty("loading", "true");
718         readPreferences();
719         fMaxMessage = getPreference("maxmessage", fMaxMessage);
720     }
721
722     public String JavaDoc getTitle() {
723         return ("Run Unit Tests");
724     }
725
726     private void promptState(ControllerResponse myResponse,
727                              ControllerRequest params)
728             throws ControllerException {
729         try {
730             Input chooseSchema = new Input();
731             chooseSchema.setLabel("Choose Schema");
732             chooseSchema.setName("SchemaClass");
733
734             Vector JavaDoc v2 = new Vector JavaDoc(2);
735             v2.addElement(new ValidValue("com.jcorporate.expresso." + "core.ExpressoSchema",
736                     "General"));
737
738             SchemaList sl = new SchemaList(SecuredDBObject.SYSTEM_ACCOUNT);
739             sl.setDataContext(params.getDataContext());
740
741             SchemaList oneSchema = null;
742
743             for (Iterator JavaDoc e = sl.searchAndRetrieveList("Descrip").iterator();
744                  e.hasNext();) {
745                 oneSchema = (SchemaList) e.next();
746                 v2.addElement(new ValidValue(oneSchema.getField("SchemaClass"),
747                         oneSchema.getField("Descrip")));
748             }
749
750             chooseSchema.setValidValues(v2);
751             myResponse.addInput(chooseSchema);
752
753             /* now the actions */
754
755             /* Action selTest = new Action("Select Test(s)", getClass().getName());
756
757 selTest.setName("selTest");
758
759 selTest.addParam(STATE_PARAM_KEY, "selTest");
760
761 addAction(selTest); */

762             Transition runAllTests = new Transition("Run All Tests",
763                     getClass().getName());
764             runAllTests.setName("runAllTests");
765             runAllTests.addParam(STATE_PARAM_KEY, "runAllTests");
766             myResponse.addTransition(runAllTests);
767         } catch (DBException de) {
768             throw new ControllerException(de);
769         }
770     }
771
772
773     /**
774      * test a transition to a controller/state
775      * which requires a form
776      */

777     protected void runTransition2FormTestState(ControllerRequest request,
778                                                ControllerResponse response)
779             throws ControllerException,
780             NonHandleableException {
781         Transition trans = new Transition();
782         trans.setControllerObject(Registration.class);
783         trans.setState("promptSelfRegister");
784         trans.addParam("dbContext", "default");
785         trans.transition(request, response);
786     }
787
788     /**
789      * test a transition to a controller/state
790      * note that the ControllerSecurityMatrix output uses the default layout,
791      * so the title at the top of that page will show this test controller.
792      */

793     protected void runTransitionTestState(ControllerRequest request,
794                                           ControllerResponse response)
795             throws ControllerException,
796             NonHandleableException {
797         Transition trans = new Transition();
798         trans.setControllerObject(Download.class);
799         trans.setState("list");
800         trans.transition(request, response);
801     }
802
803     /**
804      * test a transition to a controller/state
805      * which requires a form
806      */

807     protected void runPromptTestState(ControllerRequest request,
808                                       ControllerResponse response)
809             throws ControllerException,
810             NonHandleableException {
811         Input input = new Input("demoprompt", "demoprompt");
812         //input.setType("textbox");
813
response.addInput(input);
814         Transition trans = new Transition("transitionFromFormTest", this);
815         response.addTransition(trans);
816     }
817
818
819     /**
820      * test a transition from a controller/state
821      * which uses a form to one that does not use a form
822      */

823     protected void runTransitionFromFormTestState(ControllerRequest request,
824                                                   ControllerResponse response)
825             throws ControllerException,
826             NonHandleableException {
827         Transition trans = new Transition();
828         trans.setControllerObject(Download.class);
829         trans.setState("list");
830         trans.transition(request, response);
831     }
832
833 } /* TestController */
834
Popular Tags