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 import java.util.Set;
27
28 import org.apache.commons.lang.time.DateUtils;
29 import org.junit.After;
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.kuali.hr.lm.LMConstants;
33 import org.kuali.hr.lm.accrual.AccrualCategoryRule;
34 import org.kuali.hr.lm.leavepayout.LeavePayout;
35 import org.kuali.hr.lm.employeeoverride.EmployeeOverride;
36 import org.kuali.hr.lm.leaveSummary.LeaveSummary;
37 import org.kuali.hr.lm.leaveSummary.LeaveSummaryRow;
38 import org.kuali.hr.lm.leaveblock.LeaveBlock;
39 import org.kuali.hr.lm.leavecalendar.LeaveCalendarDocument;
40 import org.kuali.hr.test.KPMETestCase;
41 import org.kuali.hr.time.calendar.CalendarEntries;
42 import org.kuali.hr.time.service.base.TkServiceLocator;
43 import org.kuali.hr.time.timesheet.TimesheetDocument;
44 import org.kuali.hr.time.util.TKUtils;
45 import org.kuali.rice.krad.util.ObjectUtils;
46
47 public class LeavePayoutServiceTest extends KPMETestCase {
48
49
50
51
52 private final String USER_ID = "testUser1";
53
54 private LeaveCalendarDocument janLCD;
55 private CalendarEntries janEntry;
56 private LeaveCalendarDocument decLCD;
57 private CalendarEntries decEntry;
58
59 private Date janStart;
60 private Date janEnd;
61 private Date decStart;
62 private Date decEnd;
63
64 private final String JAN_ID = "5001";
65 private final String DEC_ID = "5000";
66
67
68
69
70
71 private final String TS_USER_ID = "testUser2";
72
73 private TimesheetDocument endJanTSD;
74 private CalendarEntries endJanTSDEntry;
75 private TimesheetDocument midJanTSD;
76 private CalendarEntries midJanTSDEntry;
77 private TimesheetDocument endDecTSD;
78 private CalendarEntries endDecTSDEntry;
79 private TimesheetDocument midDecTSD;
80 private CalendarEntries midDecTSDEntry;
81
82 private Date midJanStart;
83 private Date midJanEnd;
84 private Date endDecStart;
85 private Date endDecEnd;
86 private Date midDecStart;
87 private Date midDecEnd;
88
89 private final String TSD_MID_DEC_PERIOD_ID = "5000";
90 private final String TSD_END_DEC_PERIOD_ID = "5001";
91 private final String TSD_MID_JAN_PERIOD_ID = "5002";
92 private final String TSD_END_JAN_PERIOD_ID = "5003";
93
94
95
96
97
98 private final String OD_XFER = "5000";
99 private final String YE_XFER = "5001";
100 private final String LA_XFER = "5002";
101 private final String OD_XFER_MAC = "5003";
102 private final String YE_XFER_MAC = "5004";
103 private final String LA_XFER_MAC = "5005";
104 private final String OD_LOSE = "5006";
105 private final String YE_LOSE = "5007";
106 private final String LA_LOSE = "5008";
107 private final String OD_LOSE_MAC = "5009";
108 private final String YE_LOSE_MAC = "5010";
109 private final String LA_LOSE_MAC = "5011";
110 private final String YE_XFER_EO = "5012";
111 private final java.sql.Date LM_FROM = TKUtils.formatDateString("11/01/2012");
112 private final java.sql.Date LM_TO = TKUtils.formatDateString("02/01/2013");
113 private final java.sql.Date TK_FROM = TKUtils.formatDateString("11/01/2011");
114 private final java.sql.Date TK_TO = TKUtils.formatDateString("02/01/2012");
115
116 @Before
117 public void setUp() throws Exception {
118 super.setUp();
119 TkServiceLocator.getAccrualService().runAccrual(USER_ID,LM_FROM,LM_TO,true,USER_ID);
120 janLCD = TkServiceLocator.getLeaveCalendarService().getLeaveCalendarDocument(JAN_ID);
121 janEntry = janLCD.getCalendarEntry();
122 janStart = janEntry.getBeginPeriodDate();
123 janEnd = janEntry.getEndPeriodDate();
124 decLCD = TkServiceLocator.getLeaveCalendarService().getLeaveCalendarDocument(DEC_ID);
125 decEntry = decLCD.getCalendarEntry();
126 decStart = decEntry.getBeginPeriodDate();
127 decEnd = decEntry.getEndPeriodDate();
128 }
129
130 @After
131 public void tearDown() throws Exception {
132 super.tearDown();
133 }
134
135
136
137
138
139
140
141
142
143 @Test
144 public void testInitializePayoutNullAccrualRule() throws Exception {
145 LeavePayout lp = new LeavePayout();
146
147 java.sql.Date effectiveDate = new java.sql.Date(DateUtils.addDays(decStart,3).getTime());
148 lp = TkServiceLocator.getLeavePayoutService().initializePayout(USER_ID, null, BigDecimal.ZERO, effectiveDate);
149 assertNull(lp);
150 }
151
152 @Test
153 public void testInitializePayoutNullLeaveSummary() throws Exception {
154 LeavePayout lp = new LeavePayout();
155
156 lp = TkServiceLocator.getLeavePayoutService().initializePayout(USER_ID, OD_XFER, null, TKUtils.getCurrentDate());
157 assertNull(lp);
158 }
159
160 @Test
161 public void testInitializePayoutNullAccrualRuleNullLeaveSummary() {
162 LeavePayout lp = new LeavePayout();
163 lp = TkServiceLocator.getLeavePayoutService().initializePayout(USER_ID, null, null, TKUtils.getCurrentDate());
164 assertNull(lp);
165 }
166
167 @Test
168 public void testInitializePayoutOnDemand() throws Exception {
169 LeavePayout lp = new LeavePayout();
170 LeaveSummary summary = TkServiceLocator.getLeaveSummaryService().getLeaveSummary(USER_ID, decEntry);
171 LeaveSummaryRow aRow = summary.getLeaveSummaryRowForAccrualCategory(OD_XFER);
172 java.sql.Date effectiveDate = new java.sql.Date(DateUtils.addDays(decStart,3).getTime());
173 lp = TkServiceLocator.getLeavePayoutService().initializePayout(USER_ID, OD_XFER, aRow.getAccruedBalance(), effectiveDate);
174 assertEquals("payoutOnDemand payout amount", (new BigDecimal(1)).longValue(), lp.getPayoutAmount().longValue());
175 assertEquals("payoutOnDemand forfeited amount",(new BigDecimal(0)).longValue(), lp.getForfeitedAmount().longValue());
176
177 }
178
179 @Test
180 public void testInitializePayoutOnDemandWithForfeiture() throws Exception {
181 LeavePayout lp = new LeavePayout();
182 LeaveSummary summary = TkServiceLocator.getLeaveSummaryService().getLeaveSummary(USER_ID, janEntry);
183 LeaveSummaryRow aRow = summary.getLeaveSummaryRowForAccrualCategory(OD_XFER);
184 java.sql.Date effectiveDate = new java.sql.Date(DateUtils.addDays(janStart,3).getTime());
185 lp = TkServiceLocator.getLeavePayoutService().initializePayout(USER_ID, OD_XFER, aRow.getAccruedBalance(), effectiveDate);
186 assertEquals("payoutOnDemand payout amount", (new BigDecimal(10)).longValue(), lp.getPayoutAmount().longValue());
187 assertEquals("payoutOnDemand forfeited amount", (new BigDecimal(7)).longValue(), lp.getForfeitedAmount().longValue());
188
189 }
190
191 @Test
192 public void testInitializePayoutOnYearEnd() throws Exception {
193 LeavePayout lp = new LeavePayout();
194 TkServiceLocator.getLeaveBlockService().deleteLeaveBlocksForDocumentId(DEC_ID);
195 LeaveSummary summary = TkServiceLocator.getLeaveSummaryService().getLeaveSummary(USER_ID, janEntry);
196 LeaveSummaryRow aRow = summary.getLeaveSummaryRowForAccrualCategory(YE_XFER);
197 java.sql.Date effectiveDate = new java.sql.Date(DateUtils.addDays(janStart,3).getTime());
198 lp = TkServiceLocator.getLeavePayoutService().initializePayout(USER_ID, YE_XFER, aRow.getAccruedBalance(), effectiveDate);
199 assertEquals("payoutOnDemand payout amount", (new BigDecimal(1)).longValue(), lp.getPayoutAmount().longValue());
200 assertEquals("payoutOnDemand forfeited amount",(new BigDecimal(0)).longValue(), lp.getForfeitedAmount().longValue());
201
202 }
203
204 @Test
205 public void testInitializePayoutOnYearEndWithForfeiture() throws Exception {
206 LeavePayout lp = new LeavePayout();
207 LeaveSummary summary = TkServiceLocator.getLeaveSummaryService().getLeaveSummary(USER_ID, janEntry);
208 LeaveSummaryRow aRow = summary.getLeaveSummaryRowForAccrualCategory(YE_XFER);
209 java.sql.Date effectiveDate = new java.sql.Date(DateUtils.addDays(janStart,3).getTime());
210 lp = TkServiceLocator.getLeavePayoutService().initializePayout(USER_ID, YE_XFER, aRow.getAccruedBalance(), effectiveDate);
211 assertEquals("payoutOnDemand payout amount", (new BigDecimal(10)).longValue(), lp.getPayoutAmount().longValue());
212 assertEquals("payoutOnDemand forfeited amount", (new BigDecimal(7)).longValue(), lp.getForfeitedAmount().longValue());
213
214 }
215
216 @Test
217 public void testInitializePayoutOnLeaveApprove() throws Exception {
218 LeavePayout lp = new LeavePayout();
219 LeaveSummary summary = TkServiceLocator.getLeaveSummaryService().getLeaveSummary(USER_ID, decEntry);
220 LeaveSummaryRow aRow = summary.getLeaveSummaryRowForAccrualCategory(LA_XFER);
221 java.sql.Date effectiveDate = new java.sql.Date(DateUtils.addDays(decStart,3).getTime());
222 lp = TkServiceLocator.getLeavePayoutService().initializePayout(USER_ID, LA_XFER, aRow.getAccruedBalance(), effectiveDate);
223 assertEquals("payoutOnDemand payout amount", (new BigDecimal(1)).longValue(), lp.getPayoutAmount().longValue());
224 assertEquals("payoutOnDemand forfeited amount",(new BigDecimal(0)).longValue(), lp.getForfeitedAmount().longValue());
225
226 }
227
228 @Test
229 public void testInitializePayoutOnLeaveApproveWithForfeiture() throws Exception {
230 LeavePayout lp = new LeavePayout();
231 LeaveSummary summary = TkServiceLocator.getLeaveSummaryService().getLeaveSummary(USER_ID, janEntry);
232 LeaveSummaryRow aRow = summary.getLeaveSummaryRowForAccrualCategory(LA_XFER);
233 java.sql.Date effectiveDate = new java.sql.Date(DateUtils.addDays(janStart,3).getTime());
234 lp = TkServiceLocator.getLeavePayoutService().initializePayout(USER_ID, LA_XFER, aRow.getAccruedBalance(), effectiveDate);
235 assertEquals("payoutOnDemand payout amount", (new BigDecimal(10)).longValue(), lp.getPayoutAmount().longValue());
236 assertEquals("payoutOnDemand forfeited amount", (new BigDecimal(7)).longValue(), lp.getForfeitedAmount().longValue());
237
238 }
239
240 @Test
241 public void testInitializePayoutOnDemandMaxCarryOver() throws Exception {
242
243 LeavePayout lp = new LeavePayout();
244 LeaveSummary summary = TkServiceLocator.getLeaveSummaryService().getLeaveSummary(USER_ID, decEntry);
245 LeaveSummaryRow aRow = summary.getLeaveSummaryRowForAccrualCategory(OD_XFER_MAC);
246 java.sql.Date effectiveDate = new java.sql.Date(DateUtils.addDays(decStart,3).getTime());
247 lp = TkServiceLocator.getLeavePayoutService().initializePayout(USER_ID, OD_XFER_MAC, aRow.getAccruedBalance(), effectiveDate);
248 assertEquals("payoutOnDemand payout amount", (new BigDecimal(1)).longValue(), lp.getPayoutAmount().longValue());
249 assertEquals("payoutOnDemand forfeited amount",(new BigDecimal(0)).longValue(), lp.getForfeitedAmount().longValue());
250
251 }
252
253 @Test
254 public void testInitializePayoutOnYearEndMaxCarryOver() throws Exception {
255
256
257
258
259
260
261
262
263
264
265
266
267
268 LeavePayout lp = new LeavePayout();
269 LeaveSummary summary = TkServiceLocator.getLeaveSummaryService().getLeaveSummary(USER_ID, decEntry);
270 LeaveSummaryRow aRow = summary.getLeaveSummaryRowForAccrualCategory(YE_XFER_MAC);
271 java.sql.Date effectiveDate = new java.sql.Date(DateUtils.addDays(decStart,3).getTime());
272 lp = TkServiceLocator.getLeavePayoutService().initializePayout(USER_ID, YE_XFER_MAC, aRow.getAccruedBalance(), effectiveDate);
273 assertEquals("payoutOnDemand payout amount", (new BigDecimal(6)).longValue(), lp.getPayoutAmount().longValue());
274 assertEquals("payoutOnDemand forfeited amount", (new BigDecimal(0)).longValue(), lp.getForfeitedAmount().longValue());
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
310 @Test
311 public void testInitializePayoutOnYearEndMaxCarryOverWithForfeiture() throws Exception {
312
313 LeavePayout lp = new LeavePayout();
314 LeaveSummary summary = TkServiceLocator.getLeaveSummaryService().getLeaveSummary(USER_ID, janEntry);
315 LeaveSummaryRow aRow = summary.getLeaveSummaryRowForAccrualCategory(YE_XFER_MAC);
316 java.sql.Date effectiveDate = new java.sql.Date(DateUtils.addDays(janStart,3).getTime());
317 lp = TkServiceLocator.getLeavePayoutService().initializePayout(USER_ID, YE_XFER_MAC, aRow.getAccruedBalance(), effectiveDate);
318 assertEquals("payoutOnDemand payout amount", (new BigDecimal(10)).longValue(), lp.getPayoutAmount().longValue());
319 assertEquals("payoutOnDemand forfeited amount", (new BigDecimal(12)).longValue(), lp.getForfeitedAmount().longValue());
320
321 }
322
323 @Test
324 public void testInitializePayoutOnLeaveApproveMaxCarryOver() throws Exception {
325 LeavePayout lp = new LeavePayout();
326 LeaveSummary summary = TkServiceLocator.getLeaveSummaryService().getLeaveSummary(USER_ID, decEntry);
327 LeaveSummaryRow aRow = summary.getLeaveSummaryRowForAccrualCategory(LA_XFER_MAC);
328 java.sql.Date effectiveDate = new java.sql.Date(DateUtils.addDays(decStart,3).getTime());
329 lp = TkServiceLocator.getLeavePayoutService().initializePayout(USER_ID, LA_XFER_MAC, aRow.getAccruedBalance(), effectiveDate);
330 assertEquals("payoutOnDemand payout amount", (new BigDecimal(1)).longValue(), lp.getPayoutAmount().longValue());
331 assertEquals("payoutOnDemand forfeited amount",(new BigDecimal(0)).longValue(), lp.getForfeitedAmount().longValue());
332
333 }
334
335 @Test
336 public void testInitializePayoutWithOverrides() throws Exception {
337 LeavePayout lp = new LeavePayout();
338 LeaveSummary summary = TkServiceLocator.getLeaveSummaryService().getLeaveSummary(USER_ID, janEntry);
339 LeaveSummaryRow aRow = summary.getLeaveSummaryRowForAccrualCategory(YE_XFER_EO);
340 java.sql.Date effectiveDate = new java.sql.Date(DateUtils.addDays(janStart,3).getTime());
341 lp = TkServiceLocator.getLeavePayoutService().initializePayout(USER_ID, YE_XFER_EO, aRow.getAccruedBalance(), effectiveDate);
342 assertEquals("payoutOnDemand payout amount", (new BigDecimal(7)).longValue(), lp.getPayoutAmount().longValue());
343 assertEquals("payoutOnDemand forfeited amount",(new BigDecimal(20)).longValue(), lp.getForfeitedAmount().longValue());
344
345
346 }
347
348
349
350
351 @Test
352 public void testPayoutNullLeavePayout() {
353 LeavePayout LeavePayout = null;
354 try {
355 LeavePayout = TkServiceLocator.getLeavePayoutService().payout(LeavePayout);
356 } catch (RuntimeException re) {
357 assertTrue(re.getMessage().contains("did not supply a valid LeavePayout object"));
358 }
359 }
360
361 @Test
362 public void testPayoutWithZeroPayoutAmount() throws Exception {
363 LeavePayout lp = new LeavePayout();
364 LeaveSummary summary = TkServiceLocator.getLeaveSummaryService().getLeaveSummary(USER_ID, janEntry);
365 LeaveSummaryRow aRow = summary.getLeaveSummaryRowForAccrualCategory(YE_LOSE);
366 java.sql.Date effectiveDate = new java.sql.Date(DateUtils.addDays(janStart,3).getTime());
367
368 lp.setPayoutAmount(BigDecimal.ZERO);
369 lp = TkServiceLocator.getLeavePayoutService().payout(lp);
370 LeaveBlock forfeitedLeaveBlock = TkServiceLocator.getLeaveBlockService().getLeaveBlock(lp.getForfeitedLeaveBlockId());
371 LeaveBlock payoutLeaveBlock = TkServiceLocator.getLeaveBlockService().getLeaveBlock(lp.getPayoutLeaveBlockId());
372 LeaveBlock payoutFromLeaveBlock = TkServiceLocator.getLeaveBlockService().getLeaveBlock(lp.getPayoutFromLeaveBlockId());
373 assertTrue("forfeited leave block should not exist", ObjectUtils.isNull(forfeitedLeaveBlock));
374 assertTrue("accrued leave block should not exist",ObjectUtils.isNull(payoutLeaveBlock));
375 assertTrue("debited leave block should not exist",ObjectUtils.isNull(payoutFromLeaveBlock));
376 }
377
378 @Test
379 public void testPayoutWithZeroForfeiture() throws Exception {
380 LeavePayout lp = new LeavePayout();
381 LeaveSummary summary = TkServiceLocator.getLeaveSummaryService().getLeaveSummary(USER_ID, decEntry);
382 LeaveSummaryRow aRow = summary.getLeaveSummaryRowForAccrualCategory(OD_XFER);
383 java.sql.Date effectiveDate = new java.sql.Date(DateUtils.addDays(decStart,3).getTime());
384 lp = TkServiceLocator.getLeavePayoutService().initializePayout(USER_ID, OD_XFER, aRow.getAccruedBalance(), effectiveDate);
385 lp = TkServiceLocator.getLeavePayoutService().payout(lp);
386 LeaveBlock forfeitedLeaveBlock = TkServiceLocator.getLeaveBlockService().getLeaveBlock(lp.getForfeitedLeaveBlockId());
387 LeaveBlock payoutLeaveBlock = TkServiceLocator.getLeaveBlockService().getLeaveBlock(lp.getPayoutLeaveBlockId());
388 LeaveBlock payoutFromLeaveBlock = TkServiceLocator.getLeaveBlockService().getLeaveBlock(lp.getPayoutFromLeaveBlockId());
389 assertEquals("accrued leave block leave amount incorrect", (new BigDecimal(1)).longValue(), payoutLeaveBlock.getLeaveAmount().longValue());
390 assertTrue("forfeited leave block should not exist",ObjectUtils.isNull(forfeitedLeaveBlock));
391 assertEquals("payouted leave block leave amount incorrect", (new BigDecimal(-1)).longValue(), payoutFromLeaveBlock.getLeaveAmount().longValue());
392 }
393
394 @Test
395 public void testPayoutWithThreeLeaveBlocks() throws Exception {
396 LeavePayout lp = new LeavePayout();
397 LeaveSummary summary = TkServiceLocator.getLeaveSummaryService().getLeaveSummary(USER_ID, janEntry);
398 LeaveSummaryRow aRow = summary.getLeaveSummaryRowForAccrualCategory(YE_XFER);
399 java.sql.Date effectiveDate = new java.sql.Date(DateUtils.addDays(janStart,3).getTime());
400 lp = TkServiceLocator.getLeavePayoutService().initializePayout(USER_ID, YE_XFER, aRow.getAccruedBalance(), effectiveDate);
401 lp = TkServiceLocator.getLeavePayoutService().payout(lp);
402 LeaveBlock forfeitedLeaveBlock = TkServiceLocator.getLeaveBlockService().getLeaveBlock(lp.getForfeitedLeaveBlockId());
403 LeaveBlock payoutLeaveBlock = TkServiceLocator.getLeaveBlockService().getLeaveBlock(lp.getPayoutLeaveBlockId());
404 LeaveBlock payoutFromLeaveBlock = TkServiceLocator.getLeaveBlockService().getLeaveBlock(lp.getPayoutFromLeaveBlockId());
405 assertEquals("forfeited leave block leave amount incorrect", (new BigDecimal(-7)).longValue(), forfeitedLeaveBlock.getLeaveAmount().longValue());
406 assertEquals((new BigDecimal(10)).longValue(), payoutLeaveBlock.getLeaveAmount().longValue());
407 assertEquals((new BigDecimal(-10)).longValue(), payoutFromLeaveBlock.getLeaveAmount().longValue());
408 }
409
410
411
412 @Test
413 public void testSubmitToWorkflow() {
414 assertNull(null);
415 }
416
417 }