001/**
002 * Copyright 2005-2016 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.apache.commons.lang.RandomStringUtils;
019import org.kuali.rice.testtools.selenium.AutomatedFunctionalTestUtils;
020import org.kuali.rice.testtools.selenium.WebDriverUtils;
021
022/**
023 *  @author Kuali Rice Team (rice.collab@kuali.org)
024 */
025public abstract class CampusActionListAftBase extends CampusAftBase {
026
027    /**
028     * AutomatedFunctionalTestUtils.PORTAL+"?channelTitle=Campus&channelUrl="+ WebDriverUtils
029     * .getBaseUrlString()+"/kr/lookup.do?methodToCall=start&businessObjectClassName=org.kuali.rice.location.impl.campus.CampusBo&docFormKey=88888888&returnLocation="+
030     * AutomatedFunctionalTestUtils.PORTAL_URL+ AutomatedFunctionalTestUtils.HIDE_RETURN_LINK;
031     */    
032    public static final String BOOKMARK_URL = AutomatedFunctionalTestUtils.PORTAL+"?channelTitle=Campus&channelUrl="+ WebDriverUtils
033            .getBaseUrlString()+"/kr/lookup.do?methodToCall=start&businessObjectClassName=org.kuali.rice.location.impl.campus.CampusBo&docFormKey=88888888&returnLocation="+
034            AutomatedFunctionalTestUtils.PORTAL_URL+ AutomatedFunctionalTestUtils.HIDE_RETURN_LINK;
035
036    @Override
037    protected String getBookmarkUrl() {
038        return BOOKMARK_URL;
039    }
040
041    private void assertActionListRequestGroup(String userInGroup, String group, String namespace, String actionCode, String beforeState, String afterState) throws InterruptedException {
042        namespaceCode = namespace;
043        String docId = testCreateActionRequestGroup(group, namespace, actionCode);
044        impersonateUser(userInGroup);
045        assertActionList(docId, actionCode, beforeState);
046        assertOutbox(docId, afterState);
047        selectTopFrame();
048    }
049
050    private void assertActionListRequestPerson(String user, String actionType, String beforeState, String afterState) throws Exception {
051        String[][] adhocRequests = new String [][]{{user, actionType}};
052        assertActionListRequestPerson(adhocRequests, beforeState, afterState);
053    }
054
055    private void assertActionListRequestPerson(String[][] adhocRequests, String beforeState, String afterState) throws Exception {
056        String docId = testCreateActionRequestPerson(adhocRequests);
057        impersonateUser(adhocRequests[0][0]);
058        assertActionList(docId, adhocRequests[0][1], beforeState);
059        assertOutbox(docId, afterState);
060        selectTopFrame();
061    }
062
063    protected String testCreateActionRequestGroup(String user, String namespace, String actionType) throws InterruptedException{
064        String docId = testCreateNew();
065        addAdHocRecipientsGroup(new String[]{user, actionType, namespace});
066        checkForDocError();
067        waitAndClickByName("methodToCall.route");
068        waitForProgress("Submitting...");
069
070        reattemptPrimaryKey();
071
072        waitForTextPresent("Document was successfully submitted");
073        waitAndClickByName("methodToCall.close");
074
075        return docId;
076    }
077
078    /**
079     * Creates an Action Request in a users action list.
080     *
081     * Initiates a new maintenance document (Component BO) with added adHoc request to create an action request
082     * in a users action list for the document
083     * @param userActions 2d array containing username, action pairs. (ex: "fred","A")
084     *
085     * @return documentID of the newly initiated document to which the created action request applies.
086     */
087    protected String testCreateActionRequestPerson(String[][] userActions) throws InterruptedException {
088        String docId = testCreateNew();
089        if (!userActions[0][0].isEmpty()){
090            addAdHocRecipientsPerson(userActions);
091        }
092
093        checkForDocError();
094        waitAndClickByName("methodToCall.route");
095        waitForProgress("Submitting...");
096
097        reattemptPrimaryKey();
098
099        waitForTextPresent("Document was successfully submitted");
100        waitAndClickByName("methodToCall.close");
101
102        return docId;
103    }
104
105    private void reattemptPrimaryKey() throws InterruptedException {
106        int attempts = 0;
107        while (hasDocError() && extractErrorText().contains("a record with the same primary key already exists.") &&
108                ++attempts <= 3) {
109            jGrowl("record with the same primary key already exists trying another, attempt: " + attempts);
110            clearTextByName("document.newMaintainableObject.code"); // primary key
111            jiraAwareTypeByName("document.newMaintainableObject.code", RandomStringUtils.randomAlphanumeric(2));
112            waitAndClickByName("methodToCall.route");
113            waitForProgress("Submitting...");
114        }
115    }
116
117    public void testActionListAcknowledgeGroup() throws Exception {
118        assertActionListRequestGroup("fran", "RecipeMasters", "KR-WKFLW", "K", "PROCESSED", "FINAL");
119        passed();
120    }
121
122    /**
123     * tests the Acknowledge ActionRequest.
124     * Creates an Acknowledge request for a user. Then performs the Acknowledge action.
125     * @throws Exception
126     */
127    public void testActionListAcknowledgePerson() throws Exception {
128        assertActionListRequestPerson("erin", "K", "PROCESSED", "FINAL");
129        passed();
130    }
131
132    /**
133     * tests the Acknowledge ActionRequest.
134     * Creates an Acknowledge request for a user and an approve request for a different user.
135     * Then performs the Acknowledge action.
136     * @throws Exception
137     */
138    public void testActionListAcknowledgePerson_WithPendingApprove() throws Exception {
139        String[][] adhocRequests = new String [][]{{"fred","A"},{"fran","K"}};
140        String docId = testCreateActionRequestPerson(adhocRequests);
141        impersonateUser("fran");
142        assertActionList(docId, "K", "ENROUTE");
143        assertOutbox(docId, "ENROUTE");
144        selectTopFrame();
145        passed();
146    }
147
148    /**
149     * tests the Acknowledge ActionRequest.
150     * Creates an Acknowledge request for a user and an approve request for a different user.
151     * Then performs the Acknowledge action.
152     * @throws Exception
153     */
154    public void testActionListAcknowledgePerson_WithPendingAcknowledge() throws Exception {
155        String[][] adhocRequests = new String [][]{{"fred","K"},{"fran","K"}};
156        String docId = testCreateActionRequestPerson(adhocRequests);
157        impersonateUser("fran");
158        assertActionList(docId, "K", "PROCESSED");
159        assertOutbox(docId, "PROCESSED");
160        selectTopFrame();
161        passed();
162    }
163
164    /**
165     * tests the Approve ActionRequest.
166     * Creates an approve request for a user. Then performs the Approve action.
167     * @throws Exception
168     */
169    public void testActionListApprovePerson() throws Exception {
170        assertActionListRequestPerson("fred", "A", "ENROUTE", "FINAL");
171        passed();
172    }
173
174    /**
175     * tests the Approve ActionRequest.
176     * Creates an Approve request for a user and a separate approve request for a different user.
177     * Then performs the first users Approve action.
178     * @throws Exception
179     */
180    public void testActionListApprovePerson_WithPendingApprove() throws Exception {
181        String[][] adhocRequests = new String [][]{{"fred","A"},{"fran","A"}};
182        assertActionListRequestPerson(adhocRequests, "ENROUTE", "ENROUTE");
183        passed();
184    }
185
186    /**
187     * tests the Approve ActionRequest.
188     * Creates an Approve request for a user and a separate approve request for a different user.
189     * Then performs the first users Approve action.
190     * @throws Exception
191     */
192    public void testActionListApprovePerson_WithPendingAcknowledge() throws Exception {
193        String[][] adhocRequests = new String [][]{{"fran","A"},{"fred","K"}};
194        assertActionListRequestPerson(adhocRequests, "ENROUTE", "PROCESSED");
195        passed();
196    }
197
198    public void testActionListApproveGroup() throws Exception {
199        assertActionListRequestGroup("fred", "RecipeMasters", "KR-WKFLW", "A", "ENROUTE", "FINAL");
200        passed();
201    }
202
203    public void testActionListCompleteGroup() throws Exception {
204        assertActionListRequestGroup("dev1", "Kuali Developers", "KUALI", "C", "ENROUTE", "FINAL");
205        passed();
206    }
207
208    /**
209     * tests the complete ActionRequest.
210     * Creates an complete request for a user. Then performs the Complete action.
211     * @throws Exception
212     */
213    public void testActionListCompletePerson() throws Exception {
214        assertActionListRequestPerson("fran", "C", "ENROUTE", "FINAL");
215        passed();
216    }
217
218    public void testActionListCompletePerson_WithPendingAcknowledge() throws Exception {
219        String[][] adhocRequests = new String [][]{{"fran","C"},{"fred","K"}};
220        assertActionListRequestPerson(adhocRequests, "ENROUTE", "PROCESSED");
221        passed();
222    }
223
224    public void testActionListDisapproveGroup() throws Exception {
225        assertActionListRequestGroup("director", "ChickenRecipeMasters", "KR-WKFLW", "D", "ENROUTE", "DISAPPROVED");
226        passed();
227    }
228
229    /**
230     * tests the  ActionRequest.
231     * Creates an approve request for a user. Then performs the Disapprove action.
232     * @throws Exception
233     */
234    public void testActionListDisapprovePerson() throws Exception {
235        assertActionListRequestPerson("fred", "D", "ENROUTE", "DISAPPROVED");
236        passed();
237    }
238
239    public void testActionListFyiGroup() throws Exception {
240        assertActionListRequestGroup("dev2", "Kuali Developers", "KUALI", "F", "FINAL", "FINAL");
241        passed();
242    }
243
244    /**
245     * tests the FYI ActionRequest.
246     * Creates an FYI request for a user. Then performs the FYI action.
247     * @throws Exception
248     */
249    public void testActionListFyiPerson() throws Exception {
250        assertActionListRequestPerson("eric", "F", "FINAL", "FINAL");
251        passed();
252    }
253
254
255
256    public void testActionListCancelPerson() throws Exception {
257        assertActionListRequestGroup("dev2", "Kuali Developers", "KUALI", "F", "FINAL", "FINAL");
258        passed();
259    }
260
261    public void testCampusActionListRecallAndCancel_WithPendingPersonApprove() throws Exception {
262        String user = "erin";
263        String docId = testCreateNew();
264        addAdHocRecipientsPerson(new String[]{user, "A"});
265        submit();
266        recall(true);
267        impersonateUser(user);
268        assertNotInActionList(docId);
269        passed();
270    }
271
272    public void testCampusActionListRecallToActionList_WithPendingPersonApprove() throws Exception {
273        String user = "erin";
274
275        String docId = testCreateNew();
276        addAdHocRecipientsPerson(new String[]{user, "A"});
277        submit();
278        waitForTextPresent("ENROUTE");
279        recall(false);
280        // TODO: new window vs. new tab issue
281        assertActionList(docId, "CR", "SAVED");
282
283        driver.navigate().to(WebDriverUtils.getBaseUrlString() + BOOKMARK_URL);
284        waitAndClickDocSearch();
285        selectFrameIframePortlet();
286        waitAndTypeByName("documentId",docId);
287        waitAndClickByXpath(SEARCH_XPATH);
288        waitForTextPresent("FINAL");
289        passed();
290    }
291
292    public void testCampusActionListCancel_WithPendingPersonApprove()throws Exception {
293        String docId = testCreateNew();
294        addAdHocRecipientsPerson(new String[]{"fred", "A"});
295        waitAndClickByName("methodToCall.cancel");
296        assertDocSearchNoResults(docId);
297        passed();
298    }
299
300    public void testCampusActionListSave_WithPendingPersonApprove() throws Exception {
301        String user = "erin";
302        String docId = testCreateNew();
303        addAdHocRecipientsPerson(new String[]{user, "A"});
304        saveAndReload();
305        waitForTextPresent("SAVED");
306        passed();
307    }
308
309    public void assertCampusActionListSubmit_WithPersonRequest(String user, String action, String state) throws Exception {
310        String[][] userActions = new String [][]{{user, action}};
311        String docId = testCreateNew();
312        if (!userActions[0][0].isEmpty()){
313            addAdHocRecipientsPerson(userActions);
314        }
315
316        checkForDocError();
317        waitAndClickByName("methodToCall.route");
318        waitForProgress("Submitting...");
319
320        reattemptPrimaryKey();
321
322        waitForTextPresent("Document was successfully submitted");
323
324        waitForTextPresent("ENROUTE");
325        waitAndClickByName("methodToCall.reload");
326        waitForTextPresent(state);
327        close();
328    }
329
330    public void testCampusActionListSubmit() throws Exception {
331        assertCampusActionListSubmit_WithPersonRequest("", "", "FINAL");
332        passed();
333    }
334
335    public void testCampusActionListSubmit_WithPendingPersonApprove() throws Exception {
336        assertCampusActionListSubmit_WithPersonRequest("erin", "A", "ENROUTE");
337        passed();
338    }
339
340    public void testCampusActionListSubmit_WithPendingPersonAcknowledge() throws Exception {
341        assertCampusActionListSubmit_WithPersonRequest("erin", "K", "PROCESSED");
342        passed();
343    }
344
345    public void testCampusActionListSubmit_WithPendingPersonFyi() throws Exception {
346        assertCampusActionListSubmit_WithPersonRequest("erin", "F", "FINAL");
347        passed();
348    }
349
350
351}