1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.kpme.tklm.leave.transfer;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.joda.time.LocalDate;
20 import org.junit.After;
21 import org.junit.Before;
22 import org.junit.Test;
23 import org.kuali.kpme.core.IntegrationTest;
24 import org.kuali.kpme.core.api.calendar.entry.CalendarEntry;
25 import org.kuali.kpme.core.util.TKUtils;
26 import org.kuali.kpme.tklm.TKLMIntegrationTestCase;
27 import org.kuali.kpme.tklm.api.leave.block.LeaveBlock;
28 import org.kuali.kpme.tklm.api.leave.summary.LeaveSummaryContract;
29 import org.kuali.kpme.tklm.api.leave.summary.LeaveSummaryRowContract;
30 import org.kuali.kpme.tklm.leave.calendar.LeaveCalendarDocument;
31 import org.kuali.kpme.tklm.leave.service.LmServiceLocator;
32 import org.kuali.rice.kew.api.KewApiServiceLocator;
33 import org.kuali.rice.kew.api.document.DocumentStatus;
34 import org.kuali.rice.krad.util.ObjectUtils;
35
36 import java.math.BigDecimal;
37
38 import static org.junit.Assert.*;
39
40 @IntegrationTest
41 public class BalanceTransferServiceTest 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
64
65
66
67 private final String OD_XFER = "5000";
68 private final String YE_XFER = "5001";
69 private final String LA_XFER = "5002";
70 private final String OD_XFER_MAC = "5003";
71 private final String YE_XFER_MAC = "5004";
72 private final String LA_XFER_MAC = "5005";
73 private final String OD_LOSE = "5006";
74 private final String YE_LOSE = "5007";
75 private final String LA_LOSE = "5008";
76 private final String OD_LOSE_MAC = "5009";
77 private final String YE_LOSE_MAC = "5010";
78 private final String LA_LOSE_MAC = "5011";
79 private final String YE_XFER_EO = "5012";
80 private final LocalDate LM_FROM = TKUtils.formatDateString("11/01/2012");
81 private final LocalDate LM_TO = TKUtils.formatDateString("02/01/2013");
82
83 @Before
84 public void setUp() throws Exception {
85 super.setUp();
86 LmServiceLocator.getAccrualService().runAccrual(USER_ID,LM_FROM.toDateTimeAtStartOfDay(),LM_TO.toDateTimeAtStartOfDay(),true,USER_ID);
87 janLCD = LmServiceLocator.getLeaveCalendarService().getLeaveCalendarDocument(JAN_ID);
88 janEntry = janLCD.getCalendarEntry();
89 janStart = janEntry.getBeginPeriodFullDateTime().toLocalDate();
90 decLCD = LmServiceLocator.getLeaveCalendarService().getLeaveCalendarDocument(DEC_ID);
91 decEntry = decLCD.getCalendarEntry();
92 decStart = decEntry.getBeginPeriodFullDateTime().toLocalDate();
93 }
94
95 @After
96 public void tearDown() throws Exception {
97 super.tearDown();
98 }
99
100
101
102
103
104
105
106
107
108 @Test
109 public void testInitializeTransferNullAccrualRule() throws Exception {
110 BalanceTransfer bt = new BalanceTransfer();
111
112 LocalDate effectiveDate = decStart.plusDays(3);
113 bt = LmServiceLocator.getBalanceTransferService().initializeTransfer(USER_ID, null, BigDecimal.ZERO, effectiveDate);
114 assertNull(bt);
115 }
116
117 @Test
118 public void testInitializeTransferNullLeaveSummary() throws Exception {
119 BalanceTransfer bt = new BalanceTransfer();
120
121 bt = LmServiceLocator.getBalanceTransferService().initializeTransfer(USER_ID, OD_XFER, null, LocalDate.now());
122 assertNull(bt);
123 }
124
125 @Test
126 public void testInitializeTransferNullAccrualRuleNullLeaveSummary() {
127 BalanceTransfer bt = new BalanceTransfer();
128 bt = LmServiceLocator.getBalanceTransferService().initializeTransfer(USER_ID, null, null, LocalDate.now());
129 assertNull(bt);
130 }
131
132 @Test
133 public void testInitializeTransferOnDemand() throws Exception {
134 BalanceTransfer bt = new BalanceTransfer();
135 LeaveSummaryContract summary = LmServiceLocator.getLeaveSummaryService().getLeaveSummary(USER_ID, decEntry);
136 LeaveSummaryRowContract aRow = summary.getLeaveSummaryRowForAccrualCategory(OD_XFER);
137 LocalDate effectiveDate = decStart.plusDays(3);
138 bt = LmServiceLocator.getBalanceTransferService().initializeTransfer(USER_ID, OD_XFER, aRow.getAccruedBalance(), effectiveDate);
139 assertEquals("transferOnDemand transfer amount", (new BigDecimal(1)).longValue(), bt.getTransferAmount().longValue());
140 assertEquals("transferOnDemand forfeited amount",(new BigDecimal(0)).longValue(), bt.getForfeitedAmount().longValue());
141 assertEquals("transferOnDemand amount transferred", (new BigDecimal(0.5)).longValue(), bt.getAmountTransferred().longValue());
142 }
143
144 @Test
145 public void testInitializeTransferOnDemandWithForfeiture() throws Exception {
146 BalanceTransfer bt = new BalanceTransfer();
147 LeaveSummaryContract summary = LmServiceLocator.getLeaveSummaryService().getLeaveSummary(USER_ID, janEntry);
148 LeaveSummaryRowContract aRow = summary.getLeaveSummaryRowForAccrualCategory(OD_XFER);
149 LocalDate effectiveDate = janStart.plusDays(3);
150 bt = LmServiceLocator.getBalanceTransferService().initializeTransfer(USER_ID, OD_XFER, aRow.getAccruedBalance(), effectiveDate);
151 assertEquals("transferOnDemand transfer amount", (new BigDecimal(10)).longValue(), bt.getTransferAmount().longValue());
152 assertEquals("transferOnDemand forfeited amount", (new BigDecimal(7)).longValue(), bt.getForfeitedAmount().longValue());
153 assertEquals("transferOnDemand amount transferred", (new BigDecimal(5)).longValue(), bt.getAmountTransferred().longValue());
154 }
155
156 @Test
157 public void testInitializeTransferOnYearEnd() throws Exception {
158 BalanceTransfer bt = new BalanceTransfer();
159 LmServiceLocator.getLeaveBlockService().deleteLeaveBlocksForDocumentId(DEC_ID);
160 LeaveSummaryContract summary = LmServiceLocator.getLeaveSummaryService().getLeaveSummary(USER_ID, janEntry);
161 LeaveSummaryRowContract aRow = summary.getLeaveSummaryRowForAccrualCategory(YE_XFER);
162 LocalDate effectiveDate = janStart.plusDays(3);
163 bt = LmServiceLocator.getBalanceTransferService().initializeTransfer(USER_ID, YE_XFER, aRow.getAccruedBalance(), effectiveDate);
164 assertEquals("transferOnDemand transfer amount", (new BigDecimal(1)).longValue(), bt.getTransferAmount().longValue());
165 assertEquals("transferOnDemand forfeited amount",(new BigDecimal(0)).longValue(), bt.getForfeitedAmount().longValue());
166 assertEquals("transferOnDemand amount transferred", (new BigDecimal(0.5)).longValue(), bt.getAmountTransferred().longValue());
167 }
168
169 @Test
170 public void testInitializeTransferOnYearEndWithForfeiture() throws Exception {
171 BalanceTransfer bt = new BalanceTransfer();
172 LeaveSummaryContract summary = LmServiceLocator.getLeaveSummaryService().getLeaveSummary(USER_ID, janEntry);
173 LeaveSummaryRowContract aRow = summary.getLeaveSummaryRowForAccrualCategory(YE_XFER);
174 LocalDate effectiveDate = janStart.plusDays(3);
175 bt = LmServiceLocator.getBalanceTransferService().initializeTransfer(USER_ID, YE_XFER, aRow.getAccruedBalance(), effectiveDate);
176 assertEquals("transferOnDemand transfer amount", (new BigDecimal(10)).longValue(), bt.getTransferAmount().longValue());
177 assertEquals("transferOnDemand forfeited amount", (new BigDecimal(7)).longValue(), bt.getForfeitedAmount().longValue());
178 assertEquals("transferOnDemand amount transferred", (new BigDecimal(5)).longValue(), bt.getAmountTransferred().longValue());
179 }
180
181 @Test
182 public void testInitializeTransferOnLeaveApprove() throws Exception {
183 BalanceTransfer bt = new BalanceTransfer();
184 LeaveSummaryContract summary = LmServiceLocator.getLeaveSummaryService().getLeaveSummary(USER_ID, decEntry);
185 LeaveSummaryRowContract aRow = summary.getLeaveSummaryRowForAccrualCategory(LA_XFER);
186 LocalDate effectiveDate = decStart.plusDays(3);
187 bt = LmServiceLocator.getBalanceTransferService().initializeTransfer(USER_ID, LA_XFER, aRow.getAccruedBalance(), effectiveDate);
188 assertEquals("transferOnDemand transfer amount", (new BigDecimal(1)).longValue(), bt.getTransferAmount().longValue());
189 assertEquals("transferOnDemand forfeited amount",(new BigDecimal(0)).longValue(), bt.getForfeitedAmount().longValue());
190 assertEquals("transferOnDemand amount transferred", (new BigDecimal(0.5)).longValue(), bt.getAmountTransferred().longValue());
191 }
192
193 @Test
194 public void testInitializeTransferOnLeaveApproveWithForfeiture() throws Exception {
195 BalanceTransfer bt = new BalanceTransfer();
196 LeaveSummaryContract summary = LmServiceLocator.getLeaveSummaryService().getLeaveSummary(USER_ID, janEntry);
197 LeaveSummaryRowContract aRow = summary.getLeaveSummaryRowForAccrualCategory(LA_XFER);
198 LocalDate effectiveDate = janStart.plusDays(3);
199 bt = LmServiceLocator.getBalanceTransferService().initializeTransfer(USER_ID, LA_XFER, aRow.getAccruedBalance(), effectiveDate);
200 assertEquals("transferOnDemand transfer amount", (new BigDecimal(10)).longValue(), bt.getTransferAmount().longValue());
201 assertEquals("transferOnDemand forfeited amount", (new BigDecimal(7)).longValue(), bt.getForfeitedAmount().longValue());
202 assertEquals("transferOnDemand amount transferred", (new BigDecimal(5)).longValue(), bt.getAmountTransferred().longValue());
203 }
204
205 @Test
206 public void testInitializeTransferOnDemandMaxCarryOver() throws Exception {
207
208 BalanceTransfer bt = new BalanceTransfer();
209 LeaveSummaryContract summary = LmServiceLocator.getLeaveSummaryService().getLeaveSummary(USER_ID, decEntry);
210 LeaveSummaryRowContract aRow = summary.getLeaveSummaryRowForAccrualCategory(OD_XFER_MAC);
211 LocalDate effectiveDate = decStart.plusDays(3);
212 bt = LmServiceLocator.getBalanceTransferService().initializeTransfer(USER_ID, OD_XFER_MAC, aRow.getAccruedBalance(), effectiveDate);
213 assertEquals("transferOnDemand transfer amount", (new BigDecimal(1)).longValue(), bt.getTransferAmount().longValue());
214 assertEquals("transferOnDemand forfeited amount",(new BigDecimal(0)).longValue(), bt.getForfeitedAmount().longValue());
215 assertEquals("transferOnDemand amount transferred", (new BigDecimal(0.5)).longValue(), bt.getAmountTransferred().longValue());
216 }
217
218 @Test
219 public void testInitializeTransferOnYearEndMaxCarryOver() throws Exception {
220
221
222
223
224
225
226
227
228
229
230
231
232
233 BalanceTransfer bt = new BalanceTransfer();
234 LeaveSummaryContract summary = LmServiceLocator.getLeaveSummaryService().getLeaveSummary(USER_ID, decEntry);
235 LeaveSummaryRowContract aRow = summary.getLeaveSummaryRowForAccrualCategory(YE_XFER_MAC);
236 LocalDate effectiveDate = decStart.plusDays(3);
237 bt = LmServiceLocator.getBalanceTransferService().initializeTransfer(USER_ID, YE_XFER_MAC, aRow.getAccruedBalance(), effectiveDate);
238 assertEquals("transferOnDemand transfer amount", (new BigDecimal(6)).longValue(), bt.getTransferAmount().longValue());
239 assertEquals("transferOnDemand forfeited amount", (new BigDecimal(0)).longValue(), bt.getForfeitedAmount().longValue());
240 assertEquals("transferOnDemand amount transferred", (new BigDecimal(3)).longValue(), bt.getAmountTransferred().longValue());
241 }
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275 @Test
276 public void testInitializeTransferOnYearEndMaxCarryOverWithForfeiture() throws Exception {
277
278 BalanceTransfer bt = new BalanceTransfer();
279 LeaveSummaryContract summary = LmServiceLocator.getLeaveSummaryService().getLeaveSummary(USER_ID, janEntry);
280 LeaveSummaryRowContract aRow = summary.getLeaveSummaryRowForAccrualCategory(YE_XFER_MAC);
281 LocalDate effectiveDate = janStart.plusDays(3);
282 bt = LmServiceLocator.getBalanceTransferService().initializeTransfer(USER_ID, YE_XFER_MAC, aRow.getAccruedBalance(), effectiveDate);
283 assertEquals("transferOnDemand transfer amount", (new BigDecimal(10)).longValue(), bt.getTransferAmount().longValue());
284 assertEquals("transferOnDemand forfeited amount", (new BigDecimal(12)).longValue(), bt.getForfeitedAmount().longValue());
285 assertEquals("transferOnDemand amount transferred", (new BigDecimal(5)).longValue(), bt.getAmountTransferred().longValue());
286 }
287
288 @Test
289 public void testInitializeTransferOnLeaveApproveMaxCarryOver() throws Exception {
290 BalanceTransfer bt = new BalanceTransfer();
291 LeaveSummaryContract summary = LmServiceLocator.getLeaveSummaryService().getLeaveSummary(USER_ID, decEntry);
292 LeaveSummaryRowContract aRow = summary.getLeaveSummaryRowForAccrualCategory(LA_XFER_MAC);
293 LocalDate effectiveDate = decStart.plusDays(3);
294 bt = LmServiceLocator.getBalanceTransferService().initializeTransfer(USER_ID, LA_XFER_MAC, aRow.getAccruedBalance(), effectiveDate);
295 assertEquals("transferOnDemand transfer amount", (new BigDecimal(1)).longValue(), bt.getTransferAmount().longValue());
296 assertEquals("transferOnDemand forfeited amount",(new BigDecimal(0)).longValue(), bt.getForfeitedAmount().longValue());
297 assertEquals("transferOnDemand amount transferred", (new BigDecimal(0.5)).longValue(), bt.getAmountTransferred().longValue());
298 }
299
300
301
302
303 @Test
304 public void testInitializeLoseOnDemand() throws Exception {
305 BalanceTransfer bt = new BalanceTransfer();
306 LeaveSummaryContract summary = LmServiceLocator.getLeaveSummaryService().getLeaveSummary(USER_ID, decEntry);
307 LeaveSummaryRowContract aRow = summary.getLeaveSummaryRowForAccrualCategory(OD_LOSE);
308 LocalDate effectiveDate = decStart.plusDays(3);
309 bt = LmServiceLocator.getBalanceTransferService().initializeTransfer(USER_ID, OD_LOSE, aRow.getAccruedBalance(), effectiveDate);
310 assertEquals("transferOnDemand transfer amount", (new BigDecimal(0)).longValue(), bt.getTransferAmount().longValue());
311 assertEquals("transferOnDemand forfeited amount",(new BigDecimal(1)).longValue(), bt.getForfeitedAmount().longValue());
312 assertEquals("transferOnDemand amount transferred", (new BigDecimal(0)).longValue(), bt.getAmountTransferred().longValue());
313 }
314
315 @Test
316 public void testInitializeLoseOnYearEnd() throws Exception {
317 BalanceTransfer bt = new BalanceTransfer();
318 LeaveSummaryContract summary = LmServiceLocator.getLeaveSummaryService().getLeaveSummary(USER_ID, janEntry);
319 LeaveSummaryRowContract aRow = summary.getLeaveSummaryRowForAccrualCategory(YE_LOSE);
320 LocalDate effectiveDate = janStart.plusDays(3);
321 bt = LmServiceLocator.getBalanceTransferService().initializeTransfer(USER_ID, YE_LOSE, aRow.getAccruedBalance(), effectiveDate);
322 assertEquals("transferOnDemand transfer amount", (new BigDecimal(0)).longValue(), bt.getTransferAmount().longValue());
323 assertEquals("transferOnDemand forfeited amount",(new BigDecimal(17)).longValue(), bt.getForfeitedAmount().longValue());
324 assertEquals("transferOnDemand amount transferred", (new BigDecimal(0)).longValue(), bt.getAmountTransferred().longValue());
325 }
326
327 @Test
328 public void testInitializeLoseOnLeaveApprove() throws Exception {
329 BalanceTransfer bt = new BalanceTransfer();
330 LeaveSummaryContract summary = LmServiceLocator.getLeaveSummaryService().getLeaveSummary(USER_ID, janEntry);
331 LeaveSummaryRowContract aRow = summary.getLeaveSummaryRowForAccrualCategory(LA_LOSE);
332 LocalDate effectiveDate = janStart.plusDays(3);
333 bt = LmServiceLocator.getBalanceTransferService().initializeTransfer(USER_ID, LA_LOSE, aRow.getAccruedBalance(), effectiveDate);
334 assertEquals("transferOnDemand transfer amount", (new BigDecimal(0)).longValue(), bt.getTransferAmount().longValue());
335 assertEquals("transferOnDemand forfeited amount",(new BigDecimal(17)).longValue(), bt.getForfeitedAmount().longValue());
336 assertEquals("transferOnDemand amount transferred", (new BigDecimal(0)).longValue(), bt.getAmountTransferred().longValue());
337 }
338
339 @Test
340 public void testInitializeLoseOnDemandMaxCarryOver() throws Exception {
341 BalanceTransfer bt = new BalanceTransfer();
342 LeaveSummaryContract summary = LmServiceLocator.getLeaveSummaryService().getLeaveSummary(USER_ID, janEntry);
343 LeaveSummaryRowContract aRow = summary.getLeaveSummaryRowForAccrualCategory(OD_LOSE_MAC);
344 LocalDate effectiveDate = janStart.plusDays(3);
345 bt = LmServiceLocator.getBalanceTransferService().initializeTransfer(USER_ID, OD_LOSE_MAC, aRow.getAccruedBalance(), effectiveDate);
346 assertEquals("transferOnDemand transfer amount", (new BigDecimal(0)).longValue(), bt.getTransferAmount().longValue());
347 assertEquals("transferOnDemand forfeited amount",(new BigDecimal(17)).longValue(), bt.getForfeitedAmount().longValue());
348 assertEquals("transferOnDemand amount transferred", (new BigDecimal(0)).longValue(), bt.getAmountTransferred().longValue());
349 }
350
351 @Test
352 public void testInitializeLoseOnYearEndMaxCarryOver() throws Exception {
353 BalanceTransfer bt = new BalanceTransfer();
354 LeaveSummaryContract summary = LmServiceLocator.getLeaveSummaryService().getLeaveSummary(USER_ID, janEntry);
355 LeaveSummaryRowContract aRow = summary.getLeaveSummaryRowForAccrualCategory(YE_LOSE_MAC);
356 LocalDate effectiveDate = janStart.plusDays(3);
357 bt = LmServiceLocator.getBalanceTransferService().initializeTransfer(USER_ID, YE_LOSE_MAC, aRow.getAccruedBalance(), effectiveDate);
358 assertEquals("transferOnDemand transfer amount", (new BigDecimal(0)).longValue(), bt.getTransferAmount().longValue());
359 assertEquals("transferOnDemand forfeited amount",(new BigDecimal(22)).longValue(), bt.getForfeitedAmount().longValue());
360 assertEquals("transferOnDemand amount transferred", (new BigDecimal(0)).longValue(), bt.getAmountTransferred().longValue());
361 }
362
363 @Test
364 public void testInitializeLoseOnLeaveApproveMaxCarryOver() throws Exception {
365 BalanceTransfer bt = new BalanceTransfer();
366 LeaveSummaryContract summary = LmServiceLocator.getLeaveSummaryService().getLeaveSummary(USER_ID, janEntry);
367 LeaveSummaryRowContract aRow = summary.getLeaveSummaryRowForAccrualCategory(LA_LOSE_MAC);
368 LocalDate effectiveDate = janStart.plusDays(3);
369 bt = LmServiceLocator.getBalanceTransferService().initializeTransfer(USER_ID, LA_LOSE_MAC, aRow.getAccruedBalance(), effectiveDate);
370 assertEquals("transferOnDemand transfer amount", (new BigDecimal(0)).longValue(), bt.getTransferAmount().longValue());
371 assertEquals("transferOnDemand forfeited amount",(new BigDecimal(17)).longValue(), bt.getForfeitedAmount().longValue());
372 assertEquals("transferOnDemand amount transferred", (new BigDecimal(0)).longValue(), bt.getAmountTransferred().longValue());
373 }
374
375 @Test
376 public void testInitializeTransferWithOverrides() throws Exception {
377 BalanceTransfer bt = new BalanceTransfer();
378 LeaveSummaryContract summary = LmServiceLocator.getLeaveSummaryService().getLeaveSummary(USER_ID, janEntry);
379 LeaveSummaryRowContract aRow = summary.getLeaveSummaryRowForAccrualCategory(YE_XFER_EO);
380 LocalDate effectiveDate = janStart.plusDays(3);
381 bt = LmServiceLocator.getBalanceTransferService().initializeTransfer(USER_ID, YE_XFER_EO, aRow.getAccruedBalance(), effectiveDate);
382 assertEquals("transferOnDemand transfer amount", (new BigDecimal(7)).longValue(), bt.getTransferAmount().longValue());
383 assertEquals("transferOnDemand forfeited amount",(new BigDecimal(20)).longValue(), bt.getForfeitedAmount().longValue());
384
385 assertEquals("transferOnDemand amount transferred", (new BigDecimal(7)).longValue(), bt.getAmountTransferred().longValue());
386 }
387
388
389
390
391 @Test
392 public void testTransferNullBalanceTransfer() {
393 BalanceTransfer balanceTransfer = null;
394 try {
395 balanceTransfer = LmServiceLocator.getBalanceTransferService().transfer(balanceTransfer);
396 } catch (RuntimeException re) {
397 assertTrue(re.getMessage().contains("did not supply a valid BalanceTransfer object"));
398 }
399 }
400
401 @Test
402 public void testTransferWithZeroTransferAmount() throws Exception {
403 BalanceTransfer bt = new BalanceTransfer();
404 LeaveSummaryContract summary = LmServiceLocator.getLeaveSummaryService().getLeaveSummary(USER_ID, janEntry);
405 LeaveSummaryRowContract aRow = summary.getLeaveSummaryRowForAccrualCategory(YE_LOSE);
406 LocalDate effectiveDate = janStart.plusDays(3);
407 bt = LmServiceLocator.getBalanceTransferService().initializeTransfer(USER_ID, YE_LOSE, aRow.getAccruedBalance(), effectiveDate);
408 bt = LmServiceLocator.getBalanceTransferService().transfer(bt);
409 LeaveBlock forfeitedLeaveBlock = LmServiceLocator.getLeaveBlockService().getLeaveBlock(bt.getForfeitedLeaveBlockId());
410 LeaveBlock accruedLeaveBlock = LmServiceLocator.getLeaveBlockService().getLeaveBlock(bt.getAccruedLeaveBlockId());
411 LeaveBlock debitedLeaveBlock = LmServiceLocator.getLeaveBlockService().getLeaveBlock(bt.getDebitedLeaveBlockId());
412 assertEquals("forfeited leave block leave amount incorrect", (new BigDecimal(-17)).longValue(), forfeitedLeaveBlock.getLeaveAmount().longValue());
413 assertTrue("accrued leave block should not exist",ObjectUtils.isNull(accruedLeaveBlock));
414 assertTrue("debited leave block should not exist",ObjectUtils.isNull(debitedLeaveBlock));
415 }
416
417 @Test
418 public void testTransferWithNoAmountTransferred() throws Exception {
419 BalanceTransfer bt = new BalanceTransfer();
420 LeaveSummaryContract summary = LmServiceLocator.getLeaveSummaryService().getLeaveSummary(USER_ID, janEntry);
421 LeaveSummaryRowContract aRow = summary.getLeaveSummaryRowForAccrualCategory(YE_LOSE);
422 LocalDate effectiveDate = janStart.plusDays(3);
423 bt = LmServiceLocator.getBalanceTransferService().initializeTransfer(USER_ID, YE_LOSE, aRow.getAccruedBalance(), effectiveDate);
424 bt.setAmountTransferred(null);
425 bt = LmServiceLocator.getBalanceTransferService().transfer(bt);
426 LeaveBlock forfeitedLeaveBlock = LmServiceLocator.getLeaveBlockService().getLeaveBlock(bt.getForfeitedLeaveBlockId());
427 LeaveBlock accruedLeaveBlock = LmServiceLocator.getLeaveBlockService().getLeaveBlock(bt.getAccruedLeaveBlockId());
428 LeaveBlock debitedLeaveBlock = LmServiceLocator.getLeaveBlockService().getLeaveBlock(bt.getDebitedLeaveBlockId());
429 assertEquals("forfeited leave block leave amount incorrect",(new BigDecimal(-17)).longValue(), forfeitedLeaveBlock.getLeaveAmount().longValue());
430 assertTrue("accrued leave block should not exist",ObjectUtils.isNull(accruedLeaveBlock));
431 assertTrue("debited leave block should not exist",ObjectUtils.isNull(debitedLeaveBlock));
432 }
433
434 @Test
435 public void testTransferWithZeroForfeiture() throws Exception {
436 BalanceTransfer bt = new BalanceTransfer();
437 LeaveSummaryContract summary = LmServiceLocator.getLeaveSummaryService().getLeaveSummary(USER_ID, decEntry);
438 LeaveSummaryRowContract aRow = summary.getLeaveSummaryRowForAccrualCategory(OD_XFER);
439 LocalDate effectiveDate = decStart.plusDays(3);
440 bt = LmServiceLocator.getBalanceTransferService().initializeTransfer(USER_ID, OD_XFER, aRow.getAccruedBalance(), effectiveDate);
441 bt = LmServiceLocator.getBalanceTransferService().transfer(bt);
442 LeaveBlock forfeitedLeaveBlock = LmServiceLocator.getLeaveBlockService().getLeaveBlock(bt.getForfeitedLeaveBlockId());
443 LeaveBlock accruedLeaveBlock = LmServiceLocator.getLeaveBlockService().getLeaveBlock(bt.getAccruedLeaveBlockId());
444 LeaveBlock debitedLeaveBlock = LmServiceLocator.getLeaveBlockService().getLeaveBlock(bt.getDebitedLeaveBlockId());
445 assertEquals("accrued leave block leave amount incorrect", (new BigDecimal(0.5)).longValue(), accruedLeaveBlock.getLeaveAmount().longValue());
446 assertTrue("forfeited leave block should not exist",ObjectUtils.isNull(forfeitedLeaveBlock));
447 assertEquals("transfered leave block leave amount incorrect", (new BigDecimal(-1)).longValue(), debitedLeaveBlock.getLeaveAmount().longValue());
448 }
449
450 @Test
451 public void testTransferWithThreeLeaveBlocks() throws Exception {
452 BalanceTransfer bt = new BalanceTransfer();
453 LeaveSummaryContract summary = LmServiceLocator.getLeaveSummaryService().getLeaveSummary(USER_ID, janEntry);
454 LeaveSummaryRowContract aRow = summary.getLeaveSummaryRowForAccrualCategory(YE_XFER);
455 LocalDate effectiveDate = janStart.plusDays(3);
456 bt = LmServiceLocator.getBalanceTransferService().initializeTransfer(USER_ID, YE_XFER, aRow.getAccruedBalance(), effectiveDate);
457 bt = LmServiceLocator.getBalanceTransferService().transfer(bt);
458 LeaveBlock forfeitedLeaveBlock = LmServiceLocator.getLeaveBlockService().getLeaveBlock(bt.getForfeitedLeaveBlockId());
459 LeaveBlock accruedLeaveBlock = LmServiceLocator.getLeaveBlockService().getLeaveBlock(bt.getAccruedLeaveBlockId());
460 LeaveBlock debitedLeaveBlock = LmServiceLocator.getLeaveBlockService().getLeaveBlock(bt.getDebitedLeaveBlockId());
461 assertEquals("forfeited leave block leave amount incorrect", (new BigDecimal(-7)).longValue(), forfeitedLeaveBlock.getLeaveAmount().longValue());
462 assertEquals((new BigDecimal(5)).longValue(), accruedLeaveBlock.getLeaveAmount().longValue());
463 assertEquals((new BigDecimal(-10)).longValue(), debitedLeaveBlock.getLeaveAmount().longValue());
464 }
465
466
467
468 @Test
469 public void testSubmitToWorkflow() throws Exception {
470 BalanceTransfer balanceTransfer = new BalanceTransfer();
471 LeaveSummaryContract summary = LmServiceLocator.getLeaveSummaryService().getLeaveSummary(USER_ID, janEntry);
472 LeaveSummaryRowContract aRow = summary.getLeaveSummaryRowForAccrualCategory(YE_XFER);
473 LocalDate effectiveDate = janStart.plusDays(3);
474 balanceTransfer = LmServiceLocator.getBalanceTransferService().initializeTransfer(USER_ID, YE_XFER, aRow.getAccruedBalance(), effectiveDate);
475 String workflowDocId = LmServiceLocator.getBalanceTransferService().submitToWorkflow(balanceTransfer);
476 assertNotNull("transfer document should have a workflow id", workflowDocId);
477 DocumentStatus docStatus = KewApiServiceLocator.getWorkflowDocumentService().getDocumentStatus(workflowDocId);
478 assertTrue("doc status should be enroute", StringUtils.equals(docStatus.getCode(),"R"));
479 }
480
481 }