View Javadoc

1   /**
2    * Copyright 2004-2014 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.kpme.tklm.leave.calendar;
17  
18  import java.util.List;
19  
20  import org.joda.time.DateTime;
21  import org.junit.Assert;
22  import org.junit.Test;
23  import org.kuali.kpme.core.IntegrationTest;
24  import org.kuali.kpme.core.calendar.entry.CalendarEntry;
25  import org.kuali.kpme.core.service.HrServiceLocator;
26  import org.kuali.kpme.tklm.TKLMIntegrationTestCase;
27  import org.kuali.kpme.tklm.leave.block.LeaveBlock;
28  import org.kuali.kpme.tklm.leave.service.LmServiceLocator;
29  import org.kuali.rice.kew.api.exception.WorkflowException;
30  
31  @IntegrationTest
32  public class LeaveCalendarServiceTest extends TKLMIntegrationTestCase {
33  	
34  	@Test
35  	public void testOpenLeaveCalendarDocument() throws WorkflowException {
36  		CalendarEntry calEntry = HrServiceLocator.getCalendarEntryService().getCalendarEntry("5000");
37  		DateTime beginDate = calEntry.getBeginPeriodFullDateTime();
38  		DateTime endDate = calEntry.getEndPeriodFullDateTime();
39  		
40  		List<LeaveBlock> leaveBlocks = LmServiceLocator.getLeaveBlockService().getLeaveBlocks("admin", beginDate.toLocalDate(), endDate.toLocalDate());
41  		LeaveBlock lb = leaveBlocks.get(0);
42  		Assert.assertNull("Leave Block should have null as documentId", lb.getDocumentId());
43  		
44  		// after leave document created, the existing leave blocks should be assigned with the new document id
45  		LeaveCalendarDocument lcd = LmServiceLocator.getLeaveCalendarService().openLeaveCalendarDocument("admin", calEntry);
46  		Assert.assertNotNull("Leave Calendar document should not be null", lcd);
47  		
48  		leaveBlocks = LmServiceLocator.getLeaveBlockService().getLeaveBlocks("admin", beginDate.toLocalDate(), endDate.toLocalDate());
49  		lb = leaveBlocks.get(0);
50  		Assert.assertTrue("Leave Block should have the new leave calendar document's id as document id", lb.getDocumentId().equals(lcd.getDocumentId()));		
51  	}
52  	
53  	@Test
54  	public void testShouldCreateLeaveDocument(){
55  		// no jobs found for assignment of testUser1 with flsa_status = exempt and leave_eligible = yes
56  		CalendarEntry calEntry = HrServiceLocator.getCalendarEntryService().getCalendarEntry("5001");
57  		boolean flag = LmServiceLocator.getLeaveCalendarService().shouldCreateLeaveDocument("testUser1", calEntry);
58  		Assert.assertFalse("Should NOT create leave document for 'testUser1'", flag);
59  		
60  		flag = LmServiceLocator.getLeaveCalendarService().shouldCreateLeaveDocument("testUser2", calEntry);
61  		Assert.assertTrue("Should create leave document for 'testUser2'", flag);
62  		
63  	}
64  }