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 public class DocumentRendererTest
36 extends PlexusTestCase
37 {
38 private PdfRenderer docRenderer;
39
40 private File siteDirectoryFile;
41
42
43 @Override
44 protected void setUp()
45 throws Exception
46 {
47 super.setUp();
48
49 siteDirectoryFile = getTestFile( "src/test/resources/site" );
50 }
51
52
53 @Override
54 protected void tearDown()
55 throws Exception
56 {
57 release( docRenderer );
58 super.tearDown();
59 }
60
61
62 public void testFo()
63 throws Exception
64 {
65 renderImpl( "fo" );
66 }
67
68
69 public void testFoAggregate()
70 throws Exception
71 {
72 renderAggregatedImpl( "fo" );
73 }
74
75
76 public void testIText()
77 throws Exception
78 {
79 renderImpl( "itext" );
80 }
81
82
83 public void testITextAggregate()
84 throws Exception
85 {
86 renderAggregatedImpl( "itext" );
87 }
88
89 @SuppressWarnings ( "unchecked" )
90 private void renderImpl( String implementation )
91 throws Exception
92 {
93 File outputDirectory = getTestFile( "target/output/" + implementation );
94 if ( outputDirectory.exists() )
95 {
96 FileUtils.deleteDirectory( outputDirectory );
97 }
98 outputDirectory.mkdirs();
99
100 docRenderer = (PdfRenderer) lookup( PdfRenderer.ROLE, implementation );
101 assertNotNull( docRenderer );
102
103 docRenderer.render( siteDirectoryFile, outputDirectory, null );
104
105 @SuppressWarnings ( "unchecked" )
106 List<String> files =
107 FileUtils.getFileNames( new File( siteDirectoryFile, "apt" ), "**/*.apt",
108 FileUtils.getDefaultExcludesAsString(), false );
109 files.addAll( FileUtils.getFileNames( new File( siteDirectoryFile, "fml" ), "**/*.fml",
110 FileUtils.getDefaultExcludesAsString(), false ) );
111 files.addAll( FileUtils.getFileNames( new File( siteDirectoryFile, "xdoc" ), "**/*.xml",
112 FileUtils.getDefaultExcludesAsString(), false ) );
113
114 for ( String relativeFile : files )
115 {
116 String relativePdf = StringUtils.replace( relativeFile, FileUtils.getExtension( relativeFile ), "pdf" );
117 File pdf = new File( outputDirectory, relativePdf );
118
119 assertTrue( pdf.exists() );
120 assertTrue( pdf.length() > 0 );
121 }
122 }
123
124 private void renderAggregatedImpl( String implementation )
125 throws Exception
126 {
127 File outputDirectory = getTestFile( "target/output/" + implementation + "-aggregated" );
128 if ( outputDirectory.exists() )
129 {
130 FileUtils.deleteDirectory( outputDirectory );
131 }
132 outputDirectory.mkdirs();
133
134 docRenderer = (PdfRenderer) lookup( PdfRenderer.ROLE, implementation );
135 assertNotNull( docRenderer );
136
137 DocumentModel descriptor = docRenderer.readDocumentModel( new File( siteDirectoryFile, "pdf.xml" ) );
138 assertNotNull( descriptor );
139
140 docRenderer.render( siteDirectoryFile, outputDirectory, descriptor );
141
142 File pdf = new File( outputDirectory, descriptor.getOutputName() + ".pdf" );
143
144 assertTrue( pdf.exists() );
145 assertTrue( pdf.length() > 0 );
146 }
147 }