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 IUeDocLiteXMLIngestNavIT extends AdminTmplMthdSTNavBase {
032 // values set by default for repeatable testing; left as configurable for load tests
033 private List<File> fileUploadList;
034
035 private void setUpFiles() throws Exception {
036 fileUploadList = new ArrayList<File>();
037 // Load the directory as a resource
038 // Turn the resource into a File object
039
040 File dir = new File("src/it/resources/IU");
041
042 if (dir != null && dir.listFiles().length > 0) {
043 Integer i = 1;
044 for (File file : dir.listFiles()) {
045 if (file.getName().endsWith(".xml")) {
046 if (!file.getName().equalsIgnoreCase("sample-app-config.xml"))
047 fileUploadList.add(file);
048 }
049 i++;
050 }
051 Collections.sort(fileUploadList);
052 } else {
053 throw new Exception("----Resources not found----");
054 }
055 }
056
057 @Test
058 public void test() throws Exception {
059 try {
060 setUpFiles();
061 } catch (Exception e) {
062 Assert.fail("Resources not found. Test will be skipped");
063 }
064 testXMLIngesterSuccessfulFileUpload();
065
066 Thread.sleep(2000);
067 driver.switchTo().defaultContent();
068 waitAndClickByLinkText("Main Menu");
069 waitAndClickByLinkText("eDoc Lite");
070
071 driver.switchTo().frame("iframeportlet");
072 waitAndClick(By.cssSelector("td.infoline > input[name=\"methodToCall.search\"]"));
073 Thread.sleep(2000);
074
075 driver.switchTo().defaultContent();
076
077 waitAndClickLogout();
078 passed();
079 }
080
081 /**
082 * Uploads file available from fileUploadList through XML Ingester.
083 * Uploads each sublist from main fileUploadList if size greater than 10.
084 *
085 */
086 public void testXMLIngesterSuccessfulFileUpload() throws Exception {
087 gotoMenuLinkLocator();
088 if (fileUploadList != null && !fileUploadList.isEmpty()) {
089
090 if (fileUploadList.size() > 10) {
091 List<List<File>> subLists = getSubListsForFile(fileUploadList, 10);
092 for (List<File> fileSet : subLists) {
093 fileIngester(fileSet);
094 for (File file : fileSet) {
095 assertTextPresent("Ingested xml doc: " + file.getName());
096 }
097 }
098 } else {
099 fileIngester(fileUploadList);
100 }
101 }
102 }
103
104 /**
105 * This overridden method ...
106 *
107 * @see edu.samplu.common.NavTemplateMethodSTBase#getLinkLocator()
108 */
109 @Override
110 protected String getLinkLocator() {
111
112 return "XML Ingester";
113 }
114
115 /**
116 * Performs Ingesting files to fileupload component and asserts succesful ingestion.
117 *
118 */
119 private void fileIngester(List<File> fileToUpload) throws Exception {
120 int cnt = 0;
121 for (File file : fileToUpload) {
122 String path = file.getAbsolutePath().toString();
123 driver.findElement(By.name("file[" + cnt + "]")).sendKeys(path);
124 cnt++;
125 }
126 waitAndClickByXpath("//*[@id='imageField']");
127 Thread.sleep(1000);
128 // confirm all files were uploaded successfully
129 }
130
131 /**
132 * Divides fileUploadList from resources into sublists to match the maximum number of file
133 * upload components available on XML Ingester Screen
134 *
135 */
136 private List<List<File>> getSubListsForFile(List<File> fileList, final int L) {
137 List<List<File>> subLists = new ArrayList<List<File>>();
138 final int N = fileList.size();
139 for (int i = 0; i < N; i += L) {
140 subLists.add(new ArrayList<File>(fileList.subList(i, Math.min(N, i + L))));
141 }
142 return subLists;
143 }
144 }