View Javadoc

1   /**
2    * Copyright 2004-2013 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 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  }