maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From epunza...@apache.org
Subject svn commit: r390039 - in /maven/plugins/trunk/maven-idea-plugin/src/test: java/org/apache/maven/plugin/idea/ java/org/apache/maven/plugin/idea/stubs/ plugin-configs/
Date Thu, 30 Mar 2006 09:13:26 GMT
Author: epunzalan
Date: Thu Mar 30 01:13:23 2006
New Revision: 390039

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

More plugin tests

Added:
    maven/plugins/trunk/maven-idea-plugin/src/test/plugin-configs/plugin-config-idea4.xml
      - copied, changed from r389733, maven/plugins/trunk/maven-idea-plugin/src/test/plugin-configs/plugin-config-idea5.xml
    maven/plugins/trunk/maven-idea-plugin/src/test/plugin-configs/plugin-config-jdk11.xml
      - copied, changed from r389733, maven/plugins/trunk/maven-idea-plugin/src/test/plugin-configs/plugin-config-jdkName.xml
    maven/plugins/trunk/maven-idea-plugin/src/test/plugin-configs/plugin-config-jdk15.xml
Removed:
    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/plugin-configs/plugin-config-idea5.xml
    maven/plugins/trunk/maven-idea-plugin/src/test/plugin-configs/plugin-config-jdkName.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/plugin-configs/min-plugin-config.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=390039&r1=390038&r2=390039&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
Thu Mar 30 01:13:23 2006
@@ -18,8 +18,13 @@
 
 import org.apache.maven.plugin.idea.stubs.SimpleMavenProjectStub;
 import org.apache.maven.plugins.testing.AbstractMojoTestCase;
+import org.dom4j.io.SAXReader;
+import org.dom4j.DocumentException;
+import org.dom4j.Document;
+import org.dom4j.Element;
 
 import java.io.File;
+import java.util.Iterator;
 
 /**
  * @author Edwin Punzalan
@@ -27,81 +32,136 @@
 public class IdeaProjectTest
     extends AbstractMojoTestCase
 {
+    private IdeaProjectMojo mojo;
+
     public void testIdeaProjectTestEnvironment()
         throws Exception
     {
-        File testPom = new File( getBasedir(), "src/test/plugin-configs/min-plugin-config.xml"
);
-
-        IdeaProjectMojo mojo = (IdeaProjectMojo) lookupMojo( "project", testPom );
+        Document iprDocument = executeMojo( "src/test/plugin-configs/min-plugin-config.xml"
);
 
-        assertNotNull( "Get project mojo instance using " + testPom.getAbsolutePath() , mojo
);
+        testJdkName( iprDocument, null, null );
+    }
 
-        setVariableValueToObject( mojo, "artifactMetadataSource",
-                                  lookup( "org.apache.maven.artifact.metadata.ArtifactMetadataSource",
"maven" ) );
+    public void testIdeaProjectVersion4()
+        throws Exception
+    {
+        Document iprDocument = executeMojo( "src/test/plugin-configs/plugin-config-idea4.xml"
);
 
-        setVariableValueToObject( mojo, "artifactFactory",
-                                  lookup( "org.apache.maven.artifact.factory.ArtifactFactory"
) );
+        Element root = iprDocument.getRootElement();
 
-        setVariableValueToObject( mojo, "artifactResolver",
-                                  lookup( "org.apache.maven.artifact.resolver.ArtifactResolver"
) );
+        Element component = findComponent( root, "ProjectRootManager" );
 
-        mojo.execute();
+        String jdkName = component.attributeValue( "project-jdk-name" );
 
-        int testCounter = SimpleMavenProjectStub.getUsageCounter();
+        String javaVersion = System.getProperty( "java.version" );
 
-        assertTrue( "Project file was created", new File( "target/test-harness/" + testCounter
+
-            "/plugin-test-" + testCounter + ".ipr" ).exists() );
+        assertEquals( "Default jdkName should be from System.Properties",
+                      jdkName, "java version "" + javaVersion + """ );
     }
 
-    public void testIdeaProjectVersion5()
+    public void testIdeaProjectJdk11()
         throws Exception
     {
-        File testPom = new File( getBasedir(), "src/test/plugin-configs/plugin-config-idea5.xml"
);
+        Document iprDocument = executeMojo( "src/test/plugin-configs/plugin-config-jdk11.xml"
);
 
-        IdeaProjectMojo mojo = (IdeaProjectMojo) lookupMojo( "project", testPom );
+        testJdkName( iprDocument, "1.1", "java version 1.1" );
+    }
 
-        assertNotNull( "Get project mojo instance using " + testPom.getAbsolutePath() , mojo
);
+    public void testIdeaProjectJdk15()
+        throws Exception
+    {
+        Document iprDocument = executeMojo( "src/test/plugin-configs/plugin-config-jdk15.xml"
);
 
-        setVariableValueToObject( mojo, "artifactMetadataSource",
-                                  lookup( "org.apache.maven.artifact.metadata.ArtifactMetadataSource",
"maven" ) );
+        testJdkName( iprDocument, "1.5", "java version 1.5" );
+    }
+
+    private Document executeMojo( String pluginXml )
+        throws Exception
+    {
+        File pluginXmlFile = new File( getBasedir(), pluginXml );
 
-        setVariableValueToObject( mojo, "artifactFactory",
-                                  lookup( "org.apache.maven.artifact.factory.ArtifactFactory"
) );
+        mojo = (IdeaProjectMojo) lookupMojo( "project", pluginXmlFile );
 
-        setVariableValueToObject( mojo, "artifactResolver",
-                                  lookup( "org.apache.maven.artifact.resolver.ArtifactResolver"
) );
+        assertNotNull( "Get project mojo instance using " + pluginXmlFile.getAbsolutePath()
, mojo );
 
         mojo.execute();
 
         int testCounter = SimpleMavenProjectStub.getUsageCounter();
 
-        assertTrue( "Project file was created", new File( "target/test-harness/" + testCounter
+
-            "/plugin-test-" + testCounter + ".ipr" ).exists() );
+        File iprFile = new File( "target/test-harness/" + testCounter + "/plugin-test-" +
testCounter + ".ipr" );
+
+        assertTrue( "Project file was created", iprFile.exists() );
+
+        return readXmlDocument( iprFile );
     }
 
-    public void testIdeaProjectJdkName()
+    private void testJdkName( Document document, String jdkLevel, String expected )
         throws Exception
     {
-        File testPom = new File( getBasedir(), "src/test/plugin-configs/plugin-config-jdkName.xml"
);
+        Element root = document.getRootElement();
 
-        IdeaProjectMojo mojo = (IdeaProjectMojo) lookupMojo( "project", testPom );
+        Element component = findComponent( root, "ProjectRootManager" );
 
-        setVariableValueToObject( mojo, "artifactMetadataSource",
-                                  lookup( "org.apache.maven.artifact.metadata.ArtifactMetadataSource",
"maven" ) );
+        String jdkName = component.attributeValue( "project-jdk-name" );
 
-        setVariableValueToObject( mojo, "artifactFactory",
-                                  lookup( "org.apache.maven.artifact.factory.ArtifactFactory"
) );
-
-        setVariableValueToObject( mojo, "artifactResolver",
-                                  lookup( "org.apache.maven.artifact.resolver.ArtifactResolver"
) );
+        if ( jdkLevel == null )
+        {
+            jdkLevel = System.getProperty( "java.specification.version" );
+        }
+
+        if ( jdkLevel.startsWith( "1.4" ) )
+        {
+            assertEquals( "assert-keyword must be true for jdk 1.4",
+                          "true", component.attributeValue( "assert-keyword" ) );
+
+            assertEquals( "jdk-15 must be false for jdk 1.4",
+                          "false", component.attributeValue( "jdk-15") );
+        }
+        else if ( jdkLevel.compareTo( "1.5" ) >= 0 )
+        {
+            assertEquals( "assert-keyword must be true for jdk >= 1.5",
+                          "true", component.attributeValue( "assert-keyword" ) );
+
+            assertEquals( "jdk-15 must be true for jdk >= 1.5",
+                          "true", component.attributeValue( "jdk-15") );
+        }
+        else
+        {
+            assertEquals( "assert-keyword must be true for jdk >= 1.5",
+                          "false", component.attributeValue( "assert-keyword" ) );
+        }
+
+        if ( expected != null )
+        {
+            assertEquals( "Expected jdkName test", jdkName, expected );
+        }
+    }
 
-        assertNotNull( "Get project mojo instance using " + testPom.getAbsolutePath() , mojo
);
+    private Document readXmlDocument( File xmlFile )
+        throws DocumentException
+    {
+        SAXReader reader = new SAXReader();
 
-        mojo.execute();
+        return reader.read( xmlFile );
+    }
 
-        int testCounter = SimpleMavenProjectStub.getUsageCounter();
+    private Element findComponent( Element module, String name )
+        throws Exception
+    {
+        return findElement( module, "component", name );
+    }
 
-        assertTrue( "Project file was created", new File( "target/test-harness/" + testCounter
+
-            "/plugin-test-" + testCounter + ".ipr" ).exists() );
+    private Element findElement( Element element, String elementName, String attributeName
)
+        throws Exception
+    {
+        for ( Iterator children = element.elementIterator( elementName ); children.hasNext();
)
+        {
+            Element child = (Element) children.next();
+            if ( attributeName.equals( child.attributeValue( "name" ) ) )
+            {
+                return child;
+            }
+        }
+        throw new Exception( "Expected element not found: " + elementName );
     }
 }

Modified: 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=390039&r1=390038&r2=390039&view=diff
==============================================================================
--- maven/plugins/trunk/maven-idea-plugin/src/test/plugin-configs/min-plugin-config.xml (original)
+++ maven/plugins/trunk/maven-idea-plugin/src/test/plugin-configs/min-plugin-config.xml Thu
Mar 30 01:13:23 2006
@@ -5,7 +5,7 @@
         <artifactId>maven-idea-plugin</artifactId>
         <configuration>
           <project implementation="org.apache.maven.plugin.idea.stubs.SimpleMavenProjectStub"/>
-          <localRepo implementation="org.apache.maven.plugin.idea.stubs.LocalRepositoryStub"/>
+          <localRepo>${localRepository}</localRepo>
           <ideaVersion>4</ideaVersion>
         </configuration>
       </plugin>

Copied: maven/plugins/trunk/maven-idea-plugin/src/test/plugin-configs/plugin-config-idea4.xml
(from r389733, maven/plugins/trunk/maven-idea-plugin/src/test/plugin-configs/plugin-config-idea5.xml)
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-idea-plugin/src/test/plugin-configs/plugin-config-idea4.xml?p2=maven/plugins/trunk/maven-idea-plugin/src/test/plugin-configs/plugin-config-idea4.xml&p1=maven/plugins/trunk/maven-idea-plugin/src/test/plugin-configs/plugin-config-idea5.xml&r1=389733&r2=390039&rev=390039&view=diff
==============================================================================
--- maven/plugins/trunk/maven-idea-plugin/src/test/plugin-configs/plugin-config-idea5.xml
(original)
+++ maven/plugins/trunk/maven-idea-plugin/src/test/plugin-configs/plugin-config-idea4.xml
Thu Mar 30 01:13:23 2006
@@ -5,8 +5,8 @@
         <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>5</ideaVersion>
+          <localRepo>${localRepository}</localRepo>
+          <ideaVersion>4</ideaVersion>
         </configuration>
       </plugin>
     </plugins>

Copied: maven/plugins/trunk/maven-idea-plugin/src/test/plugin-configs/plugin-config-jdk11.xml
(from r389733, maven/plugins/trunk/maven-idea-plugin/src/test/plugin-configs/plugin-config-jdkName.xml)
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-idea-plugin/src/test/plugin-configs/plugin-config-jdk11.xml?p2=maven/plugins/trunk/maven-idea-plugin/src/test/plugin-configs/plugin-config-jdk11.xml&p1=maven/plugins/trunk/maven-idea-plugin/src/test/plugin-configs/plugin-config-jdkName.xml&r1=389733&r2=390039&rev=390039&view=diff
==============================================================================
--- maven/plugins/trunk/maven-idea-plugin/src/test/plugin-configs/plugin-config-jdkName.xml
(original)
+++ maven/plugins/trunk/maven-idea-plugin/src/test/plugin-configs/plugin-config-jdk11.xml
Thu Mar 30 01:13:23 2006
@@ -5,9 +5,10 @@
         <artifactId>maven-idea-plugin</artifactId>
         <configuration>
           <project implementation="org.apache.maven.plugin.idea.stubs.SimpleMavenProjectStub"/>
-          <localRepo implementation="org.apache.maven.plugin.idea.stubs.LocalRepositoryStub"/>
+          <localRepo>${localRepository}</localRepo>
           <ideaVersion>4</ideaVersion>
-          <jdkName>1.4</jdkName>
+          <jdkName>java version 1.1</jdkName>
+          <jdkLevel>1.1</jdkLevel>
         </configuration>
       </plugin>
     </plugins>

Added: maven/plugins/trunk/maven-idea-plugin/src/test/plugin-configs/plugin-config-jdk15.xml
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-idea-plugin/src/test/plugin-configs/plugin-config-jdk15.xml?rev=390039&view=auto
==============================================================================
--- maven/plugins/trunk/maven-idea-plugin/src/test/plugin-configs/plugin-config-jdk15.xml
(added)
+++ maven/plugins/trunk/maven-idea-plugin/src/test/plugin-configs/plugin-config-jdk15.xml
Thu Mar 30 01:13:23 2006
@@ -0,0 +1,16 @@
+<project>
+  <build>
+    <plugins>
+      <plugin>
+        <artifactId>maven-idea-plugin</artifactId>
+        <configuration>
+          <project implementation="org.apache.maven.plugin.idea.stubs.SimpleMavenProjectStub"/>
+          <localRepo>${localRepository}</localRepo>
+          <ideaVersion>4</ideaVersion>
+          <jdkName>java version 1.5</jdkName>
+          <jdkLevel>1.5</jdkLevel>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>
\ No newline at end of file



Mime
View raw message