1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.struts2.util;
22
23 import java.util.HashMap;
24 import java.util.Map;
25
26 import org.apache.struts2.dispatcher.Dispatcher;
27 import org.springframework.mock.web.MockServletContext;
28
29 import com.opensymphony.xwork2.util.LocalizedTextUtil;
30
31 /***
32 * Generic test setup methods to be used with any unit testing framework.
33 */
34 public class StrutsTestCaseHelper {
35
36 /***
37 * Sets up the configuration settings, XWork configuration, and
38 * message resources
39 */
40 public static void setUp() throws Exception {
41 LocalizedTextUtil.clearDefaultResourceBundles();
42 }
43
44 public static Dispatcher initDispatcher(Map<String,String> params) {
45 if (params == null) {
46 params = new HashMap<String,String>();
47 }
48 Dispatcher du = new Dispatcher(new MockServletContext(), params);
49 du.init();
50 Dispatcher.setInstance(du);
51 return du;
52 }
53
54 public static void tearDown() throws Exception {
55 Dispatcher.setInstance(null);
56 }
57 }