org.apache.maven.doxia.module
Class AbstractIdentityTest

java.lang.Object
  extended by junit.framework.Assert
      extended by junit.framework.TestCase
          extended by org.codehaus.plexus.PlexusTestCase
              extended by org.apache.maven.doxia.AbstractModuleTest
                  extended by org.apache.maven.doxia.module.AbstractIdentityTest
All Implemented Interfaces:
junit.framework.Test, Markup

public abstract class AbstractIdentityTest
extends AbstractModuleTest

If a module provides both Parser and Sink, this class can be used to check that chaining them together results in the identity transformation, ie the model is still the same after being piped through a Parser and the corresponding Sink.

Version:
$Id: AbstractIdentityTest.java 1410919 2012-11-18 16:34:59Z hboutemy $

Field Summary
 
Fields inherited from class org.codehaus.plexus.PlexusTestCase
container, context
 
Fields inherited from interface org.apache.maven.doxia.markup.Markup
COLON, EOL, EQUAL, GREATER_THAN, LEFT_CURLY_BRACKET, LEFT_SQUARE_BRACKET, LESS_THAN, MINUS, PLUS, QUOTE, RIGHT_CURLY_BRACKET, RIGHT_SQUARE_BRACKET, SEMICOLON, SLASH, SPACE, STAR
 
Constructor Summary
AbstractIdentityTest()
           
 
Method Summary
protected  void assertIdentity(boolean doAssert)
          Set to true if the identity transformation should actually be asserted, by default only the expected and actual results are written to a file, but not compared.
protected abstract  Parser createParser()
          Create a new instance of the parser to test.
protected abstract  Sink createSink(Writer writer)
          Return a new instance of the sink that is being tested.
protected  String getExpected()
           
protected  String getOutputDir()
          Returns the directory where test output will go.
protected  String outputExtension()
          The output files generated by this class are text files, independent of the kind of module being tested.
 void testIdentity()
          Pipes a full model generated by SinkTestDocument through a Sink (generated by createSink(Writer)) and a Parser (generated by createParser()) and checks if the result is the same as the original model.
 
Methods inherited from class org.apache.maven.doxia.AbstractModuleTest
getBasedirFile, getTestReader, getTestReader, getTestWriter, getTestWriter, getTestWriterFile, getTestWriterFile, getXmlTestWriter, getXmlTestWriter, outputBaseDir
 
Methods inherited from class org.codehaus.plexus.PlexusTestCase
customizeContext, getBasedir, getClassLoader, getConfiguration, getConfiguration, getConfigurationName, getContainer, getCustomConfigurationName, getResourceAsStream, getTestConfiguration, getTestConfiguration, getTestFile, getTestFile, getTestPath, getTestPath, lookup, lookup, lookup, lookup, release, setUp, tearDown
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, run, run, runBare, runTest, 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, failNotEquals, failNotSame, failSame, format
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AbstractIdentityTest

public AbstractIdentityTest()
Method Detail

createParser

protected abstract Parser createParser()
Create a new instance of the parser to test.

Returns:
the parser to test.

createSink

protected abstract Sink createSink(Writer writer)
Return a new instance of the sink that is being tested.

Parameters:
writer - The writer for the sink.
Returns:
A new sink.

testIdentity

public void testIdentity()
                  throws IOException,
                         ParseException
Pipes a full model generated by SinkTestDocument through a Sink (generated by createSink(Writer)) and a Parser (generated by createParser()) and checks if the result is the same as the original model. By default, this doesn't actually assert anything (use assertIdentity(boolean) in the setUp() of an implementation to switch on the test), but the two generated output files, expected.txt and actual.txt, can be compared for differences.

Throws:
IOException - if there's a problem reading/writing a test file.
ParseException - if a model cannot be parsed.

getOutputDir

protected String getOutputDir()
Returns the directory where test output will go. Should be relative to outputBaseDir().

Specified by:
getOutputDir in class AbstractModuleTest
Returns:
The test output directory, relative to outputBaseDir().

outputExtension

protected String outputExtension()
The output files generated by this class are text files, independent of the kind of module being tested.

Specified by:
outputExtension in class AbstractModuleTest
Returns:
The String "txt".

assertIdentity

protected void assertIdentity(boolean doAssert)
Set to true if the identity transformation should actually be asserted, by default only the expected and actual results are written to a file, but not compared. This should be called during setUp().

Parameters:
doAssert - True to actually execute the test.

getExpected

protected String getExpected()
Returns:
the expected identity string


Copyright © 2005-2013 The Apache Software Foundation. All Rights Reserved.