aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/uk/ac/ox/cs/pagoda/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/uk/ac/ox/cs/pagoda/util')
-rw-r--r--src/test/java/uk/ac/ox/cs/pagoda/util/SimpleProgressBarTester.java16
-rw-r--r--src/test/java/uk/ac/ox/cs/pagoda/util/TestUtil.java97
2 files changed, 113 insertions, 0 deletions
diff --git a/src/test/java/uk/ac/ox/cs/pagoda/util/SimpleProgressBarTester.java b/src/test/java/uk/ac/ox/cs/pagoda/util/SimpleProgressBarTester.java
new file mode 100644
index 0000000..3de30e4
--- /dev/null
+++ b/src/test/java/uk/ac/ox/cs/pagoda/util/SimpleProgressBarTester.java
@@ -0,0 +1,16 @@
1package uk.ac.ox.cs.pagoda.util;
2
3import org.testng.annotations.Test;
4
5public class SimpleProgressBarTester {
6
7 @Test
8 public void test() throws InterruptedException {
9 SimpleProgressBar simpleProgressBar = new SimpleProgressBar("TestBar", 1000);
10 for(int i = 0; i < 1000; i++) {
11 simpleProgressBar.update(i);
12 Thread.sleep(10);
13 }
14 simpleProgressBar.dispose();
15 }
16}
diff --git a/src/test/java/uk/ac/ox/cs/pagoda/util/TestUtil.java b/src/test/java/uk/ac/ox/cs/pagoda/util/TestUtil.java
new file mode 100644
index 0000000..c7f024a
--- /dev/null
+++ b/src/test/java/uk/ac/ox/cs/pagoda/util/TestUtil.java
@@ -0,0 +1,97 @@
1package uk.ac.ox.cs.pagoda.util;
2
3import org.apache.log4j.Appender;
4import org.apache.log4j.FileAppender;
5import org.apache.log4j.Logger;
6import org.semanticweb.owlapi.model.IRI;
7
8import java.io.File;
9import java.io.IOException;
10import java.io.InputStream;
11import java.net.URL;
12import java.nio.file.Files;
13import java.nio.file.Path;
14import java.nio.file.Paths;
15import java.util.Enumeration;
16import java.util.Properties;
17
18import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
19
20/**
21 * A collection of utility methods for testing.
22 */
23public class TestUtil {
24
25 public static final String CONFIG_FILE = "test.properties";
26 private static final Logger LOGGER = Logger.getLogger("Tester");
27 private static boolean isConfigLoaded = false;
28 private static Properties config;
29
30 public static Properties getConfig() {
31 if(!isConfigLoaded) {
32 try(InputStream in = TestUtil.class.getClassLoader().getResourceAsStream(CONFIG_FILE)) {
33 config = new java.util.Properties();
34 config.load(in);
35 in.close();
36 isConfigLoaded = true;
37 } catch (IOException e) {
38 e.printStackTrace();
39 }
40 }
41 return config;
42 }
43
44 public static String combinePaths(String path1, String path2) {
45 File file1 = new File(path1);
46 File file2 = new File(file1, path2);
47 return file2.getPath();
48 }
49
50 public static void copyFile(String src, String dst) throws IOException {
51 Files.copy(Paths.get(src), Paths.get(dst), REPLACE_EXISTING);
52 }
53
54 /**
55 * Get the log file, which is assumed unique.
56 * */
57 public static String getLogFileName() {
58 Enumeration e = Logger.getRootLogger().getAllAppenders();
59 while (e.hasMoreElements()){
60 Appender app = (Appender)e.nextElement();
61 if (app instanceof FileAppender){
62 return ((FileAppender)app).getFile();
63 }
64 }
65 return null;
66 }
67
68 public static Path getAnswersFilePath(String name) {
69 URL givenAnswersURL = TestUtil.class.getClassLoader()
70 .getResource(name);
71 if(givenAnswersURL == null) throw new RuntimeException("Missing answers file:" + name);
72 return Paths.get(givenAnswersURL.getPath());
73 }
74
75 public static void logInfo(Object msg) {
76 LOGGER.info(msg);
77 }
78
79 public static void logDebug(Object msg) {
80 LOGGER.debug(msg);
81 }
82
83 public static void logError(Object msg) {
84 LOGGER.error(msg);
85 }
86
87 public static void logError(Object msg, Throwable t) {
88 LOGGER.error(msg, t);
89 }
90
91 public static final String NS = "http://example.org/test#%s";
92
93 public static IRI getEntityIRI(String name) {
94 return IRI.create(String.format(NS, name));
95 }
96
97}