1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.time.web.lookup;
17
18 import java.sql.Date;
19 import java.util.HashMap;
20
21 import org.apache.commons.lang.StringUtils;
22 import org.joda.time.DateTime;
23 import org.joda.time.DateTimeZone;
24 import org.junit.Assert;
25 import org.junit.Before;
26 import org.junit.Test;
27 import org.kuali.hr.test.KPMETestCase;
28 import org.kuali.hr.time.clock.location.ClockLocationRule;
29 import org.kuali.hr.time.test.HtmlUnitUtil;
30 import org.kuali.hr.time.util.TKUtils;
31 import org.kuali.rice.krad.service.BusinessObjectService;
32 import org.kuali.rice.krad.service.KRADServiceLocator;
33
34 import com.gargoylesoftware.htmlunit.html.HtmlForm;
35 import com.gargoylesoftware.htmlunit.html.HtmlInput;
36 import com.gargoylesoftware.htmlunit.html.HtmlPage;
37
38 public class ClockLocationRuleLookupTest extends KPMETestCase {
39
40 private static BusinessObjectService boService = null;
41
42
43
44
45
46 @Before
47 public void setUp() throws Exception {
48 super.setUp();
49 boService = KRADServiceLocator.getBusinessObjectService();
50 clearBusinessObjects(ClockLocationRule.class);
51
52 ClockLocationRule clr = new ClockLocationRule();
53 clr.setActive(true);
54 clr.setDept("12345");
55 Date asOfDate = new Date((new DateTime(2010, 8, 1, 12, 0, 0, 0, TKUtils.getSystemDateTimeZone())).getMillis());
56 clr.setEffectiveDate(asOfDate);
57 boService.save(clr);
58 }
59
60
61
62 @Test
63 public void testLookup() throws Exception{
64 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";
65 HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(baseUrl);
66 Assert.assertNotNull(page);
67 Assert.assertTrue("Could not find text 'Clock Location Rule Lookup' in page.", StringUtils.contains(page.asText(), "Clock Location Rule Lookup"));
68 HtmlForm form = page.getFormByName("KualiForm");
69 Assert.assertNotNull("Search form was missing from page.", form);
70
71 HtmlInput input = HtmlUnitUtil.getInputContainingText(form, "methodToCall.search");
72 Assert.assertNotNull("Could not locate search submit button", input);
73 page = (HtmlPage) input.click();
74 Assert.assertNotNull("Page not returned from click.", page);
75 HtmlUnitUtil.createTempFile(page);
76 Assert.assertTrue("Expected one result.", StringUtils.contains(page.asText(), "One item retrieved"));
77
78 page = HtmlUnitUtil.gotoPageAndLogin(baseUrl);
79 form = page.getFormByName("KualiForm");
80 Assert.assertNotNull("Search form was missing from page.", form);
81 HtmlUnitUtil.createTempFile(page);
82 form.getInputByName("dept").setValueAttribute("20");
83 input = HtmlUnitUtil.getInputContainingText(form, "methodToCall.search");
84 Assert.assertNotNull("Could not locate search submit button", input);
85 page = (HtmlPage) input.click();
86 Assert.assertNotNull("Page not returned from click.", page);
87 Assert.assertTrue("Expected zero results.", StringUtils.contains(page.asText(), "No values match this search."));
88 }
89
90 @SuppressWarnings("unchecked")
91 public static void clearBusinessObjects(Class clazz) {
92 boService.deleteMatching(clazz, new HashMap());
93 }
94
95
96
97 @Override
98 public void tearDown() throws Exception {
99 clearBusinessObjects(ClockLocationRule.class);
100 super.tearDown();
101 }
102 }