View Javadoc

1   /*
2    * $Id: StrutsTestCase.java 462522 2006-10-10 19:42:16Z mrdon $
3    *
4    * Copyright 2006 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.struts2;
19  
20  import org.apache.struts2.config.Settings;
21  import org.apache.struts2.config.StrutsXmlConfigurationProvider;
22  import org.apache.struts2.dispatcher.Dispatcher;
23  import org.springframework.mock.web.MockServletContext;
24  
25  import com.opensymphony.xwork2.XWorkTestCase;
26  import com.opensymphony.xwork2.config.ConfigurationManager;
27  import com.opensymphony.xwork2.util.LocalizedTextUtil;
28  
29  /***
30   * Base test case for unit testing Struts.
31   */
32  public abstract class StrutsTestCase extends XWorkTestCase {
33  
34  
35      /***
36       * Sets up the configuration settings, XWork configuration, and
37       * message resources
38       */
39      protected void setUp() throws Exception {
40          super.setUp();
41          Settings.reset();
42          LocalizedTextUtil.clearDefaultResourceBundles();
43          Dispatcher du = new Dispatcher(new MockServletContext());
44          Dispatcher.setInstance(du);
45          configurationManager = new ConfigurationManager();
46          configurationManager.addConfigurationProvider(
47                  new StrutsXmlConfigurationProvider("struts-default.xml", false));
48          configurationManager.addConfigurationProvider(
49                  new StrutsXmlConfigurationProvider("struts-plugin.xml", false));
50          configurationManager.addConfigurationProvider(
51                  new StrutsXmlConfigurationProvider("struts.xml", false));
52          du.setConfigurationManager(configurationManager);
53          
54      }
55  
56      protected void tearDown() throws Exception {
57          super.tearDown();
58      }
59  
60  }