Author: ltheussl Date: Wed Nov 14 05:51:51 2007 New Revision: 594883 URL: http://svn.apache.org/viewvc?rev=594883&view=rev Log: [DOXIA-187] Use AbstractSinkTest in DocBookBookSinkTest
Modified: maven/doxia/doxia/trunk/doxia-book/src/test/java/org/apache/maven/doxia/book/services/renderer/docbook/DocBookBookSinkTest.java Modified: maven/doxia/doxia/trunk/doxia-book/src/test/java/org/apache/maven/doxia/book/services/renderer/docbook/DocBookBookSinkTest.java URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-book/src/test/java/org/apache/maven/doxia/book/services/renderer/docbook/DocBookBookSinkTest.java?rev=594883&r1=594882&r2=594883&view=diff ============================================================================== --- maven/doxia/doxia/trunk/doxia-book/src/test/java/org/apache/maven/doxia/book/services/renderer/docbook/DocBookBookSinkTest.java (original) +++ maven/doxia/doxia/trunk/doxia-book/src/test/java/org/apache/maven/doxia/book/services/renderer/docbook/DocBookBookSinkTest.java Wed Nov 14 05:51:51 2007 @@ -1,41 +1,441 @@ package org.apache.maven.doxia.book.services.renderer.docbook; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.Reader; - -import org.apache.maven.doxia.module.docbook.DocBookParser; -import org.apache.maven.doxia.parser.Parser; -import org.apache.maven.doxia.sink.AbstractSinkTestCase; +import java.io.Writer; + +import org.apache.maven.doxia.sink.AbstractSinkTest; import org.apache.maven.doxia.sink.Sink; /** * Test the book path of the DockBook sink * @author Dave Syer */ -public class DocBookBookSinkTest extends AbstractSinkTestCase +public class DocBookBookSinkTest extends AbstractSinkTest { + /** [EMAIL PROTECTED] */ protected String outputExtension() { return "docbook"; } - protected Parser createParser() + /** [EMAIL PROTECTED] */ + protected Sink createSink( Writer writer ) + { + return new DocBookBookSink( writer ); + } + + // + // DocBookBookSink specific + // + + /** + * Checks that the sequence <code>[bookTitle(), text( title ), bookTitle_()]</code>, + * invoked on the current sink, produces the same result as + * [EMAIL PROTECTED] #getBookTitleBlock getBookTitleBlock}( title ). + * NewLines are ignored. + */ + public void testBookTitle() + { + DocBookBookSink sink = (DocBookBookSink) getSink(); + + String title = "Grodek"; + sink.bookTitle(); + sink.text( title ); + sink.bookTitle_(); + sink.flush(); + + String actual = noNewLine( getSinkContent() ); + String expected = noNewLine( getBookTitleBlock( title ) ); + + assertEquals( "Wrong book title!", expected, actual ); + } + + /** + * Checks that the sequence <code>[bookAuthor(), text( author ), bookAuthor_()] + * </code>, invoked on the current sink, produces the same result as + * [EMAIL PROTECTED] #getBookAuthorBlock getBookAuthorBlock}( author ). + * NewLines are ignored. + */ + public void testBookAuthor() + { + DocBookBookSink sink = (DocBookBookSink) getSink(); + + String author = "Georg Trakl"; + sink.bookAuthor(); + sink.text( author ); + sink.bookAuthor_(); + sink.flush(); + + String actual = noNewLine( getSinkContent() ); + String expected = noNewLine( getBookAuthorBlock( author ) ); + + assertEquals( "Wrong book author!", expected, actual ); + } + + /** + * Checks that the sequence <code>[bookDate(), text( date ), bookDate_()]</code>, + * invoked on the current sink, produces the same result as + * [EMAIL PROTECTED] #getBookDateBlock getBookDateBlock}( date ). NewLines are ignored. + */ + public void testBookDate() + { + DocBookBookSink sink = (DocBookBookSink) getSink(); + + String date = "1914"; + sink.bookDate(); + sink.text( date ); + sink.bookDate_(); + sink.flush(); + + String actual = noNewLine( getSinkContent() ); + String expected = noNewLine( getBookDateBlock( date ) ); + + assertEquals( "Wrong book date!", expected, actual ); + } + + /** + * Checks that the sequence <code>[bookHead(), bookHead_()]</code>, + * invoked on the current sink, produces the same result as + * [EMAIL PROTECTED] #getBookHeadBlock getBookHeadBlock()}. NewLines are ignored. + */ + public void testBookHead() + { + DocBookBookSink sink = (DocBookBookSink) getSink(); + + //sink.bookHead(); + sink.bookHead_(); + sink.flush(); + + String actual = noNewLine( getSinkContent() ); + String expected = noNewLine( getBookHeadBlock() ); + + assertEquals( "Wrong book head!", expected, actual ); + } + + /** + * Checks that the sequence <code>[book(), book_()]</code>, + * invoked on the current sink, produces the same result as + * [EMAIL PROTECTED] #getBookBlock getBookBlock()}. NewLines are ignored. + */ + public void testBook() + { + DocBookBookSink sink = (DocBookBookSink) getSink(); + + sink.book(); + sink.book_(); + sink.flush(); + + String actual = noNewLine( getSinkContent() ); + String expected = noNewLine( getBookBlock() ); + + assertEquals( "Wrong book body!", expected, actual ); + } + + /** + * Checks that the sequence <code>[chapterTitle(), text( title ), + * chapterTitle_()]</code>, invoked on the current sink, produces + * the same result as + * [EMAIL PROTECTED] #getChapterTitleBlock getChapterTitleBlock}( title ). + * NewLines are ignored. + */ + public void testChapterTitle() + { + DocBookBookSink sink = (DocBookBookSink) getSink(); + + String title = "Title"; + sink.chapterTitle(); + sink.text( title ); + sink.chapterTitle_(); + sink.flush(); + + String actual = noNewLine( getSinkContent() ); + String expected = noNewLine( getChapterTitleBlock( title ) ); + + assertEquals( "Wrong chapterTitle!", expected, actual ); + } + + /** + * Checks that the sequence <code>[chapter(), chapter_()]</code>, + * invoked on the current sink, produces the same result as + * [EMAIL PROTECTED] #getChapterBlock getChapterBlock}(). + * NewLines are ignored. + */ + public void testChapter() { - return new DocBookParser(); + DocBookBookSink sink = (DocBookBookSink) getSink(); + + sink.chapter(); + sink.chapter_(); + sink.flush(); + + String actual = noNewLine( getSinkContent() ); + String expected = noNewLine( getChapterBlock() ); + + assertEquals( "Wrong chapter block!", expected, actual ); } - protected Sink createSink() throws Exception + /** + * Returns a title block generated by this sink. + * @param title The title to use. + * @return The result of invoking a title block on the current sink. + * @see #testBookTitle() + */ + protected String getBookTitleBlock( String title ) { - return new DocBookBookSink( getTestWriter() ); + return "<bookinfo><title>" + title + "</title>"; } - protected Reader getTestReader() throws Exception + /** + * Returns an author block generated by this sink. + * @param author The author to use. + * @return The result of invoking an author block on the current sink. + * @see #testBookAuthor() + */ + protected String getBookAuthorBlock( String author ) { - InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream( "book-1.xml" ); + return "<bookinfo><corpauthor>" + author + "</corpauthor>"; + } - InputStreamReader reader = new InputStreamReader( is ); + /** + * Returns a date block generated by this sink. + * @param date The date to use. + * @return The result of invoking a date block on the current sink. + * @see #testBookDate() + */ + protected String getBookDateBlock( String date ) + { + return "<bookinfo><date>" + date + "</date>"; + } + + /** + * Returns a head block generated by this sink. + * @return The result of invoking a head block on the current sink. + * @see #testBookHead() + */ + protected String getBookHeadBlock() + { + return ""; + } + + /** + * Returns a body block generated by this sink. + * @return The result of invoking a body block on the current sink. + * @see #testBook() + */ + protected String getBookBlock() + { + return "<?xml version=\"1.0\" ?><!DOCTYPE book PUBLIC \"" + DocBookBookSink.DEFAULT_XML_PUBLIC_ID + + "\"\"" + DocBookBookSink.DEFAULT_XML_SYSTEM_ID + "\"><book></book>"; + } + + /** + * Returns a SectionTitle block generated by this sink. + * @param title The title to use. + * @return The result of invoking a SectionTitle block on the current sink. + * @see #testChapterTitle() + */ + protected String getChapterTitleBlock( String title ) + { + return "<title>" + title + "</title>"; + } + + /** + * Returns a Section1 block generated by this sink. + * @param title The title to use. + * @return The result of invoking a Section1 block on the current sink. + * @see #testChapter() + */ + protected String getChapterBlock() + { + return "<chapter></chapter>"; + } + + + // + // from DocBookSink + // + + + /** [EMAIL PROTECTED] */ + protected String getTitleBlock( String title ) + { + return ""; + } + + /** [EMAIL PROTECTED] */ + protected String getAuthorBlock( String author ) + { + return ""; + } + + /** [EMAIL PROTECTED] */ + protected String getDateBlock( String date ) + { + return "<date>" + date + "</date>"; + } + + /** [EMAIL PROTECTED] */ + protected String getHeadBlock() + { + return ""; + } - return reader; + /** [EMAIL PROTECTED] */ + protected String getBodyBlock() + { + return ""; + } + + /** [EMAIL PROTECTED] */ + protected String getSectionTitleBlock( String title ) + { + return "<title>" + title + "</title>"; + } + + /** [EMAIL PROTECTED] */ + protected String getSection1Block( String title ) + { + return "<section><title>" + title + "</title></section>"; + } + + /** [EMAIL PROTECTED] */ + protected String getSection2Block( String title ) + { + return "<section><title>" + title + "</title></section>"; + } + + /** [EMAIL PROTECTED] */ + protected String getSection3Block( String title ) + { + return "<section><title>" + title + "</title></section>"; + } + + /** [EMAIL PROTECTED] */ + protected String getSection4Block( String title ) + { + return "<section><title>" + title + "</title></section>"; + } + + /** [EMAIL PROTECTED] */ + protected String getSection5Block( String title ) + { + return "<section><title>" + title + "</title></section>"; + } + + /** [EMAIL PROTECTED] */ + protected String getListBlock( String item ) + { + return "<itemizedlist><listitem>" + item + "</listitem></itemizedlist>"; + } + + /** [EMAIL PROTECTED] */ + protected String getNumberedListBlock( String item ) + { + return "<orderedlist numeration=\"lowerroman\"><listitem>" + + item + "</listitem></orderedlist>"; + } + + /** [EMAIL PROTECTED] */ + protected String getDefinitionListBlock( String definum, String definition ) + { + return "<variablelist><varlistentry><term>" + definum + + "</term><listitem>" + definition + + "</listitem></varlistentry></variablelist>"; + } + + /** [EMAIL PROTECTED] */ + protected String getFigureBlock( String source, String caption ) + { + // TODO: fix source + return "<figure><title>" + caption + "</title><mediaobject><imageobject><imagedata fileref=\"figure.jpeg\" format=\"JPEG\" /></imageobject></mediaobject></figure>"; + } + + /** [EMAIL PROTECTED] */ + protected String getTableBlock( String cell, String caption ) + { + return "<table frame=\"none\" rowsep=\"0\" colsep=\"0\"><title>" + caption + + "</title><tgroup cols=\"1\"><colspec align=\"center\" /><tbody><row><entry>" + + cell + "</entry></row></tbody></tgroup></table>"; + } + + /** [EMAIL PROTECTED] */ + protected String getParagraphBlock( String text ) + { + return "<para>" + text + "</para>"; + } + + /** [EMAIL PROTECTED] */ + protected String getVerbatimBlock( String text ) + { + return "<programlisting>" + text + "</programlisting>"; + } + + /** [EMAIL PROTECTED] */ + protected String getHorizontalRuleBlock() + { + return "<!-- HR -->"; + } + + /** [EMAIL PROTECTED] */ + protected String getPageBreakBlock() + { + return "<!-- PB -->"; + } + + /** [EMAIL PROTECTED] */ + protected String getAnchorBlock( String anchor ) + { + // TODO: fix id + return "<anchor id=\"a.anchor\" />" + anchor; + } + + /** [EMAIL PROTECTED] */ + protected String getLinkBlock( String link, String text ) + { + // TODO: fix link + return "<link linkend=\"a.link\">" + text + "</link>"; + } + + /** [EMAIL PROTECTED] */ + protected String getItalicBlock( String text ) + { + return "<emphasis>" + text + "</emphasis>"; + } + + /** [EMAIL PROTECTED] */ + protected String getBoldBlock( String text ) + { + return "<emphasis role=\"bold\">" + text + "</emphasis>"; + } + + /** [EMAIL PROTECTED] */ + protected String getMonospacedBlock( String text ) + { + return "<literal>" + text + "</literal>"; + } + + /** [EMAIL PROTECTED] */ + protected String getLineBreakBlock() + { + return "<!-- LB -->"; + } + + /** [EMAIL PROTECTED] */ + protected String getNonBreakingSpaceBlock() + { + return " "; + } + + /** [EMAIL PROTECTED] */ + protected String getTextBlock( String text ) + { + // TODO: retreive those from the sink + return "~, =, -, +, *, [, ], <, >, {, }, \\"; + } + + /** [EMAIL PROTECTED] */ + protected String getRawTextBlock( String text ) + { + // TODO + return ""; } }