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