View Javadoc

1   /**
2    * Copyright 2004-2014 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 static org.junit.Assert.assertTrue;
19  
20  import java.math.BigDecimal;
21  
22  import org.apache.log4j.Logger;
23  import org.junit.Test;
24  import org.kuali.kpme.core.IntegrationTest;
25  import org.kuali.kpme.core.UnitTest;
26  import org.kuali.kpme.tklm.TKLMIntegrationTestCase;
27  
28  
29  @UnitTest
30  public class BalanceTransferTest extends TKLMIntegrationTestCase {
31      private static final Logger LOG = Logger.getLogger(BalanceTransferTest.class);
32      public static final String USER_PRINCIPAL_ID = "admin";
33  	private BalanceTransfer balanceTransfer;
34  	
35  	@Override
36  	public void setUp() throws Exception {
37  		super.setUp();
38          //setBaseDetailURL(TkTestConstants.Urls.LEAVE_CALENDAR_SUBMIT_URL + "?documentId=");
39          balanceTransfer = new BalanceTransfer();
40          balanceTransfer.setTransferAmount(new BigDecimal(20));
41          balanceTransfer.setForfeitedAmount(new BigDecimal(0));
42          balanceTransfer.setAmountTransferred(new BigDecimal(10));
43          balanceTransfer.setAccrualCategoryRule("5000");
44  	}
45  	
46  	@Test
47  	public void testTransferWithAccrualRule() throws Exception {
48  		BalanceTransfer btd = new BalanceTransfer();
49  		//btd.setCreditedAccrualCategory(TKTestUtils.creat)
50  		assertTrue("Dummy assertion",true);
51  	}
52  	
53  	@Test
54  	public void testAdjustLowerTransferAmount() {
55  		BigDecimal adjustedTransferAmount = new BigDecimal(10);
56  		balanceTransfer = balanceTransfer.adjust(adjustedTransferAmount);
57  		
58  		assertTrue("Transfer Amount not equals", balanceTransfer.getTransferAmount().compareTo(adjustedTransferAmount) == 0);
59  		assertTrue("Forfeited amount not updated", balanceTransfer.getForfeitedAmount().compareTo(new BigDecimal(10)) == 0);
60  		assertTrue(balanceTransfer.getAmountTransferred().compareTo(new BigDecimal(5)) == 0);
61  	}
62  	
63  	@Test
64  	public void testAdjustLowerTransferAmountWithForfeiture() {
65  		BigDecimal adjustedTransferAmount = new BigDecimal(10);
66  		balanceTransfer.setForfeitedAmount(new BigDecimal(10));
67  		balanceTransfer = balanceTransfer.adjust(adjustedTransferAmount);
68  		
69  		assertTrue("Transfer Amount not equals", balanceTransfer.getTransferAmount().compareTo(adjustedTransferAmount) == 0);
70  		assertTrue("Forfeited amount not updated", balanceTransfer.getForfeitedAmount().compareTo(new BigDecimal(20)) == 0);
71  		assertTrue(balanceTransfer.getAmountTransferred().compareTo(new BigDecimal(5)) == 0);
72  	}
73  	
74  	@Test
75  	public void testAdjustRaiseTransferAmount() {
76  		BigDecimal adjustedTransferAmount = new BigDecimal(30);
77  		balanceTransfer = balanceTransfer.adjust(adjustedTransferAmount);
78  		
79  		assertTrue("Transfer Amount not equals", balanceTransfer.getTransferAmount().compareTo(adjustedTransferAmount) == 0);
80  		assertTrue("Forfeited amount not updated", balanceTransfer.getForfeitedAmount().compareTo(BigDecimal.ZERO) == 0);
81  		assertTrue(balanceTransfer.getAmountTransferred().compareTo(new BigDecimal(15)) == 0);
82  	}
83  	
84  	@Test
85  	public void testAdjustRaiseTransferAmountWithForfeitureLessThanDifference() {
86  		BigDecimal adjustedTransferAmount = new BigDecimal(40);
87  		balanceTransfer.setForfeitedAmount(new BigDecimal(10));
88  		
89  		balanceTransfer = balanceTransfer.adjust(adjustedTransferAmount);
90  		
91  		assertTrue("Transfer Amount not equals", balanceTransfer.getTransferAmount().compareTo(adjustedTransferAmount) == 0);
92  		assertTrue("Forfeited amount not updated", balanceTransfer.getForfeitedAmount().compareTo(BigDecimal.ZERO) == 0);
93  		assertTrue(balanceTransfer.getAmountTransferred().compareTo(new BigDecimal(20)) == 0);
94  	}
95  	
96  	@Test
97  	public void testAdjustRaiseTransferAmountWithForfeitureMoreThanDifference() {
98  		BigDecimal adjustedTransferAmount = new BigDecimal(30);
99  		balanceTransfer.setForfeitedAmount(new BigDecimal(15));
100 		balanceTransfer = balanceTransfer.adjust(adjustedTransferAmount);
101 		
102 		assertTrue("Transfer Amount not equals", balanceTransfer.getTransferAmount().compareTo(adjustedTransferAmount) == 0);
103 		assertTrue("Forfeited amount not updated", balanceTransfer.getForfeitedAmount().compareTo(new BigDecimal(5)) == 0);
104 		assertTrue(balanceTransfer.getAmountTransferred().compareTo(new BigDecimal(15)) == 0);
105 	}
106 	
107 }