1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.core.earncode;
17
18 import java.math.BigDecimal;
19 import java.text.DateFormat;
20 import java.text.SimpleDateFormat;
21 import java.util.List;
22
23 import org.joda.time.DateTime;
24 import org.junit.Assert;
25 import org.junit.Ignore;
26 import org.junit.Test;
27 import org.kuali.hr.KPMEWebTestCase;
28 import org.kuali.hr.util.HtmlUnitUtil;
29 import org.kuali.kpme.core.FunctionalTest;
30 import org.kuali.kpme.core.earncode.EarnCode;
31 import org.kuali.kpme.core.util.HrTestConstants;
32 import org.kuali.kpme.core.util.TKUtils;
33 import org.kuali.kpme.tklm.time.timeblock.TimeBlock;
34 import org.kuali.rice.krad.service.KRADServiceLocator;
35
36 import com.gargoylesoftware.htmlunit.html.DomElement;
37 import com.gargoylesoftware.htmlunit.html.HtmlCheckBoxInput;
38 import com.gargoylesoftware.htmlunit.html.HtmlElement;
39 import com.gargoylesoftware.htmlunit.html.HtmlInput;
40 import com.gargoylesoftware.htmlunit.html.HtmlPage;
41 import com.gargoylesoftware.htmlunit.html.HtmlRadioButtonInput;
42 import com.gargoylesoftware.htmlunit.html.HtmlSelect;
43 import com.gargoylesoftware.htmlunit.html.HtmlTextInput;
44
45 @FunctionalTest
46 public class EarnCodeMaintenanceTest extends KPMEWebTestCase {
47 private static final DateTime TEST_DATE = new DateTime(2009, 1, 1, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone());
48 private static final String EARN_CODE = "RGN";
49 private static final DateFormat DATE_FORMAT = new SimpleDateFormat("MM/dd/yy");
50
51 private static String hrEarnCodeId;
52 private static String timeBlockId;
53
54 @Override
55 public void setUp() throws Exception {
56 super.setUp();
57 EarnCode earnCode = new EarnCode();
58 earnCode.setActive(true);
59 earnCode.setEarnCode(EARN_CODE);
60 earnCode.setEffectiveLocalDate(TEST_DATE.toLocalDate());
61 earnCode.setRecordMethod("T");
62 earnCode.setFractionalTimeAllowed("99");
63 earnCode.setRoundingOption("T");
64 earnCode.setAffectPay("Y");
65 earnCode.setWorkmansComp("Y");
66 earnCode.setEligibleForAccrual("Y");
67 earnCode.setAllowScheduledLeave("Y");
68 earnCode.setFmla("Y");
69 earnCode.setAllowNegativeAccrualBalance("Y");
70 earnCode.setDescription("RGN Test");
71 earnCode.setOvtEarnCode(false);
72 earnCode.setInflateMinHours(BigDecimal.ZERO);
73 earnCode.setInflateFactor(BigDecimal.ZERO);
74
75 KRADServiceLocator.getBusinessObjectService().save(earnCode);
76 hrEarnCodeId = earnCode.getHrEarnCodeId();
77
78 TimeBlock timeBlock = new TimeBlock();
79 timeBlock.setAmount(BigDecimal.ONE);
80 timeBlock.setAssignmentKey("somedesc");
81 timeBlock.setJobNumber(new Long(30));
82 timeBlock.setBeginDate(DATE_FORMAT.parse("01/01/2010"));
83 timeBlock.setEndDate(DATE_FORMAT.parse("01/03/2010"));
84 timeBlock.setBeginDateTime(new DateTime(2010, 1, 1, 0, 0, 0));
85 timeBlock.setEndDateTime(new DateTime(2010, 1, 3, 0, 0, 0));
86 timeBlock.setEarnCode(EARN_CODE);
87 timeBlock.setWorkArea(new Long(20));
88 timeBlock.setTask(new Long(15));
89 timeBlock.setLunchDeleted(false);
90 timeBlock.setTimestamp(TKUtils.getCurrentTimestamp());
91 timeBlock.setUserPrincipalId("princ");
92 timeBlock.setHours(BigDecimal.TEN);
93 timeBlock.setClockLogCreated(true);
94 timeBlock.setDocumentId("10039");
95
96 KRADServiceLocator.getBusinessObjectService().save(timeBlock);
97 timeBlockId = timeBlock.getTkTimeBlockId();
98 }
99
100 @Override
101 public void tearDown() throws Exception {
102 EarnCode earnCodeObj = KRADServiceLocator.getBusinessObjectService().findBySinglePrimaryKey(EarnCode.class, hrEarnCodeId);
103 KRADServiceLocator.getBusinessObjectService().delete(earnCodeObj);
104
105
106 super.tearDown();
107 }
108
109 @Test
110 public void testEarnCodeMaintenancePage() throws Exception{
111
112 HtmlPage earnCodeLookUp = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), HrTestConstants.Urls.EARN_CODE_MAINT_URL);
113 earnCodeLookUp = HtmlUnitUtil.clickInputContainingText(earnCodeLookUp, "search");
114 Assert.assertTrue("Page must contain SDR entry", earnCodeLookUp.asText().contains("SDR"));
115 HtmlPage maintPage = HtmlUnitUtil.clickAnchorContainingText(earnCodeLookUp, "edit","1");
116
117
118 HtmlSelect inputText= maintPage.getHtmlElementById("document.newMaintainableObject.recordMethod");
119 inputText.setDefaultValue("H");
120
121 HtmlInput inputForDescription = HtmlUnitUtil.getInputContainingText(
122 maintPage, "* Document Description");
123 inputForDescription.setValueAttribute("Description");
124
125
126
127 HtmlRadioButtonInput hb = maintPage.getHtmlElementById("document.newMaintainableObject.fractionalTimeAllowed99");
128 hb.setChecked(true);
129
130 HtmlPage resultantPageAfterEdit = HtmlUnitUtil
131 .clickInputContainingText(maintPage, "submit");
132 LOG.debug(resultantPageAfterEdit.asText());
133
134
135
136
137
138
139
140
141
142
143 inputForDescription = HtmlUnitUtil.getInputContainingText(
144 maintPage, "* Document Description");
145 inputForDescription.setValueAttribute("Description");
146 resultantPageAfterEdit = HtmlUnitUtil
147 .clickInputContainingText(maintPage, "submit");
148
149
150 }
151
152 @Test
153 public void testEditExistingEarnCode() throws Exception {
154 HtmlPage earnCodeLookUp = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), HrTestConstants.Urls.EARN_CODE_MAINT_URL);
155 List<DomElement> lstElements = earnCodeLookUp.getElementsByIdAndOrName("history");
156 for(DomElement e : lstElements) {
157 HtmlRadioButtonInput radioButton = (HtmlRadioButtonInput) e;
158 if(e.getAttribute("title").equals("Show History - Yes")) {
159 radioButton.setChecked(true);
160 break;
161 }
162 }
163 earnCodeLookUp = HtmlUnitUtil.clickInputContainingText(earnCodeLookUp, "search");
164 Assert.assertTrue("Page contains test Earn Code", earnCodeLookUp.asText().contains("RGN Test"));
165 HtmlPage maintPage = HtmlUnitUtil.clickAnchorContainingText(earnCodeLookUp, "edit", hrEarnCodeId.toString());
166 Assert.assertTrue("Maintenance Page contains Test ",maintPage.asText().contains("RGN Test"));
167 HtmlTextInput text = (HtmlTextInput) maintPage.getHtmlElementById("document.documentHeader.documentDescription");
168 text.setValueAttribute("test");
169 HtmlElement element = maintPage.getElementByName("methodToCall.route");
170 HtmlPage finalPage = element.click();
171
172 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"));
173 HtmlElement yesButton = finalPage.getElementByName("methodToCall.processAnswer.button0");
174 finalPage = yesButton.click();
175 Assert.assertTrue("Maintenance Page contains error messages", finalPage.asText().contains("There is a newer version of this Earn Code."));
176 }
177
178 @Test
179 public void testDeactivateEarnCodeWithActiveTimeBlock() throws Exception {
180
181 HtmlPage earnCodeLookUp = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), HrTestConstants.Urls.EARN_CODE_MAINT_URL);
182 List<DomElement> lstElements = earnCodeLookUp.getElementsByIdAndOrName("history");
183 for(DomElement e : lstElements) {
184 HtmlRadioButtonInput radioButton = (HtmlRadioButtonInput) e;
185 if(e.getAttribute("title").equals("Show History - Yes")) {
186 radioButton.setChecked(true);
187 break;
188 }
189 }
190 earnCodeLookUp = HtmlUnitUtil.clickInputContainingText(earnCodeLookUp, "search");
191 Assert.assertTrue("Page contains test Earn Code", earnCodeLookUp.asText().contains("RGN Test"));
192 HtmlPage maintPage = HtmlUnitUtil.clickAnchorContainingText(earnCodeLookUp, "edit", hrEarnCodeId.toString());
193 Assert.assertTrue("Maintenance Page contains Test ",maintPage.asText().contains("RGN Test"));
194 HtmlTextInput text = (HtmlTextInput) maintPage.getHtmlElementById("document.documentHeader.documentDescription");
195 text.setValueAttribute("test");
196 HtmlCheckBoxInput active = (HtmlCheckBoxInput) maintPage.getHtmlElementById("document.newMaintainableObject.active");
197 active.setChecked(false);
198 HtmlTextInput effectiveDate = (HtmlTextInput) maintPage.getHtmlElementById("document.newMaintainableObject.effectiveDate");
199 effectiveDate.setValueAttribute("01/02/2010");
200 HtmlElement element = maintPage.getElementByName("methodToCall.route");
201 HtmlPage finalPage = element.click();
202 Assert.assertTrue("Maintenance Page does not return warning about active timeblock existence.", finalPage.asText().contains("Can not inactivate earn code 'RGN'. It is used in active time blocks"));
203 }
204
205 @Test
206 public void testDeactivateEarnCodeWithInActiveTimeBlock() throws Exception {
207
208 HtmlPage earnCodeLookUp = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), HrTestConstants.Urls.EARN_CODE_MAINT_URL);
209 List<DomElement> lstElements = earnCodeLookUp.getElementsByIdAndOrName("history");
210 for(DomElement e : lstElements) {
211 HtmlRadioButtonInput radioButton = (HtmlRadioButtonInput) e;
212 if(e.getAttribute("title").equals("Show History - Yes")) {
213 radioButton.setChecked(true);
214 break;
215 }
216 }
217 earnCodeLookUp = HtmlUnitUtil.clickInputContainingText(earnCodeLookUp, "search");
218 Assert.assertTrue("Page contains test Earn Code", earnCodeLookUp.asText().contains("RGN Test"));
219 HtmlPage maintPage = HtmlUnitUtil.clickAnchorContainingText(earnCodeLookUp, "edit", hrEarnCodeId.toString());
220 Assert.assertTrue("Maintenance Page contains Test ",maintPage.asText().contains("RGN Test"));
221 HtmlTextInput text = (HtmlTextInput) maintPage.getHtmlElementById("document.documentHeader.documentDescription");
222 text.setValueAttribute("test");
223 HtmlCheckBoxInput active = (HtmlCheckBoxInput) maintPage.getHtmlElementById("document.newMaintainableObject.active");
224 active.setChecked(false);
225 HtmlTextInput effectiveDate = (HtmlTextInput) maintPage.getHtmlElementById("document.newMaintainableObject.effectiveDate");
226 effectiveDate.setValueAttribute("01/04/2010");
227 HtmlElement element = maintPage.getElementByName("methodToCall.route");
228 HtmlPage finalPage = element.click();
229 Assert.assertTrue("Maintenance Page should not return warning about active timeblock existence.", !finalPage.asText().contains("Can not inactivate earn code 'RGN'. It is used in active time blocks"));
230 }
231
232 }