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.validation;
017    
018    import java.sql.Date;
019    
020    import org.joda.time.DateTime;
021    import org.junit.Assert;
022    import org.junit.Test;
023    import org.kuali.hr.lm.balancetransfer.BalanceTransfer;
024    import org.kuali.hr.test.KPMETestCase;
025    import org.kuali.hr.time.util.TKUtils;
026    import org.kuali.rice.krad.util.GlobalVariables;
027    
028    public class BalanceTransferValidationUtilsTest extends KPMETestCase {
029    
030            @Test
031            public void TestValidateSstoTranser() {
032                    Date leaveDate = new Date((new DateTime(2013, 1, 11, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone())).getMillis());
033                    BalanceTransfer bt = new BalanceTransfer();
034                    bt.setEffectiveDate(leaveDate);
035                    bt.setPrincipalId("testUser");
036                    
037                    boolean flag = BalanceTransferValidationUtils.validateSstoTranser(bt);
038                    Assert.assertFalse("Validation should be false", flag);
039                    Assert.assertTrue("There should be 1 error messages",  GlobalVariables.getMessageMap().getErrorCount() == 1);
040                    Assert.assertTrue("There should be error messages for SSTO does not exist", GlobalVariables.getMessageMap().containsMessageKey("balanceTransfer.transferSSTO.sstoDoesNotExis"));
041                    
042                    GlobalVariables.getMessageMap().clearErrorMessages();
043                    bt.setSstoId("5000");
044                    bt.setFromAccrualCategory("fromAC");
045                    flag = BalanceTransferValidationUtils.validateSstoTranser(bt);
046                    Assert.assertFalse("Validation should be false", flag);
047                    Assert.assertTrue("There should be 1 error messages",  GlobalVariables.getMessageMap().getErrorCount() == 1);
048                    Assert.assertTrue("There should be error messages for From Accrual category being wrong", GlobalVariables.getMessageMap().containsMessageKey("balanceTransfer.transferSSTO.fromACWrong"));
049                    
050                    GlobalVariables.getMessageMap().clearErrorMessages();
051                    bt.setFromAccrualCategory("ISU-HOL");
052                    bt.setToAccrualCategory("ISU-HOL");
053                    flag = BalanceTransferValidationUtils.validateSstoTranser(bt);
054                    Assert.assertFalse("Validation should be false", flag);
055                    Assert.assertTrue("There should be 1 error messages",  GlobalVariables.getMessageMap().getErrorCount() == 1);
056                    Assert.assertTrue("There should be error messages for From and To Accrual categories are the same", GlobalVariables.getMessageMap().containsMessageKey("balanceTransfer.transferSSTO.fromAndToACTheSame"));
057                    
058                    GlobalVariables.getMessageMap().clearErrorMessages();
059                    bt.setToAccrualCategory("ISU-HOL-TRF");
060                    flag = BalanceTransferValidationUtils.validateSstoTranser(bt);
061                    Assert.assertFalse("Validation should be false", flag);
062                    Assert.assertTrue("There should be 1 error messages",  GlobalVariables.getMessageMap().getErrorCount() == 1);
063                    Assert.assertTrue("There should be error messages for Accrual categories does not exist", GlobalVariables.getMessageMap().containsMessageKey("balanceTransfer.transferSSTO.acDoesNotExist"));
064                    
065                    leaveDate = new Date((new DateTime(2013, 2, 11, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone())).getMillis());
066                    bt.setEffectiveDate(leaveDate);
067                    GlobalVariables.getMessageMap().clearErrorMessages();
068                    flag = BalanceTransferValidationUtils.validateSstoTranser(bt);
069                    Assert.assertTrue("Validation should be true", flag);
070                    Assert.assertTrue("There should be NO error messages",  GlobalVariables.getMessageMap().getErrorCount() == 0);
071            }
072            
073    }