1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.time.overtime.daily.rule.service;
17
18 import java.math.BigDecimal;
19 import java.util.ArrayList;
20 import java.util.HashMap;
21 import java.util.List;
22
23 import org.joda.time.DateTime;
24 import org.junit.Assert;
25 import org.junit.Test;
26 import org.kuali.hr.KPMEWebTestCase;
27 import org.kuali.kpme.core.FunctionalTest;
28 import org.kuali.kpme.core.calendar.entry.CalendarEntry;
29 import org.kuali.kpme.core.service.HrServiceLocator;
30 import org.kuali.kpme.core.util.TKUtils;
31 import org.kuali.kpme.tklm.time.rules.overtime.daily.DailyOvertimeRule;
32 import org.kuali.kpme.tklm.time.rules.overtime.daily.service.DailyOvertimeRuleService;
33 import org.kuali.kpme.tklm.time.service.TkServiceLocator;
34 import org.kuali.kpme.tklm.time.timeblock.TimeBlock;
35 import org.kuali.kpme.tklm.time.timesheet.TimesheetDocument;
36 import org.kuali.kpme.tklm.time.util.TkTimeBlockAggregate;
37 import org.kuali.kpme.tklm.utils.TkTestUtils;
38
39 @FunctionalTest
40 public class DailyOvertimeRuleServiceTest extends KPMEWebTestCase {
41
42 public static final String USER_PRINCIPAL_ID = "admin";
43 private DateTime JAN_AS_OF_DATE = new DateTime(2010, 1, 1, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone());
44
45
46 private void createDailyOvertimeRule(String fromEarnGroup, String earnCode, String location, String paytype, String dept, Long workArea, Long task, BigDecimal minHours, BigDecimal maxGap, String overtimePref) {
47 DailyOvertimeRuleService service = TkServiceLocator.getDailyOvertimeRuleService();
48 DailyOvertimeRule rule = new DailyOvertimeRule();
49
50 rule.setEffectiveLocalDate(JAN_AS_OF_DATE.toLocalDate());
51 rule.setFromEarnGroup(fromEarnGroup);
52 rule.setEarnCode(earnCode);
53 rule.setLocation(location);
54 rule.setPaytype(paytype);
55 rule.setDept(dept);
56 rule.setWorkArea(workArea);
57 rule.setMaxGap(maxGap);
58 rule.setMinHours(minHours);
59 rule.setActive(true);
60
61 service.saveOrUpdate(rule);
62 }
63
64
65 @SuppressWarnings("serial")
66 @Test
67 public void testDailyOvertimeGapExceeded() throws Exception {
68 Long jobNumber = 30L;
69 Long workArea = 30L;
70 Long task = 30L;
71 createDailyOvertimeRule("REG", "OVT", "SD1", "BW", "TEST-DEPT", workArea,
72 task, new BigDecimal(8), new BigDecimal("0.10"), null);
73
74
75 DateTime start = new DateTime(2010, 3, 29, 14, 0, 0, 0, TKUtils.getSystemDateTimeZone());
76 List<TimeBlock> blocks = new ArrayList<TimeBlock>();
77 CalendarEntry payCalendarEntry = HrServiceLocator.getCalendarEntryService().getCurrentCalendarDates("admin", start);
78 blocks.addAll(TkTestUtils.createUniformTimeBlocks(start, 2, new BigDecimal("4"), "REG", jobNumber, workArea, task));
79 blocks.addAll(TkTestUtils.createUniformTimeBlocks(start.plusHours(4).plusMinutes(15), 2, new BigDecimal("5"), "REG", jobNumber, workArea, task));
80 TkTimeBlockAggregate aggregate = new TkTimeBlockAggregate(blocks, payCalendarEntry);
81
82
83 TkTestUtils.verifyAggregateHourSums("Pre-Check", new HashMap<String,BigDecimal>() {{put("OVT", BigDecimal.ZERO);put("REG", new BigDecimal(18));}},aggregate,2);
84
85
86 TimesheetDocument tdoc = TkTestUtils.populateBlankTimesheetDocument(start, "admin");
87 tdoc.setTimeBlocks(blocks);
88 TkServiceLocator.getDailyOvertimeRuleService().processDailyOvertimeRules(tdoc, aggregate);
89
90
91 TkTestUtils.verifyAggregateHourSums("Post Rules Check", new HashMap<String,BigDecimal>() {{put("OVT", new BigDecimal(0));put("REG", new BigDecimal(18));}},aggregate,2);
92 }
93
94
95 @SuppressWarnings("serial")
96 @Test
97 public void testDailyOvertimeSimpleCase() throws Exception {
98 Long jobNumber = 30L;
99 Long workArea = 30L;
100 Long task = 30L;
101 createDailyOvertimeRule("REG", "OVT", "SD1", "BW", "TEST-DEPT", workArea,
102 task, new BigDecimal(8), new BigDecimal("15.0"), null);
103
104
105
106 DateTime start = new DateTime(2010, 3, 29, 14, 0, 0, 0, TKUtils.getSystemDateTimeZone());
107 List<TimeBlock> blocks = new ArrayList<TimeBlock>();
108 CalendarEntry payCalendarEntry = HrServiceLocator.getCalendarEntryService().getCurrentCalendarDates("admin", start);
109 blocks.addAll(TkTestUtils.createUniformTimeBlocks(start, 2, new BigDecimal("4"), "REG", jobNumber, workArea, task));
110 blocks.addAll(TkTestUtils.createUniformTimeBlocks(start.plusHours(4).plusMinutes(15), 2, new BigDecimal("5"), "REG", jobNumber, workArea, task));
111 TkTimeBlockAggregate aggregate = new TkTimeBlockAggregate(blocks, payCalendarEntry);
112
113
114 TkTestUtils.verifyAggregateHourSums("Pre-Check", new HashMap<String,BigDecimal>() {{put("OVT", BigDecimal.ZERO);put("REG", new BigDecimal(18));}},aggregate,2);
115
116
117 TimesheetDocument tdoc = TkTestUtils.populateBlankTimesheetDocument(start, "admin");
118 tdoc.setTimeBlocks(blocks);
119 TkServiceLocator.getDailyOvertimeRuleService().processDailyOvertimeRules(tdoc, aggregate);
120
121
122 TkTestUtils.verifyAggregateHourSums("Post Rules Check", new HashMap<String,BigDecimal>() {{put("OVT", new BigDecimal(2));put("REG", new BigDecimal(16));}},aggregate,2);
123 }
124
125 @Test
126 public void testRuleCreationAndRetrieval() throws Exception {
127 Long workArea = 0L;
128 Long task = 30L;
129 createDailyOvertimeRule("REG", "OVT", "SD1", "BW", "TEST-DEPT", workArea,
130 task, new BigDecimal(8), new BigDecimal("0.25"), null);
131 DailyOvertimeRule rule = TkServiceLocator.getDailyOvertimeRuleService().getDailyOvertimeRule("SD1", "BW", "TEST-DEPT", workArea, JAN_AS_OF_DATE.toLocalDate());
132 Assert.assertNotNull("Rule not created.", rule);
133 }
134
135 @Test
136 public void testSearchDailyOvertimeRules() throws Exception {
137 createDailyOvertimeRule("REG", "OVT", "SD1", "BL", "TEST-DEPT", 30L, 30L, new BigDecimal(8), new BigDecimal("0.10"), null);
138 createDailyOvertimeRule("REG", "OVT", "SD1", "BL", "TEST-DEPT5", 5555L, 30L, new BigDecimal(8), new BigDecimal("0.10"), null);
139
140 List<DailyOvertimeRule> allResults = TkServiceLocator.getDailyOvertimeRuleService().getDailyOvertimeRules("admin", null, null, null, null, null, "Y", "N");
141 Assert.assertEquals("Search returned the wrong number of results.", 2, allResults.size());
142
143 List<DailyOvertimeRule> restrictedResults = TkServiceLocator.getDailyOvertimeRuleService().getDailyOvertimeRules("fran", null, null, null, null, null, "Y", "N");
144 Assert.assertEquals("Search returned the wrong number of results.", 0, restrictedResults.size());
145 }
146
147 }