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