1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.time.roles.web;
17
18 import java.util.ArrayList;
19 import java.util.HashMap;
20 import java.util.List;
21 import java.util.Map;
22
23 import org.apache.log4j.Logger;
24 import org.joda.time.DateTime;
25 import org.joda.time.DateTimeZone;
26 import org.json.simple.JSONArray;
27 import org.json.simple.JSONObject;
28 import org.json.simple.JSONValue;
29 import org.junit.Assert;
30 import org.junit.Test;
31 import org.kuali.hr.time.util.TimeDetailTestUtils;
32 import org.kuali.hr.time.workflow.TimesheetWebTestBase;
33 import org.kuali.hr.util.HtmlUnitUtil;
34 import org.kuali.kpme.core.FunctionalTest;
35 import org.kuali.kpme.core.assignment.Assignment;
36 import org.kuali.kpme.core.calendar.entry.CalendarEntry;
37 import org.kuali.kpme.core.earncode.EarnCode;
38 import org.kuali.kpme.core.service.HrServiceLocator;
39 import org.kuali.kpme.core.util.TKUtils;
40 import org.kuali.kpme.tklm.time.detail.web.TimeDetailActionFormBase;
41 import org.kuali.kpme.tklm.time.service.TkServiceLocator;
42 import org.kuali.kpme.tklm.time.timesheet.TimesheetDocument;
43 import com.gargoylesoftware.htmlunit.html.HtmlForm;
44 import com.gargoylesoftware.htmlunit.html.HtmlPage;
45
46
47
48
49 @FunctionalTest
50 public class RoleTimesheetWebIntegrationTest extends TimesheetWebTestBase {
51
52 private static final Logger LOG = Logger.getLogger(RoleTimesheetWebIntegrationTest.class);
53
54
55
56 private List<String> VALID_NON_ENTRY_USERS = new ArrayList<String>() {{
57
58
59
60
61 private List<String> INVALID_NON_ENTRY_USERS = new ArrayList<String>(){{
62 add("testuser1"); add("testuser2"); add("testuser3"); add("testuser4"); }};
63
64 private TimesheetDocument fredsDocument = null;
65 DateTime asOfDate = new DateTime(2011, 3, 1, 12, 0, 0, 0, TKUtils.getSystemDateTimeZone());
66
67 @Override
68
69
70
71
72 public void setUp() throws Exception {
73 super.setUp();
74
75 String userId = "fred";
76 DateTimeZone dateTimeZone = DateTimeZone.forID(HrServiceLocator.getTimezoneService().getUserTimezone(userId));
77
78 CalendarEntry pcd = HrServiceLocator.getCalendarEntryService().getCurrentCalendarDates(userId, asOfDate);
79 Assert.assertNotNull("No PayCalendarDates", pcd);
80 fredsDocument = TkServiceLocator.getTimesheetService().openTimesheetDocument(userId, pcd);
81 String tdocId = fredsDocument.getDocumentId();
82
83
84 verifyLogins(fredsDocument);
85
86
87 HtmlPage page = loginAndGetTimeDetailsHtmlPage(getWebClient(), userId, tdocId, true);
88 Assert.assertTrue("Calendar not loaded.", page.asText().contains("March 2011"));
89
90 HtmlForm form = page.getFormByName("TimeDetailActionForm");
91 Assert.assertNotNull(form);
92 List<Assignment> assignments = HrServiceLocator.getAssignmentService().getAssignments(userId, JAN_AS_OF_DATE.toLocalDate());
93 Assignment assignment = assignments.get(0);
94
95 List<EarnCode> earnCodes = TkServiceLocator.getTimesheetService().getEarnCodesForTime(assignment, JAN_AS_OF_DATE.toLocalDate());
96 EarnCode earnCode = earnCodes.get(0);
97 Assert.assertEquals("There should be no existing time blocks.", 0, fredsDocument.getTimeBlocks().size());
98
99
100
101
102 final DateTime start = new DateTime(2011, 3, 2, 8, 0, 0, 0, dateTimeZone);
103 final DateTime end = new DateTime(2011, 3, 2, 13, 0, 0, 0, dateTimeZone);
104 TimeDetailActionFormBase tdaf = TimeDetailTestUtils.buildDetailActionForm(fredsDocument, assignment, earnCode, start, end, null, false, null, true);
105 List<String> errors = TimeDetailTestUtils.setTimeBlockFormDetails(form, tdaf);
106 Assert.assertEquals("There should be no errors in this time detail submission", 0, errors.size());
107 page = TimeDetailTestUtils.submitTimeDetails(getWebClient(), getTimesheetDocumentUrl(tdocId), tdaf);
108 Assert.assertNotNull(page);
109
110 String dataText = page.getElementById("timeBlockString").getFirstChild().getNodeValue();
111 JSONArray jsonData = (JSONArray) JSONValue.parse(dataText);
112 final JSONObject jsonDataObject = (JSONObject) jsonData.get(0);
113 Assert.assertTrue("TimeBlock Data Missing.", checkJSONValues(new JSONObject() {{ put("outer", jsonDataObject); }},
114 new ArrayList<Map<String, Object>>() {{
115 add(new HashMap<String, Object>() {{
116 put("earnCode", "RGN");
117 put("hours", "5.0");
118 put("amount", null);
119 }});
120 }},
121 new HashMap<String, Object>() {{
122 put("earnCode", "RGN");
123 start.toString();
124 put("startNoTz", start.toString("yyyy-MM-dd'T'HH:mm:ss"));
125 put("endNoTz", end.toString("yyyy-MM-dd'T'HH:mm:ss"));
126 put("title", "SDR1 Work Area");
127 put("assignment", "30_30_30");
128 }}
129 ));
130
131
132 fredsDocument = TkServiceLocator.getTimesheetService().openTimesheetDocument(userId, pcd);
133 }
134
135
136
137
138
139 @Test
140 public void testInitiatedTimesheetIsVisibleByAll() throws Exception {
141
142 for (String uid : VALID_NON_ENTRY_USERS) {
143 LOG.info("Testing visibility for " + uid);
144 HtmlPage page = loginAndGetTimeDetailsHtmlPage(getWebClient(), uid, fredsDocument.getDocumentId(), true);
145 Assert.assertTrue("Calendar not loaded.", page.asText().contains("March 2011"));
146 }
147 }
148
149 @Test
150 public void testInitiatedTimesheetIsNotVisible() throws Exception {
151 for (String uid : INVALID_NON_ENTRY_USERS) {
152 LOG.info("Testing visibility for " + uid);
153 HtmlPage page = loginAndGetTimeDetailsHtmlPage(getWebClient(), uid, fredsDocument.getDocumentId(), false);
154
155 Assert.assertTrue("Should not have access", page.asText().contains("You are not authorized to access this portion of the application."));
156 }
157 }
158
159 public void testInitiatedTimesheetEditable(String userId) throws Exception {
160
161 String tdocId = fredsDocument.getDocumentId();
162 HtmlPage page = loginAndGetTimeDetailsHtmlPage(getWebClient(), userId, tdocId, true);
163 LOG.debug(page.asText());
164
165 Assert.assertTrue("Calendar not loaded.", page.asText().contains("March 2011"));
166
167 HtmlForm form = page.getFormByName("TimeDetailActionForm");
168 Assert.assertNotNull(form);
169 List<Assignment> assignments = HrServiceLocator.getAssignmentService().getAssignments("fred", JAN_AS_OF_DATE.toLocalDate());
170 Assignment assignment = assignments.get(0);
171
172 List<EarnCode> earnCodes = TkServiceLocator.getTimesheetService().getEarnCodesForTime(assignment, JAN_AS_OF_DATE.toLocalDate());
173 EarnCode earnCode = earnCodes.get(0);
174
175 Assert.assertEquals("There should be one existing time block.", 1, fredsDocument.getTimeBlocks().size());
176
177 DateTimeZone dateTimeZone = DateTimeZone.forID(HrServiceLocator.getTimezoneService().getUserTimezone(userId));
178 final DateTime start = new DateTime(2011, 3, 2, 13, 0, 0, 0, dateTimeZone);
179 final DateTime end = new DateTime(2011, 3, 2, 18, 0, 0, 0, dateTimeZone);
180 TimeDetailActionFormBase tdaf = TimeDetailTestUtils.buildDetailActionForm(fredsDocument, assignment, earnCode, start, end, null, false, null, true);
181
182 List<String> errors = TimeDetailTestUtils.setTimeBlockFormDetails(form, tdaf);
183 Assert.assertEquals("There should be no errors in this time detail submission", 0, errors.size());
184 String targetedTimesheetUrl = getTargetedTimesheetDocumentUrl(tdocId,"fred");
185 page = getWebClient().getPage(targetedTimesheetUrl);
186 Assert.assertNotNull(page);
187 String submitDetailsUrl = BASE_DETAIL_URL + tdocId;
188 page = TimeDetailTestUtils.submitTimeDetails(getWebClient(), submitDetailsUrl, tdaf);
189 Assert.assertNotNull(page);
190 HtmlUnitUtil.createTempFile(page, "initiatetest");
191 String dataText = page.getElementById("timeBlockString").getFirstChild().getNodeValue();
192 JSONArray jsonData = (JSONArray) JSONValue.parse(dataText);
193 final JSONObject jsonDataObject = (JSONObject) jsonData.get(1);
194 Assert.assertTrue("TimeBlock Data Missing.", checkJSONValues(new JSONObject() {{ put("outer", jsonDataObject); }},
195 new ArrayList<Map<String, Object>>() {{
196 add(new HashMap<String, Object>() {{
197 put("earnCode", "RGN");
198 put("hours", "5.0");
199 put("amount", null);
200 }});
201 }},
202 new HashMap<String, Object>() {{
203 put("earnCode", "RGN");
204 put("startNoTz", start.toString("yyyy-MM-dd'T'HH:mm:ss"));
205 put("endNoTz", end.toString("yyyy-MM-dd'T'HH:mm:ss"));
206 put("title", "SDR1 Work Area");
207 put("assignment", "30_30_30");
208 }}
209 ));
210 }
211
212 public void testInitiatedTimesheetNotEditable(String userId) throws Exception {
213
214 String tdocId = fredsDocument.getDocumentId();
215 HtmlPage page = loginAndGetTimeDetailsHtmlPage(getWebClient(), userId, tdocId, true);
216
217 Assert.assertTrue("Calendar not loaded.", page.asText().contains("March 2011"));
218
219 HtmlForm form = page.getFormByName("TimeDetailActionForm");
220 Assert.assertNotNull(form);
221 List<Assignment> assignments = HrServiceLocator.getAssignmentService().getAssignments("fred", JAN_AS_OF_DATE.toLocalDate());
222 Assignment assignment = assignments.get(0);
223
224 List<EarnCode> earnCodes = TkServiceLocator.getTimesheetService().getEarnCodesForTime(assignment, JAN_AS_OF_DATE.toLocalDate());
225 EarnCode earnCode = earnCodes.get(0);
226
227 Assert.assertEquals("There should be one existing time block.", 1, fredsDocument.getTimeBlocks().size());
228
229 DateTimeZone dateTimeZone = DateTimeZone.forID(HrServiceLocator.getTimezoneService().getUserTimezone(userId));
230 DateTime start = new DateTime(2011, 3, 4, 8, 0, 0, 0, dateTimeZone);
231 DateTime end = new DateTime(2011, 3, 4, 13, 0, 0, 0, dateTimeZone);
232 TimeDetailActionFormBase tdaf = TimeDetailTestUtils.buildDetailActionForm(fredsDocument, assignment, earnCode, start, end, null, false, null, true);
233 List<String> errors = TimeDetailTestUtils.setTimeBlockFormDetails(form, tdaf);
234 Assert.assertEquals("There should be no errors in this time detail submission", 0, errors.size());
235 page = TimeDetailTestUtils.submitTimeDetails(getWebClient(), userId, getTimesheetDocumentUrl(tdocId), tdaf);
236 Assert.assertNotNull(page);
237 HtmlUnitUtil.createTempFile(page, "aftertdadd");
238 Assert.assertTrue("Should not have access", page.asText().contains("You are not authorized to access this portion of the application."));
239 }
240
241 @Test
242 public void testInitiatedTimesheetIsEditableByAdmin() throws Exception {
243 testInitiatedTimesheetEditable("admin");
244 }
245
246 @Test
247 public void testInitiatedTimesheetIsEditableByApprover() throws Exception {
248 testInitiatedTimesheetEditable("fran");
249 }
250
251 @Test
252 public void testInitiatedTimesheetIsEditableByReviewer() throws Exception {
253 testInitiatedTimesheetEditable("frank");
254 }
255
256 @Test
257 public void testInitiatedTimesheetIs_NOT_EditableByViewOnly() throws Exception {
258 testInitiatedTimesheetNotEditable("edna");
259 }
260
261 @Test
262 public void testInitiatedTimesheetIs_NOT_EditableByDeptAdmin() throws Exception {
263 testInitiatedTimesheetNotEditable("testuser6");
264 }
265
266
267 @Test
268 public void testInitiatedTimesheetSubmitUser() throws Exception {
269
270
271
272 }
273
274 @Test
275 public void testInitiatedTimesheetSubmitAdmin() throws Exception {
276
277
278
279 }
280
281 @Test
282 public void testInitiatedTimesheetSubmitApprover() throws Exception {
283
284
285
286 }
287
288
289 @Test
290 public void testInitiatedTimesheetIs_NOT_SubmittableByUsers() throws Exception {
291
292
293 }
294
295
296
297
298
299 @Test
300 public void testEnrouteTimesheetIsVisibleByAll() throws Exception {
301
302 }
303
304 @Test
305 public void testEnrouteTimesheetIsNotVisible() throws Exception {
306
307 }
308
309 @Test
310 public void testEnrouteTimesheetIsEditableByAdmin() throws Exception {
311
312 }
313
314 @Test
315 public void testEnrouteTimesheetIsEditableByApprover() throws Exception {
316
317 }
318
319 @Test
320 public void testEnrouteTimesheetIsEditableByReviewer() throws Exception {
321
322 }
323
324 @Test
325 public void testEnrouteTimesheetIs_NOT_EditableByViewOnly() throws Exception {
326 }
327
328 @Test
329 public void testEnrouteTimesheetIs_NOT_EditableByDeptAdmin() throws Exception {
330 }
331
332
333 @Test
334 public void testEnrouteTimesheet_NOT_Approvable() throws Exception {
335
336
337 }
338
339 @Test
340 public void testEnrouteTimesheetApproveAdmin() throws Exception {
341
342
343
344 }
345
346 @Test
347 public void testEnrouteTimesheetApproveApprover() throws Exception {
348
349
350
351 }
352
353 @Test
354 public void testEnrouteTimesheetIs_NOT_SubmittableByUsers() throws Exception {
355
356
357 }
358
359
360
361
362
363
364 @Test
365 public void testFinalTimesheetIsVisibleByAll() throws Exception {
366
367 }
368
369 @Test
370 public void testFinalTimesheetIsNotVisible() throws Exception {
371
372 }
373
374 @Test
375 public void testFinalTimesheetIsNotEditable() throws Exception {
376
377 }
378
379 @Test
380 public void testFinalTimesheetIsAdminEditable() throws Exception {
381
382 }
383
384
385
386
387 private void verifyLogins(TimesheetDocument tdoc) throws Exception {
388 for (String userId : VALID_NON_ENTRY_USERS) {
389 String tdocId = tdoc.getDocumentId();
390 HtmlPage page = loginAndGetTimeDetailsHtmlPage(getWebClient(), userId, tdocId, true);
391 Assert.assertTrue("Calendar not loaded.", page.asText().contains("March 2011"));
392 }
393 }
394
395 }