001    /**
002     * Copyright 2004-2012 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.time.department.earncode.service;
017    
018    import java.util.Calendar;
019    import java.util.List;
020    
021    import org.junit.Assert;
022    import org.junit.Before;
023    import org.junit.Test;
024    import org.kuali.hr.earncodesec.EarnCodeSecurity;
025    import org.kuali.hr.earncodesec.service.EarnCodeSecurityService;
026    import org.kuali.hr.test.KPMETestCase;
027    import org.kuali.hr.time.service.base.TkServiceLocator;
028    
029    public class EarnCodeSecurityServiceImplTest extends KPMETestCase {
030    
031            public static final String TEST_TEST_DEPT = "TEST-DEPT";
032            public static final String TEST_LORA = "LORA-DEPT";
033            public static final String TEST_SAL_GROUP_A10 = "A10";
034            public static final String TEST_SAL_GROUP_A = "A";
035            public static final String TEST_LOCATION = "";
036            private static final java.sql.Date TEST_DATE=new java.sql.Date(Calendar.getInstance().getTimeInMillis());
037            private EarnCodeSecurityService earnCodeSecurityService = null;
038    
039            @Before
040            public void setUp() throws Exception {
041                    super.setUp();
042                    earnCodeSecurityService=TkServiceLocator.getEarnCodeSecurityService();
043            }
044            
045            @Test
046            public void testGetEarnCodeSecurities() throws Exception {              
047                    // Testing Wildcard on department.
048                    List<EarnCodeSecurity> earnCodeSecurities = earnCodeSecurityService.getEarnCodeSecurities(TEST_LORA, TEST_SAL_GROUP_A10, TEST_LOCATION, TEST_DATE);
049                    Assert.assertEquals("Wrong number of earn codes returned.", 5, earnCodeSecurities.size());
050                    // Test sorting of earn codes
051                    Assert.assertEquals("First Earn Code should be RGH", "RGH", earnCodeSecurities.get(0).getEarnCode());
052                    Assert.assertEquals("Second Earn Code should be SCK", "SCK", earnCodeSecurities.get(1).getEarnCode());
053                    Assert.assertEquals("Third Earn Code should be VAC", "VAC", earnCodeSecurities.get(2).getEarnCode());
054                    Assert.assertEquals("Forth Earn Code should be XYZ", "XYZ", earnCodeSecurities.get(3).getEarnCode());
055                    Assert.assertEquals("Fifth Earn Code should be XZZ", "XZZ", earnCodeSecurities.get(4).getEarnCode());
056                    
057                    for (EarnCodeSecurity ec : earnCodeSecurities) {
058                            Assert.assertTrue("Wrong department earn code.", ((ec.getDept()).equals("LORA-DEPT") || (ec.getDept()).equals("%")) );
059                            Assert.assertTrue("Wrong SAL_GROUP.", (ec.getHrSalGroup()).equals(TEST_SAL_GROUP_A10) || (ec.getHrSalGroup()).equals("%") );
060                    }
061                    
062                    // Testing Wildcard on dept and salGroup.
063                    List<EarnCodeSecurity> earnCodesSec1 = earnCodeSecurityService.getEarnCodeSecurities(TEST_TEST_DEPT, TEST_SAL_GROUP_A, TEST_LOCATION, TEST_DATE);
064                    Assert.assertEquals("Wrong number of earn codes returned.", 2, earnCodesSec1.size());
065                    
066                    for (EarnCodeSecurity ec1 : earnCodesSec1) {
067                            Assert.assertTrue("Wrong department earn code.", ((ec1.getDept()).equals(TEST_TEST_DEPT) || (ec1.getDept()).equals("%")) );
068                            Assert.assertTrue("Wrong SAL_GROUP.", (ec1.getHrSalGroup()).equals(TEST_SAL_GROUP_A) || (ec1.getHrSalGroup()).equals("%") );
069                    }
070            }
071    
072    }