View Javadoc
1   package org.apache.maven.doxia.module.rtf;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.maven.doxia.sink.Sink;
23  import org.apache.maven.doxia.sink.impl.AbstractSinkTestCase;
24  import org.apache.maven.doxia.sink.impl.SinkTestDocument;
25  import org.apache.maven.doxia.parser.Parser;
26  import org.apache.maven.doxia.module.apt.AptParser;
27  import org.codehaus.plexus.util.IOUtil;
28  
29  import java.io.File;
30  import java.io.FileOutputStream;
31  import java.io.OutputStream;
32  import java.io.Reader;
33  import java.io.InputStream;
34  import java.io.InputStreamReader;
35  
36  /**
37   * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
38   * @version $Id$
39   */
40  public class RtfSinkTest
41      extends AbstractSinkTestCase
42  {
43      /** {@inheritDoc} */
44      protected String outputExtension()
45      {
46          return "rtf";
47      }
48  
49      /** {@inheritDoc} */
50      protected Parser createParser()
51      {
52          return new AptParser();
53      }
54  
55      /** {@inheritDoc} */
56      protected Sink createSink()
57          throws Exception
58      {
59          File outputFile = new File( getBasedirFile(), "target/output/test.rtf" );
60          outputFile.getParentFile().mkdirs();
61          return new RtfSink( new FileOutputStream( outputFile ) );
62      }
63  
64      /** {@inheritDoc} */
65      protected Reader getTestReader()
66          throws Exception
67      {
68          InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream( "test.apt" );
69  
70          InputStreamReader reader = new InputStreamReader( is );
71  
72          return reader;
73      }
74  
75      public void testDocument()
76          throws Exception
77      {
78          File outputFile = new File( getBasedirFile(), "target/test-output/sink/testDocument.rtf" );
79          outputFile.getParentFile().mkdirs();
80          OutputStream out = new FileOutputStream( outputFile );
81  
82          Sink sink = new RtfSink( out );
83          try
84          {
85              SinkTestDocument.generate( sink );
86          }
87          finally
88          {
89              sink.close();
90              IOUtil.close( out );
91          }
92      }
93  }