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.positionreportcat;
17  
18  import java.util.List;
19  
20  import junit.framework.Assert;
21  
22  import org.apache.commons.collections.CollectionUtils;
23  import org.joda.time.DateTime;
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.TKUtils;
29  import org.kuali.kpme.pm.positionreportcat.PositionReportCategory;
30  import org.kuali.kpme.pm.service.base.PmServiceLocator;
31  import org.kuali.kpme.pm.utils.PmTestConstants;
32  
33  import com.gargoylesoftware.htmlunit.html.HtmlElement;
34  import com.gargoylesoftware.htmlunit.html.HtmlForm;
35  import com.gargoylesoftware.htmlunit.html.HtmlInput;
36  import com.gargoylesoftware.htmlunit.html.HtmlPage;
37  
38  @FunctionalTest
39  public class PositionReportCatMaintTest extends KPMEWebTestCase {
40  	
41  	@Test
42  	public void testRequiredFields() throws Exception {
43  	  	String baseUrl = PmTestConstants.Urls.POSITION_REPORT_CAT_MAINT_NEW_URL;
44  	  	HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), baseUrl);
45  	  	Assert.assertNotNull(page);
46  	 
47  	  	HtmlForm form = page.getFormByName("KualiForm");
48  	  	Assert.assertNotNull("Search form was missing from page.", form);
49  	  	
50  	  	HtmlInput  input  = HtmlUnitUtil.getInputContainingText(form, "methodToCall.route");
51  	  	Assert.assertNotNull("Could not locate submit button", input);
52  	  	
53  	  	HtmlElement element = page.getElementByName("methodToCall.route");
54  	  	page = element.click();
55  	  	Assert.assertTrue("page text does not contain:\n" + "Effective Date (Effective Date) is a required field.", 
56  	  			page.asText().contains("Effective Date (Effective Date) is a required field."));
57  	  	Assert.assertTrue("page text does not contain:\n" + "Position Report Category (Position Report Category) is a required field.", 
58  	  			page.asText().contains("Position Report Category (Position Report Category) is a required field."));
59  	  	Assert.assertTrue("page text does not contain:\n" + "Position Report Type (Position Report Type) is a required field.", 
60  	  			page.asText().contains("Position Report Type (Position Report Type) is a required field."));
61  	  	Assert.assertTrue("page text does not contain:\n" + "Institution (Institution) is a required field.",
62  	  			page.asText().contains("Institution (Institution) is a required field."));
63  	  	Assert.assertTrue("page text does not contain:\n" + "Location (Location) is a required field.", 
64  	  			page.asText().contains("Location (Location) is a required field."));
65  	}
66  	
67  	@Test
68  	public void testAddNew() throws Exception {
69  		DateTime effectiveDate =  new DateTime(2012, 4, 1, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone());
70  		String prcString = "testPRC";
71  		String prtString = "testPRT";
72  		List<PositionReportCategory> prcList = PmServiceLocator.getPositionReportCatService().getPositionReportCatList(prcString, prtString, "testInst", "TS", effectiveDate.toLocalDate());
73  		Assert.assertTrue("There should NOT be Position Report Category with name " + prcString, CollectionUtils.isEmpty(prcList));
74  		
75  	  	String baseUrl = PmTestConstants.Urls.POSITION_REPORT_CAT_MAINT_NEW_URL;
76  	  	HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), baseUrl);
77  	  	Assert.assertNotNull(page);
78  	 
79  	  	HtmlForm form = page.getFormByName("KualiForm");
80  	  	Assert.assertNotNull("Search form was missing from page.", form);
81  	  	
82  	  	HtmlUnitUtil.setFieldValue(page, "document.documentHeader.documentDescription", "Position Report Category - test");
83  	    HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.effectiveDate", "04/01/2012");
84  	    HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.positionReportCat", prcString);
85  	    HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.positionReportType", "noType"); // non-existing positionReportType
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  	  	Assert.assertTrue("page text contains:\n" + "The specified PositionReportType 'noType' does not exist.", 
99  	  			page.asText().contains("The specified PositionReportType 'noType' does not exist."));
100 	  	
101 	  	HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.positionReportType", prtString); // postionReportType and location do not match
102 	  	HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.location", "NN"); // existing, non-matching location
103 	  	element = page.getElementByName("methodToCall.route");
104 	  	page = element.click();
105 	  	Assert.assertFalse("page text contains:\n" + "The specified Location 'NN' does not exist.", 
106 	  			page.asText().contains("The specified Locaiton 'NN' does not exist."));
107 		Assert.assertTrue("page text contains:\n" + "Institution 'nonExistInst' is inconsistent with institution 'testInst' of PositionReportType 'testPRT'", 
108 	  			page.asText().contains("Institution 'nonExistInst' is inconsistent with institution 'testInst' of PositionReportType 'testPRT'"));
109 	  	
110 	  	HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.institution", "II"); // existing, non-matching institution
111 	  	element = page.getElementByName("methodToCall.route");
112 	  	page = element.click();
113 	  	Assert.assertTrue("page text contains:\n" + "Institution 'II' is inconsistent with institution 'testInst' of PositionReportType 'testPRT'", 
114 	  			page.asText().contains("Institution 'II' is inconsistent with institution 'testInst' of PositionReportType 'testPRT'"));
115 	  	Assert.assertFalse("page text contains:\n" + "The specified Instituion 'II' does not exist.", 
116 	  			page.asText().contains("The specified Instituion 'II' does not exist."));
117 	  	
118 	  	HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.institution", "testInst"); // matching institution	  	
119 	  	HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.location", "BL"); // matching location
120 	  	element = page.getElementByName("methodToCall.route");
121 	  	page = element.click();
122 	  	Assert.assertFalse("page text contains error", page.asText().contains("error"));
123 	  	
124 	  	prcList = PmServiceLocator.getPositionReportCatService().getPositionReportCatList(prcString, prtString, "testInst", "BL", effectiveDate.toLocalDate());
125 	  	Assert.assertTrue("There should be Position Report Category with name " + prcString, CollectionUtils.isNotEmpty(prcList));
126 	  	
127 	}
128 }