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.assignment.Assignment;
34 import org.kuali.kpme.core.calendar.entry.CalendarEntry;
35 import org.kuali.kpme.core.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("REG", "OVT", "SD1", "BW", "TEST-DEPT", workArea, task, new BigDecimal(8), new BigDecimal("9.00"), null);
71 String tdocId = KPME788_789(
72 new ArrayList<Map<String, Object>>() {{
73 add(new HashMap<String, Object>() {{
74 put("earnCode", "RGN");
75 put("hours", "5.0");
76 }});
77 }},
78 new HashMap<String, Object>() {{
79 put("earnCode", "RGN");
80 put("startNoTz", "2011-03-02T08:00:00");
81 put("endNoTz", "2011-03-02T13:00:00");
82 put("title", "SDR1 Work Area");
83 put("assignment", "30_30_30");
84 }},
85 new ArrayList<Map<String, Object>>() {{
86 add(new HashMap<String, Object>() {{
87 put("earnCode", "RGN");
88 put("hours", "5.0");
89 }});
90 }},
91 new HashMap<String, Object>() {{
92 put("earnCode", "RGN");
93 put("startNoTz", "2011-03-02T13:10:00");
94 put("endNoTz", "2011-03-02T18:10:00");
95 put("title", "SDR1 Work Area");
96 put("assignment", "30_30_30");
97 }}
98 );
99 deleteTimesheet(tdocId);
100
101 createDailyOvertimeRule("REG", "OVT", "SD1", "BW", "TEST-DEPT", workArea, task, new BigDecimal(8), new BigDecimal("10.00"), null);
102 tdocId = KPME788_789(
103 new ArrayList<Map<String, Object>>() {{
104 add(new HashMap<String, Object>() {{
105 put("earnCode", "RGN");
106 put("hours", "5.0");
107 }});
108 }},
109 new HashMap<String, Object>() {{
110 put("earnCode", "RGN");
111 put("startNoTz", "2011-03-02T08:00:00");
112 put("endNoTz", "2011-03-02T13:00:00");
113 put("title", "SDR1 Work Area");
114 put("assignment", "30_30_30");
115 }},
116 new ArrayList<Map<String, Object>>() {{
117 add(new HashMap<String, Object>() {{
118 put("earnCode", "RGN");
119 put("hours", "3.0");
120 put("earnCode", "OVT");
121 put("hours", "2.0");
122 }});
123 }},
124 new HashMap<String, Object>() {{
125 put("earnCode", "RGN");
126 put("startNoTz", "2011-03-02T13:10:00");
127 put("endNoTz", "2011-03-02T18:10:00");
128 put("title", "SDR1 Work Area");
129 put("assignment", "30_30_30");
130 }}
131 );
132 deleteTimesheet(tdocId);
133 }
134
135
136 public void deleteTimesheet(String tdocId) throws Exception {
137 HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), HrTestConstants.Urls.PORTAL_URL);
138 Assert.assertNotNull(page);
139 page = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), TkTestConstants.Urls.DELETE_TIMESHEET_URL + "?deleteDocumentId="+tdocId);
140 HtmlUnitUtil.createTempFile(page, "Deleted");
141 }
142
143 public String KPME788_789(ArrayList<Map<String, Object>> tb1ThdItems, HashMap<String, Object> tb1Items, ArrayList<Map<String, Object>> tb2ThdItems, HashMap<String, Object> tb2Items) throws Exception {
144 DateTime asOfDate = new DateTime(2011, 3, 1, 12, 0, 0, 0, TKUtils.getSystemDateTimeZone());
145 CalendarEntry pcd = HrServiceLocator.getCalendarEntryService().getCurrentCalendarDates(USER_PRINCIPAL_ID, asOfDate);
146 Assert.assertNotNull("No PayCalendarDates", pcd);
147
148 TimesheetDocument tdoc = TkServiceLocator.getTimesheetService().openTimesheetDocument(USER_PRINCIPAL_ID, pcd);
149 String tdocId = tdoc.getDocumentId();
150 HtmlPage page = loginAndGetTimeDetailsHtmlPage(getWebClient(), "admin", tdocId, true);
151 Assert.assertNotNull(page);
152 HtmlForm form = page.getFormByName("TimeDetailActionForm");
153 Assert.assertNotNull(form);
154
155 List<Assignment> assignments = HrServiceLocator.getAssignmentService().getAssignments(HrContext.getPrincipalId(), JAN_AS_OF_DATE.toLocalDate());
156 Assignment assignment = assignments.get(0);
157
158 List<EarnCode> earnCodes = TkServiceLocator.getTimesheetService().getEarnCodesForTime(assignment, JAN_AS_OF_DATE.toLocalDate());
159 EarnCode earnCode = earnCodes.get(0);
160 Assert.assertEquals("There should be no existing time blocks.", 0, tdoc.getTimeBlocks().size());
161
162
163
164
165 DateTime start = new DateTime(2011, 3, 2, 8, 0, 0, 0, TKUtils.getSystemDateTimeZone());
166 DateTime end = new DateTime(2011, 3, 2, 13, 0, 0, 0, TKUtils.getSystemDateTimeZone());
167 TimeDetailActionFormBase tdaf = TimeDetailTestUtils.buildDetailActionForm(tdoc, assignment, earnCode, start, end, null, false, null, true);
168 List<String> errors = TimeDetailTestUtils.setTimeBlockFormDetails(form, tdaf);
169 Assert.assertEquals("There should be no errors in this time detail submission", 0, errors.size());
170 page = TimeDetailTestUtils.submitTimeDetails(getWebClient(), getTimesheetDocumentUrl(tdocId), tdaf);
171 Assert.assertNotNull(page);
172
173 start = new DateTime(2011, 3, 2, 13, 10, 0, 0, TKUtils.getSystemDateTimeZone());
174 end = new DateTime(2011, 3, 2, 18, 10, 0, 0, TKUtils.getSystemDateTimeZone());
175 tdaf = TimeDetailTestUtils.buildDetailActionForm(tdoc, assignment, earnCode, start, end, null, false, null, true);
176 errors = TimeDetailTestUtils.setTimeBlockFormDetails(form, tdaf);
177 Assert.assertEquals("There should be no errors in this time detail submission", 0, errors.size());
178 page = TimeDetailTestUtils.submitTimeDetails(getWebClient(), getTimesheetDocumentUrl(tdocId), tdaf);
179 HtmlUnitUtil.createTempFile(page, "Hours");
180 Assert.assertNotNull(page);
181
182
183 String pageAsText = page.asText();
184
185
186 String dataText = page.getElementById("timeBlockString").getFirstChild().getNodeValue();
187 JSONObject jsonData = (JSONObject) JSONValue.parse(dataText);
188 Assert.assertTrue("TimeBlock #1 Data Missing.", checkJSONValues(jsonData, tb1ThdItems, tb1Items));
189 Assert.assertTrue("TimeBlock #2 Data Missing.", checkJSONValues(jsonData, tb2ThdItems, tb2Items));
190
191 return tdocId;
192 }
193
194 private DailyOvertimeRule createDailyOvertimeRule(String fromEarnGroup, String earnCode, String location, String paytype, String dept, Long workArea, Long task, BigDecimal minHours, BigDecimal maxGap, String overtimePref) {
195 DailyOvertimeRule rule = new DailyOvertimeRule();
196 rule.setEffectiveLocalDate(JAN_AS_OF_DATE.toLocalDate());
197 rule.setFromEarnGroup(fromEarnGroup);
198 rule.setEarnCode(earnCode);
199 rule.setLocation(location);
200 rule.setPaytype(paytype);
201 rule.setDept(dept);
202 rule.setWorkArea(workArea);
203 rule.setMaxGap(maxGap);
204 rule.setMinHours(minHours);
205 rule.setActive(true);
206 TkServiceLocator.getDailyOvertimeRuleService().saveOrUpdate(rule);
207 return rule;
208 }
209 }