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 org.kuali.rice.krad.demo.travel.account; 017 018import org.apache.commons.io.FileUtils; 019import org.junit.Rule; 020import org.junit.Test; 021import org.junit.rules.TemporaryFolder; 022import org.kuali.rice.testtools.selenium.AutomatedFunctionalTestUtils; 023import org.kuali.rice.testtools.selenium.WebDriverLegacyITBase; 024import org.openqa.selenium.By; 025 026import java.io.File; 027 028/** 029 * @author Kuali Rice Team (rice.collab@kuali.org) 030 */ 031public class DemoTravelAccountMaintenanceViewPermissionAft extends WebDriverLegacyITBase { 032 033 /** 034 * /kr-krad/maintenance?methodToCall=start&dataObjectClassName=org.kuali.rice.krad.demo.travel.dataobject.TravelAccount&hideReturnLink=true 035 */ 036 public static final String BOOKMARK_URL = "/kr-krad/maintenance?methodToCall=start&dataObjectClassName=org.kuali.rice.krad.demo.travel.dataobject.TravelAccount&hideReturnLink=true"; 037 038 /** 039 * Provider of the temporary folder. 040 */ 041 @Rule 042 public TemporaryFolder temporaryFolder = new TemporaryFolder(); 043 044 @Override 045 public String getBookmarkUrl() { 046 return BOOKMARK_URL; 047 } 048 049 protected void navigate() throws Exception { 050 waitAndClickDemoLink(); 051 waitAndClickByLinkText("Travel Account Maintenance (New)"); 052 } 053 054 private void createAndRouteDoc(String user) throws Exception { 055 String docid = waitForElementPresentByXpath(DOC_ID_KRAD_XPATH).getText(); 056 057 String random = AutomatedFunctionalTestUtils.createUniqueDtsPlusTwoRandomCharsNot9Digits(); 058 String accountNumber = random.substring(random.length() - 4, random.length()); 059 waitAndTypeByName("document.documentHeader.documentDescription", "Travel Account Maintenance AdHoc Recipients Document " 060 + random); 061 waitAndTypeByName("document.newMaintainableObject.dataObject.number", accountNumber); 062 waitAndTypeByName("document.newMaintainableObject.dataObject.name", random); 063 waitAndClickByXpath("//input[@name='document.newMaintainableObject.dataObject.accountTypeCode' and @value='CAT']"); 064 065 waitAndClickByXpath("//a/span[contains(text(),'Notes and Attachments')]"); 066 waitAndTypeByName("newCollectionLines['document.notes'].noteText", "Bonzo!"); 067 068 File file = temporaryFolder.newFile("attachment.oth"); 069 FileUtils.writeStringToFile(file, "Testing123"); 070 String path = file.getAbsolutePath().toString(); 071 waitAndTypeByName("attachmentFile", path); 072 waitAndSelectByName("newCollectionLines['document.notes'].attachment.attachmentTypeCode", "OTH"); 073 074 waitAndClickByXpath("//button[@title='Add a Note']"); 075 waitForTextPresent("Bonzo!"); 076 assertTextPresent("attachment.oth"); 077 078 waitAndClickByLinkText("Ad Hoc Recipients"); 079 waitAndTypeByName("newCollectionLines['document.adHocRoutePersons'].id", user); 080 waitAndClickById("Uif-AdHocPersonCollection_add"); 081 waitForElementPresentByXpath("//div[@data-parent=\"Uif-AdHocPersonCollection\"]/div/span[contains(text(), '" + user + "']"); 082 083 submitSuccessfully(); 084 085 open(getBaseUrlString() + "/portal.jsp"); 086 impersonateUser(user); 087 088 open(getBaseUrlString() + "/kr-krad/maintenance?methodToCall=docHandler&docId=" + docid 089 + "&command=displayActionListView"); 090 } 091 092 protected void testTravelAccountMaintenanceViewPermissionT1() throws Exception { 093 createAndRouteDoc("erin"); 094 waitForElementNotPresent(By.xpath("//a/span[contains(text(),'Notes and Attachments')]"), 2); 095 waitForElementNotPresent(By.xpath("//button[contains(text(),'Delete')]"), 0); 096 assertTextNotPresent("Bonzo!"); 097 assertTextNotPresent("attachment.oth"); 098 waitAndClickButtonByText("Approve"); 099 } 100 101 protected void testTravelAccountMaintenanceViewPermissionT2() throws Exception { 102 createAndRouteDoc("dev1"); 103 waitAndClickByXpath("//a/span[contains(text(),'Notes and Attachments')]"); 104 assertTextPresent("Bonzo!"); 105 assertTextPresent("attachment.oth"); 106 assertButtonEnabledByText("Download Attachment"); 107 waitAndClickButtonByText("Approve"); 108 } 109 110 protected void testTravelAccountMaintenanceViewPermissionT3() throws Exception { 111 createAndRouteDoc("admin"); 112 113 assertTextPresent("Bonzo!"); 114 assertTextPresent("attachment.oth"); 115 waitForElementNotPresent(By.xpath("//button[contains(text(),'Download Attachment')]"), 0); 116 } 117 118 @Test 119 public void testDemoTravelAccountViewPermissionT2Bookmark() throws Exception { 120 testTravelAccountMaintenanceViewPermissionT2(); 121 passed(); 122 } 123 124 @Test 125 public void testDemoTravelAccountViewPermissionT2Nav() throws Exception { 126 testTravelAccountMaintenanceViewPermissionT2(); 127 passed(); 128 } 129 130 @Test 131 public void testDemoTravelAccountViewPermissionT1Bookmark() throws Exception { 132 testTravelAccountMaintenanceViewPermissionT1(); 133 passed(); 134 } 135 136 @Test 137 public void testDemoTravelAccountViewPermissionT1Nav() throws Exception { 138 testTravelAccountMaintenanceViewPermissionT1(); 139 passed(); 140 } 141 142 @Test 143 public void testDemoTravelAccountViewPermissionT3Bookmark() throws Exception { 144 testTravelAccountMaintenanceViewPermissionT3(); 145 passed(); 146 } 147 148 @Test 149 public void testDemoTravelAccountViewPermissionT3Nav() throws Exception { 150 testTravelAccountMaintenanceViewPermissionT3(); 151 passed(); 152 } 153 154}