1 package org.apache.maven.plugins.pdf;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.plugin.testing.AbstractMojoTestCase;
23 import org.codehaus.plexus.util.IOUtil;
24 import org.codehaus.plexus.util.ReaderFactory;
25 import org.codehaus.plexus.util.StringUtils;
26 import org.codehaus.plexus.util.cli.CommandLineUtils;
27
28 import java.io.File;
29 import java.io.Reader;
30
31
32
33
34
35 public class PdfMojoTest
36 extends AbstractMojoTestCase
37 {
38
39
40
41
42
43 public void testPdfMojo()
44 throws Exception
45 {
46 executePdfMojo( "pom.xml", "fo/maven-pdf-plugin-doc.pdf" );
47 }
48
49
50
51
52
53
54 public void testITextImpl()
55 throws Exception
56 {
57 executePdfMojo( "iText_pom.xml", "itext/maven-pdf-plugin-doc.pdf" );
58 }
59
60
61
62
63
64
65 public void testPdfMojoNoDocDesriptor()
66 throws Exception
67 {
68 executePdfMojo( "no_docdescriptor_pom.xml", "no/unnamed.pdf" );
69 }
70
71
72
73
74 public void _testPdfFilterMojo()
75 throws Exception
76 {
77 executePdfMojo( "pom_filtering.xml", "filtering/maven-pdf-plugin-doc-1.0-SNAPSHOT.pdf" );
78
79 File foFile = new File( getBasedir(), "/target/test-output/pdf/filtering/maven-pdf-plugin-doc-1.0-SNAPSHOT.fo" );
80 assertTrue( "FO: Fo file not created!", foFile.exists() );
81 assertTrue( "FO: Fo file has no content!", foFile.length() > 0 );
82
83 Reader reader = null;
84 String foContent;
85 try
86 {
87 reader = ReaderFactory.newXmlReader( foFile );
88 foContent = IOUtil.toString( reader );
89 reader.close();
90 reader = null;
91 }
92 finally
93 {
94 IOUtil.close( reader );
95 }
96
97 assertTrue( foContent.indexOf( "Test filtering" ) > 0 );
98 assertTrue( foContent.indexOf( "1.0-SNAPSHOT" ) > 0 );
99
100 String m2Home = CommandLineUtils.getSystemEnvVars().getProperty( "M2_HOME" );
101 if ( StringUtils.isNotEmpty( m2Home ) )
102 {
103 assertTrue( foContent.indexOf( m2Home ) > 0 );
104 }
105
106 assertTrue( foContent.indexOf( "vsiveton@apache.org ltheussl@apache.org" ) > 0 );
107
108
109 assertTrue( foContent.indexOf( new DateBean().getDate() ) > 0 );
110 }
111
112 protected PdfMojo lookupPdfMojo( String pom )
113 throws Exception
114 {
115 File testPom = new File( getBasedir(), "target/test-classes/unit/pdf/" + pom );
116 assertTrue( "testPom does not exist!", testPom.exists() );
117 PdfMojo mojo = (PdfMojo) lookupMojo( "pdf", testPom );
118 assertNotNull( "pdf mojo not found!", mojo );
119 return mojo;
120 }
121
122 protected File prepareOutputPdf( String filename )
123 {
124 File pdfFile = new File( getBasedir(), "target/test-output/pdf/" + filename );
125 if ( pdfFile.exists() )
126 {
127 pdfFile.delete();
128 }
129 return pdfFile;
130 }
131
132 protected void executePdfMojo( String pom, String pdfFilename )
133 throws Exception
134 {
135
136 return;
137
138
139
140
141
142
143
144
145
146 }
147 }