001package org.apache.maven.doxia.module.rtf; 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 org.apache.maven.doxia.sink.Sink; 023import org.apache.maven.doxia.sink.impl.AbstractSinkTestCase; 024import org.apache.maven.doxia.sink.impl.SinkTestDocument; 025import org.apache.maven.doxia.parser.Parser; 026import org.apache.maven.doxia.module.apt.AptParser; 027import org.codehaus.plexus.util.IOUtil; 028 029import java.io.File; 030import java.io.FileOutputStream; 031import java.io.OutputStream; 032import java.io.Reader; 033import java.io.InputStream; 034import java.io.InputStreamReader; 035 036/** 037 * @author <a href="mailto:jason@maven.org">Jason van Zyl</a> 038 * @version $Id$ 039 */ 040public class RtfSinkTest 041 extends AbstractSinkTestCase 042{ 043 /** {@inheritDoc} */ 044 protected String outputExtension() 045 { 046 return "rtf"; 047 } 048 049 /** {@inheritDoc} */ 050 protected Parser createParser() 051 { 052 return new AptParser(); 053 } 054 055 /** {@inheritDoc} */ 056 protected Sink createSink() 057 throws Exception 058 { 059 File outputFile = new File( getBasedirFile(), "target/output/test.rtf" ); 060 outputFile.getParentFile().mkdirs(); 061 return new RtfSink( new FileOutputStream( outputFile ) ); 062 } 063 064 /** {@inheritDoc} */ 065 protected Reader getTestReader() 066 throws Exception 067 { 068 InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream( "test.apt" ); 069 070 InputStreamReader reader = new InputStreamReader( is ); 071 072 return reader; 073 } 074 075 public void testDocument() 076 throws Exception 077 { 078 File outputFile = new File( getBasedirFile(), "target/test-output/sink/testDocument.rtf" ); 079 outputFile.getParentFile().mkdirs(); 080 OutputStream out = new FileOutputStream( outputFile ); 081 082 Sink sink = new RtfSink( out ); 083 try 084 { 085 SinkTestDocument.generate( sink ); 086 } 087 finally 088 { 089 sink.close(); 090 IOUtil.close( out ); 091 } 092 } 093}