1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.time.timeblock.service;
17
18 import org.joda.time.DateTime;
19 import org.junit.Assert;
20 import org.junit.Test;
21 import org.kuali.hr.KPMEWebTestCase;
22 import org.kuali.kpme.core.FunctionalTest;
23 import org.kuali.kpme.tklm.time.service.TkServiceLocator;
24 import org.kuali.kpme.tklm.time.timeblock.TimeBlock;
25 import org.kuali.rice.krad.util.GlobalVariables;
26
27 @FunctionalTest
28 public class TimeBlockServiceTest extends KPMEWebTestCase {
29
30 @Test
31 public void testIsTimeBlockEditableAdmin() throws Exception {
32 TimeBlock tb = new TimeBlock();
33 tb.setJobNumber(new Long(30));
34 tb.setBeginDateTime(new DateTime(2010, 1, 1, 0, 0, 0));
35 tb.setEndDateTime(new DateTime(2010, 1, 1, 0, 0, 0));
36
37 GlobalVariables.getUserSession().setBackdoorUser("admin");
38
39 tb.setUserPrincipalId("admin");
40 boolean editable = TkServiceLocator.getTimeBlockService().getTimeBlockEditable(tb);
41 Assert.assertEquals("TimeBlock created by admin should be editable by admin", true, editable);
42
43 tb.setUserPrincipalId("eric");
44 editable = TkServiceLocator.getTimeBlockService().getTimeBlockEditable(tb);
45 Assert.assertEquals("TimeBlock created by eric should be editable by admin", true, editable);
46
47 tb.setUserPrincipalId("eric");
48 tb.setClockLogCreated(true);
49 editable = TkServiceLocator.getTimeBlockService().getTimeBlockEditable(tb);
50 Assert.assertEquals("TimeBlock created by Clock in/out should be editable by admin", true, editable);
51 }
52
53 @Test
54 public void testIsTimeBlockEditableUser() throws Exception {
55 TimeBlock tb = new TimeBlock();
56 tb.setJobNumber(new Long(1));
57 tb.setBeginDateTime(new DateTime(2010, 8, 12, 0, 0, 0));
58 tb.setEndDateTime(new DateTime(2010, 8, 12, 0, 0, 0));
59
60 GlobalVariables.getUserSession().setBackdoorUser("eric");
61
62 tb.setUserPrincipalId("admin");
63 boolean editable = TkServiceLocator.getTimeBlockService().getTimeBlockEditable(tb);
64 Assert.assertEquals("TimeBlock created by admin should NOT be editable by eric", false, editable);
65
66 tb.setUserPrincipalId("eric");
67 tb.setClockLogCreated(true);
68 editable = TkServiceLocator.getTimeBlockService().getTimeBlockEditable(tb);
69 Assert.assertEquals("TimeBlock created by Clock in/out should NOT be editable by eric", false, editable);
70 }
71
72 }