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.Iterator;
24 import java.util.List;
25
26 import org.apache.maven.doxia.docrenderer.pdf.PdfRenderer;
27 import org.apache.maven.doxia.document.DocumentModel;
28 import org.codehaus.plexus.PlexusTestCase;
29 import org.codehaus.plexus.util.FileUtils;
30 import org.codehaus.plexus.util.StringUtils;
31
32
33
34
35
36
37 public class DocumentRendererTest
38 extends PlexusTestCase
39 {
40 private PdfRenderer docRenderer;
41
42 private File siteDirectoryFile;
43
44
45 protected void setUp()
46 throws Exception
47 {
48 super.setUp();
49
50 siteDirectoryFile = getTestFile( "src/test/resources/site" );
51 }
52
53
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 private void renderImpl( String implementation )
90 throws Exception
91 {
92 File outputDirectory = getTestFile( "target/output/" + implementation );
93 if ( outputDirectory.exists() )
94 {
95 FileUtils.deleteDirectory( outputDirectory );
96 }
97 outputDirectory.mkdirs();
98
99 docRenderer = (PdfRenderer) lookup( PdfRenderer.ROLE, implementation );
100 assertNotNull( docRenderer );
101
102 docRenderer.render( siteDirectoryFile, outputDirectory, null );
103
104 List files =
105 FileUtils.getFileNames( new File( siteDirectoryFile, "apt" ), "**/*.apt",
106 FileUtils.getDefaultExcludesAsString(), false );
107 files.addAll( FileUtils.getFileNames( new File( siteDirectoryFile, "fml" ), "**/*.fml",
108 FileUtils.getDefaultExcludesAsString(), false ) );
109 files.addAll( FileUtils.getFileNames( new File( siteDirectoryFile, "xdoc" ), "**/*.xml",
110 FileUtils.getDefaultExcludesAsString(), false ) );
111
112 for ( Iterator it = files.iterator(); it.hasNext(); )
113 {
114 String relativeFile = it.next().toString();
115 String relativePdf = StringUtils.replace( relativeFile, FileUtils.getExtension( relativeFile ), "pdf" );
116 File pdf = new File( outputDirectory, relativePdf );
117
118 assertTrue( pdf.exists() );
119 assertTrue( pdf.length() > 0 );
120 }
121 }
122
123 private void renderAggregatedImpl( String implementation )
124 throws Exception
125 {
126 File outputDirectory = getTestFile( "target/output/" + implementation + "-aggregated" );
127 if ( outputDirectory.exists() )
128 {
129 FileUtils.deleteDirectory( outputDirectory );
130 }
131 outputDirectory.mkdirs();
132
133 docRenderer = (PdfRenderer) lookup( PdfRenderer.ROLE, implementation );
134 assertNotNull( docRenderer );
135
136 DocumentModel descriptor = docRenderer.readDocumentModel( new File( siteDirectoryFile, "pdf.xml" ) );
137 assertNotNull( descriptor );
138
139 docRenderer.render( siteDirectoryFile, outputDirectory, descriptor );
140
141 File pdf = new File( outputDirectory, descriptor.getOutputName() + ".pdf" );
142
143 assertTrue( pdf.exists() );
144 assertTrue( pdf.length() > 0 );
145 }
146 }