View Javadoc
1   package org.apache.maven.plugins.pdf;
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  
23  import java.io.File;
24  
25  import org.apache.maven.doxia.document.DocumentModel;
26  import org.apache.maven.plugins.pdf.stubs.FilteringMavenProjectStub;
27  
28  import org.codehaus.plexus.PlexusTestCase;
29  
30  /**
31   *
32   * @author ltheussl
33   * @version $Id: DocumentDescriptorReaderTest.java 787572 2009-06-23 07:20:35Z ltheussl $
34   */
35  public class DocumentDescriptorReaderTest
36          extends PlexusTestCase
37  {
38  /**
39       * Test of readAndFilterDocumentDescriptor method, of class DocumentDescriptorReader.
40       * @throws Exception if something happens.
41       */
42      public void testReaderNoProject()
43              throws Exception
44      {
45          DocumentDescriptorReader reader = new DocumentDescriptorReader();
46          File descriptorFile = new File( testBaseDir() + "src/site/", "model_builder_site.xml" );
47          DocumentModel model = reader.readAndFilterDocumentDescriptor( descriptorFile );
48          assertNotNull( model );
49          assertNull( model.getCover() );
50          assertNull( model.getMeta() );
51          assertNull( model.getToc() );
52      }
53  
54      /**
55       * Test of readAndFilterDocumentDescriptor method, of class DocumentDescriptorReader.
56       * @throws Exception if something happens.
57       */
58      public void testFiltering()
59              throws Exception
60      {
61          DocumentDescriptorReader reader = new DocumentDescriptorReader( new FilteringMavenProjectStub() );
62          File descriptorFile = new File( testBaseDir() + "src/site/", "pdf_filtering.xml" );
63          DocumentModel model = reader.readAndFilterDocumentDescriptor( descriptorFile );
64          assertNotNull( model );
65          assertNull( model.getCover() );
66          assertNotNull( model.getToc() );
67          assertEquals( "Table of Contents", model.getToc().getName() );
68          assertEquals( 5, model.getToc().getItems().size() );
69          assertNotNull( model.getMeta() );
70          assertTrue( model.getMeta().getTitle().indexOf(
71                  "User guide in en of Test filtering version 1.0-SNAPSHOT" ) == 0 );
72          assertEquals( "vsiveton@apache.org ltheussl@apache.org", model.getMeta().getAuthor() );
73      }
74  
75      private String testBaseDir()
76      {
77          return getBasedir() + "/src/test/resources/unit/pdf/";
78      }
79  }