View Javadoc
1   /**
2    * Copyright 2004-2014 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.pm.positionreportsubcat;
17  
18  import junit.framework.Assert;
19  
20  import org.junit.Test;
21  import org.kuali.hr.KPMEWebTestCase;
22  import org.kuali.hr.util.HtmlUnitUtil;
23  import org.kuali.kpme.core.FunctionalTest;
24  import org.kuali.kpme.pm.api.positionreportsubcat.PositionReportSubCategoryContract;
25  import org.kuali.kpme.pm.positionreportsubcat.PositionReportSubCategoryBo;
26  import org.kuali.kpme.pm.service.base.PmServiceLocator;
27  import org.kuali.kpme.pm.utils.PmTestConstants;
28  
29  import com.gargoylesoftware.htmlunit.html.HtmlElement;
30  import com.gargoylesoftware.htmlunit.html.HtmlForm;
31  import com.gargoylesoftware.htmlunit.html.HtmlInput;
32  import com.gargoylesoftware.htmlunit.html.HtmlPage;
33  
34  @FunctionalTest
35  public class PositionReportSubCatMaintTest extends KPMEWebTestCase {
36  
37  	@Test
38  	public void testRequiredFields() throws Exception {
39          //KPME-3086: converted Position Report Sub Category to KRAD which broke these tests,
40          //need TODO: rewrite this code once KRAD web tests are developed
41          /*
42  	  	String baseUrl = PmTestConstants.Urls.POSITION_REPORT_SUB_CAT_MAINT_NEW_URL;
43  	  	HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), baseUrl);
44  	  	Assert.assertNotNull(page);
45  	 
46  	  	HtmlForm form = page.getFormByName("KualiForm");
47  	  	Assert.assertNotNull("Search form was missing from page.", form);
48  	  	
49  	  	HtmlInput  input  = HtmlUnitUtil.getInputContainingText(form, "methodToCall.route");
50  	  	Assert.assertNotNull("Could not locate submit button", input);
51  	  	
52  	  	HtmlElement element = page.getElementByName("methodToCall.route");
53  	  	page = element.click();
54  	  	Assert.assertTrue("page text does not contain:\n" + "Effective Date (Effective Date) is a required field.", 
55  	  			page.asText().contains("Effective Date (Effective Date) is a required field."));
56  	  	Assert.assertTrue("page text does not contain:\n" + "Position Report Sub Category (Position Report Sub Category) is a required field.", 
57  	  			page.asText().contains("Position Report Sub Category (Position Report Sub Category) is a required field."));
58  	  	Assert.assertTrue("page text does not contain:\n" + "Position Report Category (Position Report Category) is a required field.", 
59  	  			page.asText().contains("Position Report Category (Position Report Category) is a required field."));
60  	  	Assert.assertTrue("page text does not contain:\n" + "Position Report Type (Position Report Type) is a required field.", 
61  	  			page.asText().contains("Position Report Type (Position Report Type) is a required field."));
62  	  	Assert.assertTrue("page text does not contain:\n" + "Institution (Institution) is a required field.",
63  	  			page.asText().contains("Institution (Institution) is a required field."));
64  	  	Assert.assertTrue("page text does not contain:\n" + "Location (Location) is a required field.", 
65  	  			page.asText().contains("Location (Location) is a required field."));
66  	}
67  	
68  	@Test
69  	public void testAddNew() throws Exception {
70  		String prscString = "testPRSC";
71  		PositionReportSubCategoryContract prsc = PmServiceLocator.getPositionReportSubCatService().getPositionReportSubCatById("1000");
72  		Assert.assertTrue("There should NOT be Position Report Sub Category with name " + prscString, prsc == null);
73  		
74  	  	String baseUrl = PmTestConstants.Urls.POSITION_REPORT_SUB_CAT_MAINT_NEW_URL;
75  	  	HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), baseUrl);
76  	  	Assert.assertNotNull(page);
77  	 
78  	  	HtmlForm form = page.getFormByName("KualiForm");
79  	  	Assert.assertNotNull("Search form was missing from page.", form);
80  	  	
81  	  	HtmlUnitUtil.setFieldValue(page, "document.documentHeader.documentDescription", "Position Report Category - test");
82  	    HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.effectiveDate", "04/01/2012");
83  	    HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.positionReportSubCat", prscString);
84  //	    HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.positionReportCat", "nonCat");	// non-existing PositionReportCategory
85  //	    HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.positionReportType.div", "testPRT"); 
86  	    HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.institution", "nonExistInst");	//nonexisting institution
87  	    HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.location", "nonCam");	//nonexisting location
88  	  	
89  	  	HtmlInput  input  = HtmlUnitUtil.getInputContainingText(form, "methodToCall.route");
90  	  	Assert.assertNotNull("Could not locate submit button", input);
91  	  	HtmlElement element = page.getElementByName("methodToCall.route");
92  	  	page = element.click();
93  	  	HtmlUnitUtil.createTempFile(page);
94  		Assert.assertTrue("page text contains:\n" + "The specified Instituion 'nonExistInst' does not exist.", 
95  	  			page.asText().contains("The specified Instituion 'nonExistInst' does not exist."));
96  	  	Assert.assertTrue("page text contains:\n" + "The specified Location 'nonCam' does not exist.", 
97  	  			page.asText().contains("The specified Location 'nonCam' does not exist."));
98  
99  	  	HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.institution", "testInst"); // matching institution	  	
100 	  	HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.location", "BL"); // matching Location
101 	  	element = page.getElementByName("methodToCall.route");
102 	  	page = element.click();
103 	  	Assert.assertFalse("page text should NOT contain:\n" + "The specified Instituion 'nonExistInst' does not exist.", 
104 	  			page.asText().contains("The specified Instituion 'nonExistInst' does not exist."));
105 	  	Assert.assertFalse("page text should NOT contain:\n" + "The specified Location 'nonCam' does not exist.", 
106 	  			page.asText().contains("The specified Location 'nonCam' does not exist."));
107 	*/
108 	}
109 
110 }