View Javadoc
1   package org.apache.maven.doxia.parser;
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.SinkAdapter;
24  import org.codehaus.plexus.PlexusTestCase;
25  
26  import java.io.FileReader;
27  import java.io.Reader;
28  
29  /**
30   * Test the parsing of sample input files
31   *
32   * @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
33   * @author <a href="mailto:evenisse@codehaus.org">Emmanuel Venisse</a>
34   * @version $Id$
35   * @since 1.0
36   */
37  public abstract class AbstractParserTestCase
38      extends PlexusTestCase
39  {
40      /**
41       * Parser to use to convert input to sink events
42       *
43       * @return the parser to use
44       */
45      protected abstract Parser getParser();
46  
47      /**
48       * Path of the model to test, relative to basedir
49       *
50       * @return the relative path
51       */
52      protected abstract String getDocument();
53  
54      /**
55       * Sink to write the output of the parsing
56       *
57       * @return a SinkAdapter if not overridden
58       */
59      protected Sink getSink()
60      {
61          return new SinkAdapter();
62      }
63  
64      /**
65       * Parse the model in the path specified by {@link #getDocument()},
66       * with parser from {@link #getParser()}, and output to sink from {@link #getSink()}
67       *
68       * @throws Exception if any.
69       */
70      public void testParser()
71          throws Exception
72      {
73          Reader reader = new FileReader( getTestFile( getBasedir(), getDocument() ) );
74  
75          getParser().parse( reader, getSink() );
76      }
77  }