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.util.ArrayList;
20 import java.util.List;
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.KPMEWebTestCase;
27 import org.kuali.kpme.core.FunctionalTest;
28 import org.kuali.kpme.core.util.HrConstants;
29 import org.kuali.kpme.core.util.TKUtils;
30 import org.kuali.kpme.tklm.api.time.timeblock.TimeBlock;
31 import org.kuali.kpme.tklm.api.time.timehourdetail.TimeHourDetail;
32 import org.kuali.kpme.tklm.time.rules.lunch.department.DeptLunchRule;
33 import org.kuali.kpme.tklm.time.service.TkServiceLocator;
34 import org.kuali.kpme.tklm.time.timesheet.TimesheetDocument;
35 import org.kuali.kpme.tklm.utils.TkTestUtils;
36 import org.kuali.rice.krad.service.KRADServiceLocator;
37
38 @FunctionalTest
39 public class DepartmentLunchRuleTest extends KPMEWebTestCase {
40 private DateTime JAN_AS_OF_DATE = new DateTime(2010, 1, 1, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone());
41
42 @Test
43 public void testDepartmentLunchRuleFetch() throws Exception{
44 DeptLunchRule deptLunchRule = new DeptLunchRule();
45 deptLunchRule.setActive(true);
46 deptLunchRule.setDept("TEST");
47 deptLunchRule.setWorkArea(1234L);
48 deptLunchRule.setEffectiveLocalDate(JAN_AS_OF_DATE.toLocalDate());
49 deptLunchRule.setJobNumber(0L);
50 deptLunchRule.setPrincipalId("admin");
51 deptLunchRule.setDeductionMins(new BigDecimal(30));
52 deptLunchRule.setShiftHours(new BigDecimal(6));
53 deptLunchRule.setTkDeptLunchRuleId("1001");
54 deptLunchRule.setUserPrincipalId("admin");
55 deptLunchRule.setGroupKeyCode("IU-BL");
56
57 KRADServiceLocator.getBusinessObjectService().save(deptLunchRule);
58
59 deptLunchRule = TkServiceLocator.getDepartmentLunchRuleService().getDepartmentLunchRule("TEST",
60 1234L, "admin", 0L, "IU-BL", JAN_AS_OF_DATE.toLocalDate());
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 deptLunchRule.setEffectiveLocalDate(JAN_AS_OF_DATE.toLocalDate());
77 deptLunchRule.setJobNumber(1L);
78 deptLunchRule.setPrincipalId("edna");
79 deptLunchRule.setDeductionMins(new BigDecimal(30));
80 deptLunchRule.setShiftHours(new BigDecimal(6));
81 deptLunchRule.setTkDeptLunchRuleId("1001");
82 deptLunchRule.setUserPrincipalId("admin");
83 deptLunchRule.setGroupKeyCode("IU-BL");
84
85 KRADServiceLocator.getBusinessObjectService().save(deptLunchRule);
86
87 deptLunchRule = TkServiceLocator.getDepartmentLunchRuleService().getDepartmentLunchRule("TEST-DEPT",
88 1234L, "edna", 1L, "IU-BL", JAN_AS_OF_DATE.toLocalDate());
89 Assert.assertTrue("dept lunch rule fetched ", deptLunchRule!=null);
90
91 TimesheetDocument doc = TkTestUtils.populateTimesheetDocument(JAN_AS_OF_DATE, "edna");
92
93 List<TimeBlock> timeBlocks = new ArrayList<TimeBlock>(doc.getTimeBlocks());
94 for(TimeBlock tb : doc.getTimeBlocks()){
95 TimeBlock.Builder b = TimeBlock.Builder.create(tb);
96 b.setClockLogCreated(true);
97 timeBlocks.add(b.build());
98 }
99 for(TimeBlock tb : timeBlocks) {
100 if(tb.getHours().compareTo(deptLunchRule.getShiftHours()) == 1) {
101 for(TimeHourDetail thd : tb.getTimeHourDetails()){
102
103 if(!StringUtils.equals(thd.getEarnCode(), HrConstants.LUNCH_EARN_CODE)){
104 Assert.assertEquals(new BigDecimal(9.50).setScale(2), tb.getHours());
105 }
106 }
107 }
108 }
109
110 }
111
112 @Test
113 public void testSearchDepartmentLunchRules() throws Exception {
114
115
116
117
118
119 }
120
121 }