|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.sun.javatest.TestResult
public class 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 | |
---|---|
static class |
TestResult.Fault
This exception is to report problems using TestResult objects. |
static interface |
TestResult.Observer
An interface to observe activity in a TestResult as it is created. |
static class |
TestResult.ReloadFault
This exception ay occur anytime the JTR file is being read from the filesystem. |
static class |
TestResult.ResultFileNotFoundFault
This exception is thrown if the JTR file cannot be found. |
class |
TestResult.Section
This "section" is the logical combination of a single action during test execution. |
Field Summary | |
---|---|
static int |
BAD_CHECKSUM
A code indicating that an invalid checksum was found in a .jtr file. |
static java.lang.String |
DESCRIPTION
The name of the property that defines the test description file. |
static java.lang.String |
END
The name of the property that defines the time at which the test execution finished. |
static java.lang.String |
ENVIRONMENT
The name of the property that defines the environment name. |
static java.lang.String |
EXEC_STATUS
The name of the property that defines the test execution status. |
static int |
GOOD_CHECKSUM
A code indicating that a good checksum was found in a .jtr file. |
static java.lang.String |
JAVATEST_OS
The name of the property that defines the OS on which JT Harness was running when the test was run. |
static java.lang.String |
MESSAGE_OUTPUT_NAME
The name of the default output that all Sections are equipped with. |
static java.lang.String |
MSG_SECTION_NAME
The name of the default section that all TestResult objects are equipped with. |
static int |
NO_CHECKSUM
A code indicating that no checksum was found in a .jtr file. |
static int |
NUM_CHECKSUM_STATES
The number of different checksum states (none, good, bad). |
static java.lang.String |
SCRIPT
The name of the property that defines the script that ran the test. |
static java.lang.String |
SECTIONS
The name of the property that defines the test output sections that were recorded when the test ran. |
static java.lang.String |
START
The name of the property that defines the time at which the test execution started. |
static java.lang.String |
TEST
The name of the property that defines the test for which this is the result object. |
static java.lang.String |
VERSION
The name of the property that defines which version of JT Harness was used to run the test. |
static java.lang.String |
WORK
The name of the property that defines the work directory for the test. |
Constructor Summary | |
---|---|
TestResult(java.io.File file)
Reconstruct the results of a previously run test. |
|
TestResult(TestDescription td)
Construct 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,
java.lang.String workRelativePath)
Reconstruct the results of a previously run test. |
Method Summary | |
---|---|
void |
addObserver(TestResult.Observer obs)
Add an observer to watch this test result for changes. |
TestResult.Section |
createSection(java.lang.String name)
Create a new section inside this test result. |
static java.lang.String |
formatDate(java.util.Date d)
Format the date format used for timestamps, such as the start/stop timestamp. |
byte |
getChecksumState()
Get info about the checksum in this object. |
TestDescription |
getDescription()
Get the description of the test from which this result was created. |
long |
getEndTime()
Gets the time when the test was completed, or at least the time when it's final status was set. |
java.util.Map |
getEnvironment()
Get a copy of the environment that this object has stored. |
java.io.File |
getFile()
Get the name, if any, for the result file for this object. |
TestResultTable.TreeNode |
getParent()
Get the parent node in the test result table that contains this test result object. |
java.lang.String |
getProperty(java.lang.String name)
Get the value of a property of this test result. |
java.util.Enumeration |
getPropertyNames()
Get the keys of the properties that this object has stored. |
TestResult.Section |
getSection(int index)
Get the section specified by index. |
int |
getSectionCount()
Find out how many sections this test result contains. |
java.lang.String[] |
getSectionTitles()
Get the titles of all sections in this test result. |
Status |
getStatus()
Get the status for this test. |
java.io.PrintWriter |
getTestCommentWriter()
A way to write comments about the test execution into the results. |
java.lang.String |
getTestName()
Get the test name, as given by the test URL defined by TestDescription.getRootRelativeURL(). |
java.lang.String |
getWorkRelativePath()
Get the path name for the results file for this test, relative to the work directory. |
static java.lang.String |
getWorkRelativePath(java.lang.String testURL)
Get the path name for the results file for a test, relative to the work directory. |
static java.lang.String |
getWorkRelativePath(java.lang.String baseURL,
java.lang.String testId)
Get the path name for the results file for a test, relative to the work directory. |
static java.lang.String |
getWorkRelativePath(TestDescription td)
Get the path name for the results file for a test, relative to the work directory. |
boolean |
isMutable()
Determine if the test result object is still mutable. |
boolean |
isReloadable()
Check whether this test result can be reloaded from a file. |
static boolean |
isResultFile(java.io.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 |
notRun(TestDescription td)
Create a placeholder TestResult for a test that has not yet been run. |
static java.util.Date |
parseDate(java.lang.String s)
Parse the date format used for timestamps, such as the start/stop timestamp. |
void |
putProperty(java.lang.String name,
java.lang.String value)
Add a new property value to this TestResult. |
void |
reloadFromWorkDir(WorkDirectory workDir)
Reconstruct the results of a previously run test. |
void |
removeObserver(TestResult.Observer obs)
Remove an observer that was previously added. |
void |
resetFile()
|
void |
setEnvironment(TestEnvironment environment)
Set the environment used by this test. |
void |
setStatus(Status stat)
Set the result of this test. |
void |
writeResults(WorkDirectory workDir,
BackupPolicy backupPolicy)
Writes the TestResult into a version 2 jtr file. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int NO_CHECKSUM
getChecksumState()
,
Constant Field Valuespublic static final int BAD_CHECKSUM
getChecksumState()
,
Constant Field Valuespublic static final int GOOD_CHECKSUM
getChecksumState()
,
Constant Field Valuespublic static final int NUM_CHECKSUM_STATES
public static final java.lang.String MESSAGE_OUTPUT_NAME
public static final java.lang.String MSG_SECTION_NAME
public static final java.lang.String DESCRIPTION
public static final java.lang.String END
public static final java.lang.String ENVIRONMENT
public static final java.lang.String EXEC_STATUS
public static final java.lang.String JAVATEST_OS
public static final java.lang.String SCRIPT
public static final java.lang.String SECTIONS
public static final java.lang.String START
public static final java.lang.String TEST
public static final java.lang.String VERSION
public static final java.lang.String WORK
Constructor Detail |
---|
public TestResult(TestDescription td)
td
- The test description to base this new object on. Cannot be
null.public TestResult(TestDescription td, WorkDirectory workDir) throws TestResult.Fault
workDir
- Work directory in which the tests were runtd
- Description of the test that was run
TestResult.Fault
- if there is a problem recreating the results
from the appropriate file in the work directorypublic TestResult(java.io.File file) throws TestResult.ResultFileNotFoundFault, TestResult.ReloadFault
file
- File that the results have been stored into.
TestResult.ReloadFault
- if there is a problem recreating the results
from the given file
TestResult.ResultFileNotFoundFault
- if there is a problem locating
the given filepublic TestResult(WorkDirectory workDir, java.lang.String workRelativePath) throws TestResult.Fault
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.
TestResult.Fault
- if there is a problem recreating the results
from the given filepublic TestResult(TestDescription td, Status s)
td
- Description of the tests
- Status to associate with running the test... presumed
to be of the Status.FAILED type.Method Detail |
---|
public static TestResult notRun(TestDescription td)
td
- The test description for the test
public TestResult.Section createSection(java.lang.String name)
name
- The symbolic name for this new section.
public void setEnvironment(TestEnvironment environment)
environment
- the test environment used by this test.getEnvironment()
public void setStatus(Status stat)
stat
- A status object representing the outcome of the testgetStatus()
public void putProperty(java.lang.String name, java.lang.String value)
name
- The name of the property to be updated.value
- The new value of the specified property.public void reloadFromWorkDir(WorkDirectory workDir) throws TestResult.Fault
workDir
- Work directory in which the tests were run
TestResult.Fault
- if an error occurs while reloading the resultspublic byte getChecksumState()
NO_CHECKSUM
,
BAD_CHECKSUM
,
GOOD_CHECKSUM
public java.io.PrintWriter getTestCommentWriter()
public java.lang.String getTestName()
TestDescription.getRootRelativeURL()
public boolean isReloadable()
public boolean isShrunk()
isReloadable()
and should not be used as a
substitute.
isReloadable()
public TestDescription getDescription() throws TestResult.Fault
TestResult.Fault
- if there is a problem recreating the description
from the results file.public java.lang.String getWorkRelativePath()
public java.io.File getFile()
public void resetFile()
public static java.lang.String getWorkRelativePath(TestDescription td)
td
- the test description for the test in question
public static java.lang.String getWorkRelativePath(java.lang.String testURL)
testURL
- May not be null;
public static java.lang.String getWorkRelativePath(java.lang.String baseURL, java.lang.String testId)
baseURL
- May not be null;testId
- The test identifier that goes with the URL. This may be null.
public java.util.Enumeration getPropertyNames()
public java.lang.String getProperty(java.lang.String name) throws TestResult.Fault
name
- The name of the property to be retrieved.
TestResult.Fault
- if there is a problem
recreating data from the results file.public java.util.Map getEnvironment() throws TestResult.Fault
TestResult.Fault
- if there is a problem
recreating data from the results file.setEnvironment(com.sun.javatest.TestEnvironment)
public TestResultTable.TreeNode getParent()
public boolean isMutable()
public Status getStatus()
setStatus(com.sun.javatest.Status)
public int getSectionCount()
public TestResult.Section getSection(int index) throws TestResult.ReloadFault
index
- The index of the section to be retrieved.
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.MSG_SECTION_NAME
public java.lang.String[] getSectionTitles()
public static boolean isResultFile(java.io.File f)
f
- the file to be checked
public void writeResults(WorkDirectory workDir, BackupPolicy backupPolicy) throws java.io.IOException
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.
java.lang.IllegalStateException
- This will occur if you attempt to write a result
which is still mutable.
java.io.IOException
- Occurs when the output file cannot be created or written to.
Under this condition, this object will change it status to an error.public void addObserver(TestResult.Observer obs)
obs
- the observer to be addedpublic void removeObserver(TestResult.Observer obs)
obs
- the observer to be removedpublic long getEndTime()
setStatus(com.sun.javatest.Status)
,
Date
public static java.util.Date parseDate(java.lang.String s) throws java.text.ParseException
s
- The string containing the date to be restored.
java.text.ParseException
formatDate(java.util.Date)
public static java.lang.String formatDate(java.util.Date d)
d
- The date object to be formatted into a string.parseDate(java.lang.String)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |