001 /*
002 * Copyright 2006-2012 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017 package edu.samplu.admin.test;
018
019 import org.kuali.rice.testtools.selenium.ITUtil;
020 import org.kuali.rice.testtools.selenium.WebDriverITBase;
021 import org.kuali.rice.testtools.selenium.WebDriverUtil;
022 import org.openqa.selenium.By;
023 import org.openqa.selenium.NoSuchElementException;
024 import org.openqa.selenium.WebElement;
025
026 import java.net.URLEncoder;
027 import java.util.HashMap;
028 import java.util.Map;
029 import java.util.concurrent.TimeUnit;
030
031 import static com.thoughtworks.selenium.SeleneseTestBase.assertTrue;
032 import static com.thoughtworks.selenium.SeleneseTestCase.assertEquals;
033
034 /**
035 * Tests docsearch url parameters
036 * @author Kuali Rice Team (rice.collab@kuali.org)
037 */
038 public class DocumentSearchURLParametersITBase extends WebDriverITBase {
039
040 @Override
041 public String getTestUrl() {
042 return ITUtil.PORTAL;
043 }
044
045 private static final String DOCUMENT_TYPE_NAME = "KualiNotification";
046 private static final String ADVANCED_SEARCH_ONLY_FIELD = "applicationDocumentId";
047
048 protected static final Map<String, String> CORE_FIELDS = new HashMap<String, String>();
049 static {
050 // basic
051 CORE_FIELDS.put("documentTypeName", DOCUMENT_TYPE_NAME);
052 CORE_FIELDS.put("documentId", "1234");
053 CORE_FIELDS.put("initiatorPrincipalName", "CURRENT_USER");
054 CORE_FIELDS.put("dateCreated", "11/11/11");
055
056 }
057 protected static final Map<String, String> BASIC_FIELDS = new HashMap<String, String>();
058 static {
059 BASIC_FIELDS.putAll(CORE_FIELDS);
060 // searchable attrs
061 BASIC_FIELDS.put("documentAttribute.notificationContentType", "testType");
062 BASIC_FIELDS.put("documentAttribute.notificationChannel", "testChannel");
063 BASIC_FIELDS.put("documentAttribute.notificationProducer", "testProducer");
064 BASIC_FIELDS.put("documentAttribute.notificationPriority", "testPriority");
065 BASIC_FIELDS.put("documentAttribute.notificationRecipients", "testRecipients");
066 BASIC_FIELDS.put("documentAttribute.notificationSenders", "testSenders");
067 BASIC_FIELDS.put("saveName", "testBasicSearchFields_saved_search");
068 BASIC_FIELDS.put("isAdvancedSearch", "NO");
069 }
070
071 protected static final Map<String, String> ADVANCED_FIELDS = new HashMap<String, String>();
072 static {
073 ADVANCED_FIELDS.put("approverPrincipalName", "testApproverName");
074 ADVANCED_FIELDS.put("viewerPrincipalName", "testViewerName");
075 ADVANCED_FIELDS.put("applicationDocumentId", "testApplicationDocumentId");
076 // ADVANCED_FIELDS.put("routeNodeName", "Adhoc Routing");
077 ADVANCED_FIELDS.put("dateApproved", "01/01/01");
078 ADVANCED_FIELDS.put("dateLastModified", "02/02/02");
079 ADVANCED_FIELDS.put("dateFinalized", "03/03/03");
080 ADVANCED_FIELDS.put("title", "test title");
081 ADVANCED_FIELDS.put("isAdvancedSearch", "YES");
082 }
083
084 String getDocSearchURL(Map<String, String> params) {
085 StringBuilder sb = new StringBuilder();
086 for (Map.Entry<String, String> entry: params.entrySet()) {
087 sb.append(URLEncoder.encode(entry.getKey()) + "=" + URLEncoder.encode(entry.getValue()) + "&");
088 }
089 return getDocSearchURL(sb.toString());
090
091 }
092 protected String getDocSearchURL(String params) {
093 return ITUtil.getBaseUrlString() + "/kew/DocumentSearch.do?" + params;
094 }
095
096 private WebElement findElementByTagAndName(String tag, String name) {
097 return driver.findElement(By.cssSelector(tag + "[name=" + name + "]"));
098 }
099
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) { // do the first find slow to make sure the screen has finished loading, then do them fast, else some tests take minutes to run
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) { // do the first find slow to make sure the screen has finished loading, then do them fast, else some tests take minutes to run
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 }