org.castor.xmlctf

Class XMLTestCase

Known Direct Subclasses:
MarshallingFrameworkTestCase, OnlySourceGenerationTestCase, SchemaTestCase, SourceGeneratorTestCase, TestSourceGenerator

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.

Version:
$Revision: 6787 $ $Date: 2006-04-26 15:14:53 -0600 (Wed, 26 Apr 2006) $
Authors:
Sebastien Gignoux
Arnaud Blandin

Field Summary

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.

Constructor Summary

XMLTestCase(String name)
Instantiate a new XMLTestCase with the given name.
XMLTestCase(String name, XMLTestCase tc)
Instantiates a new test cases that has the same configuration of the given test case.
XMLTestCase(CastorTestCase test, UnitTestCase unit)
Instantiates a new test case that represents the given UnitTestCase.

Method Summary

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.

Field Details

_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.

Constructor Details

XMLTestCase

public XMLTestCase(String name)
Instantiate a new XMLTestCase with the given name.
Parameters:
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.
Parameters:
name - the name of the test case
tc - 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.
Parameters:
test - the reference to the jar/directory
unit - the UnitTestCase that wraps the configuration for this XML Test case.

Method Details

buildObjectModel

protected Object buildObjectModel(String builderName)
            throws java.lang.Exception
Returns an instance of the object model hardcoded in the given ObjectModelBuilder.
Parameters:
builderName - the name of the class used as a builder
Returns:
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).
Parameters:
exception - the Exception that was thrown
checkStep - the test step that threw an Exception
Returns:
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.

Parameters:
name - the input name
Returns:
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.
Returns:
the name of the test suite to which this test case belongs to.

getXMLContext

public XMLContext getXMLContext()

initializeListeners

protected void initializeListeners(ListenerType listener)
            throws ClassNotFoundException,
                   IllegalAccessException,
                   InstantiationException
Initialize listeners for marshalling/unmarshalling
Parameters:
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!
Parameters:
objectInvoked - the object on which to invoke the methods
config - 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.
Parameters:
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.
Parameters:
object - the object to marshall.
fileName - the name of the file where to marshall the object.
Returns:
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.
Parameters:
file - the file containing the xml document to unmarshall.
Returns:
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.
Parameters:
stream - the input stream containing the xml document to unmarshall.
Returns:
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.
Parameters:
message - the message to print

Intalio Inc. (C) 1999-2008. All rights reserved http://www.intalio.com