001package org.apache.maven.doxia.module.twiki;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 *
012 *   http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import java.io.Writer;
023
024import org.apache.maven.doxia.sink.Sink;
025import org.apache.maven.doxia.sink.impl.AbstractSinkTest;
026import org.apache.maven.doxia.util.HtmlTools;
027import org.codehaus.plexus.util.StringUtils;
028
029/**
030 * Test the TWiki Sink
031 *
032 * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
033 * @version $Id$
034 * @see TWikiSink
035 */
036public class TWikiSinkTest
037    extends AbstractSinkTest
038{
039    /** {@inheritDoc} */
040    protected Sink createSink( Writer writer )
041    {
042        return new TWikiSink( writer );
043    }
044
045    /** {@inheritDoc} */
046    protected boolean isXmlSink()
047    {
048        return false;
049    }
050
051    /** {@inheritDoc} */
052    protected String getAnchorBlock( String anchor )
053    {
054        return EOL + "#" + anchor + anchor;
055    }
056
057    /** Not used.
058     * {@inheritDoc} */
059    protected String getAuthorBlock( String author )
060    {
061        return null;
062    }
063
064    /** Not used.
065     * {@inheritDoc} */
066    protected String getBodyBlock()
067    {
068        return null;
069    }
070
071    /** {@inheritDoc} */
072    protected String getBoldBlock( String text )
073    {
074        return TWikiMarkup.BOLD_START_MARKUP + text + TWikiMarkup.BOLD_END_MARKUP;
075    }
076
077    /** Not used.
078     * {@inheritDoc} */
079    protected String getDateBlock( String date )
080    {
081        return null;
082    }
083
084    /** {@inheritDoc} */
085    protected String getDefinitionListBlock( String definum, String definition )
086    {
087        return TWikiMarkup.DEFINITION_LIST_ITEM_MARKUP + definum + TWikiMarkup.DEFINITION_LIST_DEFINITION_MARKUP
088            + definition + EOL;
089    }
090
091    /** {@inheritDoc} */
092    protected String getFigureBlock( String source, String caption )
093    {
094        String figureBlock = "<img src=\"" + source + "\"";
095        if ( caption != null )
096        {
097            figureBlock += " alt=\"" + caption + "\"";
098        }
099        figureBlock += " />";
100        return figureBlock;
101    }
102
103    /** Not used.
104     * {@inheritDoc} */
105    protected String getHeadBlock()
106    {
107        return null;
108    }
109
110    /** {@inheritDoc} */
111    protected String getHorizontalRuleBlock()
112    {
113        return TWikiMarkup.HORIZONTAL_RULE_MARKUP + EOL;
114    }
115
116    /** {@inheritDoc} */
117    protected String getItalicBlock( String text )
118    {
119        return TWikiMarkup.ITALIC_START_MARKUP + text + TWikiMarkup.ITALIC_END_MARKUP;
120    }
121
122    /** {@inheritDoc} */
123    protected String getLineBreakBlock()
124    {
125        return "";
126    }
127
128    /** {@inheritDoc} */
129    protected String getLinkBlock( String link, String text )
130    {
131        return TWikiMarkup.LINK_START_MARKUP + link + TWikiMarkup.LINK_MIDDLE_MARKUP + text
132            + TWikiMarkup.LINK_END_MARKUP;
133    }
134
135    /** {@inheritDoc} */
136    protected String getListBlock( String item )
137    {
138        return TWikiMarkup.LIST_ITEM_MARKUP + item + EOL;
139    }
140
141    /** {@inheritDoc} */
142    protected String getMonospacedBlock( String text )
143    {
144        return TWikiMarkup.MONOSPACED_START_MARKUP + text + TWikiMarkup.MONOSPACED_END_MARKUP;
145    }
146
147    /** {@inheritDoc} */
148    protected String getNonBreakingSpaceBlock()
149    {
150        return "";
151    }
152
153    /** {@inheritDoc} */
154    protected String getNumberedListBlock( String item )
155    {
156        return TWikiMarkup.NUMBERING_LOWER_ROMAN_MARKUP + " " + item + EOL;
157    }
158
159    /** {@inheritDoc} */
160    protected String getPageBreakBlock()
161    {
162        return "";
163    }
164
165    /** {@inheritDoc} */
166    protected String getParagraphBlock( String text )
167    {
168        return text + EOL + EOL;
169    }
170
171    /** {@inheritDoc} */
172    protected String getRawTextBlock( String text )
173    {
174        return "";
175    }
176
177    /** {@inheritDoc} */
178    protected String getSection1Block( String title )
179    {
180        return StringUtils.repeat( "-", 3 ) + StringUtils.repeat( "+", 1 ) + title + EOL + EOL;
181    }
182
183    /** {@inheritDoc} */
184    protected String getSection2Block( String title )
185    {
186        return StringUtils.repeat( "-", 3 ) + StringUtils.repeat( "+", 2 ) + title + EOL + EOL;
187    }
188
189    /** {@inheritDoc} */
190    protected String getSection3Block( String title )
191    {
192        return StringUtils.repeat( "-", 3 ) + StringUtils.repeat( "+", 3 ) + title + EOL + EOL;
193    }
194
195    /** {@inheritDoc} */
196    protected String getSection4Block( String title )
197    {
198        return StringUtils.repeat( "-", 3 ) + StringUtils.repeat( "+", 4 ) + title + EOL + EOL;
199    }
200
201    /** {@inheritDoc} */
202    protected String getSection5Block( String title )
203    {
204        return StringUtils.repeat( "-", 3 ) + StringUtils.repeat( "+", 5 ) + title + EOL + EOL;
205    }
206
207    /** {@inheritDoc} */
208    protected String getSectionTitleBlock( String title )
209    {
210        return title;
211    }
212
213    /** {@inheritDoc} */
214    protected String getTableBlock( String cell, String caption )
215    {
216        return "| " + cell + " |" + EOL + "Table_caption";
217    }
218
219    /** {@inheritDoc} */
220    protected String getTextBlock( String text )
221    {
222        return HtmlTools.escapeHTML( text );
223    }
224
225    /** Not used.
226     * {@inheritDoc} */
227    protected String getTitleBlock( String title )
228    {
229        return null;
230    }
231
232    /** {@inheritDoc} */
233    protected String getVerbatimBlock( String text )
234    {
235        return "<div class=\"source\">" + EOL + "<verbatim>" + text + "</verbatim>" + EOL + "</div>" + EOL;
236    }
237
238    /** {@inheritDoc} */
239    protected String outputExtension()
240    {
241        return "twiki";
242    }
243
244    // ----------------------------------------------------------------------
245    // Override unused tests
246    // ----------------------------------------------------------------------
247
248    /** Not used.
249     * {@inheritDoc} */
250    public void testAuthor()
251    {
252        // nop
253    }
254
255    /** Not used.
256     * {@inheritDoc} */
257    public void testDate()
258    {
259        // nop
260    }
261
262    /** Not used.
263     * {@inheritDoc} */
264    public void testHead()
265    {
266        // nop
267    }
268
269    /** Not used.
270     * {@inheritDoc} */
271    public void testBody()
272    {
273        // nop
274    }
275
276    /** Not used.
277     * {@inheritDoc} */
278    public void testTitle()
279    {
280        // nop
281    }
282
283    /** {@inheritDoc} */
284    protected String getCommentBlock( String text )
285    {
286        return "";
287    }
288}