Print

Print


Author: [log in to unmask]
Date: Wed Jun 10 16:02:50 2015
New Revision: 3122

Log:
Add a few simple utilities to integration-tests module.

Added:
    java/trunk/integration-tests/src/main/java/org/
    java/trunk/integration-tests/src/main/java/org/hps/
    java/trunk/integration-tests/src/main/java/org/hps/test/
    java/trunk/integration-tests/src/main/java/org/hps/test/util/
    java/trunk/integration-tests/src/main/java/org/hps/test/util/TestFileUrl.java
    java/trunk/integration-tests/src/main/java/org/hps/test/util/TestOutputFile.java

Added: java/trunk/integration-tests/src/main/java/org/hps/test/util/TestFileUrl.java
 =============================================================================
--- java/trunk/integration-tests/src/main/java/org/hps/test/util/TestFileUrl.java	(added)
+++ java/trunk/integration-tests/src/main/java/org/hps/test/util/TestFileUrl.java	Wed Jun 10 16:02:50 2015
@@ -0,0 +1,42 @@
+package org.hps.test.util;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import junit.framework.TestCase;
+
+import org.lcsim.util.cache.FileCache;
+
+/**
+ * Some utility methods for getting test data from the lcsim.org site.
+ * 
+ * @author Jeremy McCormick, SLAC
+ */
+public final class TestFileUrl {
+    
+    /**
+     * Should not instantiate this class.
+     */
+    private TestFileUrl() {
+    }
+    
+    /**
+     * Base URL with test data.
+     */
+    private static final String BASE_URL = "http://www.lcsim.org/test/hps-java/";
+        
+    
+    private static URL createUrl(Class<? extends TestCase> testClass, String fileName) throws MalformedURLException {
+        return new URL(BASE_URL + "/" + testClass.getSimpleName() + "/" + fileName);
+    }
+    
+    public static File getInputFile(URL url) throws IOException {
+        return new FileCache().getCachedFile(url);
+    }
+    
+    public static File getInputFile(Class<? extends TestCase> testClass, String fileName) throws Exception {
+        return getInputFile(createUrl(testClass, fileName));
+    }
+}

Added: java/trunk/integration-tests/src/main/java/org/hps/test/util/TestOutputFile.java
 =============================================================================
--- java/trunk/integration-tests/src/main/java/org/hps/test/util/TestOutputFile.java	(added)
+++ java/trunk/integration-tests/src/main/java/org/hps/test/util/TestOutputFile.java	Wed Jun 10 16:02:50 2015
@@ -0,0 +1,32 @@
+package org.hps.test.util;
+
+import java.io.File;
+
+import junit.framework.TestCase;
+
+/**
+ * Convenience class for test file output (basically copied from lcsim.org).
+ * 
+ * @author Jeremy McCormick, SLAC
+ */
+public class TestOutputFile extends File {
+    
+    /**
+     * Root output area in target dir.
+     */
+    private static String TEST_OUTPUT_DIR = "target/test-output/";   
+    
+    /**
+     * Create output file in target dir for a specific test case.
+     * 
+     * @param testClass the TestCase class
+     * @param filename the file name (should not use a directory)
+     */
+    public TestOutputFile(Class<? extends TestCase> testClass, String filename) {
+        super(TEST_OUTPUT_DIR + File.separator + testClass.getSimpleName() + File.separator + filename);
+        File dir = this.getParentFile();
+        if (!dir.exists()) {
+            dir.mkdirs();
+        }
+    }
+}