View Javadoc

1   /*
2    * Copyright 2006-2012 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package edu.samplu.admin.test;
18  
19  import edu.samplu.common.ITUtil;
20  import edu.samplu.common.UpgradedSeleniumITBase;
21  import edu.samplu.common.WebDriverITBase;
22  import edu.samplu.common.WebDriverUtil;
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.assertTrue;
33  import static com.thoughtworks.selenium.SeleneseTestBase.fail;
34  import static com.thoughtworks.selenium.SeleneseTestCase.assertEquals;
35  
36  /**
37   * Tests docsearch url parameters
38   * @author Kuali Rice Team (rice.collab@kuali.org)
39   */
40  public class DocumentSearchURLParametersITBase extends WebDriverITBase {
41  
42      @Override
43      public String getTestUrl() {
44          return ITUtil.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          // basic
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          // searchable attrs
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          // ADVANCED_FIELDS.put("routeNodeName", "Adhoc Routing");
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 ITUtil.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) { // 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 }