1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.core.institution;
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 InstitutionMaintenanceTest extends KPMEWebTestCase {
34
35 private static String newUrl;
36 private static String lookupUrl;
37 private static Map<String,String> requiredFields;
38
39 private void before() {
40
41 newUrl = HrTestConstants.Urls.INSTITUTION_MAINT_NEW_URL;
42 lookupUrl = HrTestConstants.Urls.INSTITUTION_MAINT_URL;
43
44 requiredFields = new HashMap<String,String>();
45 requiredFields.put("effectiveDate", "Effective Date (Effective Date) is a required field.");
46 requiredFields.put("institutionCode", "Institution Code (Institution Code) is a required field.");
47 }
48
49 private void after() {
50 requiredFields.clear();
51 }
52
53 @Override
54 public void setUp() throws Exception {
55 before();
56 super.setUp();
57 }
58
59 @Override
60 public void tearDown() throws Exception {
61 after();
62 super.tearDown();
63 }
64
65 @Test
66 public void testRequiredFields() throws Exception {
67 HtmlPage maintPage = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), newUrl);
68 assertNotNull("maintenance page is null", maintPage);
69
70 HtmlInput docDescription = HtmlUnitUtil.getInputContainingText(maintPage, "* Document Description");
71 assertNotNull("maintenance page does not contain document description", docDescription);
72
73 docDescription.setValueAttribute("testing submission");
74
75 HtmlPage resultPage = HtmlUnitUtil.clickInputContainingText(maintPage, "submit");
76 assertNotNull("no result page returned after submit", resultPage);
77
78 String resultPageAsText = resultPage.asText();
79 for(Entry<String,String> requiredField : requiredFields.entrySet()) {
80 assertTrue("page does not contain error message for required field: '" + requiredField.getKey() + "'",
81 resultPageAsText.contains(requiredField.getValue()));
82 }
83 }
84
85 @Test
86 public void testLookup() throws Exception {
87 HtmlPage lookupPage = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), lookupUrl);
88 assertNotNull("lookup page is null", lookupPage);
89
90 lookupPage = HtmlUnitUtil.clickInputContainingText(lookupPage, "search");
91 assertNotNull("lookup result page is null", lookupPage);
92
93 }
94
95 }