1 package eu.simuline.m2latex.integration;
2
3 import eu.simuline.m2latex.mojo.InjectionMojo;
4 import eu.simuline.m2latex.mojo.PdfMojo;
5
6 import org.apache.maven.plugin.testing.AbstractMojoTestCase;
7
8 import org.apache.commons.io.FileUtils;
9
10 import java.io.File;
11
12 public class PdfMojoTest extends AbstractMojoTestCase {
13 /**
14 * @see junit.framework.TestCase#setUp()
15 */
16 protected void setUp() throws Exception {
17 // required for mojo lookups to work
18 super.setUp();
19 }
20
21 protected void tearDown() throws Exception {
22 // required
23 super.tearDown();
24 }
25
26 /**
27 * Tests whether the manual is the same as the one stored for comparison.
28 *
29 * @throws Exception
30 */
31 public void testMojoGoal() throws Exception {
32 // getBasedir() is inherited from org.codehaus.plexus.PlexusTestCase
33 File thisDir = new File(getBasedir(), "src/test/resources/integration/");
34 File testPom = new File(thisDir, "pom4pdf.xml");
35 assertNotNull(testPom);
36 assertTrue(testPom.exists());
37
38 // cleanup the target folder
39 File target = new File(thisDir, "target/");
40 FileUtils.deleteDirectory(target);
41 boolean res = target.mkdir();
42 assert res || !res;
43
44 // define the file to be created and the one to be compared with
45 //File act = new File(thisDir, "target/manualLMP.pdf");
46 //File cmp = new File(thisDir, "cmp/manualLMP.pdf");
47 //File act = new File(thisDir, "target/dvi/dviFormat.pdf");
48 //File cmp = new File(thisDir, "cmp/dvi/dviFormat.pdf");
49
50 // run the pdf-goal in the pom
51 // TBD: in other framework: also check lifecycle phase like site and so
52 // TBD: clarify why this does not work
53 InjectionMojo injMojo = (InjectionMojo) lookupMojo("inj", testPom);// this is to update .latexmkrc
54 // assertNotNull(injMojo);
55 // injMojo.execute();// does not work.
56
57 // TBD: bugfix
58 // This is roughly descibed in the changes.xml
59 // The overall aim is to get the test run independent from the productive run.
60 // In the productive run, before executing something like goal 'pdf',
61 // - goal 'inj' is needed
62 // - further actions are taken not tied directly to this plugin
63 // altogether these actions are taken invoking 'mvn validate'.
64 // So, what is missing is a technique to invoke also the other plugins with appropriate goals.
65 // It must be clarified, what lookupMojo(....) really does.
66 // Is it applicable to other plugins also? What does it tie to this latex plugin?
67 // In former versions, it was sufficient that the injections are present
68 // and no one cared that it was not configured by pom4pdf.xml but by pom.xml itself.
69 // But now a difference occurs:
70 // The config cfgDiff affects the created .latexmkrc which is now used to really compile.
71 // In pom.xml this shall not be set so it takes the default 'false',
72 // whereas in pom4pdf.xml it is set so this does not fit:
73 // If .latexmkrc is not reconfigured in test, compilation with latexmk is with chfDiff=false,
74 // whereas diff is done in the java part is and it is performed because chkDiff=true, so crash.
75 //
76 // Seemingly, execute tries to get the version of this plugin to filter the injections.
77 // The critical place is LatexProcessor.processFileInjections invoked by the InjectionMojo
78 // Fails to run getCoordinates(...).
79 // Looks as if the mojo test accesses not the jar file but the incomplete data in the target folder.
80 // So, in fact, the config given by the pom in the base directory is in effect.
81 // To have chkDiff activated, one has to set it there.
82 // Even if execution of injMojo worked, the tests are still not independent.
83 // But even if this worked, the test would not be independent.
84
85 // perform the proper tests
86 PdfMojo testMojo = (PdfMojo) lookupMojo("pdf", testPom);
87 assertNotNull(testMojo);
88 testMojo.execute();
89 // Here, according to pom2pdf.xml, the generated pdf is expected at
90 // ${basedir}/src/test/resources/integration/target/manualLMP.pdf
91 //assert act.exists() && cmp.exists();
92
93 // check that the goal yielded the expected document.
94 // This is no longer needed as that test is done by the plugin itself
95 // and even more generally: bitwise equality not required.
96 //assertTrue(IOUtils.contentEquals(new FileInputStream(cmp), new FileInputStream(act)));
97
98 // cleanup
99 FileUtils.deleteDirectory(target);
100 }
101 }