1   package org.apache.maven.doxia.docrenderer.itext;
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.docrenderer.DocRenderer;
25  import org.codehaus.plexus.PlexusTestCase;
26  import org.codehaus.plexus.util.FileUtils;
27  
28  /**
29   * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
30   * @version $Id: DefaultPdfRendererTest.java 638287 2008-03-18 09:43:43Z bentmann $
31   */
32  public class DefaultPdfRendererTest
33      extends PlexusTestCase
34  {
35      private static final String OUTPUT = "target/output";
36  
37      private static final String SITE = "src/test/resources/site";
38  
39      private static final String DESCRIPTOR_WITHOUT_TOC = "src/test/resources/doc-without-TOC.xml";
40  
41      private File outputDirectory;
42  
43      private File siteDirectoryFile;
44  
45      private DocRenderer docRenderer;
46  
47      /** {@inheritDoc} */
48      protected void setUp()
49          throws Exception
50      {
51          super.setUp();
52  
53          docRenderer = (DocRenderer) lookup( DocRenderer.ROLE );
54  
55          outputDirectory = getTestFile( OUTPUT );
56          outputDirectory.mkdirs();
57  
58          siteDirectoryFile = getTestFile( SITE );
59  
60          FileUtils.copyDirectory( new File( siteDirectoryFile, "resources/css" ), new File( outputDirectory, "css" ),
61                                   "*.css", ".svn" );
62          FileUtils.copyDirectory( new File( siteDirectoryFile, "resources/images" ),
63                                   new File( outputDirectory, "images" ), "*.png", ".svn" );
64      }
65  
66      /** {@inheritDoc} */
67      protected void tearDown()
68          throws Exception
69      {
70          release( docRenderer );
71          super.tearDown();
72      }
73  
74      /**
75       * @throws Exception
76       */
77      public void testRenderFileFile()
78          throws Exception
79      {
80          docRenderer.render( siteDirectoryFile, outputDirectory );
81  
82          assertTrue( new File( outputDirectory, "faq.pdf" ).exists() );
83          assertTrue( new File( outputDirectory, "faq.pdf" ).length() > 0 );
84          assertTrue( new File( outputDirectory, "index.pdf" ).exists() );
85          assertTrue( new File( outputDirectory, "index.pdf" ).length() > 0 );
86          assertTrue( new File( outputDirectory, "overview.pdf" ).exists() );
87          assertTrue( new File( outputDirectory, "overview.pdf" ).length() > 0 );
88          assertTrue( new File( outputDirectory, "resources.pdf" ).exists() );
89          assertTrue( new File( outputDirectory, "resources.pdf" ).length() > 0 );
90  
91      }
92  
93      /**
94       * @throws Exception
95       */
96      public void testRenderFileFileFile()
97          throws Exception
98      {
99          File descriptor = getTestFile( DESCRIPTOR_WITHOUT_TOC );
100 
101         docRenderer.render( siteDirectoryFile, outputDirectory, descriptor );
102 
103         assertTrue( new File( outputDirectory, "doc-with-merged.pdf" ).exists() );
104         assertTrue( new File( outputDirectory, "doc-with-merged.pdf" ).length() > 0 );
105     }
106 }