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