001/**
002 * Copyright 2004-2014 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 */
016package org.kuali.hr.time.timeblock.service;
017
018import org.joda.time.DateTime;
019import org.junit.Assert;
020import org.junit.Test;
021import org.kuali.hr.KPMEWebTestCase;
022import org.kuali.kpme.core.FunctionalTest;
023import org.kuali.kpme.tklm.time.service.TkServiceLocator;
024import org.kuali.kpme.tklm.time.timeblock.TimeBlockBo;
025import org.kuali.rice.krad.util.GlobalVariables;
026
027@FunctionalTest
028public class TimeBlockServiceTest extends KPMEWebTestCase {
029        
030        @Test
031        public void testIsTimeBlockEditableAdmin() throws Exception {
032                TimeBlockBo tb = new TimeBlockBo();
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(TimeBlockBo.to(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(TimeBlockBo.to(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(TimeBlockBo.to(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                TimeBlockBo tb = new TimeBlockBo();
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(TimeBlockBo.to(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(TimeBlockBo.to(tb));
069                Assert.assertEquals("TimeBlock created by Clock in/out should NOT be editable by eric", false, editable);
070        }
071
072}