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