blob: c7f024a796c9c3ecc1d024d7184915fbf90c2949 (
plain) (
blame)
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
|
package uk.ac.ox.cs.pagoda.util;
import org.apache.log4j.Appender;
import org.apache.log4j.FileAppender;
import org.apache.log4j.Logger;
import org.semanticweb.owlapi.model.IRI;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Enumeration;
import java.util.Properties;
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
/**
* A collection of utility methods for testing.
*/
public class TestUtil {
public static final String CONFIG_FILE = "test.properties";
private static final Logger LOGGER = Logger.getLogger("Tester");
private static boolean isConfigLoaded = false;
private static Properties config;
public static Properties getConfig() {
if(!isConfigLoaded) {
try(InputStream in = TestUtil.class.getClassLoader().getResourceAsStream(CONFIG_FILE)) {
config = new java.util.Properties();
config.load(in);
in.close();
isConfigLoaded = true;
} catch (IOException e) {
e.printStackTrace();
}
}
return config;
}
public static String combinePaths(String path1, String path2) {
File file1 = new File(path1);
File file2 = new File(file1, path2);
return file2.getPath();
}
public static void copyFile(String src, String dst) throws IOException {
Files.copy(Paths.get(src), Paths.get(dst), REPLACE_EXISTING);
}
/**
* Get the log file, which is assumed unique.
* */
public static String getLogFileName() {
Enumeration e = Logger.getRootLogger().getAllAppenders();
while (e.hasMoreElements()){
Appender app = (Appender)e.nextElement();
if (app instanceof FileAppender){
return ((FileAppender)app).getFile();
}
}
return null;
}
public static Path getAnswersFilePath(String name) {
URL givenAnswersURL = TestUtil.class.getClassLoader()
.getResource(name);
if(givenAnswersURL == null) throw new RuntimeException("Missing answers file:" + name);
return Paths.get(givenAnswersURL.getPath());
}
public static void logInfo(Object msg) {
LOGGER.info(msg);
}
public static void logDebug(Object msg) {
LOGGER.debug(msg);
}
public static void logError(Object msg) {
LOGGER.error(msg);
}
public static void logError(Object msg, Throwable t) {
LOGGER.error(msg, t);
}
public static final String NS = "http://example.org/test#%s";
public static IRI getEntityIRI(String name) {
return IRI.create(String.format(NS, name));
}
}
|