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.lm.util; 017 018 import java.util.Calendar; 019 import java.util.Date; 020 import java.util.List; 021 022 import junit.framework.Assert; 023 024 import org.junit.Test; 025 import org.kuali.hr.lm.leaveblock.LeaveBlock; 026 import org.kuali.hr.test.KPMETestCase; 027 import org.kuali.hr.time.calendar.CalendarEntries; 028 import org.kuali.hr.time.service.base.TkServiceLocator; 029 import org.kuali.hr.time.util.TKUtils; 030 031 public class LeaveBlockAggregateTest extends KPMETestCase { 032 private String TEST_USER = "admin"; 033 034 @Test 035 public void testGetLeaveBlockAggregate(){ 036 // 03/01/2012 to 03/15/2012 037 Calendar cal = Calendar.getInstance(); 038 cal.setTime(TKUtils.getTimelessDate(null)); 039 cal.set(Calendar.YEAR, 2012); 040 cal.set(Calendar.MONTH, 2); 041 cal.set(Calendar.DATE, 1); 042 043 Date beginDate = cal.getTime(); 044 cal.add(Calendar.DATE,14); 045 Date endDate = cal.getTime(); 046 CalendarEntries ce = TkServiceLocator.getCalendarEntriesService().getCalendarEntries("55"); 047 List<LeaveBlock> leaveBlocks = TkServiceLocator.getLeaveBlockService().getLeaveBlocks(TEST_USER, beginDate, endDate); 048 049 // get leaveBlockAggaregate with leaveBlocks, calendarEntry and intervals 050 LeaveBlockAggregate lbAgg = new LeaveBlockAggregate(leaveBlocks, ce, TKUtils.getFullWeekDaySpanForCalendarEntry(ce)); 051 Assert.assertNotNull("LeaveBlockAggregate should not be null.", lbAgg); 052 Assert.assertTrue("LeaveBlockAggregate should have 21 days, not " + lbAgg.getDayLeaveBlockList().size(), lbAgg.getDayLeaveBlockList().size() == 21); 053 Assert.assertTrue("There should be 1 leave block on 03/01.", lbAgg.getDayLeaveBlockList().get(4).size() == 1); 054 Assert.assertTrue("There should be 1 leave block on 03/02.", lbAgg.getDayLeaveBlockList().get(5).size() == 1); 055 056 // get leaveBlockAggaregate with leaveBlocks, calendarEntry 057 lbAgg = new LeaveBlockAggregate(leaveBlocks, ce); 058 Assert.assertNotNull("LeaveBlockAggregate should not be null.", lbAgg); 059 Assert.assertTrue("LeaveBlockAggregate should have 14 days, not " + lbAgg.getDayLeaveBlockList().size(), lbAgg.getDayLeaveBlockList().size() == 14); 060 Assert.assertTrue("There should be 1 leave block on 03/01.", lbAgg.getDayLeaveBlockList().get(0).size() == 1); 061 Assert.assertTrue("There should be 1 leave block on 03/02.", lbAgg.getDayLeaveBlockList().get(1).size() == 1); 062 } 063 }