1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package edu.sampleu.admin;
17
18 import org.junit.Test;
19 import org.kuali.rice.krad.util.KRADConstants;
20 import org.kuali.rice.testtools.selenium.AutomatedFunctionalTestUtils;
21 import org.kuali.rice.testtools.selenium.WebDriverITBase;
22 import org.kuali.rice.testtools.selenium.WebDriverUtils;
23 import org.openqa.selenium.By;
24 import org.openqa.selenium.NoSuchElementException;
25 import org.openqa.selenium.WebElement;
26
27 import java.net.URLEncoder;
28 import java.util.HashMap;
29 import java.util.Map;
30 import java.util.concurrent.TimeUnit;
31
32 import static com.thoughtworks.selenium.SeleneseTestBase.assertFalse;
33 import static com.thoughtworks.selenium.SeleneseTestBase.assertTrue;
34 import static com.thoughtworks.selenium.SeleneseTestCase.assertEquals;
35
36
37
38
39
40 public class DocumentSearchUrlParametersAft extends WebDriverITBase {
41
42 @Override
43 public String getTestUrl() {
44 return AutomatedFunctionalTestUtils.PORTAL;
45 }
46
47 private static final String DOCUMENT_TYPE_NAME = "KualiNotification";
48 private static final String ADVANCED_SEARCH_ONLY_FIELD = "applicationDocumentId";
49
50 protected static final Map<String, String> CORE_FIELDS = new HashMap<String, String>();
51 static {
52
53 CORE_FIELDS.put("documentTypeName", DOCUMENT_TYPE_NAME);
54 CORE_FIELDS.put("documentId", "1234");
55 CORE_FIELDS.put("initiatorPrincipalName", "CURRENT_USER");
56 CORE_FIELDS.put("dateCreated", "11/11/11");
57
58 }
59 protected static final Map<String, String> BASIC_FIELDS = new HashMap<String, String>();
60 static {
61 BASIC_FIELDS.putAll(CORE_FIELDS);
62
63 BASIC_FIELDS.put("documentAttribute.notificationContentType", "testType");
64 BASIC_FIELDS.put("documentAttribute.notificationChannel", "testChannel");
65 BASIC_FIELDS.put("documentAttribute.notificationProducer", "testProducer");
66 BASIC_FIELDS.put("documentAttribute.notificationPriority", "testPriority");
67 BASIC_FIELDS.put("documentAttribute.notificationRecipients", "testRecipients");
68 BASIC_FIELDS.put("documentAttribute.notificationSenders", "testSenders");
69 BASIC_FIELDS.put("saveName", "testBasicSearchFields_saved_search");
70 BASIC_FIELDS.put("isAdvancedSearch", "NO");
71 }
72
73 protected static final Map<String, String> ADVANCED_FIELDS = new HashMap<String, String>();
74 static {
75 ADVANCED_FIELDS.put("approverPrincipalName", "testApproverName");
76 ADVANCED_FIELDS.put("viewerPrincipalName", "testViewerName");
77 ADVANCED_FIELDS.put("applicationDocumentId", "testApplicationDocumentId");
78
79 ADVANCED_FIELDS.put("dateApproved", "01/01/01");
80 ADVANCED_FIELDS.put("dateLastModified", "02/02/02");
81 ADVANCED_FIELDS.put("dateFinalized", "03/03/03");
82 ADVANCED_FIELDS.put("title", "test title");
83 ADVANCED_FIELDS.put("isAdvancedSearch", "YES");
84 }
85
86 String getDocSearchURL(Map<String, String> params) {
87 StringBuilder sb = new StringBuilder();
88 for (Map.Entry<String, String> entry: params.entrySet()) {
89 sb.append(URLEncoder.encode(entry.getKey()) + "=" + URLEncoder.encode(entry.getValue()) + "&");
90 }
91 return getDocSearchURL(sb.toString());
92
93 }
94 protected String getDocSearchURL(String params) {
95 return WebDriverUtils.getBaseUrlString() + "/kew/DocumentSearch.do?" + params;
96 }
97
98 private WebElement findElementByTagAndName(String tag, String name) {
99 return driver.findElement(By.cssSelector(tag + "[name=" + name + "]"));
100 }
101
102 private WebElement findInput(String name) {
103 return driver.findElement(By.xpath("//input[@name='" + name + "']"));
104 }
105
106 protected WebElement findModeToggleButton() {
107 WebElement toggleAdvancedSearch = null;
108 try {
109 return driver.findElement(By.id("toggleAdvancedSearch"));
110 } catch (NoSuchElementException e) {
111 fail("toggleAdvancedSearch button not found");
112 return null;
113 }
114 }
115
116 protected void assertSearchDetailMode(WebElement e, boolean advanced) {
117 assertEquals((advanced ? "basic" : "detailed") + " search", e.getAttribute("title"));
118
119 try {
120 findInput(ADVANCED_SEARCH_ONLY_FIELD);
121 if (!advanced) fail("Advanced search field found in basic search");
122 } catch (NoSuchElementException nsee) {
123 if (advanced) fail("Advanced search field not found in advancedsearch");
124 }
125 }
126
127 protected void assertInputValues(Map<String, String> fields) {
128 boolean quickmode = false;
129 for (Map.Entry<String, String> entry: fields.entrySet()) {
130 String value = findInput(entry.getKey()).getAttribute("value");
131 assertEquals("Field '" + entry.getKey() + "' expected '" + entry.getValue() + "' got '" + value + "'", entry.getValue(), value);
132 if (!quickmode) {
133 driver.manage().timeouts().implicitlyWait(WebDriverUtils.IMPLICIT_WAIT_TIME_LOOP_MS, TimeUnit.MILLISECONDS);
134 quickmode = true;
135 }
136 }
137 if (quickmode) {
138 driver.manage().timeouts().implicitlyWait(WebDriverUtils.configuredImplicityWait(), TimeUnit.SECONDS);
139 }
140 }
141
142 protected void assertInputPresence(Map<String, String> fields, boolean present) {
143 boolean quickmode = false;
144 for (String name: fields.keySet()) {
145 if (present) {
146 assertTrue("Expected field '" + name + "' to be present", driver.findElements(By.name(name)).size() != 0);
147 } else {
148 assertEquals("Expected field '" + name + "' not to be present", 0, driver.findElements(By.name(name)).size());
149 }
150 if (!quickmode) {
151 driver.manage().timeouts().implicitlyWait(WebDriverUtils.IMPLICIT_WAIT_TIME_LOOP_MS, TimeUnit.MILLISECONDS);
152 quickmode = true;
153 }
154 }
155 if (quickmode) {
156 driver.manage().timeouts().implicitlyWait(WebDriverUtils.configuredImplicityWait(), TimeUnit.SECONDS);
157 }
158 }
159
160 @Test
161 public void testAdvancedSearchFields() throws InterruptedException{
162
163 Map<String, String> values = new HashMap<String, String>(BASIC_FIELDS);
164 values.putAll(ADVANCED_FIELDS);
165 driver.get(getDocSearchURL(values));
166
167 assertInputValues(values);
168
169 driver.findElement(By.id("toggleAdvancedSearch")).click();
170
171 assertInputValues(BASIC_FIELDS);
172 }
173
174 @Test
175 public void testAdvancedSearchFieldsAndExecuteSearch() throws InterruptedException{
176
177 Map<String, String> expected = new HashMap<String, String>(BASIC_FIELDS);
178 expected.putAll(ADVANCED_FIELDS);
179
180 Map<String, String> values = new HashMap<String, String>(expected);
181 values.put("methodToCall", "search");
182 driver.get(getDocSearchURL(values));
183
184 assertInputValues(expected);
185
186
187 assertTrue(driver.getPageSource().contains("No values match this search"));
188
189 driver.findElement(By.id("toggleAdvancedSearch")).click();
190
191 assertInputValues(BASIC_FIELDS);
192 }
193
194 @Test
195 public void testAdvancedSearchFieldsAndExecuteSearchWithHiddenCriteria() throws InterruptedException {
196
197 Map<String, String> expected = new HashMap<String, String>(BASIC_FIELDS);
198 expected.putAll(ADVANCED_FIELDS);
199
200 Map<String, String> values = new HashMap<String, String>(expected);
201 values.put("methodToCall", "search");
202 values.put("searchCriteriaEnabled", "NO");
203 driver.get(getDocSearchURL(values));
204
205 assertInputPresence(expected, false);
206
207
208 assertTrue(driver.getPageSource().contains("No values match this search"));
209
210
211 }
212
213 @Test
214 public void testAdvancedSearchMode() {
215 driver.get(getDocSearchURL((KRADConstants.ADVANCED_SEARCH_FIELD + "=YES")));
216 WebElement toggle = findModeToggleButton();
217 assertSearchDetailMode(toggle, true);
218 toggle.click();
219 assertSearchDetailMode(findModeToggleButton(), false);
220 }
221
222 @Test
223 public void testBasicSearchFields() throws InterruptedException{
224
225 driver.get(getDocSearchURL(BASIC_FIELDS));
226
227 assertInputValues(BASIC_FIELDS);
228
229 driver.findElement(By.id("toggleAdvancedSearch")).click();
230
231 Map<String, String> expected = new HashMap<String, String>(BASIC_FIELDS);
232 for (Map.Entry<String, String> entry: ADVANCED_FIELDS.entrySet()) {
233 if (!"isAdvancedSearch".equals(entry.getKey())) {
234 expected.put(entry.getKey(), "");
235 } else {
236 expected.put(entry.getKey(), entry.getValue());
237 }
238 }
239 assertInputValues(expected);
240 }
241
242 @Test
243 public void testBasicSearchFieldsAndExecuteSearch() throws InterruptedException {
244
245 Map<String, String> fields = new HashMap<String, String>();
246 fields.putAll(BASIC_FIELDS);
247 fields.put("methodToCall", "search");
248 driver.get(getDocSearchURL(fields));
249
250 assertInputValues(BASIC_FIELDS);
251
252
253 assertTrue(driver.getPageSource().contains("No values match this search"));
254
255 driver.findElement(By.id("toggleAdvancedSearch")).click();
256
257 Map<String, String> expected = new HashMap<String, String>(BASIC_FIELDS);
258 for (Map.Entry<String, String> entry: ADVANCED_FIELDS.entrySet()) {
259 if (!"isAdvancedSearch".equals(entry.getKey())) {
260 expected.put(entry.getKey(), "");
261 } else {
262 expected.put(entry.getKey(), entry.getValue());
263 }
264 }
265 assertInputValues(expected);
266
267
268
269 }
270
271 @Test
272 public void testBasicSearchFieldsAndExecuteSearchWithHiddenCriteria() throws InterruptedException {
273
274 Map<String, String> fields = new HashMap<String, String>();
275 fields.putAll(BASIC_FIELDS);
276 fields.put("methodToCall", "search");
277 fields.put("searchCriteriaEnabled", "NO");
278 driver.get(getDocSearchURL(fields));
279
280 assertInputPresence(BASIC_FIELDS, false);
281
282
283 assertTrue(driver.getPageSource().contains("No values match this search"));
284
285
286 }
287
288 @Test
289 public void testBasicSearchMode() throws InterruptedException{
290 driver.get(getDocSearchURL(""));
291 WebElement toggle = findModeToggleButton();
292 assertSearchDetailMode(toggle, false);
293 toggle.click();
294 assertSearchDetailMode(findModeToggleButton(), true);
295 }
296
297 @Test
298 public void testCriteriaDisabled() throws InterruptedException{
299 driver.get(getDocSearchURL("searchCriteriaEnabled=NO"));
300 assertInputPresence(CORE_FIELDS, false);
301 driver.get(getDocSearchURL("searchCriteriaEnabled=true"));
302 assertInputPresence(CORE_FIELDS, true);
303 }
304
305 @Test
306 public void testHeaderBarDisabled() throws InterruptedException{
307 driver.get(getDocSearchURL("headerBarEnabled=false"));
308 assertTrue(driver.findElements(By.id("headerarea-small")).isEmpty());
309 assertInputPresence(CORE_FIELDS, true);
310 driver.get(getDocSearchURL("headerBarEnabled=true"));
311 assertFalse(driver.findElements(By.id("headerarea-small")).isEmpty());
312 assertInputPresence(CORE_FIELDS, true);
313 }
314
315
316
317
318
319 @Test
320 public void testSupplyingSavedSearchNameDoesNothing() throws InterruptedException {
321
322 driver.get(getDocSearchURL(BASIC_FIELDS));
323
324 driver.get(getDocSearchURL("saveName=testBasicSearchFields_saved_search"));
325
326 Map<String, String> emptyForm = new HashMap<String, String>();
327 for (String key: CORE_FIELDS.keySet()) {
328 emptyForm.put(key, "");
329 }
330
331 assertInputValues(emptyForm);
332 }
333 }