org.castor.xmlctf
Class XMLTestCase
TestCase
org.castor.xmlctf.XMLTestCase
public abstract class XMLTestCase
extends TestCase
This class encapsulates all the common logic to run the test patterns for
Castor XML. Basically it handle the marshalling/marshalling/comparing. This
is used to factor the common code for the source generator test and the
mapping/introspection tests as only the setup differ in the test patterns.
This class is not complete and expects to be extended.
$Revision: 6787 $ $Date: 2006-04-26 15:14:53 -0600 (Wed, 26 Apr 2006) $protected Configuration | _configuration - The Configuration the Marshalling Framework.
|
protected FailureType | _failure - The failure object that is not null if the test is expected to fail.
|
protected boolean | _hasDump - If true, the dumpFields() function has been implemented in the root class.
|
protected Object | _listener - A listener for marshalling.
|
protected String | _listenerGoldFile - Gold file for listener.
|
protected TypeType | _listenerType - Type of listener test -- Marshal, Unmarshal or Both.
|
protected Mapping | _mapping - The name of the mapping file to use in a Marshalling Framework Test Case.
|
protected String | _name - Name of this test.
|
protected File | _outputRootFile - Place where the temporary file have to be put.
|
protected static boolean | _printStack - True if we dump the stack trace for any exception that occurs during testing.
|
protected Class | _rootClass - The root class for this test.
|
protected String | _rootClassName - The name of the root class for this test.
|
protected boolean | _skip - True if the test needs to be skipped.
|
protected String | _suiteName - Name of the test suite to which this test belongs.
|
protected CastorTestCase | _test - Used only to retrieve the classloader.
|
protected UnitTestCase | _unitTest - The unit test case this class represent.
|
static boolean | _verbose - True if we desire a lot of info on what happen.
|
protected Object | buildObjectModel(String builderName) - Returns an instance of the object model hardcoded in the given
ObjectModelBuilder.
|
protected boolean | checkExceptionWasExpected(Exception exception, FailureStepType checkStep) - Called when a test case throws an Exception.
|
(package private) static String | cleanup(String name) - Returns a version of the input name that is suitable for JUnit test case
or test suite use.
|
String | getTestSuiteName() - Returns the name of the test suite to which this test case belongs to.
|
XMLContext | getXMLContext()
|
protected void | initializeListeners(ListenerType listener) - Initialize listeners for marshalling/unmarshalling
|
protected List | invokeEnumeratedMethods(Object objectInvoked, ConfigurationType config) - Invokes all requested methods on the object we are supplied.
|
void | setTestSuiteName(String suiteName) - Sets the name of the test suite to which this test case belongs to.
|
protected abstract void | setUp()
|
void | setXMLContext(XMLContext xmlContext)
|
protected abstract void | tearDown()
|
protected File | testMarshal(Object object, String fileName) - Marshals the object with the configuration of the test.
|
protected Object | testUnmarshal(File file) - Unmarshals the given file with the configuration of that test.
|
protected Object | testUnmarshal(InputStream stream) - Unmarshals the given input stream with the configuration of that test.
|
protected void | verbose(String message) - print the message if in verbose mode.
|
_configuration
protected Configuration _configuration
The Configuration the Marshalling Framework.
_failure
protected final FailureType _failure
The failure object that is not null if the test is expected to fail.
_hasDump
protected boolean _hasDump
If true, the dumpFields() function has been implemented in the root class.
_listener
protected Object _listener
A listener for marshalling.
_listenerGoldFile
protected String _listenerGoldFile
Gold file for listener.
_listenerType
protected TypeType _listenerType
Type of listener test -- Marshal, Unmarshal or Both.
_mapping
protected Mapping _mapping
The name of the mapping file to use in a Marshalling Framework Test Case.
Must be set by a concrete class if a test with a reference document is used.
_name
protected final String _name
Name of this test.
_outputRootFile
protected final File _outputRootFile
Place where the temporary file have to be put.
_printStack
protected static boolean _printStack
True if we dump the stack trace for any exception that occurs during testing.
_rootClass
protected Class _rootClass
The root class for this test. Must be set by a concrete class.
_rootClassName
protected String _rootClassName
The name of the root class for this test. Must be set by a concrete class
if a test with a random object is used.
_skip
protected final boolean _skip
True if the test needs to be skipped.
_suiteName
protected String _suiteName
Name of the test suite to which this test belongs.
_test
protected final CastorTestCase _test
Used only to retrieve the classloader.
_unitTest
protected final UnitTestCase _unitTest
The unit test case this class represent.
_verbose
public static boolean _verbose
True if we desire a lot of info on what happen.
XMLTestCase
public XMLTestCase(String name)
Instantiate a new XMLTestCase with the given name.
name
- the name of this test case.
XMLTestCase
public XMLTestCase(String name,
XMLTestCase tc)
Instantiates a new test cases that has the same configuration of the given
test case.
name
- the name of the test casetc
- the XML test case that hold the configuration for this test case
XMLTestCase
public XMLTestCase(CastorTestCase test,
UnitTestCase unit)
Instantiates a new test case that represents the given UnitTestCase.
test
- the reference to the jar/directoryunit
- the UnitTestCase that wraps the configuration for this XML Test case.
buildObjectModel
protected Object buildObjectModel(String builderName)
throws java.lang.Exception
Returns an instance of the object model hardcoded in the given
ObjectModelBuilder.
builderName
- the name of the class used as a builder
- an instance of the object model hardcoded in the given
ObjectModelBuilder.
checkExceptionWasExpected
protected boolean checkExceptionWasExpected(Exception exception,
FailureStepType checkStep)
Called when a test case throws an Exception. Returns true if we expected
this test to fail (and if this was the correct Exception class, if one is
specified, and if this was the correct test step for the failure to
occur, if one was specified).
exception
- the Exception that was throwncheckStep
- the test step that threw an Exception
- true if we pass the test (because we expected this Exception)
cleanup
(package private) static String cleanup(String name)
Returns a version of the input name that is suitable for JUnit test case
or test suite use. Apparently, JUnit truncates test case names after
encountering certain characters, so we scrub those characters from the
test case or test suite name.
We also translate all whitespace to blanks, remove all leading and
trailing whitespace, and collapse consecutive whitespace to a single
blank.
- a name suitable for JUnit test case or test suite use.
getTestSuiteName
public String getTestSuiteName()
Returns the name of the test suite to which this test case belongs to.
- the name of the test suite to which this test case belongs to.
initializeListeners
protected void initializeListeners(ListenerType listener)
throws ClassNotFoundException,
IllegalAccessException,
InstantiationException
Initialize listeners for marshalling/unmarshalling
listener
- the listener to initialize
invokeEnumeratedMethods
protected List invokeEnumeratedMethods(Object objectInvoked,
ConfigurationType config)
throws java.lang.Exception
Invokes all requested methods on the object we are supplied. Keeps track
of the objects returned from each invocation and returns a List containing
all of the return values. Some of the return values may be null. This
is not an error!
objectInvoked
- the object on which to invoke the methodsconfig
- configuration object listing the methods we are to call
setTestSuiteName
public void setTestSuiteName(String suiteName)
Sets the name of the test suite to which this test case belongs to.
suiteName
- the name of the test suite.
setUp
protected abstract void setUp()
throws Exception
setXMLContext
public void setXMLContext(XMLContext xmlContext)
tearDown
protected abstract void tearDown()
throws Exception
testMarshal
protected File testMarshal(Object object,
String fileName)
Marshals the object with the configuration of the test.
object
- the object to marshall.fileName
- the name of the file where to marshall the object.
- a file containing marshalled output.
testUnmarshal
protected Object testUnmarshal(File file)
throws Exception
Unmarshals the given file with the configuration of that test. If we
unmarshal null, complain and fail the test case.
file
- the file containing the xml document to unmarshall.
- the result of the unmarshalling of the given file.
testUnmarshal
protected Object testUnmarshal(InputStream stream)
throws Exception
Unmarshals the given input stream with the configuration of that test.
stream
- the input stream containing the xml document to unmarshall.
- the result of the unmarshalling of the given file, null if
anything went wrong.
verbose
protected void verbose(String message)
print the message if in verbose mode.
message
- the message to print
Intalio Inc. (C) 1999-2008. All rights reserved http://www.intalio.com