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