1 19 20 package org.apache.geronimo.testsupport; 21 22 import java.io.File ; 23 24 import junit.framework.TestCase; 25 26 import org.apache.commons.logging.Log; 27 import org.apache.commons.logging.LogFactory; 28 29 34 public abstract class TestSupport 35 extends TestCase 36 { 37 42 protected final File BASEDIR = getBaseDir(); 43 44 49 56 protected Log log = LogFactory.getLog(getClass()); 57 58 63 protected TestSupport(final String name) { 64 super(name); 65 66 log.info("Initialized"); 67 } 68 69 72 protected TestSupport() { 73 super(); 74 75 log.info("Initialized"); 76 } 77 78 91 protected final File getBaseDir() { 92 File dir; 93 94 String tmp = System.getProperty("basedir"); 96 if (tmp != null) { 97 dir = new File (tmp); 98 } 99 else { 100 String path = getClass().getProtectionDomain().getCodeSource().getLocation().getFile(); 102 103 dir = new File (path).getParentFile().getParentFile(); 105 106 System.setProperty("basedir", dir.getPath()); 108 } 109 110 112 return dir; 113 } 114 115 121 protected final File resolveFile(final String path) { 122 assert path != null; 123 124 File file = new File (path); 125 126 if (file.isAbsolute()) { 128 log.warn("Given path is already absolute; nothing to resolve: " + file); 129 } 130 else { 131 file = new File (BASEDIR, path); 132 } 133 134 return file; 135 } 136 137 145 protected final String resolvePath(final String path) { 146 assert path != null; 147 148 return resolveFile(path).getPath(); 149 } 150 } 151 | Popular Tags |