001package dk.netarkivet.testutils; 002 003import java.io.File; 004import java.net.URL; 005 006import org.junit.Assert; 007 008public class TestResourceUtils { 009 010 public static final String OUTPUT_DIR = "target/test-output"; 011 012 protected static ClassLoader clsLdr = TestResourceUtils.class.getClassLoader(); 013 014 public static String getFilePath(String filename) { 015 System.out.println(filename); 016 String path = null; 017 try { 018 URL url = clsLdr.getResource(filename); 019 if (url != null) { 020 path = url.getFile(); 021 path = path.replaceAll("%5b", "["); 022 path = path.replaceAll("%5d", "]"); 023 } 024 } catch (Throwable t) { 025 t.printStackTrace(); 026 } 027 if (path == null) { 028 Assert.fail("Didn't find resource '" + filename + "' on the classpath."); 029 } 030 return path; 031 } 032 033 public static File getFile(String filename) { 034 File file = new File(getFilePath(filename)); 035 if (!file.exists()) { 036 Assert.fail("Resource '" + filename + "' does not exist."); 037 } 038 return file; 039 } 040 041}