KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > turbine > modules > screens > ErrorTest


1 package org.apache.turbine.modules.screens;
2  
3 /*
4  * Copyright 2001-2004 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License")
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 import junit.framework.Test;
20 import junit.framework.TestSuite;
21
22 import org.apache.cactus.ServletTestCase;
23 import org.apache.turbine.Turbine;
24 import org.apache.turbine.modules.ScreenLoader;
25 import org.apache.turbine.services.TurbineServices;
26 import org.apache.turbine.services.rundata.RunDataService;
27 import org.apache.turbine.util.RunData;
28
29 /**
30  * ErrorTest
31  *
32  *@author <a HREF="epugh@upstate.com">Eric Pugh</a>
33  *@version $Id: ErrorTest.java,v 1.2.2.2 2004/05/20 03:33:12 seade Exp $
34  */

35 public class ErrorTest extends ServletTestCase
36 {
37     private RunData data = null;
38     private org.apache.turbine.modules.screens.Error errorScreen = null;
39     private Turbine turbine = null;
40     
41     /**
42      * Defines the testcase name for JUnit.
43      *
44      *@param name the testcase's name.
45      */

46     public ErrorTest(String JavaDoc name)
47     {
48         super(name);
49     }
50
51     /**
52      * Start the tests.
53      *
54      *@param args the arguments. Not used
55      */

56     public static void main(String JavaDoc args[])
57     {
58         junit.awtui.TestRunner.main(new String JavaDoc[] { ErrorTest.class.getName()});
59     }
60
61     /**
62      * Creates the test suite.
63      *
64      *@return a test suite (<code>TestSuite</code>) that includes all methods
65      * starting with "test"
66      */

67     public static Test suite()
68     {
69         // All methods starting with "test" will be executed in the test suite.
70
return new TestSuite(ErrorTest.class);
71     }
72
73     protected void setUp() throws Exception JavaDoc
74     {
75         super.setUp();
76
77     }
78
79     /**
80     * After each testXXX test runs, shut down the Turbine servlet.
81     */

82     protected void tearDown() throws Exception JavaDoc
83     {
84         turbine.destroy();
85         super.tearDown();
86     }
87
88     /**
89        * Tests if we can call the doBuild method
90        *
91        *@todo Move the turbine setup stuff into the setUp() method.
92        */

93     public void testDobuild() throws Exception JavaDoc
94     {
95
96         config.setInitParameter(
97             "properties",
98             "/WEB-INF/conf/TurbineCacheTest.properties");
99         turbine = new Turbine();
100         turbine.init(config);
101
102         data = ((RunDataService) TurbineServices.getInstance().getService(RunDataService.SERVICE_NAME)).getRunData(request, response, config);
103
104         errorScreen =
105             (org.apache.turbine.modules.screens.Error) ScreenLoader
106                 .getInstance()
107                 .getInstance("Error");
108         data.getParameters ().setString ( "param", "param1Value" );
109         errorScreen.doBuild(data);
110         
111         assertTrue("Make sure we have our error parameter.",data.getPage().toString().indexOf("param1Value")>-1);
112
113     }
114
115 }
116
Popular Tags