Return-Path: Delivered-To: apmail-maven-commits-archive@www.apache.org Received: (qmail 2779 invoked from network); 30 Mar 2006 09:13:59 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 30 Mar 2006 09:13:59 -0000 Received: (qmail 26235 invoked by uid 500); 30 Mar 2006 09:13:50 -0000 Delivered-To: apmail-maven-commits-archive@maven.apache.org Received: (qmail 26066 invoked by uid 500); 30 Mar 2006 09:13:50 -0000 Mailing-List: contact commits-help@maven.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@maven.apache.org Delivered-To: mailing list commits@maven.apache.org Received: (qmail 25998 invoked by uid 99); 30 Mar 2006 09:13:49 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 30 Mar 2006 01:13:49 -0800 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Thu, 30 Mar 2006 01:13:48 -0800 Received: (qmail 2418 invoked by uid 65534); 30 Mar 2006 09:13:28 -0000 Message-ID: <20060330091328.2413.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@maven.apache.org From: epunzalan@apache.org X-Mailer: svnmailer-1.0.7 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N 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 @@ maven-idea-plugin - + ${localRepository} 4 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 @@ maven-idea-plugin - - 5 + ${localRepository} + 4 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 @@ maven-idea-plugin - + ${localRepository} 4 - 1.4 + java version 1.1 + 1.1 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 @@ + + + + + maven-idea-plugin + + + ${localRepository} + 4 + java version 1.5 + 1.5 + + + + + \ No newline at end of file