Class WorkDirectory

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

public class WorkDirectory extends Object
A class providing access to the working state of a test run, as embodied in a work directory.
  • Field Details

  • Method Details

    • isWorkDirectory

      public static boolean isWorkDirectory(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(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(File dir)
      Do sanity check of workdir. All critical areas must be read-write.
    • create

      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.
      See Also:
    • convert

      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:
      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.
      See Also:
    • changeTemplate

      public static void changeTemplate(File dir, File newTemplate)
    • getDiffInPaths

      public static String[] getDiffInPaths(String newPath, String oldWDpath)
    • open

      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:
      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.TemplateMissingFault
    • open

      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:
      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.TemplateMissingFault
    • getLogFileName

      public String getLogFileName()
    • getPrevWDPath

      public String getPrevWDPath()
    • getRoot

      public File getRoot()
      Get the root directory for this work directory.
      Returns:
      the root directory for this work directory
    • getPath

      public String getPath()
      Get the root directory for this work directory.
      Returns:
      the path of the root directory for this work directory
    • getJTData

      public File getJTData()
      Get the data directory for this work directory.
      Returns:
      the system (jtData) directory for this work directory
    • getFile

      public File getFile(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 File getSystemFile(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

      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:
    • 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

      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:
      NullPointerException - if trt is null.
      IllegalArgumentException - if the test result table has been initialized with a different work directory.
      See Also:
    • isTRTSet

      public boolean isTRTSet()
    • log

      public void log(I18NResourceBundle i18n, 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, String key, 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, String key, 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, String key, String value)
      See putTestAnnotation(String,String,String).
      See Also:
    • putTestAnnotation

      public void putTestAnnotation(String testName, String key, 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 Map<String,String> getTestAnnotations(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:
      NullPointerException - if the parameter is null.
      See Also:
    • getTestAnnotations

      public Map<String,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:
      NullPointerException - if the parameter is null.
    • purge

      public boolean purge(String path)
      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.