Index: C:/development/maven/maven-release-plugin/src/test/java/org/apache/maven/plugins/release/phase/ScmCommitPhaseTest.java =================================================================== --- C:/development/maven/maven-release-plugin/src/test/java/org/apache/maven/plugins/release/phase/ScmCommitPhaseTest.java (revision 440387) +++ C:/development/maven/maven-release-plugin/src/test/java/org/apache/maven/plugins/release/phase/ScmCommitPhaseTest.java (working copy) @@ -16,6 +16,13 @@ * limitations under the License. */ +import java.io.File; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import java.util.Properties; + import org.apache.maven.plugins.release.ReleaseExecutionException; import org.apache.maven.plugins.release.ReleaseFailureException; import org.apache.maven.plugins.release.config.ReleaseConfiguration; @@ -33,6 +40,8 @@ import org.apache.maven.scm.provider.ScmProvider; import org.apache.maven.scm.provider.ScmProviderStub; import org.apache.maven.scm.repository.ScmRepositoryException; +import org.apache.maven.settings.Profile; +import org.apache.maven.settings.Settings; import org.jmock.Mock; import org.jmock.core.Constraint; import org.jmock.core.constraint.IsAnything; @@ -43,273 +52,311 @@ import org.jmock.core.stub.ReturnStub; import org.jmock.core.stub.ThrowStub; -import java.io.File; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; - /** * Test the SCM commit phase. - * + * * @author Brett Porter */ -public class ScmCommitPhaseTest - extends AbstractReleaseTestCase -{ +public class ScmCommitPhaseTest extends AbstractReleaseTestCase { private static final String PREFIX = "[maven-release-plugin] prepare release "; private static final File[] EMPTY_FILE_ARRAY = new File[0]; - protected void setUp() - throws Exception - { + protected void setUp() throws Exception { super.setUp(); - phase = (ReleasePhase) lookup( ReleasePhase.ROLE, "scm-commit-release" ); + phase = (ReleasePhase) lookup(ReleasePhase.ROLE, "scm-commit-release"); } - public void testCommit() - throws Exception - { - ReleaseConfiguration config = createConfigurationFromProjects( "scm-commit/", "single-pom", false ); - config.setUrl( "scm-url" ); - MavenProject rootProject = (MavenProject) config.getReactorProjects().get( 0 ); - config.setWorkingDirectory( rootProject.getFile().getParentFile() ); - config.setReleaseLabel( "release-label" ); + public void testCommit() throws Exception { + ReleaseConfiguration config = createConfigurationFromProjects( + "scm-commit/", "single-pom", false); + config.setUrl("scm-url"); + MavenProject rootProject = (MavenProject) config.getReactorProjects() + .get(0); + config.setWorkingDirectory(rootProject.getFile().getParentFile()); + config.setReleaseLabel("release-label"); - ScmFileSet fileSet = new ScmFileSet( rootProject.getFile().getParentFile(), rootProject.getFile() ); + ScmFileSet fileSet = new ScmFileSet(rootProject.getFile() + .getParentFile(), rootProject.getFile()); - Mock scmProviderMock = new Mock( ScmProvider.class ); - Constraint[] arguments = new Constraint[]{new IsAnything(), new IsScmFileSetEquals( fileSet ), new IsNull(), - new IsEqual( PREFIX + "release-label" )}; - scmProviderMock.expects( new InvokeOnceMatcher() ).method( "checkIn" ).with( arguments ).will( - new ReturnStub( new CheckInScmResult( "...", Collections.singletonList( rootProject.getFile() ) ) ) ); + Mock scmProviderMock = new Mock(ScmProvider.class); + Constraint[] arguments = new Constraint[] { new IsAnything(), + new IsScmFileSetEquals(fileSet), new IsNull(), + new IsEqual(PREFIX + "release-label") }; + scmProviderMock.expects(new InvokeOnceMatcher()).method("checkIn") + .with(arguments).will( + new ReturnStub(new CheckInScmResult("...", Collections + .singletonList(rootProject.getFile())))); - ScmManagerStub stub = (ScmManagerStub) lookup( ScmManager.ROLE ); - stub.setScmProvider( (ScmProvider) scmProviderMock.proxy() ); + ScmManagerStub stub = (ScmManagerStub) lookup(ScmManager.ROLE); + stub.setScmProvider((ScmProvider) scmProviderMock.proxy()); - phase.execute( config ); + phase.execute(config); - assertTrue( true ); + assertTrue(true); } - public void testCommitMultiModule() - throws Exception - { - ReleaseConfiguration config = createConfigurationFromProjects( "scm-commit/", "multiple-poms", false ); - config.setUrl( "scm-url" ); - MavenProject rootProject = (MavenProject) config.getReactorProjects().get( 0 ); - config.setWorkingDirectory( rootProject.getFile().getParentFile() ); - config.setReleaseLabel( "release-label" ); + public void testCommitMultiModule() throws Exception { + ReleaseConfiguration config = createConfigurationFromProjects( + "scm-commit/", "multiple-poms", false); + config.setUrl("scm-url"); + MavenProject rootProject = (MavenProject) config.getReactorProjects() + .get(0); + config.setWorkingDirectory(rootProject.getFile().getParentFile()); + config.setReleaseLabel("release-label"); List poms = new ArrayList(); - for ( Iterator i = config.getReactorProjects().iterator(); i.hasNext(); ) - { + for (Iterator i = config.getReactorProjects().iterator(); i.hasNext();) { MavenProject project = (MavenProject) i.next(); - poms.add( project.getFile() ); + poms.add(project.getFile()); } - ScmFileSet fileSet = - new ScmFileSet( rootProject.getFile().getParentFile(), (File[]) poms.toArray( EMPTY_FILE_ARRAY ) ); + ScmFileSet fileSet = new ScmFileSet(rootProject.getFile() + .getParentFile(), (File[]) poms.toArray(EMPTY_FILE_ARRAY)); - Mock scmProviderMock = new Mock( ScmProvider.class ); - Constraint[] arguments = new Constraint[]{new IsAnything(), new IsScmFileSetEquals( fileSet ), new IsNull(), - new IsEqual( PREFIX + "release-label" )}; - scmProviderMock.expects( new InvokeOnceMatcher() ).method( "checkIn" ).with( arguments ).will( - new ReturnStub( new CheckInScmResult( "...", Collections.singletonList( rootProject.getFile() ) ) ) ); + Mock scmProviderMock = new Mock(ScmProvider.class); + Constraint[] arguments = new Constraint[] { new IsAnything(), + new IsScmFileSetEquals(fileSet), new IsNull(), + new IsEqual(PREFIX + "release-label") }; + scmProviderMock.expects(new InvokeOnceMatcher()).method("checkIn") + .with(arguments).will( + new ReturnStub(new CheckInScmResult("...", Collections + .singletonList(rootProject.getFile())))); - ScmManagerStub stub = (ScmManagerStub) lookup( ScmManager.ROLE ); - stub.setScmProvider( (ScmProvider) scmProviderMock.proxy() ); + ScmManagerStub stub = (ScmManagerStub) lookup(ScmManager.ROLE); + stub.setScmProvider((ScmProvider) scmProviderMock.proxy()); - phase.execute( config ); + phase.execute(config); - assertTrue( true ); + assertTrue(true); } - public void testCommitDevelopment() - throws Exception - { - phase = (ReleasePhase) lookup( ReleasePhase.ROLE, "scm-commit-development" ); + public void testCommitMultiModuleWinNtCVS() throws Exception { + ReleaseConfiguration config = createConfigurationFromProjects( + "scm-commit/", "multiple-poms", false); + config.setUrl("scm-url"); + MavenProject rootProject = (MavenProject) config.getReactorProjects() + .get(0); + config.setWorkingDirectory(rootProject.getFile().getParentFile()); + config.setReleaseLabel("release-label"); - ReleaseConfiguration config = createConfigurationFromProjects( "scm-commit/", "single-pom", false ); - config.setUrl( "scm-url" ); - MavenProject rootProject = (MavenProject) config.getReactorProjects().get( 0 ); - config.setWorkingDirectory( rootProject.getFile().getParentFile() ); - config.setReleaseLabel( "release-label" ); + // set up the users profile. - ScmFileSet fileSet = new ScmFileSet( rootProject.getFile().getParentFile(), rootProject.getFile() ); + // set the winntcvs option + Properties props = new Properties(); + props.setProperty(ScmCommitPhase.WINNTCVS, ScmCommitPhase.TRUE); - Mock scmProviderMock = new Mock( ScmProvider.class ); - Constraint[] arguments = new Constraint[]{new IsAnything(), new IsScmFileSetEquals( fileSet ), new IsNull(), - new IsEqual( "[maven-release-plugin] prepare for next development iteration" )}; - scmProviderMock.expects( new InvokeOnceMatcher() ).method( "checkIn" ).with( arguments ).will( - new ReturnStub( new CheckInScmResult( "...", Collections.singletonList( rootProject.getFile() ) ) ) ); + Profile p = new Profile(); + p.setId("test"); + p.setProperties(props); - ScmManagerStub stub = (ScmManagerStub) lookup( ScmManager.ROLE ); - stub.setScmProvider( (ScmProvider) scmProviderMock.proxy() ); + Settings settings = new Settings(); + settings.addActiveProfile("test"); + settings.addProfile(p); - phase.execute( config ); + config.setSettings(settings); - assertTrue( true ); + Mock scmProviderMock = new Mock(ScmProvider.class); + + MavenProject project; + Constraint[] arguments; + ScmFileSet fileSet; + + // List poms = new ArrayList(); + for (Iterator i = config.getReactorProjects().iterator(); i.hasNext();) { + project = (MavenProject) i.next(); + + fileSet = new ScmFileSet(rootProject.getFile() + .getParentFile(), new File[] { project.getFile() }); + + arguments = new Constraint[] { new IsAnything(), + new IsScmFileSetEquals(fileSet), new IsNull(), + new IsEqual(PREFIX + "release-label") }; + + scmProviderMock.expects(new InvokeOnceMatcher()).method("checkIn") + .with(arguments).will( + new ReturnStub(new CheckInScmResult("...", + Collections.singletonList(rootProject + .getFile())))); + } + + ScmManagerStub stub = (ScmManagerStub) lookup(ScmManager.ROLE); + stub.setScmProvider((ScmProvider) scmProviderMock.proxy()); + + phase.execute(config); + + assertTrue(true); } - public void testCommitNoReleaseLabel() - throws Exception - { - ReleaseConfiguration config = createConfigurationFromProjects( "scm-commit/", "single-pom", false ); + public void testCommitDevelopment() throws Exception { + phase = (ReleasePhase) lookup(ReleasePhase.ROLE, + "scm-commit-development"); - try - { - phase.execute( config ); - fail( "Should have thrown an exception" ); + ReleaseConfiguration config = createConfigurationFromProjects( + "scm-commit/", "single-pom", false); + config.setUrl("scm-url"); + MavenProject rootProject = (MavenProject) config.getReactorProjects() + .get(0); + config.setWorkingDirectory(rootProject.getFile().getParentFile()); + config.setReleaseLabel("release-label"); + + ScmFileSet fileSet = new ScmFileSet(rootProject.getFile() + .getParentFile(), rootProject.getFile()); + + Mock scmProviderMock = new Mock(ScmProvider.class); + Constraint[] arguments = new Constraint[] { + new IsAnything(), + new IsScmFileSetEquals(fileSet), + new IsNull(), + new IsEqual( + "[maven-release-plugin] prepare for next development iteration") }; + scmProviderMock.expects(new InvokeOnceMatcher()).method("checkIn") + .with(arguments).will( + new ReturnStub(new CheckInScmResult("...", Collections + .singletonList(rootProject.getFile())))); + + ScmManagerStub stub = (ScmManagerStub) lookup(ScmManager.ROLE); + stub.setScmProvider((ScmProvider) scmProviderMock.proxy()); + + phase.execute(config); + + assertTrue(true); + } + + public void testCommitNoReleaseLabel() throws Exception { + ReleaseConfiguration config = createConfigurationFromProjects( + "scm-commit/", "single-pom", false); + + try { + phase.execute(config); + fail("Should have thrown an exception"); + } catch (ReleaseFailureException e) { + assertTrue(true); } - catch ( ReleaseFailureException e ) - { - assertTrue( true ); - } } - public void testSimulateCommit() - throws Exception - { - ReleaseConfiguration config = createConfigurationFromProjects( "scm-commit/", "single-pom", false ); - config.setUrl( "scm-url" ); - MavenProject rootProject = (MavenProject) config.getReactorProjects().get( 0 ); - config.setWorkingDirectory( rootProject.getFile().getParentFile() ); - config.setReleaseLabel( "release-label" ); + public void testSimulateCommit() throws Exception { + ReleaseConfiguration config = createConfigurationFromProjects( + "scm-commit/", "single-pom", false); + config.setUrl("scm-url"); + MavenProject rootProject = (MavenProject) config.getReactorProjects() + .get(0); + config.setWorkingDirectory(rootProject.getFile().getParentFile()); + config.setReleaseLabel("release-label"); - Mock scmProviderMock = new Mock( ScmProvider.class ); - scmProviderMock.expects( new TestFailureMatcher( "Shouldn't have called checkIn" ) ).method( "checkIn" ); + Mock scmProviderMock = new Mock(ScmProvider.class); + scmProviderMock.expects( + new TestFailureMatcher("Shouldn't have called checkIn")) + .method("checkIn"); - ScmManagerStub stub = (ScmManagerStub) lookup( ScmManager.ROLE ); - stub.setScmProvider( (ScmProvider) scmProviderMock.proxy() ); + ScmManagerStub stub = (ScmManagerStub) lookup(ScmManager.ROLE); + stub.setScmProvider((ScmProvider) scmProviderMock.proxy()); - phase.simulate( config ); + phase.simulate(config); - assertTrue( true ); + assertTrue(true); } - public void testSimulateCommitNoReleaseLabel() - throws Exception - { - ReleaseConfiguration config = createConfigurationFromProjects( "scm-commit/", "single-pom", false ); + public void testSimulateCommitNoReleaseLabel() throws Exception { + ReleaseConfiguration config = createConfigurationFromProjects( + "scm-commit/", "single-pom", false); - try - { - phase.simulate( config ); - fail( "Should have thrown an exception" ); + try { + phase.simulate(config); + fail("Should have thrown an exception"); + } catch (ReleaseFailureException e) { + assertTrue(true); } - catch ( ReleaseFailureException e ) - { - assertTrue( true ); - } } - public void testNoSuchScmProviderExceptionThrown() - throws Exception - { + public void testNoSuchScmProviderExceptionThrown() throws Exception { ReleaseConfiguration releaseConfiguration = createReleaseConfiguration(); - Mock scmManagerMock = new Mock( ScmManager.class ); - scmManagerMock.expects( new InvokeOnceMatcher() ).method( "makeScmRepository" ).with( - new IsEqual( "scm-url" ) ).will( new ThrowStub( new NoSuchScmProviderException( "..." ) ) ); + Mock scmManagerMock = new Mock(ScmManager.class); + scmManagerMock.expects(new InvokeOnceMatcher()).method( + "makeScmRepository").with(new IsEqual("scm-url")).will( + new ThrowStub(new NoSuchScmProviderException("..."))); ScmManager scmManager = (ScmManager) scmManagerMock.proxy(); - DefaultScmRepositoryConfigurator configurator = - (DefaultScmRepositoryConfigurator) lookup( ScmRepositoryConfigurator.ROLE ); - configurator.setScmManager( scmManager ); + DefaultScmRepositoryConfigurator configurator = (DefaultScmRepositoryConfigurator) lookup(ScmRepositoryConfigurator.ROLE); + configurator.setScmManager(scmManager); - try - { - phase.execute( releaseConfiguration ); + try { + phase.execute(releaseConfiguration); - fail( "Status check should have failed" ); + fail("Status check should have failed"); + } catch (ReleaseExecutionException e) { + assertEquals("check cause", NoSuchScmProviderException.class, e + .getCause().getClass()); } - catch ( ReleaseExecutionException e ) - { - assertEquals( "check cause", NoSuchScmProviderException.class, e.getCause().getClass() ); - } } - public void testScmRepositoryExceptionThrown() - throws Exception - { + public void testScmRepositoryExceptionThrown() throws Exception { ReleaseConfiguration releaseConfiguration = createReleaseConfiguration(); - Mock scmManagerMock = new Mock( ScmManager.class ); - scmManagerMock.expects( new InvokeOnceMatcher() ).method( "makeScmRepository" ).with( - new IsEqual( "scm-url" ) ).will( new ThrowStub( new ScmRepositoryException( "..." ) ) ); + Mock scmManagerMock = new Mock(ScmManager.class); + scmManagerMock.expects(new InvokeOnceMatcher()).method( + "makeScmRepository").with(new IsEqual("scm-url")).will( + new ThrowStub(new ScmRepositoryException("..."))); ScmManager scmManager = (ScmManager) scmManagerMock.proxy(); - DefaultScmRepositoryConfigurator configurator = - (DefaultScmRepositoryConfigurator) lookup( ScmRepositoryConfigurator.ROLE ); - configurator.setScmManager( scmManager ); + DefaultScmRepositoryConfigurator configurator = (DefaultScmRepositoryConfigurator) lookup(ScmRepositoryConfigurator.ROLE); + configurator.setScmManager(scmManager); - try - { - phase.execute( releaseConfiguration ); + try { + phase.execute(releaseConfiguration); - fail( "Status check should have failed" ); + fail("Status check should have failed"); + } catch (ReleaseScmRepositoryException e) { + assertNull("Check no additional cause", e.getCause()); } - catch ( ReleaseScmRepositoryException e ) - { - assertNull( "Check no additional cause", e.getCause() ); - } } - public void testScmExceptionThrown() - throws Exception - { + public void testScmExceptionThrown() throws Exception { ReleaseConfiguration releaseConfiguration = createReleaseConfiguration(); - Mock scmProviderMock = new Mock( ScmProvider.class ); - scmProviderMock.expects( new InvokeOnceMatcher() ).method( "checkIn" ).will( - new ThrowStub( new ScmException( "..." ) ) ); + Mock scmProviderMock = new Mock(ScmProvider.class); + scmProviderMock.expects(new InvokeOnceMatcher()).method("checkIn") + .will(new ThrowStub(new ScmException("..."))); - ScmManagerStub stub = (ScmManagerStub) lookup( ScmManager.ROLE ); - stub.setScmProvider( (ScmProvider) scmProviderMock.proxy() ); + ScmManagerStub stub = (ScmManagerStub) lookup(ScmManager.ROLE); + stub.setScmProvider((ScmProvider) scmProviderMock.proxy()); - try - { - phase.execute( releaseConfiguration ); + try { + phase.execute(releaseConfiguration); - fail( "Status check should have failed" ); + fail("Status check should have failed"); + } catch (ReleaseExecutionException e) { + assertEquals("check cause", ScmException.class, e.getCause() + .getClass()); } - catch ( ReleaseExecutionException e ) - { - assertEquals( "check cause", ScmException.class, e.getCause().getClass() ); - } } - public void testScmResultFailure() - throws Exception - { + public void testScmResultFailure() throws Exception { ReleaseConfiguration releaseConfiguration = createReleaseConfiguration(); - ScmManager scmManager = (ScmManager) lookup( ScmManager.ROLE ); - ScmProviderStub providerStub = (ScmProviderStub) scmManager.getProviderByUrl( releaseConfiguration.getUrl() ); + ScmManager scmManager = (ScmManager) lookup(ScmManager.ROLE); + ScmProviderStub providerStub = (ScmProviderStub) scmManager + .getProviderByUrl(releaseConfiguration.getUrl()); - providerStub.setCheckInScmResult( new CheckInScmResult( "", "", "", false ) ); + providerStub + .setCheckInScmResult(new CheckInScmResult("", "", "", false)); - try - { - phase.execute( releaseConfiguration ); + try { + phase.execute(releaseConfiguration); - fail( "Commit should have failed" ); + fail("Commit should have failed"); + } catch (ReleaseScmCommandException e) { + assertNull("check no other cause", e.getCause()); } - catch ( ReleaseScmCommandException e ) - { - assertNull( "check no other cause", e.getCause() ); - } } - private ReleaseConfiguration createReleaseConfiguration() - throws Exception - { - ReleaseConfiguration config = createConfigurationFromProjects( "scm-commit/", "single-pom", false ); - config.setUrl( "scm-url" ); - config.setReleaseLabel( "release-label" ); - config.setWorkingDirectory( getTestFile( "target/test/checkout" ) ); + private ReleaseConfiguration createReleaseConfiguration() throws Exception { + ReleaseConfiguration config = createConfigurationFromProjects( + "scm-commit/", "single-pom", false); + config.setUrl("scm-url"); + config.setReleaseLabel("release-label"); + config.setWorkingDirectory(getTestFile("target/test/checkout")); return config; }