1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package net.smartlab.web;
24
25 import java.io.File;
26 import java.text.ParseException;
27 import java.util.Arrays;
28
29 import javax.servlet.http.HttpServletRequest;
30 import javax.servlet.http.HttpServletResponse;
31
32 import net.sf.ezmorph.test.ArrayAssertions;
33 import net.smartlab.web.DataAccessObject.SearchInfo;
34
35 import org.apache.struts.action.ActionForm;
36 import org.apache.struts.action.ActionMapping;
37
38 import servletunit.HttpServletRequestSimulator;
39 import servletunit.struts.MockStrutsTestCase;
40
41
42
43
44
45 public class AbstractArchiveActionTest extends MockStrutsTestCase {
46
47
48
49
50 protected void setUp() throws Exception {
51 super.setUp();
52 super.setContextDirectory(new File("res/test"));
53 super.setConfigFile("/WEB-INF/struts.xml");
54 super.setServletConfigFile("/WEB-INF/web.xml");
55 }
56
57
58
59
60
61
62
63
64 public void testGetListSelection() throws ParseException {
65 HttpServletRequestSimulator request = super.getMockRequest();
66 request.addParameter("selection", new String[] {"1", "2", "3"});
67 String[] selection = AbstractArchiveAction.getListSelection(request);
68 ArrayAssertions.assertEquals(new String[] {"1", "2", "3"}, selection);
69 }
70
71
72
73
74
75
76 public void testGetSelection() {
77 super.setRequestPathInfo("/list");
78 super.addRequestParameter("selection", new String[] {"1", "2", "3"});
79 super.actionPerform();
80 super.verifyForward("success");
81 super.verifyNoActionErrors();
82 }
83
84
85
86
87
88
89 public void testSetSelection() {
90 super.setRequestPathInfo("/set");
91 super.addRequestParameter("selection", new String[] {"1", "2", "3"});
92 super.actionPerform();
93 super.verifyForward("success");
94 super.verifyNoActionErrors();
95 }
96
97
98
99
100
101
102 public void testResetSelection() {
103 super.setRequestPathInfo("/reset");
104 super.addRequestParameter("selection", new String[] {"1", "2", "3"});
105 super.actionPerform();
106 super.verifyForward("success");
107 super.verifyNoActionErrors();
108 }
109
110
111
112
113
114
115 public void testGetSearchInfo() {
116 super.setRequestPathInfo("/reset");
117 super.addRequestParameter("selection", new String[] {"1", "2", "3"});
118 super.actionPerform();
119 super.verifyForward("success");
120 super.verifyNoActionErrors();
121 }
122
123
124 public static class Stub extends AbstractArchiveAction {
125
126 public String remove(ActionForm form, HttpServletRequest request, HttpServletResponse response,
127 ActionMapping mapping) throws Exception {
128 return null;
129 }
130
131 public String removeAll(ActionForm form, HttpServletRequest request, HttpServletResponse response,
132 ActionMapping mapping) throws Exception {
133 return null;
134 }
135
136 public String search(ActionForm form, HttpServletRequest request, HttpServletResponse response,
137 ActionMapping mapping) throws Exception {
138 SearchInfo info = AbstractArchiveAction.getSearchInfo(request);
139 if (info.getFilters().size() == 5 && info.getOrder().equals("display") && info.isDescendant()
140 && !info.isUnion()) {
141 return "success";
142 } else {
143 throw new Exception(info.toString());
144 }
145 }
146
147 public String select(ActionForm form, HttpServletRequest request, HttpServletResponse response,
148 ActionMapping mapping) throws Exception {
149 return null;
150 }
151
152 public String update(ActionForm form, HttpServletRequest request, HttpServletResponse response,
153 ActionMapping mapping) throws Exception {
154 return null;
155 }
156
157 public String listSelection(ActionForm form, HttpServletRequest request, HttpServletResponse response,
158 ActionMapping mapping) throws Exception {
159 String[] list = AbstractArchiveAction.getListSelection(request);
160 if (list.length == 3 && Arrays.equals(new String[] {"1", "2", "3"}, list)) {
161 return "success";
162 } else {
163 throw new Exception(list.toString());
164 }
165 }
166
167 public String setSelection(ActionForm form, HttpServletRequest request, HttpServletResponse response,
168 ActionMapping mapping) throws Exception {
169 String[] list = AbstractArchiveAction.getListSelection(request);
170 if (list.length == 3 && Arrays.equals(new String[] {"1", "2", "3"}, list)) {
171 return "success";
172 } else {
173 throw new Exception(list.toString());
174 }
175 }
176
177 public String resetSelection(ActionForm form, HttpServletRequest request, HttpServletResponse response,
178 ActionMapping mapping) throws Exception {
179 String[] list = AbstractArchiveAction.getListSelection(request);
180 if (list.length == 3 && Arrays.equals(new String[] {"1", "2", "3"}, list)) {
181 return "success";
182 } else {
183 throw new Exception(list.toString());
184 }
185 }
186 }
187 }