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