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.kfs.coa.businessobject.Account;
29 import org.kuali.kpme.core.kfs.coa.businessobject.Organization;
30 import org.kuali.kpme.core.util.HrTestConstants;
31 import org.kuali.rice.krad.service.KRADServiceLocator;
32
33 import com.gargoylesoftware.htmlunit.html.HtmlInput;
34 import com.gargoylesoftware.htmlunit.html.HtmlPage;
35
36 public class OrganizationMaintTest extends KPMEWebTestCase {
37
38 private static final String NEW_MAINT_DOC_PREFIX = "document.newMaintainableObject.";
39 private String newUrl;
40 private String lookupUrl;
41 private Map<String,String> requiredFields;
42
43 @Override
44 public void setUp() throws Exception {
45 super.setUp();
46 before();
47 }
48
49 @Override
50 public void tearDown() throws Exception {
51 after();
52 super.tearDown();
53 }
54
55 private void setDefaultTestInputValues() {
56 requiredFields = new HashMap<String,String>();
57 requiredFields.put("active", "on");
58 requiredFields.put("chartOfAccountsCode", "UA");
59 requiredFields.put("organizationCode", "A-ORG-CD");
60 requiredFields.put("organizationName", "ANOTHER ORGANIZATION");
61 }
62
63 private void before() {
64
65 newUrl = HrTestConstants.Urls.ORGANIZATION_MAINT_NEW_URL;
66 lookupUrl = HrTestConstants.Urls.ORGANIZATION_MAINT_URL;
67
68 requiredFields = new HashMap<String,String>();
69 requiredFields.put("chartOfAccountsCode", "Chart Code (Chart) is a required field.");
70 requiredFields.put("organizationCode", "Organization Code (Org) is a required field.");
71 requiredFields.put("organizationName", "Organization Name (Org Name) is a required field.");
72 }
73
74 private void after() {
75 requiredFields.clear();
76 }
77
78 @Test
79 public void testRequiredFields() throws Exception {
80 HtmlPage maintPage = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), newUrl);
81 assertNotNull("maintenance page is null", maintPage);
82
83 HtmlInput docDescription = HtmlUnitUtil.getInputContainingText(maintPage, "* Document Description");
84 assertNotNull("maintenance page does not contain document description", docDescription);
85
86 docDescription.setValueAttribute("testing submission");
87
88 HtmlPage resultPage = HtmlUnitUtil.clickInputContainingText(maintPage, "submit");
89 assertNotNull("no result page returned after submit", resultPage);
90
91 String resultPageAsText = resultPage.asText();
92 for(Entry<String,String> requiredField : requiredFields.entrySet()) {
93 assertTrue("page does not contain error message for required field: '" + requiredField.getKey() + "'",
94 resultPageAsText.contains(requiredField.getValue()));
95 }
96 }
97
98 @Test
99 public void testLookup() throws Exception {
100 HtmlPage lookupPage = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), lookupUrl);
101 assertNotNull("lookup page is null", lookupPage);
102
103 lookupPage = HtmlUnitUtil.clickInputContainingText(lookupPage, "search");
104 assertNotNull("lookup result page is null", lookupPage);
105
106 assertTrue("lookup result page should contain one record", lookupPage.asText().contains("ORG-CODE"));
107 }
108
109 @Test
110 public void testInValidChart() throws Exception {
111
112
113
114
115
116
117
118
119
120 HtmlPage maintPage = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), newUrl);
121 assertNotNull("maintenance page is null", maintPage);
122
123 HtmlInput docDescription = HtmlUnitUtil.getInputContainingText(maintPage, "* Document Description");
124 assertNotNull("maintenance page does not contain document description", docDescription);
125
126 setDefaultTestInputValues();
127 for(Entry<String,String> entry : requiredFields.entrySet()) {
128 HtmlUnitUtil.setFieldValue(maintPage, NEW_MAINT_DOC_PREFIX + entry.getKey(), entry.getValue());
129 }
130 docDescription.setValueAttribute("testing submission");
131
132 HtmlUnitUtil.setFieldValue(maintPage, NEW_MAINT_DOC_PREFIX + "chartOfAccountsCode","BP");
133
134 HtmlPage resultPage = HtmlUnitUtil.clickInputContainingText(maintPage, "submit");
135 assertTrue("page should contain active account existence error", resultPage.asText().contains("No active chart exists for this code"));
136 }
137
138 @Test
139 public void testValidChart() throws Exception {
140
141 HtmlPage maintPage = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), newUrl);
142 assertNotNull("maintenance page is null", maintPage);
143
144 HtmlInput docDescription = HtmlUnitUtil.getInputContainingText(maintPage, "* Document Description");
145 assertNotNull("maintenance page does not contain document description", docDescription);
146
147 setDefaultTestInputValues();
148 for(Entry<String,String> entry : requiredFields.entrySet()) {
149 HtmlUnitUtil.setFieldValue(maintPage, NEW_MAINT_DOC_PREFIX + entry.getKey(), entry.getValue());
150 }
151 docDescription.setValueAttribute("testing submission");
152
153 HtmlPage resultPage = HtmlUnitUtil.clickInputContainingText(maintPage, "submit");
154 assertTrue("page should contain active account existence error", !resultPage.asText().contains("error(s)"));
155
156 Map<String,String> keys = new HashMap<String,String>();
157 keys.put("chartOfAccountsCode", "UA");
158 keys.put("organizationCode", "A-ORG-CD");
159
160 Organization organization = (Organization) KRADServiceLocator.getBusinessObjectService().findByPrimaryKey(Organization.class, keys);
161 assertNotNull("newly created sub-object code should exist", organization);
162
163 KRADServiceLocator.getBusinessObjectService().delete(organization);
164 }
165
166 }