1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package edu.samplu.admin.test;
17
18 import edu.samplu.common.Failable;
19 import edu.samplu.common.FreemarkerSTBase;
20 import edu.samplu.common.ITUtil;
21 import edu.samplu.common.PropertiesUtils;
22 import org.openqa.selenium.By;
23
24 import java.io.File;
25 import java.io.IOException;
26 import java.util.ArrayList;
27 import java.util.List;
28 import java.util.Properties;
29
30
31
32
33
34
35
36 public abstract class XMLIngesterAbstractSmokeTestBase extends FreemarkerSTBase {
37
38
39
40
41 public static final String BOOKMARK_URL = ITUtil.PORTAL + "?channelTitle=XML%20Ingester&channelUrl="
42 + ITUtil.getBaseUrlString() + "/kew/../core/Ingester.do";
43
44
45 private String PROPS_LOCATION = System.getProperty("xmlingester.props.location", null);
46 private static final String DEFAULT_PROPS_LOCATION = "XML/xmlingester.properties";
47
48
49 private static final String DIR_TMPL = "/XML/";
50 private static final String TMPL_USER_CONTENT = "SimpleUserContent.ftl";
51 private static final String TMPL_GROUP_CONTENT = "SimpleGroupContent.ftl";
52
53
54
55
56
57
58
59 protected abstract File newTempFile(String name) throws IOException;
60
61
62
63
64
65
66 @Override
67 protected String getTemplateDir() {
68 return DIR_TMPL;
69 }
70
71
72
73
74
75
76 @Override
77 public String getTestUrl() {
78 return ITUtil.PORTAL;
79 }
80
81
82
83
84
85
86 @Override
87 public String getUserName() {
88 return "admin";
89 }
90
91
92
93
94 protected void navigate(Failable failable) throws Exception {
95 selectTopFrame();
96 waitAndClickAdministration(failable);
97 waitForTitleToEqualKualiPortalIndex();
98 waitAndClickXMLIngester(failable);
99 selectFrameIframePortlet();
100 checkForIncidentReport("XML Ingester", failable, "");
101 }
102
103
104
105
106
107
108
109 protected void testIngestionNav(Failable failable) throws Exception {
110 navigate(failable);
111 testIngestion(failable);
112 passed();
113 }
114
115 protected void testIngestionBookmark(Failable failable) throws Exception {
116 testIngestion(failable);
117 passed();
118 }
119
120
121
122
123
124
125
126
127 protected void testIngestion(Failable failable) throws Exception {
128 selectFrameIframePortlet();
129 List<File> fileUploadList = buildFileUploadList();
130 int cnt = 0;
131
132 for(File file : fileUploadList) {
133 String path = file.getAbsolutePath().toString();
134 if (isKrad()){
135 driver.findElement(By.name("files[" + cnt + "]")).sendKeys(path);
136 } else {
137 driver.findElement(By.name("file[" + cnt + "]")).sendKeys(path);
138 }
139 cnt++;
140 }
141
142
143 if (isKrad()){
144 waitAndClickByXpath("//button");
145 } else {
146 waitAndClickByXpath("//*[@id='imageField']");
147 }
148
149
150 Thread.sleep(1000);
151 for(File file: fileUploadList) {
152 assertTextPresent("Ingested xml doc: " + file.getName());
153 }
154 }
155
156 protected List<File> buildFileUploadList() throws Exception {
157 List<File> fileUploadList = new ArrayList<File>();
158 try {
159
160 Properties props = loadProperties(PROPS_LOCATION, DEFAULT_PROPS_LOCATION);
161 if(props.get("userIncludeDTSinPrefix") != null
162 && "true".equalsIgnoreCase((String) props.get("userIncludeDTSinPrefix"))) {
163 props.setProperty("userPrefix", "" + props.get("userPrefix") + ITUtil.DTS);
164 }
165 PropertiesUtils.systemPropertiesOverride(props, "XMLIngester");
166
167
168 fileUploadList.add(
169 writeTemplateToFile(newTempFile("loadtest-users.xml"), cfg.getTemplate(TMPL_USER_CONTENT), props));
170 fileUploadList.add(
171 writeTemplateToFile(newTempFile("loadtest-group.xml"), cfg.getTemplate(TMPL_GROUP_CONTENT), props));
172 } catch( Exception e) {
173 throw new Exception("Unable to generate files for upload", e);
174 }
175
176 return fileUploadList;
177 }
178 }