001/** 002 * Copyright 2004-2015 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 */ 016package org.kuali.hr.core.institution; 017 018import org.junit.Assert; 019import org.junit.Test; 020import org.kuali.hr.KPMEWebTestCase; 021import org.kuali.hr.util.HtmlUnitUtil; 022import org.kuali.kpme.core.FunctionalTest; 023import org.kuali.kpme.core.util.HrTestConstants; 024 025import com.gargoylesoftware.htmlunit.html.HtmlAnchor; 026import com.gargoylesoftware.htmlunit.html.HtmlElement; 027import com.gargoylesoftware.htmlunit.html.HtmlForm; 028import com.gargoylesoftware.htmlunit.html.HtmlInput; 029import com.gargoylesoftware.htmlunit.html.HtmlPage; 030 031@FunctionalTest 032public class InstitutionMaintTest extends KPMEWebTestCase { 033 034 private static final String INST_CODE = "SOME-CODE"; 035 036 @Override 037 public void setUp() throws Exception { 038 super.setUp(); 039 } 040 041 @Override 042 public void tearDown() throws Exception { 043 super.tearDown(); 044 } 045 046 @Test 047 public void testRequiredFields() throws Exception { 048 String baseUrl = HrTestConstants.Urls.INSTITUTION_MAINT_NEW_URL; 049 HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), baseUrl); 050 Assert.assertNotNull(page); 051 052 HtmlForm form = page.getFormByName("KualiForm"); 053 Assert.assertNotNull("Search form was missing from page.", form); 054 055 HtmlInput input = HtmlUnitUtil.getInputContainingText(form, "methodToCall.route"); 056 Assert.assertNotNull("Could not locate submit button", input); 057 058 HtmlElement element = page.getElementByName("methodToCall.route"); 059 page = element.click(); 060 Assert.assertTrue("page text does not contain:\n" + "Effective Date (Effective Date) is a required field.", 061 page.asText().contains("Effective Date (Effective Date) is a required field.")); 062 Assert.assertTrue("page text does not contain:\n" + "Institution Code (Institution Code) is a required field.", 063 page.asText().contains("Institution Code (Institution Code) is a required field.")); 064 065 } 066 067 @Test 068 public void testLookup() throws Exception { 069 String baseUrl = HrTestConstants.Urls.INSTITUTION_MAINT_URL; 070 HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), baseUrl); 071 Assert.assertNotNull(page); 072 073 HtmlForm form = page.getFormByName("KualiForm"); 074 Assert.assertNotNull("Search form was missing from page.", form); 075 076 Assert.assertNotNull("form should have show history", form.getInputByName("history")); 077 078 Assert.assertNotNull("form should have active field", form.getInputByName("active")); 079 080 Assert.assertNotNull("form should have institution code", form.getInputByName("institutionCode")); 081 Assert.assertNotNull("form should have effectiveDateTo", form.getInputByName("effectiveDate")); 082 HtmlInput input = HtmlUnitUtil.getInputContainingText(form, "search"); 083 Assert.assertNotNull("search input not found", input); 084 085 HtmlPage resultPage = input.click(); 086 087 Assert.assertTrue("page text does not contain institution", 088 resultPage.asText().contains(INST_CODE)); 089 090 HtmlAnchor viewAnchor = resultPage.getAnchorByText("view"); 091 Assert.assertNotNull("no 'view' anchor found", viewAnchor); 092 093 HtmlAnchor editAnchor = resultPage.getAnchorByText("edit"); 094 Assert.assertNotNull("no 'edit' anchor found", editAnchor); 095 } 096 097}