View Javadoc
1   /**
2    * Copyright 2005-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.krad.demo.travel.account;
17  
18  import org.apache.commons.io.FileUtils;
19  import org.junit.Rule;
20  import org.junit.Test;
21  import org.junit.rules.TemporaryFolder;
22  import org.kuali.rice.testtools.selenium.AutomatedFunctionalTestUtils;
23  import org.kuali.rice.testtools.selenium.WebDriverLegacyITBase;
24  import org.openqa.selenium.By;
25  
26  import java.io.File;
27  
28  /**
29   * @author Kuali Rice Team (rice.collab@kuali.org)
30   */
31  public class DemoTravelAccountMaintenanceViewPermissionAft extends WebDriverLegacyITBase {
32  
33      /**
34       * /kr-krad/maintenance?methodToCall=start&dataObjectClassName=org.kuali.rice.krad.demo.travel.dataobject.TravelAccount&hideReturnLink=true
35       */
36      public static final String BOOKMARK_URL = "/kr-krad/maintenance?methodToCall=start&dataObjectClassName=org.kuali.rice.krad.demo.travel.dataobject.TravelAccount&hideReturnLink=true";
37  
38      /**
39       * Provider of the temporary folder.
40       */
41      @Rule
42      public TemporaryFolder temporaryFolder = new TemporaryFolder();
43  
44      @Override
45      public String getBookmarkUrl() {
46          return BOOKMARK_URL;
47      }
48  
49      protected void navigate() throws Exception {
50          waitAndClickDemoLink();
51          waitAndClickByLinkText("Travel Account Maintenance (New)");
52      }
53  
54      private void createAndRouteDoc(String user) throws Exception {
55          String docid = waitForElementPresentByXpath(DOC_ID_KRAD_XPATH).getText();
56  
57          String random = AutomatedFunctionalTestUtils.createUniqueDtsPlusTwoRandomCharsNot9Digits();
58          String accountNumber = random.substring(random.length() - 4, random.length());
59          waitAndTypeByName("document.documentHeader.documentDescription", "Travel Account Maintenance AdHoc Recipients Document "
60                  + random);
61          waitAndTypeByName("document.newMaintainableObject.dataObject.number", accountNumber);
62          waitAndTypeByName("document.newMaintainableObject.dataObject.name", random);
63          waitAndClickByXpath("//input[@name='document.newMaintainableObject.dataObject.accountTypeCode' and @value='CAT']");
64  
65          waitAndClickByXpath("//a/span[contains(text(),'Notes and Attachments')]");
66          waitAndTypeByName("newCollectionLines['document.notes'].noteText", "Bonzo!");
67  
68          File file = temporaryFolder.newFile("attachment.oth");
69          FileUtils.writeStringToFile(file, "Testing123");
70          String path = file.getAbsolutePath().toString();
71          waitAndTypeByName("attachmentFile", path);
72          waitAndSelectByName("newCollectionLines['document.notes'].attachment.attachmentTypeCode", "OTH");
73  
74          waitAndClickByXpath("//button[@title='Add a Note']");
75          waitForTextPresent("Bonzo!");
76          assertTextPresent("attachment.oth");
77  
78          waitAndClickByLinkText("Ad Hoc Recipients");
79          waitAndTypeByName("newCollectionLines['document.adHocRoutePersons'].id", user);
80          waitAndClickById("Uif-AdHocPersonCollection_add");
81          waitForElementPresentByXpath("//div[@data-parent=\"Uif-AdHocPersonCollection\"]/div/span[contains(text(), '" + user + "']");
82  
83          submitSuccessfully();
84  
85          open(getBaseUrlString() + "/portal.jsp");
86          impersonateUser(user);
87  
88          open(getBaseUrlString() + "/kr-krad/maintenance?methodToCall=docHandler&docId=" + docid
89                  + "&command=displayActionListView");
90      }
91  
92      protected void testTravelAccountMaintenanceViewPermissionT1() throws Exception {
93          createAndRouteDoc("erin");
94          waitForElementNotPresent(By.xpath("//a/span[contains(text(),'Notes and Attachments')]"));
95          waitForElementNotPresent(By.xpath("//button[contains(text(),'Delete')]"));
96          assertTextNotPresent("Bonzo!");
97          assertTextNotPresent("attachment.oth");
98          waitAndClickButtonByText("Approve");
99      }
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     @Test
111     public void testDemoTravelAccountViewPermissionT2Bookmark() throws Exception {
112         testTravelAccountMaintenanceViewPermissionT2();
113         passed();
114     }
115 
116     @Test
117     public void testDemoTravelAccountViewPermissionT2Nav() throws Exception {
118         testTravelAccountMaintenanceViewPermissionT2();
119         passed();
120     }
121 
122     @Test
123     public void testDemoTravelAccountViewPermissionT1Bookmark() throws Exception {
124         testTravelAccountMaintenanceViewPermissionT1();
125         passed();
126     }
127 
128     @Test
129     public void testDemoTravelAccountViewPermissionT1Nav() throws Exception {
130         testTravelAccountMaintenanceViewPermissionT1();
131         passed();
132     }
133 
134 }