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