001/**
002 * Copyright 2005-2015 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.workflow;
017
018import org.apache.commons.lang.RandomStringUtils;
019import org.junit.Test;
020import org.kuali.rice.testtools.selenium.AutomatedFunctionalTestUtils;
021import org.kuali.rice.testtools.selenium.WebDriverLegacyITBase;
022import org.kuali.rice.testtools.selenium.WebDriverUtils;
023import org.openqa.selenium.By;
024import org.openqa.selenium.WebDriver;
025
026import java.text.SimpleDateFormat;
027import java.util.Date;
028
029/**
030 * @author Kuali Rice Team (rice.collab@kuali.org)
031 */
032public class DocumentOperationAft extends WebDriverLegacyITBase {
033
034    /**
035     *   AutomatedFunctionalTestUtils.PORTAL+"?channelTitle=Document%20Operation&channelUrl="+ WebDriverUtils
036     *   .getBaseUrlString()+"/kew/DocumentOperation.do";
037     */
038    public static final String BOOKMARK_URL = AutomatedFunctionalTestUtils.PORTAL+"?channelTitle=Document%20Operation&channelUrl="+ WebDriverUtils
039            .getBaseUrlString()+"/kew/DocumentOperation.do";
040
041    private static String documentId = null;
042
043    @Override
044    protected String getBookmarkUrl() {
045        return BOOKMARK_URL;
046    }
047
048    @Override
049    protected void navigate() throws InterruptedException {
050        waitAndClickAdministration();
051        waitAndClickByLinkText("Document Operation");
052    }
053
054    protected void testCreateDocument() throws Exception {
055        waitForPageToLoad();
056        waitAndClickAdministration();
057        waitAndClickByLinkText("Document Type");
058        selectFrameIframePortlet();
059        waitAndClickByXpath("//a[@title='Create a new record']");
060        selectFrameIframePortlet();
061        String randomString = RandomStringUtils.randomAlphabetic(9).toUpperCase();
062        documentId = getTextByXpath("//table[@summary='document header: general information']/tbody/tr/td");
063        waitAndTypeByName("document.documentHeader.documentDescription",randomString);
064        waitAndTypeByName("document.newMaintainableObject.name",randomString);
065        waitAndTypeByName("document.newMaintainableObject.label","Label "+randomString);
066        waitAndClickByName("methodToCall.route");
067        waitForTextPresent("Document was successfully submitted.");
068        selectParentWindow();
069        waitAndClickAdministration();
070        acceptAlertIfPresent();
071        waitForPageToLoad();
072        waitAndClickByLinkText("Document Operation");
073    }
074
075    protected void testDocumentOperation() throws Exception {
076        waitForPageToLoad();
077        selectFrameIframePortlet();
078        if(documentId!=null) {
079            waitAndTypeByName("documentId", documentId);
080            waitAndClickByName("methodToCall.getDocument");
081            waitForElementPresentByXpath("//input[@src='images/buttonsmall_save.gif']");
082            assertTextPresent(
083                    new String[] {"Document Actions", "Queue Document", "Queue Action Invocation", "Document ID:",
084                            documentId});
085        }
086    }
087
088    /**
089     * Tests the document disapprove operation on the document operation screen
090     * @throws Exception if errors while disapproving a document on the document operation screen
091     */
092    protected void testDocumentOperationDisapprove() throws Exception {
093        waitAndClickMainMenu();
094        String docId = createTestEdocLite();
095        if (docId == null || "".equals(docId)) {
096            fail("Returned document id is empty or null!");
097        }
098
099        disapproveDocViaDocOpScreen(docId);
100        validateDocDisapprovedViaRouteLog(docId);
101    }
102
103    /**
104     * Method validates the disapproved status within the document route log.
105     * @param docId the document id
106     * @throws Exception if errors while validating the document status in the route log.
107     */
108    private void validateDocDisapprovedViaRouteLog(String docId) throws Exception {
109        jGrowl("Redirecting to portal screen");
110        driver.get(WebDriverUtils.getBaseUrlString());
111        waitAndClickDocSearch();
112        selectFrameIframePortlet();
113        waitAndTypeByName("documentId", docId);
114        waitAndClickSearch();
115        jGrowl("Clicking Route Log link.");
116        waitAndClickByXpath("//*[@id=\"row\"]/tbody/tr/td[7]/a/img");
117        assertTextPresent("DISAPPROVED");
118    }
119
120    /**
121     * Given an example edoclite document id this method will disapproved the document from the document operations screen
122     * @param docId the document id
123     * @throws Exception if errors while disapproving this document.
124     */
125    private void disapproveDocViaDocOpScreen(String docId) throws Exception {
126        jGrowl("Redirecting to portal screen");
127        driver.get(WebDriverUtils.getBaseUrlString());
128        waitAndClickAdministration();
129        waitAndClickByLinkText("Document Operation");
130        selectFrameIframePortlet();
131        waitAndTypeByName("documentId", docId);
132        waitAndClickByName("methodToCall.getDocument");
133        jGrowl("Clicking Update Radio Button");
134        waitAndClickByXpath("//*[@id=\"kualiForm\"]/table/tbody/tr/td[2]/table[2]/tbody/tr[5]/td[2]/table/tbody/tr[2]/td[2]/input[1]");
135        selectByName("routeHeader.docRouteStatus", "DISAPPROVED");
136
137        jGrowl("Clicking Update Radio on Action Request");
138        waitAndClickByXpath("//*[@id=\"kualiForm\"]/table/tbody/tr/td[2]/table[2]/tbody/tr[6]/td[2]/table/tbody/tr[2]/td[2]/input[1]");
139        jGrowl("Selecting DONE status for action request.");
140        selectByName("actionRequests[0].status", "DONE");
141
142        jGrowl("Clicking delete radio on Action Item");
143        waitAndClickByXpath("//*[@id=\"kualiForm\"]/table/tbody/tr/td[2]/table[2]/tbody/tr[8]/td[2]/table/tbody/tr[2]/td[2]/input[2]");
144
145        jGrowl("Clicking the Save button.");
146        waitAndClickByXpath("//*[@id=\"kualiForm\"]/table/tbody/tr/td[2]/table[2]/tbody/tr[12]/td[2]/table/tbody/tr/th/div/input");
147    }
148
149    /**
150     * Creates an edoclite from the example doctype
151     * @return the document id as a String
152     * @throws Exception if errors while creating the example edoc lite
153     */
154    private String createTestEdocLite() throws Exception {
155        waitAndClickByLinkText("eDoc Lite");
156        selectFrameIframePortlet();
157        waitAndTypeByName("edlName", "eDoc.Example1Doctype");
158        waitAndClickSearch();
159        waitAndClickByLinkText("Create Document");
160        waitAndTypeByName("userName", "Test User");
161        waitAndTypeByName("rqstDate", getDateToday());
162        waitAndSelectByName("campus", "IUPUI");
163        waitAndTypeByName("addText", "This is a sample note.");
164        jGrowl("Click Note Save Button");
165        waitAndClickByXpath("//*[@id=\"edoclite\"]/table[2]/tbody/tr[3]/td[4]/div/img");
166        selectFrameIframePortlet();
167        jGrowl("Getting the document id.");
168        String docId = getText(By.xpath("/html/body/table[2]/tbody/tr/td[2]/table/tbody/tr[4]/td[2]"));
169        jGrowl("Document id is: " + docId);
170        jGrowl("Click Edoc Lite Save Button.");
171        waitAndClickByXpath("//*[@id=\"edoclite\"]/table[3]/tbody/tr/td/input[2]");
172        return docId;
173    }
174
175    @Test
176    public void testDocumentOperationBookmark() throws Exception {
177        testCreateDocument();
178        testDocumentOperation();
179        passed();
180    }
181
182    @Test
183    public void testDocumentOperationNav() throws Exception {
184        testCreateDocument();
185        testDocumentOperation();
186        passed();
187    }
188
189    /**
190     * Test the document disapproval process from the bookmark link
191     * @throws Exception if errors while disapproving a document in the document operation.
192     */
193    @Test
194    public void testDocumentOperationDisapproveBookmark() throws Exception {
195        testDocumentOperationDisapprove();
196        passed();
197    }
198
199    /**
200     * Thest the document disapproval process by navigating to it.
201     * @throws Exception if errors while disapproving a document in the document operation.
202     */
203    @Test
204    public void testDocumentOperationDisapproveNav() throws Exception {
205        testDocumentOperationDisapprove();
206        passed();
207    }
208}