001 /**
002 * Copyright 2004-2013 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.hr.time.timeblock.service;
017
018 import org.joda.time.DateTime;
019 import org.junit.Assert;
020 import org.junit.Test;
021 import org.kuali.hr.KPMEWebTestCase;
022 import org.kuali.kpme.core.FunctionalTest;
023 import org.kuali.kpme.tklm.time.service.TkServiceLocator;
024 import org.kuali.kpme.tklm.time.timeblock.TimeBlock;
025 import org.kuali.rice.krad.util.GlobalVariables;
026
027 @FunctionalTest
028 public class TimeBlockServiceTest extends KPMEWebTestCase {
029
030 @Test
031 public void testIsTimeBlockEditableAdmin() throws Exception {
032 TimeBlock tb = new TimeBlock();
033 tb.setJobNumber(new Long(30));
034 tb.setBeginDateTime(new DateTime(2010, 1, 1, 0, 0, 0));
035 tb.setEndDateTime(new DateTime(2010, 1, 1, 0, 0, 0));
036
037 GlobalVariables.getUserSession().setBackdoorUser("admin");
038
039 tb.setUserPrincipalId("admin");
040 boolean editable = TkServiceLocator.getTimeBlockService().getTimeBlockEditable(tb);
041 Assert.assertEquals("TimeBlock created by admin should be editable by admin", true, editable);
042
043 tb.setUserPrincipalId("eric");
044 editable = TkServiceLocator.getTimeBlockService().getTimeBlockEditable(tb);
045 Assert.assertEquals("TimeBlock created by eric should be editable by admin", true, editable);
046
047 tb.setUserPrincipalId("eric");
048 tb.setClockLogCreated(true);
049 editable = TkServiceLocator.getTimeBlockService().getTimeBlockEditable(tb);
050 Assert.assertEquals("TimeBlock created by Clock in/out should be editable by admin", true, editable);
051 }
052
053 @Test
054 public void testIsTimeBlockEditableUser() throws Exception {
055 TimeBlock tb = new TimeBlock();
056 tb.setJobNumber(new Long(1));
057 tb.setBeginDateTime(new DateTime(2010, 8, 12, 0, 0, 0));
058 tb.setEndDateTime(new DateTime(2010, 8, 12, 0, 0, 0));
059
060 GlobalVariables.getUserSession().setBackdoorUser("eric");
061
062 tb.setUserPrincipalId("admin");
063 boolean editable = TkServiceLocator.getTimeBlockService().getTimeBlockEditable(tb);
064 Assert.assertEquals("TimeBlock created by admin should NOT be editable by eric", false, editable);
065
066 tb.setUserPrincipalId("eric");
067 tb.setClockLogCreated(true);
068 editable = TkServiceLocator.getTimeBlockService().getTimeBlockEditable(tb);
069 Assert.assertEquals("TimeBlock created by Clock in/out should NOT be editable by eric", false, editable);
070 }
071
072 }