1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.time.department.lunch.rule;
17
18 import java.math.BigDecimal;
19 import java.sql.Date;
20 import java.util.Calendar;
21
22 import org.apache.commons.lang.StringUtils;
23 import org.joda.time.DateTime;
24 import org.junit.Assert;
25 import org.junit.Test;
26 import org.kuali.hr.test.KPMETestCase;
27 import org.kuali.hr.time.dept.lunch.DeptLunchRule;
28 import org.kuali.hr.time.service.base.TkServiceLocator;
29 import org.kuali.hr.time.test.TkTestUtils;
30 import org.kuali.hr.time.timeblock.TimeBlock;
31 import org.kuali.hr.time.timeblock.TimeHourDetail;
32 import org.kuali.hr.time.timesheet.TimesheetDocument;
33 import org.kuali.hr.time.util.TKContext;
34 import org.kuali.hr.time.util.TKUser;
35 import org.kuali.hr.time.util.TKUtils;
36 import org.kuali.hr.time.util.TkConstants;
37 import org.kuali.rice.kim.api.identity.Person;
38 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
39 import org.kuali.rice.krad.service.KRADServiceLocator;
40
41 public class DepartmentLunchRuleTest extends KPMETestCase {
42 private Date JAN_AS_OF_DATE = new Date((new DateTime(2010, 1, 1, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone())).getMillis());
43
44 @Test
45 public void testDepartmentLunchRuleFetch() throws Exception{
46 DeptLunchRule deptLunchRule = new DeptLunchRule();
47 deptLunchRule.setActive(true);
48 deptLunchRule.setDept("TEST");
49 deptLunchRule.setWorkArea(1234L);
50 deptLunchRule.setEffectiveDate(JAN_AS_OF_DATE);
51 deptLunchRule.setJobNumber(0L);
52 deptLunchRule.setPrincipalId("admin");
53 deptLunchRule.setDeductionMins(new BigDecimal(30));
54 deptLunchRule.setShiftHours(new BigDecimal(6));
55 deptLunchRule.setTkDeptLunchRuleId("1001");
56
57 KRADServiceLocator.getBusinessObjectService().save(deptLunchRule);
58
59 deptLunchRule = TkServiceLocator.getDepartmentLunchRuleService().getDepartmentLunchRule("TEST",
60 1234L, "admin", 0L, JAN_AS_OF_DATE);
61 Assert.assertTrue("dept lunch rule fetched ", deptLunchRule!=null);
62
63 }
64
65
66
67
68
69 @Test
70 public void testDepartmentLunchRule() throws Exception {
71
72 DeptLunchRule deptLunchRule = new DeptLunchRule();
73 deptLunchRule.setActive(true);
74 deptLunchRule.setDept("TEST-DEPT");
75 deptLunchRule.setWorkArea(1234L);
76 Calendar cal = Calendar.getInstance();
77 cal.set(2010, 1, 1);
78 deptLunchRule.setEffectiveDate(JAN_AS_OF_DATE);
79 deptLunchRule.setJobNumber(1L);
80 deptLunchRule.setPrincipalId("edna");
81 deptLunchRule.setDeductionMins(new BigDecimal(30));
82 deptLunchRule.setShiftHours(new BigDecimal(6));
83 deptLunchRule.setTkDeptLunchRuleId("1001");
84
85 KRADServiceLocator.getBusinessObjectService().save(deptLunchRule);
86
87 deptLunchRule = TkServiceLocator.getDepartmentLunchRuleService().getDepartmentLunchRule("TEST-DEPT",
88 1234L, "edna", 1L, JAN_AS_OF_DATE);
89 Assert.assertTrue("dept lunch rule fetched ", deptLunchRule!=null);
90
91 Person testUser = KimApiServiceLocator.getPersonService().getPerson("edna");
92 TKUser.setTargetPerson(testUser);
93 TimesheetDocument doc = TkTestUtils.populateTimesheetDocument(JAN_AS_OF_DATE);
94
95 for(TimeBlock tb : doc.getTimeBlocks()){
96 tb.setClockLogCreated(true);
97 }
98
99
100
101 for(TimeBlock tb : doc.getTimeBlocks()) {
102 if(tb.getHours().compareTo(deptLunchRule.getShiftHours()) == 1) {
103 for(TimeHourDetail thd : tb.getTimeHourDetails()){
104
105 if(!StringUtils.equals(thd.getEarnCode(), TkConstants.LUNCH_EARN_CODE)){
106 Assert.assertEquals(new BigDecimal(9.50).setScale(2), tb.getHours());
107 }
108 }
109 }
110 }
111
112 }
113
114
115
116
117
118
119 }