1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package edu.samplu.admin.test;
16
17 import org.junit.Assert;
18 import org.openqa.selenium.By;
19
20 import java.io.File;
21 import java.util.ArrayList;
22 import java.util.Collections;
23 import java.util.List;
24
25
26
27
28
29 public abstract class EdocLiteXmlIngesterBase extends AdminTmplMthdSTNavBase {
30
31 protected List<File> fileUploadList;
32
33 @Override
34 public void fail(String message) {
35 Assert.fail(message);
36 }
37
38
39
40
41
42
43 @Override
44 protected String getLinkLocator() {
45 return "XML Ingester";
46 }
47
48
49
50
51
52 private void fileIngester(List<File> fileToUpload) throws Exception {
53 int cnt = 0;
54 for (File file : fileToUpload) {
55 String path = file.getAbsolutePath().toString();
56 driver.findElement(By.name("file[" + cnt + "]")).sendKeys(path);
57 cnt++;
58 }
59 waitAndClickByXpath("//*[@id='imageField']");
60 Thread.sleep(1000);
61
62 }
63
64
65
66
67
68
69 private List<List<File>> getSubListsForFile(List<File> fileList, final int L) {
70 List<List<File>> subLists = new ArrayList<List<File>>();
71 final int N = fileList.size();
72 for (int i = 0; i < N; i += L) {
73 subLists.add(new ArrayList<File>(fileList.subList(i, Math.min(N, i + L))));
74 }
75 return subLists;
76 }
77
78 protected void setUpFiles(String path) throws Exception {
79 fileUploadList = new ArrayList<File>();
80
81
82
83 File dir = new File(path);
84
85 if (dir != null && dir.listFiles().length > 0) {
86 Integer i = 1;
87 for (File file : dir.listFiles()) {
88 if (file.getName().endsWith(".xml")) {
89 if (!file.getName().equalsIgnoreCase("sample-app-config.xml"))
90 fileUploadList.add(file);
91 }
92 i++;
93 }
94 Collections.sort(fileUploadList);
95 } else {
96 throw new Exception("----Resources not found----");
97 }
98 }
99
100 protected void testEdocLiteIngestion() throws Exception {
101 testXMLIngesterSuccessfulFileUpload();
102
103 Thread.sleep(2000);
104 driver.switchTo().defaultContent();
105 waitAndClickByLinkText("Main Menu");
106 waitAndClickByLinkText("eDoc Lite");
107
108 selectFrameIframePortlet();
109 waitIsVisible(By.cssSelector("input.tinybutton:nth-child(1)"));
110 waitAndClick(By.cssSelector("input.tinybutton:nth-child(1)"));
111 Thread.sleep(2000);
112 driver.switchTo().defaultContent();
113 Thread.sleep(1000);
114 waitIsVisible(By.className("exportlinks"));
115 selectFrameIframePortlet();
116 }
117
118
119
120
121
122
123 public void testXMLIngesterSuccessfulFileUpload() throws Exception {
124 if (fileUploadList == null && fileUploadList.isEmpty()) {
125 return;
126 }
127 if (fileUploadList.size() > 10) {
128 List<List<File>> subLists = getSubListsForFile(fileUploadList, 10);
129 for (List<File> fileSet : subLists) {
130 fileIngester(fileSet);
131 for (File file : fileSet) {
132 checkMessages(file);
133 }
134 }
135 } else {
136 fileIngester(fileUploadList);
137 }
138 }
139
140 private void checkMessages(File file) throws InterruptedException {
141 waitIsVisible(By.className("error"));
142 if (!isTextPresent("without allowOverwrite set")) {
143
144 assertTextPresent("Ingested xml doc: " + file.getName());
145 }
146 }
147 }