Author: epunzalan
Date: Tue Mar 28 18:22:17 2006
New Revision: 389656

URL: http://svn.apache.org/viewcvs?rev=389656&view=rev
Log:
First try on the plugin test harness

Added:
    
maven/plugins/trunk/maven-idea-plugin/src/test/java/org/apache/maven/plugin/idea/IdeaProjectTest.java
    
maven/plugins/trunk/maven-idea-plugin/src/test/java/org/apache/maven/plugin/idea/stubs/
    
maven/plugins/trunk/maven-idea-plugin/src/test/java/org/apache/maven/plugin/idea/stubs/ArtifactStub.java
    
maven/plugins/trunk/maven-idea-plugin/src/test/java/org/apache/maven/plugin/idea/stubs/LocalRepositoryStub.java
    
maven/plugins/trunk/maven-idea-plugin/src/test/java/org/apache/maven/plugin/idea/stubs/SimpleMavenProjectStub.java
    maven/plugins/trunk/maven-idea-plugin/src/test/plugin-configs/
    
maven/plugins/trunk/maven-idea-plugin/src/test/plugin-configs/min-plugin-config.xml
Modified:
    maven/plugins/trunk/maven-idea-plugin/pom.xml

Modified: maven/plugins/trunk/maven-idea-plugin/pom.xml
URL: 
http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-idea-plugin/pom.xml?rev=389656&r1=389655&r2=389656&view=diff
==============================================================================
--- maven/plugins/trunk/maven-idea-plugin/pom.xml (original)
+++ maven/plugins/trunk/maven-idea-plugin/pom.xml Tue Mar 28 18:22:17 2006
@@ -53,5 +53,11 @@
       <artifactId>dom4j</artifactId>
       <version>1.6.1</version>
     </dependency>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-plugin-testing-harness</artifactId>
+      <version>1.0-SNAPSHOT</version>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
 </project>

Added: 
maven/plugins/trunk/maven-idea-plugin/src/test/java/org/apache/maven/plugin/idea/IdeaProjectTest.java
URL: 
http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-idea-plugin/src/test/java/org/apache/maven/plugin/idea/IdeaProjectTest.java?rev=389656&view=auto
==============================================================================
--- 
maven/plugins/trunk/maven-idea-plugin/src/test/java/org/apache/maven/plugin/idea/IdeaProjectTest.java
 (added)
+++ 
maven/plugins/trunk/maven-idea-plugin/src/test/java/org/apache/maven/plugin/idea/IdeaProjectTest.java
 Tue Mar 28 18:22:17 2006
@@ -0,0 +1,63 @@
+package org.apache.maven.plugin.idea;
+
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed 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 org.apache.maven.plugins.testing.AbstractMojoTestCase;
+import org.apache.maven.plugin.idea.stubs.SimpleMavenProjectStub;
+
+import java.io.File;
+
+/**
+ * @author Edwin Punzalan
+ */
+public class IdeaProjectTest
+    extends AbstractMojoTestCase
+{
+    public void testIdeaProjectTestEnvironment()
+        throws Exception
+    {
+        File testPom = new File( getBasedir(), 
"src/test/plugin-configs/min-plugin-config.xml" );
+
+        IdeaProjectMojo mojo = (IdeaProjectMojo) lookupMojo( "project", 
testPom );
+
+        assertNotNull( "Get project mojo instance using " + 
testPom.getAbsolutePath() , mojo );
+
+        mojo.execute();
+
+        int testCounter = SimpleMavenProjectStub.getUsageCounter();
+
+        assertTrue( "Project file was created", new File( 
"target/test-harness/" + testCounter +
+            "/plugin-test-" + testCounter + ".ipr" ).exists() );
+    }
+
+    public void testIdeaProjectTestEnvironment2()
+        throws Exception
+    {
+        File testPom = new File( getBasedir(), 
"src/test/plugin-configs/min-plugin-config.xml" );
+
+        IdeaProjectMojo mojo = (IdeaProjectMojo) lookupMojo( "project", 
testPom );
+
+        assertNotNull( "Get project mojo instance using " + 
testPom.getAbsolutePath() , mojo );
+
+        mojo.execute();
+
+        int testCounter = SimpleMavenProjectStub.getUsageCounter();
+
+        assertTrue( "Project file was created", new File( 
"target/test-harness/" + testCounter +
+            "/plugin-test-" + testCounter + ".ipr" ).exists() );
+    }
+}

Added: 
maven/plugins/trunk/maven-idea-plugin/src/test/java/org/apache/maven/plugin/idea/stubs/ArtifactStub.java
URL: 
http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-idea-plugin/src/test/java/org/apache/maven/plugin/idea/stubs/ArtifactStub.java?rev=389656&view=auto
==============================================================================
--- 
maven/plugins/trunk/maven-idea-plugin/src/test/java/org/apache/maven/plugin/idea/stubs/ArtifactStub.java
 (added)
+++ 
maven/plugins/trunk/maven-idea-plugin/src/test/java/org/apache/maven/plugin/idea/stubs/ArtifactStub.java
 Tue Mar 28 18:22:17 2006
@@ -0,0 +1,56 @@
+package org.apache.maven.plugin.idea.stubs;
+
+import org.apache.maven.artifact.versioning.ArtifactVersion;
+import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
+import org.apache.maven.artifact.versioning.OverConstrainedVersionException;
+import org.apache.maven.plugins.testing.stubs.StubArtifact;
+
+/**
+ * @author Edwin Punzalan
+ */
+public class ArtifactStub
+    extends StubArtifact
+{
+    private String groupId;
+
+    private String artifactId;
+
+    private String version;
+
+
+    public void setGroupId( String groupId )
+    {
+        this.groupId = groupId;
+    }
+
+    public String getGroupId()
+    {
+        return groupId;
+    }
+
+    public void setArtifactId( String artifactId )
+    {
+        this.artifactId = artifactId;
+    }
+
+    public String getArtifactId( String artifactId )
+    {
+        return artifactId;
+    }
+
+    public void setVersion( String version )
+    {
+        this.version = version;
+    }
+
+    public String getVersion()
+    {
+        return version;
+    }
+
+    public ArtifactVersion getSelectedVersion()
+        throws OverConstrainedVersionException
+    {
+        return new DefaultArtifactVersion( getVersion() );
+    }
+}

Added: 
maven/plugins/trunk/maven-idea-plugin/src/test/java/org/apache/maven/plugin/idea/stubs/LocalRepositoryStub.java
URL: 
http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-idea-plugin/src/test/java/org/apache/maven/plugin/idea/stubs/LocalRepositoryStub.java?rev=389656&view=auto
==============================================================================
--- 
maven/plugins/trunk/maven-idea-plugin/src/test/java/org/apache/maven/plugin/idea/stubs/LocalRepositoryStub.java
 (added)
+++ 
maven/plugins/trunk/maven-idea-plugin/src/test/java/org/apache/maven/plugin/idea/stubs/LocalRepositoryStub.java
 Tue Mar 28 18:22:17 2006
@@ -0,0 +1,16 @@
+package org.apache.maven.plugin.idea.stubs;
+
+import org.apache.maven.artifact.repository.DefaultArtifactRepository;
+import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
+
+/**
+ * @author Edwin Punzalan
+ */
+public class LocalRepositoryStub
+    extends DefaultArtifactRepository
+{
+    public LocalRepositoryStub()
+    {
+        super( "local-repo", "file://" + System.getProperty( 
"localRepository") , new DefaultRepositoryLayout() );
+    }
+}

Added: 
maven/plugins/trunk/maven-idea-plugin/src/test/java/org/apache/maven/plugin/idea/stubs/SimpleMavenProjectStub.java
URL: 
http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-idea-plugin/src/test/java/org/apache/maven/plugin/idea/stubs/SimpleMavenProjectStub.java?rev=389656&view=auto
==============================================================================
--- 
maven/plugins/trunk/maven-idea-plugin/src/test/java/org/apache/maven/plugin/idea/stubs/SimpleMavenProjectStub.java
 (added)
+++ 
maven/plugins/trunk/maven-idea-plugin/src/test/java/org/apache/maven/plugin/idea/stubs/SimpleMavenProjectStub.java
 Tue Mar 28 18:22:17 2006
@@ -0,0 +1,120 @@
+package org.apache.maven.plugin.idea.stubs;
+
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed 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 org.apache.maven.artifact.Artifact;
+import org.apache.maven.model.Dependency;
+import org.apache.maven.plugins.testing.stubs.StubMavenProject;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.io.File;
+
+/**
+ * @author Edwin Punzalan
+ */
+public class SimpleMavenProjectStub
+    extends StubMavenProject
+{
+    private static int usageCounter;
+
+    private List collectedProjects;
+
+    public SimpleMavenProjectStub()
+    {
+        usageCounter++;
+    }
+
+    public static int getUsageCounter()
+    {
+        return usageCounter;
+    }
+
+    public String getGroupId()
+    {
+        return "org.apache.maven.plugin.test";
+    }
+
+    public String getArtifactId()
+    {
+        return "plugin-test-" + usageCounter;
+    }
+
+    public String getVersion()
+    {
+        return String.valueOf( usageCounter );
+    }
+
+    public File getBasedir()
+    {
+        File basedir = new File( "target/test-harness/" + usageCounter );
+
+        if ( !basedir.exists() )
+        {
+            basedir.mkdirs();
+        }
+
+        return basedir;
+    }
+
+    public List getCollectedProjects()
+    {
+        if ( collectedProjects == null )
+        {
+            collectedProjects = new ArrayList();
+        }
+        return collectedProjects;
+    }
+
+    public void setCollectedProjects( List list )
+    {
+        collectedProjects = list;
+    }
+
+    public List getDependencies()
+    {
+        List dependencies = new ArrayList();
+
+        Dependency dep = new Dependency();
+        dep.setGroupId( "org.apache.maven" );
+        dep.setArtifactId( "maven-model" );
+        dep.setVersion( "2.0.1" );
+        dep.setScope( Artifact.SCOPE_COMPILE );
+        dependencies.add( dep );
+
+        return dependencies;
+    }
+
+    public Artifact getArtifact()
+    {
+        Artifact artifact = new ArtifactStub();
+
+        artifact.setGroupId( getGroupId() );
+
+        artifact.setArtifactId( getArtifactId() );
+
+        artifact.setVersion( getVersion() );
+
+        return artifact;
+    }
+
+    public List getRemoteArtifactRepositories()
+    {
+        return Collections.EMPTY_LIST;
+    }
+}

Added: 
maven/plugins/trunk/maven-idea-plugin/src/test/plugin-configs/min-plugin-config.xml
URL: 
http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-idea-plugin/src/test/plugin-configs/min-plugin-config.xml?rev=389656&view=auto
==============================================================================
--- 
maven/plugins/trunk/maven-idea-plugin/src/test/plugin-configs/min-plugin-config.xml
 (added)
+++ 
maven/plugins/trunk/maven-idea-plugin/src/test/plugin-configs/min-plugin-config.xml
 Tue Mar 28 18:22:17 2006
@@ -0,0 +1,14 @@
+<project>
+  <build>
+    <plugins>
+      <plugin>
+        <artifactId>maven-idea-plugin</artifactId>
+        <configuration>
+          <project 
implementation="org.apache.maven.plugin.idea.stubs.SimpleMavenProjectStub"/>
+          <localRepo 
implementation="org.apache.maven.plugin.idea.stubs.LocalRepositoryStub"/>
+          <ideaVersion>4</ideaVersion>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>
\ No newline at end of file


Reply via email to