001    /**
002     * Copyright 2004-2012 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.sql.Date;
019    import java.util.Map;
020    
021    import org.joda.time.DateTime;
022    import org.junit.Assert;
023    import org.junit.Ignore;
024    import org.junit.Test;
025    import org.kuali.hr.test.KPMETestCase;
026    import org.kuali.hr.time.detail.web.ActionFormUtils;
027    import org.kuali.hr.time.service.base.TkServiceLocator;
028    import org.kuali.hr.time.test.TkTestUtils;
029    import org.kuali.hr.time.timeblock.TimeBlock;
030    import org.kuali.hr.time.timesheet.TimesheetDocument;
031    import org.kuali.hr.time.util.TKUtils;
032    import org.kuali.hr.time.util.TkConstants;
033    @Ignore
034    public class TimeBlockServiceTest extends KPMETestCase {
035            @Test
036            public void testBuildAssignmentStyleClassMap() {
037                    Date aDate = new Date((new DateTime(2011, 7, 7, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone())).getMillis());
038                    TimesheetDocument doc = TkTestUtils.populateTimesheetDocument(aDate);
039                    Map<String, String> aMap = ActionFormUtils.buildAssignmentStyleClassMap(doc.getTimeBlocks());
040                    Assert.assertEquals("Wrong number of classes in style class map", 8, aMap.size());
041                    Assert.assertEquals("Wrong key for class assignment0", "assignment0", aMap.get("1_1234_1"));
042                    Assert.assertEquals("Wrong key for class assignment7", "assignment7", aMap.get("6_1100_5"));
043            }
044    
045            @Test
046            public void testIsTimeBlockEditable() {
047                    // creator and user are the same person
048                    TimeBlock tb = new TimeBlock();
049                    tb.setClockLogCreated(false);
050                    tb.setJobNumber(new Long(30));
051                    tb.setUserPrincipalId("admin");
052                    
053                    Boolean editable = TkServiceLocator.getTimeBlockService().isTimeBlockEditable(tb);
054                    Assert.assertEquals("TimeBlock created by admin should be editable by admin", true, editable);
055    
056                    // creator and user are different, but user is a system admin
057                    tb.setUserPrincipalId("fran");
058                    editable = TkServiceLocator.getTimeBlockService().isTimeBlockEditable(tb);
059                    Assert.assertEquals("TimeBlock created by fran should be editable by admin", true, editable);
060    
061                    // login as fran
062    //              user = TkServiceLocator.getUserService().buildTkUser("fran", TKUtils.getCurrentDate());
063    //              TKContext.setUser(user);
064    //              // creator and user are different, user is not a system admin
065    //              tb.setUserPrincipalId("admin");
066    //              editable = TkServiceLocator.getTimeBlockService().isTimeBlockEditable(tb);
067    //              assertEquals("TimeBlock created by admin should NOT be editable by fran", false, editable);
068                    
069                    tb.setUserPrincipalId("fran");
070                    tb.setClockLogCreated(true);
071                    editable = TkServiceLocator.getTimeBlockService().isTimeBlockEditable(tb);
072                    Assert.assertEquals("TimeBlock created by Clock in/out should NOT be editable by fran", false, editable);
073                    
074            }
075    
076    }