001 /** 002 * Copyright 2004-2014 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.core.kfs; 017 018 import static org.junit.Assert.assertNotNull; 019 import static org.junit.Assert.assertTrue; 020 021 import java.util.HashMap; 022 import java.util.Map; 023 import java.util.Map.Entry; 024 025 import org.junit.Test; 026 import org.kuali.hr.KPMEWebTestCase; 027 import org.kuali.hr.util.HtmlUnitUtil; 028 import org.kuali.kpme.core.util.HrTestConstants; 029 030 import com.gargoylesoftware.htmlunit.html.HtmlInput; 031 import com.gargoylesoftware.htmlunit.html.HtmlPage; 032 033 public class ChartMaintTest extends KPMEWebTestCase { 034 035 private String newUrl; 036 private String lookupUrl; 037 private Map<String,String> requiredFields; 038 039 private void before() { 040 newUrl = HrTestConstants.Urls.CHART_MAINT_NEW_URL; 041 lookupUrl = HrTestConstants.Urls.CHART_MAINT_URL; 042 043 requiredFields = new HashMap<String,String>(); 044 requiredFields.put("chartOfAccountsCode", "Chart Code (Chart) is a required field."); 045 requiredFields.put("finChartOfAccountDescription", "Chart Description (Description) is a required field."); 046 } 047 048 private void after() { 049 requiredFields.clear(); 050 } 051 052 @Test 053 public void testRequiredFields() throws Exception { 054 HtmlPage maintPage = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), newUrl); 055 assertNotNull("maintenance page is null", maintPage); 056 057 HtmlInput docDescription = HtmlUnitUtil.getInputContainingText(maintPage, "* Document Description"); 058 assertNotNull("maintenance page does not contain document description", docDescription); 059 060 docDescription.setValueAttribute("testing submission"); 061 062 HtmlPage resultPage = HtmlUnitUtil.clickInputContainingText(maintPage, "submit"); 063 assertNotNull("no result page returned after submit", resultPage); 064 065 String resultPageAsText = resultPage.asText(); 066 for(Entry<String,String> requiredField : requiredFields.entrySet()) { 067 assertTrue("page does not contain error message for required field: '" + requiredField.getKey() + "'", 068 resultPageAsText.contains(requiredField.getValue())); 069 } 070 } 071 072 @Test 073 public void testLookup() throws Exception { 074 HtmlPage lookupPage = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), lookupUrl); 075 assertNotNull("lookup page is null", lookupPage); 076 077 lookupPage = HtmlUnitUtil.clickInputContainingText(lookupPage, "search"); 078 assertNotNull("lookup result page is null", lookupPage); 079 080 } 081 082 @Override 083 public void setUp() throws Exception { 084 super.setUp(); 085 before(); 086 } 087 088 @Override 089 public void tearDown() throws Exception { 090 after(); 091 super.tearDown(); 092 } 093 }