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