Added: maven/scm/trunk/maven-scm-providers/maven-scm-provider-accurev/src/test/java/org/apache/maven/scm/provider/accurev/command/login/AccuRevLoginCommandTest.java URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-providers/maven-scm-provider-accurev/src/test/java/org/apache/maven/scm/provider/accurev/command/login/AccuRevLoginCommandTest.java?rev=980673&view=auto ============================================================================== --- maven/scm/trunk/maven-scm-providers/maven-scm-provider-accurev/src/test/java/org/apache/maven/scm/provider/accurev/command/login/AccuRevLoginCommandTest.java (added) +++ maven/scm/trunk/maven-scm-providers/maven-scm-provider-accurev/src/test/java/org/apache/maven/scm/provider/accurev/command/login/AccuRevLoginCommandTest.java Fri Jul 30 08:14:27 2010 @@ -0,0 +1,133 @@ +package org.apache.maven.scm.provider.accurev.command.login; + +/* + * 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 static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertThat; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyString; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.io.File; + +import org.apache.maven.scm.CommandParameters; +import org.apache.maven.scm.ScmFileSet; +import org.apache.maven.scm.command.login.LoginScmResult; +import org.apache.maven.scm.provider.accurev.command.AbstractAccuRevCommandTest; +import org.junit.Test; + +public class AccuRevLoginCommandTest + extends AbstractAccuRevCommandTest +{ + + @Test + public void testWhenNotLoggedIn() + throws Exception + { + + repo.setUser( "myUser" ); + repo.setPassword( "aPassword" ); + info.setUser( "(not logged in)" ); + when( accurev.info( any( File.class ) ) ).thenReturn( info ); + when( accurev.login( "myUser", "aPassword" ) ).thenReturn( true ); + AccuRevLoginCommand command = new AccuRevLoginCommand( getLogger() ); + + LoginScmResult result = command.login( repo, new ScmFileSet( basedir ), new CommandParameters() ); + + assertThat( result.isSuccess(), is( true ) ); + verify( accurev ).login( "myUser", "aPassword" ); + + } + + @Test + public void testWhenAlreadyLoggedInAsSomeoneElse() + throws Exception + { + repo.setUser( "myUser" ); + repo.setPassword( "aPassword" ); + info.setUser( "A.N.Other" ); + when( accurev.info( any( File.class ) ) ).thenReturn( info ); + when( accurev.login( "myUser", "aPassword" ) ).thenReturn( true ); + AccuRevLoginCommand command = new AccuRevLoginCommand( getLogger() ); + + LoginScmResult result = command.login( repo, new ScmFileSet( basedir ), new CommandParameters() ); + + assertThat( result.isSuccess(), is( true ) ); + verify( accurev ).login( "myUser", "aPassword" ); + + } + + @Test + public void testWhenAlreadyLoggedInAsRequiredUser() + throws Exception + { + + repo.setUser( "myUser" ); + repo.setPassword( "aPassword" ); + info.setUser( "myUser" ); + when( accurev.info( any( File.class ) ) ).thenReturn( info ); + AccuRevLoginCommand command = new AccuRevLoginCommand( getLogger() ); + + LoginScmResult result = command.login( repo, new ScmFileSet( basedir ), new CommandParameters() ); + + assertThat( result.isSuccess(), is( true ) ); + // This is an important case as logging in will start an expiry timer + // that might be shorter than the current expiry timer! + verify( accurev, never() ).login( eq( "myUser" ), anyString() ); + + } + + @Test + public void testWhenNoUserSuppliedAndAlreadyLoggedIn() + throws Exception + { + + repo.setUser( null ); + info.setUser( "anyUser" ); + when( accurev.info( any( File.class ) ) ).thenReturn( info ); + AccuRevLoginCommand command = new AccuRevLoginCommand( getLogger() ); + + LoginScmResult result = command.login( repo, new ScmFileSet( basedir ), new CommandParameters() ); + + assertThat( result.isSuccess(), is( true ) ); + verify( accurev, never() ).login( anyString(), anyString() ); + + } + + @Test + public void testFailsWhenNoUserSuppliedAndNotLoggedIn() + throws Exception + { + + repo.setUser( null ); + info.setUser( "(not logged in)" ); + when( accurev.info( any( File.class ) ) ).thenReturn( info ); + AccuRevLoginCommand command = new AccuRevLoginCommand( getLogger() ); + + LoginScmResult result = command.login( repo, new ScmFileSet( basedir ), new CommandParameters() ); + + assertThat( result.isSuccess(), is( false ) ); + verify( accurev, never() ).login( anyString(), anyString() ); + + } +}
Propchange: maven/scm/trunk/maven-scm-providers/maven-scm-provider-accurev/src/test/java/org/apache/maven/scm/provider/accurev/command/login/AccuRevLoginCommandTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/scm/trunk/maven-scm-providers/maven-scm-provider-accurev/src/test/java/org/apache/maven/scm/provider/accurev/command/login/AccuRevLoginCommandTest.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Modified: maven/scm/trunk/maven-scm-providers/maven-scm-provider-accurev/src/test/java/org/apache/maven/scm/provider/accurev/command/remove/AccuRevRemoveCommandTest.java URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-providers/maven-scm-provider-accurev/src/test/java/org/apache/maven/scm/provider/accurev/command/remove/AccuRevRemoveCommandTest.java?rev=980673&r1=980672&r2=980673&view=diff ============================================================================== --- maven/scm/trunk/maven-scm-providers/maven-scm-provider-accurev/src/test/java/org/apache/maven/scm/provider/accurev/command/remove/AccuRevRemoveCommandTest.java (original) +++ maven/scm/trunk/maven-scm-providers/maven-scm-provider-accurev/src/test/java/org/apache/maven/scm/provider/accurev/command/remove/AccuRevRemoveCommandTest.java Fri Jul 30 08:14:27 2010 @@ -20,12 +20,13 @@ package org.apache.maven.scm.provider.ac */ import static org.apache.maven.scm.ScmFileMatcher.assertHasScmFile; -import static org.apache.maven.scm.provider.accurev.AddElementsAction.addElementsTo; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; import static org.junit.Assert.assertThat; +import static org.mockito.Mockito.when; import java.io.File; +import java.util.Collections; import java.util.List; import org.apache.maven.scm.CommandParameter; @@ -33,37 +34,23 @@ import org.apache.maven.scm.CommandParam import org.apache.maven.scm.ScmFileSet; import org.apache.maven.scm.ScmFileStatus; import org.apache.maven.scm.command.remove.RemoveScmResult; -import org.apache.maven.scm.provider.accurev.AccuRevScmProviderRepository; import org.apache.maven.scm.provider.accurev.command.AbstractAccuRevCommandTest; -import org.jmock.Expectations; import org.junit.Test; public class AccuRevRemoveCommandTest extends AbstractAccuRevCommandTest { - @SuppressWarnings("unchecked") + @SuppressWarnings( "unchecked" ) @Test public void testRemove() throws Exception { final ScmFileSet testFileSet = new ScmFileSet( basedir, new File( "src/main/java/Foo.java" ) ); - context.checking( new Expectations() - { - { - one( accurev ).defunct( with( basedir ), with( testFileSet.getFileList() ), with( "A deleted file" ), - with( any( List.class ) ) ); - will( doAll( addElementsTo( 3, new File( "removed/file" ) ), returnValue( true ) ) ); - inSequence( sequence ); - - } - } ); - - AccuRevScmProviderRepository repo = new AccuRevScmProviderRepository(); - repo.setStreamName( "myStream" ); - repo.setAccuRev( accurev ); - repo.setProjectPath( "/project/dir" ); + List<File> removedFiles = Collections.singletonList( new File( "removed/file" ) ); + + when( accurev.defunct( basedir, testFileSet.getFileList(), "A deleted file" ) ).thenReturn( removedFiles ); AccuRevRemoveCommand command = new AccuRevRemoveCommand( getLogger() ); @@ -71,35 +58,19 @@ public class AccuRevRemoveCommandTest commandParameters.setString( CommandParameter.MESSAGE, "A deleted file" ); RemoveScmResult result = command.remove( repo, testFileSet, commandParameters ); - context.assertIsSatisfied(); - assertThat( result.isSuccess(), is( true ) ); assertThat( result.getRemovedFiles().size(), is( 1 ) ); assertHasScmFile( result.getRemovedFiles(), "removed/file", ScmFileStatus.DELETED ); } - @SuppressWarnings("unchecked") + @SuppressWarnings( "unchecked" ) @Test public void testAddFailed() throws Exception { final ScmFileSet testFileSet = new ScmFileSet( basedir, new File( "src/main/java/Foo.java" ) ); - context.checking( new Expectations() - { - { - one( accurev ).defunct( with( basedir ), with( testFileSet.getFileList() ), with( "A deleted file" ), - with( any( List.class ) ) ); - will( returnValue( false ) ); - inSequence( sequence ); - - } - } ); - - AccuRevScmProviderRepository repo = new AccuRevScmProviderRepository(); - repo.setStreamName( "myStream" ); - repo.setAccuRev( accurev ); - repo.setProjectPath( "/project/dir" ); + when( accurev.defunct( basedir, testFileSet.getFileList(), "A deleted file" ) ).thenReturn( null ); AccuRevRemoveCommand command = new AccuRevRemoveCommand( getLogger() ); @@ -107,8 +78,6 @@ public class AccuRevRemoveCommandTest commandParameters.setString( CommandParameter.MESSAGE, "A deleted file" ); RemoveScmResult result = command.remove( repo, testFileSet, commandParameters ); - context.assertIsSatisfied(); - assertThat( result.isSuccess(), is( false ) ); assertThat( result.getProviderMessage(), notNullValue() ); } Modified: maven/scm/trunk/maven-scm-providers/maven-scm-provider-accurev/src/test/java/org/apache/maven/scm/provider/accurev/command/status/AccuRevStatusCommandTest.java URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-providers/maven-scm-provider-accurev/src/test/java/org/apache/maven/scm/provider/accurev/command/status/AccuRevStatusCommandTest.java?rev=980673&r1=980672&r2=980673&view=diff ============================================================================== --- maven/scm/trunk/maven-scm-providers/maven-scm-provider-accurev/src/test/java/org/apache/maven/scm/provider/accurev/command/status/AccuRevStatusCommandTest.java (original) +++ maven/scm/trunk/maven-scm-providers/maven-scm-provider-accurev/src/test/java/org/apache/maven/scm/provider/accurev/command/status/AccuRevStatusCommandTest.java Fri Jul 30 08:14:27 2010 @@ -21,16 +21,19 @@ package org.apache.maven.scm.provider.ac import static org.apache.maven.scm.ScmFileMatcher.assertHasScmFile; import static org.apache.maven.scm.ScmFileMatcher.scmFile; -import static org.apache.maven.scm.provider.accurev.AddElementsAction.addElementsTo; -import static org.hamcrest.Matchers.allOf; import static org.hamcrest.Matchers.hasItem; import static org.hamcrest.Matchers.hasItems; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.notNullValue; import static org.junit.Assert.assertThat; +import static org.mockito.Matchers.anyListOf; +import static org.mockito.Matchers.argThat; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.when; import java.io.File; +import java.util.Arrays; import java.util.Collection; import java.util.List; @@ -39,17 +42,16 @@ import org.apache.maven.scm.ScmFile; import org.apache.maven.scm.ScmFileSet; import org.apache.maven.scm.ScmFileStatus; import org.apache.maven.scm.command.status.StatusScmResult; -import org.apache.maven.scm.provider.accurev.AccuRevScmProviderRepository; import org.apache.maven.scm.provider.accurev.AccuRevStat; +import org.apache.maven.scm.provider.accurev.CategorisedElements; import org.apache.maven.scm.provider.accurev.command.AbstractAccuRevCommandTest; -import org.jmock.Expectations; import org.junit.Test; public class AccuRevStatusCommandTest extends AbstractAccuRevCommandTest { - @SuppressWarnings("unchecked") + @SuppressWarnings( "unchecked" ) @Test public void testStatus() throws Exception @@ -57,67 +59,49 @@ public class AccuRevStatusCommandTest final ScmFileSet testFileSet = getScmFileSet(); - AccuRevScmProviderRepository repo = new AccuRevScmProviderRepository(); - repo.setStreamName( "myStream" ); - repo.setAccuRev( accurev ); - repo.setProjectPath( "/project/dir" ); - - context.checking( new Expectations() - { - { - File keptFile = new File( "kept/file" ); - File keptAdded = new File( "kept/added" ); - // this is the special one, it is returned by both the kept and defunct stat calls, so the command - // needs to filter it out. - File keptDefunct = new File( "kept/defunct" ); - File modifiedFile = new File( "modified/file" ); - File modifiedAdded = new File( "modified/added" ); - File missingFile = new File( "missing/file" ); - File externalFile = new File( "external/file" ); - - one( accurev ).stat( with( basedir ), with( testFileSet.getFileList() ), with( AccuRevStat.DEFUNCT ), - with( any( List.class ) ) ); - will( doAll( addElementsTo( 3, keptDefunct ), returnValue( true ) ) ); - - one( accurev ).stat( with( basedir ), with( testFileSet.getFileList() ), with( AccuRevStat.MODIFIED ), - with( any( List.class ) ) ); - will( doAll( addElementsTo( 3, modifiedFile, modifiedAdded ), returnValue( true ) ) ); - - one( accurev ).stat( with( basedir ), with( testFileSet.getFileList() ), with( AccuRevStat.KEPT ), - with( any( List.class ) ) ); - will( doAll( addElementsTo( 3, keptDefunct, keptFile, keptAdded ), returnValue( true ) ) ); - - one( accurev ).stat( with( basedir ), with( testFileSet.getFileList() ), with( AccuRevStat.MISSING ), - with( any( List.class ) ) ); - will( doAll( addElementsTo( 3, missingFile ), returnValue( true ) ) ); - - one( accurev ).stat( with( basedir ), with( testFileSet.getFileList() ), with( AccuRevStat.EXTERNAL ), - with( any( List.class ) ) ); - will( doAll( addElementsTo( 3, externalFile ), returnValue( true ) ) ); - - one( accurev ).statBackingStream( - with( basedir ), - (Collection<File>) with( allOf( hasItems( modifiedFile, - modifiedAdded, keptFile, - keptAdded ), - not( hasItem( keptDefunct ) ) ) ), - with( any( List.class ) ), with( any( List.class ) ) ); - will( doAll( addElementsTo( 2, modifiedFile, keptFile ), addElementsTo( 3, modifiedAdded, keptAdded ), - returnValue( true ) ) ); - - } - } ); + File keptFile = new File( "kept/file" ); + File keptAdded = new File( "kept/added" ); + // this is the special one, it is returned by both the kept and defunct stat calls, so the command + // needs to filter it out. + File keptDefunct = new File( "kept/defunct" ); + File modifiedFile = new File( "modified/file" ); + File modifiedAdded = new File( "modified/added" ); + File missingFile = new File( "missing/file" ); + File externalFile = new File( "external/file" ); + + when( accurev.stat( eq( basedir ), anyListOf( File.class ), eq( AccuRevStat.DEFUNCT ) ) ).thenReturn( + Arrays.asList( keptDefunct ) ); + when( accurev.stat( eq( basedir ), anyListOf( File.class ), eq( AccuRevStat.MODIFIED ) ) ).thenReturn( + Arrays.asList( modifiedFile,modifiedAdded ) ); + when( accurev.stat( eq( basedir ), anyListOf( File.class ), eq( AccuRevStat.KEPT ) ) ).thenReturn( + Arrays.asList( + keptDefunct, + keptFile, + keptAdded ) ); + + when( accurev.stat( eq( basedir ), anyListOf( File.class ), eq( AccuRevStat.MISSING ) ) ).thenReturn( + Arrays.asList( missingFile ) ); + + when( accurev.stat( eq( basedir ), anyListOf( File.class ), eq( AccuRevStat.EXTERNAL ) ) ).thenReturn( + Arrays.asList( externalFile ) ); + + CategorisedElements catElems = new CategorisedElements(); + catElems.getMemberElements().addAll( Arrays.asList( modifiedFile, keptFile ) ); + catElems.getNonMemberElements().addAll( Arrays.asList( modifiedAdded, keptAdded ) ); + when( + accurev.statBackingStream( eq( basedir ), (Collection<File>) argThat( hasItems( modifiedFile, + modifiedAdded, keptFile, + keptAdded ) ) ) ).thenReturn( + catElems ); AccuRevStatusCommand command = new AccuRevStatusCommand( getLogger() ); CommandParameters commandParameters = new CommandParameters(); StatusScmResult result = command.status( repo, testFileSet, commandParameters ); - context.assertIsSatisfied(); - assertThat( result.isSuccess(), is( true ) ); assertThat( result.getChangedFiles().size(), is( 7 ) ); - // Note the case.. without compiles under Eclipse but not sun JDK + assertThat( (List<ScmFile>) result.getChangedFiles(), not( hasItem( scmFile( "kept/defunct", ScmFileStatus.MODIFIED ) ) ) ); assertHasScmFile( result.getChangedFiles(), "kept/file", ScmFileStatus.MODIFIED ); @@ -130,7 +114,7 @@ public class AccuRevStatusCommandTest } - @SuppressWarnings("unchecked") + @SuppressWarnings( "unchecked" ) @Test public void testFailure() throws Exception @@ -138,31 +122,13 @@ public class AccuRevStatusCommandTest final ScmFileSet testFileSet = getScmFileSet(); - AccuRevScmProviderRepository repo = new AccuRevScmProviderRepository(); - repo.setStreamName( "myStream" ); - repo.setAccuRev( accurev ); - repo.setProjectPath( "/project/dir" ); - - context.checking( new Expectations() - { - { - one( accurev ).stat( with( basedir ), with( testFileSet.getFileList() ), with( AccuRevStat.MODIFIED ), - with( any( List.class ) ) ); - will( returnValue( false ) ); - - atMost( 4 ).of( accurev ).stat( with( basedir ), with( testFileSet.getFileList() ), - with( any( AccuRevStat.class ) ), with( any( List.class ) ) ); - will( returnValue( true ) ); - } - } ); + when( accurev.stat( basedir, testFileSet.getFileList(), AccuRevStat.MODIFIED ) ).thenReturn( null ); AccuRevStatusCommand command = new AccuRevStatusCommand( getLogger() ); CommandParameters commandParameters = new CommandParameters(); StatusScmResult result = command.status( repo, testFileSet, commandParameters ); - context.assertIsSatisfied(); - assertThat( result.isSuccess(), is( false ) ); assertThat( result.getProviderMessage(), notNullValue() ); Modified: maven/scm/trunk/maven-scm-providers/maven-scm-provider-accurev/src/test/java/org/apache/maven/scm/provider/accurev/command/tag/AccuRevTagCommandTckTest.java URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-providers/maven-scm-provider-accurev/src/test/java/org/apache/maven/scm/provider/accurev/command/tag/AccuRevTagCommandTckTest.java?rev=980673&r1=980672&r2=980673&view=diff ============================================================================== --- maven/scm/trunk/maven-scm-providers/maven-scm-provider-accurev/src/test/java/org/apache/maven/scm/provider/accurev/command/tag/AccuRevTagCommandTckTest.java (original) +++ maven/scm/trunk/maven-scm-providers/maven-scm-provider-accurev/src/test/java/org/apache/maven/scm/provider/accurev/command/tag/AccuRevTagCommandTckTest.java Fri Jul 30 08:14:27 2010 @@ -27,7 +27,6 @@ import org.apache.maven.scm.ScmTag; import org.apache.maven.scm.command.checkin.CheckInScmResult; import org.apache.maven.scm.command.checkout.CheckOutScmResult; import org.apache.maven.scm.command.tag.TagScmResult; -import org.apache.maven.scm.provider.accurev.AccuRevScmProviderRepository; import org.apache.maven.scm.provider.accurev.cli.AccuRevJUnitUtil; import org.apache.maven.scm.provider.accurev.command.AccuRevTckUtil; import org.apache.maven.scm.repository.ScmRepository; @@ -69,6 +68,7 @@ public class AccuRevTagCommandTckTest super.setUp(); } + @SuppressWarnings( "deprecation" ) @Test public void testReleasePluginStyleTagThenCheckout() throws Exception @@ -82,23 +82,21 @@ public class AccuRevTagCommandTckTest addToWorkingTree( getWorkingCopy(), new File( ".acignore" ), scmRepository ); - CheckInScmResult checkinResult = getScmManager().checkIn( scmRepository, new ScmFileSet( getWorkingCopy() ), - "add acignore" ); + CheckInScmResult checkinResult = + getScmManager().checkIn( scmRepository, new ScmFileSet( getWorkingCopy() ), "add acignore" ); assertResultIsSuccess( checkinResult ); - TagScmResult tagResult = getScmManager().getProviderByUrl( getScmUrl() ) - .tag( scmRepository, new ScmFileSet( getWorkingCopy() ), tag ); + TagScmResult tagResult = + getScmManager().getProviderByUrl( getScmUrl() ).tag( scmRepository, new ScmFileSet( getWorkingCopy() ), tag ); assertResultIsSuccess( tagResult ); scmRepository.getProviderRepository().setPersistCheckout( false ); - CheckOutScmResult checkoutResult = getScmManager().checkOut( - scmRepository, - new ScmFileSet( new File( getWorkingCopy(), - "target/checkout" ) ), - new ScmTag( tag ) ); + CheckOutScmResult checkoutResult = + getScmManager().checkOut( scmRepository, new ScmFileSet( new File( getWorkingCopy(), "target/checkout" ) ), + new ScmTag( tag ) ); assertResultIsSuccess( checkoutResult ); @@ -128,7 +126,6 @@ public class AccuRevTagCommandTckTest throws Exception { accurevTckTestUtil.initRepo( getContainer() ); - System.setProperty( AccuRevScmProviderRepository.TAG_PREFIX, accurevTckTestUtil.getDepotName() + "_" ); } @Override @@ -145,7 +142,6 @@ public class AccuRevTagCommandTckTest } finally { - System.clearProperty( AccuRevScmProviderRepository.TAG_PREFIX ); super.tearDown(); } } Modified: maven/scm/trunk/maven-scm-providers/maven-scm-provider-accurev/src/test/java/org/apache/maven/scm/provider/accurev/command/tag/AccuRevTagCommandTest.java URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-providers/maven-scm-provider-accurev/src/test/java/org/apache/maven/scm/provider/accurev/command/tag/AccuRevTagCommandTest.java?rev=980673&r1=980672&r2=980673&view=diff ============================================================================== --- maven/scm/trunk/maven-scm-providers/maven-scm-provider-accurev/src/test/java/org/apache/maven/scm/provider/accurev/command/tag/AccuRevTagCommandTest.java (original) +++ maven/scm/trunk/maven-scm-providers/maven-scm-provider-accurev/src/test/java/org/apache/maven/scm/provider/accurev/command/tag/AccuRevTagCommandTest.java Fri Jul 30 08:14:27 2010 @@ -20,12 +20,13 @@ package org.apache.maven.scm.provider.ac */ import static org.apache.maven.scm.ScmFileMatcher.assertHasScmFile; -import static org.apache.maven.scm.provider.accurev.AddElementsAction.addElementsTo; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; import static org.junit.Assert.assertThat; +import static org.mockito.Mockito.when; import java.io.File; +import java.util.Collections; import java.util.List; import org.apache.maven.scm.CommandParameter; @@ -36,14 +37,12 @@ import org.apache.maven.scm.command.tag. import org.apache.maven.scm.provider.accurev.AccuRevInfo; import org.apache.maven.scm.provider.accurev.AccuRevScmProviderRepository; import org.apache.maven.scm.provider.accurev.command.AbstractAccuRevCommandTest; -import org.jmock.Expectations; import org.junit.Test; public class AccuRevTagCommandTest extends AbstractAccuRevCommandTest { - @SuppressWarnings("unchecked") @Test public void testTag() throws Exception @@ -60,22 +59,12 @@ public class AccuRevTagCommandTest repo.setAccuRev( accurev ); repo.setProjectPath( "/project/dir" ); - context.checking( new Expectations() - { - { - one( accurev ).info( with( basedir ) ); - will( returnValue( info ) ); - inSequence( sequence ); - - one( accurev ).mksnap( with( "theTagName" ), with( basisStream ) ); - will( returnValue( true ) ); - inSequence( sequence ); + when( accurev.info( basedir )).thenReturn(info); + + when( accurev.mksnap( "theTagName", basisStream ) ).thenReturn( Boolean.TRUE ); - one( accurev ).statTag( with( "theTagName" ), with( any( List.class ) ) ); - will( doAll( addElementsTo( 1, new File( "tagged/file" ) ), returnValue( true ) ) ); - - } - } ); + List<File> taggedFiles = Collections.singletonList( new File( "tagged/file" ) ); + when( accurev.statTag( "theTagName" ) ).thenReturn( taggedFiles ); AccuRevTagCommand command = new AccuRevTagCommand( getLogger() ); @@ -83,8 +72,6 @@ public class AccuRevTagCommandTest commandParameters.setString( CommandParameter.TAG_NAME, "theTagName" ); TagScmResult result = command.tag( repo, testFileSet, commandParameters ); - context.assertIsSatisfied(); - assertThat( result.isSuccess(), is( true ) ); assertThat( result.getTaggedFiles().size(), is( 1 ) ); assertHasScmFile( result.getTaggedFiles(), "tagged/file", ScmFileStatus.TAGGED ); @@ -106,29 +93,15 @@ public class AccuRevTagCommandTest repo.setStreamName( "myStream" ); repo.setAccuRev( accurev ); repo.setProjectPath( "/project/dir" ); + when( accurev.info( basedir )).thenReturn(info); - context.checking( new Expectations() - { - { - one( accurev ).info( with( basedir ) ); - will( returnValue( info ) ); - inSequence( sequence ); - - one( accurev ).mksnap( with( "theTagName" ), with( basisStream ) ); - will( returnValue( false ) ); - inSequence( sequence ); - - } - } ); - + when( accurev.mksnap( "theTagName", basisStream ) ).thenReturn( Boolean.FALSE ); AccuRevTagCommand command = new AccuRevTagCommand( getLogger() ); CommandParameters commandParameters = new CommandParameters(); commandParameters.setString( CommandParameter.TAG_NAME, "theTagName" ); TagScmResult result = command.tag( repo, testFileSet, commandParameters ); - context.assertIsSatisfied(); - assertThat( result.isSuccess(), is( false ) ); assertThat( result.getProviderMessage(), notNullValue() ); Modified: maven/scm/trunk/maven-scm-providers/maven-scm-provider-accurev/src/test/java/org/apache/maven/scm/provider/accurev/command/update/AccurevUpdateCommandTest.java URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-providers/maven-scm-provider-accurev/src/test/java/org/apache/maven/scm/provider/accurev/command/update/AccurevUpdateCommandTest.java?rev=980673&r1=980672&r2=980673&view=diff ============================================================================== --- maven/scm/trunk/maven-scm-providers/maven-scm-provider-accurev/src/test/java/org/apache/maven/scm/provider/accurev/command/update/AccurevUpdateCommandTest.java (original) +++ maven/scm/trunk/maven-scm-providers/maven-scm-provider-accurev/src/test/java/org/apache/maven/scm/provider/accurev/command/update/AccurevUpdateCommandTest.java Fri Jul 30 08:14:27 2010 @@ -20,14 +20,17 @@ package org.apache.maven.scm.provider.ac */ import static org.apache.maven.scm.ScmFileMatcher.assertHasScmFile; -import static org.apache.maven.scm.provider.accurev.AddElementsAction.addElementsTo; -import static org.apache.maven.scm.provider.accurev.PutMapEntryAction.putEntryTo; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; -import static org.hamcrest.Matchers.nullValue; import static org.junit.Assert.assertThat; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.when; import java.io.File; +import java.util.Arrays; +import java.util.Collections; +import java.util.Date; import java.util.List; import java.util.Map; @@ -36,47 +39,44 @@ import org.apache.maven.scm.CommandParam import org.apache.maven.scm.ScmFileSet; import org.apache.maven.scm.ScmFileStatus; import org.apache.maven.scm.command.update.UpdateScmResult; -import org.apache.maven.scm.provider.accurev.AccuRevScmProviderRepository; +import org.apache.maven.scm.provider.accurev.Transaction; import org.apache.maven.scm.provider.accurev.WorkSpace; import org.apache.maven.scm.provider.accurev.command.AbstractAccuRevCommandTest; import org.hamcrest.core.IsInstanceOf; -import org.jmock.Expectations; import org.junit.Test; public class AccurevUpdateCommandTest extends AbstractAccuRevCommandTest { - @SuppressWarnings("unchecked") + private ScmFileSet testFileSet; + + private File basedir; + + @Override + public void setUp() + throws Exception + { + super.setUp(); + testFileSet = new ScmFileSet( new File( "/my/workspace/project/dir" ) ); + basedir = testFileSet.getBasedir(); + + info.setWorkSpace( "theWorkSpace" ); + when( accurev.info( basedir ) ).thenReturn( info ); + + } + @Test public void testUpdate() throws Exception { - final ScmFileSet testFileSet = new ScmFileSet( new File( "/my/workspace/project/dir" ) ); - final File basedir = testFileSet.getBasedir(); - AccuRevScmProviderRepository repo = new AccuRevScmProviderRepository(); - repo.setStreamName( "myStream" ); - repo.setAccuRev( accurev ); - repo.setProjectPath( "/project/dir" ); + final File keptFile = new File( "updated/file" ); + final File keptAdded = new File( "new/file" ); - info.setWorkSpace( "theWorkSpace" ); + List<File> files = Arrays.asList( keptFile, keptAdded ); - context.checking( new Expectations() - { - { - File keptFile = new File( "updated/file" ); - File keptAdded = new File( "new/file" ); - - one( accurev ).info( basedir ); - will( returnValue( info ) ); - - // TODO Should test that the timeSpec parameter is a formatted date - one( accurev ).update( with( basedir ), with( any( String.class ) ), with( any( List.class ) ) ); - will( doAll( addElementsTo( 2, keptFile, keptAdded ), returnValue( true ) ) ); - - } - } ); + when( accurev.update( eq( basedir ), any( String.class ) ) ).thenReturn( files ); AccuRevUpdateCommand command = new AccuRevUpdateCommand( getLogger() ); @@ -84,8 +84,6 @@ public class AccurevUpdateCommandTest commandParameters.setString( CommandParameter.RUN_CHANGELOG_WITH_UPDATE, Boolean.toString( false ) ); UpdateScmResult result = command.update( repo, testFileSet, commandParameters ); - context.assertIsSatisfied(); - assertThat( result.isSuccess(), is( true ) ); assertThat( result.getUpdatedFiles().size(), is( 2 ) ); assertHasScmFile( result.getUpdatedFiles(), "updated/file", ScmFileStatus.UPDATED ); @@ -93,37 +91,27 @@ public class AccurevUpdateCommandTest } - @SuppressWarnings("unchecked") @Test public void testUpdateWithChangeLog() throws Exception { - final ScmFileSet testFileSet = new ScmFileSet( new File( "/my/workspace/project/dir" ) ); - final File basedir = testFileSet.getBasedir(); - AccuRevScmProviderRepository repo = new AccuRevScmProviderRepository(); - repo.setStreamName( "myStream" ); - repo.setAccuRev( accurev ); - repo.setProjectPath( "/project/dir" ); + final WorkSpace wsBefore = new WorkSpace( "theWorkSpace", 123 ); - info.setWorkSpace( "theWorkSpace" ); - info.setBasis( "myStream" ); - context.checking( new Expectations() - { - { - WorkSpace wsBefore = new WorkSpace( "theWorkSpace", 123 ); - - one( accurev ).info( basedir ); - will( returnValue( info ) ); + Map<String, WorkSpace> workspaces = Collections.singletonMap( "theWorkSpace", wsBefore ); + + when( accurev.showWorkSpaces() ).thenReturn( workspaces ); - one( accurev ).showWorkSpaces( with( any( Map.class ) ) ); - will( doAll( putEntryTo( 0, "theWorkSpace", wsBefore ), returnValue( true ) ) ); + List<File> emptyList = Collections.emptyList(); + when( accurev.update( eq( basedir ), any( String.class ) ) ).thenReturn( emptyList ); - one( accurev ).update( with( basedir ), with( any( String.class ) ), with( any( List.class ) ) ); - will( returnValue( true ) ); + final Date currentDate = new Date(); + List<Transaction> transactions = + Collections.singletonList( new Transaction( 197L, currentDate, "type", "user" ) ); - } - } ); + when( + accurev.history( any( String.class ), any( String.class ), any( String.class ), eq( 1 ), eq( true ), + eq( true ) ) ).thenReturn( transactions ); AccuRevUpdateCommand command = new AccuRevUpdateCommand( getLogger() ); @@ -131,17 +119,14 @@ public class AccurevUpdateCommandTest commandParameters.setString( CommandParameter.RUN_CHANGELOG_WITH_UPDATE, Boolean.toString( true ) ); UpdateScmResult result = command.update( repo, testFileSet, commandParameters ); - context.assertIsSatisfied(); - assertThat( result.isSuccess(), is( true ) ); assertThat( result, IsInstanceOf.instanceOf( AccuRevUpdateScmResult.class ) ); AccuRevUpdateScmResult accuRevResult = (AccuRevUpdateScmResult) result; - assertThat( accuRevResult.getFromVersion().getTimeSpec(), is( "124" ) ); - assertThat( accuRevResult.getToVersion().getTimeSpec(), nullValue() ); + assertThat( accuRevResult.getFromRevision(), is( "theWorkSpace/123" ) ); + assertThat( accuRevResult.getToRevision(), is( "theWorkSpace/197" ) ); } - @SuppressWarnings("unchecked") @Test public void testAccuRevFailure() throws Exception @@ -149,26 +134,9 @@ public class AccurevUpdateCommandTest final ScmFileSet testFileSet = new ScmFileSet( new File( "/my/workspace/project/dir" ) ); final File basedir = testFileSet.getBasedir(); - AccuRevScmProviderRepository repo = new AccuRevScmProviderRepository(); - repo.setStreamName( "myStream" ); - repo.setAccuRev( accurev ); - repo.setProjectPath( "/project/dir" ); - info.setWorkSpace( "theWorkSpace" ); - context.checking( new Expectations() - { - { - File keptFile = new File( "updated/file" ); - File keptAdded = new File( "new/file" ); - one( accurev ).info( basedir ); - will( returnValue( info ) ); - - one( accurev ).update( with( basedir ), with( any( String.class ) ), with( any( List.class ) ) ); - will( doAll( addElementsTo( 2, keptFile, keptAdded ), returnValue( false ) ) ); - - } - } ); + when( accurev.update( eq( basedir ), any( String.class ) ) ).thenReturn( null ); AccuRevUpdateCommand command = new AccuRevUpdateCommand( getLogger() ); @@ -176,8 +144,6 @@ public class AccurevUpdateCommandTest commandParameters.setString( CommandParameter.RUN_CHANGELOG_WITH_UPDATE, Boolean.toString( false ) ); UpdateScmResult result = command.update( repo, testFileSet, commandParameters ); - context.assertIsSatisfied(); - assertThat( result.isSuccess(), is( false ) ); assertThat( result.getProviderMessage(), notNullValue() ); Added: maven/scm/trunk/maven-scm-providers/maven-scm-provider-accurev/src/test/java/org/apache/maven/scm/provider/accurev/util/QuotedPropertyParserTest.java URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-providers/maven-scm-provider-accurev/src/test/java/org/apache/maven/scm/provider/accurev/util/QuotedPropertyParserTest.java?rev=980673&view=auto ============================================================================== --- maven/scm/trunk/maven-scm-providers/maven-scm-provider-accurev/src/test/java/org/apache/maven/scm/provider/accurev/util/QuotedPropertyParserTest.java (added) +++ maven/scm/trunk/maven-scm-providers/maven-scm-provider-accurev/src/test/java/org/apache/maven/scm/provider/accurev/util/QuotedPropertyParserTest.java Fri Jul 30 08:14:27 2010 @@ -0,0 +1,48 @@ +package org.apache.maven.scm.provider.accurev.util; + +/* + * 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 static org.hamcrest.Matchers.hasEntry; +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertThat; + +import java.util.Map; + +import org.junit.Test; + +public class QuotedPropertyParserTest +{ + + @Test + public void testname() + throws Exception + { + + Map<String, String> result = + QuotedPropertyParser.parse( "param1=one&\"\"param2='2'&\"myK\"ey='my&\"value'¶m3=3" ); + + assertThat( result, hasEntry( "param1", "one" ) ); + assertThat( result, hasEntry( "param2", "2" ) ); + assertThat( result, hasEntry( "myKey", "my&\"value" ) ); + assertThat( result, hasEntry( "param3", "3" ) ); + assertThat( "3 entries", result.size(), is( 4 ) ); + + } +} Propchange: maven/scm/trunk/maven-scm-providers/maven-scm-provider-accurev/src/test/java/org/apache/maven/scm/provider/accurev/util/QuotedPropertyParserTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/scm/trunk/maven-scm-providers/maven-scm-provider-accurev/src/test/java/org/apache/maven/scm/provider/accurev/util/QuotedPropertyParserTest.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Added: maven/scm/trunk/maven-scm-providers/maven-scm-provider-accurev/src/test/resources/accurev.txt URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-providers/maven-scm-provider-accurev/src/test/resources/accurev.txt?rev=980673&view=auto ============================================================================== --- maven/scm/trunk/maven-scm-providers/maven-scm-provider-accurev/src/test/resources/accurev.txt (added) +++ maven/scm/trunk/maven-scm-providers/maven-scm-provider-accurev/src/test/resources/accurev.txt Fri Jul 30 08:14:27 2010 @@ -0,0 +1,3 @@ +AccuRev 4.7.4b (02/25/2010) Enterprise Edition +Copyright (c) 1995-2010 AccuRev Inc. All rights reserved +type 'accurev help' for help. Propchange: maven/scm/trunk/maven-scm-providers/maven-scm-provider-accurev/src/test/resources/accurev.txt ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/scm/trunk/maven-scm-providers/maven-scm-provider-accurev/src/test/resources/accurev.txt ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Added: maven/scm/trunk/maven-scm-providers/maven-scm-provider-accurev/src/test/resources/diff-vvt.txt URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-providers/maven-scm-provider-accurev/src/test/resources/diff-vvt.txt?rev=980673&view=auto ============================================================================== --- maven/scm/trunk/maven-scm-providers/maven-scm-provider-accurev/src/test/resources/diff-vvt.txt (added) +++ maven/scm/trunk/maven-scm-providers/maven-scm-provider-accurev/src/test/resources/diff-vvt.txt Fri Jul 30 08:14:27 2010 @@ -0,0 +1,4 @@ +/./tcktests/src/main/java/Application.java created +/./tcktests/hello.world moved to /./tcktests/hello-world.txt +/./tcktests/hello-world.txt changed from 6/1 to 2/4 +/./tcktests/testfile1 created Propchange: maven/scm/trunk/maven-scm-providers/maven-scm-provider-accurev/src/test/resources/diff-vvt.txt ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/scm/trunk/maven-scm-providers/maven-scm-provider-accurev/src/test/resources/diff-vvt.txt ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Added: maven/scm/trunk/maven-scm-providers/maven-scm-provider-accurev/src/test/resources/diff-vvt.xml URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-providers/maven-scm-provider-accurev/src/test/resources/diff-vvt.xml?rev=980673&view=auto ============================================================================== --- maven/scm/trunk/maven-scm-providers/maven-scm-provider-accurev/src/test/resources/diff-vvt.xml (added) +++ maven/scm/trunk/maven-scm-providers/maven-scm-provider-accurev/src/test/resources/diff-vvt.xml Fri Jul 30 08:14:27 2010 @@ -0,0 +1,58 @@ +<AcResponse + Command="diff" + TaskId="2817"> + <Element> + <Change + What="created"> + <Stream2 + Name="/tcktests/src/main/java/Application.java" + eid="8" + Version="2/3" + IsDir="no" + elemType="text"/> + </Change> + </Element> + <Element> + <Change + What="moved"> + <Stream1 + Name="/tcktests/hello.world" + eid="9" + Version="6/1" + IsDir="no" + elemType="text"/> + <Stream2 + Name="/tcktests/hello-world.txt" + eid="9" + Version="2/4" + IsDir="no" + elemType="text"/> + </Change> + <Change + What="version"> + <Stream1 + Name="/tcktests/hello.world" + eid="9" + Version="6/1" + IsDir="no" + elemType="text"/> + <Stream2 + Name="/tcktests/hello-world.txt" + eid="9" + Version="2/4" + IsDir="no" + elemType="text"/> + </Change> + </Element> + <Element> + <Change + What="created"> + <Stream2 + Name="/tcktests/testfile1" + eid="10" + Version="6/1" + IsDir="no" + elemType="text"/> + </Change> + </Element> +</AcResponse> Propchange: maven/scm/trunk/maven-scm-providers/maven-scm-provider-accurev/src/test/resources/diff-vvt.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/scm/trunk/maven-scm-providers/maven-scm-provider-accurev/src/test/resources/diff-vvt.xml ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Added: maven/scm/trunk/maven-scm-providers/maven-scm-provider-accurev/src/test/resources/info.notloggedin.txt URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-providers/maven-scm-provider-accurev/src/test/resources/info.notloggedin.txt?rev=980673&view=auto ============================================================================== --- maven/scm/trunk/maven-scm-providers/maven-scm-provider-accurev/src/test/resources/info.notloggedin.txt (added) +++ maven/scm/trunk/maven-scm-providers/maven-scm-provider-accurev/src/test/resources/info.notloggedin.txt Fri Jul 30 08:14:27 2010 @@ -0,0 +1,9 @@ +Shell: /bin/bash +Principal: (not logged in) +Host: aClient +Domain: (none) +Server name: aServer +Port: 5047 +ACCUREV_BIN: /usr/local/accurev/bin +Client time: 2010/06/20 14:15:39 EST (1277007339) +Server time: 2010/06/20 14:15:39 EST (1277007339) Propchange: maven/scm/trunk/maven-scm-providers/maven-scm-provider-accurev/src/test/resources/info.notloggedin.txt ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/scm/trunk/maven-scm-providers/maven-scm-provider-accurev/src/test/resources/info.notloggedin.txt ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Added: maven/scm/trunk/maven-scm-providers/maven-scm-provider-accurev/src/test/resources/showstreams.xml URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-providers/maven-scm-provider-accurev/src/test/resources/showstreams.xml?rev=980673&view=auto ============================================================================== --- maven/scm/trunk/maven-scm-providers/maven-scm-provider-accurev/src/test/resources/showstreams.xml (added) +++ maven/scm/trunk/maven-scm-providers/maven-scm-provider-accurev/src/test/resources/showstreams.xml Fri Jul 30 08:14:27 2010 @@ -0,0 +1,48 @@ +<streams> + <stream + name="mvnscm_1275484086" + depotName="mvnscm_1275484086" + streamNumber="1" + isDynamic="true" + type="normal" + startTime="1275484087"/> + <stream + name="mvnscm_1275484086_tckTests" + basis="mvnscm_1275484086" + basisStreamNumber="1" + depotName="mvnscm_1275484086" + streamNumber="2" + isDynamic="true" + type="normal" + startTime="1275484088"/> + <stream + name="mvnscm_1275484086_initRepo_ggardner" + basis="mvnscm_1275484086_tckTests" + basisStreamNumber="2" + depotName="mvnscm_1275484086" + streamNumber="3" + isDynamic="false" + type="workspace" + startTime="1275484091" + hidden="true"/> + <stream + name="mvnscm_1275484086_tckTests_co_ggardner" + basis="mvnscm_1275484086_tckTests" + basisStreamNumber="2" + depotName="mvnscm_1275484086" + streamNumber="4" + isDynamic="false" + type="workspace" + startTime="1275484101" + hidden="true"/> + <stream + name="mvnscm_1275484086_tckTests_up_ggardner" + basis="mvnscm_1275484086_tckTests" + basisStreamNumber="2" + depotName="mvnscm_1275484086" + streamNumber="5" + isDynamic="false" + type="workspace" + startTime="1275484101" + hidden="true"/> +</streams> Propchange: maven/scm/trunk/maven-scm-providers/maven-scm-provider-accurev/src/test/resources/showstreams.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/scm/trunk/maven-scm-providers/maven-scm-provider-accurev/src/test/resources/showstreams.xml ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision