You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by vs...@apache.org on 2009/05/07 13:23:50 UTC

svn commit: r772617 - in /maven/plugins/trunk/maven-pdf-plugin/src/test: java/org/apache/maven/plugins/pdf/ java/org/apache/maven/plugins/pdf/stubs/ resources/unit/pdf/ resources/unit/pdf/src/site/

Author: vsiveton
Date: Thu May  7 11:23:50 2009
New Revision: 772617

URL: http://svn.apache.org/viewvc?rev=772617&view=rev
Log:
MPDF-1: Ability to use pom properties in pdf.xml

o added a test case

Added:
    maven/plugins/trunk/maven-pdf-plugin/src/test/java/org/apache/maven/plugins/pdf/stubs/
    maven/plugins/trunk/maven-pdf-plugin/src/test/java/org/apache/maven/plugins/pdf/stubs/DefaultMavenProjectStub.java   (with props)
    maven/plugins/trunk/maven-pdf-plugin/src/test/resources/unit/pdf/pom_filtering.xml   (with props)
    maven/plugins/trunk/maven-pdf-plugin/src/test/resources/unit/pdf/src/site/pdf_filtering.xml   (with props)
Modified:
    maven/plugins/trunk/maven-pdf-plugin/src/test/java/org/apache/maven/plugins/pdf/PdfMojoTest.java

Modified: maven/plugins/trunk/maven-pdf-plugin/src/test/java/org/apache/maven/plugins/pdf/PdfMojoTest.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pdf-plugin/src/test/java/org/apache/maven/plugins/pdf/PdfMojoTest.java?rev=772617&r1=772616&r2=772617&view=diff
==============================================================================
--- maven/plugins/trunk/maven-pdf-plugin/src/test/java/org/apache/maven/plugins/pdf/PdfMojoTest.java (original)
+++ maven/plugins/trunk/maven-pdf-plugin/src/test/java/org/apache/maven/plugins/pdf/PdfMojoTest.java Thu May  7 11:23:50 2009
@@ -20,8 +20,11 @@
  */
 
 import org.apache.maven.plugin.testing.AbstractMojoTestCase;
+import org.codehaus.plexus.util.IOUtil;
+import org.codehaus.plexus.util.ReaderFactory;
 
 import java.io.File;
+import java.io.Reader;
 
 /**
  * @author ltheussl
@@ -95,5 +98,44 @@
         assertTrue( "iText: Pdf file has no content!", pdfFile.length() > 0 );
      }
 
+    /**
+     * @throws Exception if any.
+     */
+    public void testPdfFilterMojo() throws Exception
+    {
+        File testPom = new File( getBasedir(), "/target/test-classes/unit/pdf/pom_filtering.xml" );
+        assertTrue( "testPom does not exist!", testPom.exists() );
+
+        PdfMojo mojo = (PdfMojo) lookupMojo( "pdf", testPom );
+        assertNotNull( "pdf mojo not found!", mojo );
+
+        File pdfFile = new File( getBasedir(), "/target/test-output/pdf/maven-pdf-plugin-doc-1.0-SNAPSHOT.pdf" );
+        if ( pdfFile.exists() )
+        {
+            pdfFile.delete();
+        }
+
+        mojo.execute();
+
+        assertTrue( "FO: Pdf file not created!", pdfFile.exists() );
+        assertTrue( "FO: Pdf file has no content!", pdfFile.length() > 0 );
+
+        File foFile = new File( getBasedir(), "/target/test-output/pdf/maven-pdf-plugin-doc-1.0-SNAPSHOT.fo" );
+        assertTrue( "FO: Fo file not created!", foFile.exists() );
+        assertTrue( "FO: Fo file has no content!", foFile.length() > 0 );
+
+        Reader reader = null;
+        String foContent;
+        try
+        {
+            reader = ReaderFactory.newXmlReader( foFile );
+            foContent = IOUtil.toString( reader );
+        }
+        finally
+        {
+            IOUtil.close( reader );
+        }
+        assertTrue( foContent.indexOf( ">Test filtering<" ) > 0 );
+    }
 
 }
\ No newline at end of file

Added: maven/plugins/trunk/maven-pdf-plugin/src/test/java/org/apache/maven/plugins/pdf/stubs/DefaultMavenProjectStub.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pdf-plugin/src/test/java/org/apache/maven/plugins/pdf/stubs/DefaultMavenProjectStub.java?rev=772617&view=auto
==============================================================================
--- maven/plugins/trunk/maven-pdf-plugin/src/test/java/org/apache/maven/plugins/pdf/stubs/DefaultMavenProjectStub.java (added)
+++ maven/plugins/trunk/maven-pdf-plugin/src/test/java/org/apache/maven/plugins/pdf/stubs/DefaultMavenProjectStub.java Thu May  7 11:23:50 2009
@@ -0,0 +1,67 @@
+package org.apache.maven.plugins.pdf.stubs;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.File;
+import java.io.FileReader;
+
+import org.apache.maven.model.Model;
+import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
+import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
+
+/**
+ * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
+ * @version $Id$
+ */
+public class DefaultMavenProjectStub
+    extends MavenProjectStub
+{
+    public DefaultMavenProjectStub()
+    {
+        MavenXpp3Reader pomReader = new MavenXpp3Reader();
+        try
+        {
+            Model model = pomReader.read( new FileReader( new File( getBasedir() + "/pom_filtering.xml" ) ) );
+            setModel( model );
+        }
+        catch ( Exception e )
+        {
+            throw new RuntimeException( e );
+        }
+    }
+
+    /** {@inheritDoc} */
+    public String getName()
+    {
+        return getModel().getName();
+    }
+
+    /** {@inheritDoc} */
+    public String getVersion()
+    {
+        return getModel().getVersion();
+    }
+
+    /** {@inheritDoc} */
+    public File getBasedir()
+    {
+        return new File( super.getBasedir() + "/target/test-classes/unit/pdf/" );
+    }
+}

Propchange: maven/plugins/trunk/maven-pdf-plugin/src/test/java/org/apache/maven/plugins/pdf/stubs/DefaultMavenProjectStub.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-pdf-plugin/src/test/java/org/apache/maven/plugins/pdf/stubs/DefaultMavenProjectStub.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/plugins/trunk/maven-pdf-plugin/src/test/resources/unit/pdf/pom_filtering.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pdf-plugin/src/test/resources/unit/pdf/pom_filtering.xml?rev=772617&view=auto
==============================================================================
--- maven/plugins/trunk/maven-pdf-plugin/src/test/resources/unit/pdf/pom_filtering.xml (added)
+++ maven/plugins/trunk/maven-pdf-plugin/src/test/resources/unit/pdf/pom_filtering.xml Thu May  7 11:23:50 2009
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing,
+  software distributed under the License is distributed on an
+  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  KIND, either express or implied.  See the License for the
+  specific language governing permissions and limitations
+  under the License.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+  <version>1.0-SNAPSHOT</version>
+  <name>Test filtering</name>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-pdf-plugin</artifactId>
+        <configuration>
+          <project implementation="org.apache.maven.plugins.pdf.stubs.DefaultMavenProjectStub"/>
+          <docDescriptor>${basedir}/target/test-classes/unit/pdf/src/site/pdf_filtering.xml</docDescriptor>
+          <siteDirectory>${basedir}/target/test-classes/unit/pdf/src/site/</siteDirectory>
+          <outputDirectory>${basedir}/target/test-output/pdf</outputDirectory>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>

Propchange: maven/plugins/trunk/maven-pdf-plugin/src/test/resources/unit/pdf/pom_filtering.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-pdf-plugin/src/test/resources/unit/pdf/pom_filtering.xml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/plugins/trunk/maven-pdf-plugin/src/test/resources/unit/pdf/src/site/pdf_filtering.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pdf-plugin/src/test/resources/unit/pdf/src/site/pdf_filtering.xml?rev=772617&view=auto
==============================================================================
--- maven/plugins/trunk/maven-pdf-plugin/src/test/resources/unit/pdf/src/site/pdf_filtering.xml (added)
+++ maven/plugins/trunk/maven-pdf-plugin/src/test/resources/unit/pdf/src/site/pdf_filtering.xml Thu May  7 11:23:50 2009
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+ -->
+
+<document outputName="maven-pdf-plugin-doc-${project.version}">
+
+  <meta>
+    <title>${project.name}</title>
+    <author>The Apache Maven Project</author>
+  </meta>
+
+  <toc name="Table of Contents">
+    <item name="Introduction" ref="index.apt"/>
+    <item name="Usage" ref="usage.apt"/>
+    <item name="Limitations" ref="limitations.apt"/>
+    <item name="Links" ref="ref/links.apt"/>
+    <item name="FAQ" ref="faq.fml"/>
+  </toc>
+
+</document>

Propchange: maven/plugins/trunk/maven-pdf-plugin/src/test/resources/unit/pdf/src/site/pdf_filtering.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-pdf-plugin/src/test/resources/unit/pdf/src/site/pdf_filtering.xml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision