View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.plugins.pdf;
20  
21  /*
22   * Licensed to the Apache Software Foundation (ASF) under one
23   * or more contributor license agreements.  See the NOTICE file
24   * distributed with this work for additional information
25   * regarding copyright ownership.  The ASF licenses this file
26   * to you under the Apache License, Version 2.0 (the
27   * "License"); you may not use this file except in compliance
28   * with the License.  You may obtain a copy of the License at
29   *
30   *   http://www.apache.org/licenses/LICENSE-2.0
31   *
32   * Unless required by applicable law or agreed to in writing,
33   * software distributed under the License is distributed on an
34   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
35   * KIND, either express or implied.  See the License for the
36   * specific language governing permissions and limitations
37   * under the License.
38   */
39  
40  import java.io.File;
41  
42  import org.apache.maven.doxia.document.DocumentModel;
43  import org.apache.maven.plugins.pdf.stubs.FilteringMavenProjectStub;
44  import org.codehaus.plexus.PlexusTestCase;
45  
46  /**
47   *
48   * @author ltheussl
49   */
50  public class DocumentDescriptorReaderTest extends PlexusTestCase {
51      /**
52       * Test of readAndFilterDocumentDescriptor method, of class DocumentDescriptorReader.
53       * @throws Exception if something happens.
54       */
55      public void testReaderNoProject() throws Exception {
56          DocumentDescriptorReader reader = new DocumentDescriptorReader();
57          File descriptorFile = new File(testBaseDir() + "src/site/", "model_builder_site.xml");
58          DocumentModel model = reader.readAndFilterDocumentDescriptor(descriptorFile);
59          assertNotNull(model);
60          assertNull(model.getCover());
61          assertNull(model.getMeta());
62          assertNull(model.getToc());
63      }
64  
65      /**
66       * Test of readAndFilterDocumentDescriptor method, of class DocumentDescriptorReader.
67       * @throws Exception if something happens.
68       */
69      public void testFiltering() throws Exception {
70          DocumentDescriptorReader reader = new DocumentDescriptorReader(new FilteringMavenProjectStub());
71          File descriptorFile = new File(testBaseDir() + "src/site/", "pdf_filtering.xml");
72          DocumentModel model = reader.readAndFilterDocumentDescriptor(descriptorFile);
73          assertNotNull(model);
74          assertNull(model.getCover());
75          assertNotNull(model.getToc());
76          assertEquals("Table of Contents", model.getToc().getName());
77          assertEquals(5, model.getToc().getItems().size());
78          assertNotNull(model.getMeta());
79          assertEquals(0, model.getMeta().getTitle().indexOf("User guide in en of Test filtering version 1.0-SNAPSHOT"));
80          assertEquals("vsiveton@apache.org ltheussl@apache.org", model.getMeta().getAuthor());
81      }
82  
83      private String testBaseDir() {
84          return getBasedir() + "/src/test/resources/unit/pdf/";
85      }
86  }