1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.time.shiftdiff.rule;
17
18 import com.google.common.collect.ImmutableMap;
19 import org.joda.time.DateTime;
20 import org.joda.time.DateTimeZone;
21 import org.joda.time.LocalTime;
22 import org.junit.Assert;
23 import org.junit.Ignore;
24 import org.junit.Test;
25 import org.kuali.hr.KPMEWebTestCase;
26 import org.kuali.kpme.core.FunctionalTest;
27 import org.kuali.kpme.core.api.assignment.Assignment;
28 import org.kuali.kpme.core.api.assignment.AssignmentDescriptionKey;
29 import org.kuali.kpme.core.api.calendar.entry.CalendarEntry;
30 import org.kuali.kpme.core.calendar.CalendarBo;
31 import org.kuali.kpme.core.service.HrServiceLocator;
32 import org.kuali.kpme.core.util.HrContext;
33 import org.kuali.kpme.core.util.TKUtils;
34 import org.kuali.kpme.tklm.api.leave.block.LeaveBlock;
35 import org.kuali.kpme.tklm.api.time.timeblock.TimeBlock;
36 import org.kuali.kpme.tklm.time.rules.shiftdifferential.ShiftDifferentialRule;
37 import org.kuali.kpme.tklm.time.rules.shiftdifferential.service.ShiftDifferentialRuleService;
38 import org.kuali.kpme.tklm.time.service.TkServiceLocator;
39 import org.kuali.kpme.tklm.time.timesheet.TimesheetDocument;
40 import org.kuali.kpme.tklm.time.timesheet.TimesheetUtils;
41 import org.kuali.kpme.tklm.time.util.TkTimeBlockAggregate;
42 import org.kuali.kpme.tklm.utils.TkTestUtils;
43
44 import java.math.BigDecimal;
45 import java.sql.Time;
46 import java.util.ArrayList;
47 import java.util.HashMap;
48 import java.util.List;
49
50
51
52
53
54
55 @FunctionalTest
56 public class ShiftDifferentialRuleServiceProcessTest extends KPMEWebTestCase {
57
58
59 public static final String USER_PRINCIPAL_ID = "admin";
60 private DateTime JAN_AS_OF_DATE = new DateTime(2010, 1, 1, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone());
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115 @SuppressWarnings("serial")
116 @Test
117 public void testProcessTimesheetBoundaryCarryoverOverlapCase() throws Exception {
118 DateTimeZone tz = HrServiceLocator.getTimezoneService().getUserTimezoneWithFallback();
119
120 boolean[] dayArray = {false, false, true, true, true, true, true};
121
122 Long jobNumber = 30L;
123 Long workArea = 0L;
124 this.createShiftDifferentialRule(
125 "BWS-CAL", "REG", "PRM", "IN", "SD1", "SD1",
126 (new LocalTime(22, 0)),
127 (new LocalTime(4, 0)),
128 new BigDecimal(3),
129 new BigDecimal("15.00"),
130 dayArray);
131
132
133
134
135
136 DateTime beginPeriodDate = new DateTime(2010, 8, 15, 0, 0, 0, 0, tz);
137 CalendarEntry endOfAugust = HrServiceLocator.getCalendarEntryService().getCalendarEntryByIdAndPeriodEndDate("2", new DateTime(2010, 9, 1, 0, 0, 0, 0));
138 DateTime start = new DateTime(2010, 8, 31, 21, 45, 0, 0, tz);
139 List<TimeBlock> blocks = new ArrayList<TimeBlock>();
140 TimesheetDocument tdoc = TkServiceLocator.getTimesheetService().openTimesheetDocument("admin", endOfAugust);
141 Assignment assignment = HrServiceLocator.getAssignmentService().getAssignment("admin", AssignmentDescriptionKey.get("IU-IN_30_30_30"), beginPeriodDate.toLocalDate());
142 blocks.addAll(TkTestUtils.createUniformActualTimeBlocks(tdoc, assignment, "RGN", start, 1, new BigDecimal(2), BigDecimal.ZERO, "admin"));
143 TkTimeBlockAggregate aggregate = new TkTimeBlockAggregate(blocks, endOfAugust, HrServiceLocator.getCalendarService().getCalendar(endOfAugust.getHrCalendarId()), true);
144 tdoc.setTimeBlocks(blocks);
145 TkServiceLocator.getShiftDifferentialRuleService().processShiftDifferentialRules(tdoc, aggregate);
146 TkTestUtils.verifyAggregateHourSumsFlatList("August Pre-Check", new HashMap<String,BigDecimal>() {{put("PRM", BigDecimal.ZERO);put("RGN", new BigDecimal(2));}},aggregate);
147 TkServiceLocator.getTimeBlockService().saveOrUpdateTimeBlocks(new ArrayList<TimeBlock>(), aggregate.getFlattenedTimeBlockList(), "admin");
148
149
150
151
152 start = new DateTime(2010, 9, 1, 0, 0, 0, 0, tz);
153 CalendarEntry payCalendarEntry = HrServiceLocator.getCalendarEntryService().getCurrentCalendarDates("admin", start.toLocalDate().toDateTimeAtStartOfDay());
154 tdoc = TkServiceLocator.getTimesheetService().openTimesheetDocument("admin", payCalendarEntry);
155 blocks = new ArrayList<TimeBlock>();
156 blocks.addAll(TkTestUtils.createUniformTimeBlocks(start, 1, new BigDecimal("5"), "RGN", jobNumber, workArea));
157 blocks.addAll(TkTestUtils.createUniformTimeBlocks(start.plusHours(6), 1, new BigDecimal("6"), "RGN", jobNumber, workArea));
158 blocks.addAll(TkTestUtils.createUniformTimeBlocks(start.plusHours(22), 1, new BigDecimal("2"), "RGN", jobNumber, workArea));
159 blocks.addAll(TkTestUtils.createUniformTimeBlocks(start.plusDays(1), 1, new BigDecimal("1"), "RGN", jobNumber, workArea));
160 blocks.addAll(TkTestUtils.createUniformTimeBlocks(start.plusDays(1).plusHours(17), 1, new BigDecimal("6"), "RGN", jobNumber, workArea));
161 blocks = setDocumentIdOnBlocks(blocks, tdoc.getDocumentId());
162
163 aggregate = new TkTimeBlockAggregate(blocks, payCalendarEntry, HrServiceLocator.getCalendarService().getCalendar(payCalendarEntry.getHrCalendarId()), true);
164
165 TkTestUtils.verifyAggregateHourSumsFlatList("September Pre-Check", new HashMap<String,BigDecimal>() {{put("PRM", BigDecimal.ZERO);put("RGN", new BigDecimal(20));}},aggregate);
166
167
168 TkServiceLocator.getShiftDifferentialRuleService().processShiftDifferentialRules(tdoc, aggregate);
169 TkTestUtils.verifyAggregateHourSumsFlatList("September Post-Check", new HashMap<String,BigDecimal>() {{put("PRM", new BigDecimal("8.75"));put("RGN", new BigDecimal(22));}},aggregate);
170 }
171
172 private List<TimeBlock> setDocumentIdOnBlocks(List<TimeBlock> blocks, String id) {
173 List<TimeBlock> updatedTimeBlocks = new ArrayList<TimeBlock>();
174 for (TimeBlock b : blocks) {
175 TimeBlock.Builder builder = TimeBlock.Builder.create(b);
176 builder.setDocumentId(id);
177 updatedTimeBlocks.add(builder.build());
178 }
179 return updatedTimeBlocks;
180 }
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199 @SuppressWarnings("serial")
200 @Test
201 public void testProcessShiftTimesheeetBoundaryCarryoverCase() throws Exception {
202
203 boolean[] dayArray = {false, false, true, false, true, true, true};
204
205 Long jobNumber = 30L;
206 Long workArea = 0L;
207
208 DateTimeZone tz = HrServiceLocator.getTimezoneService().getTargetUserTimezoneWithFallback();
209 this.createShiftDifferentialRule(
210 "BWS-CAL",
211 "REG",
212 "PRM",
213 "IN",
214 "SD1",
215 "SD1",
216 (new LocalTime(22, 0)),
217 (new LocalTime(5, 0)),
218 new BigDecimal(3),
219 new BigDecimal("0.25"),
220 dayArray);
221
222
223 DateTime endPeriodDate = new DateTime(2010, 9, 1, 0, 0, 0, 0);
224 CalendarEntry endOfAugust = HrServiceLocator.getCalendarEntryService().getCalendarEntryByIdAndPeriodEndDate("2", endPeriodDate);
225 DateTime start = new DateTime(2010, 8, 31, 22, 0, 0, 0, tz);
226 List<TimeBlock> blocks = new ArrayList<TimeBlock>();
227 TimesheetDocument tdoc = TkServiceLocator.getTimesheetService().openTimesheetDocument("admin", endOfAugust);
228 Assignment assignment = HrServiceLocator.getAssignmentService().getAssignment("admin", AssignmentDescriptionKey.get("IU-IN_30_30_30"), endOfAugust.getBeginPeriodFullDateTime().toLocalDate());
229 blocks.addAll(TkTestUtils.createUniformActualTimeBlocks(tdoc, assignment, "RGN", start, 1, new BigDecimal(2), BigDecimal.ZERO, "admin"));
230 TkTimeBlockAggregate aggregate = new TkTimeBlockAggregate(blocks, endOfAugust, HrServiceLocator.getCalendarService().getCalendar(endOfAugust.getHrCalendarId()), true);
231
232
233
234 tdoc.setTimeBlocks(blocks);
235 TkServiceLocator.getShiftDifferentialRuleService().processShiftDifferentialRules(tdoc, aggregate);
236 TkTestUtils.verifyAggregateHourSumsFlatList("August Pre-Check", new HashMap<String,BigDecimal>() {{put("PRM", BigDecimal.ZERO);put("RGN", new BigDecimal(2));}},aggregate);
237 TkServiceLocator.getTimeBlockService().saveOrUpdateTimeBlocks(new ArrayList<TimeBlock>(), aggregate.getFlattenedTimeBlockList(), "admin");
238
239
240
241 start = new DateTime(2010, 9, 1, 0, 0, 0, 0, tz);
242 CalendarEntry payCalendarEntry = HrServiceLocator.getCalendarEntryService().getCurrentCalendarDates("admin", start.toLocalDate().toDateTimeAtStartOfDay());
243 tdoc = TkServiceLocator.getTimesheetService().openTimesheetDocument("admin", payCalendarEntry);
244 blocks = new ArrayList<TimeBlock>();
245 blocks.addAll(TkTestUtils.createUniformTimeBlocks(start, 1, new BigDecimal("5"), "RGN", jobNumber, workArea));
246 aggregate = new TkTimeBlockAggregate(blocks, payCalendarEntry, HrServiceLocator.getCalendarService().getCalendar(payCalendarEntry.getHrCalendarId()), true);
247 TkTestUtils.verifyAggregateHourSumsFlatList("September Pre-Check", new HashMap<String,BigDecimal>() {{put("PRM", BigDecimal.ZERO);put("RGN", new BigDecimal(5));}},aggregate);
248
249
250 TkServiceLocator.getShiftDifferentialRuleService().processShiftDifferentialRules(tdoc, aggregate);
251 TkTestUtils.verifyAggregateHourSumsFlatList("September Post-Check", new HashMap<String,BigDecimal>() {{put("PRM", new BigDecimal(7));put("RGN", new BigDecimal(7));}},aggregate);
252 }
253
254 @SuppressWarnings("serial")
255 @Test
256
257
258
259
260
261
262
263
264
265
266 public void testProcessShiftSimpleNoisyCase() throws Exception {
267
268 boolean[] dayArray = {true, true, true, true, true, true, true};
269
270 Long jobNumber = 30L;
271 Long workArea = 0L;
272 DateTimeZone zone = HrServiceLocator.getTimezoneService().getTargetUserTimezoneWithFallback();
273 this.createShiftDifferentialRule(
274 "BWS-CAL",
275 "REG",
276 "PRM",
277 "IN",
278 "SD1",
279 "SD1",
280 (new LocalTime(16, 0)),
281 (new LocalTime(0, 0)),
282 new BigDecimal(4),
283 new BigDecimal("15"),
284 dayArray);
285
286
287 DateTime start = new DateTime(2010, 3, 29, 14, 0, 0, 0, zone);
288 List<TimeBlock> blocks = new ArrayList<TimeBlock>();
289 CalendarEntry payCalendarEntry = HrServiceLocator.getCalendarEntryService().getCurrentCalendarDates("admin", start);
290 blocks.addAll(TkTestUtils.createUniformTimeBlocks(start, 2, new BigDecimal("4"), "RGN", jobNumber, workArea));
291 blocks.addAll(TkTestUtils.createUniformTimeBlocks(start.plusHours(4).plusMinutes(15), 2, new BigDecimal("2"), "RGN", jobNumber, workArea));
292 blocks.addAll(TkTestUtils.createUniformTimeBlocks(new DateTime(2010, 3, 29, 12, 58, 0, 0, zone), 2, new BigDecimal(1), "RGN", jobNumber, workArea));
293 TkTimeBlockAggregate aggregate = new TkTimeBlockAggregate(blocks, payCalendarEntry);
294
295
296 TkTestUtils.verifyAggregateHourSums("admin", "Pre-Check", new HashMap<String,BigDecimal>() {{put("PRM", BigDecimal.ZERO);put("RGN", new BigDecimal(14));}},aggregate,2);
297
298
299 TimesheetDocument tdoc = TkTestUtils.populateBlankTimesheetDocument(start, "admin");
300 tdoc.setTimeBlocks(blocks);
301 TkServiceLocator.getShiftDifferentialRuleService().processShiftDifferentialRules(tdoc, aggregate);
302
303
304 TkTestUtils.verifyAggregateHourSums("admin", "Post Rules Check", new HashMap<String,BigDecimal>() {{put("PRM", new BigDecimal(8));put("RGN", new BigDecimal(14));}},aggregate,2);
305 }
306
307 @SuppressWarnings("serial")
308 @Test
309
310
311
312
313
314
315
316 public void testProcessShiftSimpleCase() throws Exception {
317
318 boolean[] dayArray = {true, true, true, true, true, true, true};
319
320 Long jobNumber = 30L;
321 Long workArea = 0L;
322 DateTimeZone zone = HrServiceLocator.getTimezoneService().getTargetUserTimezoneWithFallback();
323 this.createShiftDifferentialRule(
324 "BWS-CAL",
325 "REG",
326 "PRM",
327 "IN",
328 "SD1",
329 "SD1",
330 (new LocalTime(16, 0)),
331 (new LocalTime(0, 0)),
332 new BigDecimal(4),
333 new BigDecimal("15.00"),
334 dayArray);
335
336
337 DateTime start = new DateTime(2010, 3, 29, 14, 0, 0, 0, zone);
338 List<TimeBlock> blocks = new ArrayList<TimeBlock>();
339 CalendarEntry payCalendarEntry = HrServiceLocator.getCalendarEntryService().getCurrentCalendarDates("admin", start);
340 blocks.addAll(TkTestUtils.createUniformTimeBlocks(start, 2, new BigDecimal("4"), "REG", jobNumber, workArea));
341 blocks.addAll(TkTestUtils.createUniformTimeBlocks(start.plusHours(4).plusMinutes(15), 2, new BigDecimal("2"), "REG", jobNumber, workArea));
342 TkTimeBlockAggregate aggregate = new TkTimeBlockAggregate(blocks, payCalendarEntry);
343
344
345 TkTestUtils.verifyAggregateHourSums("admin","Pre-Check", new HashMap<String,BigDecimal>() {{put("PRM", BigDecimal.ZERO);put("REG", new BigDecimal(12));}},aggregate,2);
346
347
348 TimesheetDocument tdoc = TkTestUtils.populateBlankTimesheetDocument(start, "admin");
349 tdoc.setTimeBlocks(blocks);
350 TkServiceLocator.getShiftDifferentialRuleService().processShiftDifferentialRules(tdoc, aggregate);
351
352
353 TkTestUtils.verifyAggregateHourSums("admin","Post Rules Check", new HashMap<String,BigDecimal>() {{put("PRM", new BigDecimal(8));put("REG", new BigDecimal(12));}},aggregate,2);
354 }
355
356
357
358
359
360
361 private void createShiftDifferentialRule(String pyCalendarGroup, String fromEarnGroup, String premiumEarnCode, String location, String payGrade, String hrSalGroup, LocalTime startTime, LocalTime endTime, BigDecimal minHours, BigDecimal maxGap, boolean dayBooleans[]) {
362 Assert.assertTrue("Wrong number of day booleans", dayBooleans.length == 7);
363
364 ShiftDifferentialRuleService service = TkServiceLocator.getShiftDifferentialRuleService();
365 ShiftDifferentialRule sdr = new ShiftDifferentialRule();
366
367 sdr.setBeginTime(new Time(startTime.toDateTimeToday().getMillis()));
368 sdr.setEndTime(new Time(endTime.toDateTimeToday().getMillis()));
369 sdr.setMinHours(minHours);
370 sdr.setMaxGap(maxGap);
371 sdr.setActive(true);
372 sdr.setUserPrincipalId(USER_PRINCIPAL_ID);
373 sdr.setEffectiveLocalDate(JAN_AS_OF_DATE.toLocalDate());
374 sdr.setLocation(location);
375 sdr.setPayGrade(payGrade);
376 sdr.setHrSalGroup(hrSalGroup);
377 sdr.setFromEarnGroup(fromEarnGroup);
378 sdr.setPyCalendarGroup(pyCalendarGroup);
379 sdr.setEarnCode(premiumEarnCode);
380 sdr.setRuleType("default");
381
382 for (int i=0; i<dayBooleans.length; i++) {
383 switch(i) {
384 case 0:
385 sdr.setSunday(dayBooleans[i]);
386 break;
387 case 1:
388 sdr.setMonday(dayBooleans[i]);
389 break;
390 case 2:
391 sdr.setTuesday(dayBooleans[i]);
392 break;
393 case 3:
394 sdr.setWednesday(dayBooleans[i]);
395 break;
396 case 4:
397 sdr.setThursday(dayBooleans[i]);
398 break;
399 case 5:
400 sdr.setFriday(dayBooleans[i]);
401 break;
402 case 6:
403 sdr.setSaturday(dayBooleans[i]);
404 break;
405 }
406 }
407
408 service.saveOrUpdate(sdr);
409
410 ShiftDifferentialRule sdrBack = service.getShiftDifferentialRule(sdr.getTkShiftDiffRuleId());
411
412 DateTimeZone tz = HrServiceLocator.getTimezoneService().getUserTimezoneWithFallback();
413 LocalTime orig_start = new LocalTime(sdr.getBeginTime());
414 LocalTime orig_end = new LocalTime(sdr.getEndTime());
415
416 LocalTime stored_start = new LocalTime(sdrBack.getBeginTime());
417 LocalTime stored_end = new LocalTime(sdrBack.getEndTime());
418
419 Assert.assertTrue("Start times not equal.", orig_start.equals(stored_start));
420 Assert.assertTrue("End times not equal.", orig_end.equals(stored_end));
421 }
422
423
424
425
426
427
428
429 @Test
430 public void overlapMultipleShiftsWithSameTimeBlock() {
431
432 boolean[] dayArray = {true, true, true, true, true, true, true};
433
434 Long jobNumber = 30L;
435 Long workArea = 0L;
436 DateTimeZone zone = HrServiceLocator.getTimezoneService().getTargetUserTimezoneWithFallback();
437
438
439 this.createShiftDifferentialRule(
440 "BWS-CAL",
441 "REG",
442 "PRM",
443 "IN",
444 "SD1",
445 "SD1",
446 (new LocalTime(15, 0)),
447 (new LocalTime(8, 0)),
448 new BigDecimal(6),
449 new BigDecimal("90.00"),
450 dayArray);
451
452
453 DateTime start = new DateTime(2010, 3, 29, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone());
454 CalendarEntry payCalendarEntry = HrServiceLocator.getCalendarEntryService().getCurrentCalendarDates("admin", start);
455
456 List<TimeBlock> blocks = new ArrayList<TimeBlock>();
457 DateTime tbStart = new DateTime(2010, 3, 29, 0, 0, 0, 0, zone);
458
459
460 blocks.addAll(TkTestUtils.createUniformTimeBlocks(tbStart, 1, new BigDecimal("24"), "REG", jobNumber, workArea));
461
462 TkTimeBlockAggregate aggregate = new TkTimeBlockAggregate(blocks, payCalendarEntry);
463
464
465 TkTestUtils.verifyAggregateHourSums("admin","Pre-Check", new HashMap<String,BigDecimal>() {{put("PRM", BigDecimal.ZERO);put("REG", new BigDecimal(24));}},aggregate,2);
466
467
468 TimesheetDocument tdoc = TkTestUtils.populateBlankTimesheetDocument(start, "admin");
469 tdoc.setTimeBlocks(blocks);
470 TkServiceLocator.getShiftDifferentialRuleService().processShiftDifferentialRules(tdoc, aggregate);
471
472
473 TkTestUtils.verifyAggregateHourSums("admin","Post Rules Check", new HashMap<String,BigDecimal>() {{put("PRM", new BigDecimal(17));put("REG", new BigDecimal(24));}},aggregate,2);
474
475 }
476
477
478
479
480
481
482 @Test
483 public void overlapMultipleShiftsWithMultipleTimeBlocks() {
484
485 boolean[] dayArray = {true, true, true, true, true, true, true};
486
487 Long jobNumber = 30L;
488 Long workArea = 0L;
489 DateTimeZone zone = HrServiceLocator.getTimezoneService().getTargetUserTimezoneWithFallback();
490
491
492 this.createShiftDifferentialRule(
493 "BWS-CAL",
494 "REG",
495 "PRM",
496 "IN",
497 "SD1",
498 "SD1",
499 (new LocalTime(15, 0)),
500 (new LocalTime(8, 0)),
501 new BigDecimal(6),
502 new BigDecimal("90.00"),
503 dayArray);
504
505
506 DateTime start = new DateTime(2010, 3, 29, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone());
507 CalendarEntry payCalendarEntry = HrServiceLocator.getCalendarEntryService().getCurrentCalendarDates("admin", start);
508
509 List<TimeBlock> blocks = new ArrayList<TimeBlock>();
510 DateTime tbStart = new DateTime(2010, 3, 29, 0, 0, 0, 0, zone);
511
512
513 blocks.addAll(TkTestUtils.createUniformTimeBlocks(tbStart, 1, new BigDecimal("24"), "REG", jobNumber, workArea));
514
515
516 blocks.addAll(TkTestUtils.createUniformTimeBlocks(tbStart.plusDays(1), 1, new BigDecimal("24"), "REG", jobNumber, workArea));
517
518 TkTimeBlockAggregate aggregate = new TkTimeBlockAggregate(blocks, payCalendarEntry);
519
520
521 TkTestUtils.verifyAggregateHourSums("admin","Pre-Check", new HashMap<String,BigDecimal>() {{put("PRM", BigDecimal.ZERO);put("REG", new BigDecimal(48));}},aggregate,2);
522
523
524 TimesheetDocument tdoc = TkTestUtils.populateBlankTimesheetDocument(start, "admin");
525 tdoc.setTimeBlocks(blocks);
526 TkServiceLocator.getShiftDifferentialRuleService().processShiftDifferentialRules(tdoc, aggregate);
527
528
529
530 TkTestUtils.verifyAggregateHourSums("admin","Post Rules Check", new HashMap<String,BigDecimal>() {{put("PRM", new BigDecimal(34));put("REG", new BigDecimal(48));}},aggregate,2);
531
532 }
533
534
535
536
537
538
539 @Test
540 public void overlapMultipleShiftsWithSameTimeBlockExceedingMinOnOneShift() {
541
542 boolean[] dayArray = {true, true, true, true, true, true, true};
543
544 Long jobNumber = 30L;
545 Long workArea = 0L;
546 DateTimeZone zone = HrServiceLocator.getTimezoneService().getTargetUserTimezoneWithFallback();
547
548
549 this.createShiftDifferentialRule(
550 "BWS-CAL",
551 "REG",
552 "PRM",
553 "IN",
554 "SD1",
555 "SD1",
556 (new LocalTime(15, 0)),
557 (new LocalTime(8, 0)),
558 new BigDecimal(6),
559 new BigDecimal("90.00"),
560 dayArray);
561
562 DateTime start = new DateTime(2010, 3, 29, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone());
563 List<TimeBlock> blocks = new ArrayList<TimeBlock>();
564 CalendarEntry payCalendarEntry = HrServiceLocator.getCalendarEntryService().getCurrentCalendarDates("admin", start);
565
566
567 DateTime tbStart = new DateTime(2010, 3, 30, 3, 0, 0, 0, zone);
568 blocks.addAll(TkTestUtils.createUniformTimeBlocks(tbStart, 1, new BigDecimal("21"), "REG", jobNumber, workArea));
569
570 TkTimeBlockAggregate aggregate = new TkTimeBlockAggregate(blocks, payCalendarEntry);
571
572
573 TkTestUtils.verifyAggregateHourSums("admin","Pre-Check", new ImmutableMap.Builder<String, BigDecimal>()
574 .put("PRM", BigDecimal.ZERO)
575 .put("REG", new BigDecimal(21)).build(), aggregate, 2);
576
577
578 TimesheetDocument tdoc = TkTestUtils.populateBlankTimesheetDocument(start, "admin");
579 tdoc.setTimeBlocks(blocks);
580 TkServiceLocator.getShiftDifferentialRuleService().processShiftDifferentialRules(tdoc, aggregate);
581
582
583 TkTestUtils.verifyAggregateHourSums("admin","Post Rules Check", new ImmutableMap.Builder<String, BigDecimal>()
584 .put("PRM", new BigDecimal(9))
585 .put("REG", new BigDecimal(21)).build(),
586 aggregate,
587 2);
588
589 }
590
591
592
593
594
595
596 @Test
597 public void overlapMultipleShiftsWithSameTimeBlockExceedingMinOnFirstShift() {
598
599 boolean[] dayArray = {true, true, true, true, true, true, true};
600
601 Long jobNumber = 30L;
602 Long workArea = 0L;
603 DateTimeZone zone = HrServiceLocator.getTimezoneService().getTargetUserTimezoneWithFallback();
604
605
606 this.createShiftDifferentialRule(
607 "BWS-CAL",
608 "REG",
609 "PRM",
610 "IN",
611 "SD1",
612 "SD1",
613 (new LocalTime(15, 0)),
614 (new LocalTime(8, 0)),
615 new BigDecimal(6),
616 new BigDecimal("90.00"),
617 dayArray);
618
619 DateTime start = new DateTime(2010, 3, 29, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone());
620 List<TimeBlock> blocks = new ArrayList<TimeBlock>();
621 CalendarEntry payCalendarEntry = HrServiceLocator.getCalendarEntryService().getCurrentCalendarDates("admin", start);
622
623
624 DateTime tbStart = new DateTime(2010, 3, 30, 1, 0, 0, 0, zone);
625 blocks.addAll(TkTestUtils.createUniformTimeBlocks(tbStart, 1, new BigDecimal("19"), "REG", jobNumber, workArea));
626
627 TkTimeBlockAggregate aggregate = new TkTimeBlockAggregate(blocks, payCalendarEntry);
628
629
630 TkTestUtils.verifyAggregateHourSums("admin","Pre-Check", new ImmutableMap.Builder<String, BigDecimal>()
631 .put("PRM", BigDecimal.ZERO)
632 .put("REG", new BigDecimal(19)).build(), aggregate, 2);
633
634
635 TimesheetDocument tdoc = TkTestUtils.populateBlankTimesheetDocument(start, "admin");
636 tdoc.setTimeBlocks(blocks);
637 TkServiceLocator.getShiftDifferentialRuleService().processShiftDifferentialRules(tdoc, aggregate);
638
639
640 TkTestUtils.verifyAggregateHourSums("admin","Post Rules Check", new ImmutableMap.Builder<String, BigDecimal>()
641 .put("PRM", new BigDecimal(7))
642 .put("REG", new BigDecimal(19)).build(),
643 aggregate,
644 2);
645
646 }
647
648
649
650
651
652
653 @Test
654 public void overlapMultipleShiftsWithSameTimeBlocNeitherExceedingMin() {
655
656 boolean[] dayArray = {true, true, true, true, true, true, true};
657
658 Long jobNumber = 30L;
659 Long workArea = 0L;
660 DateTimeZone zone = HrServiceLocator.getTimezoneService().getTargetUserTimezoneWithFallback();
661
662
663 this.createShiftDifferentialRule(
664 "BWS-CAL",
665 "REG",
666 "PRM",
667 "IN",
668 "SD1",
669 "SD1",
670 (new LocalTime(15, 0)),
671 (new LocalTime(8, 0)),
672 new BigDecimal(6),
673 new BigDecimal("90.00"),
674 dayArray);
675
676
677 DateTime start = new DateTime(2010, 3, 29, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone());
678 List<TimeBlock> blocks = new ArrayList<TimeBlock>();
679 CalendarEntry payCalendarEntry = HrServiceLocator.getCalendarEntryService().getCurrentCalendarDates("admin", start);
680
681
682 DateTime tbStart = new DateTime(2010, 3, 30, 3, 0, 0, 0, zone);
683 blocks.addAll(TkTestUtils.createUniformTimeBlocks(tbStart, 1, new BigDecimal("17"), "REG", jobNumber, workArea));
684
685 TkTimeBlockAggregate aggregate = new TkTimeBlockAggregate(blocks, payCalendarEntry);
686
687
688 TkTestUtils.verifyAggregateHourSums("admin","Pre-Check", new ImmutableMap.Builder<String, BigDecimal>()
689 .put("PRM", BigDecimal.ZERO)
690 .put("REG", new BigDecimal(17)).build(), aggregate, 2);
691
692
693 TimesheetDocument tdoc = TkTestUtils.populateBlankTimesheetDocument(start, "admin");
694 tdoc.setTimeBlocks(blocks);
695 TkServiceLocator.getShiftDifferentialRuleService().processShiftDifferentialRules(tdoc, aggregate);
696
697
698 TkTestUtils.verifyAggregateHourSums("admin","Post Rules Check", new ImmutableMap.Builder<String, BigDecimal>()
699 .put("PRM", BigDecimal.ZERO)
700 .put("REG", new BigDecimal(17)).build(),
701 aggregate,
702 2);
703 }
704
705
706
707
708
709
710 @Test
711 public void multipleTimeBlocksOvernightExceedingMin() {
712
713 boolean[] dayArray = {true, true, true, true, true, true, true};
714
715 Long jobNumber = 30L;
716 Long workArea = 0L;
717 DateTimeZone zone = HrServiceLocator.getTimezoneService().getTargetUserTimezoneWithFallback();
718
719
720 this.createShiftDifferentialRule(
721 "BWS-CAL",
722 "REG",
723 "PRM",
724 "IN",
725 "SD1",
726 "SD1",
727 (new LocalTime(15, 0)),
728 (new LocalTime(8, 0)),
729 new BigDecimal(6),
730 new BigDecimal("90.00"),
731 dayArray);
732
733
734 DateTime start = new DateTime(2010, 3, 29, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone());
735 List<TimeBlock> blocks = new ArrayList<TimeBlock>();
736 CalendarEntry payCalendarEntry = HrServiceLocator.getCalendarEntryService().getCurrentCalendarDates("admin", start);
737
738
739 DateTime tbStart1 = new DateTime(2010, 3, 30, 22, 0, 0, 0, zone);
740 blocks.addAll(TkTestUtils.createUniformTimeBlocks(tbStart1, 1, new BigDecimal("2"), "REG", jobNumber, workArea));
741
742 DateTime tbStart2 = new DateTime(2010, 3, 31, 0, 0, 0, 0, zone);
743 blocks.addAll(TkTestUtils.createUniformTimeBlocks(tbStart2, 1, new BigDecimal("5"), "REG", jobNumber, workArea));
744
745 TkTimeBlockAggregate aggregate = new TkTimeBlockAggregate(blocks, payCalendarEntry);
746
747
748 TkTestUtils.verifyAggregateHourSums("admin","Pre-Check", new ImmutableMap.Builder<String, BigDecimal>()
749 .put("PRM", BigDecimal.ZERO)
750 .put("REG", BigDecimal.valueOf(7)).build(), aggregate, 2);
751
752
753 TimesheetDocument tdoc = TkTestUtils.populateBlankTimesheetDocument(start, "admin");
754 tdoc.setTimeBlocks(blocks);
755 TkServiceLocator.getShiftDifferentialRuleService().processShiftDifferentialRules(tdoc, aggregate);
756
757
758 TkTestUtils.verifyAggregateHourSums("admin","Post Rules Check", new ImmutableMap.Builder<String, BigDecimal>()
759 .put("PRM", BigDecimal.valueOf(7))
760 .put("REG", BigDecimal.valueOf(7)).build(),
761 aggregate,
762 2);
763 }
764
765
766
767
768
769
770 @Test
771 public void multipleTimeBlocksOvernightExceedingMinWithSixtyMinuteGap() {
772
773 boolean[] dayArray = {true, true, true, true, true, true, true};
774
775 Long jobNumber = 30L;
776 Long workArea = 0L;
777 DateTimeZone zone = HrServiceLocator.getTimezoneService().getTargetUserTimezoneWithFallback();
778
779
780 this.createShiftDifferentialRule(
781 "BWS-CAL",
782 "REG",
783 "PRM",
784 "IN",
785 "SD1",
786 "SD1",
787 (new LocalTime(15, 0)),
788 (new LocalTime(8, 0)),
789 new BigDecimal(6),
790 new BigDecimal("90.00"),
791 dayArray);
792
793
794 DateTime start = new DateTime(2010, 3, 29, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone());
795 List<TimeBlock> blocks = new ArrayList<TimeBlock>();
796 CalendarEntry payCalendarEntry = HrServiceLocator.getCalendarEntryService().getCurrentCalendarDates("admin", start);
797
798
799 DateTime tbStart1 = new DateTime(2010, 3, 30, 22, 0, 0, 0, zone);
800 blocks.addAll(TkTestUtils.createUniformTimeBlocks(tbStart1, 1, new BigDecimal("2"), "REG", jobNumber, workArea));
801
802 DateTime tbStart2 = new DateTime(2010, 3, 31, 1, 0, 0, 0, zone);
803 blocks.addAll(TkTestUtils.createUniformTimeBlocks(tbStart2, 1, new BigDecimal("4"), "REG", jobNumber, workArea));
804
805 TkTimeBlockAggregate aggregate = new TkTimeBlockAggregate(blocks, payCalendarEntry);
806
807
808 TkTestUtils.verifyAggregateHourSums("admin","Pre-Check", new ImmutableMap.Builder<String, BigDecimal>()
809 .put("PRM", BigDecimal.ZERO)
810 .put("REG", BigDecimal.valueOf(6)).build(), aggregate, 2);
811
812
813 TimesheetDocument tdoc = TkTestUtils.populateBlankTimesheetDocument(start, "admin");
814 tdoc.setTimeBlocks(blocks);
815 TkServiceLocator.getShiftDifferentialRuleService().processShiftDifferentialRules(tdoc, aggregate);
816
817
818 TkTestUtils.verifyAggregateHourSums("admin","Post Rules Check", new ImmutableMap.Builder<String, BigDecimal>()
819 .put("PRM", BigDecimal.valueOf(6))
820 .put("REG", BigDecimal.valueOf(6)).build(),
821 aggregate,
822 2);
823 }
824
825
826
827
828
829
830 @Test
831 public void multipleTimeBlocksOvernightExceedingMinWithNinetyMinuteGap() {
832
833 boolean[] dayArray = {true, true, true, true, true, true, true};
834
835 Long jobNumber = 30L;
836 Long workArea = 0L;
837 DateTimeZone zone = HrServiceLocator.getTimezoneService().getTargetUserTimezoneWithFallback();
838
839
840 this.createShiftDifferentialRule(
841 "BWS-CAL",
842 "REG",
843 "PRM",
844 "IN",
845 "SD1",
846 "SD1",
847 (new LocalTime(15, 0)),
848 (new LocalTime(8, 0)),
849 new BigDecimal(6),
850 new BigDecimal("90.00"),
851 dayArray);
852
853
854 DateTime start = new DateTime(2010, 3, 29, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone());
855 List<TimeBlock> blocks = new ArrayList<TimeBlock>();
856 CalendarEntry payCalendarEntry = HrServiceLocator.getCalendarEntryService().getCurrentCalendarDates("admin", start);
857
858
859 DateTime tbStart1 = new DateTime(2010, 3, 30, 22, 0, 0, 0, zone);
860 blocks.addAll(TkTestUtils.createUniformTimeBlocks(tbStart1, 1, new BigDecimal("2"), "REG", jobNumber, workArea));
861
862 DateTime tbStart2 = new DateTime(2010, 3, 31, 1, 30, 0, 0, zone);
863 blocks.addAll(TkTestUtils.createUniformTimeBlocks(tbStart2, 1, new BigDecimal("4"), "REG", jobNumber, workArea));
864
865 TkTimeBlockAggregate aggregate = new TkTimeBlockAggregate(blocks, payCalendarEntry);
866
867
868 TkTestUtils.verifyAggregateHourSums("admin","Pre-Check", new ImmutableMap.Builder<String, BigDecimal>()
869 .put("PRM", BigDecimal.ZERO)
870 .put("REG", BigDecimal.valueOf(6)).build(), aggregate, 2);
871
872
873 TimesheetDocument tdoc = TkTestUtils.populateBlankTimesheetDocument(start, "admin");
874 tdoc.setTimeBlocks(blocks);
875 TkServiceLocator.getShiftDifferentialRuleService().processShiftDifferentialRules(tdoc, aggregate);
876
877
878 TkTestUtils.verifyAggregateHourSums("admin","Post Rules Check", new ImmutableMap.Builder<String, BigDecimal>()
879 .put("PRM", BigDecimal.valueOf(6))
880 .put("REG", BigDecimal.valueOf(6)).build(),
881 aggregate,
882 2);
883 }
884
885
886
887
888
889
890 @Test
891 public void multipleTimeBlocksOvernightExceedingMinButExceedingGap() {
892
893 boolean[] dayArray = {true, true, true, true, true, true, true};
894
895 Long jobNumber = 30L;
896 Long workArea = 0L;
897 DateTimeZone zone = HrServiceLocator.getTimezoneService().getTargetUserTimezoneWithFallback();
898
899
900 this.createShiftDifferentialRule(
901 "BWS-CAL",
902 "REG",
903 "PRM",
904 "IN",
905 "SD1",
906 "SD1",
907 (new LocalTime(15, 0)),
908 (new LocalTime(8, 0)),
909 new BigDecimal(6),
910 new BigDecimal("90.00"),
911 dayArray);
912
913
914 DateTime start = new DateTime(2010, 3, 29, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone());
915 List<TimeBlock> blocks = new ArrayList<TimeBlock>();
916 CalendarEntry payCalendarEntry = HrServiceLocator.getCalendarEntryService().getCurrentCalendarDates("admin", start);
917
918
919 DateTime tbStart1 = new DateTime(2010, 3, 30, 22, 0, 0, 0, zone);
920 blocks.addAll(TkTestUtils.createUniformTimeBlocks(tbStart1, 1, new BigDecimal("2"), "REG", jobNumber, workArea));
921
922 DateTime tbStart2 = new DateTime(2010, 3, 31, 1, 36, 0, 0, zone);
923 blocks.addAll(TkTestUtils.createUniformTimeBlocks(tbStart2, 1, new BigDecimal("4"), "REG", jobNumber, workArea));
924
925 TkTimeBlockAggregate aggregate = new TkTimeBlockAggregate(blocks, payCalendarEntry);
926
927
928 TkTestUtils.verifyAggregateHourSums("admin","Pre-Check", new ImmutableMap.Builder<String, BigDecimal>()
929 .put("PRM", BigDecimal.ZERO)
930 .put("REG", BigDecimal.valueOf(6)).build(), aggregate, 2);
931
932
933 TimesheetDocument tdoc = TkTestUtils.populateBlankTimesheetDocument(start, "admin");
934 tdoc.setTimeBlocks(blocks);
935 TkServiceLocator.getShiftDifferentialRuleService().processShiftDifferentialRules(tdoc, aggregate);
936
937
938 TkTestUtils.verifyAggregateHourSums("admin","Post Rules Check", new ImmutableMap.Builder<String, BigDecimal>()
939 .put("PRM", BigDecimal.valueOf(0))
940 .put("REG", BigDecimal.valueOf(6)).build(),
941 aggregate,
942 2);
943 }
944
945
946
947
948
949
950
951 @Test
952 public void threeBlocksWithinSameShift() {
953
954 boolean[] dayArray = {true, true, true, true, true, true, true};
955
956 Long jobNumber = 30L;
957 Long workArea = 0L;
958 DateTimeZone zone = HrServiceLocator.getTimezoneService().getTargetUserTimezoneWithFallback();
959
960
961 this.createShiftDifferentialRule(
962 "BWS-CAL",
963 "REG",
964 "PRM",
965 "IN",
966 "SD1",
967 "SD1",
968 (new LocalTime(15, 0)),
969 (new LocalTime(8, 0)),
970 new BigDecimal(6),
971 new BigDecimal("90.00"),
972 dayArray);
973
974
975 DateTime start = new DateTime(2010, 3, 29, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone());
976 CalendarEntry payCalendarEntry = HrServiceLocator.getCalendarEntryService().getCurrentCalendarDates("admin", start);
977
978 List<TimeBlock> blocks = new ArrayList<TimeBlock>();
979
980
981 DateTime tbStart1 = new DateTime(2010, 3, 30, 15, 0, 0, 0, zone);
982 blocks.addAll(TkTestUtils.createUniformTimeBlocks(tbStart1, 1, new BigDecimal("2"), "REG", jobNumber, workArea));
983
984
985 DateTime tbStart2 = new DateTime(2010, 3, 30, 18, 0, 0, 0, zone);
986 blocks.addAll(TkTestUtils.createUniformTimeBlocks(tbStart2, 1, new BigDecimal("3"), "REG", jobNumber, workArea));
987
988
989 DateTime tbStart3 = new DateTime(2010, 3, 30, 22, 0, 0, 0, zone);
990 blocks.addAll(TkTestUtils.createUniformTimeBlocks(tbStart3, 1, new BigDecimal("1"), "REG", jobNumber, workArea));
991
992 TkTimeBlockAggregate aggregate = new TkTimeBlockAggregate(blocks, payCalendarEntry);
993
994
995 TkTestUtils.verifyAggregateHourSums("admin","Pre-Check", new ImmutableMap.Builder<String, BigDecimal>()
996 .put("PRM", BigDecimal.ZERO)
997 .put("REG", BigDecimal.valueOf(6)).build(), aggregate, 2);
998
999
1000 TimesheetDocument tdoc = TkTestUtils.populateBlankTimesheetDocument(start, "admin");
1001 tdoc.setTimeBlocks(blocks);
1002 TkServiceLocator.getShiftDifferentialRuleService().processShiftDifferentialRules(tdoc, aggregate);
1003
1004
1005 TkTestUtils.verifyAggregateHourSums("admin","Post Rules Check", new ImmutableMap.Builder<String, BigDecimal>()
1006 .put("PRM", BigDecimal.valueOf(6))
1007 .put("REG", BigDecimal.valueOf(6)).build(),
1008 aggregate,
1009 2);
1010 }
1011
1012
1013
1014
1015
1016
1017 @Test
1018 public void fourBlocksWithinSameShiftSpanningTwoDays() {
1019
1020 boolean[] dayArray = {true, true, true, true, true, true, true};
1021
1022 Long jobNumber = 30L;
1023 Long workArea = 0L;
1024 DateTimeZone zone = HrServiceLocator.getTimezoneService().getTargetUserTimezoneWithFallback();
1025
1026
1027 this.createShiftDifferentialRule(
1028 "BWS-CAL",
1029 "REG",
1030 "PRM",
1031 "IN",
1032 "SD1",
1033 "SD1",
1034 (new LocalTime(15, 0)),
1035 (new LocalTime(8, 0)),
1036 new BigDecimal(6),
1037 new BigDecimal("90.00"),
1038 dayArray);
1039
1040
1041 DateTime start = new DateTime(2010, 3, 29, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone());
1042 CalendarEntry payCalendarEntry = HrServiceLocator.getCalendarEntryService().getCurrentCalendarDates("admin", start);
1043
1044 List<TimeBlock> blocks = new ArrayList<TimeBlock>();
1045
1046
1047 DateTime tbStart1 = new DateTime(2010, 3, 30, 17, 0, 0, 0, zone);
1048 blocks.addAll(TkTestUtils.createUniformTimeBlocks(tbStart1, 1, new BigDecimal("1"), "REG", jobNumber, workArea));
1049
1050
1051 DateTime tbStart2 = new DateTime(2010, 3, 30, 19, 30, 0, 0, zone);
1052 blocks.addAll(TkTestUtils.createUniformTimeBlocks(tbStart2, 1, new BigDecimal("1"), "REG", jobNumber, workArea));
1053
1054
1055 DateTime tbStart3 = new DateTime(2010, 3, 30, 22, 0, 0, 0, zone);
1056 blocks.addAll(TkTestUtils.createUniformTimeBlocks(tbStart3, 1, new BigDecimal("2"), "REG", jobNumber, workArea));
1057
1058
1059 DateTime tbStart4 = new DateTime(2010, 3, 31, 1, 30, 0, 0, zone);
1060 blocks.addAll(TkTestUtils.createUniformTimeBlocks(tbStart4, 1, new BigDecimal("3"), "REG", jobNumber, workArea));
1061
1062 TkTimeBlockAggregate aggregate = new TkTimeBlockAggregate(blocks, payCalendarEntry);
1063
1064
1065 TkTestUtils.verifyAggregateHourSums("admin","Pre-Check", new ImmutableMap.Builder<String, BigDecimal>()
1066 .put("PRM", BigDecimal.ZERO)
1067 .put("REG", BigDecimal.valueOf(7)).build(), aggregate, 2);
1068
1069
1070 TimesheetDocument tdoc = TkTestUtils.populateBlankTimesheetDocument(start, "admin");
1071 tdoc.setTimeBlocks(blocks);
1072 TkServiceLocator.getShiftDifferentialRuleService().processShiftDifferentialRules(tdoc, aggregate);
1073
1074
1075 TkTestUtils.verifyAggregateHourSums("admin","Post Rules Check", new ImmutableMap.Builder<String, BigDecimal>()
1076 .put("PRM", BigDecimal.valueOf(7))
1077 .put("REG", BigDecimal.valueOf(7)).build(),
1078 aggregate,
1079 2);
1080 }
1081
1082
1083
1084
1085
1086
1087
1088 @Test
1089 public void EarnGroupTest() {
1090
1091
1092 String principalId = "10112";
1093
1094
1095 Long jobNumber = 0L;
1096 String groupKey = "IU-IN";
1097 Long workArea = 1010L;
1098 Long task = 0L;
1099 DateTimeZone zone = HrServiceLocator.getTimezoneService().getTargetUserTimezoneWithFallback();
1100
1101
1102
1103 DateTime start = new DateTime(2010, 3, 29, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone());
1104 CalendarEntry payCalendarEntry = HrServiceLocator.getCalendarEntryService().getCurrentCalendarDates("admin", start);
1105
1106 TimesheetDocument td = TkTestUtils.populateBlankTimesheetDocument(start, principalId);
1107
1108 List<TimeBlock> blocks = new ArrayList<TimeBlock>();
1109
1110
1111 DateTime tbStart1 = new DateTime(2010, 3, 30, 8, 0, 0, 0, zone);
1112 blocks.addAll(TkTestUtils.createUniformTimeBlocks(tbStart1, 1, new BigDecimal("3"), "RGH", jobNumber, workArea, task, groupKey, td.getDocumentId()));
1113
1114
1115 DateTime tbStart2 = new DateTime(2010, 3, 30, 14, 0, 0, 0, zone);
1116 blocks.addAll(TkTestUtils.createUniformTimeBlocks(tbStart2, 1, new BigDecimal("3"), "ECHR", jobNumber, workArea, task, groupKey, td.getDocumentId()));
1117
1118 TkTimeBlockAggregate aggregate = new TkTimeBlockAggregate(blocks, payCalendarEntry);
1119
1120
1121 TkTestUtils.verifyAggregateHourSums(principalId, "Pre-Check", new ImmutableMap.Builder<String, BigDecimal>()
1122 .put("RGH", BigDecimal.valueOf(3))
1123 .put("ECHR", BigDecimal.valueOf(3)).build(), aggregate, 2);
1124
1125
1126
1127
1128 List<LeaveBlock> leaveBlocks = TimesheetUtils.getLeaveBlocksForTimesheet(td);
1129 List<TimeBlock> initialBlocks = TimesheetUtils.getTimesheetTimeblocksForProcessing(td, true);
1130 List<TimeBlock> referenceTimeBlocks = TimesheetUtils.getReferenceTimeBlocks(initialBlocks);
1131
1132
1133
1134 TimesheetUtils.processTimeBlocksWithRuleChange(blocks, referenceTimeBlocks, leaveBlocks, td.getCalendarEntry(), td, HrContext.getPrincipalId());
1135
1136
1137 td = TkServiceLocator.getTimesheetService().getTimesheetDocument(td.getDocumentId());
1138 aggregate = new TkTimeBlockAggregate(td.getTimeBlocks(), payCalendarEntry);
1139
1140 TkTestUtils.verifyAggregateHourSums(principalId, "Post Rules Check", new ImmutableMap.Builder<String, BigDecimal>()
1141 .put("RGH", BigDecimal.valueOf(3))
1142 .put("ECHR", BigDecimal.valueOf(3))
1143 .put("SHEG", BigDecimal.valueOf(3)).build(),
1144 aggregate,
1145 2);
1146 }
1147
1148 @Test
1149 public void calendarGroupTest() {
1150
1151
1152 String principalId = "10113";
1153
1154
1155 Long jobNumber = 0L;
1156 String groupKey = "IU-IN";
1157 Long workArea = 1010L;
1158 Long task = 0L;
1159 DateTimeZone zone = HrServiceLocator.getTimezoneService().getTargetUserTimezoneWithFallback();
1160
1161
1162
1163 DateTime start = new DateTime(2010, 3, 16, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone());
1164 CalendarEntry payCalendarEntry = HrServiceLocator.getCalendarEntryService().getCurrentCalendarDates(principalId, start);
1165
1166 TimesheetDocument td = TkTestUtils.populateBlankTimesheetDocument(start, principalId);
1167
1168 List<TimeBlock> blocks = new ArrayList<TimeBlock>();
1169
1170
1171 DateTime tbStart1 = new DateTime(2010, 3, 21, 8, 0, 0, 0, zone);
1172 blocks.addAll(TkTestUtils.createUniformTimeBlocks(tbStart1, 1, new BigDecimal("3"), "RGH", jobNumber, workArea, task, groupKey, td.getDocumentId()));
1173
1174
1175
1176
1177
1178 TkTimeBlockAggregate aggregate = new TkTimeBlockAggregate(blocks, payCalendarEntry);
1179
1180
1181 TkTestUtils.verifyAggregateHourSums(principalId, "Pre-Check", new ImmutableMap.Builder<String, BigDecimal>()
1182 .put("RGH", BigDecimal.valueOf(3)).build(), aggregate, 1);
1183
1184
1185
1186
1187 List<LeaveBlock> leaveBlocks = TimesheetUtils.getLeaveBlocksForTimesheet(td);
1188 List<TimeBlock> initialBlocks = TimesheetUtils.getTimesheetTimeblocksForProcessing(td, true);
1189 List<TimeBlock> referenceTimeBlocks = TimesheetUtils.getReferenceTimeBlocks(initialBlocks);
1190
1191
1192
1193 TimesheetUtils.processTimeBlocksWithRuleChange(blocks, referenceTimeBlocks, leaveBlocks, td.getCalendarEntry(), td, HrContext.getPrincipalId());
1194
1195
1196 td = TkServiceLocator.getTimesheetService().getTimesheetDocument(td.getDocumentId());
1197 aggregate = new TkTimeBlockAggregate(td.getTimeBlocks(), payCalendarEntry);
1198
1199 TkTestUtils.verifyAggregateHourSums(principalId, "Post Rules Check", new ImmutableMap.Builder<String, BigDecimal>()
1200 .put("RGH", BigDecimal.valueOf(3))
1201 .put("SHCG", BigDecimal.valueOf(3))
1202 .put("SHDY", BigDecimal.valueOf(0)).build(),
1203 aggregate,
1204 1);
1205 }
1206
1207 @Test
1208 public void daysTest() {
1209
1210
1211 String principalId = "10114";
1212
1213
1214 Long jobNumber = 0L;
1215 String groupKey = "IU-IN";
1216 Long workArea = 1010L;
1217 Long task = 0L;
1218 DateTimeZone zone = HrServiceLocator.getTimezoneService().getTargetUserTimezoneWithFallback();
1219
1220
1221
1222 DateTime start = new DateTime(2010, 3, 21, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone());
1223 CalendarEntry payCalendarEntry = HrServiceLocator.getCalendarEntryService().getCurrentCalendarDates("admin", start);
1224
1225 TimesheetDocument td = TkTestUtils.populateBlankTimesheetDocument(start, principalId);
1226
1227 List<TimeBlock> blocks = new ArrayList<TimeBlock>();
1228
1229
1230 DateTime tbStart1 = new DateTime(2010, 3, 28, 15, 0, 0, 0, zone);
1231 blocks.addAll(TkTestUtils.createUniformTimeBlocks(tbStart1, 1, new BigDecimal("2"), "RGH", jobNumber, workArea, task, groupKey, td.getDocumentId()));
1232
1233
1234 DateTime tbStart2 = new DateTime(2010, 3, 29, 15, 0, 0, 0, zone);
1235 blocks.addAll(TkTestUtils.createUniformTimeBlocks(tbStart2, 1, new BigDecimal("2"), "RGH", jobNumber, workArea, task, groupKey, td.getDocumentId()));
1236
1237
1238 DateTime tbStart3 = new DateTime(2010, 3, 28, 22, 0, 0, 0, zone);
1239 blocks.addAll(TkTestUtils.createUniformTimeBlocks(tbStart3, 1, new BigDecimal("2"), "RGH", jobNumber, workArea, task, groupKey, td.getDocumentId()));
1240 DateTime tbStart4 = new DateTime(2010, 3, 29, 0, 0, 0, 0, zone);
1241 blocks.addAll(TkTestUtils.createUniformTimeBlocks(tbStart4, 1, new BigDecimal("3"), "RGH", jobNumber, workArea, task, groupKey, td.getDocumentId()));
1242
1243
1244 TkTimeBlockAggregate aggregate = new TkTimeBlockAggregate(blocks, payCalendarEntry);
1245
1246
1247 TkTestUtils.verifyAggregateHourSums(principalId, "Pre-Check", new ImmutableMap.Builder<String, BigDecimal>()
1248 .put("RGH", BigDecimal.valueOf(9)).build(), aggregate, 2);
1249
1250
1251
1252
1253 List<LeaveBlock> leaveBlocks = TimesheetUtils.getLeaveBlocksForTimesheet(td);
1254 List<TimeBlock> initialBlocks = TimesheetUtils.getTimesheetTimeblocksForProcessing(td, true);
1255 List<TimeBlock> referenceTimeBlocks = TimesheetUtils.getReferenceTimeBlocks(initialBlocks);
1256
1257
1258
1259 TimesheetUtils.processTimeBlocksWithRuleChange(blocks, referenceTimeBlocks, leaveBlocks, td.getCalendarEntry(), td, HrContext.getPrincipalId());
1260
1261
1262 td = TkServiceLocator.getTimesheetService().getTimesheetDocument(td.getDocumentId());
1263 aggregate = new TkTimeBlockAggregate(td.getTimeBlocks(), payCalendarEntry);
1264
1265 TkTestUtils.verifyAggregateHourSums(principalId, "Post Rules Check", new ImmutableMap.Builder<String, BigDecimal>()
1266 .put("RGH", BigDecimal.valueOf(9))
1267 .put("SHDY", BigDecimal.valueOf(4)).build(),
1268 aggregate,
1269 2);
1270 }
1271
1272
1273 @Test
1274 public void daysTestTimeZone() {
1275
1276
1277 String principalId = "10115";
1278
1279
1280 Long jobNumber = 0L;
1281 String groupKey = "IU-IN";
1282 Long workArea = 1010L;
1283 Long task = 0L;
1284 HrContext.setTargetPrincipalId(principalId);
1285 DateTimeZone zone = HrServiceLocator.getTimezoneService().getTargetUserTimezoneWithFallback();
1286
1287
1288
1289 DateTime start = new DateTime(2010, 3, 21, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone());
1290 CalendarEntry payCalendarEntry = HrServiceLocator.getCalendarEntryService().getCurrentCalendarDates("admin", start);
1291
1292 TimesheetDocument td = TkTestUtils.populateBlankTimesheetDocument(start, principalId);
1293
1294 List<TimeBlock> blocks = new ArrayList<TimeBlock>();
1295
1296
1297 DateTime tbStart1 = new DateTime(2010, 3, 28, 15, 0, 0, 0, zone);
1298 blocks.addAll(TkTestUtils.createUniformTimeBlocks(tbStart1, 1, new BigDecimal("2"), "RGH", jobNumber, workArea, task, groupKey, td.getDocumentId()));
1299
1300
1301 DateTime tbStart2 = new DateTime(2010, 3, 29, 15, 0, 0, 0, zone);
1302 blocks.addAll(TkTestUtils.createUniformTimeBlocks(tbStart2, 1, new BigDecimal("2"), "RGH", jobNumber, workArea, task, groupKey, td.getDocumentId()));
1303
1304
1305 DateTime tbStart3 = new DateTime(2010, 3, 28, 22, 0, 0, 0, zone);
1306 blocks.addAll(TkTestUtils.createUniformTimeBlocks(tbStart3, 1, new BigDecimal("2"), "RGH", jobNumber, workArea, task, groupKey, td.getDocumentId()));
1307 DateTime tbStart4 = new DateTime(2010, 3, 29, 0, 0, 0, 0, zone);
1308 blocks.addAll(TkTestUtils.createUniformTimeBlocks(tbStart4, 1, new BigDecimal("3"), "RGH", jobNumber, workArea, task, groupKey, td.getDocumentId()));
1309
1310
1311 TkTimeBlockAggregate aggregate = new TkTimeBlockAggregate(blocks, payCalendarEntry);
1312
1313
1314 TkTestUtils.verifyAggregateHourSums(principalId, "Pre-Check", new ImmutableMap.Builder<String, BigDecimal>()
1315 .put("RGH", BigDecimal.valueOf(9)).build(), aggregate, 2);
1316
1317
1318
1319
1320 List<LeaveBlock> leaveBlocks = TimesheetUtils.getLeaveBlocksForTimesheet(td);
1321 List<TimeBlock> initialBlocks = TimesheetUtils.getTimesheetTimeblocksForProcessing(td, true);
1322 List<TimeBlock> referenceTimeBlocks = TimesheetUtils.getReferenceTimeBlocks(initialBlocks);
1323
1324
1325
1326 TimesheetUtils.processTimeBlocksWithRuleChange(blocks, referenceTimeBlocks, leaveBlocks, td.getCalendarEntry(), td, HrContext.getPrincipalId());
1327
1328
1329 td = TkServiceLocator.getTimesheetService().getTimesheetDocument(td.getDocumentId());
1330 aggregate = new TkTimeBlockAggregate(td.getTimeBlocks(), payCalendarEntry);
1331
1332 TkTestUtils.verifyAggregateHourSums(principalId, "Post Rules Check", new ImmutableMap.Builder<String, BigDecimal>()
1333 .put("RGH", BigDecimal.valueOf(9))
1334 .put("SHDY2", BigDecimal.valueOf(4)).build(),
1335 aggregate,
1336 2);
1337 HrContext.clearTargetUser();
1338 }
1339
1340 @Test
1341 public void daysTimeTest() {
1342
1343
1344 String principalId = "10116";
1345
1346
1347 Long jobNumber = 0L;
1348 String groupKey = "IU-IN";
1349 Long workArea = 1010L;
1350 Long task = 0L;
1351 HrContext.setTargetPrincipalId(principalId);
1352 DateTimeZone zone = HrServiceLocator.getTimezoneService().getTargetUserTimezoneWithFallback();
1353
1354
1355
1356 DateTime start = new DateTime(2010, 3, 21, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone());
1357 CalendarEntry payCalendarEntry = HrServiceLocator.getCalendarEntryService().getCurrentCalendarDates("admin", start);
1358
1359 TimesheetDocument td = TkTestUtils.populateBlankTimesheetDocument(start, principalId);
1360
1361 List<TimeBlock> blocks = new ArrayList<TimeBlock>();
1362
1363
1364 DateTime tbStart1 = new DateTime(2010, 3, 22, 14, 0, 0, 0, zone);
1365 blocks.addAll(TkTestUtils.createUniformTimeBlocks(tbStart1, 1, new BigDecimal("2"), "RGH", jobNumber, workArea, task, groupKey, td.getDocumentId()));
1366
1367
1368 DateTime tbStart2 = new DateTime(2010, 3, 23, 16, 30, 0, 0, zone);
1369 blocks.addAll(TkTestUtils.createUniformTimeBlocks(tbStart2, 1, new BigDecimal("3.5"), "RGH", jobNumber, workArea, task, groupKey, td.getDocumentId()));
1370
1371
1372 DateTime tbStart3 = new DateTime(2010, 3, 21, 15, 0, 0, 0, zone);
1373 blocks.addAll(TkTestUtils.createUniformTimeBlocks(tbStart3, 1, new BigDecimal("5"), "RGH", jobNumber, workArea, task, groupKey, td.getDocumentId()));
1374
1375
1376 DateTime tbStart4 = new DateTime(2010, 3, 24, 14, 0, 0, 0, zone);
1377 blocks.addAll(TkTestUtils.createUniformTimeBlocks(tbStart4, 4, new BigDecimal("5"), "RGH", jobNumber, workArea, task, groupKey, td.getDocumentId()));
1378
1379
1380 TkTimeBlockAggregate aggregate = new TkTimeBlockAggregate(blocks, payCalendarEntry);
1381
1382
1383 TkTestUtils.verifyAggregateHourSums(principalId, "Pre-Check", new ImmutableMap.Builder<String, BigDecimal>()
1384 .put("RGH", BigDecimal.valueOf(30.5)).build(), aggregate, 1);
1385
1386
1387
1388
1389 List<LeaveBlock> leaveBlocks = TimesheetUtils.getLeaveBlocksForTimesheet(td);
1390 List<TimeBlock> initialBlocks = TimesheetUtils.getTimesheetTimeblocksForProcessing(td, true);
1391 List<TimeBlock> referenceTimeBlocks = TimesheetUtils.getReferenceTimeBlocks(initialBlocks);
1392
1393
1394
1395 TimesheetUtils.processTimeBlocksWithRuleChange(blocks, referenceTimeBlocks, leaveBlocks, td.getCalendarEntry(), td, HrContext.getPrincipalId());
1396
1397
1398 td = TkServiceLocator.getTimesheetService().getTimesheetDocument(td.getDocumentId());
1399 aggregate = new TkTimeBlockAggregate(td.getTimeBlocks(), payCalendarEntry);
1400
1401 TkTestUtils.verifyAggregateHourSums(principalId, "Post Rules Check", new ImmutableMap.Builder<String, BigDecimal>()
1402 .put("RGH", BigDecimal.valueOf(30.5))
1403 .put("SHDT", BigDecimal.valueOf(16.5)).build(),
1404 aggregate,
1405 1);
1406 HrContext.clearTargetUser();
1407 }
1408
1409 @Test
1410 public void timeTest() {
1411
1412
1413 String principalId = "10117";
1414
1415
1416 Long jobNumber = 0L;
1417 String groupKey = "IU-IN";
1418 Long workArea = 1010L;
1419 Long task = 0L;
1420 HrContext.setTargetPrincipalId(principalId);
1421 DateTimeZone zone = HrServiceLocator.getTimezoneService().getTargetUserTimezoneWithFallback();
1422
1423
1424
1425 DateTime start = new DateTime(2010, 3, 21, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone());
1426 CalendarEntry payCalendarEntry = HrServiceLocator.getCalendarEntryService().getCurrentCalendarDates("admin", start);
1427
1428 TimesheetDocument td = TkTestUtils.populateBlankTimesheetDocument(start, principalId);
1429
1430 List<TimeBlock> blocks = new ArrayList<TimeBlock>();
1431
1432
1433 DateTime tbStart1a = new DateTime(2010, 3, 21, 15, 0, 0, 0, zone);
1434 blocks.addAll(TkTestUtils.createUniformTimeBlocks(tbStart1a, 1, new BigDecimal("9"), "RGH", jobNumber, workArea, task, groupKey, td.getDocumentId()));
1435 DateTime tbStart1b = new DateTime(2010, 3, 22, 0, 0, 0, 0, zone);
1436 blocks.addAll(TkTestUtils.createUniformTimeBlocks(tbStart1b, 1, new BigDecimal("3"), "RGH", jobNumber, workArea, task, groupKey, td.getDocumentId()));
1437
1438
1439
1440 DateTime tbStart2 = new DateTime(2010, 3, 22, 3, 0, 0, 0, zone);
1441 blocks.addAll(TkTestUtils.createUniformTimeBlocks(tbStart2, 1, new BigDecimal("6"), "RGH", jobNumber, workArea, task, groupKey, td.getDocumentId()));
1442
1443
1444 DateTime tbStart3 = new DateTime(2010, 3, 22, 22, 0, 0, 0, zone);
1445 blocks.addAll(TkTestUtils.createUniformTimeBlocks(tbStart3, 1, new BigDecimal("1.5"), "RGH", jobNumber, workArea, task, groupKey, td.getDocumentId()));
1446
1447
1448 DateTime tbStart4 = new DateTime(2010, 3, 23, 0, 0, 0, 0, zone);
1449 blocks.addAll(TkTestUtils.createUniformTimeBlocks(tbStart4, 1, new BigDecimal("7"), "RGH", jobNumber, workArea, task, groupKey, td.getDocumentId()));
1450
1451
1452 DateTime tbStart5 = new DateTime(2010, 3, 24, 6, 0, 0, 0, zone);
1453 blocks.addAll(TkTestUtils.createUniformTimeBlocks(tbStart5, 1, new BigDecimal("5"), "RGH", jobNumber, workArea, task, groupKey, td.getDocumentId()));
1454
1455
1456 TkTimeBlockAggregate aggregate = new TkTimeBlockAggregate(blocks, payCalendarEntry);
1457
1458
1459 TkTestUtils.verifyAggregateHourSums(principalId, "Pre-Check", new ImmutableMap.Builder<String, BigDecimal>()
1460 .put("RGH", BigDecimal.valueOf(31.5)).build(), aggregate, 1);
1461
1462
1463
1464
1465 List<LeaveBlock> leaveBlocks = TimesheetUtils.getLeaveBlocksForTimesheet(td);
1466 List<TimeBlock> initialBlocks = TimesheetUtils.getTimesheetTimeblocksForProcessing(td, true);
1467 List<TimeBlock> referenceTimeBlocks = TimesheetUtils.getReferenceTimeBlocks(initialBlocks);
1468
1469
1470
1471 TimesheetUtils.processTimeBlocksWithRuleChange(blocks, referenceTimeBlocks, leaveBlocks, td.getCalendarEntry(), td, HrContext.getPrincipalId());
1472
1473
1474 td = TkServiceLocator.getTimesheetService().getTimesheetDocument(td.getDocumentId());
1475 aggregate = new TkTimeBlockAggregate(td.getTimeBlocks(), payCalendarEntry);
1476
1477 TkTestUtils.verifyAggregateHourSums(principalId, "Post Rules Check", new ImmutableMap.Builder<String, BigDecimal>()
1478 .put("RGH", BigDecimal.valueOf(31.5))
1479 .put("SHTT", BigDecimal.valueOf(19.5)).build(),
1480 aggregate,
1481 1);
1482 HrContext.clearTargetUser();
1483 }
1484
1485
1486 @Ignore
1487 @Test
1488 public void minHoursTest() {
1489
1490
1491 String principalId = "10118";
1492
1493
1494 Long jobNumber = 0L;
1495 String groupKey = "IU-IN";
1496 Long workArea = 1010L;
1497 Long task = 0L;
1498 HrContext.setTargetPrincipalId(principalId);
1499 DateTimeZone zone = HrServiceLocator.getTimezoneService().getTargetUserTimezoneWithFallback();
1500
1501
1502
1503 DateTime start = new DateTime(2010, 3, 21, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone());
1504 CalendarEntry payCalendarEntry = HrServiceLocator.getCalendarEntryService().getCurrentCalendarDates("admin", start);
1505
1506 TimesheetDocument td = TkTestUtils.populateBlankTimesheetDocument(start, principalId);
1507
1508 List<TimeBlock> blocks = new ArrayList<TimeBlock>();
1509
1510
1511 DateTime tbStart1a = new DateTime(2010, 3, 21, 15, 0, 0, 0, zone);
1512 blocks.addAll(TkTestUtils.createUniformTimeBlocks(tbStart1a, 1, new BigDecimal("9"), "RGH", jobNumber, workArea, task, groupKey, td.getDocumentId()));
1513 DateTime tbStart1b = new DateTime(2010, 3, 22, 0, 0, 0, 0, zone);
1514 blocks.addAll(TkTestUtils.createUniformTimeBlocks(tbStart1b, 1, new BigDecimal("3"), "RGH", jobNumber, workArea, task, groupKey, td.getDocumentId()));
1515
1516
1517
1518 DateTime tbStart2 = new DateTime(2010, 3, 22, 3, 0, 0, 0, zone);
1519 blocks.addAll(TkTestUtils.createUniformTimeBlocks(tbStart2, 1, new BigDecimal("6"), "RGH", jobNumber, workArea, task, groupKey, td.getDocumentId()));
1520
1521
1522 DateTime tbStart3 = new DateTime(2010, 3, 22, 22, 0, 0, 0, zone);
1523 blocks.addAll(TkTestUtils.createUniformTimeBlocks(tbStart3, 1, new BigDecimal("1.5"), "RGH", jobNumber, workArea, task, groupKey, td.getDocumentId()));
1524
1525
1526 DateTime tbStart4 = new DateTime(2010, 3, 23, 0, 0, 0, 0, zone);
1527 blocks.addAll(TkTestUtils.createUniformTimeBlocks(tbStart4, 1, new BigDecimal("7"), "RGH", jobNumber, workArea, task, groupKey, td.getDocumentId()));
1528
1529 TkTimeBlockAggregate aggregate = new TkTimeBlockAggregate(blocks, payCalendarEntry);
1530
1531
1532 TkTestUtils.verifyAggregateHourSums(principalId, "Pre-Check", new ImmutableMap.Builder<String, BigDecimal>()
1533 .put("RGH", BigDecimal.valueOf(26.5)).build(), aggregate, 1);
1534
1535
1536
1537
1538 List<LeaveBlock> leaveBlocks = TimesheetUtils.getLeaveBlocksForTimesheet(td);
1539 List<TimeBlock> initialBlocks = TimesheetUtils.getTimesheetTimeblocksForProcessing(td, true);
1540 List<TimeBlock> referenceTimeBlocks = TimesheetUtils.getReferenceTimeBlocks(initialBlocks);
1541
1542
1543
1544 TimesheetUtils.processTimeBlocksWithRuleChange(blocks, referenceTimeBlocks, leaveBlocks, td.getCalendarEntry(), td, HrContext.getPrincipalId());
1545
1546
1547 td = TkServiceLocator.getTimesheetService().getTimesheetDocument(td.getDocumentId());
1548 aggregate = new TkTimeBlockAggregate(td.getTimeBlocks(), payCalendarEntry);
1549
1550 TkTestUtils.verifyAggregateHourSums(principalId, "Post Rules Check", new ImmutableMap.Builder<String, BigDecimal>()
1551 .put("RGH", BigDecimal.valueOf(26.5))
1552 .put("SHTT", BigDecimal.valueOf(7.5))
1553 .put("SHMH", BigDecimal.valueOf(12)).build(),
1554 aggregate,
1555 1);
1556 HrContext.clearTargetUser();
1557 }
1558 }