UTF-X, Unit Testing Framework - Xslt

utfx.framework
Class XSLTTransformTestCase

java.lang.Object
  extended by junit.framework.Assert
      extended by junit.framework.TestCase
          extended by utfx.framework.UTFXTestCase
              extended by utfx.framework.XSLTTransformTestCase
All Implemented Interfaces:
junit.framework.Test

public class XSLTTransformTestCase
extends UTFXTestCase

JUnit extension for testing XSLT stylesheets.

Copyright © 2004 - University of Southern Queensland.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License v2 as published by the Free Software Foundation.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

$Source: /cvs/utf-x/framework/src/java/utfx/framework/XSLTTransformTestCase.java,v $

Version:
$Revision: 1.7.2.2 $ $Date: 2006/08/08 05:06:21 $ $Name: release_0_0_8_alpha $
Author:
Jacek Radajewski, Oliver Lucido, Sally MacFarlane, Alex Daniel

Field Summary
private  org.w3c.dom.DOMConfiguration domConfig
          DOM Configuration object
private  org.w3c.dom.ls.DOMImplementationLS domImplLS
          DOM Load/Save implementation
private  org.w3c.dom.bootstrap.DOMImplementationRegistry domRegistry
          DOM3 implementation registry
private  org.w3c.dom.ls.LSSerializer domSerializer
          DOM Load/Save serializer
private  java.lang.String expectedDocType
           
private  java.lang.String expectedString
          The expected output
private  java.lang.String failureMessage
          The message to output when the assertion fails
private  org.apache.log4j.Logger log
          LOG4J logging facility
private  MalformedTestException mte
          We need to flag badly formed tests at assambly time and throw an exception at test run time; this is due to JUnit limitation;
private  XSLTTestFileSuite parentSuite
          XSLTTestFileSuite that is the parent of this XSLTTransformTestCase
private  SourceParser sourceBuilder
          source builder used to parse utfx:source fragments
private  java.lang.String sourceString
          The source input
private  java.lang.String templateName
           
private  java.lang.String testName
          The name of this test case
private  javax.xml.transform.Transformer transformer
          XSLT transformer used to transform the source
private  javax.xml.transform.Source transformSource
          transformer.Source
private  boolean useSourceParser
           
private  boolean validateExpected
           
private  boolean validateSource
           
private  javax.xml.xpath.XPath xpath
          XPath
private  javax.xml.xpath.XPathFactory xpf
          XPath factory
 
Constructor Summary
XSLTTransformTestCase(org.w3c.dom.Element elem, XSLTTestFileSuite parentSuite)
          Constructs an XsltTestCase.
 
Method Summary
private  java.lang.String getDocType(java.lang.String rootTagName, java.lang.String publicID, java.lang.String systemID)
          Generate doctype declaration from root element name, public identifier and system identifier.
private  java.lang.String getExpectedDocType(java.lang.String rootTagName)
           
 java.lang.String getFailureMessage()
          Get the failureMessage.
private  java.lang.String getSourceDocType(java.lang.String rootTagName)
           
 boolean isUsingCallTemplate()
          Tests if this is using a named-template transformer.
private  boolean isValid(org.w3c.dom.Element e)
           
private  void processNode(org.w3c.dom.Element testElement)
          Process utfx:test element and create appropriate test components.
 java.lang.String serializeNode(org.w3c.dom.Node node)
          Serialize the given node to a String.
private  void setExpectedString(org.w3c.dom.Element testElement)
           
private  void setTestSourceBuilder(org.w3c.dom.Element testElement)
          Set source builder for this test.
 void setTransformer(javax.xml.transform.Transformer transformer)
          Sets the transformer to be used.
private  void setTransformSource(org.w3c.dom.Element testElement)
          Set transform.Source object.
 void testTransform()
          Transforms the source using the transformer and asserts their equivalence.
 java.lang.String toString()
           
 boolean useSourceParser()
          Get the useSourceParser value.
 boolean validateExpected()
          Get the validateExpected value.
 boolean validateSource()
          Get the validateExpected value.
 
Methods inherited from class utfx.framework.UTFXTestCase
assertEquals, assertEquals, assertEquals, assertEquals, assertEquivXML, assertEquivXML, assertEquivXML, assertEquivXML
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, run, run, runBare, runTest, setName, setUp, tearDown
 
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
 

Field Detail

xpf

private javax.xml.xpath.XPathFactory xpf
XPath factory


xpath

private javax.xml.xpath.XPath xpath
XPath


testName

private java.lang.String testName
The name of this test case


transformer

private javax.xml.transform.Transformer transformer
XSLT transformer used to transform the source


transformSource

private javax.xml.transform.Source transformSource
transformer.Source


sourceString

private java.lang.String sourceString
The source input


expectedString

private java.lang.String expectedString
The expected output


failureMessage

private java.lang.String failureMessage
The message to output when the assertion fails


templateName

private java.lang.String templateName

log

private org.apache.log4j.Logger log
LOG4J logging facility


sourceBuilder

private SourceParser sourceBuilder
source builder used to parse utfx:source fragments


domRegistry

private org.w3c.dom.bootstrap.DOMImplementationRegistry domRegistry
DOM3 implementation registry


domImplLS

private org.w3c.dom.ls.DOMImplementationLS domImplLS
DOM Load/Save implementation


domSerializer

private org.w3c.dom.ls.LSSerializer domSerializer
DOM Load/Save serializer


domConfig

private org.w3c.dom.DOMConfiguration domConfig
DOM Configuration object


validateSource

private boolean validateSource

validateExpected

private boolean validateExpected

useSourceParser

private boolean useSourceParser

expectedDocType

private java.lang.String expectedDocType

mte

private MalformedTestException mte
We need to flag badly formed tests at assambly time and throw an exception at test run time; this is due to JUnit limitation;


parentSuite

private XSLTTestFileSuite parentSuite
XSLTTestFileSuite that is the parent of this XSLTTransformTestCase

Constructor Detail

XSLTTransformTestCase

public XSLTTransformTestCase(org.w3c.dom.Element elem,
                             XSLTTestFileSuite parentSuite)
                      throws java.lang.Exception
Constructs an XsltTestCase.

Parameters:
testName - the name of this test
source - the source input
expected - the expected output
Throws:
java.lang.InstantiationException
java.lang.reflect.InvocationTargetException
java.lang.IllegalAccessException
java.lang.NoSuchMethodException
java.lang.ClassNotFoundException
javax.xml.xpath.XPathExpressionException
MalformedTestException
java.lang.Exception
Method Detail

getFailureMessage

public java.lang.String getFailureMessage()
Get the failureMessage. Method used for testing.

Returns:
failureMessage

useSourceParser

public boolean useSourceParser()
Get the useSourceParser value. Method used for testing.

Returns:
true iff use-source-parser="yes" is set on <utfx:source>

validateExpected

public boolean validateExpected()
Get the validateExpected value. Method used for testing.

Returns:
false if validate="no" has been set on <utfx:expected< and true otherwise. NOTE: validate="yes" is the default.

validateSource

public boolean validateSource()
Get the validateExpected value. Method used for testing.

Returns:
false if validate="no" has been set on <utfx:source< and true otherwise. NOTE: validate="yes" is the default.

processNode

private void processNode(org.w3c.dom.Element testElement)
                  throws java.lang.Exception
Process utfx:test element and create appropriate test components.

Parameters:
testElement - dom.Element representing utfx:test
Throws:
java.lang.ClassNotFoundException
java.lang.NoSuchMethodException
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException
java.lang.InstantiationException
javax.xml.xpath.XPathExpressionException
MalformedTestException
java.lang.Exception

setTestSourceBuilder

private void setTestSourceBuilder(org.w3c.dom.Element testElement)
                           throws java.lang.Exception
Set source builder for this test. If this test does not specify its own source builder then the source builder set by the file test suite will be used.

Parameters:
testElement - this UTF-X test as DOM Element.
Throws:
javax.xml.xpath.XPathExpressionException
java.lang.ClassNotFoundException
java.lang.NoSuchMethodException
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException
java.lang.InstantiationException
java.lang.Exception

serializeNode

public java.lang.String serializeNode(org.w3c.dom.Node node)
                               throws java.lang.Exception
Serialize the given node to a String.

Parameters:
node -
Returns:
Throws:
java.lang.Exception

setTransformSource

private void setTransformSource(org.w3c.dom.Element testElement)
                         throws java.lang.Exception
Set transform.Source object.

Parameters:
testElement - dom.Element representing the UTF-X test.
Throws:
java.lang.Exception

setExpectedString

private void setExpectedString(org.w3c.dom.Element testElement)
                        throws java.lang.Exception
Parameters:
testElement -
Throws:
java.lang.Exception

isValid

private boolean isValid(org.w3c.dom.Element e)
                 throws javax.xml.xpath.XPathExpressionException
Parameters:
e -
Throws:
javax.xml.xpath.XPathExpressionException

isUsingCallTemplate

public boolean isUsingCallTemplate()
Tests if this is using a named-template transformer.


setTransformer

public void setTransformer(javax.xml.transform.Transformer transformer)
Sets the transformer to be used.


testTransform

public void testTransform()
                   throws java.lang.Exception
Transforms the source using the transformer and asserts their equivalence. This is the method that is called by the JUnit framework to run the UTF-X test.

Throws:
java.lang.Exception

getDocType

private java.lang.String getDocType(java.lang.String rootTagName,
                                    java.lang.String publicID,
                                    java.lang.String systemID)
Generate doctype declaration from root element name, public identifier and system identifier.

Parameters:
rootTagName -
publicID -
systemID -
Returns:

getSourceDocType

private java.lang.String getSourceDocType(java.lang.String rootTagName)

getExpectedDocType

private java.lang.String getExpectedDocType(java.lang.String rootTagName)

toString

public java.lang.String toString()
Overrides:
toString in class junit.framework.TestCase

UTF-X, Unit Testing Framework - Xslt