You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by jd...@apache.org on 2006/11/14 17:17:09 UTC

svn commit: r474849 - in /maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse: EclipsePluginUnitTest.java writers/EclipseClasspathWriterUnitTest.java writers/testutils/ writers/testutils/TestEclipseWriterConfig.java

Author: jdcasey
Date: Tue Nov 14 08:17:08 2006
New Revision: 474849

URL: http://svn.apache.org/viewvc?view=rev&rev=474849
Log:
Forgot to add the new unit tests I wrote.

Added:
    maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/EclipsePluginUnitTest.java   (with props)
    maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/writers/EclipseClasspathWriterUnitTest.java   (with props)
    maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/writers/testutils/
    maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/writers/testutils/TestEclipseWriterConfig.java   (with props)

Added: maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/EclipsePluginUnitTest.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/EclipsePluginUnitTest.java?view=auto&rev=474849
==============================================================================
--- maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/EclipsePluginUnitTest.java (added)
+++ maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/EclipsePluginUnitTest.java Tue Nov 14 08:17:08 2006
@@ -0,0 +1,241 @@
+package org.apache.maven.plugin.eclipse;
+
+import org.apache.maven.model.Build;
+import org.apache.maven.model.Model;
+import org.apache.maven.model.Resource;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.shared.tools.easymock.TestFileManager;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.LinkedHashSet;
+import java.util.Set;
+
+import junit.framework.TestCase;
+
+public class EclipsePluginUnitTest
+    extends TestCase
+{
+
+    private TestFileManager fileManager = new TestFileManager( "EclipsePlugin.unitTest.", "" );
+
+    public void tearDown()
+        throws IOException
+    {
+        fileManager.cleanUp();
+    }
+
+    public void testBuildDirectoryList_ShouldUseTestOutputDirFromProjectWhenBuildOutputDirIsStandard()
+        throws MojoExecutionException
+    {
+        File basedir = fileManager.createTempDir();
+
+        Build build = new Build();
+
+        Resource resource = new Resource();
+
+        String resDir = "src/main/resources";
+        new File( basedir, resDir ).mkdirs();
+
+        String resOutput = "target/main-output";
+
+        resource.setDirectory( resDir );
+
+        build.addTestResource( resource );
+        build.setOutputDirectory( "target/classes" );
+        build.setTestOutputDirectory( resOutput );
+
+        Model model = new Model();
+        model.setBuild( build );
+
+        MavenProject project = new MavenProject( model );
+
+        File pom = new File( basedir, "pom.xml" );
+        project.setFile( pom );
+
+        EclipseSourceDir[] result = new EclipsePlugin().buildDirectoryList( project, basedir,
+                                                                            new File( "target/classes" ) );
+
+        assertEquals( "should have added 1 resource.", 1, result.length );
+
+        String path = result[0].getOutput();
+
+        assertTrue( "output directory should end with: " + resOutput, path.endsWith( resOutput ) );
+    }
+
+    public void testExtractResourceDirs_ShouldUseResourceOutput()
+        throws MojoExecutionException
+    {
+        File basedir = fileManager.createTempDir();
+
+        Build build = new Build();
+
+        Resource resource = new Resource();
+
+        String resDir = "src/main/resources";
+        new File( basedir, resDir ).mkdirs();
+
+        // assumes base of target/classes.
+        String resOutput = "main-output";
+
+        resource.setDirectory( resDir );
+        resource.setTargetPath( resOutput );
+        build.addResource( resource );
+
+        Model model = new Model();
+        model.setBuild( build );
+
+        MavenProject project = new MavenProject( model );
+
+        Set result = new LinkedHashSet();
+
+        EclipsePlugin plugin = new EclipsePlugin();
+
+        plugin.extractResourceDirs( result, project.getBuild().getResources(), project, basedir, basedir, false,
+                                    "target/classes" );
+
+        Iterator resultIter = result.iterator();
+
+        assertEquals( "too many resource entries added.", 1, result.size() );
+
+        String path = ( (EclipseSourceDir) resultIter.next() ).getOutput();
+        
+        String prefix = "target/classes/";
+
+        assertTrue( "output directory should end with: " + prefix + resOutput + "\nWas: " + path, path
+            .endsWith( prefix + resOutput ) );
+    }
+
+    public void testExtractResourceDirs_ShouldUseSpecifiedOutputDirectory()
+        throws MojoExecutionException
+    {
+        File basedir = fileManager.createTempDir();
+
+        Build build = new Build();
+
+        Resource resource = new Resource();
+
+        String resDir = "src/main/resources";
+        new File( basedir, resDir ).mkdirs();
+
+        String resOutput = "target/main-output";
+
+        resource.setDirectory( resDir );
+
+        build.addTestResource( resource );
+
+        Model model = new Model();
+        model.setBuild( build );
+
+        MavenProject project = new MavenProject( model );
+
+        Set result = new LinkedHashSet();
+
+        EclipsePlugin plugin = new EclipsePlugin();
+
+        plugin.extractResourceDirs( result, project.getBuild().getTestResources(), project, basedir, basedir, false,
+                                    resOutput );
+
+        Iterator resultIter = result.iterator();
+
+        assertEquals( "should have added 1 resource.", 1, result.size() );
+
+        String path = ( (EclipseSourceDir) resultIter.next() ).getOutput();
+
+        assertTrue( "output directory should end with: " + resOutput, path.endsWith( resOutput ) );
+    }
+
+    public void testExtractResourceDirs_ShouldIncludeMainAndTestResources()
+        throws MojoExecutionException
+    {
+        File basedir = fileManager.createTempDir();
+
+        runResourceExtractionTest( basedir, basedir );
+    }
+
+    public void testExtractResourceDirs_ShouldIncludeMainAndTestResourcesWhenBaseDirsDiffer()
+        throws MojoExecutionException
+    {
+        File basedir = fileManager.createTempDir();
+        File projectBasedir = fileManager.createTempDir();
+
+        runResourceExtractionTest( basedir, projectBasedir );
+    }
+
+    private void runResourceExtractionTest( File basedir, File workspaceProjectBasedir )
+        throws MojoExecutionException
+    {
+        Build build = new Build();
+
+        Resource resource = new Resource();
+
+        String resDir = "src/main/resources";
+        new File( basedir, resDir ).mkdirs();
+
+        resource.setDirectory( resDir );
+        build.addResource( resource );
+
+        Resource testResource = new Resource();
+
+        String testResDir = "src/test/resources";
+        new File( basedir, testResDir ).mkdirs();
+
+        testResource.setDirectory( testResDir );
+        build.addTestResource( testResource );
+
+        Model model = new Model();
+        model.setBuild( build );
+
+        MavenProject project = new MavenProject( model );
+
+        Set result = new LinkedHashSet();
+
+        EclipsePlugin plugin = new EclipsePlugin();
+
+        plugin.extractResourceDirs( result, project.getBuild().getResources(), project, basedir,
+                                    workspaceProjectBasedir, false, "target/classes" );
+
+        Iterator resultIter = result.iterator();
+
+        assertEquals( "too many resource entries added.", 1, result.size() );
+
+        String path = ( (EclipseSourceDir) resultIter.next() ).getPath();
+
+        if ( basedir.equals( workspaceProjectBasedir ) )
+        {
+            assertTrue( "resource dir path: " + path + " does not end with: " + resDir, path.endsWith( resDir ) );
+        }
+        else
+        {
+            resDir = resDir.replace( '\\', '/' ).replace( '/', '-' );
+
+            assertTrue( "resource dir path: " + path + " does not end with: " + resDir, path.endsWith( resDir ) );
+        }
+
+        plugin.extractResourceDirs( result, project.getBuild().getTestResources(), project, basedir,
+                                    workspaceProjectBasedir, false, "target/test-classes" );
+
+        resultIter = result.iterator();
+        resultIter.next();
+
+        assertEquals( "too many test-resource entries added.", 2, result.size() );
+
+        path = ( (EclipseSourceDir) resultIter.next() ).getPath();
+
+        if ( basedir.equals( workspaceProjectBasedir ) )
+        {
+            assertTrue( "test-resource dir path: " + path + " does not end with: " + testResDir, path
+                .endsWith( testResDir ) );
+        }
+        else
+        {
+            testResDir = testResDir.replace( '\\', '/' ).replace( '/', '-' );
+
+            assertTrue( "test-resource dir path: " + path + " does not end with: " + testResDir, path
+                .endsWith( testResDir ) );
+        }
+
+    }
+}

Propchange: maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/EclipsePluginUnitTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/EclipsePluginUnitTest.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/writers/EclipseClasspathWriterUnitTest.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/writers/EclipseClasspathWriterUnitTest.java?view=auto&rev=474849
==============================================================================
--- maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/writers/EclipseClasspathWriterUnitTest.java (added)
+++ maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/writers/EclipseClasspathWriterUnitTest.java Tue Nov 14 08:17:08 2006
@@ -0,0 +1,95 @@
+package org.apache.maven.plugin.eclipse.writers;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.eclipse.EclipseSourceDir;
+import org.apache.maven.plugin.eclipse.writers.testutils.TestEclipseWriterConfig;
+import org.apache.maven.plugin.logging.Log;
+import org.apache.maven.plugin.logging.SystemStreamLog;
+import org.apache.maven.shared.tools.easymock.TestFileManager;
+import org.jdom.Document;
+import org.jdom.JDOMException;
+import org.jdom.Text;
+import org.jdom.input.SAXBuilder;
+import org.jdom.xpath.XPath;
+
+import java.io.File;
+import java.io.IOException;
+
+import junit.framework.TestCase;
+
+public class EclipseClasspathWriterUnitTest
+    extends TestCase
+{
+
+    private TestFileManager fileManager = new TestFileManager( "EclipseClasspathWriter.unitTest.", "" );
+
+    protected void tearDown()
+        throws IOException
+    {
+        fileManager.cleanUp();
+    }
+
+    public void testWrite_ShouldMaskOutputDirsNestedWithinAnExistingOutputDir()
+        throws MojoExecutionException, JDOMException, IOException
+    {
+        TestEclipseWriterConfig config = new TestEclipseWriterConfig();
+
+        File basedir = fileManager.createTempDir();
+
+        config.setProjectBaseDir( basedir );
+        config.setEclipseProjectDirectory( basedir );
+
+        String baseOutputDir = "target/classes";
+        String maskedOutputDir = "target/classes/main-resources";
+
+        File buildOutputDir = new File( basedir, baseOutputDir );
+        buildOutputDir.mkdirs();
+
+        config.setBuildOutputDirectory( buildOutputDir );
+
+        new File( basedir, maskedOutputDir ).mkdirs();
+
+        EclipseSourceDir dir = new EclipseSourceDir( "src/main/resources", "target/classes", true, false, null, null,
+                                                     false );
+        EclipseSourceDir testDir = new EclipseSourceDir( "src/test/resources", "target/classes/test-resources", true,
+                                                         true, null, null, false );
+
+        EclipseSourceDir[] dirs = { dir, testDir };
+
+        config.setSourceDirs( dirs );
+        
+        config.setEclipseProjectName( "test-project" );
+
+        TestLog log = new TestLog();
+
+        EclipseClasspathWriter classpathWriter = new EclipseClasspathWriter();
+        classpathWriter.init( log, config );
+        classpathWriter.write();
+        
+        SAXBuilder builder = new SAXBuilder( false );
+
+        Document doc = builder.build( new File( basedir, ".classpath" ) );
+
+        XPath resourcePath = XPath.newInstance( "//classpathentry[@path='src/main/resources']" );
+        
+        assertTrue( "resources classpath entry not found.", resourcePath.selectSingleNode( doc ) != null );
+        
+        XPath testResourcePath = XPath.newInstance( "//classpathentry[@path='src/test/resources']" );
+        
+        assertTrue( "test resources (minus custom output dir) classpath entry not found.", testResourcePath.selectSingleNode( doc ) != null );
+        
+        XPath stdOutputPath = XPath.newInstance( "//classpathentry[@kind='output' && @path='target/classes']" );
+        
+        assertTrue( "standard output classpath entry not found.", stdOutputPath.selectSingleNode( doc ) != null );
+
+    }
+    
+    private static final class TestLog extends SystemStreamLog
+    {
+        public boolean isDebugEnabled()
+        {
+            return true;
+        }
+    }
+
+}

Propchange: maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/writers/EclipseClasspathWriterUnitTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/writers/EclipseClasspathWriterUnitTest.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/writers/testutils/TestEclipseWriterConfig.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/writers/testutils/TestEclipseWriterConfig.java?view=auto&rev=474849
==============================================================================
--- maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/writers/testutils/TestEclipseWriterConfig.java (added)
+++ maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/writers/testutils/TestEclipseWriterConfig.java Tue Nov 14 08:17:08 2006
@@ -0,0 +1,74 @@
+package org.apache.maven.plugin.eclipse.writers.testutils;
+
+import org.apache.maven.plugin.eclipse.EclipseSourceDir;
+import org.apache.maven.plugin.eclipse.writers.EclipseWriterConfig;
+import org.apache.maven.plugin.ide.IdeDependency;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class TestEclipseWriterConfig
+    extends EclipseWriterConfig
+{
+
+    public List getBuildCommands()
+    {
+        List result = super.getBuildCommands();
+        
+        if ( result == null )
+        {
+            result = new ArrayList();
+        }
+        
+        return result;
+    }
+
+    public List getClasspathContainers()
+    {
+        List result = super.getClasspathContainers();
+        
+        if ( result == null )
+        {
+            result = new ArrayList();
+        }
+        
+        return result;
+    }
+
+    public IdeDependency[] getDeps()
+    {
+        IdeDependency[] deps = super.getDeps();
+        
+        if ( deps == null )
+        {
+            deps = new IdeDependency[0];
+        }
+        
+        return deps;
+    }
+
+    public List getProjectnatures()
+    {
+        List result = super.getProjectnatures();
+        
+        if ( result == null )
+        {
+            result = new ArrayList();
+        }
+        
+        return result;
+    }
+
+    public EclipseSourceDir[] getSourceDirs()
+    {
+        EclipseSourceDir[] dirs = super.getSourceDirs();
+        
+        if ( dirs == null )
+        {
+            dirs = new EclipseSourceDir[0];
+        }
+        
+        return dirs;
+    }
+
+}

Propchange: maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/writers/testutils/TestEclipseWriterConfig.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/writers/testutils/TestEclipseWriterConfig.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"