001 /**
002 * Copyright 2004-2013 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.hr.time.earncode.validation;
017
018 import java.math.BigDecimal;
019 import java.sql.Date;
020 import java.util.List;
021
022 import org.joda.time.DateTime;
023 import org.junit.Assert;
024 import org.junit.Test;
025 import org.kuali.hr.test.KPMETestCase;
026 import org.kuali.hr.time.earncode.EarnCode;
027 import org.kuali.hr.time.test.HtmlUnitUtil;
028 import org.kuali.hr.time.test.TkTestConstants;
029 import org.kuali.hr.time.util.TKUtils;
030 import org.kuali.hr.time.util.TkConstants;
031 import org.kuali.rice.krad.service.KRADServiceLocator;
032
033 import com.gargoylesoftware.htmlunit.html.HtmlElement;
034 import com.gargoylesoftware.htmlunit.html.HtmlPage;
035 import com.gargoylesoftware.htmlunit.html.HtmlRadioButtonInput;
036 import com.gargoylesoftware.htmlunit.html.HtmlTextInput;
037
038 public class EarnCodeMaintenaceTest extends KPMETestCase {
039 private static final java.sql.Date TEST_DATE = new Date((new DateTime(2009, 1, 1, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone())).getMillis());
040 private static final String EARN_CODE = "RGN";
041 private static String hrEarnCodeId;
042
043 @Override
044 public void setUp() throws Exception {
045 super.setUp();
046 EarnCode earnCode = new EarnCode();
047 earnCode.setActive(true);
048 earnCode.setEarnCode(EARN_CODE);
049 earnCode.setEffectiveDate(TEST_DATE);
050 earnCode.setRecordMethod("T");
051 earnCode.setFractionalTimeAllowed("99");
052 earnCode.setRoundingOption("T");
053 earnCode.setAffectPay("Y");
054 earnCode.setWorkmansComp("Y");
055 earnCode.setEligibleForAccrual("Y");
056 earnCode.setAllowScheduledLeave("Y");
057 earnCode.setFmla("Y");
058 earnCode.setAllowNegativeAccrualBalance("Y");
059 earnCode.setDescription("RGN Test");
060 earnCode.setOvtEarnCode(false);
061 earnCode.setInflateMinHours(BigDecimal.ZERO);
062 earnCode.setInflateFactor(BigDecimal.ZERO);
063
064 KRADServiceLocator.getBusinessObjectService().save(earnCode);
065 hrEarnCodeId = earnCode.getHrEarnCodeId();
066 }
067
068 @Override
069 public void tearDown() throws Exception {
070 EarnCode earnCodeObj = KRADServiceLocator.getBusinessObjectService().findBySinglePrimaryKey(EarnCode.class, hrEarnCodeId);
071 KRADServiceLocator.getBusinessObjectService().delete(earnCodeObj);
072 super.tearDown();
073 }
074
075
076 @Test
077 public void testEditExistingEarnCode() throws Exception {
078 HtmlPage earnCodeLookUp = HtmlUnitUtil.gotoPageAndLogin(TkTestConstants.Urls.EARN_CODE_MAINT_URL);
079 List<HtmlElement> lstElements = earnCodeLookUp.getElementsByIdAndOrName("history");
080 for(HtmlElement e : lstElements) {
081 HtmlRadioButtonInput radioButton = (HtmlRadioButtonInput) e;
082 if(e.getAttribute("title").equals("Show History - Yes")) {
083 radioButton.setChecked(true); // set show history to yes
084 break;
085 }
086 }
087 earnCodeLookUp = HtmlUnitUtil.clickInputContainingText(earnCodeLookUp, "search");
088 Assert.assertTrue("Page contains test Earn Code", earnCodeLookUp.asText().contains("RGN Test"));
089 HtmlPage maintPage = HtmlUnitUtil.clickAnchorContainingText(earnCodeLookUp, "edit", hrEarnCodeId.toString());
090 Assert.assertTrue("Maintenance Page contains Test ",maintPage.asText().contains("RGN Test"));
091 HtmlTextInput text = (HtmlTextInput) maintPage.getHtmlElementById("document.documentHeader.documentDescription");
092 text.setValueAttribute("test");
093 HtmlElement element = maintPage.getElementByName("methodToCall.route");
094 HtmlPage finalPage = element.click();
095
096 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"));
097 HtmlElement yesButton = finalPage.getElementByName("methodToCall.processAnswer.button0");
098 finalPage = yesButton.click();
099 Assert.assertTrue("Maintenance Page contains error messages", finalPage.asText().contains("There is a newer version of this Earn Code."));
100 }
101
102 }