Package org.castor.xmlctf
Class XMLTestCase
java.lang.Object
junit.framework.Assert
junit.framework.TestCase
org.castor.xmlctf.XMLTestCase
- All Implemented Interfaces:
junit.framework.Test
- Direct Known Subclasses:
MarshallingFrameworkTestCase
,OnlySourceGenerationTestCase
,SchemaTestCase
,SourceGeneratorTestCase
,TestSourceGenerator
public abstract class XMLTestCase
extends junit.framework.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) $
- Author:
- Sebastien Gignoux, Arnaud Blandin
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Configuration
The Configuration the Marshalling Framework.protected final FailureType
The failure object that is not null if the test is expected to fail.protected boolean
If true, the dumpFields() function has been implemented in the root class.protected Object
A listener for marshalling.protected String
Gold file for listener.protected TypeType
Type of listener test -- Marshal, Unmarshal or Both.protected Mapping
The name of the mapping file to use in a Marshalling Framework Test Case.protected final String
Name of this test.protected final File
Place where the temporary file have to be put.protected static boolean
True if we dump the stack trace for any exception that occurs during testing.protected Class
The root class for this test.protected String
The name of the root class for this test.protected final boolean
True if the test needs to be skipped.protected String
Name of the test suite to which this test belongs.protected final CastorTestCase
Used only to retrieve the classloader.protected final UnitTestCase
The unit test case this class represent.static boolean
True if we desire a lot of info on what happen. -
Constructor Summary
ConstructorsConstructorDescriptionXMLTestCase
(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
Modifier and TypeMethodDescriptionprotected 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
Returns a version of the input name that is suitable for JUnit test case or test suite use.Returns the name of the test suite to which this test case belongs to.protected void
initializeListeners
(ListenerType listener) Initialize listeners for marshalling/unmarshallingprotected 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
print the message if in verbose mode.Methods inherited from class junit.framework.TestCase
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, countTestCases, createResult, fail, fail, failNotEquals, failNotSame, failSame, format, getName, run, run, runBare, runTest, setName, toString
-
Field Details
-
_verbose
public static boolean _verboseTrue if we desire a lot of info on what happen. -
_printStack
protected static boolean _printStackTrue if we dump the stack trace for any exception that occurs during testing. -
_suiteName
Name of the test suite to which this test belongs. -
_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. -
_rootClass
The root class for this test. Must be set by a concrete class. -
_hasDump
protected boolean _hasDumpIf true, the dumpFields() function has been implemented in the root class. -
_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. -
_listener
A listener for marshalling. -
_listenerType
protected TypeType _listenerTypeType of listener test -- Marshal, Unmarshal or Both. -
_listenerGoldFile
Gold file for listener. -
_configuration
protected Configuration _configurationThe Configuration the Marshalling Framework. -
_name
Name of this test. -
_unitTest
protected final UnitTestCase _unitTestThe unit test case this class represent. -
_outputRootFile
Place where the temporary file have to be put. -
_skip
protected final boolean _skipTrue if the test needs to be skipped. -
_failure
protected final FailureType _failureThe failure object that is not null if the test is expected to fail. -
_test
Used only to retrieve the classloader.
-
-
Constructor Details
-
XMLTestCase
Instantiate a new XMLTestCase with the given name.- Parameters:
name
- the name of this test case.
-
XMLTestCase
Instantiates a new test case that represents the given UnitTestCase.- Parameters:
test
- the reference to the jar/directoryunit
- the UnitTestCase that wraps the configuration for this XML Test case.
-
XMLTestCase
Instantiates a new test cases that has the same configuration of the given test case.- Parameters:
name
- the name of the test casetc
- the XML test case that hold the configuration for this test case
-
-
Method Details
-
setUp
- Overrides:
setUp
in classjunit.framework.TestCase
- Throws:
Exception
-
tearDown
- Overrides:
tearDown
in classjunit.framework.TestCase
- Throws:
Exception
-
setXMLContext
-
getXMLContext
-
cleanup
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.
-
setTestSuiteName
Sets the name of the test suite to which this test case belongs to.- Parameters:
suiteName
- the name of the test suite.
-
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.
-
checkExceptionWasExpected
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 throwncheckStep
- the test step that threw an Exception- Returns:
- true if we pass the test (because we expected this Exception)
-
testMarshal
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
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.
- Throws:
Exception
- if anything goes wrong during the test
-
testUnmarshal
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.
- Throws:
Exception
- if anything goes wrong during the test
-
invokeEnumeratedMethods
protected List invokeEnumeratedMethods(Object objectInvoked, ConfigurationType config) throws 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 methodsconfig
- configuration object listing the methods we are to call- Throws:
Exception
- if anything goes wrong during the test
-
initializeListeners
protected void initializeListeners(ListenerType listener) throws ClassNotFoundException, IllegalAccessException, InstantiationException Initialize listeners for marshalling/unmarshalling- Parameters:
listener
- the listener to initialize- Throws:
ClassNotFoundException
IllegalAccessException
InstantiationException
-
buildObjectModel
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.
- Throws:
Exception
- if anything goes wrong during the test
-
verbose
print the message if in verbose mode.- Parameters:
message
- the message to print
-