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 java.text.DateFormat;
19 import java.text.SimpleDateFormat;
20
21 import org.junit.Assert;
22 import org.junit.Test;
23 import org.kuali.hr.test.KPMETestCase;
24 import org.kuali.hr.time.service.base.TkServiceLocator;
25 import org.kuali.hr.time.timeblock.TimeBlock;
26 import org.kuali.rice.krad.util.GlobalVariables;
27
28 public class TimeBlockServiceTest extends KPMETestCase {
29
30 private static final DateFormat DATE_FORMAT = new SimpleDateFormat("MM/dd/yy");
31
32 @Test
33 public void testIsTimeBlockEditableAdmin() throws Exception {
34 TimeBlock tb = new TimeBlock();
35 tb.setJobNumber(new Long(30));
36 tb.setBeginDate(new java.sql.Date(DATE_FORMAT.parse("01/01/2010").getTime()));
37 tb.setEndDate(new java.sql.Date(DATE_FORMAT.parse("01/01/2010").getTime()));
38
39 GlobalVariables.getUserSession().setBackdoorUser("admin");
40
41 tb.setUserPrincipalId("admin");
42 boolean editable = TkServiceLocator.getTimeBlockService().isTimeBlockEditable(tb);
43 Assert.assertEquals("TimeBlock created by admin should be editable by admin", true, editable);
44
45 tb.setUserPrincipalId("eric");
46 editable = TkServiceLocator.getTimeBlockService().isTimeBlockEditable(tb);
47 Assert.assertEquals("TimeBlock created by eric should be editable by admin", true, editable);
48
49 tb.setUserPrincipalId("eric");
50 tb.setClockLogCreated(true);
51 editable = TkServiceLocator.getTimeBlockService().isTimeBlockEditable(tb);
52 Assert.assertEquals("TimeBlock created by Clock in/out should be editable by admin", true, editable);
53 }
54
55 @Test
56 public void testIsTimeBlockEditableUser() throws Exception {
57 TimeBlock tb = new TimeBlock();
58 tb.setJobNumber(new Long(1));
59 tb.setBeginDate(new java.sql.Date(DATE_FORMAT.parse("08/12/2010").getTime()));
60 tb.setEndDate(new java.sql.Date(DATE_FORMAT.parse("08/12/2010").getTime()));
61
62 GlobalVariables.getUserSession().setBackdoorUser("eric");
63
64 tb.setUserPrincipalId("admin");
65 boolean editable = TkServiceLocator.getTimeBlockService().isTimeBlockEditable(tb);
66 Assert.assertEquals("TimeBlock created by admin should NOT be editable by eric", false, editable);
67
68 tb.setUserPrincipalId("eric");
69 tb.setClockLogCreated(true);
70 editable = TkServiceLocator.getTimeBlockService().isTimeBlockEditable(tb);
71 Assert.assertEquals("TimeBlock created by Clock in/out should NOT be editable by eric", false, editable);
72 }
73
74 }