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