1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.lm.leave.approval.service;
17
18 import java.math.BigDecimal;
19 import java.text.DateFormat;
20 import java.text.ParseException;
21 import java.text.SimpleDateFormat;
22 import java.util.ArrayList;
23 import java.util.Date;
24 import java.util.List;
25 import java.util.Map;
26
27 import org.apache.commons.collections.CollectionUtils;
28 import org.junit.Assert;
29 import org.junit.Test;
30 import org.kuali.hr.lm.leaveblock.LeaveBlock;
31 import org.kuali.hr.test.KPMETestCase;
32 import org.kuali.hr.time.approval.web.ApprovalLeaveSummaryRow;
33 import org.kuali.hr.time.calendar.CalendarEntries;
34 import org.kuali.hr.time.person.TKPerson;
35 import org.kuali.hr.time.service.base.TkServiceLocator;
36
37 public class LeaveApprovalServiceTest extends KPMETestCase {
38
39 private static final DateFormat DATE_FORMAT = new SimpleDateFormat("MM/dd/yy");
40
41 @Test
42 public void testGetLeaveApprovalSummaryRows() {
43 CalendarEntries ce = TkServiceLocator.getCalendarEntriesService().getCalendarEntries("55");
44 List<Date> leaveSummaryDates = TkServiceLocator.getLeaveSummaryService().getLeaveSummaryDates(ce);
45 List<String> ids = new ArrayList<String>();
46 ids.add("admin");
47 List<TKPerson> persons = TkServiceLocator.getPersonService().getPersonCollection(ids);
48
49 List<ApprovalLeaveSummaryRow> rows = TkServiceLocator.getLeaveApprovalService().getLeaveApprovalSummaryRows(persons, ce, leaveSummaryDates);
50 Assert.assertTrue("Rows should not be empty. ", CollectionUtils.isNotEmpty(rows));
51
52 ApprovalLeaveSummaryRow aRow = rows.get(0);
53 Map<Date, Map<String, BigDecimal>> aMap = aRow.getEarnCodeLeaveHours();
54 Assert.assertTrue("Leave Approval Summary Rows should have 14 items, not " + aMap.size(), aMap.size() == 14);
55 }
56
57 @Test
58 public void testGetEarnCodeLeaveHours() throws Exception {
59 CalendarEntries ce = TkServiceLocator.getCalendarEntriesService().getCalendarEntries("55");
60 List<Date> leaveSummaryDates = TkServiceLocator.getLeaveSummaryService().getLeaveSummaryDates(ce);
61
62 List<LeaveBlock> lbList = TkServiceLocator.getLeaveBlockService().getLeaveBlocks("admin", ce.getBeginPeriodDateTime(), ce.getEndPeriodDateTime());
63 Assert.assertTrue("Leave Block list should not be empty. ", CollectionUtils.isNotEmpty(lbList));
64 Map<Date, Map<String, BigDecimal>> aMap = TkServiceLocator.getLeaveApprovalService().getEarnCodeLeaveHours(lbList, leaveSummaryDates);
65
66 Assert.assertTrue("Map should have 14 entries, not " + aMap.size(), aMap.size() == 14);
67 Map<String, BigDecimal> dayMap = aMap.get(DATE_FORMAT.parse("03/05/2012"));
68 Assert.assertTrue("Map on day 03/05 should have 1 entries, not " + dayMap.size(), dayMap.size() == 1);
69 Assert.assertTrue("EC on day 03/05 should have 8 hours, not " + dayMap.get("EC6|P|AS"), dayMap.get("EC6|P|AS").equals(new BigDecimal(8)));
70 }
71
72 @Test
73 public void testGetAccrualCategoryLeaveHours() throws Exception {
74 CalendarEntries ce = TkServiceLocator.getCalendarEntriesService().getCalendarEntries("55");
75 List<Date> leaveSummaryDates = TkServiceLocator.getLeaveSummaryService().getLeaveSummaryDates(ce);
76
77 List<LeaveBlock> lbList = TkServiceLocator.getLeaveBlockService().getLeaveBlocks("admin", ce.getBeginPeriodDateTime(), ce.getEndPeriodDateTime());
78 Assert.assertTrue("Leave Block list should not be empty. ", CollectionUtils.isNotEmpty(lbList));
79 Map<Date, Map<String, BigDecimal>> aMap = TkServiceLocator.getLeaveApprovalService().getAccrualCategoryLeaveHours(lbList, leaveSummaryDates);
80
81 Assert.assertTrue("Map should have 14 entries, not " + aMap.size(), aMap.size() == 14);
82 Map<String, BigDecimal> dayMap = aMap.get(DATE_FORMAT.parse("03/05/2012"));
83 Assert.assertTrue("Map on day 03/05 should have 1 entries, not " + dayMap.size(), dayMap.size() == 1);
84 Assert.assertTrue("testAC on day 03/05 should have 8 hours, not " + dayMap.get("testAC"), dayMap.get("testAC").equals(new BigDecimal(8)));
85 }
86
87 @Test
88 public void testGetLeavePrincipalIdsWithSearchCriteria() throws ParseException {
89 List<String> workAreaList = new ArrayList<String>();
90 String calendarGroup = "leaveCal";
91 java.sql.Date beginDate = new java.sql.Date(DATE_FORMAT.parse("03/01/2012").getTime());
92 java.sql.Date endDate = new java.sql.Date(DATE_FORMAT.parse("03/30/2012").getTime());
93
94 List<String> idList = TkServiceLocator.getLeaveApprovalService()
95 .getLeavePrincipalIdsWithSearchCriteria(workAreaList, calendarGroup, endDate, beginDate, endDate);
96 Assert.assertTrue("There should be 0 principal ids when searching with empty workarea list, not " + idList.size(), idList.isEmpty());
97
98 workAreaList.add("1111");
99 workAreaList.add("2222");
100 idList = TkServiceLocator.getLeaveApprovalService()
101 .getLeavePrincipalIdsWithSearchCriteria(workAreaList, calendarGroup, endDate, beginDate, endDate);
102 Assert.assertTrue("There should be 2 principal ids when searching with both workareas, not " + idList.size(), idList.size() == 2);
103
104 for(String anId : idList) {
105 if(!(anId.equals("1011") || anId.equals("1022"))) {
106 Assert.fail("PrincipalIds searched with both workareas should be either '1011' or '1022', not " + anId);
107 }
108 }
109
110 workAreaList = new ArrayList<String>();
111 workAreaList.add("1111");
112 idList = TkServiceLocator.getLeaveApprovalService()
113 .getLeavePrincipalIdsWithSearchCriteria(workAreaList, calendarGroup, endDate, beginDate, endDate);
114 Assert.assertTrue("There should be 1 principal ids for workArea '1111', not " + idList.size(), idList.size() == 1);
115 Assert.assertTrue("Principal id for workArea '1111' should be principalA, not " + idList.get(0), idList.get(0).equals("1011"));
116
117 workAreaList = new ArrayList<String>();
118 workAreaList.add("2222");
119 idList = TkServiceLocator.getLeaveApprovalService()
120 .getLeavePrincipalIdsWithSearchCriteria(workAreaList, calendarGroup, endDate, beginDate, endDate);
121 Assert.assertTrue("There should be 1 principal ids for workArea '2222', not " + idList.size(), idList.size() == 1);
122 Assert.assertTrue("Principal id for workArea '2222' should be principalB, not " + idList.get(0), idList.get(0).equals("1022"));
123 }
124
125 }