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 org.kuali.rice.krad.demo.travel.application; 017 018import org.apache.commons.lang.RandomStringUtils; 019import org.junit.Test; 020import org.kuali.rice.testtools.selenium.WebDriverLegacyITBase; 021import org.kuali.rice.testtools.selenium.WebDriverUtils; 022 023/** 024 * @author Kuali Rice Team (rice.collab@kuali.org) 025 */ 026public class DemoTravelCompanyCompletionRequestAft extends WebDriverLegacyITBase { 027 028 /** 029 * /kr-krad/maintenance?methodToCall=start&dataObjectClassName=edu.sampleu.travel.dataobject.TravelCompany 030 */ 031 public static final String BOOKMARK_URL = "/kr-krad/maintenance?methodToCall=start&dataObjectClassName=edu.sampleu.travel.dataobject.TravelCompany"; 032 033 private static final String DOC_HANDLER_URL = "/kew/DocHandler.do?command=displayDocSearchView&docId="; 034 private static final String USER1_PRINCIPAL_NAME = "user1"; 035 private static final String ADMIN_PRINCIPAL_NAME = "admin"; 036 037 private static final String FINAL = "FINAL"; 038 private static final String CANCELED = "CANCELED"; 039 040 private static final String COMPLETE = "Complete"; 041 private static final String UCANCEL = "ucancel"; 042 private static final String CANCEL = "Cancel"; 043 private static final String APPROVE = "Approve"; 044 private static final String DISAPPROVE = "Disapprove"; 045 private static final String BLANKET_APPROVE = "Blanket Approve"; 046 private static final String SUPER_USER_ACTIONS = "Super User Actions"; 047 048 public static final String DESCRIPTION_FIELD = "document.documentHeader.documentDescription"; 049 public static final String COMPANY_NAME_FIELD = "document.newMaintainableObject.dataObject.travelCompanyName"; 050 051 @Override 052 public String getBookmarkUrl() { 053 return BOOKMARK_URL; 054 } 055 056 protected void navigate() throws Exception { 057 waitAndClickDemoLink(); 058 waitAndClickByLinkText("Travel Company Lookup"); 059 waitAndClickByLinkText("Create New"); 060 } 061 062 @Override 063 public String getUserName() { 064 if ((testName.getMethodName().equals("testDemoTravelCompanyCompletionRequestForAdminBookmark"))|| 065 (testName.getMethodName().equals("testDemoTravelCompanyCompletionRequestForAdminNav"))) { 066 return USER1_PRINCIPAL_NAME; 067 } else { 068 return super.getUserName(); 069 } 070 } 071 072 private void openTravelCompanyDoc(String documentNumber, String principalName) throws Exception { 073 open(getBaseUrlString() + "/portal.do"); 074 impersonateUser(principalName); 075 076 open(getBaseUrlString() + DOC_HANDLER_URL + documentNumber); 077 } 078 079 protected void travelAccountCreateDocument(String principalName) throws Exception { 080 waitAndTypeByName(DESCRIPTION_FIELD,"Travel Company Super User Test"); 081 String randomCode = RandomStringUtils.randomAlphabetic(9).toUpperCase(); 082 waitAndTypeByName(COMPANY_NAME_FIELD, "Company Name " + randomCode); 083 084 waitAndClickByLinkText("Ad Hoc Recipients"); 085 waitAndTypeByName("newCollectionLines['document.adHocRoutePersons'].actionRequested", "Complete"); 086 waitAndTypeByName("newCollectionLines['document.adHocRoutePersons'].id", principalName); 087 jGrowl("Click Add button"); 088 waitAndClickById("Uif-AdHocPersonCollection_add"); 089 waitForElementPresentByXpath( 090 "//div[@data-parent=\"Uif-AdHocPersonCollection\"]/div/span[contains(text(), principalName]"); 091 waitAndClickByLinkText("Ad Hoc Recipients"); 092 093 waitAndClickSubmitByText(); 094 waitAndClickConfirmSubmitOk(); 095 waitForProgress("Loading...", WebDriverUtils.configuredImplicityWait() * 4); 096 waitForTextPresent("Document was successfully submitted.", WebDriverUtils.configuredImplicityWait() * 2); 097 } 098 099 protected void testDemoTravelCompanyCompletionRequestForAdmin() throws Exception { 100 String documentNumber = waitForDocIdKrad(); 101 102 travelAccountCreateDocument(ADMIN_PRINCIPAL_NAME); 103 104 openTravelCompanyDoc(documentNumber, ADMIN_PRINCIPAL_NAME); 105 106 //Make sure the document can be edited 107 waitAndTypeByName(COMPANY_NAME_FIELD, " Extra"); 108 109 // Admin is a super user but the approve and disapprove buttons will not 110 // be shown since the completion request was for Admin 111 Thread.sleep(3000); 112 waitAndClickByLinkText(SUPER_USER_ACTIONS); 113 verifyButtons(); 114 waitAndClickButtonByText(COMPLETE); 115 waitForProgress("Loading...", WebDriverUtils.configuredImplicityWait() * 8); 116 117 ReloadAndCheckDocStatus(FINAL); 118 } 119 120 protected void testDemoTravelCompanyCompletionRequestForUser1() throws Exception { 121 String documentNumber = waitForDocIdKrad(); 122 123 travelAccountCreateDocument(USER1_PRINCIPAL_NAME); 124 125 // Admin is a super user so the approve and disapprove buttons should be shown to Admin but not to user1 126 waitAndClickByLinkText(SUPER_USER_ACTIONS); 127 waitForTextPresent(APPROVE); 128 waitForTextPresent(DISAPPROVE); 129 130 openTravelCompanyDoc(documentNumber, USER1_PRINCIPAL_NAME); 131 132 //Make sure the document can be edited 133 waitAndTypeByName(COMPANY_NAME_FIELD, " Extra"); 134 135 assertTextNotPresent(SUPER_USER_ACTIONS); 136 verifyButtons(); 137 138 waitAndClickButtonByText(COMPLETE); 139 waitForProgress("Loading...", WebDriverUtils.configuredImplicityWait() * 8); 140 141 ReloadAndCheckDocStatus(FINAL); 142 } 143 144 protected void testDemoTravelCompanyCompletionRequestForUser1Cancel() throws Exception { 145 String documentNumber = waitForDocIdKrad(); 146 147 travelAccountCreateDocument(USER1_PRINCIPAL_NAME); 148 149 openTravelCompanyDoc(documentNumber, USER1_PRINCIPAL_NAME); 150 151 Thread.sleep(2000); 152 verifyButtons(); 153 154 waitAndClickById(UCANCEL); 155 waitAndClickByXpath("//div[@data-parent='ConfirmCancelDialog']/button[contains(text(),'OK')]"); 156 Thread.sleep(2000); 157 158 openTravelCompanyDoc(documentNumber, USER1_PRINCIPAL_NAME); 159 assertTextPresent(CANCELED); 160 } 161 162 private void ReloadAndCheckDocStatus(String docStatus) throws Exception { 163 waitAndClickButtonByText("Reload"); 164 waitForProgressLoading(); 165 waitForTextPresent("Document was successfully reloaded."); 166 assertTextPresent(docStatus); 167 } 168 169 private void verifyButtons() throws Exception { 170 Thread.sleep(3000); 171 assertTextNotPresent(APPROVE); 172 assertTextNotPresent(DISAPPROVE); 173 assertTextNotPresent(BLANKET_APPROVE); 174 assertTextPresent(CANCEL); 175 assertTextPresent(COMPLETE); 176 } 177 178 @Test 179 public void testDemoTravelCompanyCompletionRequestForUser1Bookmark() throws Exception { 180 testDemoTravelCompanyCompletionRequestForUser1(); 181 passed(); 182 } 183 184 @Test 185 public void testDemoTravelCompanyCompletionRequestForUser1Nav() throws Exception { 186 testDemoTravelCompanyCompletionRequestForUser1(); 187 passed(); 188 } 189 190 @Test 191 public void testDemoTravelCompanyCompletionRequestForAdminBookmark() throws Exception { 192 testDemoTravelCompanyCompletionRequestForAdmin(); 193 passed(); 194 } 195 196 @Test 197 public void testDemoTravelCompanyCompletionRequestForAdminNav() throws Exception { 198 testDemoTravelCompanyCompletionRequestForAdmin(); 199 passed(); 200 } 201 202 @Test 203 public void testDemoTravelCompanyCompletionRequestForUser1CancelBookmark() throws Exception { 204 testDemoTravelCompanyCompletionRequestForUser1Cancel(); 205 passed(); 206 } 207 208 @Test 209 public void testDemoTravelCompanyCompletionRequestForUser1CancelNav() throws Exception { 210 testDemoTravelCompanyCompletionRequestForUser1Cancel(); 211 passed(); 212 } 213}