View Javadoc

1   /**
2    * Copyright 2004-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.hr.core.paygrade.validation;
17  
18  import java.util.List;
19  
20  import junit.framework.Assert;
21  
22  import org.apache.commons.lang.StringUtils;
23  import org.junit.Ignore;
24  import org.junit.Test;
25  import org.kuali.hr.KPMEWebTestCase;
26  import org.kuali.hr.util.HtmlUnitUtil;
27  import org.kuali.kpme.core.FunctionalTest;
28  import org.kuali.kpme.core.util.HrTestConstants;
29  
30  import com.gargoylesoftware.htmlunit.html.FrameWindow;
31  import com.gargoylesoftware.htmlunit.html.HtmlAnchor;
32  import com.gargoylesoftware.htmlunit.html.HtmlElement;
33  import com.gargoylesoftware.htmlunit.html.HtmlForm;
34  import com.gargoylesoftware.htmlunit.html.HtmlInput;
35  import com.gargoylesoftware.htmlunit.html.HtmlPage;
36  
37  @FunctionalTest
38  public class PayGradeValidationTest extends KPMEWebTestCase {
39  	@Ignore
40  	@Test
41  	public void testValidateSalGroup() throws Exception {
42          String baseUrl = HrTestConstants.Urls.PAY_GRADE_MAINT_NEW_URL;
43          HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), HrTestConstants.BASE_URL, true);
44          page = HtmlUnitUtil.clickAnchorContainingText(page,"Maintenance");
45          HtmlUnitUtil.createTempFile(page);
46          page = HtmlUnitUtil.clickAnchorContainingText(page,"Pay Grade");
47          HtmlUnitUtil.createTempFile(page);
48          List<HtmlAnchor> anchors = page.getAnchors();
49          List<FrameWindow> frames = page.getFrames();
50          for (FrameWindow frame : frames) {
51              if (StringUtils.equals(frame.getName(), "iframeportlet")) {
52                 page = frame.getEnclosingPage();
53              }
54          }
55          page.initialize();
56          page = HtmlUnitUtil.clickAnchorContainingText(page,"Create");
57          
58          HtmlUnitUtil.createTempFile(page);
59          page.initialize();
60          Assert.assertNotNull(page);
61          frames = page.getFrames();
62          for (FrameWindow frame : frames) {
63              if (StringUtils.equals(frame.getName(), "iframeportlet")) {
64                 page = frame.getEnclosingPage();
65              }
66          }
67          HtmlForm form = (HtmlForm) page.getElementById("kualiForm");
68  //        List<HtmlForm> forms = page.getDocumentElement().getElementsByAttribute("form", "id", "kualiForm");
69  //            if (forms.size() == 0) {
70  //                throw new ElementNotFoundException("form", "id", "kualiForm");
71  //                } else {
72  //                form = forms.get(0);
73  //            }
74          Assert.assertNotNull("Search form was missing from page.", form);
75  	  	
76  	  	HtmlUnitUtil.setFieldValue(page, "document.documentHeader.documentDescription", "Pay Grade - test");
77  	    HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.effectiveDate", "04/01/2012");
78  	    HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.payGrade", "test");
79  	    HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.salGroup", "testSG");	//nonexisting salary group
80  	    HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.description", "test");	
81  	  	
82  	  	HtmlInput  input  = HtmlUnitUtil.getInputContainingText(form, "methodToCall.route");
83  	  	Assert.assertNotNull("Could not locate submit button", input);
84  	  	HtmlElement element = page.getElementByName("methodToCall.route");
85  	  	page = element.click();
86  	  	HtmlUnitUtil.createTempFile(page);
87  	  	Assert.assertTrue("page text contains:\n" + "'testSG' does not exist", page.asText().contains("'testSG' does not exist"));
88  	  	
89  	  	HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.salGroup", "SD1");	//existing salary group
90  	  	element = page.getElementByName("methodToCall.route");
91  	  	page = element.click();
92  	  	Assert.assertFalse("page text contains: error", page.asText().contains("error"));
93  	  	Assert.assertTrue("New Pay grade successfully submitted.", page.asText().contains("Document was successfully submitted"));
94  	}
95  	
96  }