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