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