org.iternine.jeppetto.testsupport
Class FileSystemFixtureSupport

java.lang.Object
  extended by org.iternine.jeppetto.testsupport.FileSystemFixtureSupport

public class FileSystemFixtureSupport
extends Object

This prvoides a convenient way to manage files for unit tests. It allows for creating a per-test directory structure that can be used for temporary data as well as load directory/file structures using zip archives. To use: Create a FileSystemFixtureSupport. You can either specify a root directory or a name prefix to use when creating the temporary directory. Your test can create new directories using createDirectory() or load pre-built zip archives of directory structures into the temporary directory. In your test's @Before method, you can cleanup the files/directories created during the test through the teardown() method. You can also delete the temporary directory by calling the destroy() method from an @AfterClass method. Once this is called, the fixture support cannot be used.


Constructor Summary
FileSystemFixtureSupport(File rootDir)
          Create a FileSystemFixtureSupport that will manage the specified File as its temporary root directory.
FileSystemFixtureSupport(String prefix)
          Create a FileSystemFixtureSupport that will create a new temporary directory using the specified name prefix.
 
Method Summary
 File createDirectory(String path)
          Creates a new directory that is relative to the temporary testing root.
 void destroy()
          Deletes all of the fixture files as well as the temporary root directory.
 File getTestingRoot()
           
 void loadFileFixtures(List<String> resourcesToLoad)
          Loads a directory structure from a zip archive.
 void teardown()
          Deletes any directories or files that have been created by this class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileSystemFixtureSupport

public FileSystemFixtureSupport(String prefix)
Create a FileSystemFixtureSupport that will create a new temporary directory using the specified name prefix.

Parameters:
prefix - the prefix used when naming the temporary directory this will manage

FileSystemFixtureSupport

public FileSystemFixtureSupport(File rootDir)
Create a FileSystemFixtureSupport that will manage the specified File as its temporary root directory. When destroy() is invoked, this directory will be deleted.

Parameters:
rootDir - the temporary root directory. This will be created if it does not already exist.
Method Detail

createDirectory

public File createDirectory(String path)
Creates a new directory that is relative to the temporary testing root.

Parameters:
path - the relative path of the new directory.
Returns:
the new directory

loadFileFixtures

public void loadFileFixtures(List<String> resourcesToLoad)
                      throws IOException
Loads a directory structure from a zip archive. The archive will be extracted at the testing root dierectory.

Parameters:
resourcesToLoad - the names of zip archives in the classpath that should be loaded.
Throws:
IOException - if we cannot unarchive the files

teardown

public void teardown()
              throws IOException
Deletes any directories or files that have been created by this class.

Throws:
IOException - if we are unable to delete the data

destroy

public void destroy()
             throws IOException
Deletes all of the fixture files as well as the temporary root directory. This should only be invoked when the this class is no longer going to be used.

Throws:
IOException - if deletion fails

getTestingRoot

public File getTestingRoot()


Copyright © 2012. All Rights Reserved.