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 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
33
34 @FunctionalTest
35 public class LMPermissionServiceTest extends KPMEWebTestCase {
36
37 @Before
38 public void setUp() throws Exception{
39 super.setUp();
40
41
42 PrincipalHRAttributesBo phra = PrincipalHRAttributesBo.from(HrServiceLocator.getPrincipalHRAttributeService().getPrincipalHRAttributes("2"));
43 phra.setLeaveCalendar("BWS-LM");
44 phra.setLeaveCalObj(CalendarBo.from(HrServiceLocator.getCalendarService().getCalendarByGroup("BWS-LM")));
45 KRADServiceLocatorWeb.getLegacyDataAdapter().save(phra);
46 }
47
48 @After
49 public void tearDown() throws Exception {
50 super.tearDown();
51
52 PrincipalHRAttributesBo phra = PrincipalHRAttributesBo.from(HrServiceLocator.getPrincipalHRAttributeService().getPrincipalHRAttributes("2"));
53 phra.setLeaveCalendar(null);
54 phra.setLeaveCalObj(null);
55 KRADServiceLocatorWeb.getLegacyDataAdapter().save(phra);
56 }
57
58 @Test
59
60
61 public void testCanDeleteLeaveBlockForSSTOUsageLB() {
62
63
64 LeaveBlock.Builder lb = LeaveBlock.Builder.create(LmServiceLocator.getLeaveBlockService().getLeaveBlock("6000"));
65 lb.setLeaveDateTime(LocalDate.now().toDateTimeAtStartOfDay());
66 boolean deleteFlag = LmServiceLocator.getLMPermissionService().canDeleteLeaveBlock("eric", lb.build());
67 Assert.assertTrue("Leave Block 6000 should be deletable", deleteFlag);
68
69
70 lb = LeaveBlock.Builder.create(LmServiceLocator.getLeaveBlockService().getLeaveBlock("6001"));
71 lb.setLeaveDateTime(LocalDate.now().toDateTimeAtStartOfDay());
72 deleteFlag = LmServiceLocator.getLMPermissionService().canDeleteLeaveBlock("eric", lb.build());
73 Assert.assertTrue("Leave Block 6001 should be deletable", deleteFlag);
74
75
76 lb = LeaveBlock.Builder.create(LmServiceLocator.getLeaveBlockService().getLeaveBlock("6002"));
77 deleteFlag = LmServiceLocator.getLMPermissionService().canDeleteLeaveBlock("eric", lb.build());
78 Assert.assertFalse("Leave Block 6002 should NOT be deletable", deleteFlag);
79
80
81 lb = LeaveBlock.Builder.create(LmServiceLocator.getLeaveBlockService().getLeaveBlock("6003"));
82 lb.setLeaveDateTime(LocalDate.now().toDateTimeAtStartOfDay());
83 deleteFlag = LmServiceLocator.getLMPermissionService().canDeleteLeaveBlock("eric", lb.build());
84 Assert.assertFalse("Leave Block 6003 should NOT be deletable", deleteFlag);
85
86
87 }
88 }