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 edu.samplu.common.ITUtil; 020 import edu.samplu.common.UpgradedSeleniumITBase; 021 import edu.samplu.common.WebDriverITBase; 022 import edu.samplu.common.WebDriverUtil; 023 import org.openqa.selenium.By; 024 import org.openqa.selenium.NoSuchElementException; 025 import org.openqa.selenium.WebElement; 026 027 import java.net.URLEncoder; 028 import java.util.HashMap; 029 import java.util.Map; 030 import java.util.concurrent.TimeUnit; 031 032 import static com.thoughtworks.selenium.SeleneseTestBase.assertTrue; 033 import static com.thoughtworks.selenium.SeleneseTestBase.fail; 034 import static com.thoughtworks.selenium.SeleneseTestCase.assertEquals; 035 036 /** 037 * Tests docsearch url parameters 038 * @author Kuali Rice Team (rice.collab@kuali.org) 039 */ 040 public class DocumentSearchURLParametersITBase extends WebDriverITBase { 041 042 @Override 043 public String getTestUrl() { 044 return ITUtil.PORTAL; 045 } 046 047 private static final String DOCUMENT_TYPE_NAME = "KualiNotification"; 048 private static final String ADVANCED_SEARCH_ONLY_FIELD = "applicationDocumentId"; 049 050 protected static final Map<String, String> CORE_FIELDS = new HashMap<String, String>(); 051 static { 052 // basic 053 CORE_FIELDS.put("documentTypeName", DOCUMENT_TYPE_NAME); 054 CORE_FIELDS.put("documentId", "1234"); 055 CORE_FIELDS.put("initiatorPrincipalName", "CURRENT_USER"); 056 CORE_FIELDS.put("dateCreated", "11/11/11"); 057 058 } 059 protected static final Map<String, String> BASIC_FIELDS = new HashMap<String, String>(); 060 static { 061 BASIC_FIELDS.putAll(CORE_FIELDS); 062 // searchable attrs 063 BASIC_FIELDS.put("documentAttribute.notificationContentType", "testType"); 064 BASIC_FIELDS.put("documentAttribute.notificationChannel", "testChannel"); 065 BASIC_FIELDS.put("documentAttribute.notificationProducer", "testProducer"); 066 BASIC_FIELDS.put("documentAttribute.notificationPriority", "testPriority"); 067 BASIC_FIELDS.put("documentAttribute.notificationRecipients", "testRecipients"); 068 BASIC_FIELDS.put("documentAttribute.notificationSenders", "testSenders"); 069 BASIC_FIELDS.put("saveName", "testBasicSearchFields_saved_search"); 070 BASIC_FIELDS.put("isAdvancedSearch", "NO"); 071 } 072 073 protected static final Map<String, String> ADVANCED_FIELDS = new HashMap<String, String>(); 074 static { 075 ADVANCED_FIELDS.put("approverPrincipalName", "testApproverName"); 076 ADVANCED_FIELDS.put("viewerPrincipalName", "testViewerName"); 077 ADVANCED_FIELDS.put("applicationDocumentId", "testApplicationDocumentId"); 078 // ADVANCED_FIELDS.put("routeNodeName", "Adhoc Routing"); 079 ADVANCED_FIELDS.put("dateApproved", "01/01/01"); 080 ADVANCED_FIELDS.put("dateLastModified", "02/02/02"); 081 ADVANCED_FIELDS.put("dateFinalized", "03/03/03"); 082 ADVANCED_FIELDS.put("title", "test title"); 083 ADVANCED_FIELDS.put("isAdvancedSearch", "YES"); 084 } 085 086 String getDocSearchURL(Map<String, String> params) { 087 StringBuilder sb = new StringBuilder(); 088 for (Map.Entry<String, String> entry: params.entrySet()) { 089 sb.append(URLEncoder.encode(entry.getKey()) + "=" + URLEncoder.encode(entry.getValue()) + "&"); 090 } 091 return getDocSearchURL(sb.toString()); 092 093 } 094 protected String getDocSearchURL(String params) { 095 return ITUtil.getBaseUrlString() + "/kew/DocumentSearch.do?" + params; 096 } 097 098 private WebElement findElementByTagAndName(String tag, String name) { 099 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) { // do the first find slow to make sure the screen has finished loading, then do them fast, else some tests take minutes to run 133 driver.manage().timeouts().implicitlyWait(WebDriverUtil.SHORT_IMPLICIT_WAIT_TIME, TimeUnit.SECONDS); 134 quickmode = true; 135 } 136 } 137 if (quickmode) { 138 driver.manage().timeouts().implicitlyWait(WebDriverUtil.DEFAULT_IMPLICIT_WAIT_TIME, 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) { // do the first find slow to make sure the screen has finished loading, then do them fast, else some tests take minutes to run 151 driver.manage().timeouts().implicitlyWait(WebDriverUtil.SHORT_IMPLICIT_WAIT_TIME, TimeUnit.SECONDS); 152 quickmode = true; 153 } 154 } 155 if (quickmode) { 156 driver.manage().timeouts().implicitlyWait(WebDriverUtil.DEFAULT_IMPLICIT_WAIT_TIME, TimeUnit.SECONDS); 157 } 158 } 159 }