001 /**
002 * Copyright 2004-2012 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 java.sql.Date;
019 import java.util.HashMap;
020
021 import org.apache.commons.lang.StringUtils;
022 import org.joda.time.DateTime;
023 import org.joda.time.DateTimeZone;
024 import org.junit.Assert;
025 import org.junit.Before;
026 import org.junit.Test;
027 import org.kuali.hr.test.KPMETestCase;
028 import org.kuali.hr.time.clock.location.ClockLocationRule;
029 import org.kuali.hr.time.test.HtmlUnitUtil;
030 import org.kuali.hr.time.util.TKUtils;
031 import org.kuali.rice.krad.service.BusinessObjectService;
032 import org.kuali.rice.krad.service.KRADServiceLocator;
033
034 import com.gargoylesoftware.htmlunit.html.HtmlForm;
035 import com.gargoylesoftware.htmlunit.html.HtmlInput;
036 import com.gargoylesoftware.htmlunit.html.HtmlPage;
037
038 public class ClockLocationRuleLookupTest extends KPMETestCase {
039
040 private static BusinessObjectService boService = null;
041
042 /**
043 * Load some data to find for all of the tests in this test collection.
044 */
045
046 @Before
047 public void setUp() throws Exception {
048 super.setUp();
049 boService = KRADServiceLocator.getBusinessObjectService();
050 clearBusinessObjects(ClockLocationRule.class);
051
052 ClockLocationRule clr = new ClockLocationRule();
053 clr.setActive(true);
054 clr.setDept("12345");
055 Date asOfDate = new Date((new DateTime(2010, 8, 1, 12, 0, 0, 0, TKUtils.getSystemDateTimeZone())).getMillis());
056 clr.setEffectiveDate(asOfDate);
057 boService.save(clr);
058 }
059
060
061
062 @Test
063 public void testLookup() throws Exception{
064 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";
065 HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(baseUrl);
066 Assert.assertNotNull(page);
067 Assert.assertTrue("Could not find text 'Clock Location Rule Lookup' in page.", StringUtils.contains(page.asText(), "Clock Location Rule Lookup"));
068 HtmlForm form = page.getFormByName("KualiForm");
069 Assert.assertNotNull("Search form was missing from page.", form);
070
071 HtmlInput input = HtmlUnitUtil.getInputContainingText(form, "methodToCall.search");
072 Assert.assertNotNull("Could not locate search submit button", input);
073 page = (HtmlPage) input.click();
074 Assert.assertNotNull("Page not returned from click.", page);
075 HtmlUnitUtil.createTempFile(page);
076 Assert.assertTrue("Expected one result.", StringUtils.contains(page.asText(), "One item retrieved"));
077
078 page = HtmlUnitUtil.gotoPageAndLogin(baseUrl);
079 form = page.getFormByName("KualiForm");
080 Assert.assertNotNull("Search form was missing from page.", form);
081 HtmlUnitUtil.createTempFile(page);
082 form.getInputByName("dept").setValueAttribute("20");
083 input = HtmlUnitUtil.getInputContainingText(form, "methodToCall.search");
084 Assert.assertNotNull("Could not locate search submit button", input);
085 page = (HtmlPage) input.click();
086 Assert.assertNotNull("Page not returned from click.", page);
087 Assert.assertTrue("Expected zero results.", StringUtils.contains(page.asText(), "No values match this search."));
088 }
089
090 @SuppressWarnings("unchecked")
091 public static void clearBusinessObjects(Class clazz) {
092 boService.deleteMatching(clazz, new HashMap());
093 }
094
095
096
097 @Override
098 public void tearDown() throws Exception {
099 clearBusinessObjects(ClockLocationRule.class);
100 super.tearDown();
101 }
102 }