org.woopi.ant.taskdefs.junit
Class JunitVelocityReportTask

java.lang.Object
  extended by org.apache.tools.ant.ProjectComponent
      extended by org.apache.tools.ant.Task
          extended by org.woopi.ant.taskdefs.junit.JunitVelocityReportTask
All Implemented Interfaces:
XMLConstants

public class JunitVelocityReportTask
extends org.apache.tools.ant.Task
implements XMLConstants

Aggregates all <junit> XML formatter testsuite data under a specific directory and transforms the results via XSLT. It is not particulary clean but should be helpful while I am thinking about another technique.

The main problem is due to the fact that a JVM can be forked for a testcase thus making it impossible to aggregate all testcases since the listener is (obviously) in the forked JVM. A solution could be to write a TestListener that will receive events from the TestRunner via sockets. This is IMHO the simplest way to do it to avoid this file hacking thing.


Field Summary
static java.lang.String DEFAULT_DIR
          The default directory: ..
static java.lang.String DEFAULT_FILENAME
          the default file name: TESTS-TestSuites.xml
 java.text.DecimalFormat dnf
           
protected  java.util.Vector filesets
          the list of all filesets, that should contains the xml to aggregate
protected  java.io.File toDir
          the directory to write the file to
protected  java.lang.String toFile
          the name of the result file
protected  java.util.Vector transformers
           
 
Fields inherited from class org.apache.tools.ant.Task
description, location, target, taskName, taskType, wrapper
 
Fields inherited from class org.apache.tools.ant.ProjectComponent
project
 
Fields inherited from interface org.woopi.ant.taskdefs.junit.XMLConstants
ATTR_CLASSNAME, ATTR_ERRORS, ATTR_FAILURES, ATTR_MESSAGE, ATTR_NAME, ATTR_PACKAGE, ATTR_TESTS, ATTR_TIME, ATTR_TYPE, ATTR_VALUE, ERROR, FAILURE, JAVADOC, PROPERTIES, PROPERTY, SYSTEM_ERR, SYSTEM_OUT, TESTCASE, TESTSUITE, TESTSUITES
 
Constructor Summary
JunitVelocityReportTask()
           
 
Method Summary
 void addFileSet(org.apache.tools.ant.types.FileSet fs)
          Add a new fileset containing the XML results to aggregate
protected  void addTestSuite(org.w3c.dom.Element root, org.w3c.dom.Element testsuite)
           Add a new testsuite node to the document.
protected  org.w3c.dom.Element createDocument()
           Create a DOM tree.
 AggregateTransformer createReport()
          Generate a report based on the document created by the merge.
 void execute()
          Aggregate all testsuites into a single document and write it to the specified directory and file.
 void generateAllClassesFrame(org.w3c.dom.Element rootElement)
           
 void generateIndex(org.w3c.dom.Element rootElement)
           
 void generateOverviewFrame(org.w3c.dom.Element rootElement)
           
 void generateOverviewSummary(org.w3c.dom.Element rootElement)
           
 void generatePackageFrames(org.w3c.dom.Element rootElement)
           
 void generatePackageSummaryFiles(org.w3c.dom.Element rootElement)
           
 void generateStylesheet(org.w3c.dom.Element rootElement)
           
 void generateTestClassInfo(org.w3c.dom.Element testCaseElement)
           
 void generateTestClassInfos(org.w3c.dom.Element rootElement)
           
 void generateTestClassSystemErr(org.w3c.dom.Element testCaseElement)
           
 void generateTestClassSystemOut(org.w3c.dom.Element testCaseElement)
           
 void generateVelocityReport(org.w3c.dom.Element rootElement)
          the rootElement should contain the node testsuits
 java.util.Map[] getClassesMap(org.w3c.dom.Element rootElement)
          just applicable to testsuites Node
 java.util.Map[] getClassesMap(org.w3c.dom.Element rootElement, java.lang.String packageNameP)
          just applicable to testsuites Node
protected  java.io.File getDestinationFile()
          Get the full destination file where to write the result.
 double getDoubleSumCount(org.w3c.dom.Element rootElement, java.lang.String attributeName)
          just applicable to testsuites Node
protected  java.io.File[] getFiles()
          Get all .xml files in the fileset.
 int getIntegerSumCount(org.w3c.dom.Element rootElement, java.lang.String attributeName)
          just applicable to testsuites Node
 java.util.Map[] getPackagesMap(org.w3c.dom.Element rootElement)
          just applicable to testsuites Node
 java.util.Map[] getPackageStatisticsMap(org.w3c.dom.Element rootElement)
          just applicable to testsuites Node
 java.util.Map[] getSpecialPackageStatisticsMap(org.w3c.dom.Element rootElement, java.lang.String packageNameP)
          just applicable to testsuites Node
 java.lang.String getSummaryStylesheetClass(int errorCount, int failureCount)
           
 java.util.Map[] getTestCaseInfos(org.w3c.dom.Element testSuiteElement)
           
 java.util.Map[] getTestClassProperties(org.w3c.dom.Element testSuiteElement)
           
 java.lang.String getTimeFormat(double time)
           
 java.lang.String jsEscape(java.lang.String inString)
           
 void setTodir(java.io.File value)
          Set the destination directory where the results should be written.
 void setTofile(java.lang.String value)
          Set the name of the aggregegated results file.
protected  void writeDOMTree(org.w3c.dom.Document doc, java.io.File file)
          Write the DOM tree to a file.
 
Methods inherited from class org.apache.tools.ant.Task
getDescription, getLocation, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, getTaskType, getWrapper, handleErrorFlush, handleErrorOutput, handleFlush, handleInput, handleOutput, init, isInvalid, log, log, maybeConfigure, perform, reconfigure, setDescription, setLocation, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName, setTaskType
 
Methods inherited from class org.apache.tools.ant.ProjectComponent
getProject, setProject
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

filesets

protected java.util.Vector filesets
the list of all filesets, that should contains the xml to aggregate


toFile

protected java.lang.String toFile
the name of the result file


toDir

protected java.io.File toDir
the directory to write the file to


transformers

protected java.util.Vector transformers

DEFAULT_DIR

public static final java.lang.String DEFAULT_DIR
The default directory: .. It is resolved from the project directory

See Also:
Constant Field Values

DEFAULT_FILENAME

public static final java.lang.String DEFAULT_FILENAME
the default file name: TESTS-TestSuites.xml

See Also:
Constant Field Values

dnf

public java.text.DecimalFormat dnf
Constructor Detail

JunitVelocityReportTask

public JunitVelocityReportTask()
Method Detail

createReport

public AggregateTransformer createReport()
Generate a report based on the document created by the merge.


setTofile

public void setTofile(java.lang.String value)
Set the name of the aggregegated results file. It must be relative from the todir attribute. If not set it will use DEFAULT_FILENAME

Parameters:
value - the name of the file.
See Also:
setTodir(File)

setTodir

public void setTodir(java.io.File value)
Set the destination directory where the results should be written. If not set if will use DEFAULT_DIR. When given a relative directory it will resolve it from the project directory.

Parameters:
value - the directory where to write the results, absolute or relative.

addFileSet

public void addFileSet(org.apache.tools.ant.types.FileSet fs)
Add a new fileset containing the XML results to aggregate

Parameters:
fs - the new fileset of xml results.

execute

public void execute()
             throws org.apache.tools.ant.BuildException
Aggregate all testsuites into a single document and write it to the specified directory and file.

Overrides:
execute in class org.apache.tools.ant.Task
Throws:
org.apache.tools.ant.BuildException - thrown if there is a serious error while writing the document.

generateVelocityReport

public void generateVelocityReport(org.w3c.dom.Element rootElement)
the rootElement should contain the node testsuits


getIntegerSumCount

public int getIntegerSumCount(org.w3c.dom.Element rootElement,
                              java.lang.String attributeName)
just applicable to testsuites Node


getDoubleSumCount

public double getDoubleSumCount(org.w3c.dom.Element rootElement,
                                java.lang.String attributeName)
just applicable to testsuites Node


getSummaryStylesheetClass

public java.lang.String getSummaryStylesheetClass(int errorCount,
                                                  int failureCount)

getPackagesMap

public java.util.Map[] getPackagesMap(org.w3c.dom.Element rootElement)
just applicable to testsuites Node


getClassesMap

public java.util.Map[] getClassesMap(org.w3c.dom.Element rootElement)
just applicable to testsuites Node


getClassesMap

public java.util.Map[] getClassesMap(org.w3c.dom.Element rootElement,
                                     java.lang.String packageNameP)
just applicable to testsuites Node


getPackageStatisticsMap

public java.util.Map[] getPackageStatisticsMap(org.w3c.dom.Element rootElement)
just applicable to testsuites Node


getSpecialPackageStatisticsMap

public java.util.Map[] getSpecialPackageStatisticsMap(org.w3c.dom.Element rootElement,
                                                      java.lang.String packageNameP)
just applicable to testsuites Node


generateOverviewSummary

public void generateOverviewSummary(org.w3c.dom.Element rootElement)

generateStylesheet

public void generateStylesheet(org.w3c.dom.Element rootElement)

generateIndex

public void generateIndex(org.w3c.dom.Element rootElement)

generateOverviewFrame

public void generateOverviewFrame(org.w3c.dom.Element rootElement)

generateAllClassesFrame

public void generateAllClassesFrame(org.w3c.dom.Element rootElement)

generatePackageFrames

public void generatePackageFrames(org.w3c.dom.Element rootElement)

getTestClassProperties

public java.util.Map[] getTestClassProperties(org.w3c.dom.Element testSuiteElement)

jsEscape

public java.lang.String jsEscape(java.lang.String inString)

getTestCaseInfos

public java.util.Map[] getTestCaseInfos(org.w3c.dom.Element testSuiteElement)

getTimeFormat

public java.lang.String getTimeFormat(double time)

generateTestClassInfo

public void generateTestClassInfo(org.w3c.dom.Element testCaseElement)

generateTestClassSystemOut

public void generateTestClassSystemOut(org.w3c.dom.Element testCaseElement)

generateTestClassSystemErr

public void generateTestClassSystemErr(org.w3c.dom.Element testCaseElement)

generateTestClassInfos

public void generateTestClassInfos(org.w3c.dom.Element rootElement)

generatePackageSummaryFiles

public void generatePackageSummaryFiles(org.w3c.dom.Element rootElement)

getDestinationFile

protected java.io.File getDestinationFile()
Get the full destination file where to write the result. It is made of the todir and tofile attributes.

Returns:
the destination file where should be written the result file.

getFiles

protected java.io.File[] getFiles()
Get all .xml files in the fileset.

Returns:
all files in the fileset that end with a '.xml'.

writeDOMTree

protected void writeDOMTree(org.w3c.dom.Document doc,
                            java.io.File file)
                     throws java.io.IOException
Write the DOM tree to a file.

Parameters:
doc - the XML document to dump to disk.
file - the filename to write the document to. Should obviouslly be a .xml file.
Throws:
java.io.IOException - thrown if there is an error while writing the content.

createDocument

protected org.w3c.dom.Element createDocument()

Create a DOM tree. Has 'testsuites' as firstchild and aggregates all testsuite results that exists in the base directory.

Returns:
the root element of DOM tree that aggregates all testsuites.

addTestSuite

protected void addTestSuite(org.w3c.dom.Element root,
                            org.w3c.dom.Element testsuite)

Add a new testsuite node to the document. The main difference is that it split the previous fully qualified name into a package and a name.

For example: org.apache.Whatever will be split into org.apache and Whatever.

Parameters:
root - the root element to which the testsuite node should be appended.
testsuite - the element to append to the given root. It will slightly modify the original node to change the name attribute and add a package one.


Copyright 2000-${year} Apache Software Foundation. All Rights Reserved.