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