1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
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  		
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  		
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  }