001 /** 002 * Copyright 2004-2013 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.lm.leaveCalendar.service; 017 018 import java.util.Date; 019 import java.util.List; 020 021 import org.junit.Assert; 022 import org.junit.Test; 023 import org.kuali.hr.lm.leaveblock.LeaveBlock; 024 import org.kuali.hr.lm.leavecalendar.LeaveCalendarDocument; 025 import org.kuali.hr.test.KPMETestCase; 026 import org.kuali.hr.time.calendar.CalendarEntries; 027 import org.kuali.hr.time.service.base.TkServiceLocator; 028 import org.kuali.rice.kew.api.exception.WorkflowException; 029 030 public class LeaveCalendarServiceTest extends KPMETestCase { 031 032 @Test 033 public void testOpenLeaveCalendarDocument() throws WorkflowException { 034 CalendarEntries calEntry = TkServiceLocator.getCalendarEntriesService().getCalendarEntries("5000"); 035 Date beginDate = calEntry.getBeginPeriodDate(); 036 Date endDate = calEntry.getEndPeriodDate(); 037 038 List<LeaveBlock> leaveBlocks = TkServiceLocator.getLeaveBlockService().getLeaveBlocks("admin", beginDate, endDate); 039 LeaveBlock lb = leaveBlocks.get(0); 040 Assert.assertNull("Leave Block should have null as documentId", lb.getDocumentId()); 041 042 // after leave document created, the existing leave blocks should be assigned with the new document id 043 LeaveCalendarDocument lcd = TkServiceLocator.getLeaveCalendarService().openLeaveCalendarDocument("admin", calEntry); 044 Assert.assertNotNull("Leave Calendar document should not be null", lcd); 045 046 leaveBlocks = TkServiceLocator.getLeaveBlockService().getLeaveBlocks("admin", beginDate, endDate); 047 lb = leaveBlocks.get(0); 048 Assert.assertTrue("Leave Block should have the new leave calendar document's id as document id", lb.getDocumentId().equals(lcd.getDocumentId())); 049 } 050 051 @Test 052 public void testShouldCreateLeaveDocument(){ 053 // no jobs found for assignment of testUser1 with flsa_status = exempt and leave_eligible = yes 054 CalendarEntries calEntry = TkServiceLocator.getCalendarEntriesService().getCalendarEntries("5001"); 055 boolean flag = TkServiceLocator.getLeaveCalendarService().shouldCreateLeaveDocument("testUser1", calEntry); 056 Assert.assertFalse("Should NOT create leave document for 'testUser1'", flag); 057 058 flag = TkServiceLocator.getLeaveCalendarService().shouldCreateLeaveDocument("testUser2", calEntry); 059 Assert.assertTrue("Should create leave document for 'testUser2'", flag); 060 061 } 062 }