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