1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
30
31 public class OAAeDocLiteXMLIngestNavIT extends AdminTmplMthdSTNavBase {
32
33 private List<File> fileUploadList;
34
35 private void setUpFiles() throws Exception {
36 fileUploadList = new ArrayList<File>();
37
38
39
40 File dir = new File("src/it/resources/OAA");
41
42 if (dir != null && dir.listFiles().length > 0) {
43 Integer i = 1;
44 for (File file : dir.listFiles()) {
45 if (file.getName().endsWith(".xml")) {
46 if (!file.getName().equalsIgnoreCase("sample-app-config.xml"))
47 fileUploadList.add(file);
48 }
49 i++;
50 }
51 Collections.sort(fileUploadList);
52 } else {
53 throw new Exception("----Resources not found----");
54 }
55
56 }
57
58 @Test
59 public void test() throws Exception {
60 try {
61 setUpFiles();
62 } catch (Exception e) {
63 Assert.fail("Resources not found. Test will be skipped");
64 }
65 testXMLIngesterSuccessfulFileUpload();
66
67 Thread.sleep(2000);
68 driver.switchTo().defaultContent();
69 waitAndClickByLinkText("Main Menu");
70 waitAndClickByLinkText("eDoc Lite");
71
72 driver.switchTo().frame("iframeportlet");
73 waitAndClick(By.cssSelector("td.infoline > input[name=\"methodToCall.search\"]"));
74 Thread.sleep(2000);
75
76
77
78
79
80
81
82
83
84
85 driver.switchTo().defaultContent();
86
87 waitAndClickLogout();
88 passed();
89 }
90
91
92
93
94
95
96 public void testXMLIngesterSuccessfulFileUpload() throws Exception {
97 gotoMenuLinkLocator();
98 if (fileUploadList != null && !fileUploadList.isEmpty()) {
99
100 if (fileUploadList.size() > 10) {
101 List<List<File>> subLists = getSubListsForFile(fileUploadList, 10);
102 for (List<File> fileSet : subLists) {
103 fileIngester(fileSet);
104 }
105 } else {
106 fileIngester(fileUploadList);
107 }
108 }
109 }
110
111 @Override
112 protected String getLinkLocator() {
113
114 return "XML Ingester";
115 }
116
117
118
119
120
121 private void fileIngester(List<File> fileToUpload) throws Exception {
122 int cnt = 0;
123 for (File file : fileToUpload) {
124 String path = file.getAbsolutePath().toString();
125 driver.findElement(By.name("file[" + cnt + "]")).sendKeys(path);
126 cnt++;
127 }
128 waitAndClickByXpath("//*[@id='imageField']");
129 Thread.sleep(2000);
130
131 for (File file : fileToUpload) {
132 assertTextPresent("Ingested xml doc: " + file.getName());
133
134 }
135 }
136
137
138
139
140
141
142 private List<List<File>> getSubListsForFile(List<File> fileList, final int L) {
143 List<List<File>> subLists = new ArrayList<List<File>>();
144 final int N = fileList.size();
145 for (int i = 0; i < N; i += L) {
146 subLists.add(new ArrayList<File>(fileList.subList(i, Math.min(N, i + L))));
147 }
148 return subLists;
149 }
150 }