001/**
002 * Copyright 2004-2015 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 */
016package org.kuali.hr.lm.permission.service;
017
018import org.joda.time.LocalDate;
019import org.junit.After;
020import org.junit.Assert;
021import org.junit.Before;
022import org.junit.Test;
023import org.kuali.hr.KPMEWebTestCase;
024import org.kuali.kpme.core.FunctionalTest;
025import org.kuali.kpme.core.principal.PrincipalHRAttributes;
026import org.kuali.kpme.core.service.HrServiceLocator;
027import org.kuali.kpme.tklm.leave.block.LeaveBlock;
028import org.kuali.kpme.tklm.leave.service.LmServiceLocator;
029import org.kuali.rice.krad.service.KRADServiceLocator;
030
031@FunctionalTest
032public class LMPermissionServiceTest extends KPMEWebTestCase {
033        
034        @Before
035        public void setUp() throws Exception{
036                super.setUp();
037                // change taget person to a non-admin
038            //HrContext.setTargetPrincipalId("eric");
039            PrincipalHRAttributes phra = HrServiceLocator.getPrincipalHRAttributeService().getPrincipalHRAttributes("2");
040            phra.setLeaveCalendar("BWS-LM");
041            phra.setLeaveCalObj(HrServiceLocator.getCalendarService().getCalendarByGroup("BWS-LM"));
042            KRADServiceLocator.getBusinessObjectService().save(phra);
043        }
044
045        @After
046        public void tearDown() throws Exception {
047                super.tearDown();
048            //HrContext.setTargetPrincipalId("admin");
049            PrincipalHRAttributes phra = HrServiceLocator.getPrincipalHRAttributeService().getPrincipalHRAttributes("2");
050            phra.setLeaveCalendar(null);
051            phra.setLeaveCalObj(null);
052            KRADServiceLocator.getBusinessObjectService().save(phra);
053        }
054        
055        @Test
056        // added this brand new test for kpme-2109 so this test does not cover all existing scenarios,
057        // only system scheduled time off usage leave blocks that can be banked or transferred
058        public void testCanDeleteLeaveBlockForSSTOUsageLB() {
059                // leave block 6000 is a bankable ssto usage block that is on current leave calendar, 
060                // ssto 2000's unused time is "B"
061                LeaveBlock lb = LmServiceLocator.getLeaveBlockService().getLeaveBlock("6000");
062                lb.setLeaveDate(LocalDate.now().toDate());
063                boolean deleteFlag = LmServiceLocator.getLMPermissionService().canDeleteLeaveBlock("eric", lb);
064                Assert.assertTrue("Leave Block 6000 should be deletable", deleteFlag);
065                
066                // leave block 6001 is a ssto usage block that can be transferred, ssto 2001's unused time is "T"
067                lb = LmServiceLocator.getLeaveBlockService().getLeaveBlock("6001");
068                lb.setLeaveDate(LocalDate.now().toDate());
069                deleteFlag = LmServiceLocator.getLMPermissionService().canDeleteLeaveBlock("eric", lb);
070                Assert.assertTrue("Leave Block 6001 should be deletable", deleteFlag);
071                
072                // leave block 6002 is a ssto usage block that is not on current leave calendar
073                lb = LmServiceLocator.getLeaveBlockService().getLeaveBlock("6002");
074                deleteFlag = LmServiceLocator.getLMPermissionService().canDeleteLeaveBlock("eric", lb);
075                Assert.assertFalse("Leave Block 6002 should NOT be deletable", deleteFlag);
076                
077                // leave block 6003 is a ssto accrual block, not a usage, it's leave amount is 8
078                lb = LmServiceLocator.getLeaveBlockService().getLeaveBlock("6003");
079                lb.setLeaveDate(LocalDate.now().toDate());
080                deleteFlag = LmServiceLocator.getLMPermissionService().canDeleteLeaveBlock("eric", lb);
081                Assert.assertFalse("Leave Block 6003 should NOT be deletable", deleteFlag);
082                
083                
084        }
085}