1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package edu.samplu.admin.test;
18
19 import edu.samplu.common.ITUtil;
20 import edu.samplu.common.WebDriverITBase;
21 import edu.samplu.common.WebDriverUtil;
22 import org.openqa.selenium.By;
23 import org.openqa.selenium.NoSuchElementException;
24 import org.openqa.selenium.WebElement;
25
26 import java.net.URLEncoder;
27 import java.util.HashMap;
28 import java.util.Map;
29 import java.util.concurrent.TimeUnit;
30
31 import static com.thoughtworks.selenium.SeleneseTestBase.assertTrue;
32 import static com.thoughtworks.selenium.SeleneseTestBase.fail;
33 import static com.thoughtworks.selenium.SeleneseTestCase.assertEquals;
34
35
36
37
38
39 public class DocumentSearchURLParametersITBase extends WebDriverITBase {
40
41 @Override
42 public String getTestUrl() {
43 return ITUtil.PORTAL;
44 }
45
46 private static final String DOCUMENT_TYPE_NAME = "KualiNotification";
47 private static final String ADVANCED_SEARCH_ONLY_FIELD = "applicationDocumentId";
48
49 protected static final Map<String, String> CORE_FIELDS = new HashMap<String, String>();
50 static {
51
52 CORE_FIELDS.put("documentTypeName", DOCUMENT_TYPE_NAME);
53 CORE_FIELDS.put("documentId", "1234");
54 CORE_FIELDS.put("initiatorPrincipalName", "CURRENT_USER");
55 CORE_FIELDS.put("dateCreated", "11/11/11");
56
57 }
58 protected static final Map<String, String> BASIC_FIELDS = new HashMap<String, String>();
59 static {
60 BASIC_FIELDS.putAll(CORE_FIELDS);
61
62 BASIC_FIELDS.put("documentAttribute.notificationContentType", "testType");
63 BASIC_FIELDS.put("documentAttribute.notificationChannel", "testChannel");
64 BASIC_FIELDS.put("documentAttribute.notificationProducer", "testProducer");
65 BASIC_FIELDS.put("documentAttribute.notificationPriority", "testPriority");
66 BASIC_FIELDS.put("documentAttribute.notificationRecipients", "testRecipients");
67 BASIC_FIELDS.put("documentAttribute.notificationSenders", "testSenders");
68 BASIC_FIELDS.put("saveName", "testBasicSearchFields_saved_search");
69 BASIC_FIELDS.put("isAdvancedSearch", "NO");
70 }
71
72 protected static final Map<String, String> ADVANCED_FIELDS = new HashMap<String, String>();
73 static {
74 ADVANCED_FIELDS.put("approverPrincipalName", "testApproverName");
75 ADVANCED_FIELDS.put("viewerPrincipalName", "testViewerName");
76 ADVANCED_FIELDS.put("applicationDocumentId", "testApplicationDocumentId");
77
78 ADVANCED_FIELDS.put("dateApproved", "01/01/01");
79 ADVANCED_FIELDS.put("dateLastModified", "02/02/02");
80 ADVANCED_FIELDS.put("dateFinalized", "03/03/03");
81 ADVANCED_FIELDS.put("title", "test title");
82 ADVANCED_FIELDS.put("isAdvancedSearch", "YES");
83 }
84
85 String getDocSearchURL(Map<String, String> params) {
86 StringBuilder sb = new StringBuilder();
87 for (Map.Entry<String, String> entry: params.entrySet()) {
88 sb.append(URLEncoder.encode(entry.getKey()) + "=" + URLEncoder.encode(entry.getValue()) + "&");
89 }
90 return getDocSearchURL(sb.toString());
91
92 }
93 protected String getDocSearchURL(String params) {
94 return ITUtil.getBaseUrlString() + "/kew/DocumentSearch.do?" + params;
95 }
96
97 private WebElement findElementByTagAndName(String tag, String name) {
98 return driver.findElement(By.cssSelector(tag + "[name=" + name + "]"));
99 }
100
101 private WebElement findInput(String name) {
102 return driver.findElement(By.xpath("//input[@name='" + name + "']"));
103 }
104
105 protected WebElement findModeToggleButton() {
106 WebElement toggleAdvancedSearch = null;
107 try {
108 return driver.findElement(By.id("toggleAdvancedSearch"));
109 } catch (NoSuchElementException e) {
110 fail("toggleAdvancedSearch button not found");
111 return null;
112 }
113 }
114
115 protected void assertSearchDetailMode(WebElement e, boolean advanced) {
116 assertEquals((advanced ? "basic" : "detailed") + " search", e.getAttribute("title"));
117
118 try {
119 findInput(ADVANCED_SEARCH_ONLY_FIELD);
120 if (!advanced) fail("Advanced search field found in basic search");
121 } catch (NoSuchElementException nsee) {
122 if (advanced) fail("Advanced search field not found in advancedsearch");
123 }
124 }
125
126 protected void assertInputValues(Map<String, String> fields) {
127 boolean quickmode = false;
128 for (Map.Entry<String, String> entry: fields.entrySet()) {
129 String value = findInput(entry.getKey()).getAttribute("value");
130 assertEquals("Field '" + entry.getKey() + "' expected '" + entry.getValue() + "' got '" + value + "'", entry.getValue(), value);
131 if (!quickmode) {
132 driver.manage().timeouts().implicitlyWait(WebDriverUtil.SHORT_IMPLICIT_WAIT_TIME, TimeUnit.SECONDS);
133 quickmode = true;
134 }
135 }
136 if (quickmode) {
137 driver.manage().timeouts().implicitlyWait(WebDriverUtil.DEFAULT_IMPLICIT_WAIT_TIME, TimeUnit.SECONDS);
138 }
139 }
140
141 protected void assertInputPresence(Map<String, String> fields, boolean present) {
142 boolean quickmode = false;
143 for (String name: fields.keySet()) {
144 if (present) {
145 assertTrue("Expected field '" + name + "' to be present", driver.findElements(By.name(name)).size() != 0);
146 } else {
147 assertEquals("Expected field '" + name + "' not to be present", 0, driver.findElements(By.name(name)).size());
148 }
149 if (!quickmode) {
150 driver.manage().timeouts().implicitlyWait(WebDriverUtil.SHORT_IMPLICIT_WAIT_TIME, TimeUnit.SECONDS);
151 quickmode = true;
152 }
153 }
154 if (quickmode) {
155 driver.manage().timeouts().implicitlyWait(WebDriverUtil.DEFAULT_IMPLICIT_WAIT_TIME, TimeUnit.SECONDS);
156 }
157 }
158 }