You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ep...@apache.org on 2006/04/03 05:32:51 UTC

svn commit: r390948 - in /maven/plugins/trunk/maven-idea-plugin/src/test: java/org/apache/maven/plugin/idea/ java/org/apache/maven/plugin/idea/stubs/ plugin-configs/

Author: epunzalan
Date: Sun Apr  2 20:32:49 2006
New Revision: 390948

URL: http://svn.apache.org/viewcvs?rev=390948&view=rev
Log:
PR: MIDEA-43

more test for the idea:project mojo

Added:
    maven/plugins/trunk/maven-idea-plugin/src/test/java/org/apache/maven/plugin/idea/stubs/MavenProjectModuleStub.java
    maven/plugins/trunk/maven-idea-plugin/src/test/java/org/apache/maven/plugin/idea/stubs/MavenProjectWithModulesStub.java
    maven/plugins/trunk/maven-idea-plugin/src/test/java/org/apache/maven/plugin/idea/stubs/TestCounter.java
    maven/plugins/trunk/maven-idea-plugin/src/test/plugin-configs/plugin-config-modules.xml
Modified:
    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/SimpleMavenProjectStub.java
    maven/plugins/trunk/maven-idea-plugin/src/test/plugin-configs/plugin-config-idea4.xml

Modified: 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=390948&r1=390947&r2=390948&view=diff
==============================================================================
--- maven/plugins/trunk/maven-idea-plugin/src/test/java/org/apache/maven/plugin/idea/IdeaProjectTest.java (original)
+++ maven/plugins/trunk/maven-idea-plugin/src/test/java/org/apache/maven/plugin/idea/IdeaProjectTest.java Sun Apr  2 20:32:49 2006
@@ -16,15 +16,16 @@
  * limitations under the License.
  */
 
-import org.apache.maven.plugin.idea.stubs.SimpleMavenProjectStub;
+import org.apache.maven.plugin.idea.stubs.TestCounter;
 import org.apache.maven.plugin.testing.AbstractMojoTestCase;
-import org.dom4j.io.SAXReader;
-import org.dom4j.DocumentException;
 import org.dom4j.Document;
+import org.dom4j.DocumentException;
 import org.dom4j.Element;
+import org.dom4j.io.SAXReader;
 
 import java.io.File;
 import java.util.Iterator;
+import java.util.List;
 
 /**
  * @author Edwin Punzalan
@@ -57,6 +58,12 @@
 
         assertEquals( "Default jdkName should be from System.Properties",
                       jdkName, "java version "" + javaVersion + """ );
+
+        component = findComponent( root, "CompilerConfiguration" );
+
+        Element patterns = findElementByNameAttribute( component, "wildcardResourcePatterns", null );
+
+        findElementByNameAttribute( patterns, "entry", "!?*.java" );
     }
 
     public void testIdeaProjectJdk11()
@@ -75,6 +82,40 @@
         testJdkName( iprDocument, "1.5", "java version 1.5" );
     }
 
+    public void testIdeaProjectWithModules()
+        throws Exception
+    {
+        Document iprDocument = executeMojo( "src/test/plugin-configs/plugin-config-modules.xml" );
+
+        Element component = findComponent( iprDocument.getRootElement(), "ProjectModuleManager" );
+
+        Element el = findElementByNameAttribute( component, "modules", null );
+
+        List modules = findElementsByName( el, "module" );
+
+        assertEquals( "Must have 4 modules", 4, modules.size() );
+
+        el = (Element) modules.get( 0 );
+        assertEquals( "Test project module",
+                      "$PROJECT_DIR$/plugin-test-" + TestCounter.currentCount() + ".iml",
+                      el.attributeValue( "filepath" ) );
+
+        el = (Element) modules.get( 1 );
+        assertEquals( "Test module 1",
+                      "$PROJECT_DIR$/module-1/module-1.iml",
+                      el.attributeValue( "filepath" ) );
+
+        el = (Element) modules.get( 2 );
+        assertEquals( "Test module 2",
+                      "$PROJECT_DIR$/module-2/module-2.iml",
+                      el.attributeValue( "filepath" ) );
+
+        el = (Element) modules.get( 3 );
+        assertEquals( "Test module 3",
+                      "$PROJECT_DIR$/module-3/module-3.iml",
+                      el.attributeValue( "filepath" ) );
+    }
+
     private Document executeMojo( String pluginXml )
         throws Exception
     {
@@ -86,7 +127,7 @@
 
         mojo.execute();
 
-        int testCounter = SimpleMavenProjectStub.getUsageCounter();
+        int testCounter = TestCounter.currentCount();
 
         File iprFile = new File( "target/test-harness/" + testCounter + "/plugin-test-" + testCounter + ".ipr" );
 
@@ -148,20 +189,44 @@
     private Element findComponent( Element module, String name )
         throws Exception
     {
-        return findElement( module, "component", name );
+        return findElementByNameAttribute( module, "component", name );
     }
 
-    private Element findElement( Element element, String elementName, String attributeName )
+    private Element findElementByNameAttribute( Element element, String elementName, String nameAttribute )
         throws Exception
     {
+        Element e = null;
+
         for ( Iterator children = element.elementIterator( elementName ); children.hasNext(); )
         {
             Element child = (Element) children.next();
-            if ( attributeName.equals( child.attributeValue( "name" ) ) )
+            if ( nameAttribute == null )
+            {
+                e = child;
+            }
+            else if ( nameAttribute.equals( child.attributeValue( "name" ) ) )
+            {
+                e = child;
+            }
+        }
+
+        if ( e == null)
+        {
+            if ( nameAttribute == null )
+            {
+                fail( "Element " + elementName + " not found." );
+            }
+            else
             {
-                return child;
+                fail( "Attribute " + nameAttribute + " not found in elements " + elementName + "." );
             }
         }
-        throw new Exception( "Expected element not found: " + elementName );
+
+        return e;
+    }
+
+    private List findElementsByName( Element element, String elementName )
+    {
+        return element.elements( elementName );
     }
 }

Added: maven/plugins/trunk/maven-idea-plugin/src/test/java/org/apache/maven/plugin/idea/stubs/MavenProjectModuleStub.java
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-idea-plugin/src/test/java/org/apache/maven/plugin/idea/stubs/MavenProjectModuleStub.java?rev=390948&view=auto
==============================================================================
--- maven/plugins/trunk/maven-idea-plugin/src/test/java/org/apache/maven/plugin/idea/stubs/MavenProjectModuleStub.java (added)
+++ maven/plugins/trunk/maven-idea-plugin/src/test/java/org/apache/maven/plugin/idea/stubs/MavenProjectModuleStub.java Sun Apr  2 20:32:49 2006
@@ -0,0 +1,35 @@
+package org.apache.maven.plugin.idea.stubs;
+
+import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
+
+import java.io.File;
+
+/**
+ * @author Edwin Punzalan
+ */
+public class MavenProjectModuleStub
+    extends MavenProjectStub
+{
+    private File basedir;
+
+    private String artifactId;
+
+    public MavenProjectModuleStub( String artifactId, File basedir )
+    {
+        super();
+
+        this.basedir = basedir;
+
+        this.artifactId = artifactId;
+    }
+
+    public File getBasedir()
+    {
+        return basedir;
+    }
+
+    public String getArtifactId()
+    {
+        return artifactId;
+    }
+}

Added: maven/plugins/trunk/maven-idea-plugin/src/test/java/org/apache/maven/plugin/idea/stubs/MavenProjectWithModulesStub.java
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-idea-plugin/src/test/java/org/apache/maven/plugin/idea/stubs/MavenProjectWithModulesStub.java?rev=390948&view=auto
==============================================================================
--- maven/plugins/trunk/maven-idea-plugin/src/test/java/org/apache/maven/plugin/idea/stubs/MavenProjectWithModulesStub.java (added)
+++ maven/plugins/trunk/maven-idea-plugin/src/test/java/org/apache/maven/plugin/idea/stubs/MavenProjectWithModulesStub.java Sun Apr  2 20:32:49 2006
@@ -0,0 +1,30 @@
+package org.apache.maven.plugin.idea.stubs;
+
+import org.apache.maven.project.MavenProject;
+
+import java.util.List;
+import java.util.ArrayList;
+import java.io.File;
+
+/**
+ * @author Edwin Punzalan
+ */
+public class MavenProjectWithModulesStub
+    extends SimpleMavenProjectStub
+{
+    public List getCollectedProjects()
+    {
+        List projects = new ArrayList();
+
+        projects.add( createModule( "module-1" ) );
+        projects.add( createModule( "module-2" ) );
+        projects.add( createModule( "module-3" ) );
+
+        return projects;
+    }
+
+    private MavenProject createModule( String artifactId )
+    {
+        return new MavenProjectModuleStub( artifactId, new File( getBasedir(), artifactId ) );
+    }
+}

Modified: 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=390948&r1=390947&r2=390948&view=diff
==============================================================================
--- maven/plugins/trunk/maven-idea-plugin/src/test/java/org/apache/maven/plugin/idea/stubs/SimpleMavenProjectStub.java (original)
+++ maven/plugins/trunk/maven-idea-plugin/src/test/java/org/apache/maven/plugin/idea/stubs/SimpleMavenProjectStub.java Sun Apr  2 20:32:49 2006
@@ -31,18 +31,11 @@
 public class SimpleMavenProjectStub
     extends MavenProjectStub
 {
-    private static int usageCounter;
-
     private List collectedProjects;
 
     public SimpleMavenProjectStub()
     {
-        usageCounter++;
-    }
-
-    public static int getUsageCounter()
-    {
-        return usageCounter;
+        TestCounter.nextCount();
     }
 
     public String getGroupId()
@@ -52,17 +45,17 @@
 
     public String getArtifactId()
     {
-        return "plugin-test-" + usageCounter;
+        return "plugin-test-" + TestCounter.currentCount();
     }
 
     public String getVersion()
     {
-        return String.valueOf( usageCounter );
+        return String.valueOf( TestCounter.currentCount() );
     }
 
     public File getBasedir()
     {
-        File basedir = new File( "target/test-harness/" + usageCounter );
+        File basedir = new File( "target/test-harness/" + TestCounter.currentCount() );
 
         if ( !basedir.exists() )
         {

Added: maven/plugins/trunk/maven-idea-plugin/src/test/java/org/apache/maven/plugin/idea/stubs/TestCounter.java
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-idea-plugin/src/test/java/org/apache/maven/plugin/idea/stubs/TestCounter.java?rev=390948&view=auto
==============================================================================
--- maven/plugins/trunk/maven-idea-plugin/src/test/java/org/apache/maven/plugin/idea/stubs/TestCounter.java (added)
+++ maven/plugins/trunk/maven-idea-plugin/src/test/java/org/apache/maven/plugin/idea/stubs/TestCounter.java Sun Apr  2 20:32:49 2006
@@ -0,0 +1,19 @@
+package org.apache.maven.plugin.idea.stubs;
+
+/**
+ * @author Edwin Punzalan
+ */
+public class TestCounter
+{
+    public static int ctr = 0;
+
+    public static int nextCount()
+    {
+        return ++ctr;
+    }
+
+    public static int currentCount()
+    {
+        return ctr;
+    }
+}

Modified: maven/plugins/trunk/maven-idea-plugin/src/test/plugin-configs/plugin-config-idea4.xml
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-idea-plugin/src/test/plugin-configs/plugin-config-idea4.xml?rev=390948&r1=390947&r2=390948&view=diff
==============================================================================
--- maven/plugins/trunk/maven-idea-plugin/src/test/plugin-configs/plugin-config-idea4.xml (original)
+++ maven/plugins/trunk/maven-idea-plugin/src/test/plugin-configs/plugin-config-idea4.xml Sun Apr  2 20:32:49 2006
@@ -7,6 +7,7 @@
           <project implementation="org.apache.maven.plugin.idea.stubs.SimpleMavenProjectStub"/>
           <localRepo>${localRepository}</localRepo>
           <ideaVersion>4</ideaVersion>
+          <wildcardResourcePatterns>!?*.java</wildcardResourcePatterns>
         </configuration>
       </plugin>
     </plugins>

Added: maven/plugins/trunk/maven-idea-plugin/src/test/plugin-configs/plugin-config-modules.xml
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-idea-plugin/src/test/plugin-configs/plugin-config-modules.xml?rev=390948&view=auto
==============================================================================
--- maven/plugins/trunk/maven-idea-plugin/src/test/plugin-configs/plugin-config-modules.xml (added)
+++ maven/plugins/trunk/maven-idea-plugin/src/test/plugin-configs/plugin-config-modules.xml Sun Apr  2 20:32:49 2006
@@ -0,0 +1,14 @@
+<project>
+  <build>
+    <plugins>
+      <plugin>
+        <artifactId>maven-idea-plugin</artifactId>
+        <configuration>
+          <project implementation="org.apache.maven.plugin.idea.stubs.MavenProjectWithModulesStub"/>
+          <localRepo>${localRepository}</localRepo>
+          <ideaVersion>4</ideaVersion>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>
\ No newline at end of file