diff options
author | Olivier Lamy <olamy@apache.org> | 2013-11-13 06:31:24 +0000 |
---|---|---|
committer | Olivier Lamy <olamy@apache.org> | 2013-11-13 06:31:24 +0000 |
commit | ab6f5bde33f4ab6899557733fac009497053952e (patch) | |
tree | 87f9bc0ff11f7429ffbead336649d57ece92e4ac /archiva-modules/archiva-base/archiva-proxy/src | |
parent | 16b6da8bf0942336143734e6992d3a81b3b977df (diff) | |
download | archiva-ab6f5bde33f4ab6899557733fac009497053952e.tar.gz archiva-ab6f5bde33f4ab6899557733fac009497053952e.zip |
move to last easymock 3.2
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1541399 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-modules/archiva-base/archiva-proxy/src')
7 files changed, 91 insertions, 53 deletions
diff --git a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/AbstractProxyTestCase.java b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/AbstractProxyTestCase.java index ddefd39ec..ca6d94a37 100644 --- a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/AbstractProxyTestCase.java +++ b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/AbstractProxyTestCase.java @@ -42,8 +42,8 @@ import org.apache.commons.lang.ArrayUtils; import org.apache.maven.index.NexusIndexer; import org.apache.maven.index.context.IndexingContext; import org.apache.maven.wagon.Wagon; -import org.easymock.ArgumentsMatcher; -import org.easymock.MockControl; +import org.easymock.EasyMock; +import org.easymock.IMocksControl; import org.junit.After; import org.junit.Before; import org.junit.runner.RunWith; @@ -110,7 +110,7 @@ public abstract class AbstractProxyTestCase protected static final String REPOPATH_LEGACY_MANAGED_TARGET = "target/test-repository/legacy-managed"; - protected MockControl wagonMockControl; + protected IMocksControl wagonMockControl; protected Wagon wagonMock; @@ -205,8 +205,8 @@ public abstract class AbstractProxyTestCase proxyHandler = applicationContext.getBean( "repositoryProxyConnectors#test", RepositoryProxyConnectors.class ); // Setup the wagon mock. - wagonMockControl = MockControl.createNiceControl( Wagon.class ); - wagonMock = (Wagon) wagonMockControl.getMock(); + wagonMockControl = EasyMock.createNiceControl( ); + wagonMock = wagonMockControl.createMock( Wagon.class ); delegate = (WagonDelegate) applicationContext.getBean( "wagon#test", Wagon.class ); @@ -236,7 +236,7 @@ public abstract class AbstractProxyTestCase } } - + /* protected static final ArgumentsMatcher customWagonGetIfNewerMatcher = new ArgumentsMatcher() { @@ -288,7 +288,7 @@ public abstract class AbstractProxyTestCase return ArrayUtils.toString( arguments ); } }; - + */ protected void assertChecksums( File expectedFile, String expectedSha1Contents, String expectedMd5Contents ) throws Exception diff --git a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/CacheFailuresTransferTest.java b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/CacheFailuresTransferTest.java index 5d1a4e2b9..1b7933489 100644 --- a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/CacheFailuresTransferTest.java +++ b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/CacheFailuresTransferTest.java @@ -27,6 +27,7 @@ import org.apache.archiva.policies.ReleasesPolicy; import org.apache.archiva.policies.SnapshotsPolicy; import org.apache.archiva.policies.urlcache.UrlFailureCache; import org.apache.maven.wagon.ResourceDoesNotExistException; +import org.easymock.EasyMock; import org.junit.Test; import java.io.File; @@ -46,6 +47,9 @@ public class CacheFailuresTransferTest // TODO: test some hard failures (eg TransferFailedException) // TODO: test the various combinations of fetchFrom* (note: need only test when caching is enabled) + @Inject + UrlFailureCache urlFailureCache; + @Test public void testGetWithCacheFailuresOn() throws Exception @@ -68,11 +72,14 @@ public class CacheFailuresTransferTest saveConnector( ID_DEFAULT_MANAGED, "badproxied2", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.YES, false ); - wagonMock.get( path, new File( expectedFile.getParentFile(), expectedFile.getName() + ".tmp" ) ); + //wagonMock.get( path, new File( expectedFile.getParentFile(), expectedFile.getName() + ".tmp" ) ); + //wagonMockControl.setMatcher( customWagonGetMatcher ); + //wagonMockControl.setThrowable( new ResourceDoesNotExistException( "resource does not exist." ), 2 ); - wagonMockControl.setMatcher( customWagonGetMatcher ); + wagonMock.get( EasyMock.eq( path ), EasyMock.anyObject( File.class )); + + EasyMock.expectLastCall().andThrow( new ResourceDoesNotExistException( "resource does not exist." ) ).times( 2 ); - wagonMockControl.setThrowable( new ResourceDoesNotExistException( "resource does not exist." ), 2 ); wagonMockControl.replay(); @@ -112,10 +119,12 @@ public class CacheFailuresTransferTest saveConnector( ID_DEFAULT_MANAGED, "badproxied2", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false ); - wagonMock.get( path, new File( expectedFile.getParentFile(), expectedFile.getName() + ".tmp" ) ); + //wagonMock.get( path, new File( expectedFile.getParentFile(), expectedFile.getName() + ".tmp" ) ); + //wagonMockControl.setMatcher( customWagonGetMatcher ); + //wagonMockControl.setThrowable( new ResourceDoesNotExistException( "resource does not exist." ), 2 ); - wagonMockControl.setMatcher( customWagonGetMatcher ); - wagonMockControl.setThrowable( new ResourceDoesNotExistException( "resource does not exist." ), 2 ); + wagonMock.get( EasyMock.eq( path ), EasyMock.anyObject( File.class )); + EasyMock.expectLastCall().andThrow( new ResourceDoesNotExistException( "resource does not exist." ) ).times( 2 ); wagonMockControl.replay(); @@ -125,10 +134,15 @@ public class CacheFailuresTransferTest // Second attempt to download same artifact DOES NOT use cache wagonMockControl.reset(); - wagonMock.get( path, new File( expectedFile.getParentFile(), expectedFile.getName() + ".tmp" ) ); - wagonMockControl.setMatcher( customWagonGetMatcher ); - wagonMockControl.setThrowable( new ResourceDoesNotExistException( "resource does not exist." ), 2 ); + + //wagonMock.get( path, new File( expectedFile.getParentFile(), expectedFile.getName() + ".tmp" ) ); + //wagonMockControl.setMatcher( customWagonGetMatcher ); + //wagonMockControl.setThrowable( new ResourceDoesNotExistException( "resource does not exist." ), 2 ); + + wagonMock.get( EasyMock.eq( path ), EasyMock.anyObject( File.class )); + EasyMock.expectLastCall().andThrow( new ResourceDoesNotExistException( "resource does not exist." ) ).times( 2 ); + wagonMockControl.replay(); downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); @@ -171,13 +185,9 @@ public class CacheFailuresTransferTest assertNoTempFiles( expectedFile ); } - @Inject - UrlFailureCache urlFailureCache; - protected UrlFailureCache lookupUrlFailureCache() throws Exception { - //UrlFailureCache urlFailureCache = (UrlFailureCache) lookup( "urlFailureCache" ); assertNotNull( "URL Failure Cache cannot be null.", urlFailureCache ); return urlFailureCache; } diff --git a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/ChecksumTransferTest.java b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/ChecksumTransferTest.java index 8db426096..ce6edd3fe 100644 --- a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/ChecksumTransferTest.java +++ b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/ChecksumTransferTest.java @@ -26,6 +26,7 @@ import org.apache.archiva.policies.ChecksumPolicy; import org.apache.archiva.policies.ReleasesPolicy; import org.apache.archiva.policies.SnapshotsPolicy; import org.apache.maven.wagon.ResourceDoesNotExistException; +import org.easymock.EasyMock; import org.junit.Test; import java.io.File; @@ -435,15 +436,25 @@ public class ChecksumTransferTest saveConnector( ID_DEFAULT_MANAGED, "badproxied", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS, SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false ); - wagonMock.get( path, new File( expectedFile.getAbsolutePath() + ".tmp" ) ); - wagonMockControl.setMatcher( customWagonGetMatcher ); - wagonMockControl.setVoidCallable(); - wagonMock.get( path + ".sha1", new File( expectedFile.getAbsolutePath() + ".sha1.tmp" ) ); - wagonMockControl.setMatcher( customWagonGetMatcher ); - wagonMockControl.setVoidCallable(); - wagonMock.get( path + ".md5", new File( expectedFile.getAbsolutePath() + ".md5.tmp" ) ); - wagonMockControl.setMatcher( customWagonGetMatcher ); - wagonMockControl.setThrowable( new ResourceDoesNotExistException( "Resource does not exist." ) ); + //wagonMock.get( path, new File( expectedFile.getAbsolutePath() + ".tmp" ) ); + //wagonMockControl.setMatcher( customWagonGetMatcher ); + //wagonMockControl.setVoidCallable(); + wagonMock.get( EasyMock.eq( path ), EasyMock.anyObject( File.class )); + EasyMock.expectLastCall().once(); + + //wagonMock.get( path + ".sha1", new File( expectedFile.getAbsolutePath() + ".sha1.tmp" ) ); + //wagonMockControl.setMatcher( customWagonGetMatcher ); + //wagonMockControl.setVoidCallable(); + wagonMock.get( EasyMock.eq( path + ".sha1" ), EasyMock.anyObject( File.class )); + EasyMock.expectLastCall().once(); + + //wagonMock.get( path + ".md5", new File( expectedFile.getAbsolutePath() + ".md5.tmp" ) ); + //wagonMockControl.setMatcher( customWagonGetMatcher ); + //wagonMockControl.setThrowable( new ResourceDoesNotExistException( "Resource does not exist." ) ); + + wagonMock.get( EasyMock.eq( path + ".md5" ), EasyMock.anyObject( File.class )); + EasyMock.expectLastCall().andThrow( new ResourceDoesNotExistException( "Resource does not exist." ) ).once(); + wagonMockControl.replay(); File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); diff --git a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/ErrorHandlingTest.java b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/ErrorHandlingTest.java index 6d5139c52..4a5c2471a 100644 --- a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/ErrorHandlingTest.java +++ b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/ErrorHandlingTest.java @@ -30,6 +30,7 @@ import org.apache.archiva.repository.layout.LayoutException; import org.apache.maven.wagon.ResourceDoesNotExistException; import org.apache.maven.wagon.TransferFailedException; import org.apache.maven.wagon.authorization.AuthorizationException; +import org.easymock.EasyMock; import org.junit.Test; import java.io.File; @@ -565,17 +566,21 @@ public class ErrorHandlingTest private void simulateGetError( String path, File expectedFile, Exception throwable ) throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException { - wagonMock.get( path, createExpectedTempFile( expectedFile ) ); - wagonMockControl.setMatcher(customWagonGetMatcher); - wagonMockControl.setThrowable( throwable, 1 ); + //wagonMock.get( path, createExpectedTempFile( expectedFile ) ); + //wagonMockControl.setMatcher(customWagonGetMatcher); + //wagonMockControl.setThrowable( throwable, 1 ); + wagonMock.get( EasyMock.eq( path ), EasyMock.anyObject( File.class )); + EasyMock.expectLastCall().andThrow(throwable ); } private void simulateGetIfNewerError( String path, File expectedFile, TransferFailedException exception ) throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException { - wagonMock.getIfNewer( path, createExpectedTempFile( expectedFile ), expectedFile.lastModified() ); - wagonMockControl.setMatcher(customWagonGetIfNewerMatcher); - wagonMockControl.setThrowable( exception, 1 ); + //wagonMock.getIfNewer( path, createExpectedTempFile( expectedFile ), expectedFile.lastModified() ); + //wagonMockControl.setMatcher(customWagonGetIfNewerMatcher); + //wagonMockControl.setThrowable( exception, 1 ); + wagonMock.getIfNewer( EasyMock.eq( path ), EasyMock.anyObject( File.class ), EasyMock.eq( expectedFile.lastModified() )); + EasyMock.expectLastCall().andThrow( exception ); } private File createExpectedTempFile( File expectedFile ) diff --git a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/ManagedDefaultTransferTest.java b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/ManagedDefaultTransferTest.java index ed739f186..c2a6f9063 100644 --- a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/ManagedDefaultTransferTest.java +++ b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/ManagedDefaultTransferTest.java @@ -27,6 +27,7 @@ import org.apache.archiva.policies.SnapshotsPolicy; import org.apache.commons.io.FileUtils; import org.apache.commons.lang.StringUtils; import org.apache.maven.wagon.ResourceDoesNotExistException; +import org.easymock.EasyMock; import org.junit.Test; import java.io.File; @@ -398,9 +399,12 @@ public class ManagedDefaultTransferTest // Configure Repository (usually done within archiva.xml configuration) saveRemoteRepositoryConfig( "badproxied", "Bad Proxied", "test://bad.machine.com/repo/", "default" ); - wagonMock.get( path, new File( expectedFile.getAbsolutePath() + ".tmp" ) ); - wagonMockControl.setMatcher( customWagonGetMatcher ); - wagonMockControl.setThrowable( new ResourceDoesNotExistException( "transfer failed" ) ); + //wagonMock.get( path, new File( expectedFile.getAbsolutePath() + ".tmp" ) ); + //wagonMockControl.setMatcher( customWagonGetMatcher ); + //wagonMockControl.setThrowable( new ResourceDoesNotExistException( "transfer failed" ) ); + + wagonMock.get( EasyMock.eq( path), EasyMock.anyObject( File.class ) ); + EasyMock.expectLastCall().andThrow( new ResourceDoesNotExistException( "transfer failed" ) ); wagonMockControl.replay(); // Configure Connector (usually done within archiva.xml configuration) @@ -438,15 +442,18 @@ public class ManagedDefaultTransferTest saveConnector( ID_DEFAULT_MANAGED, "badproxied2", false ); File tmpFile = new File( expectedFile.getParentFile(), expectedFile.getName() + ".tmp" ); - wagonMock.get( path, tmpFile ); - - wagonMockControl.setMatcher( customWagonGetMatcher ); - wagonMockControl.setThrowable( new ResourceDoesNotExistException( "Can't find resource." ) ); - - wagonMock.get( path, tmpFile ); - wagonMockControl.setMatcher( customWagonGetMatcher ); - wagonMockControl.setThrowable( new ResourceDoesNotExistException( "Can't find resource." ) ); + //wagonMock.get( path, tmpFile ); + //wagonMockControl.setMatcher( customWagonGetMatcher ); + //wagonMockControl.setThrowable( new ResourceDoesNotExistException( "Can't find resource." ) ); + wagonMock.get( EasyMock.eq( path ), EasyMock.anyObject( File.class ) ); + EasyMock.expectLastCall().andThrow( new ResourceDoesNotExistException( "Can't find resource." ) ); + + //wagonMock.get( path, tmpFile ); + //wagonMockControl.setMatcher( customWagonGetMatcher ); + //wagonMockControl.setThrowable( new ResourceDoesNotExistException( "Can't find resource." ) ); + wagonMock.get( EasyMock.eq( path ), EasyMock.anyObject( File.class ) ); + EasyMock.expectLastCall().andThrow( new ResourceDoesNotExistException( "Can't find resource." ) ); wagonMockControl.replay(); diff --git a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/MetadataTransferTest.java b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/MetadataTransferTest.java index a14089067..056c5799d 100644 --- a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/MetadataTransferTest.java +++ b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/MetadataTransferTest.java @@ -35,9 +35,11 @@ import org.apache.archiva.repository.metadata.MetadataTools; import org.apache.archiva.repository.metadata.RepositoryMetadataException; import org.apache.archiva.repository.metadata.RepositoryMetadataWriter; import org.apache.commons.lang.StringUtils; +import org.apache.maven.wagon.ResourceDoesNotExistException; import org.apache.maven.wagon.TransferFailedException; import org.custommonkey.xmlunit.DetailedDiff; import org.custommonkey.xmlunit.Diff; +import org.easymock.EasyMock; import org.junit.Test; import javax.inject.Inject; @@ -154,11 +156,13 @@ public class MetadataTransferTest // ensure that a hard failure in the first proxy connector is skipped and the second repository checked File expectedFile = new File( managedDefaultDir.getAbsoluteFile(), metadataTools.getRepositorySpecificName( "badproxied1", requestedResource ) ); - wagonMock.get( requestedResource, new File( expectedFile.getParentFile(), expectedFile.getName() + ".tmp" ) ); - wagonMockControl.setMatcher( customWagonGetMatcher ); + //wagonMock.get( requestedResource, new File( expectedFile.getParentFile(), expectedFile.getName() + ".tmp" ) ); + //wagonMockControl.setMatcher( customWagonGetMatcher ); + //wagonMockControl.setThrowable( new TransferFailedException( "can't connect" ) ); + wagonMock.get( EasyMock.eq( requestedResource ), EasyMock.anyObject( File.class )); + EasyMock.expectLastCall().andThrow( new TransferFailedException( "can't connect" ) ); - wagonMockControl.setThrowable( new TransferFailedException( "can't connect" ) ); wagonMockControl.replay(); diff --git a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/MockConfiguration.java b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/MockConfiguration.java index 8397a56ce..20490acf5 100644 --- a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/MockConfiguration.java +++ b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/MockConfiguration.java @@ -28,7 +28,8 @@ import org.apache.archiva.configuration.RepositoryScanningConfiguration; import org.apache.archiva.redback.components.registry.Registry; import org.apache.archiva.redback.components.registry.RegistryException; import org.apache.archiva.redback.components.registry.RegistryListener; -import org.easymock.MockControl; +import org.easymock.EasyMock; +import org.easymock.IMocksControl; import org.springframework.stereotype.Service; import java.util.Collections; @@ -53,14 +54,14 @@ public class MockConfiguration private Set<ConfigurationListener> configListeners = new HashSet<ConfigurationListener>(); - private MockControl registryControl; + private IMocksControl registryControl; private Registry registryMock; public MockConfiguration() { - registryControl = MockControl.createNiceControl( org.apache.archiva.redback.components.registry.Registry.class ); - registryMock = (org.apache.archiva.redback.components.registry.Registry) registryControl.getMock(); + registryControl = EasyMock.createNiceControl( ); + registryMock = registryControl.createMock( Registry.class ); } @PostConstruct |