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