1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.lm.permission.service;
17
18 import org.joda.time.LocalDate;
19 import org.junit.After;
20 import org.junit.Assert;
21 import org.junit.Before;
22 import org.junit.Test;
23 import org.kuali.hr.KPMEWebTestCase;
24 import org.kuali.kpme.core.FunctionalTest;
25 import org.kuali.kpme.core.api.principal.PrincipalHRAttributes;
26 import org.kuali.kpme.core.calendar.CalendarBo;
27 import org.kuali.kpme.core.principal.PrincipalHRAttributesBo;
28 import org.kuali.kpme.core.service.HrServiceLocator;
29 import org.kuali.kpme.tklm.api.leave.block.LeaveBlock;
30 import org.kuali.kpme.tklm.leave.service.LmServiceLocator;
31 import org.kuali.rice.krad.service.KRADServiceLocator;
32
33 @FunctionalTest
34 public class LMPermissionServiceTest extends KPMEWebTestCase {
35
36 @Before
37 public void setUp() throws Exception{
38 super.setUp();
39
40
41 PrincipalHRAttributesBo phra = PrincipalHRAttributesBo.from(HrServiceLocator.getPrincipalHRAttributeService().getPrincipalHRAttributes("2"));
42 phra.setLeaveCalendar("BWS-LM");
43 phra.setLeaveCalObj(CalendarBo.from(HrServiceLocator.getCalendarService().getCalendarByGroup("BWS-LM")));
44 KRADServiceLocator.getBusinessObjectService().save(phra);
45 }
46
47 @After
48 public void tearDown() throws Exception {
49 super.tearDown();
50
51 PrincipalHRAttributesBo phra = PrincipalHRAttributesBo.from(HrServiceLocator.getPrincipalHRAttributeService().getPrincipalHRAttributes("2"));
52 phra.setLeaveCalendar(null);
53 phra.setLeaveCalObj(null);
54 KRADServiceLocator.getBusinessObjectService().save(phra);
55 }
56
57 @Test
58
59
60 public void testCanDeleteLeaveBlockForSSTOUsageLB() {
61
62
63 LeaveBlock.Builder lb = LeaveBlock.Builder.create(LmServiceLocator.getLeaveBlockService().getLeaveBlock("6000"));
64 lb.setLeaveDateTime(LocalDate.now().toDateTimeAtStartOfDay());
65 boolean deleteFlag = LmServiceLocator.getLMPermissionService().canDeleteLeaveBlock("eric", lb.build());
66 Assert.assertTrue("Leave Block 6000 should be deletable", deleteFlag);
67
68
69 lb = LeaveBlock.Builder.create(LmServiceLocator.getLeaveBlockService().getLeaveBlock("6001"));
70 lb.setLeaveDateTime(LocalDate.now().toDateTimeAtStartOfDay());
71 deleteFlag = LmServiceLocator.getLMPermissionService().canDeleteLeaveBlock("eric", lb.build());
72 Assert.assertTrue("Leave Block 6001 should be deletable", deleteFlag);
73
74
75 lb = LeaveBlock.Builder.create(LmServiceLocator.getLeaveBlockService().getLeaveBlock("6002"));
76 deleteFlag = LmServiceLocator.getLMPermissionService().canDeleteLeaveBlock("eric", lb.build());
77 Assert.assertFalse("Leave Block 6002 should NOT be deletable", deleteFlag);
78
79
80 lb = LeaveBlock.Builder.create(LmServiceLocator.getLeaveBlockService().getLeaveBlock("6003"));
81 lb.setLeaveDateTime(LocalDate.now().toDateTimeAtStartOfDay());
82 deleteFlag = LmServiceLocator.getLMPermissionService().canDeleteLeaveBlock("eric", lb.build());
83 Assert.assertFalse("Leave Block 6003 should NOT be deletable", deleteFlag);
84
85
86 }
87 }