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