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 com.gargoylesoftware.htmlunit.html.HtmlElement;
19 import com.gargoylesoftware.htmlunit.html.HtmlPage;
20 import com.gargoylesoftware.htmlunit.html.HtmlRadioButtonInput;
21 import com.gargoylesoftware.htmlunit.html.HtmlTextInput;
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 java.math.BigDecimal;
34 import java.sql.Date;
35 import java.util.List;
36
37 public class EarnCodeMaintenaceTest extends KPMETestCase {
38 private static final java.sql.Date TEST_DATE = new Date((new DateTime(2009, 1, 1, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone())).getMillis());
39 private static final String EARN_CODE = "RGN";
40 private static String hrEarnCodeId;
41
42 @Override
43 public void setUp() throws Exception {
44 super.setUp();
45 EarnCode earnCode = new EarnCode();
46 earnCode.setActive(true);
47 earnCode.setEarnCode(EARN_CODE);
48 earnCode.setEffectiveDate(TEST_DATE);
49 earnCode.setRecordMethod("T");
50 earnCode.setDescription("RGN Test");
51 earnCode.setOvtEarnCode(false);
52 earnCode.setInflateMinHours(BigDecimal.ZERO);
53 earnCode.setInflateFactor(BigDecimal.ZERO);
54
55 KRADServiceLocator.getBusinessObjectService().save(earnCode);
56 hrEarnCodeId = earnCode.getHrEarnCodeId();
57 }
58
59 @Override
60 public void tearDown() throws Exception {
61 EarnCode earnCodeObj = KRADServiceLocator.getBusinessObjectService().findBySinglePrimaryKey(EarnCode.class, hrEarnCodeId);
62 KRADServiceLocator.getBusinessObjectService().delete(earnCodeObj);
63 super.tearDown();
64 }
65
66
67 @Test
68 public void testEditExistingEarnCode() throws Exception {
69 HtmlPage earnCodeLookUp = HtmlUnitUtil.gotoPageAndLogin(TkTestConstants.Urls.EARN_CODE_MAINT_URL);
70 List<HtmlElement> lstElements = earnCodeLookUp.getElementsByIdAndOrName("history");
71 for(HtmlElement e : lstElements) {
72 HtmlRadioButtonInput radioButton = (HtmlRadioButtonInput) e;
73 if(e.getAttribute("title").equals("Show History - Yes")) {
74 radioButton.setChecked(true);
75 break;
76 }
77 }
78 earnCodeLookUp = HtmlUnitUtil.clickInputContainingText(earnCodeLookUp, "search");
79 Assert.assertTrue("Page contains test Earn Code", earnCodeLookUp.asText().contains("RGN Test"));
80 HtmlPage maintPage = HtmlUnitUtil.clickAnchorContainingText(earnCodeLookUp, "edit", hrEarnCodeId.toString());
81 Assert.assertTrue("Maintenance Page contains Test ",maintPage.asText().contains("RGN Test"));
82 HtmlTextInput text = (HtmlTextInput) maintPage.getHtmlElementById("document.documentHeader.documentDescription");
83 text.setValueAttribute("test");
84 HtmlElement element = maintPage.getElementByName("methodToCall.route");
85 HtmlPage finalPage = element.click();
86
87 Assert.assertTrue("Maintenance Page contains error messages", finalPage.asText().contains("There is a newer version of this Earn Code."));
88 }
89
90 }