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 com.gargoylesoftware.htmlunit.html.HtmlElement;
019    import com.gargoylesoftware.htmlunit.html.HtmlPage;
020    import com.gargoylesoftware.htmlunit.html.HtmlRadioButtonInput;
021    import com.gargoylesoftware.htmlunit.html.HtmlTextInput;
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 java.math.BigDecimal;
034    import java.sql.Date;
035    import java.util.List;
036    
037    public class EarnCodeMaintenaceTest extends KPMETestCase {
038            private static final java.sql.Date TEST_DATE = new Date((new DateTime(2009, 1, 1, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone())).getMillis());
039            private static final String EARN_CODE = "RGN";
040            private static String hrEarnCodeId;
041    
042            @Override
043            public void setUp() throws Exception {
044                    super.setUp();
045                    EarnCode earnCode = new EarnCode();
046                    earnCode.setActive(true);
047                    earnCode.setEarnCode(EARN_CODE);
048                    earnCode.setEffectiveDate(TEST_DATE);
049                    earnCode.setRecordMethod("T");
050                    earnCode.setDescription("RGN Test");
051                    earnCode.setOvtEarnCode(false);
052                    earnCode.setInflateMinHours(BigDecimal.ZERO);
053                    earnCode.setInflateFactor(BigDecimal.ZERO);
054    
055                    KRADServiceLocator.getBusinessObjectService().save(earnCode);   
056                    hrEarnCodeId = earnCode.getHrEarnCodeId();
057            }
058    
059            @Override
060            public void tearDown() throws Exception {
061                    EarnCode earnCodeObj = KRADServiceLocator.getBusinessObjectService().findBySinglePrimaryKey(EarnCode.class, hrEarnCodeId);
062                    KRADServiceLocator.getBusinessObjectService().delete(earnCodeObj);                              
063                    super.tearDown();
064            }
065    
066    
067            @Test
068            public void testEditExistingEarnCode() throws Exception {
069                    HtmlPage earnCodeLookUp = HtmlUnitUtil.gotoPageAndLogin(TkTestConstants.Urls.EARN_CODE_MAINT_URL);
070                    List<HtmlElement> lstElements = earnCodeLookUp.getElementsByIdAndOrName("history");
071                    for(HtmlElement e : lstElements) {
072                            HtmlRadioButtonInput radioButton = (HtmlRadioButtonInput) e;
073                            if(e.getAttribute("title").equals("Show History - Yes")) {
074                                    radioButton.setChecked(true);   // set show history to yes
075                                    break;
076                            }
077                    }
078                    earnCodeLookUp = HtmlUnitUtil.clickInputContainingText(earnCodeLookUp, "search");
079                    Assert.assertTrue("Page contains test Earn Code", earnCodeLookUp.asText().contains("RGN Test"));                
080                    HtmlPage maintPage = HtmlUnitUtil.clickAnchorContainingText(earnCodeLookUp, "edit", hrEarnCodeId.toString());
081                    Assert.assertTrue("Maintenance Page contains Test ",maintPage.asText().contains("RGN Test"));
082                    HtmlTextInput text  = (HtmlTextInput) maintPage.getHtmlElementById("document.documentHeader.documentDescription");
083                    text.setValueAttribute("test");
084                    HtmlElement element = maintPage.getElementByName("methodToCall.route");
085            HtmlPage finalPage = element.click();
086            
087            Assert.assertTrue("Maintenance Page contains error messages", finalPage.asText().contains("There is a newer version of this Earn Code."));      
088            }
089    
090    }