001 /** 002 * Copyright 2004-2013 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package org.kuali.hr.lm.balancetransfer.service; 017 018 import static org.junit.Assert.*; 019 020 import java.math.BigDecimal; 021 import java.util.ArrayList; 022 import java.util.Date; 023 import java.util.List; 024 import java.util.Map; 025 import java.util.Map.Entry; 026 import java.util.Set; 027 028 import org.apache.commons.lang.time.DateUtils; 029 import org.junit.After; 030 import org.junit.Before; 031 import org.junit.Test; 032 import org.kuali.hr.lm.LMConstants; 033 import org.kuali.hr.lm.accrual.AccrualCategoryRule; 034 import org.kuali.hr.lm.balancetransfer.BalanceTransfer; 035 import org.kuali.hr.lm.employeeoverride.EmployeeOverride; 036 import org.kuali.hr.lm.leaveSummary.LeaveSummary; 037 import org.kuali.hr.lm.leaveSummary.LeaveSummaryRow; 038 import org.kuali.hr.lm.leaveblock.LeaveBlock; 039 import org.kuali.hr.lm.leavecalendar.LeaveCalendarDocument; 040 import org.kuali.hr.test.KPMETestCase; 041 import org.kuali.hr.time.calendar.CalendarEntries; 042 import org.kuali.hr.time.service.base.TkServiceLocator; 043 import org.kuali.hr.time.timesheet.TimesheetDocument; 044 import org.kuali.hr.time.util.TKUtils; 045 import org.kuali.rice.krad.util.ObjectUtils; 046 047 public class BalanceTransferServiceTest extends KPMETestCase { 048 049 /** 050 * Leave Calendar Document Test data 051 */ 052 private final String USER_ID = "testUser1"; 053 054 private LeaveCalendarDocument janLCD; 055 private CalendarEntries janEntry; 056 private LeaveCalendarDocument decLCD; 057 private CalendarEntries decEntry; 058 059 private Date janStart; 060 private Date janEnd; 061 private Date decStart; 062 private Date decEnd; 063 064 private final String JAN_ID = "5001"; 065 private final String DEC_ID = "5000"; 066 067 /** 068 * Timesheet Document Test Data; 069 */ 070 071 /** 072 * Common data 073 */ 074 075 private final String OD_XFER = "5000"; 076 private final String YE_XFER = "5001"; 077 private final String LA_XFER = "5002"; 078 private final String OD_XFER_MAC = "5003"; 079 private final String YE_XFER_MAC = "5004"; 080 private final String LA_XFER_MAC = "5005"; 081 private final String OD_LOSE = "5006"; 082 private final String YE_LOSE = "5007"; 083 private final String LA_LOSE = "5008"; 084 private final String OD_LOSE_MAC = "5009"; 085 private final String YE_LOSE_MAC = "5010"; 086 private final String LA_LOSE_MAC = "5011"; 087 private final String YE_XFER_EO = "5012"; 088 private final java.sql.Date LM_FROM = TKUtils.formatDateString("11/01/2012"); 089 private final java.sql.Date LM_TO = TKUtils.formatDateString("02/01/2013"); 090 091 @Before 092 public void setUp() throws Exception { 093 super.setUp(); 094 TkServiceLocator.getAccrualService().runAccrual(USER_ID,LM_FROM,LM_TO,true,USER_ID); 095 janLCD = TkServiceLocator.getLeaveCalendarService().getLeaveCalendarDocument(JAN_ID); 096 janEntry = janLCD.getCalendarEntry(); 097 janStart = janEntry.getBeginPeriodDate(); 098 janEnd = janEntry.getEndPeriodDate(); 099 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 * Use-case specific testing * 112 ****************************/ 113 114 // 115 // ACTION_AT_MAX_BALANCE = TRANSFER 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 //N/A - Max Carry Over on Year End transfers. 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 * decEntry is not the last calendar entry in the leave plan. Want to check amounts for this action & action frequency 232 * without exceeding the transfer limit. 233 * 234 * max transfer amount = 10 235 * leave balance = 16 236 * max balance = 15 237 * max carry over = 10 238 * 239 * all excess should be transferrable. 1 unit of time for excess over max balance, 5 units of time for 240 * excess over max carry over. 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 /* @Test 254 public void testInitializeTransferUnderMaxBalanceOnYearEndMaxCarryOver() throws Exception { 255 //Create a leave block that will bring the available balance for january down to 14. 256 //this balance would be under the max available balance (15), but over the max annual carry over amount. 257 //i.o.w., this transfer would not due to max balance limit, but max annual carry over. 258 //could also simply change the accrual amount. 259 LeaveBlock usage = new LeaveBlock(); 260 usage.setAccrualCategory(YE_XFER_MAC); 261 usage.setLeaveDate(new java.sql.Date(DateUtils.addDays(janStart,5).getTime())); 262 usage.setLeaveAmount(new BigDecimal(-18)); 263 usage.setPrincipalId(USER_ID); 264 usage.setAccrualGenerated(false); 265 usage.setRequestStatus(LMConstants.REQUEST_STATUS.APPROVED); 266 usage.setDocumentId(janLCD.getDocumentId()); 267 usage.setLmLeaveBlockId("99999"); 268 usage.setEarnCode("EC5"); 269 usage.setBlockId(0L); 270 usage.setLeaveBlockType(LMConstants.LEAVE_BLOCK_TYPE.LEAVE_CALENDAR); 271 List<LeaveBlock> leaveBlocks = new ArrayList<LeaveBlock>(); 272 leaveBlocks.add(usage); 273 TkServiceLocator.getLeaveBlockService().saveLeaveBlocks(leaveBlocks); 274 275 BalanceTransfer bt = new BalanceTransfer(); 276 janLCD = TkServiceLocator.getLeaveCalendarService().getLeaveCalendarDocument(JAN_ID); 277 LeaveSummary summary = TkServiceLocator.getLeaveSummaryService().getLeaveSummary(USER_ID, janLCD.getCalendarEntry()); 278 java.sql.Date effectiveDate = new java.sql.Date(DateUtils.addDays(janStart,3).getTime()); 279 bt = TkServiceLocator.getBalanceTransferService().initializeTransfer(USER_ID, YE_XFER_MAC, aRow.getAccruedBalance(), effectiveDate); 280 assertEquals("transferOnDemand transfer amount", (new BigDecimal(4)).longValue(), bt.getTransferAmount().longValue()); 281 assertEquals("transferOnDemand forfeited amount", (new BigDecimal(0)).longValue(), bt.getForfeitedAmount().longValue()); 282 assertEquals("transferOnDemand amount transferred", (new BigDecimal(2)).longValue(), bt.getAmountTransferred().longValue()); 283 }*/ 284 285 @Test 286 public void testInitializeTransferOnYearEndMaxCarryOverWithForfeiture() throws Exception { 287 //max bal limit reached and max annual carry over triggererd. 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 // ACTION_AT_MAX_BALANCE = LOSE 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 // max balance transfer conversion factor is undefined for YE_XFER_EO 395 assertEquals("transferOnDemand amount transferred", (new BigDecimal(7)).longValue(), bt.getAmountTransferred().longValue()); 396 } 397 /** 398 * End Use-case testing 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 //TODO: write tests for adjusted max balance cases - i.e. FTE < 1, employee override's w/ type MAX_BALANCE 477 478 @Test 479 public void testSubmitToWorkflow() { 480 assertNull(null); 481 } 482 483 }