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.leaveCalendar.service;
17  
18  import java.util.Date;
19  import java.util.List;
20  
21  import org.junit.Assert;
22  import org.junit.Test;
23  import org.kuali.hr.lm.leaveblock.LeaveBlock;
24  import org.kuali.hr.lm.leavecalendar.LeaveCalendarDocument;
25  import org.kuali.hr.test.KPMETestCase;
26  import org.kuali.hr.time.calendar.CalendarEntries;
27  import org.kuali.hr.time.service.base.TkServiceLocator;
28  import org.kuali.rice.kew.api.exception.WorkflowException;
29  
30  public class LeaveCalendarServiceTest extends KPMETestCase {
31  	
32  	@Test
33  	public void testOpenLeaveCalendarDocument() throws WorkflowException {
34  		CalendarEntries calEntry = TkServiceLocator.getCalendarEntriesService().getCalendarEntries("5000");
35  		Date beginDate = calEntry.getBeginPeriodDate();
36  		Date endDate = calEntry.getEndPeriodDate();
37  		
38  		List<LeaveBlock> leaveBlocks = TkServiceLocator.getLeaveBlockService().getLeaveBlocks("admin", beginDate, endDate);
39  		LeaveBlock lb = leaveBlocks.get(0);
40  		Assert.assertNull("Leave Block should have null as documentId", lb.getDocumentId());
41  		
42  		// after leave document created, the existing leave blocks should be assigned with the new document id
43  		LeaveCalendarDocument lcd = TkServiceLocator.getLeaveCalendarService().openLeaveCalendarDocument("admin", calEntry);
44  		Assert.assertNotNull("Leave Calendar document should not be null", lcd);
45  		
46  		leaveBlocks = TkServiceLocator.getLeaveBlockService().getLeaveBlocks("admin", beginDate, endDate);
47  		lb = leaveBlocks.get(0);
48  		Assert.assertTrue("Leave Block should have the new leave calendar document's id as document id", lb.getDocumentId().equals(lcd.getDocumentId()));		
49  	}
50  	
51  	@Test
52  	public void testShouldCreateLeaveDocument(){
53  		// no jobs found for assignment of testUser1 with flsa_status = exempt and leave_eligible = yes
54  		CalendarEntries calEntry = TkServiceLocator.getCalendarEntriesService().getCalendarEntries("5001");
55  		boolean flag = TkServiceLocator.getLeaveCalendarService().shouldCreateLeaveDocument("testUser1", calEntry);
56  		Assert.assertFalse("Should NOT create leave document for 'testUser1'", flag);
57  		
58  		flag = TkServiceLocator.getLeaveCalendarService().shouldCreateLeaveDocument("testUser2", calEntry);
59  		Assert.assertTrue("Should create leave document for 'testUser2'", flag);
60  		
61  	}
62  }