View Javadoc

1   /**
2    * Copyright 2004-2013 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.hr.lm.balancetransfer.validation;
17  
18  import java.sql.Date;
19  
20  import org.joda.time.DateTime;
21  import org.junit.Assert;
22  import org.junit.Test;
23  import org.kuali.hr.lm.balancetransfer.BalanceTransfer;
24  import org.kuali.hr.test.KPMETestCase;
25  import org.kuali.hr.time.util.TKUtils;
26  import org.kuali.rice.krad.util.GlobalVariables;
27  
28  public class BalanceTransferValidationUtilsTest extends KPMETestCase {
29  
30  	@Test
31  	public void TestValidateSstoTranser() {
32  		Date leaveDate = new Date((new DateTime(2013, 1, 11, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone())).getMillis());
33  		BalanceTransfer bt = new BalanceTransfer();
34  		bt.setEffectiveDate(leaveDate);
35  		bt.setPrincipalId("testUser");
36  		
37  		boolean flag = BalanceTransferValidationUtils.validateSstoTranser(bt);
38  		Assert.assertFalse("Validation should be false", flag);
39  		Assert.assertTrue("There should be 1 error messages",  GlobalVariables.getMessageMap().getErrorCount() == 1);
40  		Assert.assertTrue("There should be error messages for SSTO does not exist", GlobalVariables.getMessageMap().containsMessageKey("balanceTransfer.transferSSTO.sstoDoesNotExis"));
41  		
42  		GlobalVariables.getMessageMap().clearErrorMessages();
43  		bt.setSstoId("5000");
44  		bt.setFromAccrualCategory("fromAC");
45  		flag = BalanceTransferValidationUtils.validateSstoTranser(bt);
46  		Assert.assertFalse("Validation should be false", flag);
47  		Assert.assertTrue("There should be 1 error messages",  GlobalVariables.getMessageMap().getErrorCount() == 1);
48  		Assert.assertTrue("There should be error messages for From Accrual category being wrong", GlobalVariables.getMessageMap().containsMessageKey("balanceTransfer.transferSSTO.fromACWrong"));
49  		
50  		GlobalVariables.getMessageMap().clearErrorMessages();
51  		bt.setFromAccrualCategory("ISU-HOL");
52  		bt.setToAccrualCategory("ISU-HOL");
53  		flag = BalanceTransferValidationUtils.validateSstoTranser(bt);
54  		Assert.assertFalse("Validation should be false", flag);
55  		Assert.assertTrue("There should be 1 error messages",  GlobalVariables.getMessageMap().getErrorCount() == 1);
56  		Assert.assertTrue("There should be error messages for From and To Accrual categories are the same", GlobalVariables.getMessageMap().containsMessageKey("balanceTransfer.transferSSTO.fromAndToACTheSame"));
57  		
58  		GlobalVariables.getMessageMap().clearErrorMessages();
59  		bt.setToAccrualCategory("ISU-HOL-TRF");
60  		flag = BalanceTransferValidationUtils.validateSstoTranser(bt);
61  		Assert.assertFalse("Validation should be false", flag);
62  		Assert.assertTrue("There should be 1 error messages",  GlobalVariables.getMessageMap().getErrorCount() == 1);
63  		Assert.assertTrue("There should be error messages for Accrual categories does not exist", GlobalVariables.getMessageMap().containsMessageKey("balanceTransfer.transferSSTO.acDoesNotExist"));
64  		
65  		leaveDate = new Date((new DateTime(2013, 2, 11, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone())).getMillis());
66  		bt.setEffectiveDate(leaveDate);
67  		GlobalVariables.getMessageMap().clearErrorMessages();
68  		flag = BalanceTransferValidationUtils.validateSstoTranser(bt);
69  		Assert.assertTrue("Validation should be true", flag);
70  		Assert.assertTrue("There should be NO error messages",  GlobalVariables.getMessageMap().getErrorCount() == 0);
71  	}
72  	
73  }