KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > struts > action > TestActionServlet


1 /*
2  * $Id: TestActionServlet.java 54929 2004-10-16 16:38:42Z germuska $
3  *
4  * Copyright 1999-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 package org.apache.struts.action;
19
20 import javax.servlet.ServletException JavaDoc;
21 import junit.framework.Test;
22 import junit.framework.TestSuite;
23
24 import org.apache.cactus.ServletTestCase;
25 import org.apache.struts.util.MessageResources;
26
27 /**
28  * Suite of unit tests for the
29  * <code>org.apache.struts.action.ActionServlet</code> class.
30  */

31 public class TestActionServlet extends ServletTestCase
32 {
33     /**
34      * Defines the testcase name for JUnit.
35      *
36      * @param theName the testcase's name.
37      */

38     public TestActionServlet(String JavaDoc theName)
39     {
40         super(theName);
41     }
42
43     /**
44      * Start the tests.
45      *
46      * @param theArgs the arguments. Not used
47      */

48     public static void main(String JavaDoc[] theArgs)
49     {
50         junit.awtui.TestRunner.main(new String JavaDoc[] {TestActionServlet.class.getName()});
51     }
52
53     /**
54      * @return a test suite (<code>TestSuite</code>) that includes all methods
55      * starting with "test"
56      */

57     public static Test suite()
58     {
59         // All methods starting with "test" will be executed in the test suite.
60
return new TestSuite(TestActionServlet.class);
61     }
62
63
64     // ----------------------------- initInternal() and destroyInternal() tests
65

66
67     /**
68      * Verify that we can initialize and destroy our internal message
69      * resources object.
70      */

71     public void testInitDestroyInternal() {
72
73         ActionServlet servlet = new ActionServlet();
74         try {
75             servlet.initInternal();
76         } catch (ServletException JavaDoc e) {
77             fail("initInternal() threw exception: " + e);
78         }
79         assertTrue("internal was initialized",
80                    servlet.getInternal() != null);
81         assertTrue("internal of correct type",
82                    servlet.getInternal() instanceof MessageResources);
83         servlet.destroyInternal();
84         assertTrue("internal was destroyed",
85                    servlet.getInternal() == null);
86
87     }
88
89
90
91     //----- Test initApplication() method --------------------------------------
92

93     /**
94      * Verify that nothing happens if no "application" property is defined in
95      * the servlet configuration.
96      */

97     /*
98     public void testInitApplicationNull() throws ServletException
99     {
100         ActionServlet servlet = new ActionServlet();
101         servlet.init(config);
102
103         // Test the initApplication() method
104         servlet.initApplication();
105
106         // As no "application" object is found in the servlet config, no
107         // attribute should be set in the context
108         assertTrue(config.getServletContext().getAttribute(Action.MESSAGES_KEY) == null);
109     }
110     */

111
112     /**
113      * Verify that eveything is fine when only a "application" parameter is
114      * defined in the servlet configuration.
115      */

116     /*
117     public void testInitApplicationOk1() throws ServletException
118     {
119         // initialize config
120         config.setInitParameter("application", "org.apache.struts.webapp.example.ApplicationResources");
121
122         ActionServlet servlet = new ActionServlet();
123         servlet.init(config);
124
125         // Test the initApplication() method
126         servlet.initApplication();
127
128         assertTrue(servlet.application != null);
129         assertTrue(servlet.application.getReturnNull() == true);
130
131         assertTrue(config.getServletContext().getAttribute(Action.MESSAGES_KEY) != null);
132         assertEquals(servlet.application, config.getServletContext().getAttribute(Action.MESSAGES_KEY));
133
134     }
135     */

136
137     // [...]
138
}
139
Popular Tags