diff options
| author | RncLsn <rnc.lsn@gmail.com> | 2015-05-07 19:26:24 +0100 |
|---|---|---|
| committer | RncLsn <rnc.lsn@gmail.com> | 2015-05-07 19:26:24 +0100 |
| commit | 5be5fd3daa0d50980fb3791e904e035cdbca254f (patch) | |
| tree | 8109fdd92d6a8f3b59b47f147d21e23b84301494 /test/uk/ac/ox/cs/pagoda/util/TestUtil.java | |
| parent | 11a432bfc3cb11e07c68c4298fcec060ff1e25fa (diff) | |
| download | ACQuA-5be5fd3daa0d50980fb3791e904e035cdbca254f.tar.gz ACQuA-5be5fd3daa0d50980fb3791e904e035cdbca254f.zip | |
Making the output machine-readable (JSON).
Diffstat (limited to 'test/uk/ac/ox/cs/pagoda/util/TestUtil.java')
| -rw-r--r-- | test/uk/ac/ox/cs/pagoda/util/TestUtil.java | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/test/uk/ac/ox/cs/pagoda/util/TestUtil.java b/test/uk/ac/ox/cs/pagoda/util/TestUtil.java new file mode 100644 index 0000000..227398b --- /dev/null +++ b/test/uk/ac/ox/cs/pagoda/util/TestUtil.java | |||
| @@ -0,0 +1,64 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.util; | ||
| 2 | |||
| 3 | import org.apache.log4j.Appender; | ||
| 4 | import org.apache.log4j.FileAppender; | ||
| 5 | import org.apache.log4j.Logger; | ||
| 6 | |||
| 7 | import java.io.File; | ||
| 8 | import java.io.FileInputStream; | ||
| 9 | import java.io.IOException; | ||
| 10 | import java.nio.file.Files; | ||
| 11 | import java.nio.file.Paths; | ||
| 12 | import java.util.Enumeration; | ||
| 13 | import java.util.Properties; | ||
| 14 | |||
| 15 | import static java.nio.file.StandardCopyOption.REPLACE_EXISTING; | ||
| 16 | |||
| 17 | /** | ||
| 18 | * A collection of utility methods for testing. | ||
| 19 | */ | ||
| 20 | public class TestUtil { | ||
| 21 | |||
| 22 | public static final String CONFIG_FILE = "config/test.properties"; | ||
| 23 | |||
| 24 | private static boolean isConfigLoaded = false; | ||
| 25 | private static Properties config; | ||
| 26 | |||
| 27 | public static Properties getConfig() { | ||
| 28 | if(!isConfigLoaded) { | ||
| 29 | try (FileInputStream in = new FileInputStream(CONFIG_FILE)) { | ||
| 30 | config = new java.util.Properties(); | ||
| 31 | config.load(in); | ||
| 32 | in.close(); | ||
| 33 | isConfigLoaded = true; | ||
| 34 | } catch (IOException e) { | ||
| 35 | e.printStackTrace(); | ||
| 36 | } | ||
| 37 | } | ||
| 38 | return config; | ||
| 39 | } | ||
| 40 | |||
| 41 | public static String combinePaths(String path1, String path2) { | ||
| 42 | File file1 = new File(path1); | ||
| 43 | File file2 = new File(file1, path2); | ||
| 44 | return file2.getPath(); | ||
| 45 | } | ||
| 46 | |||
| 47 | public static void copyFile(String src, String dst) throws IOException { | ||
| 48 | Files.copy(Paths.get(src), Paths.get(dst), REPLACE_EXISTING); | ||
| 49 | } | ||
| 50 | |||
| 51 | /* | ||
| 52 | * Get the log file, which is assumed unique. | ||
| 53 | * */ | ||
| 54 | public static String getLogFileName() { | ||
| 55 | Enumeration e = Logger.getRootLogger().getAllAppenders(); | ||
| 56 | while (e.hasMoreElements()){ | ||
| 57 | Appender app = (Appender)e.nextElement(); | ||
| 58 | if (app instanceof FileAppender){ | ||
| 59 | return ((FileAppender)app).getFile(); | ||
| 60 | } | ||
| 61 | } | ||
| 62 | return null; | ||
| 63 | } | ||
| 64 | } | ||
