001package org.apache.maven.doxia.parser; 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.SinkAdapter; 024import org.codehaus.plexus.PlexusTestCase; 025 026import java.io.FileReader; 027import java.io.Reader; 028 029/** 030 * Test the parsing of sample input files 031 * 032 * @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a> 033 * @author <a href="mailto:evenisse@codehaus.org">Emmanuel Venisse</a> 034 * @version $Id$ 035 * @since 1.0 036 */ 037public abstract class AbstractParserTestCase 038 extends PlexusTestCase 039{ 040 /** 041 * Parser to use to convert input to sink events 042 * 043 * @return the parser to use 044 */ 045 protected abstract Parser getParser(); 046 047 /** 048 * Path of the model to test, relative to basedir 049 * 050 * @return the relative path 051 */ 052 protected abstract String getDocument(); 053 054 /** 055 * Sink to write the output of the parsing 056 * 057 * @return a SinkAdapter if not overridden 058 */ 059 protected Sink getSink() 060 { 061 return new SinkAdapter(); 062 } 063 064 /** 065 * Parse the model in the path specified by {@link #getDocument()}, 066 * with parser from {@link #getParser()}, and output to sink from {@link #getSink()} 067 * 068 * @throws Exception if any. 069 */ 070 public void testParser() 071 throws Exception 072 { 073 Reader reader = new FileReader( getTestFile( getBasedir(), getDocument() ) ); 074 075 getParser().parse( reader, getSink() ); 076 } 077}