junit.extensions.xml
Class XMLTestCase

java.lang.Object
  extended byjunit.framework.Assert
      extended byjunit.framework.TestCase
          extended byjunit.extensions.xml.XMLTestCase
All Implemented Interfaces:
IXMLTest, IXMLTestCase, junit.framework.Test, XMLConstants

public class XMLTestCase
extends junit.framework.TestCase
implements IXMLTestCase, XMLConstants

Test Case for running XML Script based testing.

Author:
Kevin Wilson, Vijay Aravamudhan : ThoughtWorks Inc.

Field Summary
private  org.w3c.dom.Element m_element
          The element to be processed.
private  java.lang.String m_filename
          The name of the test xml script file - found from the classpath.
private  IXMLTest m_parent
          Parent test.
private  XMLObjectCache m_procedures
          Map of the procedures for this test case.
private  XMLPropertyCache m_properties
          A Map of all objects that have been found - keyed by the string name.
 
Fields inherited from class junit.framework.TestCase
 
Fields inherited from interface junit.extensions.xml.XMLConstants
ACTION, ACTUALOBJ, ACTUALREFID, ADD, ASSERTENABLED, ASSERTEQUALS, ASSERTNOTEQUALS, ASSERTNOTNULL, ASSERTNOTSAME, ASSERTNULL, ASSERTSAME, CALL, CASE, CHOOSE, CLASSNAME, COLUMN, CONFIRM, DEBUG, DEFAULT, DELIMITER, DIALOG, DUMP, ECHO, ENABLED, ENCODING, EVALUATE, EXPECTEDOBJ, EXPECTEDREFID, FAIL, FILE, FOCUS, FOREACH, ID, INDEX, JFCFILELOC, LESSTHAN, LISTITEM, LOG, MARK, MESSAGE, METHOD, MODE, NAME, OTHERWISE, PATHREFID, PROCEDURE, PROPERTY, RECURSIVE, REFID, RELATIVE, REMOVE, ROW, SAVE, STDERR, STDOUT, STOPWATCH, SUITE, SWITCH, TABLECELL, TAGHANDLERS, TAGNAME, TEST, TYPE, USERE, VALUE, WHEN, WHILE
 
Constructor Summary
XMLTestCase(java.lang.String filename, org.w3c.dom.Element element)
          The default constructor that is needed to createa a test case.
 
Method Summary
 void addProcedure(IXMLProcedure proc)
          Add a procedure definition.
 void addProperty(java.lang.String name, java.lang.Object obj)
          Add each found object into the cache map.
 void callProcedure(java.lang.String name, org.w3c.dom.Element element)
          Call a procedure by name.
 void clearProperties()
          For each test (method) element, the found objects has to be cleared.
 boolean getDebug()
          Get the debug state.
 IXMLProcedure getProcedure(java.lang.String name)
          Get a procedure definition.
 XMLObjectCache getProcedureCache()
          Get the procedure cache.
 java.lang.Object getProperty(java.lang.String name)
          Retrieve the object that was found previously.
 XMLObjectCache getPropertyCache()
          Get the property cache.
 java.lang.String getPropertyName(java.lang.Object comp)
          Get the name of a component which has been found.
 java.lang.String[] getPropertyNames()
          Get the names of the found objects.
 void processChildren(org.w3c.dom.Element element)
          Process the child XML Elements.
 void removeProperty(java.lang.String name)
          Remove the object with the name given.
 java.lang.String resolveProperties(java.lang.String s)
          Resolve embeded property names withing a string.
 void runBare()
          Sets up, executes and then tears down a test.
protected  void runTest()
          Executes a test.
 void runXMLTest()
          This method is the one that actually performs the test by processing the elements.
 void setParent(IXMLTest parent)
          Set the parent of the test case.
 void setUp()
          Default setUp which does nothing.
static junit.framework.Test suite()
          Returns an empty suite.
 void tearDown()
          Default tearDown which does nothing.
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, run, run, setName, toString
 
Methods inherited from class junit.framework.Assert
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, fail, fail
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface junit.extensions.xml.IXMLTestCase
getName, setName
 
Methods inherited from interface junit.framework.Test
countTestCases, run
 

Field Detail

m_element

private org.w3c.dom.Element m_element
The element to be processed.


m_parent

private IXMLTest m_parent
Parent test.


m_filename

private java.lang.String m_filename
The name of the test xml script file - found from the classpath.


m_procedures

private XMLObjectCache m_procedures
Map of the procedures for this test case.


m_properties

private XMLPropertyCache m_properties
A Map of all objects that have been found - keyed by the string name.

Constructor Detail

XMLTestCase

public XMLTestCase(java.lang.String filename,
                   org.w3c.dom.Element element)
The default constructor that is needed to createa a test case.

Parameters:
filename - The name of the test xml script file (found from the classpath)
element - The Element to be processed
Method Detail

getDebug

public final boolean getDebug()
Get the debug state.

Specified by:
getDebug in interface IXMLTest
Returns:
true if debug is enabled.

setParent

public final void setParent(IXMLTest parent)
Set the parent of the test case.

Specified by:
setParent in interface IXMLTest
Parameters:
parent - of the test case.

getProcedure

public final IXMLProcedure getProcedure(java.lang.String name)
Get a procedure definition.

Specified by:
getProcedure in interface IXMLTest
Parameters:
name - Name of the procedure.
Returns:
IXMLProcedure defined by name.

getProcedureCache

public final XMLObjectCache getProcedureCache()
Get the procedure cache.

Specified by:
getProcedureCache in interface IXMLTest
Returns:
XMLObjectCache which contains the procedure.

getProperty

public final java.lang.Object getProperty(java.lang.String name)
Retrieve the object that was found previously.

Specified by:
getProperty in interface IXMLTest
Parameters:
name - The name of the object that was found
Returns:
The object to be retrieved

getPropertyCache

public final XMLObjectCache getPropertyCache()
Get the property cache.

Specified by:
getPropertyCache in interface IXMLTest
Returns:
XMLObjectCache containing the properties.

getPropertyName

public final java.lang.String getPropertyName(java.lang.Object comp)
Get the name of a component which has been found.

Specified by:
getPropertyName in interface IXMLTest
Parameters:
comp - Component to locate
Returns:
The name of the component.

getPropertyNames

public final java.lang.String[] getPropertyNames()
Get the names of the found objects.

Specified by:
getPropertyNames in interface IXMLTest
Returns:
array containing the names of the objects.

setUp

public void setUp()
           throws java.lang.Exception
Default setUp which does nothing. Override this to set up the environment for your test.

Throws:
java.lang.Exception - An instance of java.lang.Exception can be thrown
See Also:
TestCase.setUp()

addProcedure

public final void addProcedure(IXMLProcedure proc)
Add a procedure definition.

Specified by:
addProcedure in interface IXMLTest
Parameters:
proc - Procedure to be added.

callProcedure

public final void callProcedure(java.lang.String name,
                                org.w3c.dom.Element element)
                         throws XMLException
Call a procedure by name.

Specified by:
callProcedure in interface IXMLTestCase
Parameters:
name - Name of the procedure to be called.
element - Element of the call
Throws:
XMLException - may be thrown.

processChildren

public final void processChildren(org.w3c.dom.Element element)
                           throws XMLException
Process the child XML Elements.

Specified by:
processChildren in interface IXMLTestCase
Parameters:
element - Element which has children to be processed.
Throws:
XMLException - may be thrown during processing.

removeProperty

public final void removeProperty(java.lang.String name)
Remove the object with the name given.

Specified by:
removeProperty in interface IXMLTest
Parameters:
name - Name of the object to be removed

resolveProperties

public final java.lang.String resolveProperties(java.lang.String s)
Resolve embeded property names withing a string.

Specified by:
resolveProperties in interface IXMLTest
Parameters:
s - String to be resolved.
Returns:
String without property names.

runBare

public void runBare()
             throws java.lang.Throwable
Sets up, executes and then tears down a test.

Throws:
java.lang.Throwable - exceptions thrown by code.

runXMLTest

public final void runXMLTest()
                      throws java.lang.Exception
This method is the one that actually performs the test by processing the elements.

Throws:
java.lang.Exception - An instance of java.lang.Exception can be thrown.

suite

public static junit.framework.Test suite()
Returns an empty suite.

Returns:
Test An empty XMLTestSuite is returned by default.

addProperty

public final void addProperty(java.lang.String name,
                              java.lang.Object obj)
Add each found object into the cache map.

Specified by:
addProperty in interface IXMLTest
Parameters:
name - The name of the found object.
obj - The actual object that was found.

clearProperties

public final void clearProperties()
For each test (method) element, the found objects has to be cleared.

Specified by:
clearProperties in interface IXMLTest

tearDown

public void tearDown()
              throws java.lang.Exception
Default tearDown which does nothing. Override this to tear down the environment for your test.

Throws:
java.lang.Exception - An instance of java.lang.Exception can be thrown
See Also:
TestCase.setUp()

runTest

protected void runTest()
                throws java.lang.Throwable
Executes a test.

Throws:
java.lang.Throwable - exceptions thrown by code.


Licensed under: GNU Lesser General Public License, Ver 2.1, February 1999