1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
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
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
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 }