1 package org.apache.maven.doxia.docrenderer;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23 import java.util.List;
24
25 import org.apache.maven.doxia.docrenderer.pdf.PdfRenderer;
26 import org.apache.maven.doxia.document.DocumentModel;
27 import org.codehaus.plexus.PlexusTestCase;
28 import org.codehaus.plexus.util.FileUtils;
29 import org.codehaus.plexus.util.StringUtils;
30
31
32
33
34
35
36 public class DocumentRendererTest
37 extends PlexusTestCase
38 {
39 private PdfRenderer docRenderer;
40
41 private File siteDirectoryFile;
42
43
44 protected void setUp()
45 throws Exception
46 {
47 super.setUp();
48
49 siteDirectoryFile = getTestFile( "src/test/resources/site" );
50 }
51
52
53 protected void tearDown()
54 throws Exception
55 {
56 release( docRenderer );
57 super.tearDown();
58 }
59
60
61 public void testFo()
62 throws Exception
63 {
64 renderImpl( "fo" );
65 }
66
67
68 public void testFoAggregate()
69 throws Exception
70 {
71 renderAggregatedImpl( "fo" );
72 }
73
74
75 public void testIText()
76 throws Exception
77 {
78 renderImpl( "itext" );
79 }
80
81
82 public void testITextAggregate()
83 throws Exception
84 {
85 renderAggregatedImpl( "itext" );
86 }
87
88 private void renderImpl( String implementation )
89 throws Exception
90 {
91 File outputDirectory = getTestFile( "target/output/" + implementation );
92 if ( outputDirectory.exists() )
93 {
94 FileUtils.deleteDirectory( outputDirectory );
95 }
96 outputDirectory.mkdirs();
97
98 docRenderer = (PdfRenderer) lookup( PdfRenderer.ROLE, implementation );
99 assertNotNull( docRenderer );
100
101 docRenderer.render( siteDirectoryFile, outputDirectory, null );
102
103 List<String> files =
104 FileUtils.getFileNames( new File( siteDirectoryFile, "apt" ), "**/*.apt",
105 FileUtils.getDefaultExcludesAsString(), false );
106 files.addAll( FileUtils.getFileNames( new File( siteDirectoryFile, "fml" ), "**/*.fml",
107 FileUtils.getDefaultExcludesAsString(), false ) );
108 files.addAll( FileUtils.getFileNames( new File( siteDirectoryFile, "xdoc" ), "**/*.xml",
109 FileUtils.getDefaultExcludesAsString(), false ) );
110
111 for ( String relativeFile : files )
112 {
113 String relativePdf = StringUtils.replace( relativeFile, FileUtils.getExtension( relativeFile ), "pdf" );
114 File pdf = new File( outputDirectory, relativePdf );
115
116 assertTrue( pdf.exists() );
117 assertTrue( pdf.length() > 0 );
118 }
119 }
120
121 private void renderAggregatedImpl( String implementation )
122 throws Exception
123 {
124 File outputDirectory = getTestFile( "target/output/" + implementation + "-aggregated" );
125 if ( outputDirectory.exists() )
126 {
127 FileUtils.deleteDirectory( outputDirectory );
128 }
129 outputDirectory.mkdirs();
130
131 docRenderer = (PdfRenderer) lookup( PdfRenderer.ROLE, implementation );
132 assertNotNull( docRenderer );
133
134 DocumentModel descriptor = docRenderer.readDocumentModel( new File( siteDirectoryFile, "pdf.xml" ) );
135 assertNotNull( descriptor );
136
137 docRenderer.render( siteDirectoryFile, outputDirectory, descriptor );
138
139 File pdf = new File( outputDirectory, descriptor.getOutputName() + ".pdf" );
140
141 assertTrue( pdf.exists() );
142 assertTrue( pdf.length() > 0 );
143 }
144 }