View Javadoc

1   /**
2    * Copyright 2004-2013 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.hr.lm.util;
17  
18  import java.util.Calendar;
19  import java.util.Date;
20  import java.util.List;
21  
22  import junit.framework.Assert;
23  
24  import org.junit.Test;
25  import org.kuali.hr.lm.leaveblock.LeaveBlock;
26  import org.kuali.hr.test.KPMETestCase;
27  import org.kuali.hr.time.calendar.CalendarEntries;
28  import org.kuali.hr.time.service.base.TkServiceLocator;
29  import org.kuali.hr.time.util.TKUtils;
30  
31  public class LeaveBlockAggregateTest extends KPMETestCase {
32  	private String TEST_USER = "admin";
33  	
34  	@Test
35  	public void testGetLeaveBlockAggregate(){
36  		// 03/01/2012 to 03/15/2012
37  		Calendar cal = Calendar.getInstance();
38  		cal.setTime(TKUtils.getTimelessDate(null));
39  		cal.set(Calendar.YEAR, 2012);
40  		cal.set(Calendar.MONTH, 2);
41  		cal.set(Calendar.DATE, 1);
42  		
43  		Date beginDate = cal.getTime();
44  		cal.add(Calendar.DATE,14);
45  		Date endDate = cal.getTime();
46  		CalendarEntries ce = TkServiceLocator.getCalendarEntriesService().getCalendarEntries("55");
47  		List<LeaveBlock> leaveBlocks = TkServiceLocator.getLeaveBlockService().getLeaveBlocks(TEST_USER, beginDate, endDate);
48  		
49  		// get leaveBlockAggaregate with leaveBlocks, calendarEntry and intervals
50  		LeaveBlockAggregate lbAgg = new LeaveBlockAggregate(leaveBlocks, ce, TKUtils.getFullWeekDaySpanForCalendarEntry(ce));
51  		Assert.assertNotNull("LeaveBlockAggregate should not be null.", lbAgg);
52  		Assert.assertTrue("LeaveBlockAggregate should have 21 days, not " + lbAgg.getDayLeaveBlockList().size(), lbAgg.getDayLeaveBlockList().size() == 21);
53  		Assert.assertTrue("There should be 1 leave block on 03/01.", lbAgg.getDayLeaveBlockList().get(4).size() == 1);
54  		Assert.assertTrue("There should be 1 leave block on 03/02.", lbAgg.getDayLeaveBlockList().get(5).size() == 1);
55  		
56  		// get leaveBlockAggaregate with leaveBlocks, calendarEntry
57  		lbAgg = new LeaveBlockAggregate(leaveBlocks, ce);
58  		Assert.assertNotNull("LeaveBlockAggregate should not be null.", lbAgg);
59  		Assert.assertTrue("LeaveBlockAggregate should have 14 days, not " + lbAgg.getDayLeaveBlockList().size(), lbAgg.getDayLeaveBlockList().size() == 14);
60  		Assert.assertTrue("There should be 1 leave block on 03/01.", lbAgg.getDayLeaveBlockList().get(0).size() == 1);
61  		Assert.assertTrue("There should be 1 leave block on 03/02.", lbAgg.getDayLeaveBlockList().get(1).size() == 1);
62  	}
63  }