1   package net.kwfgrid.gworkflowdl;
2   
3   import junit.framework.TestCase;
4   
5   import java.io.File;
6   import java.io.FileReader;
7   import java.io.BufferedReader;
8   import java.io.IOException;
9   
10  import org.apache.log4j.Logger;
11  import org.apache.log4j.Level;
12  
13  /***
14   * Abstract base class for test cases.
15   *
16   * @todo implement test case for gworkflowdl package.
17   */
18  public abstract class AbstractTestCase
19          extends TestCase {
20      /***
21       * Basedir for all file I/O. Important when running tests from
22       * the reactor.
23       */
24      public String basedir = System.getProperty("basedir");
25  
26      /***
27       * Constructor.
28       */
29      public AbstractTestCase(String testName) {
30          super(testName);
31          Logger.getLogger(getClass()).setLevel(Level.DEBUG);
32      }
33  
34      /***
35       * Get test input file.
36       *
37       * @param path Path to test input file.
38       */
39      public String getTestFile(String path)
40      {
41          if (basedir == null) {
42              basedir = "gworkflowdl";
43          }
44          File file = new File(basedir,path);
45          return file.getAbsolutePath();
46      }
47  
48      public String readfile(String fn) throws IOException {
49          BufferedReader in = (new BufferedReader(new FileReader(getTestFile(fn))));
50          String line;
51          StringBuffer buffer = new StringBuffer();
52          line = in.readLine();
53          while (line != null) {
54              buffer.append(line);
55              buffer.append("\r\n");
56              line = in.readLine();
57          }
58          return buffer.toString();
59      }
60      
61  }
62