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

    Fields
    Modifier and Type
    Field
    Description
    protected 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

    Constructors
    Constructor
    Description
    Instantiate a new XMLTestCase with the given name.
    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 Type
    Method
    Description
    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
    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/unmarshalling
    protected List
    invokeEnumeratedMethods(Object objectInvoked, ConfigurationType config)
    Invokes all requested methods on the object we are supplied.
    void
    Sets the name of the test suite to which this test case belongs to.
    protected abstract void
     
    void
     
    protected abstract void
     
    protected File
    testMarshal(Object object, String fileName)
    Marshals the object with the configuration of the test.
    protected Object
    Unmarshals the given file with the configuration of that test.
    protected Object
    Unmarshals the given input stream with the configuration of that test.
    protected void
    verbose(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

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • _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 String _suiteName
      Name of the test suite to which this test belongs.
    • _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.
    • _rootClass

      protected 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 Object _listener
      A listener for marshalling.
    • _listenerType

      protected TypeType _listenerType
      Type of listener test -- Marshal, Unmarshal or Both.
    • _listenerGoldFile

      protected String _listenerGoldFile
      Gold file for listener.
    • _configuration

      protected Configuration _configuration
      The Configuration the Marshalling Framework.
    • _name

      protected final String _name
      Name of this test.
    • _unitTest

      protected final UnitTestCase _unitTest
      The unit test case this class represent.
    • _outputRootFile

      protected final 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 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(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.
    • 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
  • Method Details

    • setUp

      protected abstract void setUp() throws Exception
      Overrides:
      setUp in class junit.framework.TestCase
      Throws:
      Exception
    • tearDown

      protected abstract void tearDown() throws Exception
      Overrides:
      tearDown in class junit.framework.TestCase
      Throws:
      Exception
    • setXMLContext

      public void setXMLContext(XMLContext xmlContext)
    • getXMLContext

      public XMLContext getXMLContext()
    • cleanup

      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.
    • 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.
    • 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.
    • 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)
    • 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.
      Throws:
      Exception - if anything goes wrong during the test
    • 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.
      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 methods
      config - 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

      protected Object buildObjectModel(String builderName) throws 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.
      Throws:
      Exception - if anything goes wrong during the test
    • verbose

      protected void verbose(String message)
      print the message if in verbose mode.
      Parameters:
      message - the message to print