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.core.institution;
17  
18  import static org.junit.Assert.assertNotNull;
19  import static org.junit.Assert.assertTrue;
20  
21  import java.util.HashMap;
22  import java.util.Map;
23  import java.util.Map.Entry;
24  
25  import org.junit.Test;
26  import org.kuali.hr.KPMEWebTestCase;
27  import org.kuali.hr.util.HtmlUnitUtil;
28  import org.kuali.kpme.core.util.HrTestConstants;
29  
30  import com.gargoylesoftware.htmlunit.html.HtmlInput;
31  import com.gargoylesoftware.htmlunit.html.HtmlPage;
32  
33  public class InstitutionMaintenanceTest extends KPMEWebTestCase {
34  
35  	private static String newUrl;
36  	private static String lookupUrl;
37  	private static Map<String,String> requiredFields;
38  
39  	private void before() {
40  		
41  		newUrl = HrTestConstants.Urls.INSTITUTION_MAINT_NEW_URL;
42  		lookupUrl = HrTestConstants.Urls.INSTITUTION_MAINT_URL;
43  		
44  		requiredFields = new HashMap<String,String>();
45  		requiredFields.put("effectiveDate", "Effective Date (Effective Date) is a required field.");
46  		requiredFields.put("institutionCode", "Institution Code (Institution Code) is a required field.");
47  	}
48  	
49  	private void after() {
50  		requiredFields.clear();
51  	}
52  	
53  	@Override
54  	public void setUp() throws Exception {
55  		before();
56  		super.setUp();
57  	}
58  	
59  	@Override
60  	public void tearDown() throws Exception {
61  		after();
62  		super.tearDown();
63  	}
64  	
65  	@Test
66  	public void testRequiredFields() throws Exception {
67  		HtmlPage maintPage = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), newUrl);
68  		assertNotNull("maintenance page is null", maintPage);
69  		
70  		HtmlInput docDescription = HtmlUnitUtil.getInputContainingText(maintPage, "* Document Description");
71  		assertNotNull("maintenance page does not contain document description", docDescription);
72  		
73  		docDescription.setValueAttribute("testing submission");
74  		
75  		HtmlPage resultPage = HtmlUnitUtil.clickInputContainingText(maintPage, "submit");
76  		assertNotNull("no result page returned after submit", resultPage);
77  		
78  		String resultPageAsText = resultPage.asText();
79  		for(Entry<String,String> requiredField : requiredFields.entrySet()) {
80  			assertTrue("page does not contain error message for required field: '" + requiredField.getKey() + "'",
81  					resultPageAsText.contains(requiredField.getValue()));
82  		}
83  	}
84  	
85  	@Test
86  	public void testLookup() throws Exception {
87  		HtmlPage lookupPage = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), lookupUrl);
88  		assertNotNull("lookup page is null", lookupPage);
89  		
90  		lookupPage = HtmlUnitUtil.clickInputContainingText(lookupPage, "search");
91  		assertNotNull("lookup result page is null", lookupPage);
92  		
93  	}
94  	
95  }