1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.core.kfs;
17
18 import static org.junit.Assert.assertNotNull;
19 import static org.junit.Assert.assertTrue;
20 import java.util.HashMap;
21 import java.util.Map;
22 import java.util.Map.Entry;
23
24 import org.junit.Test;
25 import org.kuali.hr.KPMEWebTestCase;
26 import org.kuali.hr.util.HtmlUnitUtil;
27 import org.kuali.kpme.core.kfs.coa.businessobject.SubObjectCode;
28 import org.kuali.kpme.core.util.HrTestConstants;
29 import org.kuali.rice.krad.service.KRADServiceLocator;
30 import com.gargoylesoftware.htmlunit.html.HtmlInput;
31 import com.gargoylesoftware.htmlunit.html.HtmlPage;
32 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
33
34 public class SubObjectCodeMaintTest extends KPMEWebTestCase {
35
36 private static final String NEW_MAINT_DOC_PREFIX = "document.newMaintainableObject.";
37 private String newUrl;
38 private String lookupUrl;
39 private Map<String,String> requiredFields;
40
41 @Override
42 public void setUp() throws Exception {
43
44 super.setUp();
45 before();
46 }
47
48 @Override
49 public void tearDown() throws Exception {
50 requiredFields.clear();
51
52 super.tearDown();
53 }
54
55 private void before() {
56
57 newUrl = HrTestConstants.Urls.SUB_OBJECT_CODE_MAINT_NEW_URL;
58 lookupUrl = HrTestConstants.Urls.SUB_OBJECT_CODE_MAINT_URL;
59
60 requiredFields = new HashMap<String,String>();
61 requiredFields.put("universityFiscalYear", "University Fiscal Year (Year) is a required field.");
62 requiredFields.put("chartOfAccountsCode", "Chart Code (Chart) is a required field.");
63 requiredFields.put("accountNumber", "Account Number (Account Number) is a required field.");
64 requiredFields.put("financialObjectCode", "Object Code (Object) is a required field.");
65 requiredFields.put("financialSubObjectCode", "Sub-Object Code (Sub-Object) is a required field.");
66 requiredFields.put("financialSubObjectCodeName", "Sub-Object Code Name (SubObjCodeName) is a required field.");
67 requiredFields.put("financialSubObjectCdshortNm", "Sub-Object Code Short Name (SubObjCodeShortName) is a required field.");
68 }
69
70 private void setDefaultTestInputValues() {
71 requiredFields = new HashMap<String,String>();
72 requiredFields.put("active", "on");
73 requiredFields.put("universityFiscalYear", "2013");
74 requiredFields.put("chartOfAccountsCode", "UA");
75 requiredFields.put("accountNumber", "1111");
76 requiredFields.put("financialObjectCode", "1000");
77 requiredFields.put("financialSubObjectCode", "10");
78 requiredFields.put("financialSubObjectCodeName", "Test Sub Obj");
79 requiredFields.put("financialSubObjectCdshortNm", "Sub Obj TST");
80 }
81
82 @Test
83 public void testRequiredFields() throws Exception {
84 HtmlPage maintPage = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), newUrl);
85 assertNotNull("maintenance page is null", maintPage);
86
87 HtmlInput docDescription = HtmlUnitUtil.getInputContainingText(maintPage, "* Document Description");
88 assertNotNull("maintenance page does not contain document description", docDescription);
89
90 docDescription.setValueAttribute("testing submission");
91
92 HtmlPage resultPage = HtmlUnitUtil.clickInputContainingText(maintPage, "submit");
93 assertNotNull("no result page returned after submit", resultPage);
94
95 String resultPageAsText = resultPage.asText();
96 for(Entry<String,String> requiredField : requiredFields.entrySet()) {
97 assertTrue("page does not contain error message for required field: '" + requiredField.getKey() + "'",
98 resultPageAsText.contains(requiredField.getValue()));
99 }
100 }
101
102 @Test
103 public void testLookup() throws Exception {
104 HtmlPage lookupPage = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), lookupUrl);
105 assertNotNull("lookup page is null", lookupPage);
106
107 lookupPage = HtmlUnitUtil.clickInputContainingText(lookupPage, "search");
108 assertNotNull("lookup result page is null", lookupPage);
109 assertTrue("lookup page should contain 'UA Sub Obj'", lookupPage.asText().contains("UA Sub Obj"));
110 }
111
112 @Test
113 public void testInvalidChartConsistencyCaseOne() throws Exception {
114
115
116
117
118 HtmlPage maintPage = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), newUrl);
119 assertNotNull("maintenance page is null", maintPage);
120
121 HtmlInput docDescription = HtmlUnitUtil.getInputContainingText(maintPage, "* Document Description");
122 assertNotNull("maintenance page does not contain document description", docDescription);
123
124 setDefaultTestInputValues();
125 for(Entry<String,String> entry : requiredFields.entrySet()) {
126 HtmlUnitUtil.setFieldValue(maintPage, NEW_MAINT_DOC_PREFIX + entry.getKey(), entry.getValue());
127 }
128
129 docDescription.setValueAttribute("testing submission");
130
131
132 HtmlUnitUtil.setFieldValue(maintPage, NEW_MAINT_DOC_PREFIX + "accountNumber", "9999");
133
134 before();
135 HtmlPage resultPage = HtmlUnitUtil.clickInputContainingText(maintPage, "submit");
136 assertNotNull("no result page returned after submit", resultPage);
137
138 String resultPageAsText = resultPage.asText();
139 for(Entry<String,String> requiredField : requiredFields.entrySet()) {
140 if(requiredField.getKey().equals("accountNumber")) {
141 assertTrue("page does not contain error message for the invalid field: '" + requiredField.getKey() + "'",
142 resultPageAsText.contains("No such active account exists whose chart matches 'UA'"));
143 }
144 }
145 }
146
147 @Test
148 public void testInvalidChartConsistencyCaseTwo() throws Exception {
149
150
151
152
153 HtmlPage maintPage = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), newUrl);
154 assertNotNull("maintenance page is null", maintPage);
155
156 HtmlInput docDescription = HtmlUnitUtil.getInputContainingText(maintPage, "* Document Description");
157 assertNotNull("maintenance page does not contain document description", docDescription);
158
159 setDefaultTestInputValues();
160 for(Entry<String,String> entry : requiredFields.entrySet()) {
161 HtmlUnitUtil.setFieldValue(maintPage, NEW_MAINT_DOC_PREFIX + entry.getKey(), entry.getValue());
162 }
163
164 docDescription.setValueAttribute("testing submission");
165
166
167 HtmlUnitUtil.setFieldValue(maintPage, NEW_MAINT_DOC_PREFIX + "financialObjectCode", "9000");
168
169 before();
170 HtmlPage resultPage = HtmlUnitUtil.clickInputContainingText(maintPage, "submit");
171 assertNotNull("no result page returned after submit", resultPage);
172
173 String resultPageAsText = resultPage.asText();
174 for(Entry<String,String> requiredField : requiredFields.entrySet()) {
175 if(requiredField.getKey().equals("financialObjectCode")) {
176 assertTrue("page does not contain error message for the invalid field: '" + requiredField.getKey() + "'",
177 resultPageAsText.contains("No such active object code exists whose chart matches 'UA'"));
178 }
179 }
180 }
181
182 @Test
183 public void testInvalidChartConsistencyCaseThree() throws Exception {
184
185
186
187
188 HtmlPage maintPage = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), newUrl);
189 assertNotNull("maintenance page is null", maintPage);
190
191 HtmlInput docDescription = HtmlUnitUtil.getInputContainingText(maintPage, "* Document Description");
192 assertNotNull("maintenance page does not contain document description", docDescription);
193
194 setDefaultTestInputValues();
195 for(Entry<String,String> entry : requiredFields.entrySet()) {
196 HtmlUnitUtil.setFieldValue(maintPage, NEW_MAINT_DOC_PREFIX + entry.getKey(), entry.getValue());
197 }
198
199 docDescription.setValueAttribute("testing submission");
200
201
202 HtmlUnitUtil.setFieldValue(maintPage, NEW_MAINT_DOC_PREFIX + "accountNumber", "9999");
203 HtmlUnitUtil.setFieldValue(maintPage, NEW_MAINT_DOC_PREFIX + "financialObjectCode", "9000");
204
205 before();
206 HtmlPage resultPage = HtmlUnitUtil.clickInputContainingText(maintPage, "submit");
207 assertNotNull("no result page returned after submit", resultPage);
208
209 String resultPageAsText = resultPage.asText();
210 for(Entry<String,String> requiredField : requiredFields.entrySet()) {
211 if(requiredField.getKey().equals("financialObjectCode")) {
212 assertTrue("page does not contain error message for the invalid field: '" + requiredField.getKey() + "'",
213 resultPageAsText.contains("No such active object code exists whose chart matches 'UA'"));
214 }
215 if(requiredField.getKey().equals("accountNumber")) {
216 assertTrue("page does not contain error message for the invalid field: '" + requiredField.getKey() + "'",
217 resultPageAsText.contains("No such active account exists whose chart matches 'UA'"));
218 }
219 }
220 }
221
222 @Test
223 public void testValidChartConsistencyWithClosedAccount() throws Exception {
224
225
226
227
228
229
230
231
232
233 HtmlPage maintPage = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), newUrl);
234 assertNotNull("maintenance page is null", maintPage);
235
236 HtmlInput docDescription = HtmlUnitUtil.getInputContainingText(maintPage, "* Document Description");
237 assertNotNull("maintenance page does not contain document description", docDescription);
238
239 setDefaultTestInputValues();
240 for(Entry<String,String> entry : requiredFields.entrySet()) {
241 HtmlUnitUtil.setFieldValue(maintPage, NEW_MAINT_DOC_PREFIX + entry.getKey(), entry.getValue());
242 }
243 docDescription.setValueAttribute("testing submission");
244
245 HtmlUnitUtil.setFieldValue(maintPage, NEW_MAINT_DOC_PREFIX + "accountNumber","2222");
246
247 HtmlUnitUtil.setFieldValue(maintPage, NEW_MAINT_DOC_PREFIX + "financialSubObjectCode", "20");
248 HtmlUnitUtil.setFieldValue(maintPage, NEW_MAINT_DOC_PREFIX + "financialSubObjectCodeName", "TST Sub object code");
249 HtmlUnitUtil.setFieldValue(maintPage, NEW_MAINT_DOC_PREFIX + "financialSubObjectCdshortNm", "TST SOC");
250
251 HtmlPage resultPage = HtmlUnitUtil.clickInputContainingText(maintPage, "submit");
252 assertTrue("page should contain active account existence error", resultPage.asText().contains("No such active account exists whose chart matches 'UA'"));
253
254 Map<String,String> keys = new HashMap<String,String>();
255 keys.put("universityFiscalYear", "2013");
256 keys.put("chartOfAccountsCode", "UA");
257 keys.put("accountNumber", "2222");
258 keys.put("financialObjectCode", "1000");
259 keys.put("financialSubObjectCode", "20");
260
261
262
263
264
265 }
266
267 @Test
268 public void testValidChartConsistencyWithOpenAccount() throws Exception {
269
270 HtmlPage maintPage = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), newUrl);
271 assertNotNull("maintenance page is null", maintPage);
272
273 HtmlInput docDescription = HtmlUnitUtil.getInputContainingText(maintPage, "* Document Description");
274 assertNotNull("maintenance page does not contain document description", docDescription);
275
276 setDefaultTestInputValues();
277 for(Entry<String,String> entry : requiredFields.entrySet()) {
278 HtmlUnitUtil.setFieldValue(maintPage, NEW_MAINT_DOC_PREFIX + entry.getKey(), entry.getValue());
279 }
280 docDescription.setValueAttribute("testing submission");
281
282 HtmlUnitUtil.setFieldValue(maintPage, NEW_MAINT_DOC_PREFIX + "accountNumber","3333");
283
284 HtmlUnitUtil.setFieldValue(maintPage, NEW_MAINT_DOC_PREFIX + "financialSubObjectCode", "30");
285 HtmlUnitUtil.setFieldValue(maintPage, NEW_MAINT_DOC_PREFIX + "financialSubObjectCodeName", "TST Sub object code 3");
286 HtmlUnitUtil.setFieldValue(maintPage, NEW_MAINT_DOC_PREFIX + "financialSubObjectCdshortNm", "TST SOC 3");
287
288 HtmlPage resultPage = HtmlUnitUtil.clickInputContainingText(maintPage, "submit");
289 assertTrue("page should contain active account existence error", !resultPage.asText().contains("error(s)"));
290
291 Map<String,String> keys = new HashMap<String,String>();
292 keys.put("universityFiscalYear", "2013");
293 keys.put("chartOfAccountsCode", "UA");
294 keys.put("accountNumber", "3333");
295 keys.put("financialObjectCode", "1000");
296 keys.put("financialSubObjectCode", "30");
297
298 SubObjectCode subObjectCode = KRADServiceLocatorWeb.getLegacyDataAdapter().findByPrimaryKey(SubObjectCode.class, keys);
299 assertNotNull("newly created sub-object code should exist", subObjectCode);
300
301 KRADServiceLocatorWeb.getLegacyDataAdapter().delete(subObjectCode);
302 }
303
304 @Test
305 public void testInValidChart() throws Exception {
306
307
308
309
310
311
312
313
314
315 HtmlPage maintPage = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), newUrl);
316 assertNotNull("maintenance page is null", maintPage);
317
318 HtmlInput docDescription = HtmlUnitUtil.getInputContainingText(maintPage, "* Document Description");
319 assertNotNull("maintenance page does not contain document description", docDescription);
320
321 setDefaultTestInputValues();
322 for(Entry<String,String> entry : requiredFields.entrySet()) {
323 HtmlUnitUtil.setFieldValue(maintPage, NEW_MAINT_DOC_PREFIX + entry.getKey(), entry.getValue());
324 }
325 docDescription.setValueAttribute("testing submission");
326
327 HtmlUnitUtil.setFieldValue(maintPage, NEW_MAINT_DOC_PREFIX + "chartOfAccountsCode","BP");
328
329 HtmlPage resultPage = HtmlUnitUtil.clickInputContainingText(maintPage, "submit");
330
331 assertTrue("page should contain active chart existence error", resultPage.asText().contains("No active chart exists for this code"));
332 }
333
334 }