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