1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.time.overtime.web;
17
18 import java.sql.Date;
19 import java.util.*;
20
21 import org.joda.time.DateTime;
22 import org.json.simple.JSONArray;
23 import org.json.simple.JSONObject;
24 import org.json.simple.JSONValue;
25 import org.junit.Assert;
26 import org.junit.Test;
27 import org.kuali.hr.time.assignment.Assignment;
28 import org.kuali.hr.time.calendar.CalendarEntries;
29 import org.kuali.hr.time.detail.web.TimeDetailActionFormBase;
30 import org.kuali.hr.time.earncode.EarnCode;
31 import org.kuali.hr.time.service.base.TkServiceLocator;
32 import org.kuali.hr.time.timesheet.TimesheetDocument;
33 import org.kuali.hr.time.timesheet.web.TimesheetWebTestBase;
34 import org.kuali.hr.time.util.*;
35
36 import com.gargoylesoftware.htmlunit.html.HtmlForm;
37 import com.gargoylesoftware.htmlunit.html.HtmlPage;
38
39 public class DailyOvertimeWebIntegrationTest extends TimesheetWebTestBase {
40
41 public static final String USER_PRINCIPAL_ID = "admin";
42 private Date JAN_AS_OF_DATE = new Date((new DateTime(2010, 1, 1, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone())).getMillis());
43
44 @Test
45
46
47
48
49
50
51 public void testSimpleDOTCalculationIntegration() throws Exception {
52 Date asOfDate = new Date((new DateTime(2011, 3, 1, 12, 0, 0, 0, TKUtils.getSystemDateTimeZone())).getMillis());
53
54 CalendarEntries pcd = TkServiceLocator.getCalendarService().getCurrentCalendarDates(USER_PRINCIPAL_ID, asOfDate);
55 Assert.assertNotNull("No PayCalendarDates", pcd);
56
57 TimesheetDocument tdoc = TkServiceLocator.getTimesheetService().openTimesheetDocument(USER_PRINCIPAL_ID, pcd);
58 String tdocId = tdoc.getDocumentId();
59 HtmlPage page = loginAndGetTimeDetailsHtmlPage("admin", tdocId,true);
60 Assert.assertNotNull(page);
61 HtmlForm form = page.getFormByName("TimeDetailActionForm");
62 Assert.assertNotNull(form);
63
64
65 List<Assignment> assignments = TkServiceLocator.getAssignmentService().getAssignments(TKContext.getPrincipalId(), JAN_AS_OF_DATE);
66 Assignment assignment = assignments.get(0);
67 List<EarnCode> earnCodes = TkServiceLocator.getEarnCodeService().getEarnCodes(assignment, JAN_AS_OF_DATE);
68 EarnCode earnCode = earnCodes.get(0);
69 Assert.assertEquals("There should be no existing time blocks.", 0, tdoc.getTimeBlocks().size());
70
71
72
73
74 DateTime start = new DateTime(2011, 3, 2, 8, 0, 0, 0, TKUtils.getSystemDateTimeZone());
75 DateTime end = new DateTime(2011, 3, 3, 18, 0, 0, 0, TKUtils.getSystemDateTimeZone());
76
77
78
79 TimeDetailActionFormBase tdaf = TimeDetailTestUtils.buildDetailActionForm(tdoc, assignment, earnCode, start, end, null, true, null, true);
80 List<String> errors = TimeDetailTestUtils.setTimeBlockFormDetails(form, tdaf);
81
82 Assert.assertEquals("There should be no errors in this time detail submission", 0, errors.size());
83
84 page = TimeDetailTestUtils.submitTimeDetails(getTimesheetDocumentUrl(tdocId), tdaf);
85 Assert.assertNotNull(page);
86
87
88
89 String pageAsText = page.asText();
90
91
92
93
94
95
96 String dataText = page.getElementById("timeBlockString").getFirstChild().getNodeValue();
97 JSONArray jsonData = (JSONArray) JSONValue.parse(dataText);
98 final JSONObject jsonDataObject = (JSONObject) jsonData.get(0);
99 Assert.assertTrue("TimeBlock #1 Data Missing.", checkJSONValues(new JSONObject() {{ put("outer", jsonDataObject); }},
100 new ArrayList<Map<String, Object>>() {{
101 add(new HashMap<String, Object>() {{
102 put("earnCode", "RGN");
103 put("hours", "8.0");
104 }});
105 add(new HashMap<String, Object>() {{
106 put("earnCode", "OVT");
107 put("hours", "2.0");
108 }});
109 }},
110 new HashMap<String, Object>() {{
111 put("earnCode", "RGN");
112 put("startNoTz", "2011-03-02T08:00:00");
113 put("endNoTz", "2011-03-02T18:00:00");
114 put("title", "SDR1 Work Area");
115 put("assignment", "30_30_30");
116 }}
117 ));
118 final JSONObject jsonDataObject2 = (JSONObject) jsonData.get(1);
119 Assert.assertTrue("TimeBlock #2 Data Missing.", checkJSONValues(new JSONObject() {{ put("outer", jsonDataObject2); }},
120 new ArrayList<Map<String, Object>>() {{
121 add(new HashMap<String, Object>() {{
122 put("earnCode", "RGN");
123 put("hours", "8.0");
124 }});
125 add(new HashMap<String, Object>() {{
126 put("earnCode", "OVT");
127 put("hours", "2.0");
128 }});
129 }},
130 new HashMap<String, Object>() {{
131 put("earnCode", "RGN");
132 put("startNoTz", "2011-03-03T08:00:00");
133 put("endNoTz", "2011-03-03T18:00:00");
134 put("title", "SDR1 Work Area");
135 put("assignment", "30_30_30");
136 }}
137 ));
138
139
140
141
142 Assert.assertTrue("TimeBlock not Present.", pageAsText.contains("08:00 AM - 06:00 PM"));
143 Assert.assertTrue("TimeBlock not Present.", pageAsText.contains("RGN - 8.00 hours"));
144 Assert.assertTrue("TimeBlock not Present.", pageAsText.contains("OVT - 2.00 hours"));
145 }
146
147 }