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 edu.sampleu.main;
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.krad.uif.UifPropertyPaths;
23  import org.kuali.rice.krad.util.KRADConstants;
24  import org.kuali.rice.testtools.selenium.AutomatedFunctionalTestUtils;
25  import org.kuali.rice.testtools.selenium.WebDriverUtils;
26  import org.openqa.selenium.By;
27  
28  import java.io.File;
29  
30  /**
31   * Tests the Notes and Attachments in the People Flow screen.
32   *
33   * @author Kuali Rice Team (rice.collab@kuali.org)
34   */
35  public class PeopleFlowCreateNewNotesAndAttachmentsAft extends PeopleFlowCreateNewAftBase {
36  
37      /**
38       * WebDriverUtils.getBaseUrlString() + "/kr-krad/peopleFlowMaintenance?" +
39       * "viewTypeName=MAINTENANCE&returnLocation=" + AutomatedFunctionalTestUtils.PORTAL_URL_ENCODED  + "&methodToCall=start&" +
40       * "dataObjectClassName=org.kuali.rice.kew.impl.peopleflow.PeopleFlowBo"
41       */
42      public static final String BOOKMARK_URL =  WebDriverUtils.getBaseUrlString() + "/kr-krad/peopleFlowMaintenance?" +
43              "viewTypeName=MAINTENANCE&returnLocation=" + AutomatedFunctionalTestUtils.PORTAL_URL_ENCODED  + "&methodToCall=start&" +
44              "dataObjectClassName=org.kuali.rice.kew.impl.peopleflow.PeopleFlowBo";
45  
46      /**
47       * Provider of the temporary folder.
48       */
49      @Rule
50      public TemporaryFolder temporaryFolder = new TemporaryFolder();
51  
52      private static final String NOTES_AND_ATTACHMENTS_PREFIX = UifPropertyPaths.NEW_COLLECTION_LINES
53              + "['"
54              + KRADConstants.DOCUMENT_PROPERTY_NAME
55              + "."
56              + KRADConstants.NOTES_PROPERTY_NAME
57              + "']";
58  
59      @Override
60      public String getBookmarkUrl() {
61          return BOOKMARK_URL;
62      }
63  
64      /**
65       * Tests adding both the required note and an optional attachment.
66       *
67       * @throws Exception when an error is encountered in the test
68       */
69      @Test
70      public void testPeopleFlowCreateNewNotesAndAttachments_DefaultAttachmentBookmark() throws Exception {
71          testDefaultAttachement();
72      }
73  
74      /**
75       * Tests adding both the required note and an optional attachment.
76       *
77       * @throws Exception when an error is encountered in the test
78       */
79      @Test
80      public void testPeopleFlowCreateNewNotesAndAttachments_DefaultAttachmentNav() throws Exception {
81          navigateToCreateNew();
82  
83          testDefaultAttachement();
84      }
85  
86      protected void testDefaultAttachement() throws Exception {
87          navigateToNotesAndAttachments();
88          waitAndTypeByName(NOTES_AND_ATTACHMENTS_PREFIX + "." + KRADConstants.NOTE_TEXT_PROPERTY_NAME,
89                  "Attachment_Note");
90          waitAndAddAttachment("attachment.txt", "Testing123");
91          waitAndClick(By.cssSelector("button[title='Add a Note']"));
92  
93          waitForTextPresent("Attachment_Note");
94          assertTextPresent("attachment.txt");
95          assertTextNotPresent("Note Text is a required field.");
96          passed();
97      }
98  
99      /**
100      * Tests adding just the required note.
101      *
102      * @throws Exception when an error is encountered in the test
103      */
104     @Test
105     public void testPeopleFlowCreateNewNotesAndAttachments_DefaultNoAttachmentBookmark() throws Exception {
106         testDefaultNoAttachment();
107     }
108 
109     /**
110      * Tests adding just the required note.
111      *
112      * @throws Exception when an error is encountered in the test
113      */
114     @Test
115     public void testPeopleFlowCreateNewNotesAndAttachments_DefaultNoAttachmentNav() throws Exception {
116         navigateToCreateNew();
117 
118         testDefaultNoAttachment();
119     }
120 
121     protected void testDefaultNoAttachment() throws InterruptedException {
122         navigateToNotesAndAttachments();
123         waitAndTypeByName(NOTES_AND_ATTACHMENTS_PREFIX + "." + KRADConstants.NOTE_TEXT_PROPERTY_NAME,
124                 "Attachment_Note");
125         waitAndClick(By.cssSelector("button[title='Add a Note']"));
126 
127         waitForTextPresent("Attachment_Note");
128         assertTextNotPresent("Note Text is a required field");
129         passed();
130     }
131 
132     /**
133      * Tests adding just the optional attachment, which should result in an error.
134      *
135      * @throws Exception when an error is encountered in the test
136      */
137     @Test
138     public void testPeopleFlowCreateNewNotesAndAttachments_NoNoteTextBookmark() throws Exception {
139         testNoNoteText();
140     }
141 
142     /**
143      * Tests adding just the optional attachment, which should result in an error.
144      *
145      * @throws Exception when an error is encountered in the test
146      */
147     @Test
148     public void testPeopleFlowCreateNewNotesAndAttachments_NoNoteTextNav() throws Exception {
149         navigateToCreateNew();
150 
151         testNoNoteText();
152     }
153 
154     protected void testNoNoteText() throws Exception {
155         navigateToNotesAndAttachments();
156         waitAndAddAttachment("attachment.txt", "Testing123");
157         waitAndClick(By.cssSelector("button[title='Add a Note']"));
158 
159         waitForTextPresent("Note Text is a required field");
160         assertTextNotPresent("attachment.txt");
161         passed();
162     }
163 
164     protected void navigateToCreateNew() throws Exception {
165         selectFrameIframePortlet();
166         waitAndClickByLinkText("Create New");
167     }
168 
169     private void navigateToNotesAndAttachments() throws InterruptedException {
170         waitForElementPresent(
171                 "div[data-header_for='PeopleFlow-MaintenanceView'] div[data-label='Document Number'] > span");
172 
173         waitAndClickByLinkText("Notes and Attachments (0)");
174     }
175 
176     private void waitAndAddAttachment(String fileName, String content) throws Exception {
177         File file = temporaryFolder.newFile(fileName);
178         FileUtils.writeStringToFile(file, content);
179         String path = file.getAbsolutePath().toString();
180         waitAndTypeByName("attachmentFile", path);
181     }
182 }