001/**
002 * Copyright 2005-2014 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 */
016package edu.sampleu.admin;
017
018import org.kuali.rice.testtools.selenium.AutomatedFunctionalTestUtils;
019import org.kuali.rice.testtools.selenium.WebDriverLegacyITBase;
020import org.kuali.rice.testtools.selenium.WebDriverUtils;
021import org.apache.commons.lang.RandomStringUtils;
022import org.junit.Test;
023import org.openqa.selenium.By;
024
025import java.text.SimpleDateFormat;
026import java.util.Calendar;
027
028/**
029 * Tests whether the ENABLE_FIELD_LEVEL_HELP_IND parameter is being considered and loaded on each request.
030 *
031 * @author Kuali Rice Team (rice.collab@kuali.org)
032 */
033public class DetailedDocSearchAft extends WebDriverLegacyITBase {
034    /*
035     * AutomatedFunctionalTestUtils.PORTAL + "?channelTitle=Document%20Search&channelUrl=" + WebDriverUtils
036     * .getBaseUrlString() + "/kew/DocumentSearch.do?docFormKey=88888888&returnLocation=" + AutomatedFunctionalTestUtils.PORTAL_URL + AutomatedFunctionalTestUtils.HIDE_RETURN_LINK;
037     */
038    
039    public static String BOOKMARK_URL = AutomatedFunctionalTestUtils.PORTAL + "?channelTitle=Document%20Search&channelUrl=" + WebDriverUtils
040            .getBaseUrlString() + "/kew/DocumentSearch.do?docFormKey=88888888&returnLocation=" + AutomatedFunctionalTestUtils.PORTAL_URL + AutomatedFunctionalTestUtils.HIDE_RETURN_LINK;
041
042    private String groupId = null;
043    private String groupName = null;
044    private String groupRandomCode = null;
045    private String parameterDocId = null;
046    private String todayDate = null;
047
048    @Override
049    protected String getBookmarkUrl() {
050        return BOOKMARK_URL;
051    }
052
053    @Override
054    protected void navigate() throws Exception {
055       waitAndClickByXpath("//img[@alt='doc search']"); 
056    }
057
058    @Test
059    public void testAdvancedDocSearchNav() throws Exception {
060        advancedDocSearchAll();
061    }
062    
063    @Test
064    public void testAdvancedDocSearchBookmark() throws Exception {
065        advancedDocSearchAll();
066    }
067    
068    private void advancedDocSearchAll() throws Exception{
069        todayDate = getDateToUseForSearch();
070        createGroupDocument();
071        selectTopFrame();
072        createGroupDocumentFinal();
073        selectTopFrame();
074        createGroupDocumentFinal();
075        selectTopFrame();
076        createParameterDocument();
077        selectTopFrame();
078        waitAndClickByXpath("//a[@title='Document Search']");
079        acceptAlertIfPresent();
080        selectFrameIframePortlet();
081        waitAndClickByName("toggleAdvancedSearch");
082        acceptAlertIfPresent();
083        searchByDocumentType();
084        searchByInitiator();
085        searchByApprover();
086        searchByViewer();
087        searchByGroupViewer();
088        searchByDocumentId();
089        searchByApplicationDocumentId();
090        searchByDocumentStatus();
091        searchByDateCreatedFrom();
092        searchByDateCreatedTo();
093        searchByDateApprovedFrom();
094        searchByDateApprovedTo();
095        searchByDateLastModifiedFrom();
096        searchByDateLastModifiedTo();
097        searchByDateLastFinalizedFrom();
098        searchByDateLastFinalizedTo();
099        searchByTitle();
100        passed();
101    }
102
103    private String getDateToUseForSearch() {
104        Calendar nextYearCal = Calendar.getInstance();
105        SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
106        return sdf.format(nextYearCal.getTime());
107    }
108
109    private void createGroupDocument() throws Exception{
110        waitAndClickAdministration();
111        selectFrameIframePortlet();
112        waitAndClickByLinkText("Group");
113        selectFrameIframePortlet();
114        waitAndClickByXpath("//a[@title='Create a new record']");
115        selectFrameIframePortlet();
116        String randomCode = RandomStringUtils.randomAlphabetic(9).toUpperCase();
117        waitAndSelectByName("document.groupNamespace","KR-BUS - Service Bus");
118        waitAndTypeByName("document.documentHeader.documentDescription","Group");
119        groupName = "Group 1"+randomCode;
120        waitAndTypeByName("document.groupName", groupName);
121        groupId=waitForElementPresentByXpath("//div[@id='tab-Overview-div']/div[@class='tab-container']/table/tbody/tr/td").getText();
122
123        // Add an acknowledgement request for user1 so we can search by viewer
124        waitAndClickByName("methodToCall.toggleTab.tabAdHocRecipients");
125        waitAndSelectByName("newAdHocRoutePerson.actionRequested", "ACKNOWLEDGE");
126        waitAndTypeByName("newAdHocRoutePerson.id", "user1");
127        WebDriverUtils.jGrowl(getDriver(), "Click Add Person", false, "Click Add Person");
128        waitAndClickByName("methodToCall.insertAdHocRoutePerson");
129
130        waitAndClickByXpath("//input[@name='methodToCall.route']");
131    }
132
133    private void createGroupDocumentFinal() throws Exception{
134        waitAndClickAdministration();
135        selectFrameIframePortlet();
136        waitAndClickByLinkText("Group");
137        selectFrameIframePortlet();
138        waitAndClickByXpath("//a[@title='Create a new record']");
139        selectFrameIframePortlet();
140        String randomCode = RandomStringUtils.randomAlphabetic(9).toUpperCase();
141        waitAndSelectByName("document.groupNamespace", "KR-BUS - Service Bus");
142        waitAndTypeByName("document.documentHeader.documentDescription","Group");
143        waitAndTypeByName("document.groupName", "Group Final "+randomCode);
144        waitAndClickByXpath("//input[@name='methodToCall.blanketApprove']");
145    }
146
147    private void createParameterDocument() throws Exception{
148        waitAndClickAdministration();
149        selectFrameIframePortlet();
150        waitAndClickByLinkText("Parameter");
151        selectFrameIframePortlet();
152        waitAndClickByXpath("//a[@title='Create a new record']");
153        selectFrameIframePortlet();
154        groupRandomCode = RandomStringUtils.randomAlphabetic(9).toUpperCase();
155        waitAndTypeByName("document.documentHeader.documentDescription","New Paramater " + groupRandomCode);
156        waitAndTypeByName("document.documentHeader.organizationDocumentNumber","7777777");
157        waitAndSelectByName("document.newMaintainableObject.namespaceCode", "KR-SAP - Sample App");
158        waitAndTypeByName("document.newMaintainableObject.componentCode", "TestComponent");
159        waitAndTypeByName("document.newMaintainableObject.name", "Parameter" + groupRandomCode);
160        waitAndTypeByName("document.newMaintainableObject.description", "Description " + groupRandomCode);
161        waitAndSelectByName("document.newMaintainableObject.parameterTypeCode", "Config");
162        waitAndClickByXpath(
163                "//input[@type='radio' and @id='document.newMaintainableObject.evaluationOperatorCodeAllowed' and @value='A']");
164        parameterDocId = driver.findElement(By.xpath("//div[@id='headerarea']/div/table/tbody/tr[1]/td[1]")).getText();
165
166        // Add an acknowledgement request for user1 so we can search by viewer
167        waitAndClickByName("methodToCall.toggleTab.tabAdHocRecipients");
168        waitAndSelectByName("newAdHocRoutePerson.actionRequested", "ACKNOWLEDGE");
169        waitAndTypeByName("newAdHocRoutePerson.id", "user1");
170        WebDriverUtils.jGrowl(getDriver(), "Click Add Person", false, "Click Add Person");
171        waitAndClickByName("methodToCall.insertAdHocRoutePerson");
172
173        selectOptionByName("newAdHocRouteWorkgroup.actionRequested", "ACKNOWLEDGE");
174        waitAndTypeByName("newAdHocRouteWorkgroup.recipientName", groupName);
175        waitAndTypeByName("newAdHocRouteWorkgroup.recipientNamespaceCode", "KR-BUS");
176        WebDriverUtils.jGrowl(getDriver(), "Click Add Group", false, "Click Add Group");
177        waitAndClickByName("methodToCall.insertAdHocRouteWorkgroup");
178
179        waitAndClickByXpath("//input[@name='methodToCall.route']");
180    }
181
182    private void searchByDocumentType() throws Exception {
183        selectFrameIframePortlet();
184        waitAndTypeByName("documentTypeName","ParameterMaintenanceDocument");
185        waitAndTypeByName("rangeLowerBoundKeyPrefix_dateCreated","03/24/2000");
186        waitAndClickByXpath("//td/input[@type='image' and @name='methodToCall.search']");
187        waitForTextPresent("Parameter Maintenance Document");
188        waitAndClickByName("methodToCall.clearValues");
189    }
190    
191    private void searchByInitiator() throws Exception {
192        selectFrameIframePortlet();
193        waitAndTypeByName("initiatorPrincipalName","admin");
194        waitAndClickByXpath("//td/input[@type='image' and @name='methodToCall.search']");
195        waitForTextPresent("items retrieved");
196        waitForElementPresentByXpath("//a[contains(text(),'admin, admin')]");
197        waitAndClickByName("methodToCall.clearValues");
198    }
199
200    private void searchByApprover() throws Exception {
201        selectFrameIframePortlet();
202        waitAndTypeByName("approverPrincipalName", "admin");
203        waitAndClickByXpath("//td/input[@type='image' and @name='methodToCall.search']");
204        waitForTextPresent("items retrieved");
205        waitForTextPresent("Group - Group");
206        waitAndClickByName("methodToCall.clearValues");
207    }
208
209    private void searchByViewer() throws Exception {
210        waitAndTypeByName("viewerPrincipalName","user1");
211        clearTextByName("approverPrincipalName");
212        waitAndTypeByName("rangeLowerBoundKeyPrefix_dateCreated","03/24/2000");
213        waitAndClickByXpath("//td/input[@type='image' and @name='methodToCall.search']");
214        waitForTextPresent("items retrieved");
215        waitForTextPresent("Parameter Maintenance Document");
216        waitForTextPresent("Group - Group");
217        waitAndClickByName("methodToCall.clearValues");
218    }
219    
220    private void searchByGroupViewer() throws Exception {
221        waitAndClickByXpath("//input[@type='image' and @alt='Search Group Viewer Id']");
222        selectFrameIframePortlet();
223        waitAndTypeByName("id",groupId);
224        waitAndClickByXpath("//td/input[@type='image' and @name='methodToCall.search']");
225        waitAndClickLinkContainingText("return value");
226        selectFrameIframePortlet();
227        waitAndTypeByName("rangeLowerBoundKeyPrefix_dateCreated","03/24/2000");
228        waitAndClickByXpath("//td/input[@type='image' and @name='methodToCall.search']");
229        waitForTextPresent("Parameter Maintenance Document");
230        waitForElementPresentByXpath("//a[contains(text(),'admin, admin')]");
231        waitAndClickByName("methodToCall.clearValues");
232    }
233    
234    private void searchByDocumentId() throws Exception {
235        waitAndTypeByName("documentId", parameterDocId);
236        waitAndClickByXpath("//td/input[@type='image' and @name='methodToCall.search']");
237        waitForElementPresentByXpath("//a[contains(text(),parameterDocId)]");
238        waitForTextPresent("Parameter Maintenance Document");
239        waitAndClickByName("methodToCall.clearValues");
240    }
241    
242    private void searchByApplicationDocumentId() throws Exception {
243        waitAndTypeByName("applicationDocumentId","7777777");
244        waitAndClickByXpath("//td/input[@type='image' and @name='methodToCall.search']");
245        waitForElementPresentByXpath("//a[contains(text(),parameterDocId)]");
246        waitForTextPresent("Parameter Maintenance Document");
247        waitAndClickByName("methodToCall.clearValues");
248    }
249    
250    private void searchByDocumentStatus() throws Exception {
251        selectByName("statusCode","Successful Statuses");
252        waitAndClickByXpath("//td/input[@type='image' and @name='methodToCall.search']");
253        waitForTextPresent("PROCESSED");
254        waitForTextPresent("FINAL");
255        waitAndClickByName("methodToCall.clearValues");
256    }
257    
258    private void searchByDateCreatedFrom() throws Exception {
259        waitAndTypeByName("rangeLowerBoundKeyPrefix_dateCreated","04/17/2005");
260        waitAndClickByXpath("//td/input[@type='image' and @name='methodToCall.search']");
261        waitForTextPresent("items retrieved");
262        waitAndClickByName("methodToCall.clearValues");
263    }
264    
265    private void searchByDateCreatedTo() throws Exception {
266        waitAndTypeByName("dateCreated", todayDate);
267        waitAndClickByXpath("//td/input[@type='image' and @name='methodToCall.search']");
268        waitForTextPresent("items retrieved");
269        waitAndClickByName("methodToCall.clearValues");
270
271        // At the time this test was updated, there were no old documents in the testing data.
272        // If that changes, this test will also need to be updated.
273        waitAndTypeByName("dateCreated","04/17/2014");
274        waitAndClickByXpath("//td/input[@type='image' and @name='methodToCall.search']");
275        waitForTextPresent("No values match this search.");
276        waitAndClickByName("methodToCall.clearValues");
277    }
278    
279    private void searchByDateApprovedFrom() throws Exception {
280        waitAndTypeByName("rangeLowerBoundKeyPrefix_dateApproved","04/17/2005");
281        waitAndClickByXpath("//td/input[@type='image' and @name='methodToCall.search']");
282        waitForTextPresent("items retrieved");
283        waitAndClickByName("methodToCall.clearValues");
284    }
285    
286    private void searchByDateApprovedTo() throws Exception {
287        waitAndTypeByName("dateApproved", todayDate);
288        waitAndClickByXpath("//td/input[@type='image' and @name='methodToCall.search']");
289        waitForTextPresent("items retrieved");
290        waitAndClickByName("methodToCall.clearValues");
291
292        // At the time this test was updated, there were no old documents in the testing data.
293        // If that changes, this test will also need to be updated.
294        waitAndTypeByName("dateApproved","04/17/2014");
295        waitAndClickByXpath("//td/input[@type='image' and @name='methodToCall.search']");
296        waitForTextPresent("No values match this search.");
297        waitAndClickByName("methodToCall.clearValues");
298    }
299    
300    private void searchByDateLastModifiedFrom() throws Exception {
301        waitAndTypeByName("rangeLowerBoundKeyPrefix_dateLastModified","04/17/2005");
302        waitAndClickByXpath("//td/input[@type='image' and @name='methodToCall.search']");
303        waitForTextPresent("items retrieved");
304        waitAndClickByName("methodToCall.clearValues");
305    }
306 
307    private void searchByDateLastModifiedTo() throws Exception {
308        waitAndTypeByName("dateLastModified", todayDate);
309        waitAndClickByXpath("//td/input[@type='image' and @name='methodToCall.search']");
310        waitForTextPresent("items retrieved");
311        waitAndClickByName("methodToCall.clearValues");
312
313        // At the time this test was updated, there were no old documents in the testing data.
314        // If that changes, this test will also need to be updated.
315        waitAndTypeByName("dateLastModified","04/17/2014");
316        waitAndClickByXpath("//td/input[@type='image' and @name='methodToCall.search']");
317        waitForTextPresent("No values match this search.");
318        waitAndClickByName("methodToCall.clearValues");
319    }
320    
321    private void searchByDateLastFinalizedFrom() throws Exception {
322        waitAndTypeByName("rangeLowerBoundKeyPrefix_dateFinalized","04/17/2005");
323        waitAndClickByXpath("//td/input[@type='image' and @name='methodToCall.search']");
324        waitForTextPresent("items retrieved");
325        waitAndClickByName("methodToCall.clearValues");
326    }
327
328    private void searchByDateLastFinalizedTo() throws Exception {
329        waitAndTypeByName("dateFinalized", todayDate);
330        waitAndClickByXpath("//td/input[@type='image' and @name='methodToCall.search']");
331        waitForTextPresent("items retrieved");
332        waitAndClickByName("methodToCall.clearValues");
333
334        // At the time this test was updated, there were no old documents in the testing data.
335        // If that changes, this test will also need to be updated.
336        waitAndTypeByName("dateFinalized","04/17/2014");
337        waitAndClickByXpath("//td/input[@type='image' and @name='methodToCall.search']");
338        waitForTextPresent("No values match this search.");
339        waitAndClickByName("methodToCall.clearValues");
340    }
341    
342    private void searchByTitle() throws Exception {
343        waitAndTypeByName("title","New ParameterBo - New Paramater*");
344        waitAndTypeByName("rangeLowerBoundKeyPrefix_dateCreated","03/24/2000");
345        waitAndClickByXpath("//td/input[@type='image' and @name='methodToCall.search']");
346        waitForTextPresent("New ParameterBo - New Paramater " + groupRandomCode);
347        waitAndClickByName("methodToCall.clearValues");
348    }
349}