View Javadoc
1   /**
2    * Copyright 2004-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.kpme.tklm.time.block.history;
17  
18  import java.math.BigDecimal;
19  import java.util.ArrayList;
20  import java.util.List;
21  
22  import org.joda.time.DateTime;
23  import org.junit.Assert;
24  import org.junit.Test;
25  import org.kuali.kpme.core.IntegrationTest;
26  import org.kuali.kpme.core.util.TKUtils;
27  import org.kuali.kpme.tklm.TKLMIntegrationTestCase;
28  import org.kuali.kpme.tklm.api.common.TkConstants;
29  import org.kuali.kpme.tklm.api.time.timeblock.TimeBlock;
30  import org.kuali.kpme.tklm.time.service.TkServiceLocator;
31  import org.kuali.kpme.tklm.time.timeblock.TimeBlockHistory;
32  import org.kuali.kpme.tklm.time.timesheet.TimesheetDocument;
33  import org.kuali.kpme.tklm.utils.TkTestUtils;
34  
35  @IntegrationTest
36  public class TimeBlockHistoryTest extends TKLMIntegrationTestCase {
37  
38      private static DateTime DEFAULT_EFFDT =new DateTime(2010, 1, 1, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone());
39      private static DateTime beginDateTime = new DateTime(2010, 1, 1, 8, 0, 0, 0, TKUtils.getSystemDateTimeZone());
40      private static DateTime endDateTime = new DateTime(2010, 1, 1, 16, 0, 0, 0, TKUtils.getSystemDateTimeZone());
41  
42      @Test
43      public void testTimeBlockHistory() throws Exception {
44          TimesheetDocument td = TkTestUtils.populateBlankTimesheetDocument(DEFAULT_EFFDT, "admin");
45          List<TimeBlock> tbs = TkServiceLocator.getTimeBlockService().buildTimeBlocks(td.getPrincipalId(), td.getCalendarEntry(), td.getAllAssignments().get(0), "RGH",
46                  td.getDocumentId(), beginDateTime, endDateTime, new BigDecimal("8"), BigDecimal.ZERO, true, false, "admin", null, null);
47          TkServiceLocator.getTimeBlockService().saveOrUpdateTimeBlocks(td.getTimeBlocks(), tbs, "admin");
48  
49          List<TimeBlockHistory> tbhs = new ArrayList<TimeBlockHistory>();
50          for(TimeBlock tb : td.getTimeBlocks()) {
51              tbhs.addAll(TkServiceLocator.getTimeBlockHistoryService().getTimeBlockHistoryByTkTimeBlockId(tb.getTkTimeBlockId()));
52          }
53  
54          for(TimeBlockHistory tbh : tbhs) {
55          	Assert.assertEquals(TkConstants.ACTIONS.ADD_TIME_BLOCK, tbh.getActionHistory());
56          }
57      }
58  }