View Javadoc
1   /**
2    * Copyright 2004-2015 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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  	 * Leave Calendar Document Test data
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  	 * Timesheet Document Test Data;
61  	 */
62  
63  	/**
64  	 *  Common data
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 	 * Use-case specific testing *
102 	 ****************************/
103 	
104 	//
105 	// ACTION_AT_MAX_BALANCE = TRANSFER
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 		//N/A - Max Carry Over on Year End transfers.
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 		 * decEntry is not the last calendar entry in the leave plan. Want to check amounts for this action & action frequency
222 		 * without exceeding the transfer limit.
223 		 * 
224 		 * max transfer amount = 10
225 		 * leave balance = 16
226 		 * max balance = 15
227 		 * max carry over = 10
228 		 * 
229 		 * all excess should be transferrable. 1 unit of time for excess over max balance, 5 units of time for
230 		 * excess over max carry over.
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 /*	@Test
244 	public void testInitializeTransferUnderMaxBalanceOnYearEndMaxCarryOver() throws Exception {
245 		//Create a leave block that will bring the available balance for january down to 14.
246 		//this balance would be under the max available balance (15), but over the max annual carry over amount.
247 		//i.o.w., this transfer would not due to max balance limit, but max annual carry over.
248 		//could also simply change the accrual amount.
249 		LeaveBlock usage = new LeaveBlock();
250 		usage.setAccrualCategory(YE_XFER_MAC);
251 		usage.setLeaveDate(DateUtils.addDays(janStart,5));
252 		usage.setLeaveAmount(new BigDecimal(-18));
253 		usage.setPrincipalId(USER_ID);
254 		usage.setAccrualGenerated(false);
255 		usage.setRequestStatus(HrConstants.REQUEST_STATUS.APPROVED);
256 		usage.setDocumentId(janLCD.getDocumentId());
257 		usage.setLmLeaveBlockId("99999");
258 		usage.setEarnCode("EC5");
259 		usage.setBlockId(0L);
260 		usage.setLeaveBlockType(LMConstants.LEAVE_BLOCK_TYPE.LEAVE_CALENDAR);
261 		List<LeaveBlock> leaveBlocks = new ArrayList<LeaveBlock>();
262 		leaveBlocks.add(usage);
263 		LmServiceLocator.getLeaveBlockService().saveLeaveBlocks(leaveBlocks);
264 		
265 		BalanceTransfer bt = new BalanceTransfer();
266 		janLCD = LmServiceLocator.getLeaveCalendarService().getLeaveCalendarDocument(JAN_ID);
267 		LeaveSummaryContract summary = LmServiceLocator.getLeaveSummaryService().getLeaveSummary(USER_ID, janLCD.getCalendarEntry());
268 		Date effectiveDate = DateUtils.addDays(janStart,3);
269 		bt = LmServiceLocator.getBalanceTransferService().initializeTransfer(USER_ID, YE_XFER_MAC, aRow.getAccruedBalance(), effectiveDate);
270 		assertEquals("transferOnDemand transfer amount", (new BigDecimal(4)).longValue(), bt.getTransferAmount().longValue());
271 		assertEquals("transferOnDemand forfeited amount", (new BigDecimal(0)).longValue(), bt.getForfeitedAmount().longValue());
272 		assertEquals("transferOnDemand amount transferred", (new BigDecimal(2)).longValue(), bt.getAmountTransferred().longValue());
273 	}*/
274 	
275 	@Test
276 	public void testInitializeTransferOnYearEndMaxCarryOverWithForfeiture() throws Exception {
277 		//max bal limit reached and max annual carry over triggererd.
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 	// ACTION_AT_MAX_BALANCE = LOSE
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 		// max balance transfer conversion factor is undefined for YE_XFER_EO
385 		assertEquals("transferOnDemand amount transferred", (new BigDecimal(7)).longValue(), bt.getAmountTransferred().longValue());
386 	}
387 	/**
388 	 * End Use-case testing
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 	//TODO: write tests for adjusted max balance cases - i.e. FTE < 1, employee override's w/ type MAX_BALANCE
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 }