1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.core.kfs;
17
18 import static org.junit.Assert.assertNotNull;
19 import static org.junit.Assert.assertTrue;
20
21 import java.util.HashMap;
22 import java.util.Map;
23 import java.util.Map.Entry;
24
25 import org.junit.Test;
26 import org.kuali.hr.KPMEWebTestCase;
27 import org.kuali.hr.util.HtmlUnitUtil;
28 import org.kuali.kpme.core.util.HrTestConstants;
29
30 import com.gargoylesoftware.htmlunit.html.HtmlInput;
31 import com.gargoylesoftware.htmlunit.html.HtmlPage;
32
33 public class ChartMaintTest extends KPMEWebTestCase {
34
35 private String newUrl;
36 private String lookupUrl;
37 private Map<String,String> requiredFields;
38
39 private void before() {
40 newUrl = HrTestConstants.Urls.CHART_MAINT_NEW_URL;
41 lookupUrl = HrTestConstants.Urls.CHART_MAINT_URL;
42
43 requiredFields = new HashMap<String,String>();
44 requiredFields.put("chartOfAccountsCode", "Chart Code (Chart) is a required field.");
45 requiredFields.put("finChartOfAccountDescription", "Chart Description (Description) is a required field.");
46 }
47
48 private void after() {
49 requiredFields.clear();
50 }
51
52 @Test
53 public void testRequiredFields() throws Exception {
54 HtmlPage maintPage = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), newUrl);
55 assertNotNull("maintenance page is null", maintPage);
56
57 HtmlInput docDescription = HtmlUnitUtil.getInputContainingText(maintPage, "* Document Description");
58 assertNotNull("maintenance page does not contain document description", docDescription);
59
60 docDescription.setValueAttribute("testing submission");
61
62 HtmlPage resultPage = HtmlUnitUtil.clickInputContainingText(maintPage, "submit");
63 assertNotNull("no result page returned after submit", resultPage);
64
65 String resultPageAsText = resultPage.asText();
66 for(Entry<String,String> requiredField : requiredFields.entrySet()) {
67 assertTrue("page does not contain error message for required field: '" + requiredField.getKey() + "'",
68 resultPageAsText.contains(requiredField.getValue()));
69 }
70 }
71
72 @Test
73 public void testLookup() throws Exception {
74 HtmlPage lookupPage = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), lookupUrl);
75 assertNotNull("lookup page is null", lookupPage);
76
77 lookupPage = HtmlUnitUtil.clickInputContainingText(lookupPage, "search");
78 assertNotNull("lookup result page is null", lookupPage);
79
80 }
81
82 @Override
83 public void setUp() throws Exception {
84 super.setUp();
85 before();
86 }
87
88 @Override
89 public void tearDown() throws Exception {
90 after();
91 super.tearDown();
92 }
93 }