001 /*
002 * Copyright 2005-2013 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl1.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package edu.samplu.admin.test;
017
018 import java.io.File;
019 import java.util.ArrayList;
020
021 import org.junit.Assert;
022 import org.junit.Test;
023 import org.openqa.selenium.By;
024
025 import java.util.Collections;
026 import java.util.List;
027
028 /**
029 * @author Kuali Rice Team (rice.collab@kuali.org)
030 */
031 public class OAAeDocLiteXMLIngestNavIT extends AdminTmplMthdSTNavBase {
032 // values set by default for repeatable testing; left as configurable for load tests
033 private List<File> fileUploadList;
034
035 @Override
036 public void fail(String message) {
037 Assert.fail(message);
038 }
039
040 private void setUpFiles() throws Exception {
041 fileUploadList = new ArrayList<File>();
042 // Load the directory as a resource
043 // Turn the resource into a File object
044
045 File dir = new File("src/it/resources/OAA");
046
047 if (dir != null && dir.listFiles().length > 0) {
048 Integer i = 1;
049 for (File file : dir.listFiles()) {
050 if (file.getName().endsWith(".xml")) {
051 if (!file.getName().equalsIgnoreCase("sample-app-config.xml"))
052 fileUploadList.add(file);
053 }
054 i++;
055 }
056 Collections.sort(fileUploadList);
057 } else {
058 throw new Exception("----Resources not found----");
059 }
060
061 }
062
063 @Test
064 public void test() throws Exception {
065 try {
066 setUpFiles();
067 } catch (Exception e) {
068 Assert.fail("Resources not found. Test will be skipped");
069 }
070 testXMLIngesterSuccessfulFileUpload();
071
072 Thread.sleep(2000);
073 driver.switchTo().defaultContent();
074 waitAndClickByLinkText("Main Menu");
075 waitAndClickByLinkText("eDoc Lite");
076
077 driver.switchTo().frame("iframeportlet");
078 waitAndClick(By.cssSelector("td.infoline > input[name=\"methodToCall.search\"]"));
079 Thread.sleep(2000);
080
081 /*
082 assertEquals("eDoc.Example1Doctype", driver.findElement(By.xpath("//table[@id='row']/tbody/tr/td[3]"))
083 .getText());
084 assertEquals("InterviewRequest", driver.findElement(By.xpath("//table[@id='row']/tbody/tr[2]/td[3]")).getText());
085 assertEquals("OfferRequest", driver.findElement(By.xpath("//table[@id='row']/tbody/tr[3]/td[3]")).getText());
086 assertEquals("SearchStatus", driver.findElement(By.xpath("//table[@id='row']/tbody/tr[4]/td[3]")).getText());
087 assertEquals("VacancyNotice", driver.findElement(By.xpath("//table[@id='row']/tbody/tr[5]/td[3]")).getText());
088 assertEquals("WaiverRequest", driver.findElement(By.xpath("//table[@id='row']/tbody/tr[6]/td[3]")).getText());
089 */
090 driver.switchTo().defaultContent();
091
092 waitAndClickLogout();
093 passed();
094 }
095
096 /**
097 * Uploads file available from fileUploadList through XML Ingester.
098 * Uploads each sublist from main fileUploadList if size greater than 10.
099 *
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 }