View Javadoc

1   /*
2    * Copyright 2005-2013 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/ecl1.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.samplu.admin.test;
17  
18  import java.io.File;
19  import java.util.ArrayList;
20  
21  import org.junit.Assert;
22  import org.junit.Test;
23  import org.openqa.selenium.By;
24  
25  import java.util.Collections;
26  import java.util.List;
27  
28  /**
29   * @author Kuali Rice Team (rice.collab@kuali.org)
30   */
31  public class OAAeDocLiteXMLIngestNavIT extends AdminTmplMthdSTNavBase {
32      // values set by default for repeatable testing; left as configurable for load tests
33      private List<File> fileUploadList;
34  
35      private void setUpFiles() throws Exception {
36          fileUploadList = new ArrayList<File>();
37          // Load the directory as a resource
38          // Turn the resource into a File object
39  
40          File dir = new File("src/it/resources/OAA");
41  
42          if (dir != null && dir.listFiles().length > 0) {
43              Integer i = 1;
44              for (File file : dir.listFiles()) {
45                  if (file.getName().endsWith(".xml")) {
46                      if (!file.getName().equalsIgnoreCase("sample-app-config.xml"))
47                          fileUploadList.add(file);
48                  }
49                  i++;
50              }
51              Collections.sort(fileUploadList);
52          } else {
53              throw new Exception("----Resources not found----");
54          }
55  
56      }
57  
58      @Test
59      public void test() throws Exception {
60          try {
61              setUpFiles();
62          } catch (Exception e) {
63              Assert.fail("Resources not found. Test will be skipped");
64          }
65          testXMLIngesterSuccessfulFileUpload();
66  
67          Thread.sleep(2000);
68          driver.switchTo().defaultContent();
69          waitAndClickByLinkText("Main Menu");
70          waitAndClickByLinkText("eDoc Lite");
71  
72          driver.switchTo().frame("iframeportlet");
73          waitAndClick(By.cssSelector("td.infoline > input[name=\"methodToCall.search\"]"));
74          Thread.sleep(2000);
75  
76          /*
77          assertEquals("eDoc.Example1Doctype", driver.findElement(By.xpath("//table[@id='row']/tbody/tr/td[3]"))
78                  .getText());
79          assertEquals("InterviewRequest", driver.findElement(By.xpath("//table[@id='row']/tbody/tr[2]/td[3]")).getText());
80          assertEquals("OfferRequest", driver.findElement(By.xpath("//table[@id='row']/tbody/tr[3]/td[3]")).getText());
81          assertEquals("SearchStatus", driver.findElement(By.xpath("//table[@id='row']/tbody/tr[4]/td[3]")).getText());
82          assertEquals("VacancyNotice", driver.findElement(By.xpath("//table[@id='row']/tbody/tr[5]/td[3]")).getText());
83          assertEquals("WaiverRequest", driver.findElement(By.xpath("//table[@id='row']/tbody/tr[6]/td[3]")).getText());
84         */
85          driver.switchTo().defaultContent();
86  
87          waitAndClickLogout();
88          passed();
89      }
90  
91      /**
92       * Uploads file available from fileUploadList through XML Ingester.
93       * Uploads each sublist from main fileUploadList if size greater than 10. 
94       * 
95       */
96      public void testXMLIngesterSuccessfulFileUpload() throws Exception {
97          gotoMenuLinkLocator();
98          if (fileUploadList != null && !fileUploadList.isEmpty()) {
99  
100             if (fileUploadList.size() > 10) {
101                 List<List<File>> subLists = getSubListsForFile(fileUploadList, 10);
102                 for (List<File> fileSet : subLists) {
103                     fileIngester(fileSet);
104                 }
105             } else {
106                 fileIngester(fileUploadList);
107             }
108         }
109     }
110 
111     @Override
112     protected String getLinkLocator() {
113 
114         return "XML Ingester";
115     }
116 
117     /**
118      * Performs Ingesting files to fileupload component and asserts succesful ingestion.
119      * 
120      */
121     private void fileIngester(List<File> fileToUpload) throws Exception {
122         int cnt = 0;
123         for (File file : fileToUpload) {
124             String path = file.getAbsolutePath().toString();
125             driver.findElement(By.name("file[" + cnt + "]")).sendKeys(path);
126             cnt++;
127         }
128         waitAndClickByXpath("//*[@id='imageField']");
129         Thread.sleep(2000);
130         // confirm all files were uploaded successfully
131         for (File file : fileToUpload) {
132             assertTextPresent("Ingested xml doc: " + file.getName());
133 
134         }
135     }
136 
137     /**
138      * Divides fileUploadList from resources into sublists to match the maximum number of file
139      * upload components available on XML Ingester Screen
140      * 
141      */
142     private List<List<File>> getSubListsForFile(List<File> fileList, final int L) {
143         List<List<File>> subLists = new ArrayList<List<File>>();
144         final int N = fileList.size();
145         for (int i = 0; i < N; i += L) {
146             subLists.add(new ArrayList<File>(fileList.subList(i, Math.min(N, i + L))));
147         }
148         return subLists;
149     }
150 }