View Javadoc
1   /**
2    * Copyright 2005-2015 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')]"), 2);
95          waitForElementNotPresent(By.xpath("//button[contains(text(),'Delete')]"), 0);
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     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 }