View Javadoc
1   package ubic.basecode.ontology;
2   
3   import org.apache.commons.io.file.PathUtils;
4   import org.junit.AfterClass;
5   import org.junit.BeforeClass;
6   import ubic.basecode.util.Configuration;
7   
8   import java.io.IOException;
9   import java.nio.file.Files;
10  import java.nio.file.Path;
11  
12  /**
13   * Base class for ontology-based tests.
14   * <p>
15   * This class ensures that the ontology are stored and indexed in a temporary directory.
16   */
17  public class AbstractOntologyTest {
18  
19      protected static Path tempDir;
20  
21      @BeforeClass
22      public static void setUpOntologyCacheDir() throws IOException {
23          tempDir = Files.createTempDirectory( "baseCode" );
24          Configuration.setString( "ontology.cache.dir", tempDir.resolve( "ontologyCache" ).toAbsolutePath().toString() );
25          Configuration.setString( "ontology.index.dir", tempDir.resolve( "searchIndices" ).toAbsolutePath().toString() );
26      }
27  
28      @AfterClass
29      public static void clearOntologyCacheDir() throws IOException {
30          try {
31              PathUtils.deleteDirectory( tempDir );
32          } finally {
33              Configuration.reset( "ontology.cache.dir" );
34              Configuration.reset( "ontology.index.dir" );
35          }
36      }
37  }