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