KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > test > DataDirectoryHelper


1 /**
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.test;
5
6 import java.io.File JavaDoc;
7 import java.io.FileNotFoundException JavaDoc;
8 import java.io.IOException JavaDoc;
9
10 /**
11  * A helper that fetches data directories and files, for use in tests. These directories and files must exist.
12  */

13 public class DataDirectoryHelper extends BaseDirectoryHelper {
14
15   public DataDirectoryHelper(Class JavaDoc theClass) throws IOException JavaDoc {
16     this(theClass, TestConfigObject.getInstance().dataDirectoryRoot());
17   }
18
19   // For internal use and tests only.
20
DataDirectoryHelper(Class JavaDoc theClass, String JavaDoc directoryPath) {
21     super(theClass, directoryPath);
22   }
23
24   protected File JavaDoc fetchDirectory() throws IOException JavaDoc {
25     ClassBasedDirectoryTree tree = new ClassBasedDirectoryTree(getRoot());
26     File JavaDoc theDirectory = tree.getDirectory(getTargetClass());
27     if (!theDirectory.exists()) throw new FileNotFoundException JavaDoc("No data directory '" + theDirectory.getAbsolutePath()
28                                                                 + "' exists.");
29     return theDirectory;
30   }
31
32   public File JavaDoc getFile(String JavaDoc path) throws IOException JavaDoc {
33     File JavaDoc theFile = super.getFile(path);
34     if (!theFile.exists()) throw new FileNotFoundException JavaDoc("No file '" + theFile.getAbsolutePath() + "' exists.");
35     return theFile;
36   }
37 }
Popular Tags