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