-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathTestProperties.java
More file actions
342 lines (293 loc) · 10.6 KB
/
TestProperties.java
File metadata and controls
342 lines (293 loc) · 10.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
/*
* Copyright (c) 2013-2019 LabKey Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.labkey.test;
import org.labkey.serverapi.reader.Readers;
import org.labkey.test.util.TestLogger;
import java.io.File;
import java.io.IOException;
import java.io.Reader;
import java.nio.file.Files;
import java.nio.file.StandardOpenOption;
import java.time.Duration;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public abstract class TestProperties
{
static
{
final File propFile = new File(TestFileUtils.getTestRoot(), "test.properties");
final File propFileTemplate = new File(TestFileUtils.getTestRoot(), "test.properties.template");
if (!propFile.exists())
{
TestLogger.log(String.format("'%s' does not exist. Creating default from '%s'", propFile.getName(), propFileTemplate.getName()));
try (Stream<String> propStream = Files.lines(propFileTemplate.toPath()))
{
final Iterator<String> iterator = propStream.filter(line -> !line.startsWith("#!!")).iterator();
Files.write(propFile.toPath(), (Iterable<String>) () -> iterator, StandardOpenOption.CREATE_NEW);
}
catch (IOException e)
{
TestLogger.error(e.getMessage());
}
}
try (Reader propReader = Readers.getReader(propFile))
{
TestLogger.log("Loading properties from " + propFile.getName());
Properties properties = new Properties();
properties.load(propReader);
properties.putAll(System.getProperties());
System.setProperties(properties);
}
catch (IOException ioe)
{
TestLogger.error("Failed to load " + propFile.getName() + " file. Running with hard-coded defaults");
ioe.printStackTrace(System.err);
}
}
public static void load()
{
/* Force static block to run */
}
public static boolean isTestCleanupSkipped()
{
return "false".equals(System.getProperty("clean", "false"));
}
public static boolean isLinkCheckEnabled()
{
return "true".equals(System.getProperty("linkCheck", "false")) || isInjectionCheckEnabled();
}
public static boolean isInjectionCheckEnabled()
{
return "true".equals(System.getProperty("injectCheck", "false"));
}
public static boolean isScriptCheckEnabled()
{
return "true".equals(System.getProperty("scriptCheck", "true"));
}
public static boolean isDevModeEnabled()
{
return "true".equals(System.getProperty("devMode", "true"));
}
public static boolean isTestRunningOnTeamCity()
{
String buildTypeProperty = "teamcity.buildType.id";
String undefinedBuildTypeProperty = "${" + buildTypeProperty + "}";
return !undefinedBuildTypeProperty.equals(System.getProperty(buildTypeProperty, undefinedBuildTypeProperty));
}
public static boolean isServerRemote()
{
return "true".equals(System.getProperty("webtest.server.remote", "false"));
}
public static boolean isLeakCheckSkipped()
{
return "false".equals(System.getProperty("memCheck", "true"));
}
public static boolean isQueryCheckSkipped()
{
return "false".equals(System.getProperty("queryCheck", "true"));
}
public static boolean isCspCheckSkipped()
{
// Skip by default
return "false".equals(System.getProperty("webtest.cspCheck", "false"));
}
public static boolean isNewWebDriverForEachTest()
{
return !"true".equals(System.getProperty("selenium.reuseWebDriver", "false"));
}
public static boolean isViewCheckSkipped()
{
return "false".equals(System.getProperty("viewCheck", "true"));
}
public static boolean isSystemMaintenanceDisabled()
{
return "never".equals(System.getProperty("systemMaintenance"));
}
public static boolean isHeapDumpCollectionEnabled()
{
return "true".equals(System.getProperty("webtest.enable.heap.dump"));
}
public static boolean isDiagnosticsExportEnabled()
{
return "true".equals(System.getProperty("webtest.enable.export.diagnostics"));
}
public static boolean isRunWebDriverHeadless()
{
return "true".equals(System.getProperty("webtest.webdriver.headless"));
}
public static boolean isDumpBrowserConsole()
{
return "true".equals(System.getProperty("webtest.dump.browser.console"));
}
public static double getTimeoutMultiplier()
{
try
{
return Math.max(0, Double.parseDouble(System.getProperty("webtest.timeout.multiplier", "")));
}
catch (NumberFormatException badProp)
{
return 1.0;
}
}
public static Duration getCrawlerTimeout()
{
try
{
return Duration.ofSeconds(Integer.parseInt(System.getProperty("crawlerTimeout")));
}
catch (NumberFormatException ignore)
{
return Duration.ofSeconds(90);
}
}
public static boolean isCloudPipelineEnabled()
{
return "true".equals(System.getProperty("use.cloud.pipeline"));
}
public static String getCloudPipelineBucketName()
{
return System.getProperty("cloud.pipeline.bucket");
}
public static boolean isWebDriverLoggingEnabled()
{
return "true".equals(System.getProperty("webtest.webdriver.logging"));
}
public static boolean isTroubleshootingStacktracesEnabled()
{
return "true".equals(System.getProperty("webtest.troubleshooting.stacktraces"));
}
public static boolean isDebugLoggingEnabled()
{
return "true".equals(System.getProperty("webtest.logging.debug"));
}
public static boolean isConsoleLogEnabled()
{
return "true".equals(System.getProperty("webtest.devtools.console.log"));
}
public static boolean isPrimaryUserAppAdmin()
{
return "true".equals(System.getProperty("webtest.primary.app.admin"));
}
public static boolean isWithoutTestModules()
{
return "true".equals(System.getProperty("webtest.without.test.modules"));
}
public static boolean isTrialServer()
{
return "true".equals(System.getProperty("webtest.server.trial"));
}
public static boolean isEmbeddedTomcat()
{
return !System.getProperty("useEmbeddedTomcat", "false").equals("false") || new File(TestFileUtils.getDefaultDeployDir(), "embedded").isDirectory();
}
public static boolean isCheckerFatal()
{
return "true".equals(System.getProperty("webtest.checker.fatal"));
}
public static boolean isAssayProductFeatureAvailable()
{
return isProductFeatureAvailable("assay");
}
public static boolean isProductFeatureAvailable(String feature)
{
return "true".equals(System.getProperty("webtest.productFeature." + feature.toLowerCase(), "true"));
}
/**
* Parses system property 'webtest.server.startup.timeout' to determine maximum allowed server startup time.
* If property is not defined or is not an integer, it defaults to 60 seconds.
* @return Maximum number of seconds to wait for server startup
*/
public static int getServerStartupTimeout()
{
String property = System.getProperty("webtest.server.startup.timeout");
try
{
return Integer.parseInt(property);
}
catch (NumberFormatException nfe)
{
return 120;
}
}
public static File getTomcatHome()
{
String tomcatHome = System.getProperty("tomcat.home", System.getenv("CATALINA_HOME"));
if (tomcatHome != null && !tomcatHome.isEmpty())
return new File(tomcatHome);
else
return null;
}
public static String getAdditionalPipelineTools()
{
return System.getProperty("additional.pipeline.tools");
}
public static Map<String, Boolean> getExperimentalFeatures()
{
Map<String, Boolean> features = new HashMap<>();
Properties props = System.getProperties();
for (Map.Entry<Object, Object> entry : props.entrySet())
{
String key = String.valueOf(entry.getKey());
Boolean value = (entry.getValue() instanceof Boolean)
? (Boolean)entry.getValue()
: Boolean.valueOf(String.valueOf(entry.getValue()));
String prefix = "webtest.experimental.";
if (key.startsWith(prefix))
{
String feature = key.substring(prefix.length());
features.put(feature, value);
}
}
return features;
}
public static List<String> getDebugLoggingPackages()
{
String prop = System.getProperty("webtest.debug.server.packages", "");
String[] packages = prop.split("\\s*,\\s*");
return Arrays.stream(packages).map(String::trim).filter(s -> !s.isEmpty()).collect(Collectors.toList());
}
private static File dumpDir = null;
public static File getDumpDir()
{
if (dumpDir == null)
{
String outputDir = System.getProperty("failure.output.dir");
if (outputDir != null)
{
dumpDir = new File(outputDir);
if (!dumpDir.exists())
dumpDir = new File(TestFileUtils.getLabKeyRoot(), outputDir);
}
if (dumpDir == null || !dumpDir.exists())
dumpDir = new File(System.getProperty("java.io.tmpdir"));
if (!dumpDir.exists())
{
dumpDir = null;
throw new RuntimeException("Couldn't determine directory for placement of output files. " +
"Tried system properties failure.output.dir and java.io.tmpdir");
}
TestLogger.log("Using " + dumpDir + " to store test output");
}
return dumpDir;
}
}