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