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

svn commit: r390024 - in /maven/plugins/trunk/maven-release-plugin: pom.xml src/test/java/org/apache/maven/plugins/release/PrepareReleaseMojoTest.java

Author: carlos
Date: Wed Mar 29 23:53:30 2006
New Revision: 390024

URL: http://svn.apache.org/viewcvs?rev=390024&view=rev
Log:
Add tests for PrepareReleaseMojo.writePom

Added:
    maven/plugins/trunk/maven-release-plugin/src/test/java/org/apache/maven/plugins/release/PrepareReleaseMojoTest.java   (with props)
Modified:
    maven/plugins/trunk/maven-release-plugin/pom.xml

Modified: maven/plugins/trunk/maven-release-plugin/pom.xml
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-release-plugin/pom.xml?rev=390024&r1=390023&r2=390024&view=diff
==============================================================================
--- maven/plugins/trunk/maven-release-plugin/pom.xml (original)
+++ maven/plugins/trunk/maven-release-plugin/pom.xml Wed Mar 29 23:53:30 2006
@@ -1,4 +1,6 @@
-<project>
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
   <parent>
     <artifactId>maven-plugins</artifactId>
     <groupId>org.apache.maven.plugins</groupId>
@@ -89,6 +91,18 @@
       <groupId>org.apache.maven.scm</groupId>
       <artifactId>maven-scm-provider-svnexe</artifactId>
       <version>1.0-beta-3-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>jmock</groupId>
+      <artifactId>jmock-cglib</artifactId>
+      <version>1.0.1</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven.scm</groupId>
+      <artifactId>maven-scm-test</artifactId>
+      <version>1.0-beta-3-SNAPSHOT</version>
+      <scope>test</scope>
     </dependency>
     
   </dependencies>

Added: maven/plugins/trunk/maven-release-plugin/src/test/java/org/apache/maven/plugins/release/PrepareReleaseMojoTest.java
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-release-plugin/src/test/java/org/apache/maven/plugins/release/PrepareReleaseMojoTest.java?rev=390024&view=auto
==============================================================================
--- maven/plugins/trunk/maven-release-plugin/src/test/java/org/apache/maven/plugins/release/PrepareReleaseMojoTest.java (added)
+++ maven/plugins/trunk/maven-release-plugin/src/test/java/org/apache/maven/plugins/release/PrepareReleaseMojoTest.java Wed Mar 29 23:53:30 2006
@@ -0,0 +1,126 @@
+package org.apache.maven.plugins.release;
+
+/*
+ * Copyright 2001-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 java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+
+import org.apache.maven.model.Contributor;
+import org.apache.maven.model.Model;
+import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugins.release.helpers.ScmHelper;
+import org.apache.maven.scm.ScmException;
+import org.apache.maven.scm.manager.ScmManager;
+import org.apache.maven.scm.manager.ScmManagerStub;
+import org.codehaus.plexus.PlexusTestCase;
+import org.jmock.cglib.Mock;
+import org.jmock.core.constraint.IsAnything;
+import org.jmock.core.matcher.MethodNameMatcher;
+import org.jmock.core.stub.ReturnStub;
+import org.jmock.core.stub.ThrowStub;
+
+/**
+ * Test for PrepareReleaseMojo
+ * 
+ * @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
+ * @version $Id$
+ */
+public class PrepareReleaseMojoTest
+    extends PlexusTestCase
+{
+
+    private PrepareReleaseMojo mojo;
+
+    private Mock scmHelperMock;
+
+    private ScmManager scmManager;
+
+    protected void setUp()
+        throws Exception
+    {
+        super.setUp();
+        mojo = new PrepareReleaseMojo();
+        mojo.basedir = new File( getBasedir(), "target/test" );
+        mojo.basedir.mkdirs();
+
+        scmManager = new ScmManagerStub();
+
+        scmHelperMock = new Mock( ScmHelper.class );
+        ScmHelper scmHelper = (ScmHelper) scmHelperMock.proxy();
+        mojo.setScmHelper( scmHelper );
+        mojo.setScmManager( scmManager );
+    }
+
+    /**
+     * Test for writePom with special characters in the pom
+     * @throws Exception
+     */
+    public void testWritePom()
+        throws Exception
+    {
+        Model model = new Model();
+        Contributor contributor = new Contributor();
+        contributor.setName( "special chars áéñ" );
+        model.addContributor( contributor );
+        File file = new File( mojo.basedir, "testWritePom.xml" );
+
+        scmHelperMock.expects( new MethodNameMatcher( new IsAnything() ) );
+        scmHelperMock.expects( new MethodNameMatcher( "getScmManager" ) ).will( new ReturnStub( scmManager ) );
+
+        mojo.writePom( file, model, "version" );
+
+        MavenXpp3Reader pomReader = new MavenXpp3Reader();
+
+        Model readModel = pomReader.read( new BufferedReader( new FileReader( file ) ) );
+        Contributor readContributor = (Contributor) readModel.getContributors().get( 0 );
+        assertEquals( contributor.getName(), readContributor.getName() );
+        System.out.println( readContributor.getName() );
+
+        scmHelperMock.verify();
+    }
+
+    /**
+     * Test for writePom when the ScmHelper throws a ScmException
+     * @throws Exception
+     */
+    public void testWritePomWithScmException()
+        throws Exception
+    {
+        Model model = new Model();
+        File file = new File( mojo.basedir, "testWritePomWithScmException.xml" );
+
+        scmHelperMock.expects( new MethodNameMatcher( new IsAnything() ) );
+        scmHelperMock.expects( new MethodNameMatcher( "getScmManager" ) ).will( new ReturnStub( scmManager ) );
+        scmHelperMock.expects( new MethodNameMatcher( "requiresEditMode" ) )
+            .will( new ThrowStub( new ScmException( "testing" ) ) );
+
+        try
+        {
+            mojo.writePom( file, model, "version" );
+            fail( "MojoExecutionException was not thrown" );
+        }
+        catch ( MojoExecutionException e )
+        {
+            // expected
+        }
+
+        scmHelperMock.verify();
+    }
+
+}

Propchange: maven/plugins/trunk/maven-release-plugin/src/test/java/org/apache/maven/plugins/release/PrepareReleaseMojoTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-release-plugin/src/test/java/org/apache/maven/plugins/release/PrepareReleaseMojoTest.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"