001 /** 002 * Copyright 2004-2013 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.time.web.lookup; 017 018 import org.apache.commons.lang.StringUtils; 019 import org.junit.Assert; 020 import org.junit.Test; 021 import org.kuali.hr.test.KPMETestCase; 022 import org.kuali.hr.time.test.HtmlUnitUtil; 023 024 import com.gargoylesoftware.htmlunit.html.HtmlForm; 025 import com.gargoylesoftware.htmlunit.html.HtmlInput; 026 import com.gargoylesoftware.htmlunit.html.HtmlPage; 027 028 public class ClockLocationRuleLookupTest extends KPMETestCase { 029 030 @Test 031 public void testLookup() throws Exception{ 032 String baseUrl = HtmlUnitUtil.getBaseURL() + "/kr/lookup.do?__login_user=admin&methodToCall=start&businessObjectClassName=org.kuali.hr.time.clock.location.ClockLocationRule&returnLocation=" + HtmlUnitUtil.getBaseURL() + "/portal.do&hideReturnLink=true&docFormKey=88888888"; 033 HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), baseUrl); 034 Assert.assertNotNull(page); 035 Assert.assertTrue("Could not find text 'Clock Location Rule Lookup' in page.", StringUtils.contains(page.asText(), "Clock Location Rule Lookup")); 036 HtmlForm form = page.getFormByName("KualiForm"); 037 Assert.assertNotNull("Search form was missing from page.", form); 038 039 HtmlInput input = HtmlUnitUtil.getInputContainingText(form, "methodToCall.search"); 040 Assert.assertNotNull("Could not locate search submit button", input); 041 page = (HtmlPage) input.click(); 042 Assert.assertNotNull("Page not returned from click.", page); 043 HtmlUnitUtil.createTempFile(page); 044 Assert.assertTrue("Expected one result.", StringUtils.contains(page.asText(), "One item retrieved")); 045 046 page = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), baseUrl); 047 form = page.getFormByName("KualiForm"); 048 Assert.assertNotNull("Search form was missing from page.", form); 049 HtmlUnitUtil.createTempFile(page); 050 form.getInputByName("dept").setValueAttribute("20"); 051 input = HtmlUnitUtil.getInputContainingText(form, "methodToCall.search"); 052 Assert.assertNotNull("Could not locate search submit button", input); 053 page = (HtmlPage) input.click(); 054 Assert.assertNotNull("Page not returned from click.", page); 055 Assert.assertTrue("Expected zero results.", StringUtils.contains(page.asText(), "No values match this search.")); 056 } 057 058 }