View Javadoc

1   /**
2    * Copyright 2004-2012 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.sql.Date;
19  import java.util.Map;
20  
21  import org.joda.time.DateTime;
22  import org.junit.Assert;
23  import org.junit.Ignore;
24  import org.junit.Test;
25  import org.kuali.hr.test.KPMETestCase;
26  import org.kuali.hr.time.detail.web.ActionFormUtils;
27  import org.kuali.hr.time.service.base.TkServiceLocator;
28  import org.kuali.hr.time.test.TkTestUtils;
29  import org.kuali.hr.time.timeblock.TimeBlock;
30  import org.kuali.hr.time.timesheet.TimesheetDocument;
31  import org.kuali.hr.time.util.TKUtils;
32  import org.kuali.hr.time.util.TkConstants;
33  @Ignore
34  public class TimeBlockServiceTest extends KPMETestCase {
35  	@Test
36  	public void testBuildAssignmentStyleClassMap() {
37  		Date aDate = new Date((new DateTime(2011, 7, 7, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone())).getMillis());
38  		TimesheetDocument doc = TkTestUtils.populateTimesheetDocument(aDate);
39  		Map<String, String> aMap = ActionFormUtils.buildAssignmentStyleClassMap(doc.getTimeBlocks());
40  		Assert.assertEquals("Wrong number of classes in style class map", 8, aMap.size());
41  		Assert.assertEquals("Wrong key for class assignment0", "assignment0", aMap.get("1_1234_1"));
42  		Assert.assertEquals("Wrong key for class assignment7", "assignment7", aMap.get("6_1100_5"));
43  	}
44  
45  	@Test
46  	public void testIsTimeBlockEditable() {
47  		// creator and user are the same person
48  		TimeBlock tb = new TimeBlock();
49  		tb.setClockLogCreated(false);
50  		tb.setJobNumber(new Long(30));
51  		tb.setUserPrincipalId("admin");
52  		
53  		Boolean editable = TkServiceLocator.getTimeBlockService().isTimeBlockEditable(tb);
54  		Assert.assertEquals("TimeBlock created by admin should be editable by admin", true, editable);
55  
56  		// creator and user are different, but user is a system admin
57  		tb.setUserPrincipalId("fran");
58  		editable = TkServiceLocator.getTimeBlockService().isTimeBlockEditable(tb);
59  		Assert.assertEquals("TimeBlock created by fran should be editable by admin", true, editable);
60  
61  		// login as fran
62  //		user = TkServiceLocator.getUserService().buildTkUser("fran", TKUtils.getCurrentDate());
63  //		TKContext.setUser(user);
64  //		// creator and user are different, user is not a system admin
65  //		tb.setUserPrincipalId("admin");
66  //		editable = TkServiceLocator.getTimeBlockService().isTimeBlockEditable(tb);
67  //		assertEquals("TimeBlock created by admin should NOT be editable by fran", false, editable);
68  		
69  		tb.setUserPrincipalId("fran");
70  		tb.setClockLogCreated(true);
71  		editable = TkServiceLocator.getTimeBlockService().isTimeBlockEditable(tb);
72  		Assert.assertEquals("TimeBlock created by Clock in/out should NOT be editable by fran", false, editable);
73  		
74  	}
75  
76  }