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 setUpResourceDir(String resourceDir) {
79 try {
80 setUpFiles("src/it/resources/" + resourceDir);
81 } catch (Exception e) {
82 failableFail("Files not found. If running from Intellij make sure working directory is rice-middleware/sampleapp");
83 }
84 }
85
86 protected void setUpFiles(String path) throws Exception {
87 fileUploadList = new ArrayList<File>();
88
89
90
91 File dir = new File(path);
92
93 if (dir != null && dir.listFiles().length > 0) {
94 Integer i = 1;
95 for (File file : dir.listFiles()) {
96 if (file.getName().endsWith(".xml")) {
97 if (!file.getName().equalsIgnoreCase("sample-app-config.xml"))
98 fileUploadList.add(file);
99 }
100 i++;
101 }
102 Collections.sort(fileUploadList);
103 } else {
104 throw new Exception("----Resources not found----");
105 }
106 }
107
108 protected void testEdocLiteIngestion() throws Exception {
109 testXMLIngesterSuccessfulFileUpload();
110
111 Thread.sleep(2000);
112 driver.switchTo().defaultContent();
113 waitAndClickByLinkText("Main Menu");
114 waitAndClickByLinkText("eDoc Lite");
115
116 selectFrameIframePortlet();
117 waitIsVisible(By.cssSelector("input.tinybutton:nth-child(1)"));
118 waitAndClick(By.cssSelector("input.tinybutton:nth-child(1)"));
119 Thread.sleep(2000);
120 driver.switchTo().defaultContent();
121 Thread.sleep(1000);
122 waitIsVisible(By.className("exportlinks"));
123 selectFrameIframePortlet();
124 }
125
126
127
128
129
130
131 public void testXMLIngesterSuccessfulFileUpload() throws Exception {
132 if (fileUploadList == null && fileUploadList.isEmpty()) {
133 return;
134 }
135 if (fileUploadList.size() > 10) {
136 List<List<File>> subLists = getSubListsForFile(fileUploadList, 10);
137 for (List<File> fileSet : subLists) {
138 fileIngester(fileSet);
139 for (File file : fileSet) {
140 checkMessages(file);
141 }
142 }
143 } else {
144 fileIngester(fileUploadList);
145 }
146 }
147
148 private void checkMessages(File file) throws InterruptedException {
149 waitIsVisible(By.className("error"));
150 if (!isTextPresent("without allowOverwrite set")) {
151
152 assertTextPresent("Ingested xml doc: " + file.getName());
153 }
154 }
155 }