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 IUeDocLiteXMLIngestNavIT 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/IU");
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 @Test
58 public void test() throws Exception {
59 try {
60 setUpFiles();
61 } catch (Exception e) {
62 Assert.fail("Resources not found. Test will be skipped");
63 }
64 testXMLIngesterSuccessfulFileUpload();
65
66 Thread.sleep(2000);
67 driver.switchTo().defaultContent();
68 waitAndClickByLinkText("Main Menu");
69 waitAndClickByLinkText("eDoc Lite");
70
71 driver.switchTo().frame("iframeportlet");
72 waitAndClick(By.cssSelector("td.infoline > input[name=\"methodToCall.search\"]"));
73 Thread.sleep(2000);
74
75 driver.switchTo().defaultContent();
76
77 waitAndClickLogout();
78 passed();
79 }
80
81
82
83
84
85
86 public void testXMLIngesterSuccessfulFileUpload() throws Exception {
87 gotoMenuLinkLocator();
88 if (fileUploadList != null && !fileUploadList.isEmpty()) {
89
90 if (fileUploadList.size() > 10) {
91 List<List<File>> subLists = getSubListsForFile(fileUploadList, 10);
92 for (List<File> fileSet : subLists) {
93 fileIngester(fileSet);
94 for (File file : fileSet) {
95 assertTextPresent("Ingested xml doc: " + file.getName());
96 }
97 }
98 } else {
99 fileIngester(fileUploadList);
100 }
101 }
102 }
103
104
105
106
107
108
109 @Override
110 protected String getLinkLocator() {
111
112 return "XML Ingester";
113 }
114
115
116
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
129 }
130
131
132
133
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 }