com.sun.javatest
Class WorkDirectory

java.lang.Object
  extended by com.sun.javatest.WorkDirectory

public class WorkDirectory
extends java.lang.Object

A class providing access to the working state of a test run, as embodied in a work directory.


Nested Class Summary
static class WorkDirectory.BadDirectoryFault
          Signals that there is a serious, unrecoverable problem when trying to open or create a work directory.
static class WorkDirectory.Fault
          This exception is used to report problems that arise when using work directories.
static class WorkDirectory.InitializationFault
          Signals that there is a problem trying to initialize from the data in the work directory.
static class WorkDirectory.MismatchFault
          Signals that a work directory does not match the given test suite.
static class WorkDirectory.NotWorkDirectoryFault
          Signals that a directory (while valid in itself) is not a valid work directory.
static class WorkDirectory.PurgeFault
          Signals that a problem occurred while trying to purge files in work directory.
static class WorkDirectory.TemplateMissingFault
          Signals that the template pointed to by that directory is missing.
static class WorkDirectory.TestSuiteFault
          Signals that there is a problem trying to determine the test suite appropriate for the work directory.
static class WorkDirectory.WorkDirectoryExistsFault
          Signals that a work directory already exists when an attempt is made to create one.
 
Field Summary
static java.lang.String JTDATA
           
 
Method Summary
static void changeTemplate(java.io.File dir, java.io.File newTemplate)
           
static WorkDirectory convert(java.io.File dir, TestSuite ts)
          Convert an existing directory into a work directory.
static WorkDirectory create(java.io.File dir, TestSuite ts)
          Create a new work directory with a given name, and for a given test suite.
static java.lang.String[] getDiffInPaths(java.lang.String newPath, java.lang.String oldWDpath)
           
 java.io.File getFile(java.lang.String name)
          Get a file in this work directory.
 java.io.File getJTData()
          Get the data directory for this work directory.
 java.lang.String getLogFileName()
           
 java.lang.String getPath()
          Get the root directory for this work directory.
 java.lang.String getPrevWDPath()
           
 java.io.File getRoot()
          Get the root directory for this work directory.
 java.io.File getSystemFile(java.lang.String name)
          Get a file in the system directory for this work directory.
 java.util.Map<java.lang.String,java.lang.String> getTestAnnotations(java.lang.String testName)
          Get any annotations for the given test.
 java.util.Map<java.lang.String,java.lang.String> getTestAnnotations(TestResult tr)
          Get any annotations for the given test in this work directory.
 TestResultTable getTestResultTable()
          Get a test result table containing the test results in this work directory.
 TestSuite getTestSuite()
          Get the test suite for this work directory.
 int getTestSuiteTestCount()
          Find out the number of tests in the entire test suite.
static boolean isEmptyDirectory(java.io.File dir)
          Check if a directory is an empty directory.
 boolean isTRTSet()
           
static boolean isUsableWorkDirectory(java.io.File dir)
          Do sanity check of workdir.
static boolean isWorkDirectory(java.io.File dir)
          Check if a directory is a work directory.
 void log(I18NResourceBundle i18n, java.lang.String key)
          Print a text message to the workdir logfile.
 void log(I18NResourceBundle i18n, java.lang.String key, java.lang.Object arg)
          Print a text message to the workdir logfile.
 void log(I18NResourceBundle i18n, java.lang.String key, java.lang.Object[] args)
          Print a text message to the workdir logfile.
static WorkDirectory open(java.io.File dir)
          Open an existing work directory, using the default test suite associated with it.
static WorkDirectory open(java.io.File dir, TestSuite testSuite)
          Open an existing work directory, using an explicit test suite.
 boolean purge(java.lang.String path)
          Clean the contents of the given path.
 void putTestAnnotation(java.lang.String testName, java.lang.String key, java.lang.String value)
          Add an annotation for the given test.
 void putTestAnnotation(TestResult tr, java.lang.String key, java.lang.String value)
          See putTestAnnotation(String,String,String).
 void setTestResultTable(TestResultTable trt)
          Set a test result table containing the test descriptions for the tests in this test suite.
 void setTestSuiteTestCount(int num)
          Specify the total number of tests found in this testsuite.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

JTDATA

public static final java.lang.String JTDATA
See Also:
Constant Field Values
Method Detail

isWorkDirectory

public static boolean isWorkDirectory(java.io.File dir)
Check if a directory is a work directory. This is intended to be a quick check, rather than exhaustive one; as such, it simply checks for the existence of the "jtData" subdirectory.

Parameters:
dir - the directory to be checked
Returns:
true if and only if the specified directory appears to be a work directory

isEmptyDirectory

public static boolean isEmptyDirectory(java.io.File dir)
Check if a directory is an empty directory.

Parameters:
dir - the directory to be checked
Returns:
true if and only if the directory is empty

isUsableWorkDirectory

public static boolean isUsableWorkDirectory(java.io.File dir)
Do sanity check of workdir. All critical areas must be read-write.


create

public static WorkDirectory create(java.io.File dir,
                                   TestSuite ts)
                            throws WorkDirectory.BadDirectoryFault,
                                   WorkDirectory.WorkDirectoryExistsFault,
                                   WorkDirectory.InitializationFault
Create a new work directory with a given name, and for a given test suite.

Parameters:
dir - the directory to be created as a work directory. This directory may (but need not) exist; if it does exist, it must be empty.
ts - the test suite for which this will be a work directory
Returns:
the WorkDirectory that was created
Throws:
WorkDirectory.WorkDirectoryExistsFault - if the work directory could not be created because it already exists. If this exception is thrown, you may want to call open(java.io.File) instead.
WorkDirectory.BadDirectoryFault - is there was a problem creating the work directory.
WorkDirectory.InitializationFault - if there are unrecoverable problems encountered while reading the data present in the work directory
See Also:
convert(java.io.File, com.sun.javatest.TestSuite), open(java.io.File)

convert

public static WorkDirectory convert(java.io.File dir,
                                    TestSuite ts)
                             throws WorkDirectory.BadDirectoryFault,
                                    WorkDirectory.WorkDirectoryExistsFault,
                                    java.io.FileNotFoundException,
                                    WorkDirectory.InitializationFault
Convert an existing directory into a work directory.

Parameters:
dir - the directory to be converted to a work directory
ts - the test suite for which this will be a work directory
Returns:
the WorkDirectory that was created
Throws:
java.io.FileNotFoundException - if the directory to be converted does not exist
WorkDirectory.WorkDirectoryExistsFault - if the work directory could not be created because it already exists. If this exception is thrown, you may want to call open(java.io.File) instead.
WorkDirectory.BadDirectoryFault - is there was a problem creating the work directory.
WorkDirectory.InitializationFault - if there are unrecoverable problems encountered while reading the data present in the work directory
See Also:
create(java.io.File, com.sun.javatest.TestSuite), open(java.io.File)

getLogFileName

public java.lang.String getLogFileName()

changeTemplate

public static void changeTemplate(java.io.File dir,
                                  java.io.File newTemplate)

getDiffInPaths

public static java.lang.String[] getDiffInPaths(java.lang.String newPath,
                                                java.lang.String oldWDpath)

open

public static WorkDirectory open(java.io.File dir)
                          throws java.io.FileNotFoundException,
                                 WorkDirectory.BadDirectoryFault,
                                 WorkDirectory.NotWorkDirectoryFault,
                                 WorkDirectory.MismatchFault,
                                 WorkDirectory.TestSuiteFault,
                                 WorkDirectory.InitializationFault,
                                 WorkDirectory.TemplateMissingFault
Open an existing work directory, using the default test suite associated with it.

Parameters:
dir - the directory to be opened as a WorkDirectory
Returns:
the WorkDirectory that is opened
Throws:
java.io.FileNotFoundException - if the directory identified by dir does not exist. If this exception is thrown, you may want to call create(java.io.File, com.sun.javatest.TestSuite) instead.
WorkDirectory.BadDirectoryFault - if there was a problem opening the work directory.
WorkDirectory.NotWorkDirectoryFault - if the directory identified by dir is a valid directory, but has not yet been initialized as a work directory. If this exception is thrown, you may want to call create(java.io.File, com.sun.javatest.TestSuite) instead.
WorkDirectory.MismatchFault - if the test suite recorded in the work directory does not match the test suite's ID recorded in the work directory.
WorkDirectory.TestSuiteFault - if there was a problem determining the test suite for which this is a work directory. If this exception is thrown, you can override the test suite using the other version of open(File,TestSuite).
WorkDirectory.InitializationFault - if there are unrecoverable problems encountered while reading the data present in the work directory
WorkDirectory.TemplateMissingFault

open

public static WorkDirectory open(java.io.File dir,
                                 TestSuite testSuite)
                          throws java.io.FileNotFoundException,
                                 WorkDirectory.BadDirectoryFault,
                                 WorkDirectory.NotWorkDirectoryFault,
                                 WorkDirectory.MismatchFault,
                                 WorkDirectory.InitializationFault,
                                 WorkDirectory.TemplateMissingFault
Open an existing work directory, using an explicit test suite. Any information about the test suite previously associated with this work directory is overwritten and lost. Therefore this method should be used with care: normally, a work directory should be opened with open(File).

Parameters:
dir - The directory to be opened as a WorkDirectory.
testSuite - The test suite to be associated with this work directory.
Returns:
The WorkDirectory that is opened.
Throws:
java.io.FileNotFoundException - if the directory identified by dir does not exist. If this exception is thrown, you may want to call create(java.io.File, com.sun.javatest.TestSuite) instead.
WorkDirectory.BadDirectoryFault - if there was a problem opening the work directory.
WorkDirectory.NotWorkDirectoryFault - if the directory identified by dir is a valid directory, but has not yet been initialized as a work directory. f this exception is thrown, you may want to call create(java.io.File, com.sun.javatest.TestSuite) instead.
WorkDirectory.MismatchFault - if the specified test suite does not match the ID recorded in the work directory.
WorkDirectory.InitializationFault - if there are unrecoverable problems encountered while reading the data present in the work directory
WorkDirectory.TemplateMissingFault

getPrevWDPath

public java.lang.String getPrevWDPath()

getRoot

public java.io.File getRoot()
Get the root directory for this work directory.

Returns:
the root directory for this work directory

getPath

public java.lang.String getPath()
Get the root directory for this work directory.

Returns:
the path of the root directory for this work directory

getJTData

public java.io.File getJTData()
Get the data directory for this work directory.

Returns:
the system (jtData) directory for this work directory

getFile

public java.io.File getFile(java.lang.String name)
Get a file in this work directory.

Parameters:
name - the name of a file within this work directory
Returns:
the full (absolute) name of the specified file

getSystemFile

public java.io.File getSystemFile(java.lang.String name)
Get a file in the system directory for this work directory.

Parameters:
name - the name of a file within the system (jtData) directory
Returns:
the full (absolute) name of the specified file

getTestSuite

public TestSuite getTestSuite()
Get the test suite for this work directory.

Returns:
the test suite for which this is a work directory

getTestSuiteTestCount

public int getTestSuiteTestCount()
Find out the number of tests in the entire test suite. This number is collected from either a previous iteration of the testsuite or from the TestSuite object.

Returns:
the number of tests in the test suite, -1 if not known.
See Also:
setTestSuiteTestCount(int), TestSuite.getEstimatedTestCount()

setTestSuiteTestCount

public void setTestSuiteTestCount(int num)
Specify the total number of tests found in this testsuite. When available, this class prefers to use this number rather than that provided by a TestSuite object.

Parameters:
num - the number of tests in the test suite
See Also:
getTestSuiteTestCount(), TestSuite.getEstimatedTestCount()

getTestResultTable

public TestResultTable getTestResultTable()
Get a test result table containing the test results in this work directory.

Returns:
a test result table containing the test results in this work directory
See Also:
setTestResultTable(com.sun.javatest.TestResultTable)

setTestResultTable

public void setTestResultTable(TestResultTable trt)
Set a test result table containing the test descriptions for the tests in this test suite.

Parameters:
trt - a test result table containing the test descriptions for the tests in this work directory
Throws:
java.lang.NullPointerException - if trt is null.
java.lang.IllegalArgumentException - if the test result table has been initialized with a different work directory.
See Also:
getTestResultTable()

isTRTSet

public boolean isTRTSet()

log

public void log(I18NResourceBundle i18n,
                java.lang.String key)
Print a text message to the workdir logfile. A single line of text which is as short as possible is highly recommended for readability purposes.

Parameters:
i18n - a resource bundle containing the localized messages
key - a key into the resource bundle for the required message
Since:
3.0.1

log

public void log(I18NResourceBundle i18n,
                java.lang.String key,
                java.lang.Object arg)
Print a text message to the workdir logfile. A single line of text which is as short as possible is highly recommended for readability purposes.

Parameters:
i18n - a resource bundle containing the localized messages
key - a key into the resource bundle for the required message
arg - An argument to be formatted into the specified message. If this is a Throwable, its stack trace will be included in the log.
Since:
3.0.1

log

public void log(I18NResourceBundle i18n,
                java.lang.String key,
                java.lang.Object[] args)
Print a text message to the workdir logfile. A single line of text which is as short as possible is highly recommended for readability purposes.

Parameters:
i18n - a resource bundle containing the localized messages
key - a key into the resource bundle for the required message
args - An array of arguments to be formatted into the specified message. If the first arg is a Throwable, its stack trace will be included in the log.
Since:
3.0.1

putTestAnnotation

public void putTestAnnotation(TestResult tr,
                              java.lang.String key,
                              java.lang.String value)
See putTestAnnotation(String,String,String).

See Also:
putTestAnnotation(String,String,String)

putTestAnnotation

public void putTestAnnotation(java.lang.String testName,
                              java.lang.String key,
                              java.lang.String value)
Add an annotation for the given test.

Parameters:
testName - Test for which the annotation should be added. This is the value from TestResult.getTestName().
key - The name of the value to be entered. The namespace for this value is unique for each testName.
value - The value of the annotation. Null removes the value from the map, an empty string should be used otherwise.

getTestAnnotations

public java.util.Map<java.lang.String,java.lang.String> getTestAnnotations(java.lang.String testName)
Get any annotations for the given test.

Returns:
Null if there are no annotations. May also be null if the test does not exist.
Throws:
java.lang.NullPointerException - if the parameter is null.
See Also:
getTestAnnotations(TestResult), putTestAnnotation(String, String, String), putTestAnnotation(TestResult, String, String)

getTestAnnotations

public java.util.Map<java.lang.String,java.lang.String> getTestAnnotations(TestResult tr)
Get any annotations for the given test in this work directory. The annotations take the form of a map of strings for both the key and value.

Parameters:
tr - The test to get annotations for.
Returns:
Null if there are no annotations. May also be null if the test does not exist.
Throws:
java.lang.NullPointerException - if the parameter is null.

purge

public boolean purge(java.lang.String path)
              throws WorkDirectory.PurgeFault
Clean the contents of the given path. If path is a directory, it is recursively deleted. If it is a file, that file is removed. Any user confirmation should be done before calling this method. If the path does not exist in this work directory, false is returned.

Parameters:
path - Path to a directory in this work directory or a path to a jtr file. A zero length string removes the root.
Returns:
true is the purge occurred normally, false if the purge did not complete for some reason. Most failures to purge will be announced by Faults. A null parameter will result in false.
Throws:
WorkDirectory.PurgeFault - If the file cannot be removed; the message field may not contain any useful information due to deficiencies in java.io.File.delete()..


Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved.