View Javadoc

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