1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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 }