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 public class PdfMojoTest
35 extends AbstractMojoTestCase
36 {
37
38
39
40
41 public void testPdfMojo()
42 {
43 executePdfMojo( "pom.xml", "fo/maven-pdf-plugin-doc.pdf" );
44 }
45
46
47
48
49
50 public void testITextImpl()
51 {
52 executePdfMojo( "iText_pom.xml", "itext/maven-pdf-plugin-doc.pdf" );
53 }
54
55
56
57
58
59 public void testPdfMojoNoDocDesriptor()
60 {
61 executePdfMojo( "no_docdescriptor_pom.xml", "no/unnamed.pdf" );
62 }
63
64
65
66
67 public void _testPdfFilterMojo()
68 throws Exception
69 {
70 executePdfMojo( "pom_filtering.xml", "filtering/maven-pdf-plugin-doc-1.0-SNAPSHOT.pdf" );
71
72 File foFile = new File( getBasedir(), "/target/test-output/pdf/filtering/maven-pdf-plugin-doc-1.0-SNAPSHOT.fo" );
73 assertTrue( "FO: Fo file not created!", foFile.exists() );
74 assertTrue( "FO: Fo file has no content!", foFile.length() > 0 );
75
76 String foContent;
77 try ( Reader reader = ReaderFactory.newXmlReader( foFile ) )
78 {
79 foContent = IOUtil.toString( reader );
80 }
81
82
83 assertTrue( foContent.indexOf( "Test filtering" ) > 0 );
84 assertTrue( foContent.indexOf( "1.0-SNAPSHOT" ) > 0 );
85
86 String m2Home = CommandLineUtils.getSystemEnvVars().getProperty( "M2_HOME" );
87 if ( StringUtils.isNotEmpty( m2Home ) )
88 {
89 assertTrue( foContent.indexOf( m2Home ) > 0 );
90 }
91
92 assertTrue( foContent.indexOf( "vsiveton@apache.org ltheussl@apache.org" ) > 0 );
93
94
95 assertTrue( foContent.indexOf( new DateBean().getDate() ) > 0 );
96 }
97
98 protected PdfMojo lookupPdfMojo( String pom )
99 throws Exception
100 {
101 File testPom = new File( getBasedir(), "target/test-classes/unit/pdf/" + pom );
102 assertTrue( "testPom does not exist!", testPom.exists() );
103 PdfMojo mojo = (PdfMojo) lookupMojo( "pdf", testPom );
104 assertNotNull( "pdf mojo not found!", mojo );
105 return mojo;
106 }
107
108 protected File prepareOutputPdf( String filename )
109 {
110 File pdfFile = new File( getBasedir(), "target/test-output/pdf/" + filename );
111 if ( pdfFile.exists() )
112 {
113 pdfFile.delete();
114 }
115 return pdfFile;
116 }
117
118 protected void executePdfMojo( String pom, String pdfFilename )
119 {
120
121 return;
122
123
124
125
126
127
128
129
130
131 }
132 }