Update of /cvsroot/xdoclet/generama/src/main/java/org/generama/tests In directory sc8-pr-cvs1:/tmp/cvs-serv12006/main/java/org/generama/tests
Added Files: AbstractJavaGeneratingPluginTestCase.java AbstractPluginTestCase.java AbstractTextGeneratingPluginTestCase.java AbstractXMLGeneratingPluginTestCase.java package.html Log Message: More refactorings. Generama is nearly completely refactored and completed. All TDD. --- NEW FILE: AbstractJavaGeneratingPluginTestCase.java --- package org.generama.tests; import java.io.Reader; import xjavadoc.codeunit.CodeTestCase; /** * Baseclass for testing generation of Java sources. Uses XJavaDoc's * CodeTestCase internally to compare equality of Java Sources. * * @author Aslak Hellesøy * @version $Revision: 1.1 $ */ public abstract class AbstractJavaGeneratingPluginTestCase extends AbstractPluginTestCase { protected final void compare(Reader expected, Reader actual) { CodeTestCase.assertApiEquals(expected, actual); CodeTestCase.assertAstEquals(expected, actual); } } --- NEW FILE: AbstractPluginTestCase.java --- package org.generama.tests; import junit.framework.TestCase; import java.io.StringWriter; import java.io.Reader; import java.io.StringReader; import java.io.InputStream; import java.io.InputStreamReader; import org.generama.Plugin; /** * Abstract test case for a plugin. A subclass should be made for each plugin. * * @author Aslak Hellesøy * @version $Revision: 1.1 $ */ public abstract class AbstractPluginTestCase extends TestCase { public void testGenerateContent() throws Throwable { Plugin plugin = createPlugin(); StringWriter sink = new StringWriter(); Object metadata = createMetadata(); plugin.generate(sink, metadata); Reader expected = getExpected(); String actualString = sink.getBuffer().toString(); StringReader actual = new StringReader(actualString); try { compare(expected, actual); } catch (Throwable e) { // print out all of it System.out.println("**** START GENERATED CONTENT ****"); System.out.println(actualString); System.out.println("**** END GENERATED CONTENT ****"); throw e; } } protected abstract Plugin createPlugin() throws Exception; protected abstract Object createMetadata(); protected abstract Reader getExpected(); protected abstract void compare(Reader expected, Reader actual) throws Exception; /** * Helper method for subclasses that wish to retrieve a test resource without * typing the full path. Handy for accessing e.g. java sources for XDoclet tests. * * @param resourceName * @return */ protected Reader getResourceRelativeToThisPackage(String resourceName) { String className = getClass().getName(); String packageName = className.substring(0, className.lastIndexOf('.')); String resourcePath = "/" + packageName.replace('.', '/' ) + "/" + resourceName; InputStream resource = getClass().getResourceAsStream(resourcePath); assertNotNull("Resource not found at path: " + resourcePath, resource); return new InputStreamReader( resource ); } } --- NEW FILE: AbstractTextGeneratingPluginTestCase.java --- package org.generama.tests; import org.generama.tests.AbstractPluginTestCase; import java.io.Reader; import java.io.IOException; import java.io.BufferedReader; import java.io.StringWriter; import java.io.PrintWriter; /** * Baseclass for testing generation of Java sources. * Compares content by comparing the Strings (and is therefore * sensitive to whitespaces too. * * @author Aslak Hellesøy * @version $Revision: 1.1 $ */ public abstract class AbstractTextGeneratingPluginTestCase extends AbstractPluginTestCase { protected final void compare(Reader expected, Reader actual) throws IOException { String ex = read(expected); String ac = read(actual); assertEquals("Text should be equal", ex, ac); } private String read(Reader reader) throws IOException { BufferedReader br = new BufferedReader(reader); StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); String line; while((line = br.readLine()) != null) { pw.println(line); } pw.flush(); return sw.getBuffer().toString(); } } --- NEW FILE: AbstractXMLGeneratingPluginTestCase.java --- package org.generama.tests; import org.generama.tests.AbstractPluginTestCase; import org.custommonkey.xmlunit.XMLTestCase; import org.custommonkey.xmlunit.XMLUnit; import org.xml.sax.SAXException; import javax.xml.parsers.ParserConfigurationException; import java.io.Reader; import java.io.IOException; /** * Baseclass for testing generation of XML content. Ignores * whitespace (but TODO not yet comments). * Uses XMLUnit internally to compare equality of XML documents. * * @author Aslak Hellesøy * @version $Revision: 1.1 $ */ public abstract class AbstractXMLGeneratingPluginTestCase extends AbstractPluginTestCase { protected final void compare(Reader expected, Reader actual) throws ParserConfigurationException, IOException, SAXException { XMLUnit.setIgnoreWhitespace(true); XMLTestCase xmlunit = new XMLTestCase(this.getName()); xmlunit.assertXMLEqual(expected,actual); } } --- NEW FILE: package.html --- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> </head> <body> <p> This package contains abstract JUnit TesCase classes that should be used to Test Driven Develop (TDD) new plugins. </p> <p> Depending on what kind of output is generated, the following test cases should be extended: </p> <table BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0"> <tr BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"> <th><FONT SIZE="+2"><B>Type of generated output</B></FONT></th> <th><FONT SIZE="+2"><B>TestCase to extend</B></FONT></th> <th><FONT SIZE="+2"><B>Plugin to extend</B></FONT></th> </tr> <tr BGCOLOR="white" CLASS="TableRowColor"> <td>Java sources</td> <td><B><a href="AbstractJavaGeneratingPluginTestCase.html">AbstractJavaGeneratingPluginTestCase</a></B></td> <td><B><a href="../VelocityPlugin.html">VelocityPlugin</a></B></td> </tr> <tr BGCOLOR="white" CLASS="TableRowColor"> <td>XML files</td> <td><B><a href="AbstractXMLGeneratingPluginTestCase.html">AbstractXMLGeneratingPluginTestCase</a></B></td> <td><B><a href="../JellyPlugin.html">JellyPlugin</a></B></td> </tr> <tr BGCOLOR="white" CLASS="TableRowColor"> <td>Text files</td> <td><B><a href="AbstractTextGeneratingPluginTestCase.html">AbstractTextGeneratingPluginTestCase</a></B></td> <td><B><a href="../VelocityPlugin.html">VelocityPlugin</a></B></td> </tr> </table> <p> (Although we recommend JellyPlugin for generation of XML, it is possible to generate XML with VelocityPlugin subclasses. In that case, you should use <a href="AbstractXMLGeneratingPluginTestCase.html">AbstractXMLGeneratingPluginTestCase</a> to test the output.) </p> </body> </html> ------------------------------------------------------- This SF.net email is sponsored by Dice.com. Did you know that Dice has over 25,000 tech jobs available today? From careers in IT to Engineering to Tech Sales, Dice has tech jobs from the best hiring companies. http://www.dice.com/index.epl?rel_code=104 _______________________________________________ xdoclet-devel mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/xdoclet-devel