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;
017
018 import java.math.BigDecimal;
019 import java.sql.Date;
020 import java.sql.Timestamp;
021 import java.util.ArrayList;
022 import java.util.List;
023
024 import org.joda.time.DateTime;
025 import org.joda.time.DateTimeZone;
026 import org.junit.Assert;
027 import org.junit.Test;
028 import org.kuali.hr.test.KPMETestCase;
029 import org.kuali.hr.time.service.base.TkServiceLocator;
030 import org.kuali.hr.time.test.TkTestUtils;
031 import org.kuali.hr.time.timesheet.TimesheetDocument;
032 import org.kuali.hr.time.util.TKContext;
033 import org.kuali.hr.time.util.TKUtils;
034 import org.kuali.hr.time.util.TkConstants;
035
036 public class TimeBlockHistoryTest extends KPMETestCase {
037
038 private static Date DEFAULT_EFFDT = new Date((new DateTime(2010, 1, 1, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone())).getMillis());
039 Timestamp beginTimestamp = new Timestamp(new DateTime(2010, 1, 1, 8, 0, 0, 0, TKUtils.getSystemDateTimeZone()).getMillis());
040 Timestamp endTimestamp = new Timestamp(new DateTime(2010, 1, 1, 16, 0, 0, 0, TKUtils.getSystemDateTimeZone()).getMillis());
041
042 @Test
043 public void testTimeBlockHistory() throws Exception {
044 TimesheetDocument td = TkTestUtils.populateBlankTimesheetDocument(DEFAULT_EFFDT);
045 List<TimeBlock> tbs = TkServiceLocator.getTimeBlockService().buildTimeBlocks(td.getAssignments().get(0), "RGH", td, beginTimestamp, endTimestamp, new BigDecimal("8"), BigDecimal.ZERO, true, false, TKContext.getPrincipalId());
046 TkServiceLocator.getTimeBlockService().saveTimeBlocks(td.getTimeBlocks(), tbs, TKContext.getPrincipalId());
047
048 List<TimeBlockHistory> tbhs = new ArrayList<TimeBlockHistory>();
049 for(TimeBlock tb : td.getTimeBlocks()) {
050 tbhs.add(TkServiceLocator.getTimeBlockHistoryService().getTimeBlockHistoryByTkTimeBlockId(tb.getTkTimeBlockId()));
051 }
052
053 for(TimeBlockHistory tbh : tbhs) {
054 Assert.assertEquals(TkConstants.ACTIONS.ADD_TIME_BLOCK, tbh.getActionHistory());
055 }
056 }
057 }