Package com.sun.javatest
Class TestResult
java.lang.Object
com.sun.javatest.TestResult
The TestResult object encapsulates the results from a test.
Test results are formatted in sections of command output,
comments and sometimes "streams" of output (stdout for example).
Each of these sections is represented by a (@link TestResult.Section Section).
Instances of this class are mutable until the result of the section is
set or until the result of the test itself is set.
Test results are stored in a structured text files. The TestResult class serves as the API for accessing the various components that make up the result of running a test. The status is cached as its size is small and it is accessed often.
This class and inner classes will throw IllegalStateExceptions if an attempt is made to modify the any part of the object that has been marked immutable.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
This exception is to report problems using TestResult objects.static interface
An interface to observe activity in a TestResult as it is created.static class
This exception ay occur anytime the JTR file is being read from the filesystem.static class
This exception is thrown if the JTR file cannot be found.class
This "section" is the logical combination of a single action during test execution. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
A code indicating that an invalid checksum was found in a .jtr file.static final DateFormat
DateFormat, that is used to store date into TestResultstatic final String
The name of the property that defines the test description file.static final String
The name of the property that defines the time at which the test execution finished.static final String
The name of the property that defines the environment name.static final String
The name of the property that defines the test execution status.static final int
A code indicating that a good checksum was found in a .jtr file.static final String
The name of the property that defines the OS on which JT Harness was running when the test was run.static final String
The name of the property that defines the type of class loader used when running the harness (classpath mode or module mode generally).static final String
The name of the default output that all Sections are equipped with.static final String
The name of the default section that all TestResult objects are equipped with.static final int
A code indicating that no checksum was found in a .jtr file.static final int
The number of different checksum states (none, good, bad).static final String
The name of the property that defines the script that ran the test.static final String
The name of the property that defines the test output sections that were recorded when the test ran.static final String
The name of the property that defines the time at which the test execution started.static final String
The name of the property that defines the test for which this is the result object.static final String
The name of the property that defines the variety of harness in use.static final String
The name of the property that defines which version of JT Harness was used to run the test.static final String
The name of the property that defines the work directory for the test. -
Constructor Summary
ConstructorsConstructorDescriptionConstruct a test result object that will be built as the test runs.TestResult
(TestDescription td, Status s) Create a temporary test result for which can be handed around in situations where a reasonable test result can't be created.TestResult
(TestDescription td, WorkDirectory workDir) Reconstruct the results of a previously run test.TestResult
(WorkDirectory workDir, String workRelativePath) Reconstruct the results of a previously run test.TestResult
(File file) Reconstruct the results of a previously run test. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Add an observer to watch this test result for changes.createSection
(String name) Create a new section inside this test result.static String
formatDate
(Date d) Format the date format used for timestamps, such as the start/stop timestamp.byte
Get info about the checksum in this object.Get the description of the test from which this result was created.long
Gets the time when the test was completed, or at least the time when it's final status was set.Get a copy of the environment that this object has stored.getFile()
Get the name, if any, for the result file for this object.Get the parent node in the test result table that contains this test result object.getProperty
(String name) Get the value of a property of this test result.Get the keys of the properties that this object has stored.getSection
(int index) Get the section specified by index.int
Find out how many sections this test result contains.String[]
Get the titles of all sections in this test result.Get the status for this test.A way to write comments about the test execution into the results.Get the test name, as given by the test URL defined by TestDescription.getRootRelativeURL().Get the path name for the results file for this test, relative to the work directory.static String
Get the path name for the results file for a test, relative to the work directory.static String
getWorkRelativePath
(String testURL) Get the path name for the results file for a test, relative to the work directory.static String
getWorkRelativePath
(String baseURL, String testId) Get the path name for the results file for a test, relative to the work directory.boolean
Determine if the test result object is still mutable.boolean
Check whether this test result can be reloaded from a file.static boolean
isResultFile
(File f) Check if this file is or appears to be a result (.jtr) file, according to its filename extension.boolean
isShrunk()
Check whether this object has been "shrunk" to reduce its memory footprint.static TestResult
Create a placeholder TestResult for a test that has not yet been run.static Date
Parse the date format used for timestamps, such as the start/stop timestamp.void
putProperty
(String name, String value) Add a new property value to this TestResult.void
reloadFromWorkDir
(WorkDirectory workDir) Reconstruct the results of a previously run test.void
Remove an observer that was previously added.void
void
setEnvironment
(TestEnvironment environment) Set the environment used by this test.void
setMaxOutputSize
(int size) Sets the maximum output size for the current TestResult.void
Set the result of this test.toString()
void
writeResults
(WorkDirectory workDir, BackupPolicy backupPolicy) Writes the TestResult into a version 2 jtr file.
-
Field Details
-
NO_CHECKSUM
public static final int NO_CHECKSUMA code indicating that no checksum was found in a .jtr file.- See Also:
-
BAD_CHECKSUM
public static final int BAD_CHECKSUMA code indicating that an invalid checksum was found in a .jtr file.- See Also:
-
GOOD_CHECKSUM
public static final int GOOD_CHECKSUMA code indicating that a good checksum was found in a .jtr file.- See Also:
-
NUM_CHECKSUM_STATES
public static final int NUM_CHECKSUM_STATESThe number of different checksum states (none, good, bad).- See Also:
-
MESSAGE_OUTPUT_NAME
The name of the default output that all Sections are equipped with.- See Also:
-
MSG_SECTION_NAME
The name of the default section that all TestResult objects are equipped with.- See Also:
-
DESCRIPTION
The name of the property that defines the test description file.- See Also:
-
END
The name of the property that defines the time at which the test execution finished.- See Also:
-
ENVIRONMENT
The name of the property that defines the environment name.- See Also:
-
EXEC_STATUS
The name of the property that defines the test execution status.- See Also:
-
JAVATEST_OS
The name of the property that defines the OS on which JT Harness was running when the test was run.- See Also:
-
SCRIPT
The name of the property that defines the script that ran the test.- See Also:
-
SECTIONS
The name of the property that defines the test output sections that were recorded when the test ran.- See Also:
-
START
The name of the property that defines the time at which the test execution started.- See Also:
-
TEST
The name of the property that defines the test for which this is the result object.- See Also:
-
VERSION
The name of the property that defines which version of JT Harness was used to run the test.- See Also:
-
WORK
The name of the property that defines the work directory for the test.- See Also:
-
VARIETY
The name of the property that defines the variety of harness in use. Generally the full harness or the lite version.- See Also:
-
LOADER
The name of the property that defines the type of class loader used when running the harness (classpath mode or module mode generally).- See Also:
-
dateFormat
DateFormat, that is used to store date into TestResult
-
-
Constructor Details
-
TestResult
Construct a test result object that will be built as the test runs. The status string will be "running..." rather than "not run".- Parameters:
td
- The test description to base this new object on. Cannot be null.
-
TestResult
Reconstruct the results of a previously run test.- Parameters:
td
- Description of the test that was runworkDir
- Work directory in which the tests were run- Throws:
TestResult.Fault
- if there is a problem recreating the results from the appropriate file in the work directory
-
TestResult
Reconstruct the results of a previously run test.- Parameters:
file
- File that the results have been stored into.- Throws:
TestResult.ReloadFault
- if there is a problem recreating the results from the given fileTestResult.ResultFileNotFoundFault
- if there is a problem locating the given file
-
TestResult
Reconstruct the results of a previously run test.- Parameters:
workDir
- The work directory where previous results for the guven test can be found.workRelativePath
- The path to the JTR to reload, relative to the workdir.- Throws:
TestResult.Fault
- if there is a problem recreating the results from the given file
-
TestResult
Create a temporary test result for which can be handed around in situations where a reasonable test result can't be created.- Parameters:
td
- Description of the tests
- Status to associate with running the test... presumed to be of the Status.FAILED type.
-
-
Method Details
-
notRun
Create a placeholder TestResult for a test that has not yet been run.- Parameters:
td
- The test description for the test- Returns:
- A test result that indicates that the test has not yet been run
-
getWorkRelativePath
Get the path name for the results file for a test, relative to the work directory. The internal separator is '/'.- Parameters:
td
- the test description for the test in question- Returns:
- the path name for the results file for a test, relative to the work directory
-
getWorkRelativePath
Get the path name for the results file for a test, relative to the work directory. The internal separator is '/'.- Parameters:
testURL
- May not be null;- Returns:
- The work relative path of the JTR for this test. Null if the given URL is null.
-
getWorkRelativePath
Get the path name for the results file for a test, relative to the work directory. The internal separator is '/'.- Parameters:
baseURL
- May not be null;testId
- The test identifier that goes with the URL. This may be null.- Returns:
- The work relative path of the JTR for this test. Null if the given URL is null.
-
isResultFile
Check if this file is or appears to be a result (.jtr) file, according to its filename extension.- Parameters:
f
- the file to be checked- Returns:
- true if this file is or appears to be a result (.jtr) file.
-
parseDate
Parse the date format used for timestamps, such as the start/stop timestamp.- Parameters:
s
- The string containing the date to be restored.- Throws:
ParseException
- See Also:
-
formatDate
Format the date format used for timestamps, such as the start/stop timestamp.- Parameters:
d
- The date object to be formatted into a string.- See Also:
-
createSection
Create a new section inside this test result.- Parameters:
name
- The symbolic name for this new section.- Returns:
- The new section that was created.
-
putProperty
Add a new property value to this TestResult.- Parameters:
name
- The name of the property to be updated.value
- The new value of the specified property.
-
setMaxOutputSize
public void setMaxOutputSize(int size) Sets the maximum output size for the current TestResult. The value will be used instead of the value specified by the system property javatest.maxOutputSize.- Parameters:
size
- the maximum number of characters.
-
reloadFromWorkDir
Reconstruct the results of a previously run test.- Parameters:
workDir
- Work directory in which the tests were run- Throws:
TestResult.Fault
- if an error occurs while reloading the results
-
getChecksumState
public byte getChecksumState()Get info about the checksum in this object.- Returns:
- a value indicating the validity or otherwise of the checksum found while reading this result object.
- See Also:
-
getTestCommentWriter
A way to write comments about the test execution into the results.- Returns:
- If this is null, then the object is in a state in which it does not accept new messages.
-
getTestName
Get the test name, as given by the test URL defined by TestDescription.getRootRelativeURL(). This method always returns a useful string, representing the test name.- Returns:
- the name of the test for which this is the result object
- See Also:
-
isReloadable
public boolean isReloadable()Check whether this test result can be reloaded from a file. This method does not validate the contents of the file.- Returns:
- true if the result file for this object can be read
-
isShrunk
public boolean isShrunk()Check whether this object has been "shrunk" to reduce its memory footprint. If it has, some or all of the data will have to be reloaded. This method is somewhat orthogonal toisReloadable()
and should not be used as a substitute.- Returns:
- True if this object is currently incomplete, false otherwise.
- See Also:
-
getDescription
Get the description of the test from which this result was created. Depending on how the test result was created, this information may not be immediately available, and may be recreated from the test result file.- Returns:
- the test description for this test result object
- Throws:
TestResult.Fault
- if there is a problem recreating the description from the results file.
-
getWorkRelativePath
Get the path name for the results file for this test, relative to the work directory. The internal separator is '/'.- Returns:
- the path name for the results file for this test, relative to the work directory
-
getFile
Get the name, if any, for the result file for this object. The path information contains platform specific path separators.- Returns:
- the name, if any, for the result file for this object
-
resetFile
public void resetFile() -
getPropertyNames
Get the keys of the properties that this object has stored.- Returns:
- the keys of the properties that this object has stored
-
getProperty
Get the value of a property of this test result.- Parameters:
name
- The name of the property to be retrieved.- Returns:
- The value corresponding to the property name, null if not found.
- Throws:
TestResult.Fault
- if there is a problem recreating data from the results file.
-
getEnvironment
Get a copy of the environment that this object has stored.- Returns:
- a copy of the environment that this object has stored
- Throws:
TestResult.Fault
- if there is a problem recreating data from the results file.- See Also:
-
setEnvironment
Set the environment used by this test. When the test is run, those entries in the environment that are referenced are noted; those entries will be recorded here in the test result object.- Parameters:
environment
- the test environment used by this test.- See Also:
-
getParent
Get the parent node in the test result table that contains this test result object.- Returns:
- the parent node in the test result table that contains this test result object.
-
isMutable
public boolean isMutable()Determine if the test result object is still mutable. Test results are only mutable while they are being created, up to the point that the final status is set.- Returns:
- true if the test result object is still mutable, and false otherwise
-
getStatus
Get the status for this test.- Returns:
- the status for this test
- See Also:
-
setStatus
Set the result of this test. This action makes this object immutable. If a result comparison is needed, it will be done in here.- Parameters:
stat
- A status object representing the outcome of the test- See Also:
-
getSectionCount
public int getSectionCount()Find out how many sections this test result contains.- Returns:
- The number of sections in this result.
-
getSection
Get the section specified by index. Remember that index 0 is the default message section.- Parameters:
index
- The index of the section to be retrieved.- Returns:
- The requested section. Will be null if the section does not exist.
- Throws:
TestResult.ReloadFault
- Will occur if an error is encountered when reloading JTR data. This may be the result of a corrupt or missing JTR file.- See Also:
-
getSectionTitles
Get the titles of all sections in this test result. A null result probably indicates that there are no sections. This is improbable since most test result object automatically have one section.- Returns:
- The titles, one at a time in the array. Null if the titles do not exist or could not be determined.
-
writeResults
Writes the TestResult into a version 2 jtr file.- Parameters:
workDir
- The work directory in which to write the resultsbackupPolicy
- a policy object defining what to do if a file already exists with the same name as that which is about to be written.- Throws:
IllegalStateException
- This will occur if you attempt to write a result which is still mutable.IOException
- Occurs when the output file cannot be created or written to. Under this condition, this object will change it status to an error.
-
addObserver
Add an observer to watch this test result for changes.- Parameters:
obs
- the observer to be added
-
removeObserver
Remove an observer that was previously added.- Parameters:
obs
- the observer to be removed
-
getEndTime
public long getEndTime()Gets the time when the test was completed, or at least the time when it's final status was set. Be aware that if the information is not available in memory, it will be loaded from disk.- Returns:
- Time when this test acquired its final status setting.
- See Also:
-
toString
-