View Javadoc
1   /**
2    * Copyright 2004-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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  }