View Javadoc

1   /**
2    * Copyright 2004-2013 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.time.web.lookup;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.junit.Assert;
20  import org.junit.Test;
21  import org.kuali.hr.test.KPMETestCase;
22  import org.kuali.hr.time.test.HtmlUnitUtil;
23  
24  import com.gargoylesoftware.htmlunit.html.HtmlForm;
25  import com.gargoylesoftware.htmlunit.html.HtmlInput;
26  import com.gargoylesoftware.htmlunit.html.HtmlPage;
27  
28  public class ClockLocationRuleLookupTest extends KPMETestCase {
29  
30      @Test
31      public void testLookup() throws Exception{
32      	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";
33      	HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(baseUrl);
34      	Assert.assertNotNull(page);
35      	Assert.assertTrue("Could not find text 'Clock Location Rule Lookup' in page.", StringUtils.contains(page.asText(), "Clock Location Rule Lookup"));
36      	HtmlForm form = page.getFormByName("KualiForm");
37      	Assert.assertNotNull("Search form was missing from page.", form);
38      	
39      	HtmlInput  input  = HtmlUnitUtil.getInputContainingText(form, "methodToCall.search");
40      	Assert.assertNotNull("Could not locate search submit button", input);
41      	page = (HtmlPage) input.click();
42      	Assert.assertNotNull("Page not returned from click.", page);
43      	HtmlUnitUtil.createTempFile(page);
44      	Assert.assertTrue("Expected one result.", StringUtils.contains(page.asText(), "One item retrieved"));
45      	
46      	page = HtmlUnitUtil.gotoPageAndLogin(baseUrl);
47      	form = page.getFormByName("KualiForm");
48      	Assert.assertNotNull("Search form was missing from page.", form);
49      	HtmlUnitUtil.createTempFile(page);
50      	form.getInputByName("dept").setValueAttribute("20");
51      	input  = HtmlUnitUtil.getInputContainingText(form, "methodToCall.search");
52      	Assert.assertNotNull("Could not locate search submit button", input);
53      	page = (HtmlPage) input.click();
54      	Assert.assertNotNull("Page not returned from click.", page);
55      	Assert.assertTrue("Expected zero results.", StringUtils.contains(page.asText(), "No values match this search."));
56      }
57  
58  }