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