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