Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.tools.ant.taskdefs.optional.junit
Class XMLResultAggregator

    java.lang.Object
      |
      +--org.apache.tools.ant.Task
            |
            +--org.apache.tools.ant.taskdefs.optional.junit.XMLResultAggregator

All Implemented Interfaces:
  XMLConstants

public class XMLResultAggregator
extends Task
implements XMLConstants

This is an helper class that will aggregate all testsuites under a specific directory and create a new single document. 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.

Author:
  Stephane Bailliez

Field Summary
`static java.lang.String` | `DEFAULT_DIR` the default directory: `.`.
`static java.lang.String` | `DEFAULT_FILENAME` the default file name: `TESTS-TestSuites.xml`
`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, project, target, taskName, taskType, wrapper`

Fields inherited from interface org.apache.tools.ant.taskdefs.optional.junit.XMLConstants
`ATTR_ERRORS, ATTR_FAILURES, ATTR_MESSAGE, ATTR_NAME, ATTR_PACKAGE, ATTR_TESTS, ATTR_TIME, ATTR_TYPE, ERROR, FAILURE, TESTCASE, TESTSUITE, TESTSUITES`

Constructor Summary
`XMLResultAggregator()`

Method Summary
`void` | `addFileSet(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, the main difference is that it split the previous fully qualified name into a package and a name.
`protected org.w3c.dom.Element` | `createDocument()` Create a DOM tree with firstchild as 'testsuites' and aggregates all testsuite results that exists in the base directory.
`AggregateTransformer` | `createReport()`
`void` | `execute()` Aggregate all testsuites into a single document and write it to the specified directory and file.
`protected java.io.File` | `getDestinationFile()` get the full destination file where to write the result.
`protected java.io.File[]` | `getFiles()`
`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 file aggregating the results.
`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, getProject, getRuntimeConfigurableWrapper, getTaskName, init, log, log, maybeConfigure, setDescription, setLocation, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName`

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

### DEFAULT_FILENAME

    public static final java.lang.String DEFAULT_FILENAME

  the default file name: `TESTS-TestSuites.xml`

Constructor Detail

### XMLResultAggregator

    public XMLResultAggregator()

Method Detail

### createReport

    public AggregateTransformer createReport()

### setTofile

    public void setTofile(java.lang.String value)

  Set the name of the file aggregating the results. 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(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 BuildException

  Aggregate all testsuites into a single document and write it to the specified directory and file.
  Overrides:
    `execute` in class `Task`
  Throws:
    `BuildException` - thrown if there is a serious error while writing the document.

### 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()

  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 with firstchild as 'testsuites' 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 splitted in `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.

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2000 Apache Software Foundation. All Rights Reserved.