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 java.math.BigDecimal;
19 import java.util.ArrayList;
20 import java.util.HashMap;
21 import java.util.List;
22 import java.util.Map;
23
24 import org.joda.time.DateTime;
25 import org.json.simple.JSONObject;
26 import org.json.simple.JSONValue;
27 import org.junit.Assert;
28 import org.junit.Test;
29 import org.kuali.hr.time.util.TimeDetailTestUtils;
30 import org.kuali.hr.time.workflow.TimesheetWebTestBase;
31 import org.kuali.hr.util.HtmlUnitUtil;
32 import org.kuali.kpme.core.FunctionalTest;
33 import org.kuali.kpme.core.api.assignment.Assignment;
34 import org.kuali.kpme.core.api.calendar.entry.CalendarEntry;
35 import org.kuali.kpme.core.api.earncode.EarnCode;
36 import org.kuali.kpme.core.service.HrServiceLocator;
37 import org.kuali.kpme.core.util.HrContext;
38 import org.kuali.kpme.core.util.HrTestConstants;
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.rules.overtime.daily.DailyOvertimeRule;
42 import org.kuali.kpme.tklm.time.service.TkServiceLocator;
43 import org.kuali.kpme.tklm.time.timesheet.TimesheetDocument;
44 import org.kuali.kpme.tklm.utils.TkTestConstants;
45
46 import com.gargoylesoftware.htmlunit.html.HtmlForm;
47 import com.gargoylesoftware.htmlunit.html.HtmlPage;
48
49
50
51
52
53
54 @FunctionalTest
55 public class DOTIntegrationConfluenceTests extends TimesheetWebTestBase {
56
57 @Test
58
59
60
61
62
63
64
65
66 public void testKPME788_789() throws Exception {
67 Long jobNumber = 30L;
68 Long workArea = 30L;
69 Long task = 30L;
70 DailyOvertimeRule rule = createDailyOvertimeRule("IU-IN", "REG", "OVT",
71
72 "BW", "TEST-DEPT", workArea, task, new BigDecimal(8), new BigDecimal("9.00"), null);
73 String tdocId = KPME788_789(
74 new ArrayList<Map<String, Object>>() {{
75 add(new HashMap<String, Object>() {{
76 put("earnCode", "RGN");
77 put("hours", "5.0");
78 }});
79 }},
80 new HashMap<String, Object>() {{
81 put("earnCode", "RGN");
82 put("startNoTz", "2011-03-02T08:00:00");
83 put("endNoTz", "2011-03-02T13:00:00");
84 put("title", "SDR1 Work Area");
85 put("assignment", "IU-BL_30_30_30");
86 }},
87 new ArrayList<Map<String, Object>>() {{
88 add(new HashMap<String, Object>() {{
89 put("earnCode", "RGN");
90 put("hours", "5.0");
91 }});
92 }},
93 new HashMap<String, Object>() {{
94 put("earnCode", "RGN");
95 put("startNoTz", "2011-03-02T13:10:00");
96 put("endNoTz", "2011-03-02T18:10:00");
97 put("title", "SDR1 Work Area");
98 put("assignment", "IU-BL_30_30_30");
99 }}
100 );
101 deleteTimesheet(tdocId);
102
103 createDailyOvertimeRule("IN-IU", "REG", "OVT",
104
105 "BW", "TEST-DEPT", workArea, task, new BigDecimal(8), new BigDecimal("10.00"), null);
106 tdocId = KPME788_789(
107 new ArrayList<Map<String, Object>>() {{
108 add(new HashMap<String, Object>() {{
109 put("earnCode", "RGN");
110 put("hours", "5.0");
111 }});
112 }},
113 new HashMap<String, Object>() {{
114 put("earnCode", "RGN");
115 put("startNoTz", "2011-03-02T08:00:00");
116 put("endNoTz", "2011-03-02T13:00:00");
117 put("title", "SDR1 Work Area");
118 put("assignment", "IU-BL_30_30_30");
119 }},
120 new ArrayList<Map<String, Object>>() {{
121 add(new HashMap<String, Object>() {{
122 put("earnCode", "RGN");
123 put("hours", "3.0");
124 put("earnCode", "OVT");
125 put("hours", "2.0");
126 }});
127 }},
128 new HashMap<String, Object>() {{
129 put("earnCode", "RGN");
130 put("startNoTz", "2011-03-02T13:10:00");
131 put("endNoTz", "2011-03-02T18:10:00");
132 put("title", "SDR1 Work Area");
133 put("assignment", "IU-BL_30_30_30");
134 }}
135 );
136 deleteTimesheet(tdocId);
137 }
138
139
140 public void deleteTimesheet(String tdocId) throws Exception {
141 HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), HrTestConstants.Urls.PORTAL_URL);
142 Assert.assertNotNull(page);
143 page = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), TkTestConstants.Urls.DELETE_TIMESHEET_URL + "?deleteDocumentId="+tdocId);
144 HtmlUnitUtil.createTempFile(page, "Deleted");
145 }
146
147 public String KPME788_789(ArrayList<Map<String, Object>> tb1ThdItems, HashMap<String, Object> tb1Items, ArrayList<Map<String, Object>> tb2ThdItems, HashMap<String, Object> tb2Items) throws Exception {
148 DateTime asOfDate = new DateTime(2011, 3, 1, 12, 0, 0, 0, TKUtils.getSystemDateTimeZone());
149 CalendarEntry pcd = HrServiceLocator.getCalendarEntryService().getCurrentCalendarDates(USER_PRINCIPAL_ID, asOfDate);
150 Assert.assertNotNull("No PayCalendarDates", pcd);
151
152 TimesheetDocument tdoc = TkServiceLocator.getTimesheetService().openTimesheetDocument(USER_PRINCIPAL_ID, pcd);
153 String tdocId = tdoc.getDocumentId();
154 HtmlPage page = loginAndGetTimeDetailsHtmlPage(getWebClient(), "admin", tdocId, true);
155 Assert.assertNotNull(page);
156 HtmlForm form = page.getFormByName("TimeDetailActionForm");
157 Assert.assertNotNull(form);
158
159 List<Assignment> assignments = HrServiceLocator.getAssignmentService().getAssignments(HrContext.getPrincipalId(), JAN_AS_OF_DATE.toLocalDate());
160 Assignment assignment = assignments.get(0);
161
162 List<EarnCode> earnCodes = TkServiceLocator.getTimesheetService().getEarnCodesForTime(assignment, JAN_AS_OF_DATE.toLocalDate());
163 EarnCode earnCode = earnCodes.get(0);
164 Assert.assertEquals("There should be no existing time blocks.", 0, tdoc.getTimeBlocks().size());
165
166
167
168
169 DateTime start = new DateTime(2011, 3, 2, 8, 0, 0, 0, TKUtils.getSystemDateTimeZone());
170 DateTime end = new DateTime(2011, 3, 2, 13, 0, 0, 0, TKUtils.getSystemDateTimeZone());
171 TimeDetailActionFormBase tdaf = TimeDetailTestUtils.buildDetailActionForm(tdoc, assignment, earnCode, start, end, null, false, null, true, null, null, null, null, null, null);
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(getWebClient(), getTimesheetDocumentUrl(tdocId), tdaf);
175 Assert.assertNotNull(page);
176
177 start = new DateTime(2011, 3, 2, 13, 10, 0, 0, TKUtils.getSystemDateTimeZone());
178 end = new DateTime(2011, 3, 2, 18, 10, 0, 0, TKUtils.getSystemDateTimeZone());
179 tdaf = TimeDetailTestUtils.buildDetailActionForm(tdoc, assignment, earnCode, start, end, null, false, null, true, null, null, null, null, null, null);
180 errors = TimeDetailTestUtils.setTimeBlockFormDetails(form, tdaf);
181 Assert.assertEquals("There should be no errors in this time detail submission", 0, errors.size());
182 page = TimeDetailTestUtils.submitTimeDetails(getWebClient(), getTimesheetDocumentUrl(tdocId), tdaf);
183 HtmlUnitUtil.createTempFile(page, "Hours");
184 Assert.assertNotNull(page);
185
186
187 String pageAsText = page.asText();
188
189
190 String dataText = page.getElementById("timeBlockString").getFirstChild().getNodeValue();
191 JSONObject jsonData = (JSONObject) JSONValue.parse(dataText);
192 Assert.assertTrue("TimeBlock #1 Data Missing.", checkJSONValues(jsonData, tb1ThdItems, tb1Items));
193 Assert.assertTrue("TimeBlock #2 Data Missing.", checkJSONValues(jsonData, tb2ThdItems, tb2Items));
194
195 return tdocId;
196 }
197
198 private DailyOvertimeRule createDailyOvertimeRule(String groupKeyCode, String fromEarnGroup, String earnCode,
199
200 String paytype, String dept, Long workArea, Long task, BigDecimal minHours, BigDecimal maxGap, String overtimePref) {
201 DailyOvertimeRule rule = new DailyOvertimeRule();
202
203 rule.setGroupKeyCode("IU-IN");
204 rule.setEffectiveLocalDate(JAN_AS_OF_DATE.toLocalDate());
205 rule.setFromEarnGroup(fromEarnGroup);
206 rule.setEarnCode(earnCode);
207
208 rule.setPaytype(paytype);
209 rule.setDept(dept);
210 rule.setWorkArea(workArea);
211 rule.setMaxGap(maxGap);
212 rule.setMinHours(minHours);
213 rule.setActive(true);
214 TkServiceLocator.getDailyOvertimeRuleService().saveOrUpdate(rule);
215 return rule;
216 }
217 }