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 java.text.DateFormat;
019 import java.text.SimpleDateFormat;
020
021 import org.junit.Assert;
022 import org.junit.Test;
023 import org.kuali.hr.test.KPMETestCase;
024 import org.kuali.hr.time.service.base.TkServiceLocator;
025 import org.kuali.hr.time.timeblock.TimeBlock;
026 import org.kuali.rice.krad.util.GlobalVariables;
027
028 public class TimeBlockServiceTest extends KPMETestCase {
029
030 private static final DateFormat DATE_FORMAT = new SimpleDateFormat("MM/dd/yy");
031
032 @Test
033 public void testIsTimeBlockEditableAdmin() throws Exception {
034 TimeBlock tb = new TimeBlock();
035 tb.setJobNumber(new Long(30));
036 tb.setBeginDate(new java.sql.Date(DATE_FORMAT.parse("01/01/2010").getTime()));
037 tb.setEndDate(new java.sql.Date(DATE_FORMAT.parse("01/01/2010").getTime()));
038
039 GlobalVariables.getUserSession().setBackdoorUser("admin");
040
041 tb.setUserPrincipalId("admin");
042 boolean editable = TkServiceLocator.getTimeBlockService().isTimeBlockEditable(tb);
043 Assert.assertEquals("TimeBlock created by admin should be editable by admin", true, editable);
044
045 tb.setUserPrincipalId("eric");
046 editable = TkServiceLocator.getTimeBlockService().isTimeBlockEditable(tb);
047 Assert.assertEquals("TimeBlock created by eric should be editable by admin", true, editable);
048
049 tb.setUserPrincipalId("eric");
050 tb.setClockLogCreated(true);
051 editable = TkServiceLocator.getTimeBlockService().isTimeBlockEditable(tb);
052 Assert.assertEquals("TimeBlock created by Clock in/out should be editable by admin", true, editable);
053 }
054
055 @Test
056 public void testIsTimeBlockEditableUser() throws Exception {
057 TimeBlock tb = new TimeBlock();
058 tb.setJobNumber(new Long(1));
059 tb.setBeginDate(new java.sql.Date(DATE_FORMAT.parse("08/12/2010").getTime()));
060 tb.setEndDate(new java.sql.Date(DATE_FORMAT.parse("08/12/2010").getTime()));
061
062 GlobalVariables.getUserSession().setBackdoorUser("eric");
063
064 tb.setUserPrincipalId("admin");
065 boolean editable = TkServiceLocator.getTimeBlockService().isTimeBlockEditable(tb);
066 Assert.assertEquals("TimeBlock created by admin should NOT be editable by eric", false, editable);
067
068 tb.setUserPrincipalId("eric");
069 tb.setClockLogCreated(true);
070 editable = TkServiceLocator.getTimeBlockService().isTimeBlockEditable(tb);
071 Assert.assertEquals("TimeBlock created by Clock in/out should NOT be editable by eric", false, editable);
072 }
073
074 }