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.permission.service;
17  
18  import org.joda.time.LocalDate;
19  import org.junit.After;
20  import org.junit.Assert;
21  import org.junit.Before;
22  import org.junit.Test;
23  import org.kuali.hr.KPMEWebTestCase;
24  import org.kuali.kpme.core.FunctionalTest;
25  import org.kuali.kpme.core.principal.PrincipalHRAttributes;
26  import org.kuali.kpme.core.service.HrServiceLocator;
27  import org.kuali.kpme.tklm.leave.block.LeaveBlock;
28  import org.kuali.kpme.tklm.leave.service.LmServiceLocator;
29  import org.kuali.rice.krad.service.KRADServiceLocator;
30  
31  @FunctionalTest
32  public class LMPermissionServiceTest extends KPMEWebTestCase {
33  	
34  	@Before
35  	public void setUp() throws Exception{
36  		super.setUp();
37  		// change taget person to a non-admin
38  	    //HrContext.setTargetPrincipalId("eric");
39  	    PrincipalHRAttributes phra = HrServiceLocator.getPrincipalHRAttributeService().getPrincipalHRAttributes("2");
40  	    phra.setLeaveCalendar("BWS-LM");
41  	    phra.setLeaveCalObj(HrServiceLocator.getCalendarService().getCalendarByGroup("BWS-LM"));
42  	    KRADServiceLocator.getBusinessObjectService().save(phra);
43  	}
44  
45  	@After
46  	public void tearDown() throws Exception {
47  		super.tearDown();
48  	    //HrContext.setTargetPrincipalId("admin");
49  	    PrincipalHRAttributes phra = HrServiceLocator.getPrincipalHRAttributeService().getPrincipalHRAttributes("2");
50  	    phra.setLeaveCalendar(null);
51  	    phra.setLeaveCalObj(null);
52  	    KRADServiceLocator.getBusinessObjectService().save(phra);
53  	}
54  	
55  	@Test
56  	// added this brand new test for kpme-2109 so this test does not cover all existing scenarios,
57  	// only system scheduled time off usage leave blocks that can be banked or transferred
58  	public void testCanDeleteLeaveBlockForSSTOUsageLB() {
59  		// leave block 6000 is a bankable ssto usage block that is on current leave calendar, 
60  		// ssto 2000's unused time is "B"
61  		LeaveBlock lb = LmServiceLocator.getLeaveBlockService().getLeaveBlock("6000");
62  		lb.setLeaveDate(LocalDate.now().toDate());
63  		boolean deleteFlag = LmServiceLocator.getLMPermissionService().canDeleteLeaveBlock("eric", lb);
64  		Assert.assertTrue("Leave Block 6000 should be deletable", deleteFlag);
65  		
66  		// leave block 6001 is a ssto usage block that can be transferred, ssto 2001's unused time is "T"
67  		lb = LmServiceLocator.getLeaveBlockService().getLeaveBlock("6001");
68  		lb.setLeaveDate(LocalDate.now().toDate());
69  		deleteFlag = LmServiceLocator.getLMPermissionService().canDeleteLeaveBlock("eric", lb);
70  		Assert.assertTrue("Leave Block 6001 should be deletable", deleteFlag);
71  		
72  		// leave block 6002 is a ssto usage block that is not on current leave calendar
73  		lb = LmServiceLocator.getLeaveBlockService().getLeaveBlock("6002");
74  		deleteFlag = LmServiceLocator.getLMPermissionService().canDeleteLeaveBlock("eric", lb);
75  		Assert.assertFalse("Leave Block 6002 should NOT be deletable", deleteFlag);
76  		
77  		// leave block 6003 is a ssto accrual block, not a usage, it's leave amount is 8
78  		lb = LmServiceLocator.getLeaveBlockService().getLeaveBlock("6003");
79  		lb.setLeaveDate(LocalDate.now().toDate());
80  		deleteFlag = LmServiceLocator.getLMPermissionService().canDeleteLeaveBlock("eric", lb);
81  		Assert.assertFalse("Leave Block 6003 should NOT be deletable", deleteFlag);
82  		
83  		
84  	}
85  }