1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.lm.leavepayout.service;
17
18 import static org.junit.Assert.*;
19
20 import java.math.BigDecimal;
21 import java.util.ArrayList;
22 import java.util.Date;
23 import java.util.List;
24 import java.util.Map;
25 import java.util.Map.Entry;
26
27 import org.apache.commons.lang.time.DateUtils;
28 import org.junit.After;
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.kuali.hr.lm.LMConstants;
32 import org.kuali.hr.lm.accrual.AccrualCategoryRule;
33 import org.kuali.hr.lm.leavepayout.LeavePayout;
34 import org.kuali.hr.lm.employeeoverride.EmployeeOverride;
35 import org.kuali.hr.lm.leaveSummary.LeaveSummary;
36 import org.kuali.hr.lm.leaveSummary.LeaveSummaryRow;
37 import org.kuali.hr.lm.leaveblock.LeaveBlock;
38 import org.kuali.hr.lm.leavecalendar.LeaveCalendarDocument;
39 import org.kuali.hr.test.KPMETestCase;
40 import org.kuali.hr.time.calendar.CalendarEntries;
41 import org.kuali.hr.time.service.base.TkServiceLocator;
42 import org.kuali.hr.time.timesheet.TimesheetDocument;
43 import org.kuali.hr.time.util.TKUtils;
44 import org.kuali.rice.krad.util.ObjectUtils;
45
46 public class LeavePayoutServiceTest extends KPMETestCase {
47
48
49
50
51 private final String USER_ID = "testUser1";
52
53 private LeaveCalendarDocument janLCD;
54 private CalendarEntries janEntry;
55 private LeaveCalendarDocument decLCD;
56 private CalendarEntries decEntry;
57
58 private Date janStart;
59 private Date janEnd;
60 private Date decStart;
61 private Date decEnd;
62
63 private final String JAN_ID = "5001";
64 private final String DEC_ID = "5000";
65
66
67
68
69
70 private final String TS_USER_ID = "testUser2";
71
72 private TimesheetDocument endJanTSD;
73 private CalendarEntries endJanTSDEntry;
74 private TimesheetDocument midJanTSD;
75 private CalendarEntries midJanTSDEntry;
76 private TimesheetDocument endDecTSD;
77 private CalendarEntries endDecTSDEntry;
78 private TimesheetDocument midDecTSD;
79 private CalendarEntries midDecTSDEntry;
80
81 private Date midJanStart;
82 private Date midJanEnd;
83 private Date endDecStart;
84 private Date endDecEnd;
85 private Date midDecStart;
86 private Date midDecEnd;
87
88 private final String TSD_MID_DEC_PERIOD_ID = "5000";
89 private final String TSD_END_DEC_PERIOD_ID = "5001";
90 private final String TSD_MID_JAN_PERIOD_ID = "5002";
91 private final String TSD_END_JAN_PERIOD_ID = "5003";
92
93
94
95
96
97 private final String OD_XFER = "5000";
98 private final String YE_XFER = "5001";
99 private final String LA_XFER = "5002";
100 private final String OD_XFER_MAC = "5003";
101 private final String YE_XFER_MAC = "5004";
102 private final String LA_XFER_MAC = "5005";
103 private final String OD_LOSE = "5006";
104 private final String YE_LOSE = "5007";
105 private final String LA_LOSE = "5008";
106 private final String OD_LOSE_MAC = "5009";
107 private final String YE_LOSE_MAC = "5010";
108 private final String LA_LOSE_MAC = "5011";
109 private final String YE_XFER_EO = "5012";
110 private final java.sql.Date LM_FROM = TKUtils.formatDateString("11/01/2012");
111 private final java.sql.Date LM_TO = TKUtils.formatDateString("02/01/2013");
112 private final java.sql.Date TK_FROM = TKUtils.formatDateString("11/01/2011");
113 private final java.sql.Date TK_TO = TKUtils.formatDateString("02/01/2012");
114
115 @Before
116 public void setUp() throws Exception {
117 super.setUp();
118 TkServiceLocator.getAccrualService().runAccrual(USER_ID,LM_FROM,LM_TO,true,USER_ID);
119 janLCD = TkServiceLocator.getLeaveCalendarService().getLeaveCalendarDocument(JAN_ID);
120 janEntry = janLCD.getCalendarEntry();
121 janStart = janEntry.getBeginPeriodDate();
122 janEnd = janEntry.getEndPeriodDate();
123 decLCD = TkServiceLocator.getLeaveCalendarService().getLeaveCalendarDocument(DEC_ID);
124 decEntry = decLCD.getCalendarEntry();
125 decStart = decEntry.getBeginPeriodDate();
126 decEnd = decEntry.getEndPeriodDate();
127 }
128
129 @After
130 public void tearDown() throws Exception {
131 super.tearDown();
132 }
133
134
135
136
137
138
139
140
141
142 @Test
143 public void testInitializePayoutNullAccrualRule() throws Exception {
144 LeavePayout lp = new LeavePayout();
145
146 java.sql.Date effectiveDate = new java.sql.Date(DateUtils.addDays(decStart,3).getTime());
147 lp = TkServiceLocator.getLeavePayoutService().initializePayout(USER_ID, null, BigDecimal.ZERO, effectiveDate);
148 assertNull(lp);
149 }
150
151 @Test
152 public void testInitializePayoutNullLeaveSummary() throws Exception {
153 LeavePayout lp = new LeavePayout();
154
155 lp = TkServiceLocator.getLeavePayoutService().initializePayout(USER_ID, OD_XFER, null, TKUtils.getCurrentDate());
156 assertNull(lp);
157 }
158
159 @Test
160 public void testInitializePayoutNullAccrualRuleNullLeaveSummary() {
161 LeavePayout lp = new LeavePayout();
162 lp = TkServiceLocator.getLeavePayoutService().initializePayout(USER_ID, null, null, TKUtils.getCurrentDate());
163 assertNull(lp);
164 }
165
166 @Test
167 public void testInitializePayoutOnDemand() throws Exception {
168 LeavePayout lp = new LeavePayout();
169 LeaveSummary summary = TkServiceLocator.getLeaveSummaryService().getLeaveSummary(USER_ID, decEntry);
170 LeaveSummaryRow aRow = summary.getLeaveSummaryRowForAccrualCategory(OD_XFER);
171 java.sql.Date effectiveDate = new java.sql.Date(DateUtils.addDays(decStart,3).getTime());
172 lp = TkServiceLocator.getLeavePayoutService().initializePayout(USER_ID, OD_XFER, aRow.getAccruedBalance(), effectiveDate);
173 assertEquals("payoutOnDemand payout amount", (new BigDecimal(1)).longValue(), lp.getPayoutAmount().longValue());
174 assertEquals("payoutOnDemand forfeited amount",(new BigDecimal(0)).longValue(), lp.getForfeitedAmount().longValue());
175
176 }
177
178 @Test
179 public void testInitializePayoutOnDemandWithForfeiture() throws Exception {
180 LeavePayout lp = new LeavePayout();
181 LeaveSummary summary = TkServiceLocator.getLeaveSummaryService().getLeaveSummary(USER_ID, janEntry);
182 LeaveSummaryRow aRow = summary.getLeaveSummaryRowForAccrualCategory(OD_XFER);
183 java.sql.Date effectiveDate = new java.sql.Date(DateUtils.addDays(janStart,3).getTime());
184 lp = TkServiceLocator.getLeavePayoutService().initializePayout(USER_ID, OD_XFER, aRow.getAccruedBalance(), effectiveDate);
185 assertEquals("payoutOnDemand payout amount", (new BigDecimal(10)).longValue(), lp.getPayoutAmount().longValue());
186 assertEquals("payoutOnDemand forfeited amount", (new BigDecimal(7)).longValue(), lp.getForfeitedAmount().longValue());
187
188 }
189
190 @Test
191 public void testInitializePayoutOnYearEnd() throws Exception {
192 LeavePayout lp = new LeavePayout();
193 TkServiceLocator.getLeaveBlockService().deleteLeaveBlocksForDocumentId(DEC_ID);
194 LeaveSummary summary = TkServiceLocator.getLeaveSummaryService().getLeaveSummary(USER_ID, janEntry);
195 LeaveSummaryRow aRow = summary.getLeaveSummaryRowForAccrualCategory(YE_XFER);
196 java.sql.Date effectiveDate = new java.sql.Date(DateUtils.addDays(janStart,3).getTime());
197 lp = TkServiceLocator.getLeavePayoutService().initializePayout(USER_ID, YE_XFER, aRow.getAccruedBalance(), effectiveDate);
198 assertEquals("payoutOnDemand payout amount", (new BigDecimal(1)).longValue(), lp.getPayoutAmount().longValue());
199 assertEquals("payoutOnDemand forfeited amount",(new BigDecimal(0)).longValue(), lp.getForfeitedAmount().longValue());
200
201 }
202
203 @Test
204 public void testInitializePayoutOnYearEndWithForfeiture() throws Exception {
205 LeavePayout lp = new LeavePayout();
206 LeaveSummary summary = TkServiceLocator.getLeaveSummaryService().getLeaveSummary(USER_ID, janEntry);
207 LeaveSummaryRow aRow = summary.getLeaveSummaryRowForAccrualCategory(YE_XFER);
208 java.sql.Date effectiveDate = new java.sql.Date(DateUtils.addDays(janStart,3).getTime());
209 lp = TkServiceLocator.getLeavePayoutService().initializePayout(USER_ID, YE_XFER, aRow.getAccruedBalance(), effectiveDate);
210 assertEquals("payoutOnDemand payout amount", (new BigDecimal(10)).longValue(), lp.getPayoutAmount().longValue());
211 assertEquals("payoutOnDemand forfeited amount", (new BigDecimal(7)).longValue(), lp.getForfeitedAmount().longValue());
212
213 }
214
215 @Test
216 public void testInitializePayoutOnLeaveApprove() throws Exception {
217 LeavePayout lp = new LeavePayout();
218 LeaveSummary summary = TkServiceLocator.getLeaveSummaryService().getLeaveSummary(USER_ID, decEntry);
219 LeaveSummaryRow aRow = summary.getLeaveSummaryRowForAccrualCategory(LA_XFER);
220 java.sql.Date effectiveDate = new java.sql.Date(DateUtils.addDays(decStart,3).getTime());
221 lp = TkServiceLocator.getLeavePayoutService().initializePayout(USER_ID, LA_XFER, aRow.getAccruedBalance(), effectiveDate);
222 assertEquals("payoutOnDemand payout amount", (new BigDecimal(1)).longValue(), lp.getPayoutAmount().longValue());
223 assertEquals("payoutOnDemand forfeited amount",(new BigDecimal(0)).longValue(), lp.getForfeitedAmount().longValue());
224
225 }
226
227 @Test
228 public void testInitializePayoutOnLeaveApproveWithForfeiture() throws Exception {
229 LeavePayout lp = new LeavePayout();
230 LeaveSummary summary = TkServiceLocator.getLeaveSummaryService().getLeaveSummary(USER_ID, janEntry);
231 LeaveSummaryRow aRow = summary.getLeaveSummaryRowForAccrualCategory(LA_XFER);
232 java.sql.Date effectiveDate = new java.sql.Date(DateUtils.addDays(janStart,3).getTime());
233 lp = TkServiceLocator.getLeavePayoutService().initializePayout(USER_ID, LA_XFER, aRow.getAccruedBalance(), effectiveDate);
234 assertEquals("payoutOnDemand payout amount", (new BigDecimal(10)).longValue(), lp.getPayoutAmount().longValue());
235 assertEquals("payoutOnDemand forfeited amount", (new BigDecimal(7)).longValue(), lp.getForfeitedAmount().longValue());
236
237 }
238
239 @Test
240 public void testInitializePayoutOnDemandMaxCarryOver() throws Exception {
241
242 LeavePayout lp = new LeavePayout();
243 LeaveSummary summary = TkServiceLocator.getLeaveSummaryService().getLeaveSummary(USER_ID, decEntry);
244 LeaveSummaryRow aRow = summary.getLeaveSummaryRowForAccrualCategory(OD_XFER_MAC);
245 java.sql.Date effectiveDate = new java.sql.Date(DateUtils.addDays(decStart,3).getTime());
246 lp = TkServiceLocator.getLeavePayoutService().initializePayout(USER_ID, OD_XFER_MAC, aRow.getAccruedBalance(), effectiveDate);
247 assertEquals("payoutOnDemand payout amount", (new BigDecimal(1)).longValue(), lp.getPayoutAmount().longValue());
248 assertEquals("payoutOnDemand forfeited amount",(new BigDecimal(0)).longValue(), lp.getForfeitedAmount().longValue());
249
250 }
251
252 @Test
253 public void testInitializePayoutOnYearEndMaxCarryOver() throws Exception {
254
255
256
257
258
259
260
261
262
263
264
265
266
267 LeavePayout lp = new LeavePayout();
268 LeaveSummary summary = TkServiceLocator.getLeaveSummaryService().getLeaveSummary(USER_ID, decEntry);
269 LeaveSummaryRow aRow = summary.getLeaveSummaryRowForAccrualCategory(YE_XFER_MAC);
270 java.sql.Date effectiveDate = new java.sql.Date(DateUtils.addDays(decStart,3).getTime());
271 lp = TkServiceLocator.getLeavePayoutService().initializePayout(USER_ID, YE_XFER_MAC, aRow.getAccruedBalance(), effectiveDate);
272 assertEquals("payoutOnDemand payout amount", (new BigDecimal(6)).longValue(), lp.getPayoutAmount().longValue());
273 assertEquals("payoutOnDemand forfeited amount", (new BigDecimal(0)).longValue(), lp.getForfeitedAmount().longValue());
274
275 }
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309 @Test
310 public void testInitializePayoutOnYearEndMaxCarryOverWithForfeiture() throws Exception {
311
312 LeavePayout lp = new LeavePayout();
313 LeaveSummary summary = TkServiceLocator.getLeaveSummaryService().getLeaveSummary(USER_ID, janEntry);
314 LeaveSummaryRow aRow = summary.getLeaveSummaryRowForAccrualCategory(YE_XFER_MAC);
315 java.sql.Date effectiveDate = new java.sql.Date(DateUtils.addDays(janStart,3).getTime());
316 lp = TkServiceLocator.getLeavePayoutService().initializePayout(USER_ID, YE_XFER_MAC, aRow.getAccruedBalance(), effectiveDate);
317 assertEquals("payoutOnDemand payout amount", (new BigDecimal(10)).longValue(), lp.getPayoutAmount().longValue());
318 assertEquals("payoutOnDemand forfeited amount", (new BigDecimal(12)).longValue(), lp.getForfeitedAmount().longValue());
319
320 }
321
322 @Test
323 public void testInitializePayoutOnLeaveApproveMaxCarryOver() throws Exception {
324 LeavePayout lp = new LeavePayout();
325 LeaveSummary summary = TkServiceLocator.getLeaveSummaryService().getLeaveSummary(USER_ID, decEntry);
326 LeaveSummaryRow aRow = summary.getLeaveSummaryRowForAccrualCategory(LA_XFER_MAC);
327 java.sql.Date effectiveDate = new java.sql.Date(DateUtils.addDays(decStart,3).getTime());
328 lp = TkServiceLocator.getLeavePayoutService().initializePayout(USER_ID, LA_XFER_MAC, aRow.getAccruedBalance(), effectiveDate);
329 assertEquals("payoutOnDemand payout amount", (new BigDecimal(1)).longValue(), lp.getPayoutAmount().longValue());
330 assertEquals("payoutOnDemand forfeited amount",(new BigDecimal(0)).longValue(), lp.getForfeitedAmount().longValue());
331
332 }
333
334 @Test
335 public void testInitializePayoutWithOverrides() throws Exception {
336 LeavePayout lp = new LeavePayout();
337 LeaveSummary summary = TkServiceLocator.getLeaveSummaryService().getLeaveSummary(USER_ID, janEntry);
338 LeaveSummaryRow aRow = summary.getLeaveSummaryRowForAccrualCategory(YE_XFER_EO);
339 java.sql.Date effectiveDate = new java.sql.Date(DateUtils.addDays(janStart,3).getTime());
340 lp = TkServiceLocator.getLeavePayoutService().initializePayout(USER_ID, YE_XFER_EO, aRow.getAccruedBalance(), effectiveDate);
341 assertEquals("payoutOnDemand payout amount", (new BigDecimal(7)).longValue(), lp.getPayoutAmount().longValue());
342 assertEquals("payoutOnDemand forfeited amount",(new BigDecimal(20)).longValue(), lp.getForfeitedAmount().longValue());
343
344
345 }
346
347
348
349
350 @Test
351 public void testPayoutNullLeavePayout() {
352 LeavePayout LeavePayout = null;
353 try {
354 LeavePayout = TkServiceLocator.getLeavePayoutService().payout(LeavePayout);
355 } catch (RuntimeException re) {
356 assertTrue(re.getMessage().contains("did not supply a valid LeavePayout object"));
357 }
358 }
359
360 @Test
361 public void testPayoutWithZeroPayoutAmount() throws Exception {
362 LeavePayout lp = new LeavePayout();
363 LeaveSummary summary = TkServiceLocator.getLeaveSummaryService().getLeaveSummary(USER_ID, janEntry);
364 LeaveSummaryRow aRow = summary.getLeaveSummaryRowForAccrualCategory(YE_LOSE);
365 java.sql.Date effectiveDate = new java.sql.Date(DateUtils.addDays(janStart,3).getTime());
366
367 lp.setPayoutAmount(BigDecimal.ZERO);
368 lp = TkServiceLocator.getLeavePayoutService().payout(lp);
369 LeaveBlock forfeitedLeaveBlock = TkServiceLocator.getLeaveBlockService().getLeaveBlock(lp.getForfeitedLeaveBlockId());
370 LeaveBlock payoutLeaveBlock = TkServiceLocator.getLeaveBlockService().getLeaveBlock(lp.getPayoutLeaveBlockId());
371 LeaveBlock payoutFromLeaveBlock = TkServiceLocator.getLeaveBlockService().getLeaveBlock(lp.getPayoutFromLeaveBlockId());
372 assertTrue("forfeited leave block should not exist", ObjectUtils.isNull(forfeitedLeaveBlock));
373 assertTrue("accrued leave block should not exist",ObjectUtils.isNull(payoutLeaveBlock));
374 assertTrue("debited leave block should not exist",ObjectUtils.isNull(payoutFromLeaveBlock));
375 }
376
377 @Test
378 public void testPayoutWithZeroForfeiture() throws Exception {
379 LeavePayout lp = new LeavePayout();
380 LeaveSummary summary = TkServiceLocator.getLeaveSummaryService().getLeaveSummary(USER_ID, decEntry);
381 LeaveSummaryRow aRow = summary.getLeaveSummaryRowForAccrualCategory(OD_XFER);
382 java.sql.Date effectiveDate = new java.sql.Date(DateUtils.addDays(decStart,3).getTime());
383 lp = TkServiceLocator.getLeavePayoutService().initializePayout(USER_ID, OD_XFER, aRow.getAccruedBalance(), effectiveDate);
384 lp = TkServiceLocator.getLeavePayoutService().payout(lp);
385 LeaveBlock forfeitedLeaveBlock = TkServiceLocator.getLeaveBlockService().getLeaveBlock(lp.getForfeitedLeaveBlockId());
386 LeaveBlock payoutLeaveBlock = TkServiceLocator.getLeaveBlockService().getLeaveBlock(lp.getPayoutLeaveBlockId());
387 LeaveBlock payoutFromLeaveBlock = TkServiceLocator.getLeaveBlockService().getLeaveBlock(lp.getPayoutFromLeaveBlockId());
388 assertEquals("accrued leave block leave amount incorrect", (new BigDecimal(1)).longValue(), payoutLeaveBlock.getLeaveAmount().longValue());
389 assertTrue("forfeited leave block should not exist",ObjectUtils.isNull(forfeitedLeaveBlock));
390 assertEquals("payouted leave block leave amount incorrect", (new BigDecimal(-1)).longValue(), payoutFromLeaveBlock.getLeaveAmount().longValue());
391 }
392
393 @Test
394 public void testPayoutWithThreeLeaveBlocks() throws Exception {
395 LeavePayout lp = new LeavePayout();
396 LeaveSummary summary = TkServiceLocator.getLeaveSummaryService().getLeaveSummary(USER_ID, janEntry);
397 LeaveSummaryRow aRow = summary.getLeaveSummaryRowForAccrualCategory(YE_XFER);
398 java.sql.Date effectiveDate = new java.sql.Date(DateUtils.addDays(janStart,3).getTime());
399 lp = TkServiceLocator.getLeavePayoutService().initializePayout(USER_ID, YE_XFER, aRow.getAccruedBalance(), effectiveDate);
400 lp = TkServiceLocator.getLeavePayoutService().payout(lp);
401 LeaveBlock forfeitedLeaveBlock = TkServiceLocator.getLeaveBlockService().getLeaveBlock(lp.getForfeitedLeaveBlockId());
402 LeaveBlock payoutLeaveBlock = TkServiceLocator.getLeaveBlockService().getLeaveBlock(lp.getPayoutLeaveBlockId());
403 LeaveBlock payoutFromLeaveBlock = TkServiceLocator.getLeaveBlockService().getLeaveBlock(lp.getPayoutFromLeaveBlockId());
404 assertEquals("forfeited leave block leave amount incorrect", (new BigDecimal(-7)).longValue(), forfeitedLeaveBlock.getLeaveAmount().longValue());
405 assertEquals((new BigDecimal(10)).longValue(), payoutLeaveBlock.getLeaveAmount().longValue());
406 assertEquals((new BigDecimal(-10)).longValue(), payoutFromLeaveBlock.getLeaveAmount().longValue());
407 }
408
409
410
411 @Test
412 public void testgetEligiblePayoutsLeaveApprove() throws Exception {
413 Map<String, ArrayList<String>> eligiblePayouts = TkServiceLocator.getLeavePayoutService().getEligiblePayouts(janEntry, USER_ID);
414 assertEquals(2, eligiblePayouts.get(LMConstants.MAX_BAL_ACTION_FREQ.LEAVE_APPROVE).size());
415 assertEquals(3, eligiblePayouts.get(LMConstants.MAX_BAL_ACTION_FREQ.YEAR_END).size());
416 assertEquals(2, eligiblePayouts.get(LMConstants.MAX_BAL_ACTION_FREQ.ON_DEMAND).size());
417 List<AccrualCategoryRule> rules = new ArrayList<AccrualCategoryRule>();
418 for(String eligiblePayout : eligiblePayouts.get(LMConstants.MAX_BAL_ACTION_FREQ.LEAVE_APPROVE))
419 rules.add(TkServiceLocator.getAccrualCategoryRuleService().getAccrualCategoryRule(eligiblePayout));
420
421 LeaveSummary summary = TkServiceLocator.getLeaveSummaryService().getLeaveSummary(USER_ID, janEntry);
422 for(AccrualCategoryRule aRule : rules) {
423 LeaveSummaryRow row = summary.getLeaveSummaryRowForAccrualCategory(aRule.getLmAccrualCategoryId());
424 assertNotNull("eligible accrual category has no balance limit",ObjectUtils.isNotNull(aRule.getMaxBalance()));
425 assertTrue("accrual category not eligible for payout",row.getAccruedBalance().compareTo(aRule.getMaxBalance()) > 0);
426 }
427 }
428
429 @Test
430 public void testgetEligiblePayoutsYearEnd() throws Exception {
431 Map<String, ArrayList<String>> eligiblePayouts = TkServiceLocator.getLeavePayoutService().getEligiblePayouts(janEntry, USER_ID);
432 assertEquals(2, eligiblePayouts.get(LMConstants.MAX_BAL_ACTION_FREQ.LEAVE_APPROVE).size());
433 assertEquals(3, eligiblePayouts.get(LMConstants.MAX_BAL_ACTION_FREQ.YEAR_END).size());
434 assertEquals(2, eligiblePayouts.get(LMConstants.MAX_BAL_ACTION_FREQ.ON_DEMAND).size());
435 List<AccrualCategoryRule> rules = new ArrayList<AccrualCategoryRule>();
436 for(String eligiblePayout : eligiblePayouts.get(LMConstants.MAX_BAL_ACTION_FREQ.YEAR_END))
437 rules.add(TkServiceLocator.getAccrualCategoryRuleService().getAccrualCategoryRule(eligiblePayout));
438
439
440
441
442 LeaveSummary summary = TkServiceLocator.getLeaveSummaryService().getLeaveSummary(USER_ID, janEntry);
443 for(AccrualCategoryRule aRule : rules) {
444 LeaveSummaryRow row = summary.getLeaveSummaryRowForAccrualCategory(aRule.getLmAccrualCategoryId());
445 BigDecimal maxBalance = aRule.getMaxBalance();
446 EmployeeOverride mbOverride = TkServiceLocator.getEmployeeOverrideService().getEmployeeOverride(USER_ID,
447 "testLP",
448 row.getAccrualCategory(),
449 "MB",
450 janEntry.getBeginPeriodDate());
451 if(ObjectUtils.isNotNull(mbOverride))
452 maxBalance = new BigDecimal(mbOverride.getOverrideValue());
453 assertNotNull("eligible accrual category has no balance limit",maxBalance);
454 assertTrue("accrual category not eligible for payout",row.getAccruedBalance().compareTo(maxBalance) > 0);
455 }
456 }
457
458 @Test
459 public void testgetEligiblePayoutsOnDemand() throws Exception {
460 Map<String, ArrayList<String>> eligiblePayouts = TkServiceLocator.getLeavePayoutService().getEligiblePayouts(janEntry, USER_ID);
461 assertEquals(2, eligiblePayouts.get(LMConstants.MAX_BAL_ACTION_FREQ.LEAVE_APPROVE).size());
462 assertEquals(3, eligiblePayouts.get(LMConstants.MAX_BAL_ACTION_FREQ.YEAR_END).size());
463 assertEquals(2, eligiblePayouts.get(LMConstants.MAX_BAL_ACTION_FREQ.ON_DEMAND).size());
464 List<AccrualCategoryRule> rules = new ArrayList<AccrualCategoryRule>();
465 for(String eligiblePayout : eligiblePayouts.get(LMConstants.MAX_BAL_ACTION_FREQ.ON_DEMAND))
466 rules.add(TkServiceLocator.getAccrualCategoryRuleService().getAccrualCategoryRule(eligiblePayout));
467
468 LeaveSummary summary = TkServiceLocator.getLeaveSummaryService().getLeaveSummary(USER_ID, janEntry);
469 for(AccrualCategoryRule aRule : rules) {
470 LeaveSummaryRow row = summary.getLeaveSummaryRowForAccrualCategory(aRule.getLmAccrualCategoryId());
471 assertNotNull("eligible accrual category has no balance limit",ObjectUtils.isNotNull(aRule.getMaxBalance()));
472 assertTrue("accrual category not eligible for payout",row.getAccruedBalance().compareTo(aRule.getMaxBalance()) > 0);
473 }
474 }
475
476 @Test
477 public void testgetEligiblePayoutsOnYearEndCaseOne() throws Exception {
478
479 Map<String, ArrayList<String>> eligiblePayouts = TkServiceLocator.getLeavePayoutService().getEligiblePayouts(decEntry, USER_ID);
480 assertEquals(2, eligiblePayouts.get(LMConstants.MAX_BAL_ACTION_FREQ.LEAVE_APPROVE).size());
481 assertEquals(0, eligiblePayouts.get(LMConstants.MAX_BAL_ACTION_FREQ.YEAR_END).size());
482 assertEquals(2, eligiblePayouts.get(LMConstants.MAX_BAL_ACTION_FREQ.ON_DEMAND).size());
483 List<AccrualCategoryRule> rules = new ArrayList<AccrualCategoryRule>();
484 for(String eligiblePayout : eligiblePayouts.get(LMConstants.MAX_BAL_ACTION_FREQ.YEAR_END))
485 rules.add(TkServiceLocator.getAccrualCategoryRuleService().getAccrualCategoryRule(eligiblePayout));
486
487 LeaveSummary summary = TkServiceLocator.getLeaveSummaryService().getLeaveSummary(USER_ID, decEntry);
488 for(AccrualCategoryRule aRule : rules) {
489 LeaveSummaryRow row = summary.getLeaveSummaryRowForAccrualCategory(aRule.getLmAccrualCategoryId());
490 assertNotNull("eligible accrual category has no balance limit",ObjectUtils.isNotNull(aRule.getMaxBalance()));
491 assertTrue("accrual category not eligible for payout",row.getAccruedBalance().compareTo(aRule.getMaxBalance()) > 0);
492 }
493 }
494
495 @Test
496 public void testgetEligiblePayoutsOnYearEndCaseTwo() throws Exception {
497
498 Map<String, ArrayList<String>> eligiblePayouts = TkServiceLocator.getLeavePayoutService().getEligiblePayouts(janEntry, USER_ID);
499 assertEquals(2, eligiblePayouts.get(LMConstants.MAX_BAL_ACTION_FREQ.LEAVE_APPROVE).size());
500 assertEquals(3, eligiblePayouts.get(LMConstants.MAX_BAL_ACTION_FREQ.YEAR_END).size());
501 assertEquals(2, eligiblePayouts.get(LMConstants.MAX_BAL_ACTION_FREQ.ON_DEMAND).size());
502 List<AccrualCategoryRule> rules = new ArrayList<AccrualCategoryRule>();
503 for(String eligiblePayout : eligiblePayouts.get(LMConstants.MAX_BAL_ACTION_FREQ.YEAR_END))
504 rules.add(TkServiceLocator.getAccrualCategoryRuleService().getAccrualCategoryRule(eligiblePayout));
505
506 LeaveSummary summary = TkServiceLocator.getLeaveSummaryService().getLeaveSummary(USER_ID, janEntry);
507 for(AccrualCategoryRule aRule : rules) {
508 LeaveSummaryRow row = summary.getLeaveSummaryRowForAccrualCategory(aRule.getLmAccrualCategoryId());
509 BigDecimal maxBalance = aRule.getMaxBalance();
510 EmployeeOverride mbOverride = TkServiceLocator.getEmployeeOverrideService().getEmployeeOverride(USER_ID,
511 "testLP",
512 row.getAccrualCategory(),
513 "MB",
514 janEntry.getBeginPeriodDate());
515 EmployeeOverride macOverride = TkServiceLocator.getEmployeeOverrideService().getEmployeeOverride(USER_ID,
516 "testLP",
517 row.getAccrualCategory(),
518 "MAC",
519 janEntry.getBeginPeriodDate());
520 if(ObjectUtils.isNotNull(mbOverride) && ObjectUtils.isNotNull(macOverride))
521 maxBalance = new BigDecimal(Math.min(mbOverride.getOverrideValue(), macOverride.getOverrideValue()));
522 else {
523 if(ObjectUtils.isNotNull(macOverride))
524 maxBalance = new BigDecimal(macOverride.getOverrideValue());
525 if(ObjectUtils.isNotNull(mbOverride))
526 maxBalance = new BigDecimal(mbOverride.getOverrideValue());
527 }
528 assertNotNull("eligible accrual category has no balance limit",ObjectUtils.isNotNull(maxBalance));
529 assertTrue("accrual category not eligible for payout",row.getAccruedBalance().compareTo(maxBalance) > 0);
530 }
531 }
532
533 @Test
534 public void testSubmitToWorkflow() {
535 assertNull(null);
536 }
537
538
539
540
541
542
543
544 @Test
545 public void testgetEligiblePayoutsLeaveApproveForTimesheetCaseOne() throws Exception {
546
547 TkServiceLocator.getAccrualService().runAccrual(TS_USER_ID,TK_FROM,TK_TO,true,TS_USER_ID);
548 midDecTSD = TkServiceLocator.getTimesheetService().getTimesheetDocument(TSD_MID_DEC_PERIOD_ID);
549 midDecTSDEntry = midDecTSD.getCalendarEntry();
550
551 Map<String, ArrayList<String>> eligiblePayouts = TkServiceLocator.getLeavePayoutService().getEligiblePayouts(midDecTSDEntry, TS_USER_ID);
552
553 assertEquals(2, eligiblePayouts.get(LMConstants.MAX_BAL_ACTION_FREQ.LEAVE_APPROVE).size());
554
555
556
557 List<AccrualCategoryRule> rules = new ArrayList<AccrualCategoryRule>();
558 for(String eligiblePayout : eligiblePayouts.get(LMConstants.MAX_BAL_ACTION_FREQ.LEAVE_APPROVE))
559 rules.add(TkServiceLocator.getAccrualCategoryRuleService().getAccrualCategoryRule(eligiblePayout));
560
561 LeaveSummary summary = TkServiceLocator.getLeaveSummaryService().getLeaveSummary(TS_USER_ID, midDecTSDEntry);
562 for(AccrualCategoryRule aRule : rules) {
563 LeaveSummaryRow row = summary.getLeaveSummaryRowForAccrualCategory(aRule.getLmAccrualCategoryId());
564 assertNotNull("eligible accrual category has no balance limit",ObjectUtils.isNotNull(aRule.getMaxBalance()));
565 assertTrue("accrual category not eligible for payout",row.getAccruedBalance().compareTo(aRule.getMaxBalance()) > 0);
566 }
567 }
568
569 @Test
570 public void testgetEligiblePayoutsYearEndForTimesheetCaseOne() throws Exception {
571
572 TkServiceLocator.getAccrualService().runAccrual(TS_USER_ID,TK_FROM,TK_TO,true,TS_USER_ID);
573 midDecTSD = TkServiceLocator.getTimesheetService().getTimesheetDocument(TSD_MID_DEC_PERIOD_ID);
574 midDecTSDEntry = midDecTSD.getCalendarEntry();
575
576 Map<String, ArrayList<String>> eligiblePayouts = TkServiceLocator.getLeavePayoutService().getEligiblePayouts(midDecTSDEntry, TS_USER_ID);
577
578 assertEquals(0, eligiblePayouts.get(LMConstants.MAX_BAL_ACTION_FREQ.YEAR_END).size());
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608 }
609
610 @Test
611 public void testgetEligiblePayoutsOnDemandForTimesheetCaseOne() throws Exception {
612
613 TkServiceLocator.getAccrualService().runAccrual(TS_USER_ID,TK_FROM,TK_TO,true,TS_USER_ID);
614 midDecTSD = TkServiceLocator.getTimesheetService().getTimesheetDocument(TSD_MID_DEC_PERIOD_ID);
615 midDecTSDEntry = midDecTSD.getCalendarEntry();
616
617 Map<String, ArrayList<String>> eligiblePayouts = TkServiceLocator.getLeavePayoutService().getEligiblePayouts(midDecTSDEntry, TS_USER_ID);
618
619 assertEquals(2, eligiblePayouts.get(LMConstants.MAX_BAL_ACTION_FREQ.ON_DEMAND).size());
620
621
622
623 List<AccrualCategoryRule> rules = new ArrayList<AccrualCategoryRule>();
624 for(String eligiblePayout : eligiblePayouts.get(LMConstants.MAX_BAL_ACTION_FREQ.ON_DEMAND))
625 rules.add(TkServiceLocator.getAccrualCategoryRuleService().getAccrualCategoryRule(eligiblePayout));
626
627 LeaveSummary summary = TkServiceLocator.getLeaveSummaryService().getLeaveSummary(TS_USER_ID, midDecTSDEntry);
628 for(AccrualCategoryRule aRule : rules) {
629 LeaveSummaryRow row = summary.getLeaveSummaryRowForAccrualCategory(aRule.getLmAccrualCategoryId());
630 assertNotNull("eligible accrual category has no balance limit",ObjectUtils.isNotNull(aRule.getMaxBalance()));
631 assertTrue("accrual category not eligible for payout",row.getAccruedBalance().compareTo(aRule.getMaxBalance()) > 0);
632 }
633 }
634
635 @Test
636 public void testgetEligiblePayoutsLeaveApproveForTimesheetCaseTwo() throws Exception {
637
638 TkServiceLocator.getAccrualService().runAccrual(TS_USER_ID,TK_FROM,TK_TO,true,TS_USER_ID);
639 endDecTSD = TkServiceLocator.getTimesheetService().getTimesheetDocument(TSD_END_DEC_PERIOD_ID);
640 endDecTSDEntry = endDecTSD.getCalendarEntry();
641
642 Map<String, ArrayList<String>> eligiblePayouts = TkServiceLocator.getLeavePayoutService().getEligiblePayouts(endDecTSDEntry, TS_USER_ID);
643
644 assertEquals(2, eligiblePayouts.get(LMConstants.MAX_BAL_ACTION_FREQ.LEAVE_APPROVE).size());
645
646
647
648 List<AccrualCategoryRule> rules = new ArrayList<AccrualCategoryRule>();
649 for(String eligiblePayout : eligiblePayouts.get(LMConstants.MAX_BAL_ACTION_FREQ.LEAVE_APPROVE))
650 rules.add(TkServiceLocator.getAccrualCategoryRuleService().getAccrualCategoryRule(eligiblePayout));
651
652 LeaveSummary summary = TkServiceLocator.getLeaveSummaryService().getLeaveSummary(TS_USER_ID, endDecTSDEntry);
653 for(AccrualCategoryRule aRule : rules) {
654 LeaveSummaryRow row = summary.getLeaveSummaryRowForAccrualCategory(aRule.getLmAccrualCategoryId());
655 assertNotNull("eligible accrual category has no balance limit",ObjectUtils.isNotNull(aRule.getMaxBalance()));
656 assertTrue("accrual category not eligible for payout",row.getAccruedBalance().compareTo(aRule.getMaxBalance()) > 0);
657 }
658 }
659
660 @Test
661 public void testgetEligiblePayoutsYearEndForTimesheetCaseTwo() throws Exception {
662
663 TkServiceLocator.getAccrualService().runAccrual(TS_USER_ID,TK_FROM,TK_TO,true,TS_USER_ID);
664 endDecTSD = TkServiceLocator.getTimesheetService().getTimesheetDocument(TSD_END_DEC_PERIOD_ID);
665 endDecTSDEntry = endDecTSD.getCalendarEntry();
666
667 Map<String, ArrayList<String>> eligiblePayouts = TkServiceLocator.getLeavePayoutService().getEligiblePayouts(endDecTSDEntry, TS_USER_ID);
668
669 assertEquals(0, eligiblePayouts.get(LMConstants.MAX_BAL_ACTION_FREQ.YEAR_END).size());
670
671
672
673 List<AccrualCategoryRule> rules = new ArrayList<AccrualCategoryRule>();
674 for(String eligiblePayout : eligiblePayouts.get(LMConstants.MAX_BAL_ACTION_FREQ.YEAR_END))
675 rules.add(TkServiceLocator.getAccrualCategoryRuleService().getAccrualCategoryRule(eligiblePayout));
676
677
678
679
680 LeaveSummary summary = TkServiceLocator.getLeaveSummaryService().getLeaveSummary(TS_USER_ID, endDecTSDEntry);
681 for(AccrualCategoryRule aRule : rules) {
682 LeaveSummaryRow row = summary.getLeaveSummaryRowForAccrualCategory(aRule.getLmAccrualCategoryId());
683 BigDecimal maxBalance = aRule.getMaxBalance();
684 EmployeeOverride mbOverride = TkServiceLocator.getEmployeeOverrideService().getEmployeeOverride(TS_USER_ID,
685 "testLP",
686 row.getAccrualCategory(),
687 "MB",
688 janEntry.getBeginPeriodDate());
689 if(ObjectUtils.isNotNull(mbOverride))
690 maxBalance = new BigDecimal(mbOverride.getOverrideValue());
691 assertNotNull("eligible accrual category has no balance limit",maxBalance);
692 assertTrue("accrual category not eligible for payout",row.getAccruedBalance().compareTo(maxBalance) > 0);
693 }
694 }
695
696 @Test
697 public void testgetEligiblePayoutsOnDemandForTimesheetCaseTwo() throws Exception {
698
699 TkServiceLocator.getAccrualService().runAccrual(TS_USER_ID,TK_FROM,TK_TO,true,TS_USER_ID);
700 endDecTSD = TkServiceLocator.getTimesheetService().getTimesheetDocument(TSD_END_DEC_PERIOD_ID);
701 endDecTSDEntry = endDecTSD.getCalendarEntry();
702
703
704 Map<String, ArrayList<String>> eligiblePayouts = TkServiceLocator.getLeavePayoutService().getEligiblePayouts(endDecTSDEntry, TS_USER_ID);
705
706 assertEquals(2, eligiblePayouts.get(LMConstants.MAX_BAL_ACTION_FREQ.ON_DEMAND).size());
707
708
709
710 List<AccrualCategoryRule> rules = new ArrayList<AccrualCategoryRule>();
711 for(String eligiblePayout : eligiblePayouts.get(LMConstants.MAX_BAL_ACTION_FREQ.ON_DEMAND))
712 rules.add(TkServiceLocator.getAccrualCategoryRuleService().getAccrualCategoryRule(eligiblePayout));
713
714 LeaveSummary summary = TkServiceLocator.getLeaveSummaryService().getLeaveSummary(TS_USER_ID,endDecTSDEntry);
715 for(AccrualCategoryRule aRule : rules) {
716 LeaveSummaryRow row = summary.getLeaveSummaryRowForAccrualCategory(aRule.getLmAccrualCategoryId());
717 assertNotNull("eligible accrual category has no balance limit",ObjectUtils.isNotNull(aRule.getMaxBalance()));
718 assertTrue("accrual category not eligible for payout",row.getAccruedBalance().compareTo(aRule.getMaxBalance()) > 0);
719 }
720 }
721
722 @Test
723 public void testgetEligiblePayoutsYearEndForTimesheetCaseThree() throws Exception {
724
725 TkServiceLocator.getAccrualService().runAccrual(TS_USER_ID,TK_FROM,TK_TO,true,TS_USER_ID);
726 endJanTSD = TkServiceLocator.getTimesheetService().getTimesheetDocument(TSD_END_JAN_PERIOD_ID);
727 endJanTSDEntry = endJanTSD.getCalendarEntry();
728
729 Map<String, ArrayList<String>> eligiblePayouts = TkServiceLocator.getLeavePayoutService().getEligiblePayouts(endJanTSDEntry, TS_USER_ID);
730
731
732 assertEquals(3, eligiblePayouts.get(LMConstants.MAX_BAL_ACTION_FREQ.YEAR_END).size());
733
734
735
736 List<AccrualCategoryRule> rules = new ArrayList<AccrualCategoryRule>();
737 for(String eligiblePayout : eligiblePayouts.get(LMConstants.MAX_BAL_ACTION_FREQ.YEAR_END))
738 rules.add(TkServiceLocator.getAccrualCategoryRuleService().getAccrualCategoryRule(eligiblePayout));
739
740 LeaveSummary summary = TkServiceLocator.getLeaveSummaryService().getLeaveSummary(TS_USER_ID,endJanTSDEntry);
741 for(AccrualCategoryRule aRule : rules) {
742 LeaveSummaryRow row = summary.getLeaveSummaryRowForAccrualCategory(aRule.getLmAccrualCategoryId());
743 BigDecimal maxBalance = aRule.getMaxBalance();
744 EmployeeOverride mbOverride = TkServiceLocator.getEmployeeOverrideService().getEmployeeOverride(TS_USER_ID,
745 "testLP",
746 row.getAccrualCategory(),
747 "MB",
748 janEntry.getBeginPeriodDate());
749 EmployeeOverride macOverride = TkServiceLocator.getEmployeeOverrideService().getEmployeeOverride(TS_USER_ID,
750 "testLP",
751 row.getAccrualCategory(),
752 "MAC",
753 janEntry.getBeginPeriodDate());
754 if(ObjectUtils.isNotNull(mbOverride) && ObjectUtils.isNotNull(macOverride))
755 maxBalance = new BigDecimal(Math.min(mbOverride.getOverrideValue(), macOverride.getOverrideValue()));
756 else {
757 if(ObjectUtils.isNotNull(macOverride))
758 maxBalance = new BigDecimal(macOverride.getOverrideValue());
759 if(ObjectUtils.isNotNull(mbOverride))
760 maxBalance = new BigDecimal(mbOverride.getOverrideValue());
761 }
762 assertNotNull("eligible accrual category has no balance limit",ObjectUtils.isNotNull(maxBalance));
763 assertTrue("accrual category " + aRule.getLmAccrualCategoryId() + " not eligible for payout",row.getAccruedBalance().compareTo(maxBalance) > 0);
764 }
765 }
766 }