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 protected void setUp() throws Exception
40 {
41
42 super.setUp();
43 }
44
45
46
47
48
49
50 public void testPdfMojo() throws Exception
51 {
52 File testPom = new File( getBasedir(), "/target/test-classes/unit/pdf/pom.xml" );
53 assertTrue( "testPom does not exist!", testPom.exists() );
54
55 PdfMojo mojo = (PdfMojo) lookupMojo( "pdf", testPom );
56 assertNotNull( "pdf mojo not found!", mojo );
57
58 File pdfFile = new File( getBasedir(), "/target/test-output/pdf/fo/maven-pdf-plugin-doc.pdf" );
59 if ( pdfFile.exists() )
60 {
61 pdfFile.delete();
62 }
63
64 mojo.execute();
65
66 assertTrue( "FO: Pdf file not created!", pdfFile.exists() );
67 assertTrue( "FO: Pdf file has no content!", pdfFile.length() > 0 );
68 }
69
70
71
72
73
74
75 public void testITextImpl() throws Exception
76 {
77 File testPom = new File( getBasedir(), "/target/test-classes/unit/pdf/iText_pom.xml" );
78 assertTrue( "testPom does not exist!", testPom.exists() );
79
80 PdfMojo mojo = (PdfMojo) lookupMojo( "pdf", testPom );
81 assertNotNull( "pdf mojo not found!", mojo );
82
83 File pdfFile = new File( getBasedir(), "/target/test-output/pdf/itext/maven-pdf-plugin-doc.pdf" );
84 if ( pdfFile.exists() )
85 {
86 pdfFile.delete();
87 }
88
89 mojo.execute();
90
91 assertTrue( "iText: Pdf file not created!", pdfFile.exists() );
92 assertTrue( "iText: Pdf file has no content!", pdfFile.length() > 0 );
93 }
94
95
96
97
98 public void testPdfFilterMojo() throws Exception
99 {
100 File testPom = new File( getBasedir(), "/target/test-classes/unit/pdf/pom_filtering.xml" );
101 assertTrue( "testPom does not exist!", testPom.exists() );
102
103 PdfMojo mojo = (PdfMojo) lookupMojo( "pdf", testPom );
104 assertNotNull( "pdf mojo not found!", mojo );
105
106 File pdfFile = new File( getBasedir(), "/target/test-output/pdf/filtering/maven-pdf-plugin-doc-1.0-SNAPSHOT.pdf" );
107 if ( pdfFile.exists() )
108 {
109 pdfFile.delete();
110 }
111
112 mojo.execute();
113
114 assertTrue( "FO: Pdf file not created!", pdfFile.exists() );
115 assertTrue( "FO: Pdf file has no content!", pdfFile.length() > 0 );
116
117 File foFile = new File( getBasedir(), "/target/test-output/pdf/filtering/maven-pdf-plugin-doc-1.0-SNAPSHOT.fo" );
118 assertTrue( "FO: Fo file not created!", foFile.exists() );
119 assertTrue( "FO: Fo file has no content!", foFile.length() > 0 );
120
121 Reader reader = null;
122 String foContent;
123 try
124 {
125 reader = ReaderFactory.newXmlReader( foFile );
126 foContent = IOUtil.toString( reader );
127 }
128 finally
129 {
130 IOUtil.close( reader );
131 }
132
133 assertTrue( foContent.indexOf( "Test filtering" ) > 0 );
134 assertTrue( foContent.indexOf( "1.0-SNAPSHOT" ) > 0 );
135
136 String m2Home = CommandLineUtils.getSystemEnvVars().getProperty( "M2_HOME" );
137 if ( StringUtils.isNotEmpty( m2Home ) )
138 {
139 assertTrue( foContent.indexOf( m2Home ) > 0 );
140 }
141
142 assertTrue( foContent.indexOf( "vsiveton@apache.org ltheussl@apache.org" ) > 0 );
143
144
145 assertTrue( foContent.indexOf( new DateBean().getDate() ) > 0 );
146 }
147
148
149
150
151
152
153 public void testPdfMojoNoDocDesriptor() throws Exception
154 {
155 File testPom = new File( getBasedir(), "/target/test-classes/unit/pdf/no_docdescriptor_pom.xml" );
156 assertTrue( "testPom does not exist!", testPom.exists() );
157
158 PdfMojo mojo = (PdfMojo) lookupMojo( "pdf", testPom );
159 assertNotNull( "pdf mojo not found!", mojo );
160
161 File pdfFile = new File( getBasedir(), "/target/test-output/pdf/no/unnamed.pdf" );
162 if ( pdfFile.exists() )
163 {
164 pdfFile.delete();
165 }
166
167 mojo.execute();
168
169 assertTrue( "FO: Pdf file not created!", pdfFile.exists() );
170 assertTrue( "FO: Pdf file has no content!", pdfFile.length() > 0 );
171 }
172 }