1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
42
43
44
45 public class OAAeDocLiteXMLIngestLegacyIT extends AdminMenuLegacyITBase {
46
47 private List<File> fileUploadList;
48
49 private void setUpFiles() throws Exception {
50 fileUploadList = new ArrayList<File>();
51
52
53
54 File dir = new File("src/it/resources/OAA");
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
91
92
93
94
95
96
97
98
99 driver.switchTo().defaultContent();
100
101 waitAndClickByXpath("//input[@name='imageField' and @value='Logout']");
102 passed();
103
104 }
105
106
107
108
109
110
111
112 public void testXMLIngesterSuccessfulFileUpload() throws Exception {
113 gotoMenuLinkLocator();
114 if (fileUploadList != null && !fileUploadList.isEmpty()) {
115
116 if (fileUploadList.size() > 10) {
117 List<List<File>> subLists = getSubListsForFile(fileUploadList, 10);
118 for (List<File> fileSet : subLists) {
119 fileIngester(fileSet);
120 }
121 } else {
122 fileIngester(fileUploadList);
123 }
124 }
125
126 }
127
128
129
130
131
132
133 @Override
134 protected String getLinkLocator() {
135
136 return "XML Ingester";
137 }
138
139
140
141
142
143 private void fileIngester(List<File> fileToUpload) throws Exception {
144 int cnt = 0;
145 for (File file : fileToUpload) {
146 String path = file.getAbsolutePath().toString();
147 driver.findElement(By.name("file[" + cnt + "]")).sendKeys(path);
148 cnt++;
149 }
150 waitAndClickByXpath("//*[@id='imageField']");
151 Thread.sleep(2000);
152
153 for (File file : fileToUpload) {
154 assertTextPresent("Ingested xml doc: " + file.getName());
155
156 }
157 }
158
159
160
161
162
163
164 private List<List<File>> getSubListsForFile(List<File> fileList, final int L) {
165 List<List<File>> subLists = new ArrayList<List<File>>();
166 final int N = fileList.size();
167 for (int i = 0; i < N; i += L) {
168 subLists.add(new ArrayList<File>(fileList.subList(i, Math.min(N, i + L))));
169 }
170 return subLists;
171 }
172
173 }