1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package edu.sampleu.admin;
17
18 import edu.sampleu.common.FreemarkerAftBase;
19 import freemarker.template.DefaultObjectWrapper;
20 import org.junit.Rule;
21 import org.junit.rules.TemporaryFolder;
22 import org.kuali.rice.testtools.common.JiraAwareFailable;
23 import org.kuali.rice.testtools.common.PropertiesUtils;
24 import org.kuali.rice.testtools.selenium.AutomatedFunctionalTestUtils;
25 import org.kuali.rice.testtools.selenium.WebDriverUtils;
26 import org.openqa.selenium.By;
27
28 import java.io.File;
29 import java.io.IOException;
30 import java.util.ArrayList;
31 import java.util.LinkedList;
32 import java.util.List;
33 import java.util.Properties;
34 import java.util.StringTokenizer;
35
36
37
38
39
40
41
42 public abstract class XmlIngesterAftBase extends FreemarkerAftBase {
43
44
45
46
47 public static final String BOOKMARK_URL = AutomatedFunctionalTestUtils.PORTAL + "?channelTitle=XML%20Ingester&channelUrl="
48 + WebDriverUtils.getBaseUrlString() + "/kew/../core/Ingester.do";
49
50
51 private String PROPS_LOCATION = System.getProperty("xmlingester.props.location", null);
52 private static final String DEFAULT_PROPS_LOCATION = "XML/xmlingester.properties";
53
54
55 private static final String DIR_TMPL = "/XML/";
56 private static final String TMPL_USER_CONTENT = "SimpleUserContent.ftl";
57 private static final String TMPL_GROUP_CONTENT = "SimpleGroupContent.ftl";
58
59 @Rule
60 public TemporaryFolder folder= new TemporaryFolder();
61
62 protected File newTempFile(String name) throws IOException {
63 return folder.newFile(name);
64 }
65
66
67
68
69
70
71 @Override
72 protected String getTemplateDir() {
73 return DIR_TMPL;
74 }
75
76 @Override
77 protected String getBookmarkUrl() {
78 return BOOKMARK_URL;
79 }
80
81
82
83
84
85
86 @Override
87 public String getUserName() {
88 return "admin";
89 }
90
91
92
93
94 @Override
95 protected void navigate() throws Exception {
96 selectTopFrame();
97 waitAndClickAdministration();
98 waitForTitleToEqualKualiPortalIndex();
99 waitAndClickXMLIngester(this);
100 selectFrameIframePortlet();
101 checkForIncidentReport("XML Ingester", this, "");
102 }
103
104 public void testXmlIngesterUserList() throws Exception {
105 List<File> fileUploadList = buildUserFileUploadList();
106 testIngestion(this, fileUploadList);
107 }
108
109
110
111
112
113
114
115 protected void testIngestionNav(JiraAwareFailable failable) throws Exception {
116 List<File> fileUploadList = buildFileUploadList();
117 testIngestion(failable, fileUploadList);
118 passed();
119 }
120
121 protected void testIngestionBookmark(JiraAwareFailable failable) throws Exception {
122 List<File> fileUploadList = buildFileUploadList();
123 testIngestion(failable, fileUploadList);
124 passed();
125 }
126
127
128
129
130
131
132
133
134 protected void testIngestion(JiraAwareFailable failable, List<File> fileUploadList) throws Exception {
135 selectFrameIframePortlet();
136 int cnt = 0;
137
138 for(File file : fileUploadList) {
139 String path = file.getAbsolutePath().toString();
140 if (isKrad()){
141 driver.findElement(By.name("files[" + cnt + "]")).sendKeys(path);
142 } else {
143 driver.findElement(By.name("file[" + cnt + "]")).sendKeys(path);
144 }
145 cnt++;
146 }
147
148
149 if (isKrad()){
150 waitAndClickByXpath("//button");
151 } else {
152 waitAndClickByXpath("//*[@id='imageField']");
153 }
154
155
156 Thread.sleep(1000);
157 for(File file: fileUploadList) {
158 waitForTextPresent("Ingested xml doc: " + file.getName(), 360);
159 }
160 }
161
162 protected List<File> buildFileUploadList() throws Exception {
163 List<File> fileUploadList = new ArrayList<File>();
164 try {
165
166 Properties props = loadProperties(PROPS_LOCATION, DEFAULT_PROPS_LOCATION);
167 if(props.get("userIncludeDTSinPrefix") != null
168 && "true".equalsIgnoreCase((String) props.get("userIncludeDTSinPrefix"))) {
169 props.setProperty("userPrefix", "" + props.get("userPrefix") + AutomatedFunctionalTestUtils.DTS);
170 }
171 props = new PropertiesUtils().systemPropertiesOverride(props, "XMLIngester");
172
173
174 fileUploadList.add(
175 writeTemplateToFile(newTempFile("loadtest-users.xml"), cfg.getTemplate(TMPL_USER_CONTENT), props));
176 fileUploadList.add(
177 writeTemplateToFile(newTempFile("loadtest-group.xml"), cfg.getTemplate(TMPL_GROUP_CONTENT), props));
178 } catch( Exception e) {
179 throw new Exception("Unable to generate files for upload " + e.getMessage(), e);
180 }
181
182 return fileUploadList;
183 }
184
185 protected List<File> buildUserFileUploadList() throws Exception {
186 List<File> fileUploadList = new ArrayList<File>();
187 try {
188 Properties props = loadProperties(PROPS_LOCATION, DEFAULT_PROPS_LOCATION);
189
190 String usersArg = System.getProperty("xmlingester.user.list").replace(".", "").replace("-", "").toLowerCase();
191 List<XmlIngesterUser> xmlIngesterUsers = new LinkedList<XmlIngesterUser>();
192 StringTokenizer token = new StringTokenizer(usersArg, ",");
193 while (token.hasMoreTokens()) {
194 xmlIngesterUsers.add(new XmlIngesterUser(token.nextToken()));
195 }
196
197 props.put("xmlIngesterUsers", xmlIngesterUsers);
198
199 cfg.setObjectWrapper(new DefaultObjectWrapper());
200
201
202 fileUploadList.add(
203 writeTemplateToFile(newTempFile("userlist-users.xml"), cfg.getTemplate("UserListIngestion.ftl"), props));
204
205 } catch( Exception e) {
206 throw new Exception("Unable to generate files for upload " + e.getMessage(), e);
207 }
208
209 return fileUploadList;
210 }
211 }
212