1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.core.earncode.group;
17
18 import java.math.BigDecimal;
19 import java.util.ArrayList;
20 import java.util.Collections;
21 import java.util.List;
22
23 import org.apache.commons.lang.StringUtils;
24 import org.apache.log4j.Logger;
25 import org.joda.time.LocalDate;
26 import org.junit.Assert;
27 import org.junit.Test;
28 import org.kuali.hr.KPMEWebTestCase;
29 import org.kuali.hr.util.HtmlUnitUtil;
30 import org.kuali.kpme.core.FunctionalTest;
31 import org.kuali.kpme.core.earncode.EarnCode;
32 import org.kuali.kpme.core.earncode.group.EarnCodeGroup;
33 import org.kuali.kpme.core.earncode.group.EarnCodeGroupDefinition;
34 import org.kuali.kpme.core.service.HrServiceLocator;
35 import org.kuali.kpme.core.util.HrTestConstants;
36 import org.kuali.rice.krad.service.KRADServiceLocator;
37
38 import com.gargoylesoftware.htmlunit.html.HtmlCheckBoxInput;
39 import com.gargoylesoftware.htmlunit.html.HtmlElement;
40 import com.gargoylesoftware.htmlunit.html.HtmlInput;
41 import com.gargoylesoftware.htmlunit.html.HtmlPage;
42 import com.gargoylesoftware.htmlunit.html.HtmlTextInput;
43
44 @FunctionalTest
45 public class EarnCodeGroupMaintenanceTest extends KPMEWebTestCase {
46 private static final Logger LOG = Logger.getLogger(EarnCodeGroupMaintenanceTest.class);
47 private static final LocalDate TEST_DATE = LocalDate.now();
48 private static final String EARN_CODE = "RGN";
49 private static String hrEarnGroupId;
50 private static String hrEarnCodeId;
51 private static String hrEarnGroupIdRGG;
52
53 @Override
54 public void setUp() throws Exception {
55 super.setUp();
56 List<EarnCodeGroupDefinition> earnGroups = new ArrayList<EarnCodeGroupDefinition>();
57 EarnCodeGroupDefinition definition = new EarnCodeGroupDefinition();
58 definition.setEarnCode(EARN_CODE);
59 earnGroups.add(definition);
60
61 EarnCodeGroup earnGroup = new EarnCodeGroup();
62 earnGroup.setEarnCodeGroup("testGroup");
63 earnGroup.setDescr("test");
64 earnGroup.setEffectiveLocalDate(TEST_DATE);
65 earnGroup.setShowSummary(true);
66 earnGroup.setActive(true);
67 earnGroup.setEarnCodeGroups(earnGroups);
68 KRADServiceLocator.getBusinessObjectService().save(earnGroup);
69 hrEarnGroupId = earnGroup.getHrEarnCodeGroupId();
70
71
72 EarnCode earnCode = new EarnCode();
73 earnCode.setActive(true);
74 earnCode.setEarnCode("RGG");
75 earnCode.setEffectiveLocalDate(TEST_DATE);
76 earnCode.setRecordMethod("T");
77 earnCode.setFractionalTimeAllowed("99");
78 earnCode.setRoundingOption("T");
79 earnCode.setEligibleForAccrual("Y");
80 earnCode.setAffectPay("Y");
81 earnCode.setAllowScheduledLeave("Y");
82 earnCode.setFmla("Y");
83 earnCode.setWorkmansComp("Y");
84 earnCode.setAllowNegativeAccrualBalance("Y");
85 earnCode.setDescription("RGG");
86 earnCode.setOvtEarnCode(false);
87 earnCode.setInflateMinHours(BigDecimal.ZERO);
88 earnCode.setInflateFactor(BigDecimal.ZERO);
89 earnCode = KRADServiceLocator.getBusinessObjectService().save(earnCode);
90 hrEarnCodeId = earnCode.getHrEarnCodeId();
91
92
93 EarnCodeGroup earnGroupRGG = new EarnCodeGroup();
94 earnGroupRGG.setEarnCodeGroup("RGG");
95 earnGroupRGG.setDescr("test RGG");
96 earnGroupRGG.setEffectiveLocalDate(TEST_DATE);
97 earnGroupRGG.setShowSummary(true);
98 earnGroupRGG.setActive(true);
99 earnGroupRGG = KRADServiceLocator.getBusinessObjectService().save(earnGroupRGG);
100 hrEarnGroupIdRGG = earnGroupRGG.getHrEarnCodeGroupId();
101 }
102
103 @Override
104 public void tearDown() throws Exception {
105 EarnCodeGroup earnGroupObj = KRADServiceLocator.getBusinessObjectService().findBySinglePrimaryKey(EarnCodeGroup.class, hrEarnGroupId);
106 KRADServiceLocator.getBusinessObjectService().delete(earnGroupObj);
107
108 EarnCodeGroup earnGroupObjRGG = KRADServiceLocator.getBusinessObjectService().findBySinglePrimaryKey(EarnCodeGroup.class, hrEarnGroupIdRGG);
109 KRADServiceLocator.getBusinessObjectService().delete(earnGroupObjRGG);
110
111 if (StringUtils.isNotBlank(hrEarnCodeId)) {
112 EarnCode earnCodeObj = KRADServiceLocator.getBusinessObjectService().findByPrimaryKey(EarnCode.class, Collections.singletonMap("hrEarnCodeId", hrEarnCodeId));
113 KRADServiceLocator.getBusinessObjectService().delete(earnCodeObj);
114 }
115 super.tearDown();
116 }
117
118 @Test
119 public void testEarnGroupMaintenancePage() throws Exception{
120 HtmlPage earnCodeLookUp = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), HrTestConstants.Urls.EARN_CODE_GROUP_MAINT_URL);
121 earnCodeLookUp = HtmlUnitUtil.clickInputContainingText(earnCodeLookUp, "search");
122 HtmlUnitUtil.createTempFile(earnCodeLookUp);
123 Assert.assertTrue("Page contains REG entry", earnCodeLookUp.asText().contains("REG"));
124
125 EarnCodeGroup earnGroup = HrServiceLocator.getEarnCodeGroupService().getEarnCodeGroup("REG", LocalDate.now());
126 String earnGroupId = earnGroup.getHrEarnCodeGroupId().toString();
127 HtmlPage maintPage = HtmlUnitUtil.clickAnchorContainingText(earnCodeLookUp, "edit", earnGroupId);
128 HtmlUnitUtil.createTempFile(maintPage);
129 Assert.assertTrue("Maintenance Page contains REG entry",maintPage.asText().contains("REG"));
130 }
131
132 @Test
133 public void testEditExistingEarnGroup() throws Exception {
134 HtmlPage earnGroupLookUp = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), HrTestConstants.Urls.EARN_CODE_GROUP_MAINT_URL);
135 earnGroupLookUp = HtmlUnitUtil.clickInputContainingText(earnGroupLookUp, "search");
136 Assert.assertTrue("Page contains test Earn Group", earnGroupLookUp.asText().contains("test"));
137 HtmlPage maintPage = HtmlUnitUtil.clickAnchorContainingText(earnGroupLookUp, "edit", hrEarnGroupId.toString());
138 Assert.assertTrue("Maintenance Page contains test ClockLog", maintPage.asText().contains("test"));
139 HtmlTextInput text = (HtmlTextInput) maintPage.getHtmlElementById("document.documentHeader.documentDescription");
140 text.setValueAttribute("test1");
141
142
143 earnGroupLookUp = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), HrTestConstants.Urls.EARN_CODE_GROUP_MAINT_URL);
144 earnGroupLookUp = HtmlUnitUtil.clickInputContainingText(earnGroupLookUp, "search");
145 Assert.assertTrue("Page contains test Earn Group", earnGroupLookUp.asText().contains("test RGG"));
146 HtmlPage testEditRGGPage = HtmlUnitUtil.clickAnchorContainingText(earnGroupLookUp, "edit", hrEarnGroupIdRGG.toString());
147 Assert.assertTrue("Maintenance Page contains test ClockLog", testEditRGGPage.asText().contains("test RGG"));
148 text = (HtmlTextInput) testEditRGGPage.getHtmlElementById("document.documentHeader.documentDescription");
149 text.setValueAttribute("testEditRGG");
150
151
152 text = (HtmlTextInput) testEditRGGPage.getHtmlElementById("document.newMaintainableObject.add.earnCodeGroups.earnCode");
153 text.setValueAttribute("RGG");
154 HtmlElement element = HtmlUnitUtil.getInputContainingText(testEditRGGPage, "methodToCall.addLine.earnCodeGroups");
155 HtmlPage newCodeAddedPage = element.click();
156
157 Assert.assertFalse("Page contains Error", newCodeAddedPage.asText().contains("error"));
158
159
160
161
162
163
164
165 element = newCodeAddedPage.getElementByName("methodToCall.route");
166 HtmlPage finalPage = element.click();
167
168 LOG.debug("Final Space is >>> " + finalPage.asText());
169
170 Assert.assertTrue("Maintenance page is submitted successfully", finalPage.asText().contains("Document was successfully submitted."));
171
172 }
173
174
175 @Test
176
177 public void testSubmitEarnGroupMaint() throws Exception {
178 String baseUrl = getBaseURL() + "/kr/maintenance.do?businessObjectClassName=org.kuali.kpme.core.earncode.group.EarnCodeGroup&methodToCall=start";
179 HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), baseUrl);
180 Assert.assertNotNull(page);
181
182 HtmlTextInput text = (HtmlTextInput) page.getHtmlElementById("document.documentHeader.documentDescription");
183 text.setValueAttribute("test");
184 text = (HtmlTextInput) page.getHtmlElementById(HrTestConstants.DOC_NEW_ELEMENT_ID_PREFIX + "descr");
185 text.setValueAttribute("Test Earn Group");
186 text = (HtmlTextInput) page.getHtmlElementById(HrTestConstants.DOC_NEW_ELEMENT_ID_PREFIX + "earnCodeGroup");
187 text.setValueAttribute("Test");
188
189 text = (HtmlTextInput) page.getHtmlElementById(HrTestConstants.DOC_NEW_ELEMENT_ID_PREFIX + "effectiveDate");
190 text.setValueAttribute("12/01/2008");
191
192 HtmlCheckBoxInput checkbox = (HtmlCheckBoxInput) page.getHtmlElementById(HrTestConstants.DOC_NEW_ELEMENT_ID_PREFIX + "showSummary");
193 checkbox.setChecked(true);
194 checkbox = (HtmlCheckBoxInput) page.getHtmlElementById(HrTestConstants.DOC_NEW_ELEMENT_ID_PREFIX + "active");
195 checkbox.setChecked(true);
196
197
198 text = (HtmlTextInput) page.getHtmlElementById(HrTestConstants.DOC_NEW_ELEMENT_ID_PREFIX + "add.earnCodeGroups.earnCode");
199 text.setValueAttribute(EARN_CODE);
200 HtmlElement element = HtmlUnitUtil.getInputContainingText(page, "methodToCall.addLine.earnCodeGroups");
201 HtmlPage page1 = element.click();
202
203 LOG.debug("Page1 click >>>>"+page1.asText());
204
205 Assert.assertTrue("Maintenance Page contains error messages", page1.asText().contains("The specified Earncode '" + EARN_CODE + "' does not exist."));
206
207
208 text = (HtmlTextInput) page1.getHtmlElementById(HrTestConstants.DOC_NEW_ELEMENT_ID_PREFIX + "effectiveDate");
209 text.setValueAttribute("5/01/2011");
210 element = HtmlUnitUtil.getInputContainingText(page1, "methodToCall.addLine.earnCodeGroups");
211 HtmlPage page2 = element.click();
212 Assert.assertFalse("Page contains Error", page2.asText().contains("error"));
213
214
215 text = (HtmlTextInput) page2.getHtmlElementById(HrTestConstants.DOC_NEW_ELEMENT_ID_PREFIX + "add.earnCodeGroups.earnCode");
216 text.setValueAttribute(EARN_CODE);
217 element = HtmlUnitUtil.getInputContainingText(page2, "methodToCall.addLine.earnCodeGroups");
218 page1 = element.click();
219 Assert.assertTrue("Maintenance Page contains error messages", page1.asText().contains(EARN_CODE + " is already a part of this earngroup."));
220
221 element = page1.getElementByName("methodToCall.route");
222 HtmlPage finalPage = element.click();
223
224 Assert.assertTrue("Maintenance Page contains error messages", finalPage.asText().contains(EARN_CODE + " is used by another earn group - 'test'."));
225
226
227 element = HtmlUnitUtil.getInputContainingText(finalPage, "methodToCall.deleteLine.earnCodeGroups");
228 HtmlPage page3 = element.click();
229 Assert.assertFalse("Page contains Error", page3.asText().contains("error"));
230
231
232 text = (HtmlTextInput) page3.getHtmlElementById(HrTestConstants.DOC_NEW_ELEMENT_ID_PREFIX + "add.earnCodeGroups.earnCode");
233 text.setValueAttribute("XZZ");
234 element = HtmlUnitUtil.getInputContainingText(page3, "methodToCall.addLine.earnCodeGroups");
235 page1 = element.click();
236 LOG.error("page1 click >>> adding SDR to earn code group >>>" + page1.asXml());
237 Assert.assertFalse("Page contains Error", page1.asText().contains("error"));
238 element = page1.getElementByName("methodToCall.route");
239 finalPage = element.click();
240
241 Assert.assertTrue("Maintenance page is submitted successfully", finalPage.asText().contains("Document was successfully submitted."));
242 Assert.assertTrue("Maintenance page is submitted successfully", finalPage.asText().contains("FINAL"));
243 }
244
245 @Test
246 public void testSubmitEarnGroupWithNewerVersionMaint() throws Exception {
247 String baseUrl = getBaseURL() + "/kr/maintenance.do?businessObjectClassName=org.kuali.kpme.core.earncode.group.EarnCodeGroup&methodToCall=start";
248 HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), baseUrl);
249 Assert.assertNotNull(page);
250
251
252 populateEarnGroup(page, "01/01/2011");
253 HtmlInput text = (HtmlTextInput) page.getHtmlElementById("document.newMaintainableObject.add.earnCodeGroups.earnCode");
254 text.setValueAttribute("RGH");
255 HtmlElement element = HtmlUnitUtil.getInputContainingText(page, "methodToCall.addLine.earnCodeGroups");
256 HtmlPage newCodeAddedPage = element.click();
257
258 Assert.assertFalse("Page contains Error", newCodeAddedPage.asText().contains("error"));
259 element = newCodeAddedPage.getElementByName("methodToCall.route");
260 HtmlPage finalPage = element.click();
261
262 Assert.assertTrue("Maintenance page is submitted successfully", finalPage.asText().contains("Document was successfully submitted."));
263
264
265 page = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), baseUrl);
266 populateEarnGroup(page, "01/01/2010");
267 text = (HtmlTextInput) page.getHtmlElementById("document.newMaintainableObject.add.earnCodeGroups.earnCode");
268 text.setValueAttribute("RGH");
269 element = HtmlUnitUtil.getInputContainingText(page, "methodToCall.addLine.earnCodeGroups");
270 newCodeAddedPage = element.click();
271 Assert.assertFalse("Page contains Error", newCodeAddedPage.asText().contains("error"));
272 element = newCodeAddedPage.getElementByName("methodToCall.route");
273 finalPage = element.click();
274 Assert.assertTrue("Maintenance Page doesn't return warning about later effective date", finalPage.asText().contains("A record for this object exists with a later effective date"));
275 HtmlElement yesButton = finalPage.getElementByName("methodToCall.processAnswer.button0");
276 finalPage = yesButton.click();
277 Assert.assertTrue("Maintenance Page contains error messages", finalPage.asText().contains("There is a newer version of this Earn Group."));
278
279 }
280
281 private void populateEarnGroup(HtmlPage page, String effDateString) {
282 HtmlUnitUtil.setFieldValue(page, "document.documentHeader.documentDescription", "test");
283 HtmlUnitUtil.setFieldValue(page, HrTestConstants.DOC_NEW_ELEMENT_ID_PREFIX + "descr", "Test Earn Group");
284 HtmlUnitUtil.setFieldValue(page, HrTestConstants.DOC_NEW_ELEMENT_ID_PREFIX + "earnCodeGroup", "MM");
285 HtmlUnitUtil.setFieldValue(page, HrTestConstants.DOC_NEW_ELEMENT_ID_PREFIX + "effectiveDate", effDateString);
286 HtmlUnitUtil.setFieldValue(page, HrTestConstants.DOC_NEW_ELEMENT_ID_PREFIX + "showSummary", "on");
287 HtmlUnitUtil.setFieldValue(page, HrTestConstants.DOC_NEW_ELEMENT_ID_PREFIX + "active", "on");
288 }
289
290
291 }