1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.time.collection;
17
18 import java.util.Collections;
19 import java.util.Random;
20
21 import org.joda.time.LocalDate;
22 import org.junit.Assert;
23 import org.junit.Test;
24 import org.kuali.hr.KPMEWebTestCase;
25 import org.kuali.hr.util.HtmlUnitUtil;
26 import org.kuali.kpme.core.FunctionalTest;
27 import org.kuali.kpme.core.department.DepartmentBo;
28 import org.kuali.kpme.core.service.HrServiceLocator;
29 import org.kuali.kpme.core.util.TKUtils;
30 import org.kuali.kpme.tklm.time.rules.timecollection.TimeCollectionRule;
31 import org.kuali.kpme.tklm.time.service.TkServiceLocator;
32 import org.kuali.kpme.tklm.utils.TkTestConstants;
33 import org.kuali.rice.krad.service.KRADServiceLocator;
34
35 import com.gargoylesoftware.htmlunit.html.HtmlInput;
36 import com.gargoylesoftware.htmlunit.html.HtmlPage;
37
38 @FunctionalTest
39 public class TimeCollectionRuleMaintTest extends KPMEWebTestCase {
40
41 private static final String TEST_CODE = "X";
42 private static final LocalDate TEST_DATE = LocalDate.now();
43 private static final String TEST_CODE_DEPARTMENT_VALID = "_test";
44
45 private static String timeCollectionRuleId;
46 private static String timeCollectionRuleIdWithInvalidWorkArea;
47
48 private static String TEST_CODE_INVALID_DEPT = "INVALID_DEPT";
49 private static Long TEST_CODE_INVALID_WORKAREA = 2L;
50 private static String PAY_TYPE_ERROR = "The specified payType '%' does not exist.";
51
52 private static final String TEST_GRP_KEY_CD = "DEFAULT";
53
54
55
56
57
58
59
60 @Test
61 public void testTimeCollectionRuleMaintForDeptErrorMessage() throws Exception {
62 String baseUrl = TkTestConstants.Urls.TIME_COLLECTION_RULE_MAINT_NEW_URL;
63 HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), baseUrl);
64 HtmlInput inputForDescription = HtmlUnitUtil.getInputContainingText(page, "* Document Description");
65 inputForDescription.setValueAttribute("Description");
66
67 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.effectiveDate", "01/01/2010");
68 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.dept", TEST_CODE_INVALID_DEPT);
69 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.workArea", "30");
70 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.payType", "BW");
71 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.groupKeyCode", TEST_GRP_KEY_CD);
72 HtmlPage resultantPageAfterEdit = HtmlUnitUtil
73 .clickInputContainingText(page, "submit");
74 HtmlUnitUtil.createTempFile(resultantPageAfterEdit);
75 Assert.assertTrue("Maintenance Page contains test timeCollectionRule",
76 resultantPageAfterEdit.asText().contains(
77 "The specified department '"
78 + TEST_CODE_INVALID_DEPT
79 + "' does not exist."));
80
81 HtmlUnitUtil.setFieldValue(resultantPageAfterEdit, "document.newMaintainableObject.payType", "%");
82 resultantPageAfterEdit = HtmlUnitUtil.clickInputContainingText(resultantPageAfterEdit, "submit");
83 Assert.assertFalse("Maintenance Page contains error" + PAY_TYPE_ERROR,
84 resultantPageAfterEdit.asText().contains(PAY_TYPE_ERROR));
85
86 }
87
88
89 @Test
90 public void testTimeCollectionRuleMaintForWorkAreaErrorMessage() throws Exception {
91 HtmlPage timeCollectionRuleLookup = HtmlUnitUtil
92 .gotoPageAndLogin(getWebClient(), TkTestConstants.Urls.TIME_COLLECTION_RULE_MAINT_URL);
93 timeCollectionRuleLookup = HtmlUnitUtil.clickInputContainingText(
94 timeCollectionRuleLookup, "search");
95 Assert.assertTrue("Page contains test timeCollectionRule",
96 timeCollectionRuleLookup.asText().contains(TEST_CODE));
97 HtmlPage maintPage = HtmlUnitUtil.clickAnchorContainingText(
98 timeCollectionRuleLookup, "edit",
99 timeCollectionRuleIdWithInvalidWorkArea.toString());
100 HtmlUnitUtil.createTempFile(maintPage);
101 HtmlInput inputForDescription = HtmlUnitUtil.getInputContainingText(
102 maintPage, "* Document Description");
103 inputForDescription.setValueAttribute("Description");
104 HtmlPage resultantPageAfterEdit = HtmlUnitUtil
105 .clickInputContainingText(maintPage, "submit");
106 Assert.assertTrue("Maintenance Page contains test timeCollectionRule",
107 resultantPageAfterEdit.asText().contains(
108 "The specified workarea '"
109 + TEST_CODE_INVALID_WORKAREA
110 + "' does not exist."));
111 }
112
113
114
115
116
117
118 @Test
119 public void testTimeCollectionRuleMaint() throws Exception {
120 HtmlPage timeCollectionRuleLookup = HtmlUnitUtil
121 .gotoPageAndLogin(getWebClient(), TkTestConstants.Urls.TIME_COLLECTION_RULE_MAINT_URL);
122 timeCollectionRuleLookup = HtmlUnitUtil.clickInputContainingText(
123 timeCollectionRuleLookup, "search");
124 Assert.assertTrue("Page contains test timeCollectionRule",
125 timeCollectionRuleLookup.asText().contains(TEST_CODE));
126 HtmlPage maintPage = HtmlUnitUtil.clickAnchorContainingText(
127 timeCollectionRuleLookup, "edit",
128 timeCollectionRuleId);
129 Assert.assertTrue("Maintenance Page contains test timeCollectionRule",
130 maintPage.asText().contains(TEST_CODE));
131 }
132
133 @Override
134 public void setUp() throws Exception {
135 super.setUp();
136 DepartmentBo department = new DepartmentBo();
137 department.setDept(TEST_CODE_DEPARTMENT_VALID);
138 department.setChart(TEST_CODE_DEPARTMENT_VALID);
139 department.setDescription(TEST_CODE_DEPARTMENT_VALID);
140 department.setOrg(TEST_CODE_DEPARTMENT_VALID);
141 department.setGroupKeyCode(TEST_GRP_KEY_CD);
142
143 department.setEffectiveLocalDate(TEST_DATE);
144 department.setActive(Boolean.TRUE);
145 department.setUserPrincipalId(TEST_CODE);
146 department = KRADServiceLocator.getBusinessObjectService().save(department);
147
148 TimeCollectionRule timeCollectionRule = new TimeCollectionRule();
149 timeCollectionRule.setDept(TEST_CODE_DEPARTMENT_VALID);
150 timeCollectionRule.setEffectiveLocalDate(TEST_DATE);
151 timeCollectionRule.setTimestamp(TKUtils.getCurrentTimestamp());
152 timeCollectionRule.setUserPrincipalId(TEST_CODE);
153 timeCollectionRule.setActive(true);
154 timeCollectionRule.setPayType("%");
155 timeCollectionRule.setGroupKeyCode(TEST_GRP_KEY_CD);
156 timeCollectionRule = KRADServiceLocator.getBusinessObjectService().save(timeCollectionRule);
157 timeCollectionRuleId = timeCollectionRule.getTkTimeCollectionRuleId();
158
159 TimeCollectionRule timeCollectionRuleWIthInvalidWorkArea = new TimeCollectionRule();
160
161 Random randomObj = new Random();
162 for (;;) {
163 long workAreaIndex = randomObj.nextInt();
164 int count = HrServiceLocator.getWorkAreaService().getWorkAreaCount(null, workAreaIndex);
165
166 if (count == 0) {
167 TEST_CODE_INVALID_WORKAREA = new Long(workAreaIndex);
168 break;
169 }
170 }
171 timeCollectionRuleWIthInvalidWorkArea
172 .setDept(TEST_CODE_DEPARTMENT_VALID);
173 timeCollectionRuleWIthInvalidWorkArea.setEffectiveLocalDate(TEST_DATE);
174 timeCollectionRuleWIthInvalidWorkArea.setActive(true);
175 timeCollectionRuleWIthInvalidWorkArea.setPayType("%");
176 timeCollectionRuleWIthInvalidWorkArea.setGroupKeyCode(TEST_GRP_KEY_CD);
177 timeCollectionRuleWIthInvalidWorkArea.setTimestamp(TKUtils.getCurrentTimestamp());
178 timeCollectionRuleWIthInvalidWorkArea.setUserPrincipalId(TEST_CODE);
179 timeCollectionRuleWIthInvalidWorkArea
180 .setWorkArea(TEST_CODE_INVALID_WORKAREA);
181 timeCollectionRuleWIthInvalidWorkArea = KRADServiceLocator.getBusinessObjectService().save(
182 timeCollectionRuleWIthInvalidWorkArea);
183 timeCollectionRuleIdWithInvalidWorkArea = timeCollectionRuleWIthInvalidWorkArea
184 .getTkTimeCollectionRuleId();
185
186 }
187
188 @Override
189 public void tearDown() throws Exception {
190
191 TimeCollectionRule timeCollectionRuleObj = KRADServiceLocator.getBusinessObjectService()
192 .findByPrimaryKey(TimeCollectionRule.class, Collections.singletonMap("tkTimeCollectionRuleId", timeCollectionRuleId));
193
194
195 KRADServiceLocator.getBusinessObjectService().delete(
196 timeCollectionRuleObj);
197
198 timeCollectionRuleObj = TkServiceLocator.getTimeCollectionRuleService().getTimeCollectionRule(TEST_CODE_DEPARTMENT_VALID,
199 TEST_CODE_INVALID_WORKAREA, "%", TEST_GRP_KEY_CD, LocalDate.now());
200
201
202 KRADServiceLocator.getBusinessObjectService().delete(
203 timeCollectionRuleObj);
204
205 DepartmentBo deptObj = DepartmentBo.from(HrServiceLocator.getDepartmentService().getDepartment(TEST_CODE_DEPARTMENT_VALID, TEST_GRP_KEY_CD, LocalDate.now()));
206 KRADServiceLocator.getBusinessObjectService().delete(deptObj);
207 super.tearDown();
208 }
209
210 }