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.TestCaseThis 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
Fields Modifier and Type Field Description protected Configuration_configurationThe Configuration the Marshalling Framework.protected FailureType_failureThe failure object that is not null if the test is expected to fail.protected boolean_hasDumpIf true, the dumpFields() function has been implemented in the root class.protected java.lang.Object_listenerA listener for marshalling.protected java.lang.String_listenerGoldFileGold file for listener.protected TypeType_listenerTypeType of listener test -- Marshal, Unmarshal or Both.protected Mapping_mappingThe name of the mapping file to use in a Marshalling Framework Test Case.protected java.lang.String_nameName of this test.protected java.io.File_outputRootFilePlace where the temporary file have to be put.protected static boolean_printStackTrue if we dump the stack trace for any exception that occurs during testing.protected java.lang.Class_rootClassThe root class for this test.protected java.lang.String_rootClassNameThe name of the root class for this test.protected boolean_skipTrue if the test needs to be skipped.protected java.lang.String_suiteNameName of the test suite to which this test belongs.protected CastorTestCase_testUsed only to retrieve the classloader.protected UnitTestCase_unitTestThe unit test case this class represent.static boolean_verboseTrue if we desire a lot of info on what happen.
-
Constructor Summary
Constructors Constructor Description XMLTestCase(java.lang.String name)Instantiate a new XMLTestCase with the given name.XMLTestCase(java.lang.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
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected java.lang.ObjectbuildObjectModel(java.lang.String builderName)Returns an instance of the object model hardcoded in the given ObjectModelBuilder.protected booleancheckExceptionWasExpected(java.lang.Exception exception, FailureStepType checkStep)Called when a test case throws an Exception.(package private) static java.lang.Stringcleanup(java.lang.String name)Returns a version of the input name that is suitable for JUnit test case or test suite use.java.lang.StringgetTestSuiteName()Returns the name of the test suite to which this test case belongs to.XMLContextgetXMLContext()protected voidinitializeListeners(ListenerType listener)Initialize listeners for marshalling/unmarshallingprotected java.util.ListinvokeEnumeratedMethods(java.lang.Object objectInvoked, ConfigurationType config)Invokes all requested methods on the object we are supplied.voidsetTestSuiteName(java.lang.String suiteName)Sets the name of the test suite to which this test case belongs to.protected abstract voidsetUp()voidsetXMLContext(XMLContext xmlContext)protected abstract voidtearDown()protected java.io.FiletestMarshal(java.lang.Object object, java.lang.String fileName)Marshals the object with the configuration of the test.protected java.lang.ObjecttestUnmarshal(java.io.File file)Unmarshals the given file with the configuration of that test.protected java.lang.ObjecttestUnmarshal(java.io.InputStream stream)Unmarshals the given input stream with the configuration of that test.protected voidverbose(java.lang.String message)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 Detail
-
_verbose
public static boolean _verbose
True if we desire a lot of info on what happen.
-
_printStack
protected static boolean _printStack
True if we dump the stack trace for any exception that occurs during testing.
-
_suiteName
protected java.lang.String _suiteName
Name of the test suite to which this test belongs.
-
_rootClassName
protected java.lang.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.
-
_rootClass
protected java.lang.Class _rootClass
The root class for this test. Must be set by a concrete class.
-
_hasDump
protected boolean _hasDump
If true, the dumpFields() function has been implemented in the root class.
-
_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.
-
_listener
protected java.lang.Object _listener
A listener for marshalling.
-
_listenerType
protected TypeType _listenerType
Type of listener test -- Marshal, Unmarshal or Both.
-
_listenerGoldFile
protected java.lang.String _listenerGoldFile
Gold file for listener.
-
_configuration
protected Configuration _configuration
The Configuration the Marshalling Framework.
-
_name
protected final java.lang.String _name
Name of this test.
-
_unitTest
protected final UnitTestCase _unitTest
The unit test case this class represent.
-
_outputRootFile
protected final java.io.File _outputRootFile
Place where the temporary file have to be put.
-
_skip
protected final boolean _skip
True if the test needs to be skipped.
-
_failure
protected final FailureType _failure
The failure object that is not null if the test is expected to fail.
-
_test
protected final CastorTestCase _test
Used only to retrieve the classloader.
-
-
Constructor Detail
-
XMLTestCase
public XMLTestCase(java.lang.String name)
Instantiate a new XMLTestCase with the given name.- Parameters:
name- the name of 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/directoryunit- the UnitTestCase that wraps the configuration for this XML Test case.
-
XMLTestCase
public XMLTestCase(java.lang.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 casetc- the XML test case that hold the configuration for this test case
-
-
Method Detail
-
setUp
protected abstract void setUp() throws java.lang.Exception- Overrides:
setUpin classjunit.framework.TestCase- Throws:
java.lang.Exception
-
tearDown
protected abstract void tearDown() throws java.lang.Exception- Overrides:
tearDownin classjunit.framework.TestCase- Throws:
java.lang.Exception
-
setXMLContext
public void setXMLContext(XMLContext xmlContext)
-
getXMLContext
public XMLContext getXMLContext()
-
cleanup
static java.lang.String cleanup(java.lang.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.
-
setTestSuiteName
public void setTestSuiteName(java.lang.String suiteName)
Sets the name of the test suite to which this test case belongs to.- Parameters:
suiteName- the name of the test suite.
-
getTestSuiteName
public java.lang.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.
-
checkExceptionWasExpected
protected boolean checkExceptionWasExpected(java.lang.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 throwncheckStep- the test step that threw an Exception- Returns:
- true if we pass the test (because we expected this Exception)
-
testMarshal
protected java.io.File testMarshal(java.lang.Object object, java.lang.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 java.lang.Object testUnmarshal(java.io.File file) throws java.lang.ExceptionUnmarshals 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:
java.lang.Exception- if anything goes wrong during the test
-
testUnmarshal
protected java.lang.Object testUnmarshal(java.io.InputStream stream) throws java.lang.ExceptionUnmarshals 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:
java.lang.Exception- if anything goes wrong during the test
-
invokeEnumeratedMethods
protected java.util.List invokeEnumeratedMethods(java.lang.Object objectInvoked, ConfigurationType config) throws java.lang.ExceptionInvokes 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:
java.lang.Exception- if anything goes wrong during the test
-
initializeListeners
protected void initializeListeners(ListenerType listener) throws java.lang.ClassNotFoundException, java.lang.IllegalAccessException, java.lang.InstantiationExceptionInitialize listeners for marshalling/unmarshalling- Parameters:
listener- the listener to initialize- Throws:
java.lang.ClassNotFoundExceptionjava.lang.IllegalAccessExceptionjava.lang.InstantiationException
-
buildObjectModel
protected java.lang.Object buildObjectModel(java.lang.String builderName) throws java.lang.ExceptionReturns 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:
java.lang.Exception- if anything goes wrong during the test
-
verbose
protected void verbose(java.lang.String message)
print the message if in verbose mode.- Parameters:
message- the message to print
-
-