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