From ab6f5bde33f4ab6899557733fac009497053952e Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Wed, 13 Nov 2013 06:31:24 +0000 Subject: [PATCH] move to last easymock 3.2 git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1541399 13f79535-47bb-0310-9956-ffa450edef68 --- .../ArchivaConfigurationTest.java | 48 +- .../AbstractRepositoryPurgeTest.java | 11 +- ...pReleasedSnapshotsRepositoryPurgeTest.java | 20 +- .../search/AbstractMavenRepositorySearch.java | 11 +- .../search/MavenRepositorySearchOSGITest.java | 3 +- .../search/MavenRepositorySearchTest.java | 88 ++- .../archiva/proxy/AbstractProxyTestCase.java | 14 +- .../proxy/CacheFailuresTransferTest.java | 36 +- .../archiva/proxy/ChecksumTransferTest.java | 29 +- .../archiva/proxy/ErrorHandlingTest.java | 17 +- .../proxy/ManagedDefaultTransferTest.java | 27 +- .../archiva/proxy/MetadataTransferTest.java | 10 +- .../archiva/proxy/MockConfiguration.java | 9 +- .../RepositoryContentConsumersTest.java | 63 +- ...ersionsOfArtifactRssFeedProcessorTest.java | 58 +- .../ArchivaServletAuthenticatorTest.java | 18 +- .../webdav/ArchivaDavResourceFactoryTest.java | 324 +++++++---- .../webdav/RepositoryServletSecurityTest.java | 311 ++++++---- .../archiva/audit/AuditManagerTest.java | 406 +++++++------ .../maven2/conf/MockConfiguration.java | 10 +- .../RepositoryStatisticsManagerTest.java | 548 ++++++++++-------- pom.xml | 4 +- 22 files changed, 1233 insertions(+), 832 deletions(-) diff --git a/archiva-modules/archiva-base/archiva-configuration/src/test/java/org/apache/archiva/configuration/ArchivaConfigurationTest.java b/archiva-modules/archiva-base/archiva-configuration/src/test/java/org/apache/archiva/configuration/ArchivaConfigurationTest.java index 51380cc98..e4604476b 100644 --- a/archiva-modules/archiva-base/archiva-configuration/src/test/java/org/apache/archiva/configuration/ArchivaConfigurationTest.java +++ b/archiva-modules/archiva-base/archiva-configuration/src/test/java/org/apache/archiva/configuration/ArchivaConfigurationTest.java @@ -19,18 +19,11 @@ package org.apache.archiva.configuration; * under the License. */ -import java.io.File; -import java.nio.charset.Charset; -import java.util.List; -import java.util.Map; -import javax.inject.Inject; import org.apache.archiva.common.utils.FileUtil; import org.apache.archiva.redback.components.registry.RegistryException; import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner; import org.apache.commons.io.FileUtils; import org.custommonkey.xmlunit.XMLAssert; -import org.easymock.MockControl; -import static org.junit.Assert.*; import org.junit.Test; import org.junit.runner.RunWith; import org.slf4j.Logger; @@ -40,6 +33,15 @@ import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext.ClassMode; import org.springframework.test.context.ContextConfiguration; +import javax.inject.Inject; +import java.io.File; +import java.nio.charset.Charset; +import java.util.List; +import java.util.Map; + +import static org.easymock.EasyMock.*; +import static org.junit.Assert.*; + /** * Test the configuration store. */ @@ -215,18 +217,21 @@ public class ArchivaConfigurationTest configuration.getWebapp().getUi().setAppletFindEnabled( false ); // add a change listener - MockControl control = createConfigurationListenerMockControl(); - ConfigurationListener listener = (ConfigurationListener) control.getMock(); + //MockControl control = createConfigurationListenerMockControl(); + ConfigurationListener listener = createMock( ConfigurationListener.class );// (ConfigurationListener) control.getMock(); archivaConfiguration.addListener( listener ); listener.configurationEvent( new ConfigurationEvent( ConfigurationEvent.SAVED ) ); - control.setVoidCallable(); + //control.setVoidCallable(); - control.replay(); + + //control.replay(); + replay( listener ); archivaConfiguration.save( configuration ); - control.verify(); + //control.verify(); + verify( listener ); assertTrue( "Check file exists", file.exists() ); @@ -242,9 +247,9 @@ public class ArchivaConfigurationTest assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() ); } - private static MockControl createConfigurationListenerMockControl() + private static ConfigurationListener createConfigurationListenerMockControl() { - return MockControl.createControl( ConfigurationListener.class ); + return createMock( ConfigurationListener.class );// MockControl.createControl( ConfigurationListener.class ); } @Test @@ -301,19 +306,24 @@ public class ArchivaConfigurationTest configuration.getWebapp().getUi().setAppletFindEnabled( false ); // add a change listener - MockControl control = createConfigurationListenerMockControl(); - ConfigurationListener listener = (ConfigurationListener) control.getMock(); + //MockControl control = createConfigurationListenerMockControl(); + //ConfigurationListener listener = (ConfigurationListener) control.getMock(); + ConfigurationListener listener = createConfigurationListenerMockControl(); archivaConfiguration.addListener( listener ); listener.configurationEvent( new ConfigurationEvent( ConfigurationEvent.SAVED ) ); - control.setVoidCallable( 1 ); + //control.setVoidCallable( 1 ); - control.replay(); + //control.replay(); + + replay( listener ); archivaConfiguration.save( configuration ); - control.verify(); + //control.verify(); + + verify( listener ); assertTrue( "Check file exists", userFile.exists() ); assertFalse( "Check file not created", baseFile.exists() ); diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/AbstractRepositoryPurgeTest.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/AbstractRepositoryPurgeTest.java index b218980a4..2dc0c46db 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/AbstractRepositoryPurgeTest.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/AbstractRepositoryPurgeTest.java @@ -32,7 +32,8 @@ import org.apache.commons.io.FileUtils; import org.apache.commons.lang.StringUtils; import org.apache.maven.index.NexusIndexer; import org.apache.maven.index.context.IndexingContext; -import org.easymock.MockControl; +import org.easymock.EasyMock; +import org.easymock.IMocksControl; import org.junit.After; import static org.junit.Assert.*; import org.junit.Before; @@ -82,7 +83,7 @@ public abstract class AbstractRepositoryPurgeTest protected RepositoryPurge repoPurge; - protected MockControl listenerControl; + protected IMocksControl listenerControl; protected RepositoryListener listener; @@ -104,9 +105,9 @@ public abstract class AbstractRepositoryPurgeTest removeMavenIndexes(); - listenerControl = MockControl.createControl( RepositoryListener.class ); + listenerControl = EasyMock.createControl( ); - listener = (RepositoryListener) listenerControl.getMock(); + listener = listenerControl.createMock( RepositoryListener.class ); repositorySession = mock( RepositorySession.class ); metadataRepository = mock( MetadataRepository.class ); @@ -195,7 +196,7 @@ public abstract class AbstractRepositoryPurgeTest throws Exception { removeMavenIndexes(); - File testDir = new File( AbstractRepositoryPurgeTest.fixPath( getTestRepoRoot().getAbsolutePath() ) ) ;// AbstractRepositoryPurgeTest.fixPath( getTestRepoRoot() ); + File testDir = new File( AbstractRepositoryPurgeTest.fixPath( getTestRepoRoot().getAbsolutePath() ) ); FileUtils.deleteDirectory( testDir ); File sourceDir = new File ( new File( "target/test-classes/" + TEST_REPO_ID).getAbsolutePath() ); FileUtils.copyDirectory( sourceDir, testDir ); diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurgeTest.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurgeTest.java index 6f672dee1..5909657db 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurgeTest.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurgeTest.java @@ -19,11 +19,6 @@ package org.apache.archiva.consumers.core.repository; * under the License. */ -import java.io.File; -import java.nio.charset.Charset; -import java.util.Collections; -import java.util.List; -import javax.inject.Inject; import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin; import org.apache.archiva.admin.repository.managed.DefaultManagedRepositoryAdmin; import org.apache.archiva.configuration.ArchivaConfiguration; @@ -32,12 +27,19 @@ import org.apache.archiva.repository.events.RepositoryListener; import org.apache.archiva.repository.metadata.MetadataTools; import org.apache.commons.io.FileUtils; import org.custommonkey.xmlunit.XMLAssert; -import org.easymock.MockControl; -import static org.junit.Assert.*; +import org.easymock.EasyMock; import org.junit.Before; import org.junit.Test; import org.springframework.test.context.ContextConfiguration; +import javax.inject.Inject; +import java.io.File; +import java.nio.charset.Charset; +import java.util.Collections; +import java.util.List; + +import static org.junit.Assert.assertTrue; + /** */ @@ -76,9 +78,9 @@ public class CleanupReleasedSnapshotsRepositoryPurgeTest archivaConfiguration = applicationContext.getBean( "archivaConfiguration#cleanup-released-snapshots", ArchivaConfiguration.class ); - listenerControl = MockControl.createControl( RepositoryListener.class ); + listenerControl = EasyMock.createControl( ); - listener = (RepositoryListener) listenerControl.getMock(); + listener = listenerControl.createMock( RepositoryListener.class ); List listeners = Collections.singletonList( listener ); repoPurge = new CleanupReleasedSnapshotsRepositoryPurge( getRepository(), metadataTools, applicationContext.getBean( diff --git a/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/AbstractMavenRepositorySearch.java b/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/AbstractMavenRepositorySearch.java index ef81635f5..c129fe936 100644 --- a/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/AbstractMavenRepositorySearch.java +++ b/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/AbstractMavenRepositorySearch.java @@ -28,6 +28,7 @@ import org.apache.archiva.common.utils.FileUtil; import org.apache.archiva.configuration.ArchivaConfiguration; import org.apache.archiva.configuration.Configuration; import org.apache.archiva.configuration.ManagedRepositoryConfiguration; +import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner; import org.apache.commons.io.FileUtils; import org.apache.commons.lang.SystemUtils; import org.apache.maven.index.ArtifactContext; @@ -36,7 +37,8 @@ import org.apache.maven.index.ArtifactScanningListener; import org.apache.maven.index.NexusIndexer; import org.apache.maven.index.ScanningResult; import org.apache.maven.index.context.IndexingContext; -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; @@ -47,7 +49,6 @@ import org.springframework.test.context.ContextConfiguration; import javax.inject.Inject; import java.io.File; import java.util.List; -import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner; /** * @author Olivier Lamy @@ -73,7 +74,7 @@ public abstract class AbstractMavenRepositorySearch ArtifactContextProducer artifactContextProducer; - MockControl archivaConfigControl; + IMocksControl archivaConfigControl; Configuration config; @@ -97,9 +98,9 @@ public abstract class AbstractMavenRepositorySearch FileUtils.deleteDirectory( new File( FileUtil.getBasedir(), "/target/repos/" + TEST_REPO_2 + "/.indexer" ) ); assertFalse( new File( FileUtil.getBasedir(), "/target/repos/" + TEST_REPO_2 + "/.indexer" ).exists() ); - archivaConfigControl = MockControl.createControl( ArchivaConfiguration.class ); + archivaConfigControl = EasyMock.createControl( ); - archivaConfig = (ArchivaConfiguration) archivaConfigControl.getMock(); + archivaConfig = archivaConfigControl.createMock( ArchivaConfiguration.class ); DefaultManagedRepositoryAdmin defaultManagedRepositoryAdmin = new DefaultManagedRepositoryAdmin(); defaultManagedRepositoryAdmin.setArchivaConfiguration( archivaConfig ); diff --git a/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/MavenRepositorySearchOSGITest.java b/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/MavenRepositorySearchOSGITest.java index ca59d65d2..e9c10474b 100644 --- a/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/MavenRepositorySearchOSGITest.java +++ b/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/MavenRepositorySearchOSGITest.java @@ -19,6 +19,7 @@ package org.apache.archiva.indexer.search; * under the License. */ +import org.easymock.EasyMock; import org.junit.Test; import java.io.File; @@ -43,7 +44,7 @@ public class MavenRepositorySearchOSGITest List selectedRepos = Arrays.asList( TEST_REPO_1 ); // search artifactId - archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 1, 2 ); + EasyMock.expect( archivaConfig.getConfiguration() ).andReturn( config ).times( 1, 2 ); archivaConfigControl.replay(); diff --git a/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/MavenRepositorySearchTest.java b/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/MavenRepositorySearchTest.java index 9cfc01eeb..8fc288064 100644 --- a/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/MavenRepositorySearchTest.java +++ b/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/MavenRepositorySearchTest.java @@ -23,6 +23,7 @@ import org.apache.archiva.common.utils.FileUtil; import org.apache.archiva.indexer.util.SearchUtil; import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner; import org.codehaus.plexus.util.FileUtils; +import org.easymock.EasyMock; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.test.context.ContextConfiguration; @@ -104,7 +105,8 @@ public class MavenRepositorySearchTest List selectedRepos = Arrays.asList( TEST_REPO_1 ); // search artifactId - archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 1, 2 ); + //archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 1, 2 ); + EasyMock.expect( archivaConfig.getConfiguration() ).andReturn( config ).times( 1, 2 ); archivaConfigControl.replay(); @@ -124,7 +126,8 @@ public class MavenRepositorySearchTest archivaConfigControl.reset(); // search groupId - archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 1, 2 ); + //archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 1, 2 ); + EasyMock.expect( archivaConfig.getConfiguration() ).andReturn( config ).times( 1, 2 ); archivaConfigControl.replay(); @@ -147,7 +150,8 @@ public class MavenRepositorySearchTest List selectedRepos = Arrays.asList( TEST_REPO_1 ); // search artifactId - archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 1, 2 ); + //archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 1, 2 ); + EasyMock.expect( archivaConfig.getConfiguration() ).andReturn( config ).times( 1, 2 ); archivaConfigControl.replay(); @@ -167,7 +171,8 @@ public class MavenRepositorySearchTest archivaConfigControl.reset(); // search groupId - archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 1, 2 ); + //archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 1, 2 ); + EasyMock.expect( archivaConfig.getConfiguration() ).andReturn( config ).times( 1, 2 ); archivaConfigControl.replay(); @@ -191,7 +196,8 @@ public class MavenRepositorySearchTest selectedRepos.add( TEST_REPO_1 ); // search artifactId - archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 1, 2 ); + //archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 1, 2 ); + EasyMock.expect( archivaConfig.getConfiguration() ).andReturn( config ).times( 1, 2 ); archivaConfigControl.replay(); @@ -221,7 +227,8 @@ public class MavenRepositorySearchTest selectedRepos.add( TEST_REPO_1 ); // search artifactId - archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 1, 2 ); + //archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 1, 2 ); + EasyMock.expect( archivaConfig.getConfiguration() ).andReturn( config ).times( 1, 2 ); archivaConfigControl.replay(); @@ -257,7 +264,8 @@ public class MavenRepositorySearchTest List selectedRepos = new ArrayList(); selectedRepos.add( TEST_REPO_1 ); - archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 1, 2 ); + //archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 1, 2 ); + EasyMock.expect( archivaConfig.getConfiguration() ).andReturn( config ).times( 1, 2 ); archivaConfigControl.replay(); SearchResults results = search.search( "user", selectedRepos, "archiva search", null, null ); @@ -281,7 +289,8 @@ public class MavenRepositorySearchTest SearchResultLimits limits = new SearchResultLimits( 0 ); limits.setPageSize( 1 ); - archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 1, 2 ); + //archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 1, 2 ); + EasyMock.expect( archivaConfig.getConfiguration() ).andReturn( config ).times( 1, 2 ); archivaConfigControl.replay(); @@ -301,7 +310,8 @@ public class MavenRepositorySearchTest limits = new SearchResultLimits( 1 ); limits.setPageSize( 1 ); - archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 1, 2 ); + //archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 1, 2 ); + EasyMock.expect( archivaConfig.getConfiguration() ).andReturn( config ).times( 1, 2 ); archivaConfigControl.replay(); @@ -336,7 +346,8 @@ public class MavenRepositorySearchTest config.addManagedRepository( createRepositoryConfig( TEST_REPO_2 ) ); - archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 1, 5 ); + //archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 1, 5 ); + EasyMock.expect( archivaConfig.getConfiguration() ).andReturn( config ).times( 1, 5 ); archivaConfigControl.replay(); @@ -371,7 +382,8 @@ public class MavenRepositorySearchTest List selectedRepos = new ArrayList(); selectedRepos.add( TEST_REPO_1 ); - archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 1, 2 ); + //archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 1, 2 ); + EasyMock.expect( archivaConfig.getConfiguration() ).andReturn( config ).times( 1, 2 ); archivaConfigControl.replay(); @@ -390,7 +402,8 @@ public class MavenRepositorySearchTest List selectedRepos = new ArrayList(); selectedRepos.add( TEST_REPO_1 ); - archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 1, 2 ); + //archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 1, 2 ); + EasyMock.expect( archivaConfig.getConfiguration() ).andReturn( config ).times( 1, 2 ); archivaConfigControl.replay(); @@ -408,7 +421,8 @@ public class MavenRepositorySearchTest List selectedRepos = new ArrayList(); selectedRepos.add( "non-existing-repo" ); - archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 1, 2 ); + //archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 1, 2 ); + EasyMock.expect( archivaConfig.getConfiguration() ).andReturn( config ).times( 1, 2 ); archivaConfigControl.replay(); @@ -431,7 +445,8 @@ public class MavenRepositorySearchTest List previousSearchTerms = new ArrayList(); previousSearchTerms.add( "archiva-test" ); - archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 1, 2 ); + //archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 1, 2 ); + EasyMock.expect( archivaConfig.getConfiguration() ).andReturn( config ).times( 1, 2 ); archivaConfigControl.replay(); @@ -469,7 +484,8 @@ public class MavenRepositorySearchTest searchFields.setVersion( "1.0" ); searchFields.setRepositories( selectedRepos ); - archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 1, 2 ); + //archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 1, 2 ); + EasyMock.expect( archivaConfig.getConfiguration() ).andReturn( config ).times( 1, 2 ); archivaConfigControl.replay(); @@ -504,7 +520,8 @@ public class MavenRepositorySearchTest SearchResultLimits limits = new SearchResultLimits( 0 ); limits.setPageSize( 1 ); - archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 1, 2 ); + //archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 1, 2 ); + EasyMock.expect( archivaConfig.getConfiguration() ).andReturn( config ).times( 1, 2 ); archivaConfigControl.replay(); @@ -522,7 +539,8 @@ public class MavenRepositorySearchTest limits = new SearchResultLimits( 1 ); limits.setPageSize( 1 ); - archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 1, 2 ); + //archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 1, 2 ); + EasyMock.expect( archivaConfig.getConfiguration() ).andReturn( config ).times( 1, 2 ); archivaConfigControl.replay(); @@ -554,7 +572,8 @@ public class MavenRepositorySearchTest searchFields.setArtifactId( "artifactid-numeric" ); searchFields.setRepositories( selectedRepos ); - archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 1, 2 ); + //archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 1, 2 ); + EasyMock.expect( archivaConfig.getConfiguration() ).andReturn( config ).times( 1, 2 ); archivaConfigControl.replay(); @@ -597,7 +616,8 @@ public class MavenRepositorySearchTest try { - archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 1, 2 ); + //archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 1, 2 ); + EasyMock.expect( archivaConfig.getConfiguration() ).andReturn( config ).times( 1, 2 ); archivaConfigControl.replay(); @@ -631,7 +651,8 @@ public class MavenRepositorySearchTest try { - archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 1, 2 ); + //archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 1, 2 ); + EasyMock.expect( archivaConfig.getConfiguration() ).andReturn( config ).times( 1, 2 ); archivaConfigControl.replay(); @@ -664,7 +685,8 @@ public class MavenRepositorySearchTest searchFields.setClassName( "org.apache.archiva.test.App" ); searchFields.setRepositories( selectedRepos ); - archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 1, 2 ); + //archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 1, 2 ); + EasyMock.expect( archivaConfig.getConfiguration() ).andReturn( config ).times( 1, 2 ); archivaConfigControl.replay(); @@ -695,7 +717,8 @@ public class MavenRepositorySearchTest searchFields.setPackaging( "jar" ); searchFields.setRepositories( selectedRepos ); - archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 1, 2 ); + //archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 1, 2 ); + EasyMock.expect( archivaConfig.getConfiguration() ).andReturn( config ).times( 1, 2 ); archivaConfigControl.replay(); @@ -723,7 +746,8 @@ public class MavenRepositorySearchTest searchFields.setPackaging( "war" ); searchFields.setRepositories( selectedRepos ); - archivaConfigControl.expectAndDefaultReturn( archivaConfig.getConfiguration(), config ); + //archivaConfigControl.expectAndDefaultReturn( archivaConfig.getConfiguration(), config ); + EasyMock.expect( archivaConfig.getConfiguration() ).andReturn( config ).times( 1, 2 ); archivaConfigControl.replay(); SearchResults results = search.search( "user", searchFields, null ); @@ -746,7 +770,8 @@ public class MavenRepositorySearchTest searchFields.setClassName( "com.classname.search.App" ); searchFields.setRepositories( selectedRepos ); - archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 1, 2 ); + //archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 1, 2 ); + EasyMock.expect( archivaConfig.getConfiguration() ).andReturn( config ).times( 1, 2 ); archivaConfigControl.replay(); @@ -774,7 +799,8 @@ public class MavenRepositorySearchTest searchFields.setGroupId( "org.apache.archiva" ); searchFields.setRepositories( selectedRepos ); - archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 1, 2 ); + //archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 1, 2 ); + EasyMock.expect( archivaConfig.getConfiguration() ).andReturn( config ).times( 1, 2 ); archivaConfigControl.replay(); @@ -798,7 +824,8 @@ public class MavenRepositorySearchTest searchFields.setClassName( "SomeClass" ); searchFields.setRepositories( selectedRepos ); - archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 1, 2 ); + //archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 1, 2 ); + EasyMock.expect( archivaConfig.getConfiguration() ).andReturn( config ).times( 1, 2 ); archivaConfigControl.replay(); @@ -819,7 +846,8 @@ public class MavenRepositorySearchTest List selectedRepos = Arrays.asList( TEST_REPO_1 ); - archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 0, 2 ); + //archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 0, 2 ); + EasyMock.expect( archivaConfig.getConfiguration() ).andReturn( config ).times( 0, 2 ); archivaConfigControl.replay(); @@ -847,7 +875,8 @@ public class MavenRepositorySearchTest searchFields.setClassName( "SomeClass" ); searchFields.setRepositories( selectedRepos ); - archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 1, 2 ); + //archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 1, 2 ); + EasyMock.expect( archivaConfig.getConfiguration() ).andReturn( config ).times( 1, 2 ); archivaConfigControl.replay(); @@ -877,7 +906,8 @@ public class MavenRepositorySearchTest SearchResultLimits limits = new SearchResultLimits( 0 ); limits.setPageSize( 300 ); - archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 1, 5 ); + //archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 1, 5 ); + EasyMock.expect( archivaConfig.getConfiguration() ).andReturn( config ).times( 1, 5 ); archivaConfigControl.replay(); 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( 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( 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 configListeners = new HashSet(); - 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 diff --git a/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/RepositoryContentConsumersTest.java b/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/RepositoryContentConsumersTest.java index b1ab0a727..7d23630d1 100644 --- a/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/RepositoryContentConsumersTest.java +++ b/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/RepositoryContentConsumersTest.java @@ -26,7 +26,7 @@ import org.apache.archiva.configuration.ArchivaConfiguration; import org.apache.archiva.consumers.InvalidRepositoryContentConsumer; import org.apache.archiva.consumers.KnownRepositoryContentConsumer; import org.apache.commons.lang.SystemUtils; -import org.easymock.MockControl; +import org.easymock.IMocksControl; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.BeansException; @@ -53,6 +53,7 @@ import java.util.List; import java.util.Locale; import java.util.Map; import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner; +import static org.easymock.EasyMock.*; /** * RepositoryContentConsumersTest @@ -243,24 +244,32 @@ public class RepositoryContentConsumersTest public void testExecution( ) throws Exception { - MockControl knownControl = MockControl.createNiceControl( KnownRepositoryContentConsumer.class ); + IMocksControl knownControl = createNiceControl( ); + RepositoryContentConsumers consumers = lookupRepositoryConsumers( ); - KnownRepositoryContentConsumer selectedKnownConsumer = (KnownRepositoryContentConsumer) knownControl.getMock( ); - KnownRepositoryContentConsumer unselectedKnownConsumer = - (KnownRepositoryContentConsumer) MockControl.createNiceControl( - KnownRepositoryContentConsumer.class ).getMock( ); + KnownRepositoryContentConsumer selectedKnownConsumer = knownControl.createMock( KnownRepositoryContentConsumer.class ); + + //KnownRepositoryContentConsumer unselectedKnownConsumer = + // (KnownRepositoryContentConsumer) MockControl.createNiceControl( + // KnownRepositoryContentConsumer.class ).getMock( ); + + KnownRepositoryContentConsumer unselectedKnownConsumer = createNiceControl().createMock( KnownRepositoryContentConsumer.class ); + consumers.setApplicationContext( new MockApplicationContext( Arrays.asList( selectedKnownConsumer, unselectedKnownConsumer ), null ) ); consumers.setSelectedKnownConsumers( Collections.singletonList( selectedKnownConsumer ) ); - MockControl invalidControl = MockControl.createControl( InvalidRepositoryContentConsumer.class ); - InvalidRepositoryContentConsumer selectedInvalidConsumer = - (InvalidRepositoryContentConsumer) invalidControl.getMock( ); - InvalidRepositoryContentConsumer unselectedInvalidConsumer = - (InvalidRepositoryContentConsumer) MockControl.createControl( - InvalidRepositoryContentConsumer.class ).getMock( ); + IMocksControl invalidControl = createControl(); + + InvalidRepositoryContentConsumer selectedInvalidConsumer = invalidControl.createMock( InvalidRepositoryContentConsumer.class ); + + //InvalidRepositoryContentConsumer unselectedInvalidConsumer = + // (InvalidRepositoryContentConsumer) MockControl.createControl( + // InvalidRepositoryContentConsumer.class ).getMock( ); + + InvalidRepositoryContentConsumer unselectedInvalidConsumer = createControl().createMock( InvalidRepositoryContentConsumer.class ); consumers.setApplicationContext( new MockApplicationContext( null, Arrays.asList( selectedInvalidConsumer, unselectedInvalidConsumer ) ) ); @@ -274,11 +283,9 @@ public class RepositoryContentConsumersTest startTime.setTime( 12345678 ); selectedKnownConsumer.beginScan( repo, startTime, false ); - selectedKnownConsumer.getExcludes( ); - knownControl.setReturnValue( Collections.EMPTY_LIST ); - selectedKnownConsumer.getIncludes( ); - knownControl.setReturnValue( Collections.singletonList( "**/*.txt" ) ); + expect( selectedKnownConsumer.getIncludes( ) ).andReturn( Collections.singletonList( "**/*.txt" ) ); selectedKnownConsumer.processFile( _OS( "path/to/test-file.txt" ), false ); + // knownConsumer.completeScan(); knownControl.replay( ); @@ -286,28 +293,34 @@ public class RepositoryContentConsumersTest // invalidConsumer.completeScan(); invalidControl.replay( ); + consumers.executeConsumers( repo, testFile, true ); knownControl.verify( ); invalidControl.verify( ); + //verify( in ); knownControl.reset( ); invalidControl.reset( ); + File notIncludedTestFile = new File( "target/test-repo/path/to/test-file.xml" ); selectedKnownConsumer.beginScan( repo, startTime, false ); - selectedKnownConsumer.getExcludes( ); - knownControl.setReturnValue( Collections.EMPTY_LIST ); - selectedKnownConsumer.getIncludes( ); - knownControl.setReturnValue( Collections.singletonList( "**/*.txt" ) ); + //selectedKnownConsumer.getExcludes( ); + //knownControl.setReturnValue( Collections.EMPTY_LIST ); + expect( selectedKnownConsumer.getExcludes() ).andReturn( Collections.emptyList() ); + + //selectedKnownConsumer.getIncludes( ); + //knownControl.setReturnValue( Collections.singletonList( "**/*.txt" ) ); + expect( selectedKnownConsumer.getIncludes( ) ).andReturn( Collections.singletonList( "**/*.txt" ) ); + // knownConsumer.completeScan(); knownControl.replay( ); selectedInvalidConsumer.beginScan( repo, startTime, false ); selectedInvalidConsumer.processFile( _OS( "path/to/test-file.xml" ), false ); - selectedInvalidConsumer.getId( ); - invalidControl.setReturnValue( "invalid" ); + expect( selectedInvalidConsumer.getId() ).andReturn( "invalid" ); // invalidConsumer.completeScan(); invalidControl.replay( ); @@ -322,15 +335,13 @@ public class RepositoryContentConsumersTest File excludedTestFile = new File( "target/test-repo/path/to/test-file.txt" ); selectedKnownConsumer.beginScan( repo, startTime, false ); - selectedKnownConsumer.getExcludes( ); - knownControl.setReturnValue( Collections.singletonList( "**/test-file.txt" ) ); + expect( selectedKnownConsumer.getExcludes() ).andReturn( Collections.singletonList( "**/test-file.txt" ) ); // knownConsumer.completeScan(); knownControl.replay( ); selectedInvalidConsumer.beginScan( repo, startTime, false ); selectedInvalidConsumer.processFile( _OS( "path/to/test-file.txt" ), false ); - selectedInvalidConsumer.getId( ); - invalidControl.setReturnValue( "invalid" ); + expect( selectedInvalidConsumer.getId() ).andReturn( "invalid" ); // invalidConsumer.completeScan(); invalidControl.replay( ); diff --git a/archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/processor/NewVersionsOfArtifactRssFeedProcessorTest.java b/archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/processor/NewVersionsOfArtifactRssFeedProcessorTest.java index f0562af06..bd1ee6770 100644 --- a/archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/processor/NewVersionsOfArtifactRssFeedProcessorTest.java +++ b/archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/processor/NewVersionsOfArtifactRssFeedProcessorTest.java @@ -25,7 +25,8 @@ import junit.framework.TestCase; import org.apache.archiva.metadata.model.ArtifactMetadata; import org.apache.archiva.metadata.repository.MetadataRepository; import org.apache.archiva.rss.RssFeedGenerator; -import org.easymock.MockControl; +import org.apache.archiva.test.utils.ArchivaBlockJUnit4ClassRunner; +import org.easymock.IMocksControl; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -36,9 +37,11 @@ import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; -import org.apache.archiva.test.utils.ArchivaBlockJUnit4ClassRunner; -@RunWith( ArchivaBlockJUnit4ClassRunner.class ) +import static org.easymock.EasyMock.createControl; +import static org.easymock.EasyMock.expect; + +@RunWith(ArchivaBlockJUnit4ClassRunner.class) public class NewVersionsOfArtifactRssFeedProcessorTest extends TestCase { @@ -50,7 +53,7 @@ public class NewVersionsOfArtifactRssFeedProcessorTest private static final String ARTIFACT_ID = "artifact-two"; - private MockControl metadataRepositoryControl; + private IMocksControl metadataRepositoryControl; private MetadataRepository metadataRepository; @@ -63,11 +66,11 @@ public class NewVersionsOfArtifactRssFeedProcessorTest newVersionsProcessor = new NewVersionsOfArtifactRssFeedProcessor(); newVersionsProcessor.setGenerator( new RssFeedGenerator() ); - metadataRepositoryControl = MockControl.createControl( MetadataRepository.class ); - metadataRepository = (MetadataRepository) metadataRepositoryControl.getMock(); + metadataRepositoryControl = createControl(); + metadataRepository = metadataRepositoryControl.createMock( MetadataRepository.class ); } - @SuppressWarnings( "unchecked" ) + @SuppressWarnings("unchecked") @Test public void testProcess() throws Exception @@ -85,20 +88,29 @@ public class NewVersionsOfArtifactRssFeedProcessorTest reqParams.put( RssFeedProcessor.KEY_GROUP_ID, GROUP_ID ); reqParams.put( RssFeedProcessor.KEY_ARTIFACT_ID, ARTIFACT_ID ); - metadataRepositoryControl.expectAndReturn( metadataRepository.getRepositories(), Collections.singletonList( - TEST_REPO ) ); - metadataRepositoryControl.expectAndReturn( metadataRepository.getProjectVersions( TEST_REPO, GROUP_ID, - ARTIFACT_ID ), Arrays.asList( - "1.0.1", "1.0.2", "1.0.3-SNAPSHOT" ) ); - metadataRepositoryControl.expectAndReturn( metadataRepository.getArtifacts( TEST_REPO, GROUP_ID, ARTIFACT_ID, - "1.0.1" ), - Collections.singletonList( artifact1 ) ); - metadataRepositoryControl.expectAndReturn( metadataRepository.getArtifacts( TEST_REPO, GROUP_ID, ARTIFACT_ID, - "1.0.2" ), - Collections.singletonList( artifact2 ) ); - metadataRepositoryControl.expectAndReturn( metadataRepository.getArtifacts( TEST_REPO, GROUP_ID, ARTIFACT_ID, - "1.0.3-SNAPSHOT" ), - Collections.singletonList( artifact3 ) ); + //metadataRepositoryControl.expectAndReturn( metadataRepository.getRepositories(), Collections.singletonList( + // TEST_REPO ) ); + expect( metadataRepository.getRepositories() ).andReturn( Collections.singletonList( TEST_REPO ) ); + //metadataRepositoryControl.expectAndReturn( metadataRepository.getProjectVersions( TEST_REPO, GROUP_ID, + // ARTIFACT_ID ), Arrays.asList( + // "1.0.1", "1.0.2", "1.0.3-SNAPSHOT" ) ); + expect( metadataRepository.getProjectVersions( TEST_REPO, GROUP_ID, ARTIFACT_ID ) ).andReturn( + Arrays.asList( "1.0.1", "1.0.2", "1.0.3-SNAPSHOT" ) ); + //metadataRepositoryControl.expectAndReturn( metadataRepository.getArtifacts( TEST_REPO, GROUP_ID, ARTIFACT_ID, + // "1.0.1" ), + // Collections.singletonList( artifact1 ) ); + expect( metadataRepository.getArtifacts( TEST_REPO, GROUP_ID, ARTIFACT_ID, "1.0.1" ) ).andReturn( + Collections.singletonList( artifact1 ) ); + //metadataRepositoryControl.expectAndReturn( metadataRepository.getArtifacts( TEST_REPO, GROUP_ID, ARTIFACT_ID, + // "1.0.2" ), + // Collections.singletonList( artifact2 ) ); + expect( metadataRepository.getArtifacts( TEST_REPO, GROUP_ID, ARTIFACT_ID, "1.0.2" ) ).andReturn( + Collections.singletonList( artifact2 ) ); + //metadataRepositoryControl.expectAndReturn( metadataRepository.getArtifacts( TEST_REPO, GROUP_ID, ARTIFACT_ID, + // "1.0.3-SNAPSHOT" ), + // Collections.singletonList( artifact3 ) ); + expect( metadataRepository.getArtifacts( TEST_REPO, GROUP_ID, ARTIFACT_ID, "1.0.3-SNAPSHOT" ) ).andReturn( + Collections.singletonList( artifact3 ) ); metadataRepositoryControl.replay(); SyndFeed feed = newVersionsProcessor.process( reqParams, metadataRepository ); @@ -113,8 +125,8 @@ public class NewVersionsOfArtifactRssFeedProcessorTest assertEquals( 2, entries.size() ); - assertEquals( "New Versions of Artifact 'org.apache.archiva:artifact-two' as of " + whenGathered, entries.get( - 0 ).getTitle() ); + assertEquals( "New Versions of Artifact 'org.apache.archiva:artifact-two' as of " + whenGathered, + entries.get( 0 ).getTitle() ); assertEquals( whenGathered, entries.get( 0 ).getPublishedDate() ); assertEquals( "New Versions of Artifact 'org.apache.archiva:artifact-two' as of " + whenGatheredNext, diff --git a/archiva-modules/archiva-web/archiva-security/src/test/java/org/apache/archiva/security/ArchivaServletAuthenticatorTest.java b/archiva-modules/archiva-web/archiva-security/src/test/java/org/apache/archiva/security/ArchivaServletAuthenticatorTest.java index baf48b2cf..3c63337ec 100644 --- a/archiva-modules/archiva-web/archiva-security/src/test/java/org/apache/archiva/security/ArchivaServletAuthenticatorTest.java +++ b/archiva-modules/archiva-web/archiva-security/src/test/java/org/apache/archiva/security/ArchivaServletAuthenticatorTest.java @@ -19,15 +19,16 @@ package org.apache.archiva.security; * under the License. */ -import org.apache.archiva.redback.users.User; -import org.apache.archiva.redback.users.UserManager; -import org.apache.archiva.security.common.ArchivaRoleConstants; import org.apache.archiva.redback.authentication.AuthenticationException; import org.apache.archiva.redback.authentication.AuthenticationResult; import org.apache.archiva.redback.authorization.UnauthorizedException; import org.apache.archiva.redback.system.DefaultSecuritySession; import org.apache.archiva.redback.system.SecuritySession; -import org.easymock.MockControl; +import org.apache.archiva.redback.users.User; +import org.apache.archiva.redback.users.UserManager; +import org.apache.archiva.security.common.ArchivaRoleConstants; +import org.easymock.EasyMock; +import org.easymock.IMocksControl; import org.junit.Before; import org.junit.Test; @@ -45,7 +46,7 @@ public class ArchivaServletAuthenticatorTest @Named( value = "servletAuthenticator#test" ) private ServletAuthenticator servletAuth; - private MockControl httpServletRequestControl; + private IMocksControl httpServletRequestControl; private HttpServletRequest request; @@ -55,8 +56,8 @@ public class ArchivaServletAuthenticatorTest { super.setUp(); - httpServletRequestControl = MockControl.createControl( HttpServletRequest.class ); - request = (HttpServletRequest) httpServletRequestControl.getMock(); + httpServletRequestControl = EasyMock.createControl( ); + request = httpServletRequestControl.createMock( HttpServletRequest.class ); setupRepository( "corporate" ); } @@ -123,7 +124,8 @@ public class ArchivaServletAuthenticatorTest assignRepositoryObserverRole( USER_ALPACA, "corporate" ); - httpServletRequestControl.expectAndReturn( request.getRemoteAddr(), "192.168.111.111" ); + //httpServletRequestControl.expectAndReturn( request.getRemoteAddr(), "192.168.111.111" ); + EasyMock.expect( request.getRemoteAddr() ).andReturn( "192.168.111.111" ); UserManager userManager = securitySystem.getUserManager(); User user = userManager.findUser( USER_ALPACA ); diff --git a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/ArchivaDavResourceFactoryTest.java b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/ArchivaDavResourceFactoryTest.java index 2190c195c..4ef1ff4d3 100644 --- a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/ArchivaDavResourceFactoryTest.java +++ b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/ArchivaDavResourceFactoryTest.java @@ -44,8 +44,8 @@ import org.apache.jackrabbit.webdav.DavException; import org.apache.jackrabbit.webdav.DavResourceLocator; import org.apache.jackrabbit.webdav.DavServletRequest; import org.apache.jackrabbit.webdav.DavServletResponse; -import org.easymock.MockControl; -import org.easymock.classextension.MockClassControl; + +import org.easymock.IMocksControl; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -59,6 +59,8 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; +import static org.easymock.EasyMock.*; + /** * ArchivaDavResourceFactoryTest */ @@ -79,25 +81,25 @@ public class ArchivaDavResourceFactoryTest private OverridingArchivaDavResourceFactory resourceFactory; - private MockControl requestControl; + private IMocksControl requestControl; private DavServletRequest request; - private MockControl repoRequestControl; + private IMocksControl repoRequestControl; private RepositoryRequest repoRequest; - private MockControl responseControl; + private IMocksControl responseControl; private DavServletResponse response; - private MockControl archivaConfigurationControl; + private IMocksControl archivaConfigurationControl; private ArchivaConfiguration archivaConfiguration; private Configuration config; - private MockControl repoContentFactoryControl; + private IMocksControl repoContentFactoryControl; private RepositoryContentFactory repoFactory; @@ -124,21 +126,23 @@ public class ArchivaDavResourceFactoryTest { super.setUp(); - requestControl = MockControl.createControl( DavServletRequest.class ); - request = (DavServletRequest) requestControl.getMock(); + requestControl = createControl(); + request = requestControl.createMock( DavServletRequest.class ); - responseControl = MockControl.createControl( DavServletResponse.class ); - response = (DavServletResponse) responseControl.getMock(); - responseControl.setDefaultMatcher( MockControl.ALWAYS_MATCHER ); + responseControl = createControl(); + response = responseControl.createMock( DavServletResponse.class ); + //responseControl.setDefaultMatcher( MockControl.ALWAYS_MATCHER ); - archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class ); - archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock(); + archivaConfigurationControl = createControl(); + archivaConfiguration = archivaConfigurationControl.createMock( ArchivaConfiguration.class ); config = new Configuration(); - archivaConfiguration.getConfiguration(); - archivaConfigurationControl.setReturnValue( config, 5, 20 ); + //archivaConfiguration.getConfiguration(); + //archivaConfigurationControl.setReturnValue( config, 5, 20 ); + expect( archivaConfiguration.getConfiguration() ).andReturn( config ).times( 5, 20 ); archivaConfiguration.save( config ); - archivaConfigurationControl.setVoidCallable( 1, 4 ); + //archivaConfigurationControl.setVoidCallable( 1, 4 ); + expectLastCall().times( 1, 4 ); archivaConfigurationControl.replay(); defaultManagedRepositoryAdmin.setArchivaConfiguration( archivaConfiguration ); @@ -167,11 +171,11 @@ public class ArchivaDavResourceFactoryTest defaultRepositoryGroupAdmin.addRepositoryGroup( repoGroupConfig, null ); } - repoContentFactoryControl = MockClassControl.createControl( RepositoryContentFactory.class ); - repoFactory = (RepositoryContentFactory) repoContentFactoryControl.getMock(); + repoContentFactoryControl = createControl(); + repoFactory = repoContentFactoryControl.createMock( RepositoryContentFactory.class ); - repoRequestControl = MockClassControl.createControl( RepositoryRequest.class ); - repoRequest = (RepositoryRequest) repoRequestControl.getMock(); + repoRequestControl = createControl(); + repoRequest = repoRequestControl.createMock( RepositoryRequest.class ); resourceFactory = new OverridingArchivaDavResourceFactory( applicationContext, plexusSisuBridge, archivaConfiguration ); @@ -224,33 +228,51 @@ public class ArchivaDavResourceFactoryTest try { archivaConfigurationControl.reset(); - archivaConfigurationControl.expectAndReturn( archivaConfiguration.getConfiguration(), config ); - requestControl.expectAndReturn( request.getMethod(), "GET", 2 ); - requestControl.expectAndReturn( request.getPathInfo(), "org/apache/archiva", 0, 2 ); - repoContentFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( RELEASES_REPO ), - releasesRepo ); - requestControl.expectAndReturn( request.getRemoteAddr(), "http://localhost:8080", 2 ); - requestControl.expectAndReturn( request.getDavSession(), new ArchivaDavSession(), 2 ); + //archivaConfigurationControl.expectAndReturn( archivaConfiguration.getConfiguration(), config ); + expect( archivaConfiguration.getConfiguration() ).andReturn( config ); + //requestControl.expectAndReturn( request.getMethod(), "GET", 2 ); + expect( request.getMethod() ).andReturn( "GET" ).times( 2 ); + //requestControl.expectAndReturn( request.getPathInfo(), "org/apache/archiva", 0, 2 ); + expect( request.getPathInfo() ).andReturn( "org/apache/archiva" ).times( 0, 2 ); + //repoContentFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( RELEASES_REPO ), + // releasesRepo ); + expect( repoFactory.getManagedRepositoryContent( RELEASES_REPO ) ).andReturn( releasesRepo ); + //requestControl.expectAndReturn( request.getRemoteAddr(), "http://localhost:8080", 2 ); + expect( request.getRemoteAddr() ).andReturn( "http://localhost:8080" ).times( 2 ); + //requestControl.expectAndReturn( request.getDavSession(), new ArchivaDavSession(), 2 ); + expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 2 ); - repoRequestControl.expectAndReturn( - repoRequest.isSupportFile( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ), + //repoRequestControl.expectAndReturn( + // repoRequest.isSupportFile( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ), + // false ); + expect( repoRequest.isSupportFile( + "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( true ); + //repoRequestControl.expectAndReturn( + // repoRequest.isDefault( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ), false ); + expect( + repoRequest.isDefault( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( false ); - repoRequestControl.expectAndReturn( - repoRequest.isDefault( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ), false ); - repoRequestControl.expectAndReturn( - repoRequest.toArtifactReference( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ), - null ); - repoRequestControl.expectAndReturn( - repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar", - internalRepo ), + //repoRequestControl.expectAndReturn( + // repoRequest.toArtifactReference( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ), + // null ); + expect( repoRequest.toArtifactReference( + "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( null ); + //repoRequestControl.expectAndReturn( + // repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar", internalRepo ), + // new File( config.findManagedRepositoryById( INTERNAL_REPO ).getLocation(), + // "target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ).getPath() ); + expect( repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar", + internalRepo ) ).andReturn( new File( config.findManagedRepositoryById( INTERNAL_REPO ).getLocation(), "target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ).getPath() ); - repoContentFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ), - internalRepo ); - repoRequestControl.expectAndReturn( - repoRequest.isArchetypeCatalog( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ), - false ); - + //repoContentFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ), + // internalRepo ); + expect( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ) ).andReturn( internalRepo ); + //repoRequestControl.expectAndReturn( + // repoRequest.isArchetypeCatalog( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ), + // false ); + expect( repoRequest.isArchetypeCatalog( + "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( false ); archivaConfigurationControl.replay(); requestControl.replay(); repoContentFactoryControl.replay(); @@ -296,32 +318,51 @@ public class ArchivaDavResourceFactoryTest try { archivaConfigurationControl.reset(); - archivaConfigurationControl.expectAndReturn( archivaConfiguration.getConfiguration(), config ); - requestControl.expectAndReturn( request.getMethod(), "GET", 2 ); - requestControl.expectAndReturn( request.getPathInfo(), "org/apache/archiva", 0, 2 ); - repoContentFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ), - internalRepo ); - repoContentFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( RELEASES_REPO ), - releasesRepo ); - requestControl.expectAndReturn( request.getRemoteAddr(), "http://localhost:8080", 2 ); - requestControl.expectAndReturn( request.getDavSession(), new ArchivaDavSession(), 2 ); - repoRequestControl.expectAndReturn( - repoRequest.isSupportFile( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ), + //archivaConfigurationControl.expectAndReturn( archivaConfiguration.getConfiguration(), config ); + expect( archivaConfiguration.getConfiguration() ).andReturn( config ); + //requestControl.expectAndReturn( request.getMethod(), "GET", 2 ); + expect( request.getMethod() ).andReturn( "GET" ).times( 2 ); + //requestControl.expectAndReturn( request.getPathInfo(), "org/apache/archiva", 0, 2 ); + expect( request.getPathInfo() ).andReturn( "org/apache/archiva" ).times( 0, 2 ); + //repoContentFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ), + // internalRepo ); + expect( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ) ).andReturn( internalRepo ); + //repoContentFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( RELEASES_REPO ), + // releasesRepo ); + expect( repoFactory.getManagedRepositoryContent( RELEASES_REPO ) ).andReturn( releasesRepo ); + //requestControl.expectAndReturn( request.getRemoteAddr(), "http://localhost:8080", 2 ); + expect( request.getRemoteAddr() ).andReturn( "http://localhost:8080" ).times( 2 ); + //requestControl.expectAndReturn( request.getDavSession(), new ArchivaDavSession(), 2 ); + expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 2 ); + //repoRequestControl.expectAndReturn( + // repoRequest.isSupportFile( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ), + // false ); + expect( repoRequest.isSupportFile( + "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( false ); + //repoRequestControl.expectAndReturn( + // repoRequest.isDefault( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ), false ); + expect( + repoRequest.isDefault( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( false ); - repoRequestControl.expectAndReturn( - repoRequest.isDefault( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ), false ); - repoRequestControl.expectAndReturn( - repoRequest.toArtifactReference( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ), - null ); - repoRequestControl.expectAndReturn( - repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar", - internalRepo ), + //repoRequestControl.expectAndReturn( + // repoRequest.toArtifactReference( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ), + // null ); + expect( repoRequest.toArtifactReference( + "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( null ); + //repoRequestControl.expectAndReturn( + // repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar", internalRepo ), + // new File( config.findManagedRepositoryById( INTERNAL_REPO ).getLocation(), + // "target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ).getPath() ); + expect( repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar", + internalRepo ) ).andReturn( new File( config.findManagedRepositoryById( INTERNAL_REPO ).getLocation(), "target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ).getPath() ); - repoRequestControl.expectAndReturn( - repoRequest.isArchetypeCatalog( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ), - false ); + //repoRequestControl.expectAndReturn( + // repoRequest.isArchetypeCatalog( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ), + // false ); + expect( repoRequest.isArchetypeCatalog( + "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( false ); archivaConfigurationControl.replay(); requestControl.replay(); repoContentFactoryControl.replay(); @@ -370,39 +411,58 @@ public class ArchivaDavResourceFactoryTest try { archivaConfigurationControl.reset(); - archivaConfigurationControl.expectAndReturn( archivaConfiguration.getConfiguration(), config ); - requestControl.expectAndReturn( request.getMethod(), "GET", 4 ); - requestControl.expectAndReturn( request.getPathInfo(), "org/apache/archiva", 0, 2 ); - repoContentFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ), - internalRepo ); - repoContentFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( LOCAL_MIRROR_REPO ), - localMirrorRepo ); - requestControl.expectAndReturn( request.getRemoteAddr(), "http://localhost:8080", 4 ); - requestControl.expectAndReturn( request.getDavSession(), new ArchivaDavSession(), 4 ); - repoRequestControl.expectAndReturn( - repoRequest.isSupportFile( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ), false, - 2 ); - repoRequestControl.expectAndReturn( - repoRequest.isDefault( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ), false, 2 ); - repoRequestControl.expectAndReturn( - repoRequest.toArtifactReference( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ), - null, 2 ); - repoRequestControl.expectAndReturn( - repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar", - internalRepo ), + //archivaConfigurationControl.expectAndReturn( archivaConfiguration.getConfiguration(), config ); + expect( archivaConfiguration.getConfiguration() ).andReturn( config ); + //requestControl.expectAndReturn( request.getMethod(), "GET", 4 ); + expect( request.getMethod() ).andReturn( "GET" ).times( 4 ); + //requestControl.expectAndReturn( request.getPathInfo(), "org/apache/archiva", 0, 2 ); + expect( request.getPathInfo() ).andReturn( "org/apache/archiva" ).times( 0, 2 ); + //repoContentFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ), + // internalRepo ); + expect( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ) ).andReturn( internalRepo ); + //repoContentFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( LOCAL_MIRROR_REPO ), + // localMirrorRepo ); + expect( repoFactory.getManagedRepositoryContent( LOCAL_MIRROR_REPO ) ).andReturn( localMirrorRepo ); + //requestControl.expectAndReturn( request.getRemoteAddr(), "http://localhost:8080", 4 ); + expect( request.getRemoteAddr() ).andReturn( "http://localhost:8080" ).times( 4 ); + //requestControl.expectAndReturn( request.getDavSession(), new ArchivaDavSession(), 4 ); + expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 4 ); + //repoRequestControl.expectAndReturn( + // repoRequest.isSupportFile( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ), false, + // 2 ); + expect( repoRequest.isSupportFile( + "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( false ).times( 2 ); + //repoRequestControl.expectAndReturn( + // repoRequest.isDefault( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ), false, 2 ); + expect( + repoRequest.isDefault( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( + false ).times( 2 ); + //repoRequestControl.expectAndReturn( + // repoRequest.toArtifactReference( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ), + // null, 2 ); + expect( repoRequest.toArtifactReference( + "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( null ).times( 2 ); + //repoRequestControl.expectAndReturn( + //repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar", + // internalRepo ), + //new File( config.findManagedRepositoryById( INTERNAL_REPO ).getLocation(), + // "target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ).getPath() ); + expect( repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar", + internalRepo ) ).andReturn( new File( config.findManagedRepositoryById( INTERNAL_REPO ).getLocation(), "target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ).getPath() ); - - repoRequestControl.expectAndReturn( - repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar", - localMirrorRepo ), - new File( config.findManagedRepositoryById( LOCAL_MIRROR_REPO ).getLocation(), - "target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ).getPath() ); - - repoRequestControl.expectAndReturn( - repoRequest.isArchetypeCatalog( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ), - false , 2); - + //repoRequestControl.expectAndReturn( + // repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar", localMirrorRepo ), + // new File( config.findManagedRepositoryById( LOCAL_MIRROR_REPO ).getLocation(), + // "target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ).getPath() ); + expect( repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar", + localMirrorRepo ) ) + .andReturn( new File( config.findManagedRepositoryById( LOCAL_MIRROR_REPO ).getLocation(), + "target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ).getPath() ); + //repoRequestControl.expectAndReturn( + // repoRequest.isArchetypeCatalog( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ), + // false, 2 ); + expect( repoRequest.isArchetypeCatalog( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( false ).times( 2 ); archivaConfigurationControl.replay(); requestControl.replay(); repoContentFactoryControl.replay(); @@ -442,24 +502,32 @@ public class ArchivaDavResourceFactoryTest try { archivaConfigurationControl.reset(); - archivaConfigurationControl.expectAndReturn( archivaConfiguration.getConfiguration(), config ); - repoContentFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ), - internalRepo ); - requestControl.expectAndReturn( request.getMethod(), "GET", 3 ); - requestControl.expectAndReturn( request.getRemoteAddr(), "http://localhost:8080", 3 ); - requestControl.expectAndReturn( request.getDavSession(), new ArchivaDavSession(), 2 ); - requestControl.expectAndReturn( request.getRequestURI(), - "http://localhost:8080/archiva/repository/" + INTERNAL_REPO - + "/eclipse/jdtcore/maven-metadata.xml" ); + //archivaConfigurationControl.expectAndReturn( archivaConfiguration.getConfiguration(), config ); + expect( archivaConfiguration.getConfiguration() ).andReturn( config ); + //repoContentFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ), + // internalRepo ); + expect( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ) ).andReturn( internalRepo ); + //requestControl.expectAndReturn( request.getMethod(), "GET", 3 ); + expect( request.getMethod() ).andReturn( "GET" ).times( 3 ); + //requestControl.expectAndReturn( request.getRemoteAddr(), "http://localhost:8080", 3 ); + expect( request.getRemoteAddr() ).andReturn( "http://localhost:8080" ).times( 3 ); + //requestControl.expectAndReturn( request.getDavSession(), new ArchivaDavSession(), 2 ); + expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 2 ); + //requestControl.expectAndReturn( request.getRequestURI(), + // "http://localhost:8080/archiva/repository/" + INTERNAL_REPO + "/eclipse/jdtcore/maven-metadata.xml" ); + expect( request.getRequestURI() ).andReturn( "http://localhost:8080/archiva/repository/" + INTERNAL_REPO + "/eclipse/jdtcore/maven-metadata.xml" ); response.setHeader( "Pragma", "no-cache" ); - responseControl.setVoidCallable(); + //responseControl.setVoidCallable(); + expectLastCall(); response.setHeader( "Cache-Control", "no-cache" ); - responseControl.setVoidCallable(); + //responseControl.setVoidCallable(); + expectLastCall(); - long date = 2039842134; - response.setDateHeader( "last-modified", date ); - responseControl.setVoidCallable(); + //long date = 2039842134; + response.setDateHeader( eq("Last-Modified"), anyLong() ); + //responseControl.setVoidCallable(); + expectLastCall(); archivaConfigurationControl.replay(); repoContentFactoryControl.replay(); @@ -497,12 +565,17 @@ public class ArchivaDavResourceFactoryTest try { archivaConfigurationControl.reset(); - archivaConfigurationControl.expectAndReturn( archivaConfiguration.getConfiguration(), config ); - repoContentFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ), - internalRepo ); - requestControl.expectAndReturn( request.getMethod(), "GET", 2 ); - requestControl.expectAndReturn( request.getRemoteAddr(), "http://localhost:8080", 2 ); - requestControl.expectAndReturn( request.getDavSession(), new ArchivaDavSession(), 2 ); + //archivaConfigurationControl.expectAndReturn( archivaConfiguration.getConfiguration(), config ); + expect( archivaConfiguration.getConfiguration() ).andReturn( config ); + //repoContentFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ), + // internalRepo ); + expect( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ) ).andReturn( internalRepo ); + //requestControl.expectAndReturn( request.getMethod(), "GET", 2 ); + expect( request.getMethod() ).andReturn( "GET" ).times( 2 ); + //requestControl.expectAndReturn( request.getRemoteAddr(), "http://localhost:8080", 2 ); + expect( request.getRemoteAddr() ).andReturn( "http://localhost:8080" ).times( 2 ); + //requestControl.expectAndReturn( request.getDavSession(), new ArchivaDavSession(), 2 ); + expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 2 ); archivaConfigurationControl.replay(); repoContentFactoryControl.replay(); @@ -542,12 +615,17 @@ public class ArchivaDavResourceFactoryTest try { archivaConfigurationControl.reset(); - archivaConfigurationControl.expectAndReturn( archivaConfiguration.getConfiguration(), config ); - repoContentFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( LEGACY_REPO ), - legacyRepo ); - requestControl.expectAndReturn( request.getMethod(), "GET", 2 ); - requestControl.expectAndReturn( request.getRemoteAddr(), "http://localhost:8080", 2 ); - requestControl.expectAndReturn( request.getDavSession(), new ArchivaDavSession(), 2 ); + //archivaConfigurationControl.expectAndReturn( archivaConfiguration.getConfiguration(), config ); + expect( archivaConfiguration.getConfiguration() ).andReturn( config ); + //repoContentFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( LEGACY_REPO ), + // legacyRepo ); + expect( repoFactory.getManagedRepositoryContent( LEGACY_REPO ) ).andReturn( legacyRepo ); + //requestControl.expectAndReturn( request.getMethod(), "GET", 2 ); + expect( request.getMethod() ).andReturn( "GET" ).times( 2 ); + //requestControl.expectAndReturn( request.getRemoteAddr(), "http://localhost:8080", 2 ); + expect( request.getRemoteAddr() ).andReturn( "http://localhost:8080" ).times( 2 ); + //requestControl.expectAndReturn( request.getDavSession(), new ArchivaDavSession(), 2 ); + expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 2 ); archivaConfigurationControl.replay(); repoContentFactoryControl.replay(); diff --git a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/RepositoryServletSecurityTest.java b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/RepositoryServletSecurityTest.java index c818b09db..15345225b 100644 --- a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/RepositoryServletSecurityTest.java +++ b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/RepositoryServletSecurityTest.java @@ -29,25 +29,26 @@ import com.meterware.servletunit.ServletRunner; import com.meterware.servletunit.ServletUnitClient; import junit.framework.TestCase; import net.sf.ehcache.CacheManager; -import org.apache.archiva.redback.authentication.AuthenticationException; -import org.apache.archiva.redback.users.User; -import org.apache.archiva.repository.audit.TestAuditListener; -import org.apache.archiva.security.common.ArchivaRoleConstants; -import org.apache.commons.io.FileUtils; -import org.apache.jackrabbit.webdav.DavSessionProvider; import org.apache.archiva.configuration.ArchivaConfiguration; import org.apache.archiva.configuration.Configuration; import org.apache.archiva.configuration.ManagedRepositoryConfiguration; -import org.apache.archiva.security.ServletAuthenticator; +import org.apache.archiva.redback.authentication.AuthenticationException; import org.apache.archiva.redback.authentication.AuthenticationResult; import org.apache.archiva.redback.authorization.UnauthorizedException; +import org.apache.archiva.redback.integration.filter.authentication.HttpAuthenticator; import org.apache.archiva.redback.system.DefaultSecuritySession; import org.apache.archiva.redback.system.SecuritySession; +import org.apache.archiva.redback.users.User; import org.apache.archiva.redback.users.memory.SimpleUser; -import org.apache.archiva.redback.integration.filter.authentication.HttpAuthenticator; -import org.apache.archiva.redback.integration.filter.authentication.basic.HttpBasicAuthentication; -import org.easymock.MockControl; -import org.easymock.classextension.MockClassControl; +import org.apache.archiva.repository.audit.TestAuditListener; +import org.apache.archiva.security.ServletAuthenticator; +import org.apache.archiva.security.common.ArchivaRoleConstants; +import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner; +import org.apache.commons.io.FileUtils; +import org.apache.jackrabbit.webdav.DavSessionProvider; +import org.easymock.EasyMock; +import static org.easymock.EasyMock.*; +import org.easymock.IMocksControl; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -56,19 +57,17 @@ import org.springframework.context.ApplicationContext; import org.springframework.test.context.ContextConfiguration; import javax.inject.Inject; +import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.nio.charset.Charset; -import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner; - /** * RepositoryServletSecurityTest Test the flow of the authentication and authorization checks. This does not necessarily * perform redback security checking. - * - * */ @RunWith( ArchivaSpringJUnit4ClassRunner.class ) @ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" } ) @@ -87,11 +86,11 @@ public class RepositoryServletSecurityTest private DavSessionProvider davSessionProvider; - private MockControl servletAuthControl; + private IMocksControl servletAuthControl; private ServletAuthenticator servletAuth; - private MockClassControl httpAuthControl; + private IMocksControl httpAuthControl; private HttpAuthenticator httpAuth; @@ -106,7 +105,8 @@ public class RepositoryServletSecurityTest { super.setUp(); - String appserverBase = System.getProperty( "appserver.base", new File( "target/appserver-base" ).getAbsolutePath() ); + String appserverBase = + System.getProperty( "appserver.base", new File( "target/appserver-base" ).getAbsolutePath() ); File testConf = new File( "src/test/resources/repository-archiva.xml" ); File testConfDest = new File( appserverBase, "conf/archiva.xml" ); @@ -117,9 +117,10 @@ public class RepositoryServletSecurityTest archivaConfiguration = applicationContext.getBean( ArchivaConfiguration.class ); Configuration config = archivaConfiguration.getConfiguration(); - if (!config.getManagedRepositoriesAsMap().containsKey( REPOID_INTERNAL )) + if ( !config.getManagedRepositoriesAsMap().containsKey( REPOID_INTERNAL ) ) { - config.addManagedRepository( createManagedRepository( REPOID_INTERNAL, "Internal Test Repo", repoRootInternal ) ); + config.addManagedRepository( + createManagedRepository( REPOID_INTERNAL, "Internal Test Repo", repoRootInternal ) ); } saveConfiguration( archivaConfiguration ); @@ -131,14 +132,14 @@ public class RepositoryServletSecurityTest sr.registerServlet( "/repository/*", RepositoryServlet.class.getName() ); sc = sr.newClient(); - servletAuthControl = MockControl.createControl( ServletAuthenticator.class ); - servletAuthControl.setDefaultMatcher( MockControl.ALWAYS_MATCHER ); - servletAuth = (ServletAuthenticator) servletAuthControl.getMock(); + servletAuthControl = EasyMock.createControl();// MockControl.createControl( ServletAuthenticator.class ); + //servletAuthControl.setDefaultMatcher( MockControl.ALWAYS_MATCHER ); + servletAuth = servletAuthControl.createMock( ServletAuthenticator.class ); - httpAuthControl = - MockClassControl.createControl( HttpBasicAuthentication.class, HttpBasicAuthentication.class.getMethods() ); - httpAuthControl.setDefaultMatcher( MockControl.ALWAYS_MATCHER ); - httpAuth = (HttpAuthenticator) httpAuthControl.getMock(); + httpAuthControl = EasyMock.createControl(); + //MockClassControl.createControl( HttpBasicAuthentication.class, HttpBasicAuthentication.class.getMethods() ); + //httpAuthControl.setDefaultMatcher( MockControl.ALWAYS_MATCHER ); + httpAuth = httpAuthControl.createMock( HttpAuthenticator.class ); davSessionProvider = new ArchivaDavSessionProvider( servletAuth, httpAuth ); } @@ -217,13 +218,19 @@ public class RepositoryServletSecurityTest servlet.setDavSessionProvider( davSessionProvider ); AuthenticationResult result = new AuthenticationResult(); - httpAuthControl.expectAndReturn( httpAuth.getAuthenticationResult( null, null ), result ); - servletAuthControl.expectAndThrow( servletAuth.isAuthenticated( null, null ), - new AuthenticationException( "Authentication error" ) ); + //httpAuthControl.expectAndReturn( httpAuth.getAuthenticationResult( null, null ), result ); + EasyMock.expect( httpAuth.getAuthenticationResult( anyObject( HttpServletRequest.class ), + anyObject( HttpServletResponse.class ) ) ).andReturn( result ); + //servletAuthControl.expectAndThrow( servletAuth.isAuthenticated( null, null ), + // new AuthenticationException( "Authentication error" ) ); + servletAuth.isAuthenticated( EasyMock.anyObject( HttpServletRequest.class ), + EasyMock.anyObject( AuthenticationResult.class ) ); + EasyMock.expectLastCall().andThrow( new AuthenticationException( "Authentication error" ) ); servletAuth.isAuthorized( "guest", "internal", ArchivaRoleConstants.OPERATION_REPOSITORY_UPLOAD ); - servletAuthControl.setMatcher( MockControl.EQUALS_MATCHER ); - servletAuthControl.setThrowable( new UnauthorizedException( "'guest' has no write access to repository" ) ); + //servletAuthControl.setMatcher( MockControl.EQUALS_MATCHER ); + //servletAuthControl.setThrowable( new UnauthorizedException( "'guest' has no write access to repository" ) ); + EasyMock.expectLastCall().andThrow( new UnauthorizedException( "'guest' has no write access to repository" ) ); httpAuthControl.replay(); servletAuthControl.replay(); @@ -260,27 +267,41 @@ public class RepositoryServletSecurityTest servlet.setResourceFactory( archivaDavResourceFactory ); AuthenticationResult result = new AuthenticationResult(); - httpAuthControl.expectAndReturn( httpAuth.getAuthenticationResult( null, null ), result ); - servletAuthControl.expectAndThrow( servletAuth.isAuthenticated( null, null ), - new AuthenticationException( "Authentication error" ) ); + //httpAuthControl.expectAndReturn( httpAuth.getAuthenticationResult( null, null ), result ); + EasyMock.expect( httpAuth.getAuthenticationResult( anyObject( HttpServletRequest.class ), + anyObject( HttpServletResponse.class ) ) ).andReturn( result ); + //servletAuthControl.expectAndThrow( servletAuth.isAuthenticated( null, null ), + // new AuthenticationException( "Authentication error" ) ); - servletAuth.isAuthorized( "guest", "internal", ArchivaRoleConstants.OPERATION_REPOSITORY_UPLOAD ); - servletAuthControl.setMatcher( MockControl.EQUALS_MATCHER ); - servletAuthControl.setReturnValue( true ); + EasyMock.expect( servletAuth.isAuthenticated( anyObject( HttpServletRequest.class ), + anyObject( AuthenticationResult.class ) ) ).andThrow( + new AuthenticationException( "Authentication error" ) ); + + //servletAuthControl.setMatcher( MockControl.EQUALS_MATCHER ); + //servletAuthControl.setReturnValue( true ); + EasyMock.expect(servletAuth.isAuthorized( "guest", "internal", ArchivaRoleConstants.OPERATION_REPOSITORY_UPLOAD )).andReturn( true ); // ArchivaDavResourceFactory#isAuthorized() SecuritySession session = new DefaultSecuritySession(); - httpAuthControl.expectAndReturn( httpAuth.getAuthenticationResult( null, null ), result ); - httpAuthControl.expectAndReturn( httpAuth.getSecuritySession( ic.getRequest().getSession( true ) ), session ); - servletAuthControl.expectAndThrow( servletAuth.isAuthenticated( null, result ), - new AuthenticationException( "Authentication error" ) ); + //httpAuthControl.expectAndReturn( httpAuth.getAuthenticationResult( null, null ), result ); + EasyMock.expect( httpAuth.getAuthenticationResult( anyObject( HttpServletRequest.class ), + anyObject( HttpServletResponse.class ) ) ).andReturn( result ); + //httpAuthControl.expectAndReturn( httpAuth.getSecuritySession( ic.getRequest().getSession( true ) ), session ); + EasyMock.expect( httpAuth.getSecuritySession( anyObject( HttpSession.class ) ) ).andReturn( session ); + //servletAuthControl.expectAndThrow( servletAuth.isAuthenticated( null, result ), + // new AuthenticationException( "Authentication error" ) ); + EasyMock.expect(servletAuth.isAuthenticated( anyObject( HttpServletRequest.class ), eq(result) )).andThrow( new AuthenticationException( "Authentication error" ) ); - httpAuthControl.expectAndReturn( httpAuth.getSessionUser( ic.getRequest().getSession() ), null ); + //httpAuthControl.expectAndReturn( httpAuth.getSessionUser( ic.getRequest().getSession() ), null ); + EasyMock.expect( httpAuth.getSessionUser( anyObject( HttpSession.class ) ) ).andReturn( null ); // check if guest has write access - servletAuth.isAuthorized( "guest", "internal", ArchivaRoleConstants.OPERATION_REPOSITORY_UPLOAD ); - servletAuthControl.setMatcher( MockControl.EQUALS_MATCHER ); - servletAuthControl.setReturnValue( true ); + //servletAuth.isAuthorized( "guest", "internal", ArchivaRoleConstants.OPERATION_REPOSITORY_UPLOAD ); + //servletAuthControl.setMatcher( MockControl.EQUALS_MATCHER ); + //servletAuthControl.setReturnValue( true ); + EasyMock.expect( servletAuth.isAuthorized( "guest", "internal", + ArchivaRoleConstants.OPERATION_REPOSITORY_UPLOAD ) ).andReturn( + true ); httpAuthControl.replay(); servletAuthControl.replay(); @@ -316,20 +337,31 @@ public class RepositoryServletSecurityTest servlet.setResourceFactory( archivaDavResourceFactory ); AuthenticationResult result = new AuthenticationResult(); - httpAuthControl.expectAndReturn( httpAuth.getAuthenticationResult( null, null ), result ); - servletAuthControl.expectAndReturn( servletAuth.isAuthenticated( null, null ), true ); + //httpAuthControl.expectAndReturn( httpAuth.getAuthenticationResult( null, null ), result ); + EasyMock.expect( httpAuth.getAuthenticationResult( anyObject( HttpServletRequest.class ), + anyObject( HttpServletResponse.class ) ) ).andReturn( result ); + //servletAuthControl.expectAndReturn( servletAuth.isAuthenticated( null, null ), true ); + EasyMock.expect( servletAuth.isAuthenticated( anyObject( HttpServletRequest.class ), + anyObject( AuthenticationResult.class ) ) ).andReturn( true ); // ArchivaDavResourceFactory#isAuthorized() SecuritySession session = new DefaultSecuritySession(); - httpAuthControl.expectAndReturn( httpAuth.getAuthenticationResult( null, null ), result ); - httpAuthControl.expectAndReturn( httpAuth.getSecuritySession( ic.getRequest().getSession( true ) ), session ); - httpAuthControl.expectAndReturn( httpAuth.getSessionUser( ic.getRequest().getSession() ), new SimpleUser() ); - servletAuthControl.expectAndReturn( servletAuth.isAuthenticated( null, result ), true ); - servletAuthControl.expectAndThrow( - servletAuth.isAuthorized( null, session, "internal", - ArchivaRoleConstants.OPERATION_REPOSITORY_UPLOAD ), - new UnauthorizedException( "User not authorized" ) ); - + //httpAuthControl.expectAndReturn( httpAuth.getAuthenticationResult( null, null ), result ); + EasyMock.expect( httpAuth.getAuthenticationResult( anyObject( HttpServletRequest.class ), + anyObject( HttpServletResponse.class ) ) ).andReturn( result ); + //httpAuthControl.expectAndReturn( httpAuth.getSecuritySession( ic.getRequest().getSession( true ) ), session ); + EasyMock.expect( httpAuth.getSecuritySession( ic.getRequest().getSession( true ) ) ).andReturn( session ); + //httpAuthControl.expectAndReturn( httpAuth.getSessionUser( ic.getRequest().getSession() ), new SimpleUser() ); + EasyMock.expect( httpAuth.getSessionUser( ic.getRequest().getSession() ) ).andReturn( new SimpleUser() ); + //servletAuthControl.expectAndReturn( servletAuth.isAuthenticated( null, result ), true ); + EasyMock.expect( servletAuth.isAuthenticated( anyObject( HttpServletRequest.class ), + eq( result ) ) ).andReturn( true ); + //servletAuthControl.expectAndThrow( + // servletAuth.isAuthorized( null, session, "internal", ArchivaRoleConstants.OPERATION_REPOSITORY_UPLOAD ), + // new UnauthorizedException( "User not authorized" ) ); + EasyMock.expect( servletAuth.isAuthorized( anyObject( HttpServletRequest.class ), eq(session), eq("internal"), + eq(ArchivaRoleConstants.OPERATION_REPOSITORY_UPLOAD) ) ).andThrow( + new UnauthorizedException( "User not authorized" ) ); httpAuthControl.replay(); servletAuthControl.replay(); @@ -368,22 +400,34 @@ public class RepositoryServletSecurityTest servlet.setResourceFactory( archivaDavResourceFactory ); AuthenticationResult result = new AuthenticationResult(); - httpAuthControl.expectAndReturn( httpAuth.getAuthenticationResult( null, null ), result ); - servletAuthControl.expectAndReturn( servletAuth.isAuthenticated( null, null ), true ); + //httpAuthControl.expectAndReturn( httpAuth.getAuthenticationResult( null, null ), result ); + EasyMock.expect( httpAuth.getAuthenticationResult( anyObject( HttpServletRequest.class ), + anyObject( HttpServletResponse.class) )).andReturn( result ); + //servletAuthControl.expectAndReturn( servletAuth.isAuthenticated( null, null ), true ); + EasyMock.expect( servletAuth.isAuthenticated( anyObject( HttpServletRequest.class ), + anyObject( AuthenticationResult.class ) ) ).andReturn( true ); User user = new SimpleUser(); user.setUsername( "admin" ); - + // ArchivaDavResourceFactory#isAuthorized() SecuritySession session = new DefaultSecuritySession(); - httpAuthControl.expectAndReturn( httpAuth.getAuthenticationResult( null, null ), result ); - httpAuthControl.expectAndReturn( httpAuth.getSecuritySession( ic.getRequest().getSession( true ) ), session ); - httpAuthControl.expectAndReturn( httpAuth.getSessionUser( ic.getRequest().getSession() ), user ); - servletAuthControl.expectAndReturn( servletAuth.isAuthenticated( null, result ), true ); - servletAuthControl.expectAndReturn( - servletAuth.isAuthorized( null, session, "internal", - ArchivaRoleConstants.OPERATION_REPOSITORY_UPLOAD ), - true ); + //httpAuthControl.expectAndReturn( httpAuth.getAuthenticationResult( null, null ), result ); + EasyMock.expect( httpAuth.getAuthenticationResult(anyObject( HttpServletRequest.class ), + anyObject( HttpServletResponse.class) ) ).andReturn( result ); + //httpAuthControl.expectAndReturn( httpAuth.getSecuritySession( ic.getRequest().getSession( true ) ), session ); + EasyMock.expect( httpAuth.getSecuritySession( ic.getRequest().getSession( true ) ) ).andReturn( session ); + //httpAuthControl.expectAndReturn( httpAuth.getSessionUser( ic.getRequest().getSession() ), user ); + EasyMock.expect( httpAuth.getSessionUser( ic.getRequest().getSession() ) ).andReturn( user ); + //servletAuthControl.expectAndReturn( servletAuth.isAuthenticated( null, result ), true ); + EasyMock.expect( servletAuth.isAuthenticated( anyObject( HttpServletRequest.class ), eq(result) ) ).andReturn( + true ); + //servletAuthControl.expectAndReturn( + // servletAuth.isAuthorized( null, session, "internal", ArchivaRoleConstants.OPERATION_REPOSITORY_UPLOAD ), + // true ); + EasyMock.expect( servletAuth.isAuthorized( anyObject( HttpServletRequest.class ), eq(session), eq("internal"), + eq(ArchivaRoleConstants.OPERATION_REPOSITORY_UPLOAD) ) ).andReturn( + true ); httpAuthControl.replay(); servletAuthControl.replay(); @@ -409,7 +453,7 @@ public class RepositoryServletSecurityTest File artifactFile = new File( repoRootInternal, commonsLangJar ); artifactFile.getParentFile().mkdirs(); - FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, Charset.defaultCharset() ); + FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, Charset.defaultCharset() ); WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangJar ); InvocationContext ic = sc.newInvocation( request ); @@ -423,25 +467,37 @@ public class RepositoryServletSecurityTest servlet.setResourceFactory( archivaDavResourceFactory ); AuthenticationResult result = new AuthenticationResult(); - httpAuthControl.expectAndReturn( httpAuth.getAuthenticationResult( null, null ), result ); - servletAuthControl.expectAndThrow( servletAuth.isAuthenticated( null, null ), - new AuthenticationException( "Authentication error" ) ); - servletAuthControl.expectAndReturn( - servletAuth.isAuthorized( "guest", "internal", - ArchivaRoleConstants.OPERATION_REPOSITORY_ACCESS ), - true ); + //httpAuthControl.expectAndReturn( httpAuth.getAuthenticationResult( null, null ), result ); + EasyMock.expect( httpAuth.getAuthenticationResult( anyObject( HttpServletRequest.class ), anyObject( HttpServletResponse.class ) ) ) + .andReturn( result ); + //servletAuthControl.expectAndThrow( servletAuth.isAuthenticated( null, null ), + // new AuthenticationException( "Authentication error" ) ); + EasyMock.expect( servletAuth.isAuthenticated( anyObject( HttpServletRequest.class ), anyObject( AuthenticationResult.class ) ) ).andThrow( + new AuthenticationException( "Authentication error" ) ); + //servletAuthControl.expectAndReturn( + // servletAuth.isAuthorized( "guest", "internal", ArchivaRoleConstants.OPERATION_REPOSITORY_ACCESS ), + // true ); + EasyMock.expect( servletAuth.isAuthorized( "guest", "internal", + ArchivaRoleConstants.OPERATION_REPOSITORY_ACCESS ) ).andReturn( + true ); // ArchivaDavResourceFactory#isAuthorized() SecuritySession session = new DefaultSecuritySession(); - httpAuthControl.expectAndReturn( httpAuth.getAuthenticationResult( null, null ), result ); - httpAuthControl.expectAndReturn( httpAuth.getSecuritySession( ic.getRequest().getSession( true ) ), session ); - httpAuthControl.expectAndReturn( httpAuth.getSessionUser( ic.getRequest().getSession() ), null ); - servletAuthControl.expectAndReturn( servletAuth.isAuthenticated( null, result ), true ); - servletAuthControl.expectAndReturn( - servletAuth.isAuthorized( null, session, "internal", - ArchivaRoleConstants.OPERATION_REPOSITORY_UPLOAD ), - true ); - + //httpAuthControl.expectAndReturn( httpAuth.getAuthenticationResult( null, null ), result ); + EasyMock.expect( httpAuth.getAuthenticationResult( anyObject( HttpServletRequest.class ), anyObject( HttpServletResponse.class ) ) ).andReturn( result ); + //httpAuthControl.expectAndReturn( httpAuth.getSecuritySession( ic.getRequest().getSession( true ) ), session ); + EasyMock.expect( httpAuth.getSecuritySession( anyObject( HttpSession.class ) ) ).andReturn( session ); + //httpAuthControl.expectAndReturn( httpAuth.getSessionUser( ic.getRequest().getSession() ), null ); + EasyMock.expect( httpAuth.getSessionUser( anyObject( HttpSession.class ) ) ).andReturn( null ); + //servletAuthControl.expectAndReturn( servletAuth.isAuthenticated( null, result ), true ); + EasyMock.expect( servletAuth.isAuthenticated( anyObject( HttpServletRequest.class ), eq(result) ) ).andReturn( + true ); + //servletAuthControl.expectAndReturn( + // servletAuth.isAuthorized( null, session, "internal", ArchivaRoleConstants.OPERATION_REPOSITORY_UPLOAD ), + // true ); + EasyMock.expect( servletAuth.isAuthorized( anyObject( HttpServletRequest.class ), eq(session), eq("internal"), + eq(ArchivaRoleConstants.OPERATION_REPOSITORY_ACCESS) ) ).andReturn( + true ); httpAuthControl.replay(); servletAuthControl.replay(); @@ -465,7 +521,7 @@ public class RepositoryServletSecurityTest File artifactFile = new File( repoRootInternal, commonsLangJar ); artifactFile.getParentFile().mkdirs(); - FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, Charset.defaultCharset() ); + FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, Charset.defaultCharset() ); WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangJar ); InvocationContext ic = sc.newInvocation( request ); @@ -473,14 +529,18 @@ public class RepositoryServletSecurityTest servlet.setDavSessionProvider( davSessionProvider ); AuthenticationResult result = new AuthenticationResult(); - httpAuthControl.expectAndReturn( httpAuth.getAuthenticationResult( null, null ), result ); - servletAuthControl.expectAndThrow( servletAuth.isAuthenticated( null, null ), - new AuthenticationException( "Authentication error" ) ); - servletAuthControl.expectAndReturn( - servletAuth.isAuthorized( "guest", "internal", - ArchivaRoleConstants.OPERATION_REPOSITORY_ACCESS ), - false ); - + //httpAuthControl.expectAndReturn( httpAuth.getAuthenticationResult( null, null ), result ); + EasyMock.expect( httpAuth.getAuthenticationResult( anyObject( HttpServletRequest.class ), anyObject( HttpServletResponse.class ) ) ).andReturn( result ); + //servletAuthControl.expectAndThrow( servletAuth.isAuthenticated( null, null ), + // new AuthenticationException( "Authentication error" ) ); + EasyMock.expect( servletAuth.isAuthenticated( anyObject( HttpServletRequest.class ), anyObject( AuthenticationResult.class ) ) ).andThrow( + new AuthenticationException( "Authentication error" ) ); + //servletAuthControl.expectAndReturn( + // servletAuth.isAuthorized( "guest", "internal", ArchivaRoleConstants.OPERATION_REPOSITORY_ACCESS ), + // false ); + EasyMock.expect( servletAuth.isAuthorized( "guest", "internal", + ArchivaRoleConstants.OPERATION_REPOSITORY_ACCESS ) ).andReturn( + false ); httpAuthControl.replay(); servletAuthControl.replay(); @@ -503,7 +563,7 @@ public class RepositoryServletSecurityTest File artifactFile = new File( repoRootInternal, commonsLangJar ); artifactFile.getParentFile().mkdirs(); - FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, Charset.defaultCharset() ); + FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, Charset.defaultCharset() ); WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangJar ); InvocationContext ic = sc.newInvocation( request ); @@ -517,19 +577,27 @@ public class RepositoryServletSecurityTest servlet.setResourceFactory( archivaDavResourceFactory ); AuthenticationResult result = new AuthenticationResult(); - httpAuthControl.expectAndReturn( httpAuth.getAuthenticationResult( null, null ), result ); - servletAuthControl.expectAndReturn( servletAuth.isAuthenticated( null, null ), true ); - + //httpAuthControl.expectAndReturn( httpAuth.getAuthenticationResult( null, null ), result ); + EasyMock.expect( httpAuth.getAuthenticationResult( anyObject( HttpServletRequest.class ), anyObject( HttpServletResponse.class ) ) ).andReturn( result ); + //servletAuthControl.expectAndReturn( servletAuth.isAuthenticated( null, null ), true ); + EasyMock.expect( servletAuth.isAuthenticated( anyObject( HttpServletRequest.class ), anyObject( AuthenticationResult.class ) ) ).andReturn( true ); // ArchivaDavResourceFactory#isAuthorized() SecuritySession session = new DefaultSecuritySession(); - httpAuthControl.expectAndReturn( httpAuth.getAuthenticationResult( null, null ), result ); - httpAuthControl.expectAndReturn( httpAuth.getSecuritySession( ic.getRequest().getSession( true ) ), session ); - httpAuthControl.expectAndReturn( httpAuth.getSessionUser( ic.getRequest().getSession() ), new SimpleUser() ); - servletAuthControl.expectAndReturn( servletAuth.isAuthenticated( null, result ), true ); - servletAuthControl.expectAndReturn( - servletAuth.isAuthorized( null, session, "internal", - ArchivaRoleConstants.OPERATION_REPOSITORY_UPLOAD ), - true ); + //httpAuthControl.expectAndReturn( httpAuth.getAuthenticationResult( null, null ), result ); + EasyMock.expect( httpAuth.getAuthenticationResult( anyObject( HttpServletRequest.class ), anyObject( HttpServletResponse.class ) ) ).andReturn( result ); + //httpAuthControl.expectAndReturn( httpAuth.getSecuritySession( ic.getRequest().getSession( true ) ), session ); + EasyMock.expect( httpAuth.getSecuritySession( anyObject( HttpSession.class ) ) ).andReturn( session ); + //httpAuthControl.expectAndReturn( httpAuth.getSessionUser( ic.getRequest().getSession() ), new SimpleUser() ); + EasyMock.expect( httpAuth.getSessionUser( anyObject( HttpSession.class ) ) ).andReturn( new SimpleUser() ); + //servletAuthControl.expectAndReturn( servletAuth.isAuthenticated( null, result ), true ); + EasyMock.expect( servletAuth.isAuthenticated( anyObject( HttpServletRequest.class ), eq(result) ) ).andReturn( + true ); + //servletAuthControl.expectAndReturn( + // servletAuth.isAuthorized( null, session, "internal", ArchivaRoleConstants.OPERATION_REPOSITORY_UPLOAD ), + // true ); + EasyMock.expect( servletAuth.isAuthorized( anyObject( HttpServletRequest.class ), eq(session), eq("internal"), + eq(ArchivaRoleConstants.OPERATION_REPOSITORY_ACCESS) ) ).andReturn( + true ); httpAuthControl.replay(); servletAuthControl.replay(); @@ -554,7 +622,7 @@ public class RepositoryServletSecurityTest File artifactFile = new File( repoRootInternal, commonsLangJar ); artifactFile.getParentFile().mkdirs(); - FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, Charset.defaultCharset() ); + FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, Charset.defaultCharset() ); WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangJar ); InvocationContext ic = sc.newInvocation( request ); @@ -568,20 +636,27 @@ public class RepositoryServletSecurityTest servlet.setResourceFactory( archivaDavResourceFactory ); AuthenticationResult result = new AuthenticationResult(); - httpAuthControl.expectAndReturn( httpAuth.getAuthenticationResult( null, null ), result ); - servletAuthControl.expectAndReturn( servletAuth.isAuthenticated( null, null ), true ); + //httpAuthControl.expectAndReturn( httpAuth.getAuthenticationResult( null, null ), result ); + EasyMock.expect( httpAuth.getAuthenticationResult( anyObject( HttpServletRequest.class ), anyObject( HttpServletResponse.class ) ) ).andReturn( result ); + //servletAuthControl.expectAndReturn( servletAuth.isAuthenticated( null, null ), true ); + EasyMock.expect( servletAuth.isAuthenticated( anyObject( HttpServletRequest.class ), anyObject( AuthenticationResult.class ) ) ).andReturn( true ); // ArchivaDavResourceFactory#isAuthorized() SecuritySession session = new DefaultSecuritySession(); - httpAuthControl.expectAndReturn( httpAuth.getAuthenticationResult( null, null ), result ); - httpAuthControl.expectAndReturn( httpAuth.getSecuritySession( ic.getRequest().getSession( true ) ), session ); - httpAuthControl.expectAndReturn( httpAuth.getSessionUser( ic.getRequest().getSession() ), new SimpleUser() ); - servletAuthControl.expectAndReturn( servletAuth.isAuthenticated( null, result ), true ); - servletAuthControl.expectAndThrow( - servletAuth.isAuthorized( null, session, "internal", - ArchivaRoleConstants.OPERATION_REPOSITORY_UPLOAD ), - new UnauthorizedException( "User not authorized to read repository." ) ); - + //httpAuthControl.expectAndReturn( httpAuth.getAuthenticationResult( null, null ), result ); + EasyMock.expect( httpAuth.getAuthenticationResult( anyObject( HttpServletRequest.class ), anyObject( HttpServletResponse.class ) ) ).andReturn( result ); + //httpAuthControl.expectAndReturn( httpAuth.getSecuritySession( ic.getRequest().getSession( true ) ), session ); + EasyMock.expect( httpAuth.getSecuritySession( anyObject( HttpSession.class) ) ).andReturn( session ); + //httpAuthControl.expectAndReturn( httpAuth.getSessionUser( ic.getRequest().getSession() ), new SimpleUser() ); + EasyMock.expect( httpAuth.getSessionUser( anyObject( HttpSession.class) ) ).andReturn( new SimpleUser() ); + //servletAuthControl.expectAndReturn( servletAuth.isAuthenticated( null, result ), true ); + EasyMock.expect( servletAuth.isAuthenticated( anyObject( HttpServletRequest.class ), eq(result) ) ).andReturn( + true ); + //servletAuthControl.expectAndThrow( servletAuth.isAuthorized( null, session, "internal", ArchivaRoleConstants.OPERATION_REPOSITORY_UPLOAD ), + // new UnauthorizedException( "User not authorized to read repository." ) ); + EasyMock.expect( servletAuth.isAuthorized( anyObject( HttpServletRequest.class ), eq(session), eq("internal"), + eq(ArchivaRoleConstants.OPERATION_REPOSITORY_ACCESS) ) ).andThrow( + new UnauthorizedException( "User not authorized to read repository." ) ); httpAuthControl.replay(); servletAuthControl.replay(); diff --git a/archiva-modules/plugins/audit/src/test/java/org/apache/archiva/audit/AuditManagerTest.java b/archiva-modules/plugins/audit/src/test/java/org/apache/archiva/audit/AuditManagerTest.java index 6b5b7e9f5..0deec674c 100644 --- a/archiva-modules/plugins/audit/src/test/java/org/apache/archiva/audit/AuditManagerTest.java +++ b/archiva-modules/plugins/audit/src/test/java/org/apache/archiva/audit/AuditManagerTest.java @@ -20,9 +20,14 @@ package org.apache.archiva.audit; */ import junit.framework.TestCase; -import org.apache.archiva.metadata.repository.MetadataRepository; import org.apache.archiva.configuration.ManagedRepositoryConfiguration; -import org.easymock.MockControl; +import org.apache.archiva.metadata.repository.MetadataRepository; +import org.apache.archiva.test.utils.ArchivaBlockJUnit4ClassRunner; +import org.easymock.EasyMock; +import org.easymock.IMocksControl; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; import java.text.DecimalFormat; import java.text.ParseException; @@ -35,18 +40,14 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.TimeZone; -import org.apache.archiva.test.utils.ArchivaBlockJUnit4ClassRunner; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -@RunWith( ArchivaBlockJUnit4ClassRunner.class ) +@RunWith(ArchivaBlockJUnit4ClassRunner.class) public class AuditManagerTest extends TestCase { private DefaultAuditManager auditManager; - private MockControl metadataRepositoryControl; + private IMocksControl metadataRepositoryControl; private MetadataRepository metadataRepository; @@ -82,14 +83,14 @@ public class AuditManagerTest auditManager = new DefaultAuditManager(); - metadataRepositoryControl = MockControl.createControl( MetadataRepository.class ); - metadataRepository = (MetadataRepository) metadataRepositoryControl.getMock(); + metadataRepositoryControl = EasyMock.createControl(); + metadataRepository = metadataRepositoryControl.createMock( MetadataRepository.class ); ManagedRepositoryConfiguration repository = new ManagedRepositoryConfiguration(); repository.setId( TEST_REPO_ID ); repository.setLocation( "" ); } - + @Test public void testGetMostRecentEvents() throws Exception @@ -102,20 +103,25 @@ public class AuditManagerTest expectedEvents.add( event ); } - metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID, - AuditEvent.FACET_ID ), - getEventNames( expectedEvents ) ); + //metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID, + // AuditEvent.FACET_ID ), + // getEventNames( expectedEvents ) ); + EasyMock.expect( metadataRepository.getMetadataFacets( TEST_REPO_ID, AuditEvent.FACET_ID ) ).andReturn( + getEventNames( expectedEvents ) ); for ( AuditEvent event : expectedEvents.subList( 1, expectedEvents.size() ) ) { - metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID, - AuditEvent.FACET_ID, - event.getName() ), event ); + //metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID, + // AuditEvent.FACET_ID, + // event.getName() ), event ); + EasyMock.expect( + metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID, event.getName() ) ).andReturn( + event ); } metadataRepositoryControl.replay(); - List events = auditManager.getMostRecentAuditEvents( metadataRepository, Collections.singletonList( - TEST_REPO_ID ) ); + List events = + auditManager.getMostRecentAuditEvents( metadataRepository, Collections.singletonList( TEST_REPO_ID ) ); assertNotNull( events ); assertEquals( numEvents - 1, events.size() ); int expectedTimestampCounter = numEvents - 1; @@ -140,20 +146,24 @@ public class AuditManagerTest expectedEvents.add( createEvent( AUDIT_EVENT_BASE + MILLIS_FORMAT.format( i ) ) ); } - metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID, - AuditEvent.FACET_ID ), - getEventNames( expectedEvents ) ); - + //metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID, + // AuditEvent.FACET_ID ), + // getEventNames( expectedEvents ) ); + EasyMock.expect( metadataRepository.getMetadataFacets( TEST_REPO_ID, AuditEvent.FACET_ID ) ).andReturn( + getEventNames( expectedEvents ) ); for ( AuditEvent event : expectedEvents ) { - metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID, - AuditEvent.FACET_ID, - event.getName() ), event ); + //metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID, + // AuditEvent.FACET_ID, + // event.getName() ), event ); + EasyMock.expect( + metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID, event.getName() ) ).andReturn( + event ); } metadataRepositoryControl.replay(); - List events = auditManager.getMostRecentAuditEvents( metadataRepository, Collections.singletonList( - TEST_REPO_ID ) ); + List events = + auditManager.getMostRecentAuditEvents( metadataRepository, Collections.singletonList( TEST_REPO_ID ) ); assertNotNull( events ); assertEquals( numEvents, events.size() ); int expectedTimestampCounter = numEvents - 1; @@ -185,23 +195,29 @@ public class AuditManagerTest eventNames.get( repositoryId ).add( event.getName() ); } - metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID, - AuditEvent.FACET_ID ), - eventNames.get( TEST_REPO_ID ) ); - metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID_2, - AuditEvent.FACET_ID ), - eventNames.get( TEST_REPO_ID_2 ) ); + //metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID, + // AuditEvent.FACET_ID ), + // eventNames.get( TEST_REPO_ID ) ); + EasyMock.expect( metadataRepository.getMetadataFacets( TEST_REPO_ID, AuditEvent.FACET_ID ) ).andReturn( + eventNames.get( TEST_REPO_ID ) ); + //metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID_2, + // AuditEvent.FACET_ID ), + // eventNames.get( TEST_REPO_ID_2 ) ); + EasyMock.expect( metadataRepository.getMetadataFacets( TEST_REPO_ID_2, AuditEvent.FACET_ID ) ).andReturn( + eventNames.get( TEST_REPO_ID_2 ) ); for ( AuditEvent event : events.subList( 1, events.size() ) ) { - metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( event.getRepositoryId(), - AuditEvent.FACET_ID, - event.getName() ), event ); + //metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( event.getRepositoryId(), + // AuditEvent.FACET_ID, + // event.getName() ), event ); + EasyMock.expect( metadataRepository.getMetadataFacet( event.getRepositoryId(), AuditEvent.FACET_ID, + event.getName() ) ).andReturn( event ); } metadataRepositoryControl.replay(); - events = auditManager.getMostRecentAuditEvents( metadataRepository, Arrays.asList( TEST_REPO_ID, - TEST_REPO_ID_2 ) ); + events = + auditManager.getMostRecentAuditEvents( metadataRepository, Arrays.asList( TEST_REPO_ID, TEST_REPO_ID_2 ) ); assertNotNull( events ); assertEquals( numEvents - 1, events.size() ); int expectedTimestampCounter = numEvents - 1; @@ -221,13 +237,15 @@ public class AuditManagerTest throws Exception { - metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID, - AuditEvent.FACET_ID ), - Collections.emptyList() ); + //metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID, + // AuditEvent.FACET_ID ), + // Collections.emptyList() ); + EasyMock.expect( metadataRepository.getMetadataFacets( TEST_REPO_ID, AuditEvent.FACET_ID ) ).andReturn( + Collections.emptyList() ); metadataRepositoryControl.replay(); - assertTrue( auditManager.getMostRecentAuditEvents( metadataRepository, Collections.singletonList( - TEST_REPO_ID ) ).isEmpty() ); + assertTrue( auditManager.getMostRecentAuditEvents( metadataRepository, + Collections.singletonList( TEST_REPO_ID ) ).isEmpty() ); metadataRepositoryControl.verify(); } @@ -290,21 +308,27 @@ public class AuditManagerTest AuditEvent expectedEvent = createEvent( expectedTimestamp ); AuditEvent event3 = createEvent( new Date( current.getTime() - 1000 ) ); - metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID, - AuditEvent.FACET_ID ), - Arrays.asList( event1.getName(), expectedEvent.getName(), - event3.getName() ) ); + //metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID, + // AuditEvent.FACET_ID ), + // Arrays.asList( event1.getName(), expectedEvent.getName(), + // event3.getName() ) ); + EasyMock.expect( metadataRepository.getMetadataFacets( TEST_REPO_ID, AuditEvent.FACET_ID ) ).andReturn( + Arrays.asList( event1.getName(), expectedEvent.getName(), event3.getName() ) ); // only match the middle one - metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID, - AuditEvent.FACET_ID, - expectedEvent.getName() ), - expectedEvent ); + //metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID, + // AuditEvent.FACET_ID, + // expectedEvent.getName() ), + // expectedEvent ); + EasyMock.expect( metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID, + expectedEvent.getName() ) ).andReturn( expectedEvent ); metadataRepositoryControl.replay(); - List events = auditManager.getAuditEventsInRange( metadataRepository, Collections.singletonList( - TEST_REPO_ID ), new Date( current.getTime() - 4000 ), new Date( current.getTime() - 2000 ) ); + List events = + auditManager.getAuditEventsInRange( metadataRepository, Collections.singletonList( TEST_REPO_ID ), + new Date( current.getTime() - 4000 ), + new Date( current.getTime() - 2000 ) ); assertEquals( 1, events.size() ); assertTestEvent( events.get( 0 ), TIMESTAMP_FORMAT.format( expectedTimestamp ), expectedEvent.getResource() ); @@ -324,24 +348,30 @@ public class AuditManagerTest Date ts3 = new Date( current.getTime() - 1000 ); AuditEvent expectedEvent3 = createEvent( ts3 ); - metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID, - AuditEvent.FACET_ID ), - Arrays.asList( event1.getName(), expectedEvent2.getName(), - expectedEvent3.getName() ) ); - - metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID, - AuditEvent.FACET_ID, - expectedEvent2.getName() ), - expectedEvent2 ); - metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID, - AuditEvent.FACET_ID, - expectedEvent3.getName() ), - expectedEvent3 ); + //metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID, + // AuditEvent.FACET_ID ), + // Arrays.asList( event1.getName(), expectedEvent2.getName(), + // expectedEvent3.getName() ) ); + EasyMock.expect( metadataRepository.getMetadataFacets( TEST_REPO_ID, AuditEvent.FACET_ID ) ).andReturn( + Arrays.asList( event1.getName(), expectedEvent2.getName(), expectedEvent3.getName() ) ); + //metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID, + // AuditEvent.FACET_ID, + // expectedEvent2.getName() ), + // expectedEvent2 ); + EasyMock.expect( metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID, + expectedEvent2.getName() ) ).andReturn( expectedEvent2 ); + //metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID, + // AuditEvent.FACET_ID, + // expectedEvent3.getName() ), + // expectedEvent3 ); + EasyMock.expect( metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID, + expectedEvent3.getName() ) ).andReturn( expectedEvent3 ); metadataRepositoryControl.replay(); - List events = auditManager.getAuditEventsInRange( metadataRepository, Collections.singletonList( - TEST_REPO_ID ), new Date( current.getTime() - 4000 ), current ); + List events = + auditManager.getAuditEventsInRange( metadataRepository, Collections.singletonList( TEST_REPO_ID ), + new Date( current.getTime() - 4000 ), current ); assertEquals( 2, events.size() ); assertTestEvent( events.get( 0 ), TIMESTAMP_FORMAT.format( ts3 ), expectedEvent3.getResource() ); @@ -362,24 +392,31 @@ public class AuditManagerTest AuditEvent expectedEvent2 = createEvent( expectedTimestamp ); AuditEvent event3 = createEvent( new Date( current.getTime() - 1000 ) ); - metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID, - AuditEvent.FACET_ID ), - Arrays.asList( expectedEvent1.getName(), expectedEvent2.getName(), - event3.getName() ) ); - - metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID, - AuditEvent.FACET_ID, - expectedEvent1.getName() ), - expectedEvent1 ); - metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID, - AuditEvent.FACET_ID, - expectedEvent2.getName() ), - expectedEvent2 ); + //metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID, + // AuditEvent.FACET_ID ), + // Arrays.asList( expectedEvent1.getName(), expectedEvent2.getName(), + // event3.getName() ) ); + EasyMock.expect( metadataRepository.getMetadataFacets( TEST_REPO_ID, AuditEvent.FACET_ID ) ).andReturn( + Arrays.asList( expectedEvent1.getName(), expectedEvent2.getName(), event3.getName() ) ); + //metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID, + // AuditEvent.FACET_ID, + // expectedEvent1.getName() ), + // expectedEvent1 ); + EasyMock.expect( metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID, + expectedEvent1.getName() ) ).andReturn( expectedEvent1 ); + //metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID, + // AuditEvent.FACET_ID, + // expectedEvent2.getName() ), + // expectedEvent2 ); + EasyMock.expect( metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID, + expectedEvent2.getName() ) ).andReturn( expectedEvent2 ); metadataRepositoryControl.replay(); - List events = auditManager.getAuditEventsInRange( metadataRepository, Collections.singletonList( - TEST_REPO_ID ), new Date( current.getTime() - 20000 ), new Date( current.getTime() - 2000 ) ); + List events = + auditManager.getAuditEventsInRange( metadataRepository, Collections.singletonList( TEST_REPO_ID ), + new Date( current.getTime() - 20000 ), + new Date( current.getTime() - 2000 ) ); assertEquals( 2, events.size() ); assertTestEvent( events.get( 0 ), TIMESTAMP_FORMAT.format( expectedTimestamp ), expectedEvent2.getResource() ); @@ -401,28 +438,35 @@ public class AuditManagerTest Date ts3 = new Date( current.getTime() - 1000 ); AuditEvent expectedEvent3 = createEvent( ts3 ); - metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID, - AuditEvent.FACET_ID ), - Arrays.asList( expectedEvent1.getName(), expectedEvent2.getName(), - expectedEvent3.getName() ) ); - - metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID, - AuditEvent.FACET_ID, - expectedEvent1.getName() ), - expectedEvent1 ); - metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID, - AuditEvent.FACET_ID, - expectedEvent2.getName() ), - expectedEvent2 ); - metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID, - AuditEvent.FACET_ID, - expectedEvent3.getName() ), - expectedEvent3 ); - + //metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID, + // AuditEvent.FACET_ID ), + // Arrays.asList( expectedEvent1.getName(), expectedEvent2.getName(), + // expectedEvent3.getName() ) ); + EasyMock.expect( metadataRepository.getMetadataFacets( TEST_REPO_ID, AuditEvent.FACET_ID ) ).andReturn( + Arrays.asList( expectedEvent1.getName(), expectedEvent2.getName(), expectedEvent3.getName() ) ); + //metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID, + // AuditEvent.FACET_ID, + // expectedEvent1.getName() ), + // expectedEvent1 ); + EasyMock.expect( metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID, + expectedEvent1.getName() ) ).andReturn( expectedEvent1 ); + //metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID, + // AuditEvent.FACET_ID, + // expectedEvent2.getName() ), + // expectedEvent2 ); + EasyMock.expect( metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID, + expectedEvent2.getName() ) ).andReturn( expectedEvent2 ); + //metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID, + // AuditEvent.FACET_ID, + // expectedEvent3.getName() ), + // expectedEvent3 ); + EasyMock.expect( metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID, + expectedEvent3.getName() ) ).andReturn( expectedEvent3 ); metadataRepositoryControl.replay(); - List events = auditManager.getAuditEventsInRange( metadataRepository, Collections.singletonList( - TEST_REPO_ID ), new Date( current.getTime() - 20000 ), current ); + List events = + auditManager.getAuditEventsInRange( metadataRepository, Collections.singletonList( TEST_REPO_ID ), + new Date( current.getTime() - 20000 ), current ); assertEquals( 3, events.size() ); assertTestEvent( events.get( 0 ), TIMESTAMP_FORMAT.format( ts3 ), expectedEvent3.getResource() ); @@ -446,28 +490,36 @@ public class AuditManagerTest Date ts3 = new Date( current.getTime() - 1000 ); AuditEvent expectedEvent3 = createEvent( ts3 ); - metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID, - AuditEvent.FACET_ID ), - Arrays.asList( expectedEvent1.getName(), expectedEvent2.getName(), - expectedEvent3.getName() ) ); - - metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID, - AuditEvent.FACET_ID, - expectedEvent1.getName() ), - expectedEvent1 ); - metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID, - AuditEvent.FACET_ID, - expectedEvent2.getName() ), - expectedEvent2 ); - metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID, - AuditEvent.FACET_ID, - expectedEvent3.getName() ), - expectedEvent3 ); + //metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID, + // AuditEvent.FACET_ID ), + // Arrays.asList( expectedEvent1.getName(), expectedEvent2.getName(), + // expectedEvent3.getName() ) ); + EasyMock.expect( metadataRepository.getMetadataFacets( TEST_REPO_ID, AuditEvent.FACET_ID ) ).andReturn( + Arrays.asList( expectedEvent1.getName(), expectedEvent2.getName(), expectedEvent3.getName() ) ); + //metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID, + // AuditEvent.FACET_ID, + // expectedEvent1.getName() ), + // expectedEvent1 ); + EasyMock.expect( metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID, + expectedEvent1.getName() ) ).andReturn( expectedEvent1 ); + //metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID, + // AuditEvent.FACET_ID, + // expectedEvent2.getName() ), + // expectedEvent2 ); + EasyMock.expect( metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID, + expectedEvent2.getName() ) ).andReturn( expectedEvent2 ); + //metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID, + // AuditEvent.FACET_ID, + // expectedEvent3.getName() ), + // expectedEvent3 ); + EasyMock.expect( metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID, + expectedEvent3.getName() ) ).andReturn( expectedEvent3 ); metadataRepositoryControl.replay(); - List events = auditManager.getAuditEventsInRange( metadataRepository, Collections.singletonList( - TEST_REPO_ID ), TEST_RESOURCE_BASE, new Date( current.getTime() - 20000 ), current ); + List events = + auditManager.getAuditEventsInRange( metadataRepository, Collections.singletonList( TEST_REPO_ID ), + TEST_RESOURCE_BASE, new Date( current.getTime() - 20000 ), current ); assertEquals( 2, events.size() ); assertTestEvent( events.get( 0 ), TIMESTAMP_FORMAT.format( ts3 ), expectedEvent3.getResource() ); @@ -488,28 +540,31 @@ public class AuditManagerTest expectedEvent2.setResource( "different-resource" ); AuditEvent expectedEvent3 = createEvent( new Date( current.getTime() - 1000 ) ); - metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID, - AuditEvent.FACET_ID ), - Arrays.asList( expectedEvent1.getName(), expectedEvent2.getName(), - expectedEvent3.getName() ) ); + //metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID, + // AuditEvent.FACET_ID ), + // Arrays.asList( expectedEvent1.getName(), expectedEvent2.getName(), + // expectedEvent3.getName() ) ); + EasyMock.expect( metadataRepository.getMetadataFacets( TEST_REPO_ID, AuditEvent.FACET_ID ) ).andReturn( + Arrays.asList( expectedEvent1.getName(), expectedEvent2.getName(), expectedEvent3.getName() ) ); - metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID, - AuditEvent.FACET_ID, - expectedEvent1.getName() ), - expectedEvent1 ); - metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID, - AuditEvent.FACET_ID, - expectedEvent2.getName() ), - expectedEvent2 ); - metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID, - AuditEvent.FACET_ID, - expectedEvent3.getName() ), - expectedEvent3 ); + //metadataRepositoryControl.expectAndReturn( + // metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID, expectedEvent1.getName() ), + // expectedEvent1 ); + EasyMock.expect( metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID, expectedEvent1.getName() ) ).andReturn( expectedEvent1 ); + //metadataRepositoryControl.expectAndReturn( + // metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID, expectedEvent2.getName() ), + // expectedEvent2 ); + EasyMock.expect( metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID, expectedEvent2.getName() ) ).andReturn( expectedEvent2 ); + //metadataRepositoryControl.expectAndReturn( + // metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID, expectedEvent3.getName() ), + // expectedEvent3 ); + EasyMock.expect( metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID, expectedEvent3.getName() ) ).andReturn( expectedEvent3 ); metadataRepositoryControl.replay(); - List events = auditManager.getAuditEventsInRange( metadataRepository, Collections.singletonList( - TEST_REPO_ID ), "foo", new Date( current.getTime() - 20000 ), current ); + List events = + auditManager.getAuditEventsInRange( metadataRepository, Collections.singletonList( TEST_REPO_ID ), "foo", + new Date( current.getTime() - 20000 ), current ); assertEquals( 0, events.size() ); @@ -530,32 +585,38 @@ public class AuditManagerTest Date ts3 = new Date( current.getTime() - 1000 ); AuditEvent expectedEvent3 = createEvent( ts3 ); - metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID, - AuditEvent.FACET_ID ), - Arrays.asList( expectedEvent1.getName(), - expectedEvent3.getName() ) ); - metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID_2, - AuditEvent.FACET_ID ), - Arrays.asList( expectedEvent2.getName() ) ); + //metadataRepositoryControl.expectAndReturn( + // metadataRepository.getMetadataFacets( TEST_REPO_ID, AuditEvent.FACET_ID ), + // Arrays.asList( expectedEvent1.getName(), expectedEvent3.getName() ) ); + EasyMock.expect( metadataRepository.getMetadataFacets( TEST_REPO_ID, AuditEvent.FACET_ID ) ) + .andReturn( Arrays.asList( expectedEvent1.getName(), expectedEvent3.getName() ) ); + //metadataRepositoryControl.expectAndReturn( + // metadataRepository.getMetadataFacets( TEST_REPO_ID_2, AuditEvent.FACET_ID ), + // Arrays.asList( expectedEvent2.getName() ) ); + EasyMock.expect( metadataRepository.getMetadataFacets( TEST_REPO_ID_2, AuditEvent.FACET_ID ) ) + .andReturn( Arrays.asList( expectedEvent2.getName() ) ); - metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID, - AuditEvent.FACET_ID, - expectedEvent1.getName() ), - expectedEvent1 ); - metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID_2, - AuditEvent.FACET_ID, - expectedEvent2.getName() ), - expectedEvent2 ); - metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID, - AuditEvent.FACET_ID, - expectedEvent3.getName() ), - expectedEvent3 ); + //metadataRepositoryControl.expectAndReturn( + // metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID, expectedEvent1.getName() ), + // expectedEvent1 ); + EasyMock.expect( metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID, expectedEvent1.getName() ) ) + .andReturn( expectedEvent1 ); + //metadataRepositoryControl.expectAndReturn( + // metadataRepository.getMetadataFacet( TEST_REPO_ID_2, AuditEvent.FACET_ID, expectedEvent2.getName() ), + // expectedEvent2 ); + EasyMock.expect( metadataRepository.getMetadataFacet( TEST_REPO_ID_2, AuditEvent.FACET_ID, expectedEvent2.getName() ) ) + .andReturn( expectedEvent2 ); + //metadataRepositoryControl.expectAndReturn( + // metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID, expectedEvent3.getName() ), + // expectedEvent3 ); + EasyMock.expect( metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID, expectedEvent3.getName() ) ) + .andReturn( expectedEvent3 ); metadataRepositoryControl.replay(); - List events = auditManager.getAuditEventsInRange( metadataRepository, Arrays.asList( TEST_REPO_ID, - TEST_REPO_ID_2 ), - new Date( current.getTime() - 20000 ), current ); + List events = + auditManager.getAuditEventsInRange( metadataRepository, Arrays.asList( TEST_REPO_ID, TEST_REPO_ID_2 ), + new Date( current.getTime() - 20000 ), current ); assertEquals( 3, events.size() ); assertTestEvent( events.get( 0 ), TEST_REPO_ID, TIMESTAMP_FORMAT.format( ts3 ), expectedEvent3.getResource() ); @@ -577,14 +638,18 @@ public class AuditManagerTest String name2 = createEvent( expectedTimestamp ).getName(); String name3 = createEvent( new Date( current.getTime() - 1000 ) ).getName(); - metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID, - AuditEvent.FACET_ID ), - Arrays.asList( name1, name2, name3 ) ); + //metadataRepositoryControl.expectAndReturn( + // metadataRepository.getMetadataFacets( TEST_REPO_ID, AuditEvent.FACET_ID ), + // Arrays.asList( name1, name2, name3 ) ); + EasyMock.expect( metadataRepository.getMetadataFacets( TEST_REPO_ID, AuditEvent.FACET_ID ) ) + .andReturn( Arrays.asList( name1, name2, name3 ) ); metadataRepositoryControl.replay(); - List events = auditManager.getAuditEventsInRange( metadataRepository, Collections.singletonList( - TEST_REPO_ID ), new Date( current.getTime() - 20000 ), new Date( current.getTime() - 16000 ) ); + List events = + auditManager.getAuditEventsInRange( metadataRepository, Collections.singletonList( TEST_REPO_ID ), + new Date( current.getTime() - 20000 ), + new Date( current.getTime() - 16000 ) ); assertEquals( 0, events.size() ); @@ -605,9 +670,8 @@ public class AuditManagerTest private static AuditEvent createEvent( String ts ) throws ParseException { - return createEvent( TEST_REPO_ID, ts, getDefaultTestResourceName( ts.substring( AUDIT_EVENT_BASE.length(), - AUDIT_EVENT_BASE.length() + - 3 ) ) ); + return createEvent( TEST_REPO_ID, ts, getDefaultTestResourceName( + ts.substring( AUDIT_EVENT_BASE.length(), AUDIT_EVENT_BASE.length() + 3 ) ) ); } private static AuditEvent createEvent( String repositoryId, String timestamp, String resource ) diff --git a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/conf/MockConfiguration.java b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/conf/MockConfiguration.java index db6285207..c953e9512 100755 --- a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/conf/MockConfiguration.java +++ b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/conf/MockConfiguration.java @@ -25,12 +25,14 @@ import org.apache.archiva.configuration.ConfigurationListener; 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.IMocksControl; import org.springframework.stereotype.Service; import java.util.HashSet; import java.util.Set; +import static org.easymock.EasyMock.createNiceControl; + /** * MockConfiguration * @@ -46,14 +48,14 @@ public class MockConfiguration private Set registryListeners = new HashSet(); private Set configListeners = new HashSet(); - private MockControl registryControl; + private IMocksControl registryControl; private Registry registryMock; public MockConfiguration() { - registryControl = MockControl.createNiceControl( Registry.class ); - registryMock = (Registry) registryControl.getMock(); + registryControl = createNiceControl(); + registryMock = registryControl.createMock( Registry.class ); } public void addChangeListener( RegistryListener listener ) diff --git a/archiva-modules/plugins/repository-statistics/src/test/java/org/apache/archiva/metadata/repository/stats/RepositoryStatisticsManagerTest.java b/archiva-modules/plugins/repository-statistics/src/test/java/org/apache/archiva/metadata/repository/stats/RepositoryStatisticsManagerTest.java index 8c39e402b..61ced3a38 100644 --- a/archiva-modules/plugins/repository-statistics/src/test/java/org/apache/archiva/metadata/repository/stats/RepositoryStatisticsManagerTest.java +++ b/archiva-modules/plugins/repository-statistics/src/test/java/org/apache/archiva/metadata/repository/stats/RepositoryStatisticsManagerTest.java @@ -23,8 +23,16 @@ import junit.framework.TestCase; import org.apache.archiva.metadata.model.ArtifactMetadata; import org.apache.archiva.metadata.model.maven2.MavenArtifactFacet; import org.apache.archiva.metadata.repository.MetadataRepository; -import org.easymock.MockControl; +import org.apache.archiva.test.utils.ArchivaBlockJUnit4ClassRunner; +import org.easymock.IMocksControl; +import static org.easymock.EasyMock.*; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + +import javax.jcr.Session; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; @@ -34,11 +42,6 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.TimeZone; -import javax.jcr.Session; -import org.apache.archiva.test.utils.ArchivaBlockJUnit4ClassRunner; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; @RunWith( ArchivaBlockJUnit4ClassRunner.class ) public class RepositoryStatisticsManagerTest @@ -48,7 +51,7 @@ public class RepositoryStatisticsManagerTest private static final String TEST_REPO_ID = "test-repo"; - private MockControl metadataRepositoryControl; + private IMocksControl metadataRepositoryControl; private MetadataRepository metadataRepository; @@ -76,8 +79,8 @@ public class RepositoryStatisticsManagerTest repositoryStatisticsManager = new DefaultRepositoryStatisticsManager(); - metadataRepositoryControl = MockControl.createControl( MetadataRepository.class ); - metadataRepository = (MetadataRepository) metadataRepositoryControl.getMock(); + metadataRepositoryControl = createControl(); + metadataRepository = metadataRepositoryControl.createMock( MetadataRepository.class ); } @Test @@ -97,12 +100,17 @@ public class RepositoryStatisticsManagerTest stats.setTotalGroupCount( 529 ); stats.setTotalFileCount( 56229 ); - metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID, - RepositoryStatistics.FACET_ID ), - Arrays.asList( FIRST_TEST_SCAN, SECOND_TEST_SCAN ) ); - metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID, - RepositoryStatistics.FACET_ID, - SECOND_TEST_SCAN ), stats ); + //metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID, + // RepositoryStatistics.FACET_ID ), + // Arrays.asList( FIRST_TEST_SCAN, SECOND_TEST_SCAN ) ); + expect( metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ) ).andReturn( + Arrays.asList( FIRST_TEST_SCAN, SECOND_TEST_SCAN ) ); + //metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID, + // RepositoryStatistics.FACET_ID, + // SECOND_TEST_SCAN ), stats ); + expect( metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, + SECOND_TEST_SCAN ) ).andReturn( stats ); + metadataRepositoryControl.replay(); stats = repositoryStatisticsManager.getLastStatistics( metadataRepository, TEST_REPO_ID ); @@ -124,9 +132,11 @@ public class RepositoryStatisticsManagerTest public void testGetLatestStatsWhenEmpty() throws Exception { - metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID, - RepositoryStatistics.FACET_ID ), - Collections.emptyList() ); + //metadataRepositoryControl.expectAndReturn( + // metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ), + // Collections.emptyList() ); + expect( metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ) ).andReturn( + Collections.emptyList() ); metadataRepositoryControl.replay(); RepositoryStatistics stats = repositoryStatisticsManager.getLastStatistics( metadataRepository, TEST_REPO_ID ); @@ -147,13 +157,18 @@ public class RepositoryStatisticsManagerTest walkRepository( 1 ); metadataRepository.addMetadataFacet( TEST_REPO_ID, stats ); - metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID, - RepositoryStatistics.FACET_ID ), - Arrays.asList( stats.getName() ) ); - metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID, - RepositoryStatistics.FACET_ID, - stats.getName() ), stats ); - metadataRepositoryControl.expectAndReturn( metadataRepository.canObtainAccess( Session.class ), false ); + //metadataRepositoryControl.expectAndReturn( + // metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ), + // Arrays.asList( stats.getName() ) ); + expect( metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ) ).andReturn( + Arrays.asList( stats.getName() ) ); + //metadataRepositoryControl.expectAndReturn( + // metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, stats.getName() ), + // stats ); + expect( metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, + stats.getName() ) ).andReturn( stats ); + //metadataRepositoryControl.expectAndReturn( metadataRepository.canObtainAccess( Session.class ), false ); + expect( metadataRepository.canObtainAccess( Session.class ) ).andReturn( false ); metadataRepositoryControl.replay(); @@ -190,20 +205,25 @@ public class RepositoryStatisticsManagerTest RepositoryStatistics stats2 = createTestStats( startTime2, current ); metadataRepository.addMetadataFacet( TEST_REPO_ID, stats2 ); - metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID, - RepositoryStatistics.FACET_ID ), - Arrays.asList( stats1.getName(), stats2.getName() ) ); - metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID, - RepositoryStatistics.FACET_ID, - stats2.getName() ), stats2 ); - + //metadataRepositoryControl.expectAndReturn( + // metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ), + // Arrays.asList( stats1.getName(), stats2.getName() ) ); + expect( metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ) ).andReturn( + Arrays.asList( stats1.getName(), stats2.getName() ) ); + //metadataRepositoryControl.expectAndReturn( + // metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, stats2.getName() ), + // stats2 ); + expect( metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, + stats2.getName() ) ).andReturn( stats2 ); metadataRepository.removeMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ); - metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID, - RepositoryStatistics.FACET_ID ), - Collections.emptyList() ); - metadataRepositoryControl.expectAndReturn( metadataRepository.canObtainAccess( Session.class ), false, 2 ); - + //metadataRepositoryControl.expectAndReturn( + // metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ), + // Collections.emptyList() ); + expect( metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ) ).andReturn( + Collections.emptyList() ); + //metadataRepositoryControl.expectAndReturn( metadataRepository.canObtainAccess( Session.class ), false, 2 ); + expect( metadataRepository.canObtainAccess( Session.class ) ).andReturn( false ).times( 2 ); metadataRepositoryControl.replay(); repositoryStatisticsManager.addStatisticsAfterScan( metadataRepository, TEST_REPO_ID, startTime1, @@ -224,9 +244,11 @@ public class RepositoryStatisticsManagerTest public void testDeleteStatsWhenEmpty() throws Exception { - metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID, - RepositoryStatistics.FACET_ID ), - Collections.emptyList(), 2 ); + //metadataRepositoryControl.expectAndReturn( + // metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ), + // Collections.emptyList(), 2 ); + expect( metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ) ).andReturn( + Collections.emptyList() ).times( 2 ); metadataRepository.removeMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ); metadataRepositoryControl.replay(); @@ -253,17 +275,20 @@ public class RepositoryStatisticsManagerTest addStats( new Date( current.getTime() - 1000 ), current ); ArrayList keys = new ArrayList( statsCreated.keySet() ); - metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID, - RepositoryStatistics.FACET_ID ), - keys ); + //metadataRepositoryControl.expectAndReturn( + // metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ), keys ); + expect( metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ) ).andReturn( keys ); // only match the middle one String key = keys.get( 1 ); - metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID, - RepositoryStatistics.FACET_ID, - key ), statsCreated.get( - key ) ); - metadataRepositoryControl.expectAndReturn( metadataRepository.canObtainAccess( Session.class ), false, 3 ); + //metadataRepositoryControl.expectAndReturn( + // metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, key ), + // statsCreated.get( key ) ); + expect( metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, key ) ).andReturn( + statsCreated.get( key ) ); + + //metadataRepositoryControl.expectAndReturn( metadataRepository.canObtainAccess( Session.class ), false, 3 ); + expect( metadataRepository.canObtainAccess( Session.class ) ).andReturn( false ).times( 3 ); metadataRepositoryControl.replay(); @@ -274,9 +299,10 @@ public class RepositoryStatisticsManagerTest 45 ); } - List list = repositoryStatisticsManager.getStatisticsInRange( metadataRepository, - TEST_REPO_ID, new Date( - current.getTime() - 4000 ), new Date( current.getTime() - 2000 ) ); + List list = + repositoryStatisticsManager.getStatisticsInRange( metadataRepository, TEST_REPO_ID, + new Date( current.getTime() - 4000 ), + new Date( current.getTime() - 2000 ) ); assertEquals( 1, list.size() ); assertEquals( new Date( current.getTime() - 3000 ), list.get( 0 ).getScanStartTime() ); @@ -296,22 +322,27 @@ public class RepositoryStatisticsManagerTest addStats( new Date( current.getTime() - 3000 ), new Date( current.getTime() - 2000 ) ); addStats( new Date( current.getTime() - 1000 ), current ); - ArrayList keys = new ArrayList( statsCreated.keySet() ); - metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID, - RepositoryStatistics.FACET_ID ), - keys ); + List keys = new ArrayList( statsCreated.keySet() ); + //metadataRepositoryControl.expectAndReturn( + // metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ), keys ); + expect( metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ) ).andReturn( keys ); String key = keys.get( 1 ); - metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID, - RepositoryStatistics.FACET_ID, - key ), statsCreated.get( - key ) ); + //metadataRepositoryControl.expectAndReturn( + // metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, key ), + // statsCreated.get( key ) ); + expect( metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, key ) ).andReturn( + statsCreated.get( key ) ); + key = keys.get( 2 ); - metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID, - RepositoryStatistics.FACET_ID, - key ), statsCreated.get( - key ) ); - metadataRepositoryControl.expectAndReturn( metadataRepository.canObtainAccess( Session.class ), false, 3 ); + //metadataRepositoryControl.expectAndReturn( + // metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, key ), + // statsCreated.get( key ) ); + expect( metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, key ) ).andReturn( + statsCreated.get( key ) ); + + //metadataRepositoryControl.expectAndReturn( metadataRepository.canObtainAccess( Session.class ), false, 3 ); + expect( metadataRepository.canObtainAccess( Session.class ) ).andReturn( false ).times( 3 ); metadataRepositoryControl.replay(); @@ -322,9 +353,9 @@ public class RepositoryStatisticsManagerTest 45 ); } - List list = repositoryStatisticsManager.getStatisticsInRange( metadataRepository, - TEST_REPO_ID, new Date( - current.getTime() - 4000 ), current ); + List list = + repositoryStatisticsManager.getStatisticsInRange( metadataRepository, TEST_REPO_ID, + new Date( current.getTime() - 4000 ), current ); assertEquals( 2, list.size() ); assertEquals( new Date( current.getTime() - 3000 ), list.get( 1 ).getScanStartTime() ); @@ -345,22 +376,25 @@ public class RepositoryStatisticsManagerTest addStats( new Date( current.getTime() - 3000 ), new Date( current.getTime() - 2000 ) ); addStats( new Date( current.getTime() - 1000 ), current ); - ArrayList keys = new ArrayList( statsCreated.keySet() ); - metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID, - RepositoryStatistics.FACET_ID ), - keys ); + List keys = new ArrayList( statsCreated.keySet() ); + //metadataRepositoryControl.expectAndReturn( + // metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ), keys ); + expect( metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ) ).andReturn( keys ); String key = keys.get( 0 ); - metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID, - RepositoryStatistics.FACET_ID, - key ), statsCreated.get( - key ) ); + //metadataRepositoryControl.expectAndReturn( + // metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, key ), + // statsCreated.get( key ) ); + expect( metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, key ) ).andReturn( + statsCreated.get( key ) ); key = keys.get( 1 ); - metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID, - RepositoryStatistics.FACET_ID, - key ), statsCreated.get( - key ) ); - metadataRepositoryControl.expectAndReturn( metadataRepository.canObtainAccess( Session.class ), false, 3 ); + //metadataRepositoryControl.expectAndReturn( + // metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, key ), + // statsCreated.get( key ) ); + expect( metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, key ) ).andReturn( + statsCreated.get( key ) ); + //metadataRepositoryControl.expectAndReturn( metadataRepository.canObtainAccess( Session.class ), false, 3 ); + expect( metadataRepository.canObtainAccess( Session.class ) ).andReturn( false ).times( 3 ); metadataRepositoryControl.replay(); @@ -371,9 +405,10 @@ public class RepositoryStatisticsManagerTest 45 ); } - List list = repositoryStatisticsManager.getStatisticsInRange( metadataRepository, - TEST_REPO_ID, new Date( - current.getTime() - 20000 ), new Date( current.getTime() - 2000 ) ); + List list = + repositoryStatisticsManager.getStatisticsInRange( metadataRepository, TEST_REPO_ID, + new Date( current.getTime() - 20000 ), + new Date( current.getTime() - 2000 ) ); assertEquals( 2, list.size() ); assertEquals( new Date( current.getTime() - 12345 ), list.get( 1 ).getScanStartTime() ); @@ -395,26 +430,30 @@ public class RepositoryStatisticsManagerTest addStats( new Date( current.getTime() - 1000 ), current ); ArrayList keys = new ArrayList( statsCreated.keySet() ); - metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID, - RepositoryStatistics.FACET_ID ), - keys ); + //metadataRepositoryControl.expectAndReturn( + // metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ), keys ); + expect( metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ) ).andReturn( keys ); String key = keys.get( 0 ); - metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID, - RepositoryStatistics.FACET_ID, - key ), statsCreated.get( - key ) ); + //metadataRepositoryControl.expectAndReturn( + // metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, key ), + // statsCreated.get( key ) ); + expect( metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, key ) ).andReturn( + statsCreated.get( key ) ); key = keys.get( 1 ); - metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID, - RepositoryStatistics.FACET_ID, - key ), statsCreated.get( - key ) ); + //metadataRepositoryControl.expectAndReturn( + // metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, key ), + // statsCreated.get( key ) ); + expect( metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, key ) ).andReturn( + statsCreated.get( key ) ); key = keys.get( 2 ); - metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID, - RepositoryStatistics.FACET_ID, - key ), statsCreated.get( - key ) ); - metadataRepositoryControl.expectAndReturn( metadataRepository.canObtainAccess( Session.class ), false, 3 ); + //metadataRepositoryControl.expectAndReturn( + // metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, key ), + // statsCreated.get( key ) ); + expect( metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, key ) ).andReturn( + statsCreated.get( key ) ); + //metadataRepositoryControl.expectAndReturn( metadataRepository.canObtainAccess( Session.class ), false, 3 ); + expect( metadataRepository.canObtainAccess( Session.class ) ).andReturn( false ).times( 3 ); metadataRepositoryControl.replay(); @@ -425,9 +464,9 @@ public class RepositoryStatisticsManagerTest 45 ); } - List list = repositoryStatisticsManager.getStatisticsInRange( metadataRepository, - TEST_REPO_ID, new Date( - current.getTime() - 20000 ), current ); + List list = + repositoryStatisticsManager.getStatisticsInRange( metadataRepository, TEST_REPO_ID, + new Date( current.getTime() - 20000 ), current ); assertEquals( 3, list.size() ); assertEquals( new Date( current.getTime() - 12345 ), list.get( 2 ).getScanStartTime() ); @@ -450,10 +489,11 @@ public class RepositoryStatisticsManagerTest addStats( new Date( current.getTime() - 1000 ), current ); ArrayList keys = new ArrayList( statsCreated.keySet() ); - metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID, - RepositoryStatistics.FACET_ID ), - keys ); - metadataRepositoryControl.expectAndReturn( metadataRepository.canObtainAccess( Session.class ), false, 3 ); + //metadataRepositoryControl.expectAndReturn( + // metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ), keys ); + expect( metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ) ).andReturn( keys ); + //metadataRepositoryControl.expectAndReturn( metadataRepository.canObtainAccess( Session.class ), false, 3 ); + expect( metadataRepository.canObtainAccess( Session.class ) ).andReturn( false ).times( 3 ); metadataRepositoryControl.replay(); @@ -464,9 +504,10 @@ public class RepositoryStatisticsManagerTest 45 ); } - List list = repositoryStatisticsManager.getStatisticsInRange( metadataRepository, - TEST_REPO_ID, new Date( - current.getTime() - 20000 ), new Date( current.getTime() - 16000 ) ); + List list = + repositoryStatisticsManager.getStatisticsInRange( metadataRepository, TEST_REPO_ID, + new Date( current.getTime() - 20000 ), + new Date( current.getTime() - 16000 ) ); assertEquals( 0, list.size() ); @@ -521,134 +562,167 @@ public class RepositoryStatisticsManagerTest { for ( int i = 0; i < count; i++ ) { - metadataRepositoryControl.expectAndReturn( metadataRepository.getRootNamespaces( TEST_REPO_ID ), - Arrays.asList( "com", "org" ) ); - metadataRepositoryControl.expectAndReturn( metadataRepository.getProjects( TEST_REPO_ID, "com" ), - Arrays.asList() ); - metadataRepositoryControl.expectAndReturn( metadataRepository.getNamespaces( TEST_REPO_ID, "com" ), - Arrays.asList( "example" ) ); - metadataRepositoryControl.expectAndReturn( metadataRepository.getNamespaces( TEST_REPO_ID, "com.example" ), - Arrays.asList() ); - metadataRepositoryControl.expectAndReturn( metadataRepository.getProjects( TEST_REPO_ID, "com.example" ), - Arrays.asList( "example-project" ) ); - metadataRepositoryControl.expectAndReturn( metadataRepository.getProjectVersions( TEST_REPO_ID, - "com.example", - "example-project" ), - Arrays.asList( "1.0", "1.1" ) ); - metadataRepositoryControl.expectAndReturn( metadataRepository.getArtifacts( TEST_REPO_ID, "com.example", - "example-project", "1.0" ), - Arrays.asList( createArtifact( "com.example", "example-project", - "1.0", "jar" ), createArtifact( - "com.example", "example-project", "1.0", "pom" ) ) ); - metadataRepositoryControl.expectAndReturn( metadataRepository.getArtifacts( TEST_REPO_ID, "com.example", - "example-project", "1.1" ), - Arrays.asList( createArtifact( "com.example", "example-project", - "1.1", "jar" ), createArtifact( - "com.example", "example-project", "1.1", "pom" ) ) ); - metadataRepositoryControl.expectAndReturn( metadataRepository.getNamespaces( TEST_REPO_ID, "org" ), - Arrays.asList( "apache", "codehaus" ) ); - metadataRepositoryControl.expectAndReturn( metadataRepository.getNamespaces( TEST_REPO_ID, "org.apache" ), - Arrays.asList( "archiva", "maven" ) ); - metadataRepositoryControl.expectAndReturn( metadataRepository.getProjects( TEST_REPO_ID, "org.apache" ), - Arrays.asList() ); - metadataRepositoryControl.expectAndReturn( metadataRepository.getNamespaces( TEST_REPO_ID, - "org.apache.archiva" ), - Arrays.asList() ); - metadataRepositoryControl.expectAndReturn( metadataRepository.getProjects( TEST_REPO_ID, - "org.apache.archiva" ), - Arrays.asList( "metadata-repository-api", "metadata-model" ) ); - metadataRepositoryControl.expectAndReturn( metadataRepository.getProjectVersions( TEST_REPO_ID, - "org.apache.archiva", - "metadata-repository-api" ), - Arrays.asList( "1.3-SNAPSHOT", "1.3" ) ); - metadataRepositoryControl.expectAndReturn( metadataRepository.getArtifacts( TEST_REPO_ID, - "org.apache.archiva", - "metadata-repository-api", - "1.3-SNAPSHOT" ), Arrays.asList( - createArtifact( "org.apache.archiva", "metadata-repository-api", "1.3-SNAPSHOT", "jar" ), - createArtifact( "org.apache.archiva", "metadata-repository-api", "1.3-SNAPSHOT", "pom" ) ) ); - metadataRepositoryControl.expectAndReturn( metadataRepository.getArtifacts( TEST_REPO_ID, - "org.apache.archiva", - "metadata-repository-api", - "1.3" ), Arrays.asList( - createArtifact( "org.apache.archiva", "metadata-repository-api", "1.3", "jar" ), createArtifact( - "org.apache.archiva", "metadata-repository-api", "1.3", "pom" ) ) ); - metadataRepositoryControl.expectAndReturn( metadataRepository.getProjectVersions( TEST_REPO_ID, - "org.apache.archiva", - "metadata-model" ), - Arrays.asList( "1.3-SNAPSHOT", "1.3" ) ); - metadataRepositoryControl.expectAndReturn( metadataRepository.getArtifacts( TEST_REPO_ID, - "org.apache.archiva", - "metadata-model", - "1.3-SNAPSHOT" ), Arrays.asList( - createArtifact( "org.apache.archiva", "metadata-model", "1.3-SNAPSHOT", "jar" ), createArtifact( - "org.apache.archiva", "metadata-model", "1.3-SNAPSHOT", "pom" ) ) ); - metadataRepositoryControl.expectAndReturn( metadataRepository.getArtifacts( TEST_REPO_ID, - "org.apache.archiva", - "metadata-model", "1.3" ), - Arrays.asList( createArtifact( "org.apache.archiva", - "metadata-model", "1.3", "jar" ), - createArtifact( "org.apache.archiva", - "metadata-model", "1.3", - "pom" ) ) ); - metadataRepositoryControl.expectAndReturn( metadataRepository.getNamespaces( TEST_REPO_ID, - "org.apache.maven" ), - Arrays.asList() ); - metadataRepositoryControl.expectAndReturn( metadataRepository.getProjects( TEST_REPO_ID, - "org.apache.maven" ), - Arrays.asList( "maven-model" ) ); - metadataRepositoryControl.expectAndReturn( metadataRepository.getProjectVersions( TEST_REPO_ID, - "org.apache.maven", - "maven-model" ), - Arrays.asList( "2.2.1" ) ); - metadataRepositoryControl.expectAndReturn( metadataRepository.getArtifacts( TEST_REPO_ID, - "org.apache.maven", - "maven-model", "2.2.1" ), - Arrays.asList( createArtifact( "org.apache.archiva", - "maven-model", "2.2.1", "jar" ), - createArtifact( "org.apache.archiva", - "maven-model", "2.2.1", - "pom" ) ) ); - metadataRepositoryControl.expectAndReturn( metadataRepository.getNamespaces( TEST_REPO_ID, "org.codehaus" ), - Arrays.asList( "plexus" ) ); - metadataRepositoryControl.expectAndReturn( metadataRepository.getProjects( TEST_REPO_ID, "org" ), - Arrays.asList() ); - metadataRepositoryControl.expectAndReturn( metadataRepository.getProjects( TEST_REPO_ID, "org.codehaus" ), - Arrays.asList() ); - metadataRepositoryControl.expectAndReturn( metadataRepository.getNamespaces( TEST_REPO_ID, - "org.codehaus.plexus" ), - Arrays.asList() ); - metadataRepositoryControl.expectAndReturn( metadataRepository.getProjects( TEST_REPO_ID, - "org.codehaus.plexus" ), - Arrays.asList( "plexus-spring" ) ); - metadataRepositoryControl.expectAndReturn( metadataRepository.getProjectVersions( TEST_REPO_ID, - "org.codehaus.plexus", - "plexus-spring" ), - Arrays.asList( "1.0", "1.1", "1.2" ) ); - metadataRepositoryControl.expectAndReturn( metadataRepository.getArtifacts( TEST_REPO_ID, - "org.codehaus.plexus", - "plexus-spring", "1.0" ), - Arrays.asList( createArtifact( "org.codehaus.plexus", - "plexus-spring", "1.0", "jar" ), - createArtifact( "org.codehaus.plexus", - "plexus-spring", "1.0", - "pom" ) ) ); - metadataRepositoryControl.expectAndReturn( metadataRepository.getArtifacts( TEST_REPO_ID, - "org.codehaus.plexus", - "plexus-spring", "1.1" ), - Arrays.asList( createArtifact( "org.codehaus.plexus", - "plexus-spring", "1.1", "jar" ), - createArtifact( "org.codehaus.plexus", - "plexus-spring", "1.1", - "pom" ) ) ); - metadataRepositoryControl.expectAndReturn( metadataRepository.getArtifacts( TEST_REPO_ID, - "org.codehaus.plexus", - "plexus-spring", "1.2" ), - Arrays.asList( createArtifact( "org.codehaus.plexus", - "plexus-spring", "1.2", "jar" ), - createArtifact( "org.codehaus.plexus", - "plexus-spring", "1.2", - "pom" ) ) ); + //metadataRepositoryControl.expectAndReturn( metadataRepository.getRootNamespaces( TEST_REPO_ID ), + // Arrays.asList( "com", "org" ) ); + expect( metadataRepository.getRootNamespaces( TEST_REPO_ID ) ).andReturn( Arrays.asList( "com", "org" ) ); + //metadataRepositoryControl.expectAndReturn( metadataRepository.getProjects( TEST_REPO_ID, "com" ), + // Arrays.asList() ); + expect( metadataRepository.getProjects( TEST_REPO_ID, "com" ) ).andReturn( Arrays.asList() ); + //metadataRepositoryControl.expectAndReturn( metadataRepository.getNamespaces( TEST_REPO_ID, "com" ), + // Arrays.asList( "example" ) ); + expect( metadataRepository.getNamespaces( TEST_REPO_ID, "com" ) ).andReturn( Arrays.asList( "example" ) ); + //metadataRepositoryControl.expectAndReturn( metadataRepository.getNamespaces( TEST_REPO_ID, "com.example" ), + // Arrays.asList() ); + expect( metadataRepository.getNamespaces( TEST_REPO_ID, "com.example" ) ).andReturn( + Arrays.asList() ); + //metadataRepositoryControl.expectAndReturn( metadataRepository.getProjects( TEST_REPO_ID, "com.example" ), + // Arrays.asList( "example-project" ) ); + expect( metadataRepository.getProjects( TEST_REPO_ID, "com.example" ) ).andReturn( + Arrays.asList( "example-project" ) ); + //metadataRepositoryControl.expectAndReturn( + // metadataRepository.getProjectVersions( TEST_REPO_ID, "com.example", "example-project" ), + // Arrays.asList( "1.0", "1.1" ) ); + expect( metadataRepository.getProjectVersions( TEST_REPO_ID, "com.example", "example-project" ) ).andReturn( + Arrays.asList( "1.0", "1.1" ) ); + //metadataRepositoryControl.expectAndReturn( + // metadataRepository.getArtifacts( TEST_REPO_ID, "com.example", "example-project", "1.0" ), + // Arrays.asList( createArtifact( "com.example", "example-project", "1.0", "jar" ), + // createArtifact( "com.example", "example-project", "1.0", "pom" ) ) ); + expect( + metadataRepository.getArtifacts( TEST_REPO_ID, "com.example", "example-project", "1.0" ) ).andReturn( + Arrays.asList( createArtifact( "com.example", "example-project", "1.0", "jar" ), + createArtifact( "com.example", "example-project", "1.0", "pom" ) ) ); + //metadataRepositoryControl.expectAndReturn( + // metadataRepository.getArtifacts( TEST_REPO_ID, "com.example", "example-project", "1.1" ), + // Arrays.asList( createArtifact( "com.example", "example-project", "1.1", "jar" ), + // createArtifact( "com.example", "example-project", "1.1", "pom" ) ) ); + expect( + metadataRepository.getArtifacts( TEST_REPO_ID, "com.example", "example-project", "1.1" ) ).andReturn( + Arrays.asList( createArtifact( "com.example", "example-project", "1.1", "jar" ), + createArtifact( "com.example", "example-project", "1.1", "pom" ) ) ); + + //metadataRepositoryControl.expectAndReturn( metadataRepository.getNamespaces( TEST_REPO_ID, "org" ), + // Arrays.asList( "apache", "codehaus" ) ); + expect( metadataRepository.getNamespaces( TEST_REPO_ID, "org" ) ).andReturn( Arrays.asList( "apache", "codehaus" ) ); + //metadataRepositoryControl.expectAndReturn( metadataRepository.getNamespaces( TEST_REPO_ID, "org.apache" ), + // Arrays.asList( "archiva", "maven" ) ); + expect( metadataRepository.getNamespaces( TEST_REPO_ID, "org.apache" ) ).andReturn( Arrays.asList( "archiva", "maven" ) ); + //metadataRepositoryControl.expectAndReturn( metadataRepository.getProjects( TEST_REPO_ID, "org.apache" ), + // Arrays.asList() ); + expect( metadataRepository.getProjects( TEST_REPO_ID, "org.apache" ) ).andReturn( Arrays.asList() ); + //metadataRepositoryControl.expectAndReturn( + // metadataRepository.getNamespaces( TEST_REPO_ID, "org.apache.archiva" ), Arrays.asList() ); + expect( metadataRepository.getNamespaces( TEST_REPO_ID, "org.apache.archiva" ) ).andReturn( Arrays.asList() ); + //metadataRepositoryControl.expectAndReturn( + // metadataRepository.getProjects( TEST_REPO_ID, "org.apache.archiva" ), + /// Arrays.asList( "metadata-repository-api", "metadata-model" ) ); + expect( metadataRepository.getProjects( TEST_REPO_ID, "org.apache.archiva" ) ).andReturn( Arrays.asList( "metadata-repository-api", "metadata-model" ) ); + //metadataRepositoryControl.expectAndReturn( + // metadataRepository.getProjectVersions( TEST_REPO_ID, "org.apache.archiva", "metadata-repository-api" ), + // Arrays.asList( "1.3-SNAPSHOT", "1.3" ) ); + expect( metadataRepository.getProjectVersions( TEST_REPO_ID, "org.apache.archiva", "metadata-repository-api" ) ) + .andReturn( Arrays.asList( "1.3-SNAPSHOT", "1.3" ) ); + //metadataRepositoryControl.expectAndReturn( + // metadataRepository.getArtifacts( TEST_REPO_ID, "org.apache.archiva", "metadata-repository-api", + // "1.3-SNAPSHOT" ), + // Arrays.asList( createArtifact( "org.apache.archiva", "metadata-repository-api", "1.3-SNAPSHOT", "jar" ), + // createArtifact( "org.apache.archiva", "metadata-repository-api", "1.3-SNAPSHOT", + // "pom" ) ) ); + expect( metadataRepository.getArtifacts( TEST_REPO_ID, "org.apache.archiva", "metadata-repository-api", "1.3-SNAPSHOT" ) ) + .andReturn( Arrays.asList( createArtifact( "org.apache.archiva", "metadata-repository-api", "1.3-SNAPSHOT", "jar" ), + createArtifact( "org.apache.archiva", "metadata-repository-api", "1.3-SNAPSHOT", + "pom" ) ) ); + //metadataRepositoryControl.expectAndReturn( + // metadataRepository.getArtifacts( TEST_REPO_ID, "org.apache.archiva", "metadata-repository-api", "1.3" ), + // Arrays.asList( createArtifact( "org.apache.archiva", "metadata-repository-api", "1.3", "jar" ), + // createArtifact( "org.apache.archiva", "metadata-repository-api", "1.3", "pom" ) ) ); + expect( metadataRepository.getArtifacts( TEST_REPO_ID, "org.apache.archiva", "metadata-repository-api", "1.3" ) ) + .andReturn( Arrays.asList( createArtifact( "org.apache.archiva", "metadata-repository-api", "1.3", "jar" ), + createArtifact( "org.apache.archiva", "metadata-repository-api", "1.3", "pom" ) ) ); + //metadataRepositoryControl.expectAndReturn( + // metadataRepository.getProjectVersions( TEST_REPO_ID, "org.apache.archiva", "metadata-model" ), + // Arrays.asList( "1.3-SNAPSHOT", "1.3" ) ); + expect( metadataRepository.getProjectVersions( TEST_REPO_ID, "org.apache.archiva", "metadata-model" ) ) + .andReturn( Arrays.asList( "1.3-SNAPSHOT", "1.3" ) ); + //metadataRepositoryControl.expectAndReturn( + // metadataRepository.getArtifacts( TEST_REPO_ID, "org.apache.archiva", "metadata-model", "1.3-SNAPSHOT" ), + // Arrays.asList( createArtifact( "org.apache.archiva", "metadata-model", "1.3-SNAPSHOT", "jar" ), + // createArtifact( "org.apache.archiva", "metadata-model", "1.3-SNAPSHOT", "pom" ) ) ); + expect( metadataRepository.getArtifacts( TEST_REPO_ID, "org.apache.archiva", "metadata-model", "1.3-SNAPSHOT" ) ) + .andReturn( Arrays.asList( createArtifact( "org.apache.archiva", "metadata-model", "1.3-SNAPSHOT", "jar" ), + createArtifact( "org.apache.archiva", "metadata-model", "1.3-SNAPSHOT", "pom" ) ) ); + //metadataRepositoryControl.expectAndReturn( + // metadataRepository.getArtifacts( TEST_REPO_ID, "org.apache.archiva", "metadata-model", "1.3" ), + // Arrays.asList( createArtifact( "org.apache.archiva", "metadata-model", "1.3", "jar" ), + // createArtifact( "org.apache.archiva", "metadata-model", "1.3", "pom" ) ) ); + expect( metadataRepository.getArtifacts( TEST_REPO_ID, "org.apache.archiva", "metadata-model", "1.3" ) ) + .andReturn( Arrays.asList( createArtifact( "org.apache.archiva", "metadata-model", "1.3", "jar" ), + createArtifact( "org.apache.archiva", "metadata-model", "1.3", "pom" ) ) ); + //metadataRepositoryControl.expectAndReturn( + // metadataRepository.getNamespaces( TEST_REPO_ID, "org.apache.maven" ), Arrays.asList() ); + expect( metadataRepository.getNamespaces( TEST_REPO_ID, "org.apache.maven" ) ).andReturn( Arrays.asList() ); + //metadataRepositoryControl.expectAndReturn( + // metadataRepository.getProjects( TEST_REPO_ID, "org.apache.maven" ), Arrays.asList( "maven-model" ) ); + expect( metadataRepository.getProjects( TEST_REPO_ID, "org.apache.maven" ) ) + .andReturn( Arrays.asList( "maven-model" ) ); + //metadataRepositoryControl.expectAndReturn( + // metadataRepository.getProjectVersions( TEST_REPO_ID, "org.apache.maven", "maven-model" ), + // Arrays.asList( "2.2.1" ) ); + expect( metadataRepository.getProjectVersions( TEST_REPO_ID, "org.apache.maven", "maven-model" ) ) + .andReturn( Arrays.asList( "2.2.1" ) ); + //metadataRepositoryControl.expectAndReturn( + // metadataRepository.getArtifacts( TEST_REPO_ID, "org.apache.maven", "maven-model", "2.2.1" ), + // Arrays.asList( createArtifact( "org.apache.archiva", "maven-model", "2.2.1", "jar" ), + // createArtifact( "org.apache.archiva", "maven-model", "2.2.1", "pom" ) ) ); + expect( metadataRepository.getArtifacts( TEST_REPO_ID, "org.apache.maven", "maven-model", "2.2.1" ) ) + .andReturn( Arrays.asList( createArtifact( "org.apache.archiva", "maven-model", "2.2.1", "jar" ), + createArtifact( "org.apache.archiva", "maven-model", "2.2.1", "pom" ) ) ); + //metadataRepositoryControl.expectAndReturn( metadataRepository.getNamespaces( TEST_REPO_ID, "org.codehaus" ), + // Arrays.asList( "plexus" ) ); + expect( metadataRepository.getNamespaces( TEST_REPO_ID, "org.codehaus" ) ).andReturn( Arrays.asList( "plexus" ) ); + //metadataRepositoryControl.expectAndReturn( metadataRepository.getProjects( TEST_REPO_ID, "org" ), + // Arrays.asList() ); + expect( metadataRepository.getProjects( TEST_REPO_ID, "org" ) ).andReturn( Arrays.asList( ) ); + //metadataRepositoryControl.expectAndReturn( metadataRepository.getProjects( TEST_REPO_ID, "org.codehaus" ), + // Arrays.asList() ); + expect( metadataRepository.getProjects( TEST_REPO_ID, "org.codehaus" ) ) + .andReturn( Arrays.asList( ) ); + //metadataRepositoryControl.expectAndReturn( + // metadataRepository.getNamespaces( TEST_REPO_ID, "org.codehaus.plexus" ), Arrays.asList() ); + expect( metadataRepository.getNamespaces( TEST_REPO_ID, "org.codehaus.plexus" ) ) + .andReturn( Arrays.asList( ) ); + //metadataRepositoryControl.expectAndReturn( + // metadataRepository.getProjects( TEST_REPO_ID, "org.codehaus.plexus" ), + // Arrays.asList( "plexus-spring" ) ); + expect( metadataRepository.getProjects( TEST_REPO_ID, "org.codehaus.plexus" ) ) + .andReturn( Arrays.asList( "plexus-spring" ) ); + + //metadataRepositoryControl.expectAndReturn( + // metadataRepository.getProjectVersions( TEST_REPO_ID, "org.codehaus.plexus", "plexus-spring" ), + // Arrays.asList( "1.0", "1.1", "1.2" ) ); + expect( metadataRepository.getProjectVersions( TEST_REPO_ID, "org.codehaus.plexus", "plexus-spring" ) ) + .andReturn( Arrays.asList( "1.0", "1.1", "1.2" ) ); + //metadataRepositoryControl.expectAndReturn( + // metadataRepository.getArtifacts( TEST_REPO_ID, "org.codehaus.plexus", "plexus-spring", "1.0" ), + // Arrays.asList( createArtifact( "org.codehaus.plexus", "plexus-spring", "1.0", "jar" ), + // createArtifact( "org.codehaus.plexus", "plexus-spring", "1.0", "pom" ) ) ); + expect( metadataRepository.getArtifacts( TEST_REPO_ID, "org.codehaus.plexus", "plexus-spring", "1.0" ) ) + .andReturn( Arrays.asList( createArtifact( "org.codehaus.plexus", "plexus-spring", "1.0", "jar" ), + createArtifact( "org.codehaus.plexus", "plexus-spring", "1.0", "pom" ) ) ); + //metadataRepositoryControl.expectAndReturn( + // metadataRepository.getArtifacts( TEST_REPO_ID, "org.codehaus.plexus", "plexus-spring", "1.1" ), + // Arrays.asList( createArtifact( "org.codehaus.plexus", "plexus-spring", "1.1", "jar" ), + // createArtifact( "org.codehaus.plexus", "plexus-spring", "1.1", "pom" ) ) ); + expect( metadataRepository.getArtifacts( TEST_REPO_ID, "org.codehaus.plexus", "plexus-spring", "1.1" ) ) + .andReturn( Arrays.asList( createArtifact( "org.codehaus.plexus", "plexus-spring", "1.1", "jar" ), + createArtifact( "org.codehaus.plexus", "plexus-spring", "1.1", "pom" ) ) ); + //metadataRepositoryControl.expectAndReturn( + // metadataRepository.getArtifacts( TEST_REPO_ID, "org.codehaus.plexus", "plexus-spring", "1.2" ), + // Arrays.asList( createArtifact( "org.codehaus.plexus", "plexus-spring", "1.2", "jar" ), + // createArtifact( "org.codehaus.plexus", "plexus-spring", "1.2", "pom" ) ) ); + expect( metadataRepository.getArtifacts( TEST_REPO_ID, "org.codehaus.plexus", "plexus-spring", "1.2" ) ) + .andReturn( Arrays.asList( createArtifact( "org.codehaus.plexus", "plexus-spring", "1.2", "jar" ), + createArtifact( "org.codehaus.plexus", "plexus-spring", "1.2", "pom" ) ) ); } } } diff --git a/pom.xml b/pom.xml index 342857664..a0960c5ff 100644 --- a/pom.xml +++ b/pom.xml @@ -1537,13 +1537,13 @@ org.easymock easymock - 2.5.2 + 3.2 test org.easymock easymockclassextension - 2.5 + 3.2 test