Author: jmcconnell
Date: Wed Oct 1 14:45:06 2008
New Revision: 700940
URL: http://svn.apache.org/viewvc?rev=700940&view=rev
Log:
adding in the start of some unit tests for this plugin
Added:
maven/sandbox/trunk/plugins/maven-pom-plugin/src/test/
maven/sandbox/trunk/plugins/maven-pom-plugin/src/test/java/
maven/sandbox/trunk/plugins/maven-pom-plugin/src/test/java/org/
maven/sandbox/trunk/plugins/maven-pom-plugin/src/test/java/org/apache/
maven/sandbox/trunk/plugins/maven-pom-plugin/src/test/java/org/apache/maven/
maven/sandbox/trunk/plugins/maven-pom-plugin/src/test/java/org/apache/maven/plugins/
maven/sandbox/trunk/plugins/maven-pom-plugin/src/test/java/org/apache/maven/plugins/pom/
maven/sandbox/trunk/plugins/maven-pom-plugin/src/test/java/org/apache/maven/plugins/pom/AlterByXPathMojoTest.java
maven/sandbox/trunk/plugins/maven-pom-plugin/src/test/java/org/apache/maven/plugins/pom/stubs/
maven/sandbox/trunk/plugins/maven-pom-plugin/src/test/java/org/apache/maven/plugins/pom/stubs/PomProjectStub.java
maven/sandbox/trunk/plugins/maven-pom-plugin/src/test/resources/
maven/sandbox/trunk/plugins/maven-pom-plugin/src/test/resources/unit/
maven/sandbox/trunk/plugins/maven-pom-plugin/src/test/resources/unit/alter-by-xpath-test/
maven/sandbox/trunk/plugins/maven-pom-plugin/src/test/resources/unit/alter-by-xpath-test/alter-by-xpath-pom.xml
maven/sandbox/trunk/plugins/maven-pom-plugin/src/test/resources/unit/alter-by-xpath-test/plugin-pom.xml
Modified:
maven/sandbox/trunk/plugins/maven-pom-plugin/pom.xml
maven/sandbox/trunk/plugins/maven-pom-plugin/src/main/java/org/apache/maven/plugins/pom/AlterByXPathMojo.java
Modified: maven/sandbox/trunk/plugins/maven-pom-plugin/pom.xml
URL:
http://svn.apache.org/viewvc/maven/sandbox/trunk/plugins/maven-pom-plugin/pom.xml?rev=700940&r1=700939&r2=700940&view=diff
==============================================================================
--- maven/sandbox/trunk/plugins/maven-pom-plugin/pom.xml (original)
+++ maven/sandbox/trunk/plugins/maven-pom-plugin/pom.xml Wed Oct 1 14:45:06
2008
@@ -67,5 +67,12 @@
<version>3.8.1</version>
<scope>test</scope>
</dependency>
+ <!-- Test -->
+ <dependency>
+ <groupId>org.apache.maven.shared</groupId>
+ <artifactId>maven-plugin-testing-harness</artifactId>
+ <version>1.1</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
Modified:
maven/sandbox/trunk/plugins/maven-pom-plugin/src/main/java/org/apache/maven/plugins/pom/AlterByXPathMojo.java
URL:
http://svn.apache.org/viewvc/maven/sandbox/trunk/plugins/maven-pom-plugin/src/main/java/org/apache/maven/plugins/pom/AlterByXPathMojo.java?rev=700940&r1=700939&r2=700940&view=diff
==============================================================================
---
maven/sandbox/trunk/plugins/maven-pom-plugin/src/main/java/org/apache/maven/plugins/pom/AlterByXPathMojo.java
(original)
+++
maven/sandbox/trunk/plugins/maven-pom-plugin/src/main/java/org/apache/maven/plugins/pom/AlterByXPathMojo.java
Wed Oct 1 14:45:06 2008
@@ -63,7 +63,7 @@
public void execute() throws MojoExecutionException, MojoFailureException
{
- if ( xpath == null || newValue == null )
+ if ( xpath == null || newValue == null || projectFile == null )
{
getLog().info( "missing required information" );
return;
Added:
maven/sandbox/trunk/plugins/maven-pom-plugin/src/test/java/org/apache/maven/plugins/pom/AlterByXPathMojoTest.java
URL:
http://svn.apache.org/viewvc/maven/sandbox/trunk/plugins/maven-pom-plugin/src/test/java/org/apache/maven/plugins/pom/AlterByXPathMojoTest.java?rev=700940&view=auto
==============================================================================
---
maven/sandbox/trunk/plugins/maven-pom-plugin/src/test/java/org/apache/maven/plugins/pom/AlterByXPathMojoTest.java
(added)
+++
maven/sandbox/trunk/plugins/maven-pom-plugin/src/test/java/org/apache/maven/plugins/pom/AlterByXPathMojoTest.java
Wed Oct 1 14:45:06 2008
@@ -0,0 +1,80 @@
+package org.apache.maven.plugins.pom;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 java.io.File;
+import java.io.RandomAccessFile;
+import java.nio.channels.FileChannel;
+import java.nio.channels.FileLock;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.testing.AbstractMojoTestCase;
+import org.codehaus.plexus.util.FileUtils;
+import org.apache.maven.plugins.pom.AlterByXPathMojo;
+import org.apache.maven.plugins.pom.util.XMLTool;
+
+/**
+ * Test a pom mojo.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Jesse McConnell</a>
+ * @version $Id:$
+ */
+public class AlterByXPathMojoTest
+ extends AbstractMojoTestCase
+{
+ /** [EMAIL PROTECTED] */
+ protected void setUp()
+ throws Exception
+ {
+ super.setUp();
+ }
+
+ /** [EMAIL PROTECTED] */
+ protected void tearDown()
+ throws Exception
+ {
+ super.tearDown();
+ }
+
+ /**
+ * Tests a pom alteration by xpath
+ *
+ * @throws Exception
+ */
+ public void testAlterByXPath()
+ throws Exception
+ {
+ String pluginPom = getBasedir() +
"/src/test/resources/unit/alter-by-xpath-test/plugin-pom.xml";
+
+ // safety
+ FileUtils.copyDirectory( new File( getBasedir(),
"src/test/resources/unit/alter-by-xpath-test" ),
+ new File( getBasedir(),
"target/test-files/unit/alter-by-xpath-test" ), null, "**/.svn,**/.svn/**" );
+
+ AlterByXPathMojo mojo = (AlterByXPathMojo) lookupMojo(
"alter-by-xpath", pluginPom );
+
+ assertNotNull( mojo );
+
+ mojo.execute();
+
+ XMLTool xmlTool = new XMLTool( "project", new File( getBasedir() +
"/target/test-files/unit/alter-by-xpath-test/alter-by-xpath-pom.xml" ) );
+
+ assertEquals( "1.1-SNAPSHOT",
xmlTool.getElement("/project/dependencies/dependency[artifactId[.='commons-collections']]/version").getText());
+ }
+}
Added:
maven/sandbox/trunk/plugins/maven-pom-plugin/src/test/java/org/apache/maven/plugins/pom/stubs/PomProjectStub.java
URL:
http://svn.apache.org/viewvc/maven/sandbox/trunk/plugins/maven-pom-plugin/src/test/java/org/apache/maven/plugins/pom/stubs/PomProjectStub.java?rev=700940&view=auto
==============================================================================
---
maven/sandbox/trunk/plugins/maven-pom-plugin/src/test/java/org/apache/maven/plugins/pom/stubs/PomProjectStub.java
(added)
+++
maven/sandbox/trunk/plugins/maven-pom-plugin/src/test/java/org/apache/maven/plugins/pom/stubs/PomProjectStub.java
Wed Oct 1 14:45:06 2008
@@ -0,0 +1,32 @@
+package org.apache.maven.plugin.pom.stubs;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.plugin.testing.stubs.MavenProjectStub;
+
+/**
+ * @author <a href="mailto:[EMAIL PROTECTED]">Jesse McConnell</a>
+ * @version $Id:$
+ */
+public class PomProjectStub
+ extends MavenProjectStub
+{
+ // nop
+}
Added:
maven/sandbox/trunk/plugins/maven-pom-plugin/src/test/resources/unit/alter-by-xpath-test/alter-by-xpath-pom.xml
URL:
http://svn.apache.org/viewvc/maven/sandbox/trunk/plugins/maven-pom-plugin/src/test/resources/unit/alter-by-xpath-test/alter-by-xpath-pom.xml?rev=700940&view=auto
==============================================================================
---
maven/sandbox/trunk/plugins/maven-pom-plugin/src/test/resources/unit/alter-by-xpath-test/alter-by-xpath-pom.xml
(added)
+++
maven/sandbox/trunk/plugins/maven-pom-plugin/src/test/resources/unit/alter-by-xpath-test/alter-by-xpath-pom.xml
Wed Oct 1 14:45:06 2008
@@ -0,0 +1,25 @@
+<project>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-plugin-api</artifactId>
+ <version>2.0</version>
+ </dependency>
+ <dependency>
+ <groupId>dom4j</groupId>
+ <artifactId>dom4j</artifactId>
+ <version>1.6.1</version>
+ <exclusions>
+ <exclusion>
+ <groupId>xom</groupId>
+ <artifactId>xom</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>commons-collections</groupId>
+ <artifactId>commons-collections</artifactId>
+ <version>3.2</version>
+ </dependency>
+ </dependencies>
+</project>
Added:
maven/sandbox/trunk/plugins/maven-pom-plugin/src/test/resources/unit/alter-by-xpath-test/plugin-pom.xml
URL:
http://svn.apache.org/viewvc/maven/sandbox/trunk/plugins/maven-pom-plugin/src/test/resources/unit/alter-by-xpath-test/plugin-pom.xml?rev=700940&view=auto
==============================================================================
---
maven/sandbox/trunk/plugins/maven-pom-plugin/src/test/resources/unit/alter-by-xpath-test/plugin-pom.xml
(added)
+++
maven/sandbox/trunk/plugins/maven-pom-plugin/src/test/resources/unit/alter-by-xpath-test/plugin-pom.xml
Wed Oct 1 14:45:06 2008
@@ -0,0 +1,34 @@
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you 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.
+-->
+
+<project>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-pom-plugin</artifactId>
+ <configuration>
+
<xpath>/project/dependencies/dependency[artifactId[.='commons-collections']]/version</xpath>
+ <newValue>1.1-SNAPSHOT</newValue>
+
<projectFile>${basedir}/target/test-files/unit/alter-by-xpath-test/alter-by-xpath-pom.xml</projectFile>
+ <failFast>true</failFast>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>