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.FreemarkerUtil;
21 import edu.samplu.common.ITUtil;
22 import freemarker.cache.ClassTemplateLoader;
23 import freemarker.template.Configuration;
24 import org.openqa.selenium.By;
25
26 import java.io.File;
27 import java.io.IOException;
28 import java.util.ArrayList;
29 import java.util.List;
30 import java.util.Properties;
31
32
33
34
35
36
37
38 public abstract class XMLIngesterAbstractSmokeTestBase extends FreemarkerSTBase {
39
40
41
42
43 public static final String BOOKMARK_URL = ITUtil.PORTAL + "?channelTitle=XML%20Ingester&channelUrl="
44 + ITUtil.getBaseUrlString() + "/kew/../core/Ingester.do";
45
46
47 private String PROPS_LOCATION = System.getProperty("xmlingester.props.location", null);
48 private static final String DEFAULT_PROPS_LOCATION = "XML/xmlingester.properties";
49
50
51 private static final String DIR_TMPL = "/XML/";
52 private static final String TMPL_USER_CONTENT = "SimpleUserContent.ftl";
53 private static final String TMPL_GROUP_CONTENT = "SimpleGroupContent.ftl";
54
55
56
57
58
59
60
61 protected abstract File newTempFile(String name) throws IOException;
62
63
64
65
66
67
68 @Override
69 public String getTestUrl() {
70 return ITUtil.PORTAL;
71 }
72
73
74
75
76
77
78 @Override
79 public String getUserName() {
80 return "admin";
81 }
82
83
84
85
86 protected void navigate(Failable failable) throws Exception {
87 selectTopFrame();
88 waitAndClickAdministration(failable);
89 waitForTitleToEqualKualiPortalIndex();
90 waitAndClickXMLIngester(failable);
91 selectFrameIframePortlet();
92 checkForIncidentReport("XML Ingester", failable, "");
93 }
94
95 @Override
96 public void setUp() throws Exception {
97 super.setUp();
98
99 cfg = new Configuration();
100 cfg.setTemplateLoader(new ClassTemplateLoader(getClass().getClassLoader().getClass(), DIR_TMPL));
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 protected void testIngestion(Failable failable) throws Exception {
126 List<File> fileUploadList = buildFileUploadList();
127 int cnt = 0;
128
129 for(File file : fileUploadList) {
130 String path = file.getAbsolutePath().toString();
131 driver.findElement(By.name("file[" + cnt + "]")).sendKeys(path);
132 cnt++;
133 }
134
135 waitAndClickByXpath("//*[@id='imageField']");
136
137
138 for(File file: fileUploadList) {
139 assertTextPresent("Ingested xml doc: " + file.getName());
140 }
141 }
142
143 protected List<File> buildFileUploadList() throws Exception {
144 List<File> fileUploadList = new ArrayList<File>();
145 try {
146
147 Properties props = loadProperties(PROPS_LOCATION, DEFAULT_PROPS_LOCATION);
148 if(props.get("userIncludeDTSinPrefix") != null
149 && "true".equalsIgnoreCase((String) props.get("userIncludeDTSinPrefix"))) {
150 props.setProperty("userPrefix", "" + props.get("userPrefix") + ITUtil.DTS);
151 }
152 systemPropertiesOverride(props, "XMLIngester");
153
154
155 fileUploadList.add(
156 writeTemplateToFile(newTempFile("loadtest-users.xml"), cfg.getTemplate(TMPL_USER_CONTENT), props));
157 fileUploadList.add(
158 writeTemplateToFile(newTempFile("loadtest-group.xml"), cfg.getTemplate(TMPL_GROUP_CONTENT), props));
159 } catch( Exception e) {
160 throw new Exception("Unable to generate files for upload", e);
161 }
162
163 return fileUploadList;
164 }
165 }