You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sn...@apache.org on 2006/09/23 15:51:18 UTC

svn commit: r449242 - in /maven/plugins/trunk/maven-ear-plugin: ./ src/test/java/org/apache/maven/plugin/ear/ src/test/resources/m2repo/ src/test/resources/m2repo/eartest/ src/test/resources/m2repo/eartest/ejb-sample-one/ src/test/resources/m2repo/eart...

Author: snicoll
Date: Sat Sep 23 06:51:17 2006
New Revision: 449242

URL: http://svn.apache.org/viewvc?view=rev&rev=449242
Log:
Adding test cases with the maven embedder.

Added:
    maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/AbstractEarPluginTestCase.java
    maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/EarMojoTest.java
    maven/plugins/trunk/maven-ear-plugin/src/test/resources/m2repo/
    maven/plugins/trunk/maven-ear-plugin/src/test/resources/m2repo/eartest/
    maven/plugins/trunk/maven-ear-plugin/src/test/resources/m2repo/eartest/ejb-sample-one/
    maven/plugins/trunk/maven-ear-plugin/src/test/resources/m2repo/eartest/ejb-sample-one/1.0/
    maven/plugins/trunk/maven-ear-plugin/src/test/resources/m2repo/eartest/ejb-sample-one/1.0/ejb-sample-one-1.0.jar
    maven/plugins/trunk/maven-ear-plugin/src/test/resources/m2repo/eartest/ejb-sample-one/1.0/ejb-sample-one-1.0.pom
    maven/plugins/trunk/maven-ear-plugin/src/test/resources/m2repo/eartest/ejb-sample-two/
    maven/plugins/trunk/maven-ear-plugin/src/test/resources/m2repo/eartest/ejb-sample-two/1.0/
    maven/plugins/trunk/maven-ear-plugin/src/test/resources/m2repo/eartest/ejb-sample-two/1.0/ejb-sample-two-1.0.jar
    maven/plugins/trunk/maven-ear-plugin/src/test/resources/m2repo/eartest/ejb-sample-two/1.0/ejb-sample-two-1.0.pom
    maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/
    maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-01/
    maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-01/pom.xml
    maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-02/
    maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-02/pom.xml
Modified:
    maven/plugins/trunk/maven-ear-plugin/pom.xml

Modified: maven/plugins/trunk/maven-ear-plugin/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/pom.xml?view=diff&rev=449242&r1=449241&r2=449242
==============================================================================
--- maven/plugins/trunk/maven-ear-plugin/pom.xml (original)
+++ maven/plugins/trunk/maven-ear-plugin/pom.xml Sat Sep 23 06:51:17 2006
@@ -17,30 +17,62 @@
     <url>http://jira.codehaus.org/browse/MEAR</url>
   </issueManagement>
   <dependencies>
-    <dependency>
+      <dependency>
       <groupId>org.apache.maven</groupId>
       <artifactId>maven-project</artifactId>
       <version>2.0.4</version>
     </dependency>
     <dependency>
       <groupId>org.apache.maven</groupId>
+      <artifactId>maven-settings</artifactId>
+      <version>2.0.4</version>      
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
       <artifactId>maven-plugin-api</artifactId>
       <version>2.0.4</version>
     </dependency>
     <dependency>
       <groupId>org.apache.maven</groupId>
+      <artifactId>maven-model</artifactId>
+      <version>2.0.4</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-artifact-manager</artifactId>
+      <version>2.0.4</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-embedder</artifactId>
+      <version>2.0.4</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-artifact</artifactId>
+      <version>2.0.4</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
       <artifactId>maven-archiver</artifactId>
       <version>2.1</version>
     </dependency>
     <dependency>
       <groupId>org.codehaus.plexus</groupId>
       <artifactId>plexus-utils</artifactId>
-      <version>1.1</version>
+      <version>1.0.5</version>
     </dependency>
     <dependency>
       <groupId>org.codehaus.plexus</groupId>
-      <artifactId>plexus-archiver</artifactId>
-      <version>1.0-alpha-6</version>
+      <artifactId>plexus-interactivity-jline</artifactId>
+      <version>1.0-alpha-5</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven.shared</groupId>
+      <artifactId>maven-plugin-testing-harness</artifactId>
+      <version>1.0-beta-2-SNAPSHOT</version>
+      <scope>test</scope>
     </dependency>
   </dependencies>
 </project>

Added: maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/AbstractEarPluginTestCase.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/AbstractEarPluginTestCase.java?view=auto&rev=449242
==============================================================================
--- maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/AbstractEarPluginTestCase.java (added)
+++ maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/AbstractEarPluginTestCase.java Sat Sep 23 06:51:17 2006
@@ -0,0 +1,179 @@
+package org.apache.maven.plugin.ear;
+
+import org.apache.maven.cli.ConsoleDownloadMonitor;
+import org.apache.maven.embedder.MavenEmbedder;
+import org.apache.maven.embedder.MavenEmbedderConsoleLogger;
+import org.apache.maven.embedder.PlexusLoggerAdapter;
+import org.apache.maven.monitor.event.DefaultEventMonitor;
+import org.apache.maven.monitor.event.EventMonitor;
+import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.PlexusTestCase;
+
+import java.io.File;
+import java.io.FilenameFilter;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Properties;
+
+/**
+ * @author Stephane Nicoll <st...@bsb.com>
+ * @author $Author: sni $ (last edit)
+ * @version $Revision: 1.5 $
+ */
+public abstract class AbstractEarPluginTestCase
+    extends PlexusTestCase
+{
+
+    protected final String FINAL_NAME_PREFIX = "maven-ear-plugin-test-";
+
+    protected final String FINAL_NAME_SUFFIX = "-99.0";
+
+    /**
+     * The embedder.
+     */
+    protected MavenEmbedder maven;
+
+    /**
+     * Test repository directory.
+     */
+    protected File localRepositoryDir = getTestFile( "target/test-classes/m2repo" );
+
+    /**
+     * @see org.codehaus.plexus.PlexusTestCase#setUp()
+     */
+    protected void setUp()
+        throws Exception
+    {
+        this.maven = new MavenEmbedder();
+        this.maven.setClassLoader( Thread.currentThread().getContextClassLoader() );
+        this.maven.setLogger( new MavenEmbedderConsoleLogger() );
+        this.maven.setLocalRepositoryDirectory( localRepositoryDir );
+        this.maven.setOffline( true );
+        this.maven.start();
+
+        super.setUp();
+    }
+
+    /**
+     * @see org.codehaus.plexus.PlexusTestCase#tearDown()
+     */
+    protected void tearDown()
+        throws Exception
+    {
+        maven.stop();
+        super.tearDown();
+    }
+
+    /**
+     * Execute the EAR plugin for the specified project.
+     *
+     * @param projectName the name of the project
+     * @param properties  extra properties to be used by the embedder
+     * @return the base directory of the project
+     * @throws Exception if an error occured
+     */
+    protected File executeMojo( final String projectName, final Properties properties )
+        throws Exception
+    {
+        File basedir = getTestFile( "target/test-classes/projects/" + projectName );
+
+        MavenProject project = maven.readProjectWithDependencies( new File( basedir, "pom.xml" ) );
+
+        EventMonitor eventMonitor =
+            new DefaultEventMonitor( new PlexusLoggerAdapter( new MavenEmbedderConsoleLogger() ) );
+
+        this.maven.execute( project, Arrays.asList( new String[]{"org.apache.maven.plugins:maven-clean-plugin:clean",
+            "org.apache.maven.plugins:maven-ear-plugin:generate-application-xml",
+            "org.apache.maven.plugins:maven-ear-plugin:ear"} ), eventMonitor, new ConsoleDownloadMonitor(), properties,
+                                                                basedir );
+
+        assertEarArchive( basedir, projectName );
+        assertEarDirectory( basedir, projectName );
+
+        return basedir;
+    }
+
+    protected void assertEarArchive( final File baseDir, final String projectName )
+    {
+        assertTrue( "EAR archive does not exist", getEarArchive( baseDir, projectName ).exists() );
+    }
+
+    protected void assertEarDirectory( final File baseDir, final String projectName )
+    {
+        assertTrue( "EAR archive directory does not exist", getEarDirectory( baseDir, projectName ).exists() );
+    }
+
+    protected File getTargetDirectory( final File basedir )
+    {
+        return new File( basedir, "target" );
+    }
+
+    protected File getEarArchive( final File baseDir, final String projectName )
+    {
+        return new File( getTargetDirectory( baseDir ), buildFinalName( projectName ) + ".ear" );
+    }
+
+    protected File getEarDirectory( final File baseDir, final String projectName )
+    {
+        return new File( getTargetDirectory( baseDir ), buildFinalName( projectName ) );
+    }
+
+    protected String buildFinalName( final String projectName )
+    {
+        return FINAL_NAME_PREFIX + projectName + FINAL_NAME_SUFFIX;
+    }
+
+    protected void assertArchiveContent( final File baseDir, final String projectName, final String[] artifactNames )
+    {
+        File dir = getEarDirectory( baseDir, projectName );
+        final List actualFiles = buildFiles( dir );
+        assertEquals( "Artifacts mismatch " + actualFiles, artifactNames.length, actualFiles.size() );
+        for ( int i = 0; i < artifactNames.length; i++ )
+        {
+            String artifactName = artifactNames[i];
+            File expectedFile = new File(dir, artifactName);
+            assertTrue("Artifact["+artifactName+"] not found in ear archive", actualFiles.contains( expectedFile));            
+        }
+    }
+
+    protected List buildFiles( final File baseDir )
+    {
+        final List result = new ArrayList();
+        addFiles( baseDir, result );
+
+        return result;
+    }
+
+    private void addFiles( final File directory, final List files )
+    {
+        File[] result = directory.listFiles( new FilenameFilter()
+        {
+            public boolean accept( File dir, String name )
+            {
+                if ( name.equals( "META-INF" ) )
+                {
+                    return false;
+                }
+                else
+                {
+                    return true;
+                }
+            }
+
+        } );
+
+        for ( int i = 0; i < result.length; i++ )
+        {
+            File file = result[i];
+            if ( file.isFile() )
+            {
+                files.add( file );
+            }
+            else
+            {
+                addFiles( file, files );
+            }
+        }
+    }
+}

Added: maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/EarMojoTest.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/EarMojoTest.java?view=auto&rev=449242
==============================================================================
--- maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/EarMojoTest.java (added)
+++ maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/EarMojoTest.java Sat Sep 23 06:51:17 2006
@@ -0,0 +1,44 @@
+package org.apache.maven.plugin.ear;
+
+import org.apache.maven.plugin.testing.AbstractMojoTestCase;
+import org.apache.maven.project.MavenProject;
+
+import java.io.File;
+import java.util.Properties;
+
+/**
+ * @author Stephane Nicoll <st...@bsb.com>
+ * @author $Author: sni $ (last edit)
+ * @version $Revision: 1.5 $
+ */
+public class EarMojoTest extends AbstractEarPluginTestCase
+{
+
+    /**
+     * Simple project with an EJB artifact
+     */
+    public void testProject01()
+        throws Exception
+    {
+         doTestProject( "project-01", new String[]{"ejb-sample-one-1.0.jar"});
+    }
+
+    public void testProject02()
+        throws Exception
+    {
+        // See http://jira.codehaus.org/browse/MNG-2571 - Uncomment to reproduce 
+        //doTestProject( "project-02", new String[]{"APP-INF/lib/ejb-sample-one-1.0.jar, ejb-sample-two.jar"});
+    }
+
+    protected void doTestProject(final String projectName, final String[] expectedArtifacts)
+        throws Exception
+    {
+        final File baseDir = executeMojo(projectName, new Properties());
+
+        assertArchiveContent(baseDir, projectName,expectedArtifacts);
+
+    }
+
+
+
+}

Added: maven/plugins/trunk/maven-ear-plugin/src/test/resources/m2repo/eartest/ejb-sample-one/1.0/ejb-sample-one-1.0.jar
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/test/resources/m2repo/eartest/ejb-sample-one/1.0/ejb-sample-one-1.0.jar?view=auto&rev=449242
==============================================================================
--- maven/plugins/trunk/maven-ear-plugin/src/test/resources/m2repo/eartest/ejb-sample-one/1.0/ejb-sample-one-1.0.jar (added)
+++ maven/plugins/trunk/maven-ear-plugin/src/test/resources/m2repo/eartest/ejb-sample-one/1.0/ejb-sample-one-1.0.jar Sat Sep 23 06:51:17 2006
@@ -0,0 +1 @@
+-testfile-not a valid jar-
\ No newline at end of file

Added: maven/plugins/trunk/maven-ear-plugin/src/test/resources/m2repo/eartest/ejb-sample-one/1.0/ejb-sample-one-1.0.pom
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/test/resources/m2repo/eartest/ejb-sample-one/1.0/ejb-sample-one-1.0.pom?view=auto&rev=449242
==============================================================================
--- maven/plugins/trunk/maven-ear-plugin/src/test/resources/m2repo/eartest/ejb-sample-one/1.0/ejb-sample-one-1.0.pom (added)
+++ maven/plugins/trunk/maven-ear-plugin/src/test/resources/m2repo/eartest/ejb-sample-one/1.0/ejb-sample-one-1.0.pom Sat Sep 23 06:51:17 2006
@@ -0,0 +1,10 @@
+<project>
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>eartest</groupId>
+  <artifactId>ejb-sample-one</artifactId>
+  <packaging>ejb</packaging>
+  <version>1.0</version>
+  <distributionManagement>
+    <status>verified</status>
+  </distributionManagement>
+</project>

Added: maven/plugins/trunk/maven-ear-plugin/src/test/resources/m2repo/eartest/ejb-sample-two/1.0/ejb-sample-two-1.0.jar
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/test/resources/m2repo/eartest/ejb-sample-two/1.0/ejb-sample-two-1.0.jar?view=auto&rev=449242
==============================================================================
--- maven/plugins/trunk/maven-ear-plugin/src/test/resources/m2repo/eartest/ejb-sample-two/1.0/ejb-sample-two-1.0.jar (added)
+++ maven/plugins/trunk/maven-ear-plugin/src/test/resources/m2repo/eartest/ejb-sample-two/1.0/ejb-sample-two-1.0.jar Sat Sep 23 06:51:17 2006
@@ -0,0 +1 @@
+-testfile-not a valid jar-
\ No newline at end of file

Added: maven/plugins/trunk/maven-ear-plugin/src/test/resources/m2repo/eartest/ejb-sample-two/1.0/ejb-sample-two-1.0.pom
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/test/resources/m2repo/eartest/ejb-sample-two/1.0/ejb-sample-two-1.0.pom?view=auto&rev=449242
==============================================================================
--- maven/plugins/trunk/maven-ear-plugin/src/test/resources/m2repo/eartest/ejb-sample-two/1.0/ejb-sample-two-1.0.pom (added)
+++ maven/plugins/trunk/maven-ear-plugin/src/test/resources/m2repo/eartest/ejb-sample-two/1.0/ejb-sample-two-1.0.pom Sat Sep 23 06:51:17 2006
@@ -0,0 +1,10 @@
+<project>
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>eartest</groupId>
+  <artifactId>ejb-sample-two</artifactId>
+  <packaging>ejb</packaging>
+  <version>1.0</version>
+  <distributionManagement>
+    <status>verified</status>
+  </distributionManagement>
+</project>

Added: maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-01/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-01/pom.xml?view=auto&rev=449242
==============================================================================
--- maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-01/pom.xml (added)
+++ maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-01/pom.xml Sat Sep 23 06:51:17 2006
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>ear</groupId>
+  <artifactId>maven-ear-plugin-test-project-01</artifactId>
+  <version>99.0</version>
+  <name>Maven</name>
+  <packaging>ear</packaging>
+  <dependencies>
+    <dependency>
+      <groupId>eartest</groupId>
+      <artifactId>ejb-sample-one</artifactId>
+      <version>1.0</version>
+      <type>ejb</type>
+    </dependency>
+  </dependencies>
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-ear-plugin</artifactId>
+        <configuration>
+          <displayName>Sample Ear Application</displayName>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>

Added: maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-02/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-02/pom.xml?view=auto&rev=449242
==============================================================================
--- maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-02/pom.xml (added)
+++ maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-02/pom.xml Sat Sep 23 06:51:17 2006
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>ear</groupId>
+  <artifactId>maven-ear-plugin-test-project-02</artifactId>
+  <version>99.0</version>
+  <name>Maven</name>
+  <packaging>ear</packaging>
+  <dependencies>
+    <dependency>
+      <groupId>eartest</groupId>
+      <artifactId>ejb-sample-one</artifactId>
+      <version>1.0</version>
+      <type>ejb</type>
+    </dependency>
+    <dependency>
+      <groupId>eartest</groupId>
+      <artifactId>ejb-sample-two</artifactId>
+      <version>1.0</version>
+      <type>ejb</type>
+    </dependency>
+  </dependencies>
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-ear-plugin</artifactId>
+        <configuration>
+          <displayName>Sample Ear Application</displayName>
+
+          <modules>
+            <!--
+            <ejbModule>
+              <groupId>eartest</groupId>
+              <artifactId>ejb-sample-one</artifactId>
+              <bundleDir>APP-INF/lib</bundleDir>
+            </ejbModule> -->
+
+            <ejbModule>
+              <groupId>eartest</groupId>
+              <artifactId>ejb-sample-two</artifactId>
+              <bundleFileName>ejb-sample-two.jar</bundleFileName>
+            </ejbModule>
+          </modules>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>