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.Ignore;
26 import org.junit.Test;
27 import org.kuali.hr.KPMEWebTestCase;
28 import org.kuali.hr.util.HtmlUnitUtil;
29 import org.kuali.kpme.core.kfs.coa.businessobject.Organization;
30 import org.kuali.kpme.core.kfs.coa.businessobject.ProjectCode;
31 import org.kuali.kpme.core.util.HrTestConstants;
32 import org.kuali.rice.krad.service.KRADServiceLocator;
33
34 import com.gargoylesoftware.htmlunit.html.HtmlInput;
35 import com.gargoylesoftware.htmlunit.html.HtmlPage;
36 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
37
38 public class ProjectCodeMaintTest extends KPMEWebTestCase {
39
40 private static final String NEW_MAINT_DOC_PREFIX = "document.newMaintainableObject.";
41 private String newUrl;
42 private String lookupUrl;
43 private Map<String,String> requiredFields;
44
45 private void before() {
46
47 newUrl = HrTestConstants.Urls.PROJECT_CODE_MAINT_NEW_URL;
48 lookupUrl = HrTestConstants.Urls.PROJECT_CODE_MAINT_URL;
49
50 requiredFields = new HashMap<String,String>();
51 requiredFields.put("code", "Project Code (Project) is a required field.");
52 requiredFields.put("name", "Project Name (Name) is a required field.");
53 requiredFields.put("chartOfAccountsCode", "Chart Code (Chart) is a required field.");
54 requiredFields.put("organizationCode", "Organization Code (Org) is a required field.");
55 }
56
57 private void setDefaultTestInputValues() {
58 requiredFields = new HashMap<String,String>();
59 requiredFields.put("active", "on");
60 requiredFields.put("chartOfAccountsCode", "UA");
61 requiredFields.put("code", "PRJ-CODE");
62 requiredFields.put("name", "PRJ-NAME");
63 requiredFields.put("organizationCode", "ORG-CODE");
64 }
65
66 private void after() {
67 requiredFields.clear();
68 }
69
70 @Test
71 public void testRequiredFields() throws Exception {
72 HtmlPage maintPage = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), newUrl);
73 assertNotNull("maintenance page is null", maintPage);
74
75 HtmlInput docDescription = HtmlUnitUtil.getInputContainingText(maintPage, "* Document Description");
76 assertNotNull("maintenance page does not contain document description", docDescription);
77
78 docDescription.setValueAttribute("testing submission");
79
80 HtmlPage resultPage = HtmlUnitUtil.clickInputContainingText(maintPage, "submit");
81 assertNotNull("no result page returned after submit", resultPage);
82
83 String resultPageAsText = resultPage.asText();
84 for(Entry<String,String> requiredField : requiredFields.entrySet()) {
85 assertTrue("page does not contain error message for required field: '" + requiredField.getKey() + "'",
86 resultPageAsText.contains(requiredField.getValue()));
87 }
88 }
89
90 @Test
91 public void testLookup() throws Exception {
92 HtmlPage lookupPage = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), lookupUrl);
93 assertNotNull("lookup page is null", lookupPage);
94
95 lookupPage = HtmlUnitUtil.clickInputContainingText(lookupPage, "search");
96 assertNotNull("lookup result page is null", lookupPage);
97
98 assertTrue("lookup result should not contain any project codes", lookupPage.asText().contains("No values match this search. "));
99 }
100
101 @Override
102 public void setUp() throws Exception {
103 super.setUp();
104 before();
105 }
106
107 @Override
108 public void tearDown() throws Exception {
109 after();
110 super.tearDown();
111 }
112
113 @Test
114 public void testInvalidChartConsistencyCaseTwo() throws Exception {
115
116
117
118
119 HtmlPage maintPage = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), newUrl);
120 assertNotNull("maintenance page is null", maintPage);
121
122 HtmlInput docDescription = HtmlUnitUtil.getInputContainingText(maintPage, "* Document Description");
123 assertNotNull("maintenance page does not contain document description", docDescription);
124
125 setDefaultTestInputValues();
126 for(Entry<String,String> entry : requiredFields.entrySet()) {
127 HtmlUnitUtil.setFieldValue(maintPage, NEW_MAINT_DOC_PREFIX + entry.getKey(), entry.getValue());
128 }
129
130 docDescription.setValueAttribute("testing submission");
131
132
133 HtmlUnitUtil.setFieldValue(maintPage, NEW_MAINT_DOC_PREFIX + "organizationCode", "ORG-CODE2");
134
135 before();
136 HtmlPage resultPage = HtmlUnitUtil.clickInputContainingText(maintPage, "submit");
137 assertNotNull("no result page returned after submit", resultPage);
138
139 String resultPageAsText = resultPage.asText();
140 for(Entry<String,String> requiredField : requiredFields.entrySet()) {
141 if(requiredField.getKey().equals("organizationCode")) {
142 assertTrue("page does not contain error message for the invalid field: '" + requiredField.getKey() + "'",
143 resultPageAsText.contains("No such active organization exists whose chart matches 'UA'"));
144 }
145 }
146 }
147
148 @Test
149 public void testInValidChart() throws Exception {
150
151
152
153
154
155
156
157
158
159 HtmlPage maintPage = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), newUrl);
160 assertNotNull("maintenance page is null", maintPage);
161
162 HtmlInput docDescription = HtmlUnitUtil.getInputContainingText(maintPage, "* Document Description");
163 assertNotNull("maintenance page does not contain document description", docDescription);
164
165 setDefaultTestInputValues();
166 for(Entry<String,String> entry : requiredFields.entrySet()) {
167 HtmlUnitUtil.setFieldValue(maintPage, NEW_MAINT_DOC_PREFIX + entry.getKey(), entry.getValue());
168 }
169 docDescription.setValueAttribute("testing submission");
170
171 HtmlUnitUtil.setFieldValue(maintPage, NEW_MAINT_DOC_PREFIX + "chartOfAccountsCode","BP");
172
173 HtmlPage resultPage = HtmlUnitUtil.clickInputContainingText(maintPage, "submit");
174 assertTrue("page should contain active chart existence error", resultPage.asText().contains("No active chart exists for this code"));
175 }
176
177 @Test
178 public void testValidChart() throws Exception {
179
180 HtmlPage maintPage = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), newUrl);
181 assertNotNull("maintenance page is null", maintPage);
182
183 HtmlInput docDescription = HtmlUnitUtil.getInputContainingText(maintPage, "* Document Description");
184 assertNotNull("maintenance page does not contain document description", docDescription);
185
186 setDefaultTestInputValues();
187 for(Entry<String,String> entry : requiredFields.entrySet()) {
188 HtmlUnitUtil.setFieldValue(maintPage, NEW_MAINT_DOC_PREFIX + entry.getKey(), entry.getValue());
189 }
190 docDescription.setValueAttribute("testing submission");
191
192 HtmlPage resultPage = HtmlUnitUtil.clickInputContainingText(maintPage, "submit");
193
194 assertTrue("page should contain active account existence error", !resultPage.asText().contains("error(s)"));
195
196 ProjectCode projectCode = (ProjectCode) KRADServiceLocatorWeb.getLegacyDataAdapter().findBySinglePrimaryKey(ProjectCode.class, "PRJ-CODE");
197 assertNotNull("newly created sub-object code should exist", projectCode);
198
199 KRADServiceLocatorWeb.getLegacyDataAdapter().delete(projectCode);
200 }
201 }