1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.time.earncode.validation;
17
18 import java.math.BigDecimal;
19 import java.sql.Date;
20 import java.util.List;
21
22 import org.joda.time.DateTime;
23 import org.junit.Assert;
24 import org.junit.Test;
25 import org.kuali.hr.test.KPMETestCase;
26 import org.kuali.hr.time.earncode.EarnCode;
27 import org.kuali.hr.time.test.HtmlUnitUtil;
28 import org.kuali.hr.time.test.TkTestConstants;
29 import org.kuali.hr.time.util.TKUtils;
30 import org.kuali.hr.time.util.TkConstants;
31 import org.kuali.rice.krad.service.KRADServiceLocator;
32
33 import com.gargoylesoftware.htmlunit.html.HtmlElement;
34 import com.gargoylesoftware.htmlunit.html.HtmlPage;
35 import com.gargoylesoftware.htmlunit.html.HtmlRadioButtonInput;
36 import com.gargoylesoftware.htmlunit.html.HtmlTextInput;
37
38 public class EarnCodeMaintenaceTest extends KPMETestCase {
39 private static final java.sql.Date TEST_DATE = new Date((new DateTime(2009, 1, 1, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone())).getMillis());
40 private static final String EARN_CODE = "RGN";
41 private static String hrEarnCodeId;
42
43 @Override
44 public void setUp() throws Exception {
45 super.setUp();
46 EarnCode earnCode = new EarnCode();
47 earnCode.setActive(true);
48 earnCode.setEarnCode(EARN_CODE);
49 earnCode.setEffectiveDate(TEST_DATE);
50 earnCode.setRecordMethod("T");
51 earnCode.setFractionalTimeAllowed("99");
52 earnCode.setRoundingOption("T");
53 earnCode.setAffectPay("Y");
54 earnCode.setWorkmansComp("Y");
55 earnCode.setEligibleForAccrual("Y");
56 earnCode.setAllowScheduledLeave("Y");
57 earnCode.setFmla("Y");
58 earnCode.setAllowNegativeAccrualBalance("Y");
59 earnCode.setDescription("RGN Test");
60 earnCode.setOvtEarnCode(false);
61 earnCode.setInflateMinHours(BigDecimal.ZERO);
62 earnCode.setInflateFactor(BigDecimal.ZERO);
63
64 KRADServiceLocator.getBusinessObjectService().save(earnCode);
65 hrEarnCodeId = earnCode.getHrEarnCodeId();
66 }
67
68 @Override
69 public void tearDown() throws Exception {
70 EarnCode earnCodeObj = KRADServiceLocator.getBusinessObjectService().findBySinglePrimaryKey(EarnCode.class, hrEarnCodeId);
71 KRADServiceLocator.getBusinessObjectService().delete(earnCodeObj);
72 super.tearDown();
73 }
74
75
76 @Test
77 public void testEditExistingEarnCode() throws Exception {
78 HtmlPage earnCodeLookUp = HtmlUnitUtil.gotoPageAndLogin(TkTestConstants.Urls.EARN_CODE_MAINT_URL);
79 List<HtmlElement> lstElements = earnCodeLookUp.getElementsByIdAndOrName("history");
80 for(HtmlElement e : lstElements) {
81 HtmlRadioButtonInput radioButton = (HtmlRadioButtonInput) e;
82 if(e.getAttribute("title").equals("Show History - Yes")) {
83 radioButton.setChecked(true);
84 break;
85 }
86 }
87 earnCodeLookUp = HtmlUnitUtil.clickInputContainingText(earnCodeLookUp, "search");
88 Assert.assertTrue("Page contains test Earn Code", earnCodeLookUp.asText().contains("RGN Test"));
89 HtmlPage maintPage = HtmlUnitUtil.clickAnchorContainingText(earnCodeLookUp, "edit", hrEarnCodeId.toString());
90 Assert.assertTrue("Maintenance Page contains Test ",maintPage.asText().contains("RGN Test"));
91 HtmlTextInput text = (HtmlTextInput) maintPage.getHtmlElementById("document.documentHeader.documentDescription");
92 text.setValueAttribute("test");
93 HtmlElement element = maintPage.getElementByName("methodToCall.route");
94 HtmlPage finalPage = element.click();
95
96 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"));
97 HtmlElement yesButton = finalPage.getElementByName("methodToCall.processAnswer.button0");
98 finalPage = yesButton.click();
99 Assert.assertTrue("Maintenance Page contains error messages", finalPage.asText().contains("There is a newer version of this Earn Code."));
100 }
101
102 }