1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.kpme.tklm.leave.accrual;
17
18 import java.math.BigDecimal;
19 import java.util.List;
20
21 import org.joda.time.DateTime;
22 import org.joda.time.LocalDate;
23 import org.junit.Assert;
24 import org.junit.Test;
25 import org.kuali.kpme.core.IntegrationTest;
26 import org.kuali.kpme.core.util.HrConstants;
27 import org.kuali.kpme.core.util.TKUtils;
28 import org.kuali.kpme.tklm.TKLMIntegrationTestCase;
29 import org.kuali.kpme.tklm.common.LMConstants;
30 import org.kuali.kpme.tklm.leave.block.LeaveBlock;
31 import org.kuali.kpme.tklm.leave.block.LeaveBlockHistory;
32 import org.kuali.kpme.tklm.leave.service.LmServiceLocator;
33
34 @IntegrationTest
35 public class AccrualServiceTest extends TKLMIntegrationTestCase {
36 DateTime START_DATE = new DateTime(2012, 2, 20, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone());
37 DateTime END_DATE = new DateTime(2012, 5, 3, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone());
38
39 @Test
40
41
42
43
44
45 public void testRunAccrualForStatusChange() {
46 String principal_id = "testUser";
47 List<LeaveBlock> leaveBlockList = (List<LeaveBlock>) LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, START_DATE.toLocalDate(), END_DATE.toLocalDate());
48 Assert.assertTrue("There are leave blocks before runAccrual for princiapl id " + principal_id, leaveBlockList.isEmpty());
49
50
51 LmServiceLocator.getLeaveAccrualService().runAccrual(principal_id, START_DATE, END_DATE, false, "admin");
52 verifyLeaveBlocksForStatusChange();
53
54 List<LeaveBlockHistory> historyList = LmServiceLocator.getLeaveBlockHistoryService().getLeaveBlockHistories(principal_id, null);
55 Assert.assertTrue("There should be 6 leave block history for emplyee " + principal_id + ", not " + historyList.size(), historyList.size()== 6);
56 LeaveBlockHistory lbh = historyList.get(0);
57 Assert.assertTrue("Leave Block Type of leave block history should be " + LMConstants.LEAVE_BLOCK_TYPE.ACCRUAL_SERVICE + ", not " + lbh.getLeaveBlockType()
58 , lbh.getLeaveBlockType().equals(LMConstants.LEAVE_BLOCK_TYPE.ACCRUAL_SERVICE));
59
60
61 LmServiceLocator.getLeaveAccrualService().runAccrual(principal_id, START_DATE, END_DATE, false, "admin");
62 verifyLeaveBlocksForStatusChange();
63
64 historyList = LmServiceLocator.getLeaveBlockHistoryService().getLeaveBlockHistories(principal_id, null);
65 Assert.assertTrue("There should be 16 leave block history for employee " + principal_id + ", not " + historyList.size(), historyList.size()== 16);
66 }
67 private void verifyLeaveBlocksForStatusChange() {
68 String principal_id = "testUser";
69 List<LeaveBlock> leaveBlockList;
70 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, START_DATE.toLocalDate(), END_DATE.toLocalDate());
71 Assert.assertFalse("No leave blocks created by runAccrual for princiapl id " + principal_id, leaveBlockList.isEmpty());
72 Assert.assertTrue("There should be 6 leave blocks for emplyee 'testUser', not " + leaveBlockList.size(), leaveBlockList.size()== 6);
73
74
75 DateTime intervalDate = new DateTime(2012, 3, 31, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
76 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
77 Assert.assertTrue("There should be 1 leave block for date 03/31/2012.", leaveBlockList.size()==1);
78 LeaveBlock lb = leaveBlockList.get(0);
79 Assert.assertTrue("Hours of the leave block for date 03/31/2012 should be 16, not " + lb.getLeaveAmount().toString(), lb.getLeaveAmount().equals(new BigDecimal(16)));
80 Assert.assertNull("lm_sys_schd_timeoff_id should be null for regular accrual leave block", lb.getScheduleTimeOffId());
81 Assert.assertTrue("Leave Block Type of leave block should be " + LMConstants.LEAVE_BLOCK_TYPE.ACCRUAL_SERVICE + ", not " + lb.getLeaveBlockType()
82 , lb.getLeaveBlockType().equals(LMConstants.LEAVE_BLOCK_TYPE.ACCRUAL_SERVICE));
83 Assert.assertTrue("Requst status of leave block should be " + HrConstants.REQUEST_STATUS.APPROVED + ", not " + lb.getRequestStatus()
84 , lb.getRequestStatus().equals(HrConstants.REQUEST_STATUS.APPROVED));
85
86
87
88 intervalDate = new DateTime(2012, 4, 01, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
89 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
90 Assert.assertTrue("There should be 1 leave block for date 04/01/2012.", leaveBlockList.size()==1);
91 lb = leaveBlockList.get(0);
92 Assert.assertTrue("Hours of the leave block for date 04/01/2012 should be 0, not " + lb.getLeaveAmount().toString(), lb.getLeaveAmount().equals(BigDecimal.ZERO));
93 Assert.assertTrue("Leave Code of the leave block for date 04/01/2012 should be " + LMConstants.STATUS_CHANGE_EARN_CODE + ", not " + lb.getEarnCode()
94 , lb.getEarnCode().equals(LMConstants.STATUS_CHANGE_EARN_CODE));
95 Assert.assertNull("accrual_category should be null for empty status change leave block", lb.getAccrualCategory());
96 Assert.assertTrue("Leave Block Type of leave block should be " + LMConstants.LEAVE_BLOCK_TYPE.ACCRUAL_SERVICE + ", not " + lb.getLeaveBlockType()
97 , lb.getLeaveBlockType().equals(LMConstants.LEAVE_BLOCK_TYPE.ACCRUAL_SERVICE));
98 Assert.assertTrue("Requst status of leave block should be " + HrConstants.REQUEST_STATUS.APPROVED + ", not " + lb.getRequestStatus()
99 , lb.getRequestStatus().equals(HrConstants.REQUEST_STATUS.APPROVED));
100
101
102 intervalDate = new DateTime(2012, 4, 10, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
103 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
104 Assert.assertTrue("There should be 1 leave block for date 04/10/2012.", leaveBlockList.size()==1);
105 lb = leaveBlockList.get(0);
106 Assert.assertNotNull("lm_sys_schd_timeoff_id should NOT be null for holiday accrual leave block", lb.getScheduleTimeOffId());
107 Assert.assertTrue("lm_sys_schd_timeoff_id should be 5000, not " + lb.getScheduleTimeOffId(), lb.getScheduleTimeOffId().equals("5000"));
108 Assert.assertTrue("Leave Block Type of leave block should be " + LMConstants.LEAVE_BLOCK_TYPE.ACCRUAL_SERVICE + ", not " + lb.getLeaveBlockType()
109 , lb.getLeaveBlockType().equals(LMConstants.LEAVE_BLOCK_TYPE.ACCRUAL_SERVICE));
110 Assert.assertTrue("Requst status of leave block should be " + HrConstants.REQUEST_STATUS.APPROVED + ", not " + lb.getRequestStatus()
111 , lb.getRequestStatus().equals(HrConstants.REQUEST_STATUS.APPROVED));
112 Assert.assertTrue("Hours of the leave block for date 04/10/2012 should be 4, not " + lb.getLeaveAmount().toString(), lb.getLeaveAmount().equals(new BigDecimal(4)));
113
114
115 intervalDate = new DateTime(2012, 4, 12, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
116 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
117 Assert.assertTrue("There should be 1 leave block for date 04/12/2012.", leaveBlockList.size()==1);
118 lb = leaveBlockList.get(0);
119 Assert.assertNotNull("lm_sys_schd_timeoff_id should NOT be null for holiday accrual leave block", lb.getScheduleTimeOffId());
120 Assert.assertTrue("lm_sys_schd_timeoff_id should be 5000, not " + lb.getScheduleTimeOffId(), lb.getScheduleTimeOffId().equals("5000"));
121 Assert.assertTrue("Leave Block Type of leave block should be " + LMConstants.LEAVE_BLOCK_TYPE.ACCRUAL_SERVICE + ", not " + lb.getLeaveBlockType()
122 , lb.getLeaveBlockType().equals(LMConstants.LEAVE_BLOCK_TYPE.ACCRUAL_SERVICE));
123 Assert.assertTrue("Requst status of leave block should be " + HrConstants.REQUEST_STATUS.APPROVED + ", not " + lb.getRequestStatus()
124 , lb.getRequestStatus().equals(HrConstants.REQUEST_STATUS.APPROVED));
125 Assert.assertTrue("Hours of the leave block for date 04/12/2012 should be -4, not " + lb.getLeaveAmount().toString(), lb.getLeaveAmount().equals(new BigDecimal(-4)));
126 Assert.assertNotNull("System Scheduled Timeoff usage leave block's Job number should not be null", lb.getJobNumber());
127 Assert.assertTrue("System Scheduled Timeoff usage leave block should have Job number 4, not " + lb.getJobNumber(), lb.getJobNumber().equals(4L));
128 Assert.assertNotNull("System Scheduled Timeoff usage leave block's work area should not be null", lb.getWorkArea());
129 Assert.assertTrue("System Scheduled Timeoff usage leave block should have work area 1001, not " + lb.getWorkArea(), lb.getWorkArea().equals(1001L));
130 Assert.assertNotNull("System Scheduled Timeoff usage leave block's task should not be null", lb.getTask());
131 Assert.assertTrue("System Scheduled Timeoff usage leave block should have task 0, not " + lb.getTask(), lb.getTask().equals(0L));
132
133
134 intervalDate = new DateTime(2012, 4, 11, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
135 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
136 Assert.assertTrue("There should be 1 leave block for date 04/11/2012.", leaveBlockList.size()==1);
137 lb = leaveBlockList.get(0);
138 Assert.assertNotNull("lm_sys_schd_timeoff_id should NOT be null for holiday accrual leave block", lb.getScheduleTimeOffId());
139 Assert.assertTrue("lm_sys_schd_timeoff_id should be 5005, not " + lb.getScheduleTimeOffId(), lb.getScheduleTimeOffId().equals("5005"));
140 Assert.assertTrue("Leave Block Type of leave block should be " + LMConstants.LEAVE_BLOCK_TYPE.ACCRUAL_SERVICE + ", not " + lb.getLeaveBlockType()
141 , lb.getLeaveBlockType().equals(LMConstants.LEAVE_BLOCK_TYPE.ACCRUAL_SERVICE));
142 Assert.assertTrue("Requst status of leave block should be " + HrConstants.REQUEST_STATUS.APPROVED + ", not " + lb.getRequestStatus()
143 , lb.getRequestStatus().equals(HrConstants.REQUEST_STATUS.APPROVED));
144 Assert.assertTrue("Hours of the leave block for date 04/11/2012 should be 4, not " + lb.getLeaveAmount().toString(), lb.getLeaveAmount().equals(new BigDecimal(4)));
145
146
147 intervalDate = new DateTime(2012, 4, 20, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
148 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
149 Assert.assertTrue("There should be 0 leave block for date 04/20/2012.", leaveBlockList.isEmpty());
150
151
152 intervalDate = new DateTime(2012, 4, 30, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
153 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
154 Assert.assertTrue("There should be 1 leave block for date 04/30/2012.", leaveBlockList.size()==1);
155 lb = leaveBlockList.get(0);
156 Assert.assertTrue("Hours of the regular accrual leave block for date 04/30/2012 should be 8, not " + lb.getLeaveAmount().toString(), lb.getLeaveAmount().equals(new BigDecimal(8)));
157 Assert.assertNull("lm_sys_schd_timeoff_id should be null for regular accrual leave block", lb.getScheduleTimeOffId());
158 Assert.assertTrue("Leave Block Type of leave block should be " + LMConstants.LEAVE_BLOCK_TYPE.ACCRUAL_SERVICE + ", not " + lb.getLeaveBlockType()
159 , lb.getLeaveBlockType().equals(LMConstants.LEAVE_BLOCK_TYPE.ACCRUAL_SERVICE));
160 Assert.assertTrue("Requst status of leave block should be " + HrConstants.REQUEST_STATUS.APPROVED + ", not " + lb.getRequestStatus()
161 , lb.getRequestStatus().equals(HrConstants.REQUEST_STATUS.APPROVED));
162 }
163
164 @Test
165
166
167
168
169
170 public void testCalculateFutureAccrualUsingPlanningMonth() {
171 String principal_id = "testUser";
172
173 LocalDate currentDate = LocalDate.now();
174 LmServiceLocator.getLeaveAccrualService().calculateFutureAccrualUsingPlanningMonth(principal_id, LocalDate.now(), "admin");
175 int futureSize = 12;
176 int allSize = 17;
177 if(currentDate.getDayOfMonth() == currentDate.dayOfMonth().getMaximumValue()) {
178 futureSize ++;
179 allSize ++;
180 }
181
182 LocalDate startDate = currentDate.minusMonths(5);
183 LocalDate endDate = currentDate.plusMonths(18);
184
185
186 List<LeaveBlock> leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, currentDate, endDate);
187
188 Assert.assertFalse("No leave blocks created by calculateF?utureAccrualUsingPlanningMonth for princiapl id " + principal_id, leaveBlockList.isEmpty());
189 Assert.assertTrue("There should be " + futureSize + " leave blocks for employee 'testUser', not " + leaveBlockList.size(), leaveBlockList.size()== futureSize);
190
191
192 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, startDate, endDate);
193 Assert.assertTrue("There should be " + allSize + " leave blocks for employee 'testUser', not " + leaveBlockList.size(), leaveBlockList.size()== allSize);
194 }
195
196 @Test
197
198
199
200
201
202 public void testRunAccrualForRuleChanges() {
203 String principal_id = "testUser2";
204 LocalDate endDate = START_DATE.toLocalDate().plusMonths(15);
205
206 List<LeaveBlock> leaveBlockList = (List<LeaveBlock>) LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, START_DATE.toLocalDate(), endDate);
207 Assert.assertTrue("There are leave blocks before runAccrual for princiapl id " + principal_id, leaveBlockList.isEmpty());
208
209 LmServiceLocator.getLeaveAccrualService().runAccrual(principal_id, START_DATE, endDate.toDateTimeAtStartOfDay(), false, "admin");
210
211 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, START_DATE.toLocalDate(), endDate);
212 Assert.assertTrue("There should be 14 leave blocks for emplyee " + principal_id + ", not " + leaveBlockList.size(), leaveBlockList.size()== 14);
213
214
215 DateTime intervalDate = new DateTime(2012, 7, 31, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
216 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
217 Assert.assertTrue("There should be 1 leave block for employee " + principal_id + " for date 07/31/2012.", leaveBlockList.size()==1);
218 LeaveBlock lb = leaveBlockList.get(0);
219 Assert.assertTrue("Hours of the leave block on date 07/31/2012 for employee " + principal_id + " should be 16, not " + lb.getLeaveAmount().toString()
220 , lb.getLeaveAmount().equals(new BigDecimal(16)));
221
222
223 intervalDate = new DateTime(2012, 8, 31, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
224 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
225 Assert.assertTrue("There should be 1 leave block for employee " + principal_id + " for date 08/31/2012.", leaveBlockList.size()==1);
226 lb = leaveBlockList.get(0);
227 Assert.assertTrue("Hours of the leave block for date 08/31/2012 for employee " + principal_id + " should be 24, not " + lb.getLeaveAmount().toString()
228 , lb.getLeaveAmount().equals(new BigDecimal(24)));
229
230 }
231 @Test
232
233
234
235
236 public void testRunAccrualWithDifferentAccrualIntervals() {
237 String principal_id = "testUser3";
238 List<LeaveBlock> leaveBlockList = (List<LeaveBlock>) LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, START_DATE.toLocalDate(), END_DATE.toLocalDate());
239 Assert.assertTrue("There are leave blocks before runAccrual for princiapl id " + principal_id, leaveBlockList.isEmpty());
240
241 LmServiceLocator.getLeaveAccrualService().runAccrual(principal_id, START_DATE, END_DATE, false, "admin");
242 leaveBlockList = (List<LeaveBlock>) LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, START_DATE.toLocalDate(), END_DATE.toLocalDate());
243 Assert.assertTrue("There should be 6 leave blocks for emplyee " + principal_id + ", not " + leaveBlockList.size(), leaveBlockList.size()== 6);
244
245 DateTime semiMonthlyDate = new DateTime(2012, 3, 15, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
246 DateTime monthlyDate = new DateTime(2012, 3, 31, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
247 this.verifyLeaveBlocksWithDifferentAccrualIntervals(semiMonthlyDate, monthlyDate);
248
249 semiMonthlyDate = new DateTime(2012, 4, 15, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
250 monthlyDate = new DateTime(2012, 4, 30, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
251 this.verifyLeaveBlocksWithDifferentAccrualIntervals(semiMonthlyDate, monthlyDate);
252
253 }
254 public void verifyLeaveBlocksWithDifferentAccrualIntervals(DateTime semiMonthlyDate, DateTime monthlyDate) {
255 String principal_id = "testUser3";
256 List<LeaveBlock> leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, semiMonthlyDate.toLocalDate());
257 Assert.assertTrue("There should be 1 leave block for date " + semiMonthlyDate.toString() + " for emplyee " + principal_id, leaveBlockList.size()==1);
258 LeaveBlock lb = leaveBlockList.get(0);
259 Assert.assertTrue("Hours of the leave block on date " + semiMonthlyDate.toString() + " should be 8, not " + lb.getLeaveAmount().toString(), lb.getLeaveAmount().equals(new BigDecimal(8)));
260 Assert.assertTrue("Leave code of the leave block on date " + semiMonthlyDate.toString() + " should be EC1, not " + lb.getEarnCode(), lb.getEarnCode().equals("EC1"));
261 Assert.assertTrue("accrual_category of the leave block on date " + semiMonthlyDate.toString() + " should be testAC3, not " + lb.getAccrualCategory(), lb.getAccrualCategory().equals("testAC3"));
262
263
264 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, monthlyDate.toLocalDate());
265 Assert.assertTrue("There should be 2 leave block for date " + monthlyDate.toString() + " for emplyee " + principal_id, leaveBlockList.size()==2);
266 for(LeaveBlock aLeaveBlock : leaveBlockList) {
267 if(aLeaveBlock.getAccrualCategory().equals("testAC3")) {
268 Assert.assertTrue("Leave code of the leave block with accrualCategory testAC3 on date " + monthlyDate.toString() + " should be EC1, not " + aLeaveBlock.getEarnCode()
269 , aLeaveBlock.getEarnCode().equals("EC1"));
270 Assert.assertTrue("Hours of the leave block with accrualCategory testAC4 on date " + monthlyDate.toString() + " should be 8, not " + aLeaveBlock.getLeaveAmount().toString()
271 , aLeaveBlock.getLeaveAmount().equals(new BigDecimal(8)));
272 } else if(aLeaveBlock.getAccrualCategory().equals("testAC4")) {
273 Assert.assertTrue("Leave code of the leave block with accrualCategory testAC4 on date " + monthlyDate.toString() + " should be EC2, not " + aLeaveBlock.getEarnCode()
274 , aLeaveBlock.getEarnCode().equals("EC2"));
275 Assert.assertTrue("Hours of the leave block with accrualCategory testAC4 on date " + monthlyDate.toString() + " should be 24, not " + aLeaveBlock.getLeaveAmount().toString()
276 , aLeaveBlock.getLeaveAmount().equals(new BigDecimal(24)));
277 } else {
278 Assert.fail("Leave block on date " + monthlyDate.toString() + " should not have accrual_category " + aLeaveBlock.getAccrualCategory());
279 }
280 }
281 }
282
283 @Test
284
285
286
287
288
289
290 public void testMinNotReachedProrationTrueFirstLastPeriod() {
291 String principal_id = "testUser4";
292 DateTime end = new DateTime(2012, 9, 25, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone());
293 List<LeaveBlock> leaveBlockList = (List<LeaveBlock>) LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, START_DATE.toLocalDate(), end.toLocalDate());
294 Assert.assertTrue("There are leave blocks before runAccrual for princiapl id " + principal_id, leaveBlockList.isEmpty());
295
296 LmServiceLocator.getLeaveAccrualService().runAccrual(principal_id, START_DATE, end, false, "admin");
297 leaveBlockList = (List<LeaveBlock>) LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, START_DATE.toLocalDate(), end.toLocalDate());
298 Assert.assertTrue("There should be 10 leave blocks for emplyee " + principal_id + ", not " + leaveBlockList.size(), leaveBlockList.size()== 10);
299
300 DateTime monthlyDate = new DateTime(2012, 3, 31, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
301 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, monthlyDate.toLocalDate());
302 Assert.assertTrue("There should be 1 leave block for date " + monthlyDate.toString() + " for emplyee " + principal_id, leaveBlockList.size()==1);
303 LeaveBlock lb = leaveBlockList.get(0);
304 Assert.assertTrue("Leave block on date " + monthlyDate.toString() + " should have accrual_category testAC6, not " + lb.getAccrualCategory()
305 , lb.getAccrualCategory().equals("testAC6"));
306 Assert.assertTrue("Leave block on date " + monthlyDate.toString() + " should have 7 hours, not " + lb.getLeaveAmount()
307 , lb.getLeaveAmount().equals(new BigDecimal(7)));
308
309 monthlyDate = new DateTime(2012, 4, 30, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
310 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, monthlyDate.toLocalDate());
311 Assert.assertTrue("There should be 2 leave block for date " + monthlyDate.toString() + " for emplyee " + principal_id, leaveBlockList.size()==2);
312
313
314 monthlyDate = new DateTime(2012, 8, 8, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
315 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, monthlyDate.toLocalDate());
316 Assert.assertTrue("There should be 1 leave block for date " + monthlyDate.toString() + " for emplyee " + principal_id, leaveBlockList.size()==1);
317 lb = leaveBlockList.get(0);
318 Assert.assertTrue("Leave block on date " + monthlyDate.toString() + " should have accrual_category testAC6, not " + lb.getAccrualCategory()
319 , lb.getAccrualCategory().equals("testAC6"));
320 Assert.assertTrue("Leave block on date " + monthlyDate.toString() + " should have 4 hours, not " + lb.getLeaveAmount()
321 , lb.getLeaveAmount().equals(new BigDecimal(4)));
322
323 monthlyDate = new DateTime(2012, 8, 31, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
324 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, monthlyDate.toLocalDate());
325 Assert.assertTrue("There should NOT be any leave blocks for date " + monthlyDate.toString() + " for emplyee " + principal_id, leaveBlockList.size()==0);
326 }
327 @Test
328
329
330
331
332
333 public void testMinReachedProrationTrueFirstLastPeriod() {
334 String principal_id = "testUser9";
335 DateTime end = new DateTime(2012, 9, 25, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone());
336 List<LeaveBlock> leaveBlockList = (List<LeaveBlock>) LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, START_DATE.toLocalDate(), end.toLocalDate());
337 Assert.assertTrue("There are leave blocks before runAccrual for princiapl id " + principal_id, leaveBlockList.isEmpty());
338
339 LmServiceLocator.getLeaveAccrualService().runAccrual(principal_id, START_DATE, end, false, "admin");
340 leaveBlockList = (List<LeaveBlock>) LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, START_DATE.toLocalDate(), end.toLocalDate());
341 Assert.assertTrue("There should be 6 leave blocks for emplyee " + principal_id + ", not " + leaveBlockList.size(), leaveBlockList.size()== 6);
342
343 DateTime monthlyDate = new DateTime(2012, 3, 31, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
344 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, monthlyDate.toLocalDate());
345 Assert.assertTrue("There should be 1 leave block for date " + monthlyDate.toString() + " for emplyee " + principal_id, leaveBlockList.size()==1);
346 LeaveBlock lb = leaveBlockList.get(0);
347 Assert.assertTrue("Leave block on date " + monthlyDate.toString() + " should have 5 hours, not " + lb.getLeaveAmount()
348 , lb.getLeaveAmount().equals(new BigDecimal(5)));
349
350 monthlyDate = new DateTime(2012, 4, 30, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
351 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, monthlyDate.toLocalDate());
352 Assert.assertTrue("There should be 1 leave block for date " + monthlyDate.toString() + " for emplyee " + principal_id, leaveBlockList.size()==1);
353 lb = leaveBlockList.get(0);
354 Assert.assertTrue("Leave block on date " + monthlyDate.toString() + " should have 8 hours, not " + lb.getLeaveAmount()
355 , lb.getLeaveAmount().equals(new BigDecimal(8)));
356
357 monthlyDate = new DateTime(2012, 8, 20, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
358 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, monthlyDate.toLocalDate());
359 Assert.assertTrue("There should be 1 leave block for date " + monthlyDate.toString() + " for emplyee " + principal_id, leaveBlockList.size()==1);
360 lb = leaveBlockList.get(0);
361 Assert.assertTrue("Leave block on date " + monthlyDate.toString() + " should have 5 hours, not " + lb.getLeaveAmount()
362 , lb.getLeaveAmount().equals(new BigDecimal(5)));
363
364 monthlyDate = new DateTime(2012, 8, 31, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
365 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, monthlyDate.toLocalDate());
366 Assert.assertTrue("There should NOT be any leave blocks for date " + monthlyDate.toString() + " for emplyee " + principal_id, leaveBlockList.size()==0);
367 }
368 @Test
369
370
371
372
373
374 public void testMinReachedProrationFalseFirstLastPeriod() {
375 String principal_id = "testUser10";
376 DateTime end = new DateTime(2012, 9, 25, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone());
377 List<LeaveBlock> leaveBlockList = (List<LeaveBlock>) LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, START_DATE.toLocalDate(), end.toLocalDate());
378 Assert.assertTrue("There are leave blocks before runAccrual for princiapl id " + principal_id, leaveBlockList.isEmpty());
379
380 LmServiceLocator.getLeaveAccrualService().runAccrual(principal_id, START_DATE, end, false, "admin");
381 leaveBlockList = (List<LeaveBlock>) LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, START_DATE.toLocalDate(), end.toLocalDate());
382 Assert.assertTrue("There should be 6 leave blocks for emplyee " + principal_id + ", not " + leaveBlockList.size(), leaveBlockList.size()== 6);
383
384 DateTime monthlyDate = new DateTime(2012, 3, 31, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
385 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, monthlyDate.toLocalDate());
386 Assert.assertTrue("There should be 1 leave block for date " + monthlyDate.toString() + " for emplyee " + principal_id, leaveBlockList.size()==1);
387 LeaveBlock lb = leaveBlockList.get(0);
388 Assert.assertTrue("Leave block on date " + monthlyDate.toString() + " should have 8 hours, not " + lb.getLeaveAmount()
389 , lb.getLeaveAmount().equals(new BigDecimal(8)));
390
391 monthlyDate = new DateTime(2012, 4, 30, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
392 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, monthlyDate.toLocalDate());
393 Assert.assertTrue("There should be 1 leave block for date " + monthlyDate.toString() + " for emplyee " + principal_id, leaveBlockList.size()==1);
394 lb = leaveBlockList.get(0);
395 Assert.assertTrue("Leave block on date " + monthlyDate.toString() + " should have 8 hours, not " + lb.getLeaveAmount()
396 , lb.getLeaveAmount().equals(new BigDecimal(8)));
397
398 monthlyDate = new DateTime(2012, 8, 20, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
399 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, monthlyDate.toLocalDate());
400 Assert.assertTrue("There should be 1 leave block for date " + monthlyDate.toString() + " for emplyee " + principal_id, leaveBlockList.size()==1);
401 lb = leaveBlockList.get(0);
402 Assert.assertTrue("Leave block on date " + monthlyDate.toString() + " should have 8 hours, not " + lb.getLeaveAmount()
403 , lb.getLeaveAmount().equals(new BigDecimal(8)));
404
405 monthlyDate = new DateTime(2012, 8, 31, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
406 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, monthlyDate.toLocalDate());
407 Assert.assertTrue("There should NOT be any leave blocks for date " + monthlyDate.toString() + " for emplyee " + principal_id, leaveBlockList.size()==0);
408 }
409
410 @Test
411
412
413
414
415
416 public void testMinNotReachedProrationFalseFirstLastPeriod() {
417 String principal_id = "testUser11";
418 DateTime end = new DateTime(2012, 9, 25, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone());
419 List<LeaveBlock> leaveBlockList = (List<LeaveBlock>) LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, START_DATE.toLocalDate(), end.toLocalDate());
420 Assert.assertTrue("There are leave blocks before runAccrual for princiapl id " + principal_id, leaveBlockList.isEmpty());
421
422 LmServiceLocator.getLeaveAccrualService().runAccrual(principal_id, START_DATE, end, false, "admin");
423 leaveBlockList = (List<LeaveBlock>) LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, START_DATE.toLocalDate(), end.toLocalDate());
424 Assert.assertTrue("There should be 4 leave blocks for emplyee " + principal_id + ", not " + leaveBlockList.size(), leaveBlockList.size()== 4);
425
426 DateTime monthlyDate = new DateTime(2012, 3, 31, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
427 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, monthlyDate.toLocalDate());
428 Assert.assertTrue("There should be 0 leave block for date " + monthlyDate.toString() + " for emplyee " + principal_id, leaveBlockList.isEmpty());
429
430 monthlyDate = new DateTime(2012, 4, 30, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
431 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, monthlyDate.toLocalDate());
432 Assert.assertTrue("There should be 1 leave block for date " + monthlyDate.toString() + " for emplyee " + principal_id, leaveBlockList.size()==1);
433 LeaveBlock lb = leaveBlockList.get(0);
434 Assert.assertTrue("Leave block on date " + monthlyDate.toString() + " should have 8 hours, not " + lb.getLeaveAmount()
435 , lb.getLeaveAmount().equals(new BigDecimal(8)));
436
437 monthlyDate = new DateTime(2012, 8, 20, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
438 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, monthlyDate.toLocalDate());
439 Assert.assertTrue("There should be 0 leave block for date " + monthlyDate.toString() + " for emplyee " + principal_id, leaveBlockList.isEmpty());
440
441 monthlyDate = new DateTime(2012, 8, 31, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
442 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, monthlyDate.toLocalDate());
443 Assert.assertTrue("There should NOT be any leave blocks for date " + monthlyDate.toString() + " for emplyee " + principal_id, leaveBlockList.size()==0);
444 }
445 @Test
446
447
448
449
450
451
452 public void testMinReachedProrationFalseAndRuleChange() {
453 String principal_id = "testUser5";
454 LocalDate endDate = START_DATE.toLocalDate().plusMonths(18);
455
456 List<LeaveBlock> leaveBlockList = (List<LeaveBlock>) LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, START_DATE.toLocalDate(), endDate);
457 Assert.assertTrue("There are leave blocks before runAccrual for princiapl id " + principal_id, leaveBlockList.isEmpty());
458
459 LmServiceLocator.getLeaveAccrualService().runAccrual(principal_id, START_DATE, endDate.toDateTimeAtStartOfDay(), false, "admin");
460
461 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, START_DATE.toLocalDate(), endDate);
462 Assert.assertTrue("There should be 17 leave blocks for emplyee " + principal_id + ", not " + leaveBlockList.size(), leaveBlockList.size()== 17);
463
464
465
466 DateTime intervalDate = new DateTime(2012, 3, 31, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
467 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
468 Assert.assertTrue("There should be 1 leave block for date " + intervalDate.toString() + " for emplyee " + principal_id, leaveBlockList.size()==1);
469 LeaveBlock lb = leaveBlockList.get(0);
470 Assert.assertTrue("Leave block on date " + intervalDate.toString() + " should have 16 hours, not " + lb.getLeaveAmount()
471 , lb.getLeaveAmount().equals(new BigDecimal(16)));
472
473
474 intervalDate = new DateTime(2013, 2, 28, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
475 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
476 Assert.assertTrue("There should be 1 leave block for employee " + principal_id + " for date 02/28/2013.", leaveBlockList.size()==1);
477 lb = leaveBlockList.get(0);
478 Assert.assertTrue("Hours of the leave block on date " + intervalDate.toString() + " should be 16, not " + lb.getLeaveAmount().toString()
479 , lb.getLeaveAmount().equals(new BigDecimal(16)));
480
481
482
483 intervalDate = new DateTime(2013, 3, 31, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
484 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
485 Assert.assertTrue("There should be 1 leave block for employee " + principal_id + " for date " + intervalDate.toString(), leaveBlockList.size()==1);
486 lb = leaveBlockList.get(0);
487 Assert.assertTrue("Hours of the leave block for date " + intervalDate.toString() + " should be 24, not " + lb.getLeaveAmount().toString()
488 , lb.getLeaveAmount().equals(new BigDecimal(24)));
489 }
490 @Test
491
492
493
494
495
496
497
498 public void testMinNotReachedProrationFalseAndRuleChange() {
499 String principal_id = "testUser12";
500 LocalDate endDate = START_DATE.toLocalDate().plusMonths(18);
501
502 List<LeaveBlock> leaveBlockList = (List<LeaveBlock>) LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, START_DATE.toLocalDate(), endDate);
503 Assert.assertTrue("There are leave blocks before runAccrual for princiapl id " + principal_id, leaveBlockList.isEmpty());
504
505 LmServiceLocator.getLeaveAccrualService().runAccrual(principal_id, START_DATE, endDate.toDateTimeAtStartOfDay(), false, "admin");
506
507 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, START_DATE.toLocalDate(), endDate);
508 Assert.assertTrue("There should be 17 leave blocks for emplyee " + principal_id + ", not " + leaveBlockList.size(), leaveBlockList.size()== 17);
509
510 DateTime intervalDate = new DateTime(2012, 8, 31, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
511 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
512 Assert.assertTrue("There should be 1 leave block for employee " + principal_id + " for date " + intervalDate.toString(), leaveBlockList.size()==1);
513 LeaveBlock lb = leaveBlockList.get(0);
514 Assert.assertTrue("Hours of the leave block for date " + intervalDate.toString() + " should be 16, not " + lb.getLeaveAmount().toString()
515 , lb.getLeaveAmount().equals(new BigDecimal(16)));
516
517
518 intervalDate = new DateTime(2012, 9, 30, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
519 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
520 Assert.assertTrue("There should be 1 leave block for date " + intervalDate.toString() + " for emplyee " + principal_id, leaveBlockList.size()==1);
521 lb = leaveBlockList.get(0);
522 Assert.assertTrue("Leave block on date " + intervalDate.toString() + " should have 16 hours, not " + lb.getLeaveAmount()
523 , lb.getLeaveAmount().equals(new BigDecimal(16)));
524
525
526 intervalDate = new DateTime(2012, 10, 31, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
527 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
528 Assert.assertTrue("There should be 1 leave block for employee " + principal_id + " for date " + intervalDate.toString(), leaveBlockList.size()==1);
529 lb = leaveBlockList.get(0);
530 Assert.assertTrue("Hours of the leave block on date " + intervalDate.toString() + " should be 24, not " + lb.getLeaveAmount().toString()
531 , lb.getLeaveAmount().equals(new BigDecimal(24)));
532 }
533 @Test
534
535
536
537
538
539
540
541 public void testMinReachedProrationTrueAndRuleChange() {
542 String principal_id = "testUser13";
543 LocalDate endDate = START_DATE.toLocalDate().plusMonths(18);
544
545 List<LeaveBlock> leaveBlockList = (List<LeaveBlock>) LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, START_DATE.toLocalDate(), endDate);
546 Assert.assertTrue("There are leave blocks before runAccrual for princiapl id " + principal_id, leaveBlockList.isEmpty());
547
548 LmServiceLocator.getLeaveAccrualService().runAccrual(principal_id, START_DATE, endDate.toDateTimeAtStartOfDay(), false, "admin");
549
550 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, START_DATE.toLocalDate(), endDate);
551 Assert.assertTrue("There should be 17 leave blocks for emplyee " + principal_id + ", not " + leaveBlockList.size(), leaveBlockList.size()== 17);
552
553 DateTime intervalDate = new DateTime(2012, 8, 31, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
554 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
555 Assert.assertTrue("There should be 1 leave block for employee " + principal_id + " for date " + intervalDate.toString(), leaveBlockList.size()==1);
556 LeaveBlock lb = leaveBlockList.get(0);
557 Assert.assertTrue("Hours of the leave block for date " + intervalDate.toString() + " should be 16, not " + lb.getLeaveAmount().toString()
558 , lb.getLeaveAmount().equals(new BigDecimal(16)));
559
560
561
562 intervalDate = new DateTime(2012, 9, 30, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
563 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
564 Assert.assertTrue("There should be 1 leave block for date " + intervalDate.toString() + " for emplyee " + principal_id, leaveBlockList.size()==1);
565 lb = leaveBlockList.get(0);
566 Assert.assertTrue("Leave block on date " + intervalDate.toString() + " should have 22 hours, not " + lb.getLeaveAmount()
567 , lb.getLeaveAmount().equals(new BigDecimal(22)));
568
569
570 intervalDate = new DateTime(2012, 10, 31, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
571 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
572 Assert.assertTrue("There should be 1 leave block for employee " + principal_id + " for date " + intervalDate.toString(), leaveBlockList.size()==1);
573 lb = leaveBlockList.get(0);
574 Assert.assertTrue("Hours of the leave block on date " + intervalDate.toString() + " should be 24, not " + lb.getLeaveAmount().toString()
575 , lb.getLeaveAmount().equals(new BigDecimal(24)));
576 }
577 @Test
578
579
580
581
582
583
584
585 public void testMinNotReachedProrationTrueAndRuleChange() {
586 String principal_id = "testUser14";
587 LocalDate endDate = START_DATE.toLocalDate().plusMonths(18);
588
589 List<LeaveBlock> leaveBlockList = (List<LeaveBlock>) LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, START_DATE.toLocalDate(), endDate);
590 Assert.assertTrue("There are leave blocks before runAccrual for princiapl id " + principal_id, leaveBlockList.isEmpty());
591
592 LmServiceLocator.getLeaveAccrualService().runAccrual(principal_id, START_DATE, endDate.toDateTimeAtStartOfDay(), false, "admin");
593
594 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, START_DATE.toLocalDate(), endDate);
595 Assert.assertTrue("There should be 16 leave blocks for emplyee " + principal_id + ", not " + leaveBlockList.size(), leaveBlockList.size()== 16);
596
597
598 DateTime intervalDate = new DateTime(2012, 3, 31, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
599 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
600 Assert.assertTrue("There should be 0 leave block for employee " + principal_id + " for date " + intervalDate.toString(), leaveBlockList.isEmpty());
601
602
603 intervalDate = new DateTime(2012, 8, 31, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
604 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
605 Assert.assertTrue("There should be 1 leave block for employee " + principal_id + " for date " + intervalDate.toString(), leaveBlockList.size()==1);
606 LeaveBlock lb = leaveBlockList.get(0);
607 Assert.assertTrue("Hours of the leave block for date " + intervalDate.toString() + " should be 16, not " + lb.getLeaveAmount().toString()
608 , lb.getLeaveAmount().equals(new BigDecimal(16)));
609
610
611 intervalDate = new DateTime(2012, 9, 30, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
612 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
613 Assert.assertTrue("There should be 1 leave block for date " + intervalDate.toString() + " for emplyee " + principal_id, leaveBlockList.size()==1);
614 lb = leaveBlockList.get(0);
615 Assert.assertTrue("Leave block on date " + intervalDate.toString() + " should have 16 hours, not " + lb.getLeaveAmount()
616 , lb.getLeaveAmount().equals(new BigDecimal(16)));
617
618
619 intervalDate = new DateTime(2012, 10, 31, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
620 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
621 Assert.assertTrue("There should be 1 leave block for employee " + principal_id + " for date " + intervalDate.toString(), leaveBlockList.size()==1);
622 lb = leaveBlockList.get(0);
623 Assert.assertTrue("Hours of the leave block on date " + intervalDate.toString() + " should be 24, not " + lb.getLeaveAmount().toString()
624 , lb.getLeaveAmount().equals(new BigDecimal(24)));
625 }
626 @Test
627
628
629
630
631
632
633 public void testMinNOTReachedProrationFalseAndRuleChange() {
634 String principal_id = "testUser6";
635 LocalDate endDate = START_DATE.toLocalDate().plusMonths(10);
636
637 List<LeaveBlock> leaveBlockList = (List<LeaveBlock>) LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, START_DATE.toLocalDate(), endDate);
638 Assert.assertTrue("There are leave blocks before runAccrual for princiapl id " + principal_id, leaveBlockList.isEmpty());
639
640 LmServiceLocator.getLeaveAccrualService().runAccrual(principal_id, START_DATE, endDate.toDateTimeAtStartOfDay(), false, "admin");
641
642 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, START_DATE.toLocalDate(), endDate);
643 Assert.assertTrue("There should be 17 leave blocks for emplyee " + principal_id + ", not " + leaveBlockList.size(), leaveBlockList.size()== 17);
644
645
646
647 DateTime intervalDate =new DateTime(2012, 3, 31, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
648 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
649 Assert.assertTrue("There should be 0 leave block for date " + intervalDate.toString(), leaveBlockList.isEmpty());
650
651
652 intervalDate = new DateTime(2012, 4, 15, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
653 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
654 Assert.assertTrue("There should be 1 leave block for date " + intervalDate.toString() + " for emplyee " + principal_id, leaveBlockList.size()==1);
655 LeaveBlock lb = leaveBlockList.get(0);
656 Assert.assertTrue("Leave block on date " + intervalDate.toString() + " should have 16 hours, not " + lb.getLeaveAmount()
657 , lb.getLeaveAmount().equals(new BigDecimal(16)));
658
659
660 intervalDate = new DateTime(2012, 9, 15, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
661 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
662 Assert.assertTrue("There should be 1 leave block for employee " + principal_id + " for date " + intervalDate.toString(), leaveBlockList.size()==1);
663 lb = leaveBlockList.get(0);
664 Assert.assertTrue("Hours of the leave block on date " + intervalDate.toString() + " should be 16, not " + lb.getLeaveAmount().toString()
665 , lb.getLeaveAmount().equals(new BigDecimal(16)));
666
667
668
669 intervalDate = new DateTime(2012, 9, 30, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
670 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
671 Assert.assertTrue("There should be 1 leave block for employee " + principal_id + " for date " + intervalDate.toString(), leaveBlockList.size()==1);
672 lb = leaveBlockList.get(0);
673 Assert.assertTrue("Hours of the leave block for date " + intervalDate.toString() + " should be 16, not " + lb.getLeaveAmount().toString()
674 , lb.getLeaveAmount().equals(new BigDecimal(16)));
675
676
677 intervalDate = new DateTime(2012, 10, 15, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
678 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
679 Assert.assertTrue("There should be 1 leave block for employee " + principal_id + " for date " + intervalDate.toString(), leaveBlockList.size()==1);
680 lb = leaveBlockList.get(0);
681 Assert.assertTrue("Hours of the leave block for date " + intervalDate.toString() + " should be 24, not " + lb.getLeaveAmount().toString()
682 , lb.getLeaveAmount().equals(new BigDecimal(24)));
683 }
684
685 @Test
686
687
688
689
690
691
692
693 public void testNotEligibleForAccrualAdjustment() {
694 String principal_id = "testUser7";
695 LocalDate endDate = START_DATE.toLocalDate().plusMonths(5);
696
697 List<LeaveBlock> leaveBlockList = (List<LeaveBlock>) LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, START_DATE.toLocalDate(), endDate);
698 Assert.assertTrue("There should be 4 leave blocks before runAccrual for princiapl id " + principal_id, leaveBlockList.size() == 4);
699
700 LmServiceLocator.getLeaveAccrualService().runAccrual(principal_id, START_DATE, endDate.toDateTimeAtStartOfDay(), false, "admin");
701
702 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, START_DATE.toLocalDate(), endDate);
703 Assert.assertTrue("There should be 10 leave blocks for emplyee " + principal_id + ", not " + leaveBlockList.size(), leaveBlockList.size()== 10);
704
705
706 DateTime intervalDate = new DateTime(2012, 3, 31, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
707 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
708 Assert.assertTrue("There should be 1 leave block for date " + intervalDate.toString(), leaveBlockList.size() == 1);
709 LeaveBlock lb = leaveBlockList.get(0);
710 Assert.assertTrue("Hours of the leave block for date " + intervalDate.toString() + " should be 22, not " + lb.getLeaveAmount().toString()
711 , lb.getLeaveAmount().equals(new BigDecimal(22)));
712
713
714 intervalDate = new DateTime(2012, 4, 30, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
715 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
716 Assert.assertTrue("There should be 1 leave block for date " + intervalDate.toString(), leaveBlockList.size() == 1);
717 lb = leaveBlockList.get(0);
718 Assert.assertTrue("Hours of the leave block for date " + intervalDate.toString() + " should be 32, not " + lb.getLeaveAmount().toString()
719 , lb.getLeaveAmount().equals(new BigDecimal(32)));
720
721
722 intervalDate = new DateTime(2012, 5, 31, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
723 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
724 Assert.assertTrue("There should be 2 leave block for date " + intervalDate.toString(), leaveBlockList.size() == 2);
725 for(LeaveBlock aLeaveBlock : leaveBlockList) {
726 if(aLeaveBlock.getLeaveAmount().equals(new BigDecimal(-1))) {
727 Assert.assertTrue("Accrual category of the leave block for date " + intervalDate.toString() + " should be 'testAC9' , not " + aLeaveBlock.getAccrualCategory()
728 , aLeaveBlock.getAccrualCategory().equals("testAC9"));
729 } else if(aLeaveBlock.getLeaveAmount().equals(new BigDecimal(32))) {
730 Assert.assertTrue("Accrual category of the leave block for date " + intervalDate.toString() + " should be 'testAC9' , not " + aLeaveBlock.getAccrualCategory()
731 , aLeaveBlock.getAccrualCategory().equals("testAC9"));
732 } else {
733 Assert.fail("Hours of the leave block for date " + intervalDate.toString() + " should be either 32 or -1, not " + aLeaveBlock.getLeaveAmount().toString());
734 }
735 }
736
737
738
739 intervalDate = new DateTime(2012, 6, 30, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
740 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
741 Assert.assertTrue("There should be 2 leave block for date " + intervalDate.toString(), leaveBlockList.size() == 2);
742 for(LeaveBlock aLeaveBlock : leaveBlockList) {
743 if(aLeaveBlock.getLeaveAmount().equals(new BigDecimal(-2))) {
744 Assert.assertTrue("Accrual category of the leave block for date " + intervalDate.toString() + " should be 'testAC9' , not " + aLeaveBlock.getAccrualCategory()
745 , aLeaveBlock.getAccrualCategory().equals("testAC9"));
746 } else if(aLeaveBlock.getLeaveAmount().equals(new BigDecimal(32))) {
747 Assert.assertTrue("Accrual category of the leave block for date " + intervalDate.toString() + " should be 'testAC9' , not " + aLeaveBlock.getAccrualCategory()
748 , aLeaveBlock.getAccrualCategory().equals("testAC9"));
749 } else {
750 Assert.fail("Hours of the leave block for date " + intervalDate.toString() + " should be either 32 or -2, not " + aLeaveBlock.getLeaveAmount().toString());
751 }
752 }
753 }
754
755 @Test
756
757
758
759
760
761
762 public void testAccrualCategoryChanges() {
763 String principal_id = "testUser8";
764 LocalDate endDate = START_DATE.toLocalDate().plusMonths(6);
765
766 List<LeaveBlock> leaveBlockList = (List<LeaveBlock>) LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, START_DATE.toLocalDate(), endDate);
767 Assert.assertTrue("There are leave blocks before runAccrual for princiapl id " + principal_id, leaveBlockList.isEmpty());
768
769 LmServiceLocator.getLeaveAccrualService().runAccrual(principal_id, START_DATE, endDate.toDateTimeAtStartOfDay(), false, "admin");
770
771 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, START_DATE.toLocalDate(), endDate);
772 Assert.assertTrue("There should be 5 leave blocks for emplyee " + principal_id + ", not " + leaveBlockList.size(), leaveBlockList.size()== 5);
773
774
775 DateTime intervalDate = new DateTime(2012, 3, 31, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
776 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
777 Assert.assertTrue("There should be 1 leave block for date " + intervalDate.toString(), leaveBlockList.size() == 1);
778 LeaveBlock lb = leaveBlockList.get(0);
779 Assert.assertTrue("Hours of the leave block for date " + intervalDate.toString() + " should be 11, not " + lb.getLeaveAmount().toString()
780 , lb.getLeaveAmount().equals(new BigDecimal(11)));
781
782
783 intervalDate = new DateTime(2012, 4, 30, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
784 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
785 Assert.assertTrue("There should be 1 leave block for date " + intervalDate.toString(), leaveBlockList.size() == 1);
786 lb = leaveBlockList.get(0);
787 Assert.assertTrue("Hours of the leave block for date " + intervalDate.toString() + " should be 16, not " + lb.getLeaveAmount().toString()
788 , lb.getLeaveAmount().equals(new BigDecimal(16)));
789
790
791 intervalDate = new DateTime(2012, 5, 31, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
792 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
793 Assert.assertTrue("There should be 1 leave block for date " + intervalDate.toString(), leaveBlockList.size() == 1);
794 lb = leaveBlockList.get(0);
795 Assert.assertTrue("Hours of the leave block for date " + intervalDate.toString() + " should be 32, not " + lb.getLeaveAmount().toString()
796 , lb.getLeaveAmount().equals(new BigDecimal(32)));
797
798 }
799
800 @Test
801
802
803
804
805
806
807 public void testLeaveBlocksWithLeaveCalendarDocId() {
808 String principal_id = "testUser15";
809 LocalDate endDate = START_DATE.toLocalDate().plusMonths(6);
810
811 List<LeaveBlock> leaveBlockList = (List<LeaveBlock>) LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, START_DATE.toLocalDate(), endDate);
812 Assert.assertTrue("There are leave blocks before runAccrual for princiapl id " + principal_id, leaveBlockList.isEmpty());
813
814 LmServiceLocator.getLeaveAccrualService().runAccrual(principal_id, START_DATE, endDate.toDateTimeAtStartOfDay(), false, "admin");
815
816
817 DateTime intervalDate = new DateTime(2012, 4, 30, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
818 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
819 Assert.assertTrue("There should be 1 leave block for employee " + principal_id + " for date " + intervalDate.toString(), leaveBlockList.size()==1);
820 LeaveBlock lb = leaveBlockList.get(0);
821 Assert.assertTrue("DocumentId of the leave block for date " + intervalDate.toString() + " should be 5000, not " + lb.getDocumentId()
822 , lb.getDocumentId().equals("5000"));
823
824 }
825
826 @Test
827
828
829
830
831
832
833
834
835 public void testPayCalAsEarnInterval() {
836 String principal_id = "testUser16";
837 LocalDate endDate = START_DATE.toLocalDate().plusMonths(6);
838
839 List<LeaveBlock> leaveBlockList = (List<LeaveBlock>) LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, START_DATE.toLocalDate(), endDate);
840 Assert.assertTrue("There are leave blocks before runAccrual for princiapl id " + principal_id, leaveBlockList.isEmpty());
841
842 LmServiceLocator.getLeaveAccrualService().runAccrual(principal_id, START_DATE, endDate.toDateTimeAtStartOfDay(), false, "admin");
843
844 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, START_DATE.toLocalDate(), endDate);
845 Assert.assertTrue("There should be 11 leave blocks for emplyee " + principal_id + ", not " + leaveBlockList.size(), leaveBlockList.size()== 11);
846
847
848 DateTime intervalDate = new DateTime(2012, 3, 31, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
849 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
850 Assert.assertTrue("There should be 1 leave block for employee " + principal_id + " for date " + intervalDate.toString(), leaveBlockList.size()==1);
851 LeaveBlock lb = leaveBlockList.get(0);
852 Assert.assertTrue("Hours of the leave block for date " + intervalDate.toString() + " should be 24, not " + lb.getLeaveAmount().toString()
853 , lb.getLeaveAmount().equals(new BigDecimal(24)));
854
855
856 intervalDate = new DateTime(2012, 4, 28, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
857 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
858 Assert.assertTrue("There should be 1 leave block for employee " + principal_id + " for date " + intervalDate.toString(), leaveBlockList.size()==1);
859 lb = leaveBlockList.get(0);
860 Assert.assertTrue("Hours of the leave block for date " + intervalDate.toString() + " should be 24, not " + lb.getLeaveAmount().toString()
861 , lb.getLeaveAmount().equals(new BigDecimal(24)));
862
863 intervalDate = new DateTime(2012, 5, 12, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
864 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
865 Assert.assertTrue("There should be 1 leave block for employee " + principal_id + " for date " + intervalDate.toString(), leaveBlockList.size()==1);
866
867 intervalDate = new DateTime(2012, 8, 4, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
868 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
869 Assert.assertTrue("There should be 1 leave block for employee " + principal_id + " for date " + intervalDate.toString(), leaveBlockList.size()==1);
870
871 intervalDate = new DateTime(2012, 8, 18, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
872 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
873 Assert.assertTrue("There should be 1 leave block for employee " + principal_id + " for date " + intervalDate.toString(), leaveBlockList.size()==1);
874 }
875
876 @Test
877
878
879
880
881
882
883
884
885 public void testPayCalAsEarnIntervalProrationFalseMinReached() {
886 String principal_id = "testUser17";
887 LocalDate endDate = START_DATE.toLocalDate().plusMonths(6);
888
889 List<LeaveBlock> leaveBlockList = (List<LeaveBlock>) LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, START_DATE.toLocalDate(), endDate);
890 Assert.assertTrue("There are leave blocks before runAccrual for princiapl id " + principal_id, leaveBlockList.isEmpty());
891
892 LmServiceLocator.getLeaveAccrualService().runAccrual(principal_id, START_DATE, endDate.toDateTimeAtStartOfDay(), false, "admin");
893
894 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, START_DATE.toLocalDate(), endDate);
895 Assert.assertTrue("There should be 11 leave blocks for emplyee " + principal_id + ", not " + leaveBlockList.size(), leaveBlockList.size()== 11);
896
897
898 DateTime intervalDate = new DateTime(2012, 3, 31, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
899 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
900 Assert.assertTrue("There should be 1 leave block for employee " + principal_id + " for date " + intervalDate.toString(), leaveBlockList.size()==1);
901 LeaveBlock lb = leaveBlockList.get(0);
902 Assert.assertTrue("Hours of the leave block for date " + intervalDate.toString() + " should be 12, not " + lb.getLeaveAmount().toString()
903 , lb.getLeaveAmount().equals(new BigDecimal(12)));
904
905
906 intervalDate = new DateTime(2012, 4, 28, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
907 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
908 Assert.assertTrue("There should be 1 leave block for employee " + principal_id + " for date " + intervalDate.toString(), leaveBlockList.size()==1);
909 lb = leaveBlockList.get(0);
910 Assert.assertTrue("Hours of the leave block for date " + intervalDate.toString() + " should be 24, not " + lb.getLeaveAmount().toString()
911 , lb.getLeaveAmount().equals(new BigDecimal(24)));
912
913 intervalDate = new DateTime(2012, 5, 12, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
914 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
915 Assert.assertTrue("There should be 1 leave block for employee " + principal_id + " for date " + intervalDate.toString(), leaveBlockList.size()==1);
916
917 intervalDate = new DateTime(2012, 8, 4, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
918 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
919 Assert.assertTrue("There should be 1 leave block for employee " + principal_id + " for date " + intervalDate.toString(), leaveBlockList.size()==1);
920
921 intervalDate = new DateTime(2012, 8, 18, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
922 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
923 Assert.assertTrue("There should be 1 leave block for employee " + principal_id + " for date " + intervalDate.toString(), leaveBlockList.size()==1);
924 }
925
926 @Test
927
928
929
930
931
932
933
934 public void testWeeklyAsEarnInterval() {
935 String principal_id = "testUser18";
936 LocalDate endDate = START_DATE.toLocalDate().plusMonths(6);
937
938 List<LeaveBlock> leaveBlockList = (List<LeaveBlock>) LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, START_DATE.toLocalDate(), endDate);
939 Assert.assertTrue("There are leave blocks before runAccrual for princiapl id " + principal_id, leaveBlockList.isEmpty());
940
941 LmServiceLocator.getLeaveAccrualService().runAccrual(principal_id, START_DATE, endDate.toDateTimeAtStartOfDay(), false, "admin");
942
943 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, START_DATE.toLocalDate(), endDate);
944 Assert.assertTrue("There should be 22 leave blocks for emplyee " + principal_id + ", not " + leaveBlockList.size(), leaveBlockList.size()== 22);
945
946
947 DateTime intervalDate = new DateTime(2012, 3, 24, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
948 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
949 Assert.assertTrue("There should be 1 leave block for employee " + principal_id + " for date " + intervalDate.toString(), leaveBlockList.size()==1);
950 LeaveBlock lb = leaveBlockList.get(0);
951 Assert.assertTrue("Hours of the leave block for date " + intervalDate.toString() + " should be 24, not " + lb.getLeaveAmount().toString()
952 , lb.getLeaveAmount().equals(new BigDecimal(24)));
953
954 intervalDate = new DateTime(2012, 3, 31, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
955 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
956 Assert.assertTrue("There should be 1 leave block for employee " + principal_id + " for date " + intervalDate.toString(), leaveBlockList.size()==1);
957 lb = leaveBlockList.get(0);
958 Assert.assertTrue("Hours of the leave block for date " + intervalDate.toString() + " should be 24, not " + lb.getLeaveAmount().toString()
959 , lb.getLeaveAmount().equals(new BigDecimal(24)));
960
961 intervalDate = new DateTime(2012, 8, 11, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
962 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
963 Assert.assertTrue("There should be 1 leave block for employee " + principal_id + " for date " + intervalDate.toString(), leaveBlockList.size()==1);
964 lb = leaveBlockList.get(0);
965 Assert.assertTrue("Hours of the leave block for date " + intervalDate.toString() + " should be 24, not " + lb.getLeaveAmount().toString()
966 , lb.getLeaveAmount().equals(new BigDecimal(24)));
967
968 intervalDate = new DateTime(2012, 8, 18, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
969 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
970 Assert.assertTrue("There should be 1 leave block for employee " + principal_id + " for date " + intervalDate.toString(), leaveBlockList.size()==1);
971 lb = leaveBlockList.get(0);
972 Assert.assertTrue("Hours of the leave block for date " + intervalDate.toString() + " should be 24, not " + lb.getLeaveAmount().toString()
973 , lb.getLeaveAmount().equals(new BigDecimal(24)));
974 }
975 @Test
976
977
978
979
980
981
982 public void testYearlyAsEarnInterval() {
983 String principal_id = "testUser19";
984 LocalDate endDate = START_DATE.toLocalDate().plusMonths(18);
985
986 List<LeaveBlock> leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, START_DATE.toLocalDate(), endDate);
987 Assert.assertTrue("There are leave blocks before runAccrual for princiapl id " + principal_id, leaveBlockList.isEmpty());
988
989 LmServiceLocator.getLeaveAccrualService().runAccrual(principal_id, START_DATE, endDate.toDateTimeAtStartOfDay(), false, "admin");
990
991 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, START_DATE.toLocalDate(), endDate);
992 Assert.assertTrue("There should be 1 leave blocks for emplyee " + principal_id + ", not " + leaveBlockList.size(), leaveBlockList.size()== 1);
993
994
995 DateTime intervalDate = new DateTime(2012, 12, 31, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
996 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
997 Assert.assertTrue("There should be 1 leave block for employee " + principal_id + " for date " + intervalDate.toString(), leaveBlockList.size()==1);
998 LeaveBlock lb = leaveBlockList.get(0);
999 Assert.assertTrue("Hours of the leave block for date " + intervalDate.toString() + " should be 100, not " + lb.getLeaveAmount().toString()
1000 , lb.getLeaveAmount().equals(new BigDecimal(100)));
1001 }
1002 @Test
1003
1004
1005
1006
1007
1008
1009 public void testDailyAsEarnInterval() {
1010 String principal_id = "testUser20";
1011 LocalDate endDate = START_DATE.toLocalDate().plusMonths(3);
1012
1013 List<LeaveBlock> leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, START_DATE.toLocalDate(), endDate);
1014 Assert.assertTrue("There are leave blocks before runAccrual for princiapl id " + principal_id, leaveBlockList.isEmpty());
1015
1016 LmServiceLocator.getLeaveAccrualService().runAccrual(principal_id, START_DATE, endDate.toDateTimeAtStartOfDay(), false, "admin");
1017
1018 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, START_DATE.toLocalDate(), endDate);
1019 Assert.assertTrue("There should be 44 leave blocks for emplyee " + principal_id + ", not " + leaveBlockList.size(), leaveBlockList.size()== 44);
1020
1021
1022 DateTime intervalDate = new DateTime(2012, 3, 20, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
1023 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
1024 Assert.assertTrue("There should be 1 leave block for employee " + principal_id + " for date " + intervalDate.toString(), leaveBlockList.size()==1);
1025 LeaveBlock lb = leaveBlockList.get(0);
1026 Assert.assertTrue("Hours of the leave block for date " + intervalDate.toString() + " should be 2, not " + lb.getLeaveAmount().toString()
1027 , lb.getLeaveAmount().equals(new BigDecimal(2)));
1028
1029
1030 intervalDate = new DateTime(2012, 5, 18, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
1031 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
1032 Assert.assertTrue("There should be 1 leave block for employee " + principal_id + " for date " + intervalDate.toString(), leaveBlockList.size()==1);
1033 lb = leaveBlockList.get(0);
1034 Assert.assertTrue("Hours of the leave block for date " + intervalDate.toString() + " should be 2, not " + lb.getLeaveAmount().toString()
1035 , lb.getLeaveAmount().equals(new BigDecimal(2)));
1036 }
1037
1038 @Test
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048 public void testSSTOBankedOrTransferred() {
1049 String principal_id = "testUser21";
1050 LocalDate endDate = START_DATE.toLocalDate().plusMonths(3);
1051
1052 List<LeaveBlock> leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, START_DATE.toLocalDate(), endDate);
1053 Assert.assertTrue("There should be 1 leave blocks for princiapl id before runAccrual" + principal_id, leaveBlockList.size() == 2);
1054
1055 LmServiceLocator.getLeaveAccrualService().runAccrual(principal_id, START_DATE, endDate.toDateTimeAtStartOfDay(), false, "admin");
1056
1057 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principal_id, START_DATE.toLocalDate(), endDate);
1058 Assert.assertTrue("There should be 4 leave blocks for emplyee " + principal_id + ", not " + leaveBlockList.size(), leaveBlockList.size()== 4);
1059
1060
1061 DateTime intervalDate = new DateTime(2012, 4, 10, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
1062 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
1063 Assert.assertTrue("There should be 1 leave block for employee " + principal_id + " for date " + intervalDate.toString(), leaveBlockList.size()==1);
1064 LeaveBlock lb = leaveBlockList.get(0);
1065 Assert.assertTrue("Hours of the leave block for date " + intervalDate.toString() + " should be 8, not " + lb.getLeaveAmount().toString()
1066 , lb.getLeaveAmount().equals(new BigDecimal(8)));
1067 Assert.assertTrue("LeaveBlockId of the leave block for date " + intervalDate.toString() + " should be 5004, not " + lb.getLmLeaveBlockId()
1068 , lb.getLmLeaveBlockId().equals("5004"));
1069
1070
1071 intervalDate = new DateTime(2012, 4, 15, 5, 0, 0, 0, TKUtils.getSystemDateTimeZone());
1072 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForDate(principal_id, intervalDate.toLocalDate());
1073 Assert.assertTrue("There should be 1 leave block for employee " + principal_id + " for date " + intervalDate.toString(), leaveBlockList.size()==1);
1074 lb = leaveBlockList.get(0);
1075 Assert.assertTrue("Hours of the leave block for date " + intervalDate.toString() + " should be 4, not " + lb.getLeaveAmount().toString()
1076 , lb.getLeaveAmount().equals(new BigDecimal(4)));
1077 Assert.assertTrue("LeaveBlockId of the leave block for date " + intervalDate.toString() + " should be 5005, not " + lb.getLmLeaveBlockId()
1078 , lb.getLmLeaveBlockId().equals("5005"));
1079 }
1080
1081 }