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.paygrade.validation;
017    
018    import junit.framework.Assert;
019    
020    import org.junit.Test;
021    import org.kuali.hr.test.KPMETestCase;
022    import org.kuali.hr.time.test.HtmlUnitUtil;
023    import org.kuali.hr.time.test.TkTestConstants;
024    
025    import com.gargoylesoftware.htmlunit.html.HtmlElement;
026    import com.gargoylesoftware.htmlunit.html.HtmlForm;
027    import com.gargoylesoftware.htmlunit.html.HtmlInput;
028    import com.gargoylesoftware.htmlunit.html.HtmlPage;
029    
030    public class PayGradeValidationTest extends KPMETestCase{
031            @Test
032            public void testValidateSalGroup() throws Exception {
033                    String baseUrl = TkTestConstants.Urls.PAY_GRADE_MAINT_NEW_URL;
034                    HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), baseUrl);
035                    Assert.assertNotNull(page);
036             
037                    HtmlForm form = page.getFormByName("KualiForm");
038                    Assert.assertNotNull("Search form was missing from page.", form);
039                    
040                    setFieldValue(page, "document.documentHeader.documentDescription", "Pay Grade - test");
041                setFieldValue(page, "document.newMaintainableObject.effectiveDate", "04/01/2012");
042                setFieldValue(page, "document.newMaintainableObject.payGrade", "test");
043                setFieldValue(page, "document.newMaintainableObject.salGroup", "testSG");   //nonexisting salary group
044                setFieldValue(page, "document.newMaintainableObject.description", "test");  
045                    
046                    HtmlInput  input  = HtmlUnitUtil.getInputContainingText(form, "methodToCall.route");
047                    Assert.assertNotNull("Could not locate submit button", input);
048                    HtmlElement element = page.getElementByName("methodToCall.route");
049                    page = element.click();
050                    HtmlUnitUtil.createTempFile(page);
051                    Assert.assertTrue("page text contains:\n" + "'testSG' does not exist", page.asText().contains("'testSG' does not exist"));
052                    
053                    setFieldValue(page, "document.newMaintainableObject.salGroup", "SD1");  //existing salary group
054                    element = page.getElementByName("methodToCall.route");
055                    page = element.click();
056                    Assert.assertFalse("page text contains: error", page.asText().contains("error"));
057                    Assert.assertTrue("New Pay grade successfully submitted.", page.asText().contains("Document was successfully submitted"));
058            }
059            
060    }