diff --git a/archiva-modules/archiva-base/archiva-configuration/pom.xml b/archiva-modules/archiva-base/archiva-configuration/pom.xml
index 0305dbca0..485245199 100644
--- a/archiva-modules/archiva-base/archiva-configuration/pom.xml
+++ b/archiva-modules/archiva-base/archiva-configuration/pom.xml
@@ -81,8 +81,8 @@
jakarta.annotation-api
- jakarta.inject
-jakarta.inject-api
+ jakarta.inject
+ jakarta.inject-api
@@ -113,12 +113,6 @@
-
- org.easymock
- easymock
- test
-
-
org.apache.archiva
archiva-test-utils
@@ -137,6 +131,12 @@
test
+
+ org.mockito
+ mockito-core
+ test
+
+
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 90802a64b..9a882d3e2 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
@@ -25,6 +25,7 @@ import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.mockito.Mockito;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
@@ -34,14 +35,13 @@ import org.springframework.test.context.ContextConfiguration;
import javax.inject.Inject;
import java.nio.charset.Charset;
-import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
-import static org.easymock.EasyMock.*;
import static org.junit.Assert.*;
+import static org.mockito.Mockito.mock;
/**
* Test the configuration store.
@@ -219,17 +219,13 @@ public class ArchivaConfigurationTest
configuration.getWebapp().getUi().setAppletFindEnabled( false );
// add a change listener
- ConfigurationListener listener = createMock( ConfigurationListener.class );
+ ConfigurationListener listener = mock( ConfigurationListener.class );
archivaConfiguration.addListener( listener );
listener.configurationEvent( new ConfigurationEvent( ConfigurationEvent.SAVED ) );
- replay( listener );
-
archivaConfiguration.save( configuration );
- verify( listener );
-
assertTrue( "Check file exists", Files.exists(file) );
// check it
@@ -246,7 +242,7 @@ public class ArchivaConfigurationTest
private static ConfigurationListener createConfigurationListenerMockControl()
{
- return createMock( ConfigurationListener.class );// MockControl.createControl( ConfigurationListener.class );
+ return mock( ConfigurationListener.class );// MockControl.createControl( ConfigurationListener.class );
}
@Test
@@ -308,12 +304,8 @@ public class ArchivaConfigurationTest
listener.configurationEvent( new ConfigurationEvent( ConfigurationEvent.SAVED ) );
- replay( listener );
-
archivaConfiguration.save( configuration );
- verify( listener );
-
assertTrue( "Check file exists", Files.exists(userFile) );
assertFalse( "Check file not created", Files.exists(baseFile) );
diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/pom.xml b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/pom.xml
index c7c69e428..752e88dac 100644
--- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/pom.xml
+++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/pom.xml
@@ -167,11 +167,6 @@
spring-test
test
-
- org.easymock
- easymock
- test
-
org.apache.archiva.redback
redback-rbac-jpa
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 fa4cee018..9dd1d7639 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
@@ -34,11 +34,10 @@ import org.apache.archiva.repository.features.ArtifactCleanupFeature;
import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
-import org.easymock.EasyMock;
-import org.easymock.IMocksControl;
import org.junit.After;
import org.junit.Before;
import org.junit.runner.RunWith;
+import org.mockito.Mockito;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.test.context.ContextConfiguration;
@@ -56,6 +55,7 @@ import java.util.stream.Collectors;
import static org.junit.Assert.*;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
/**
*/
@@ -96,14 +96,10 @@ public abstract class AbstractRepositoryPurgeTest
protected RepositoryPurge repoPurge;
- protected IMocksControl listenerControl;
-
protected RepositoryListener listener;
- protected IMocksControl sessionControl;
protected RepositorySession repositorySession;
- protected IMocksControl sessionFactoryControl;
protected RepositorySessionFactory sessionFactory;
protected MetadataRepository metadataRepository;
@@ -121,18 +117,13 @@ public abstract class AbstractRepositoryPurgeTest
throws Exception
{
- listenerControl = EasyMock.createControl();
+ listener = mock( RepositoryListener.class );
- listener = listenerControl.createMock( RepositoryListener.class );
-
- sessionControl = EasyMock.createControl();
- sessionFactoryControl = EasyMock.createControl( );
-
- repositorySession = sessionControl.createMock( RepositorySession.class );
+ repositorySession = mock( RepositorySession.class );
metadataRepository = mock( MetadataRepository.class );
- sessionFactory = sessionFactoryControl.createMock( RepositorySessionFactory.class );
- EasyMock.expect( repositorySession.getRepository() ).andStubReturn( metadataRepository );
- EasyMock.expect( sessionFactory.createSession( ) ).andStubReturn( repositorySession );
+ sessionFactory = mock( RepositorySessionFactory.class );
+ when( repositorySession.getRepository() ).thenReturn( metadataRepository );
+ when( sessionFactory.createSession( ) ).thenReturn( repositorySession );
}
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 8e497dc2c..0a50b3043 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
@@ -30,9 +30,9 @@ import org.apache.archiva.repository.RepositoryContentFactory;
import org.apache.archiva.repository.RepositoryRegistry;
import org.apache.archiva.metadata.audit.RepositoryListener;
import org.apache.archiva.repository.metadata.base.MetadataTools;
-import org.easymock.EasyMock;
import org.junit.Before;
import org.junit.Test;
+import org.mockito.Mockito;
import org.springframework.test.context.ContextConfiguration;
import org.xmlunit.assertj.XmlAssert;
@@ -47,7 +47,7 @@ import java.util.List;
import java.util.Set;
import static org.junit.Assert.assertTrue;
-import static org.mockito.Matchers.eq;
+import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.*;
@@ -90,19 +90,12 @@ public class CleanupReleasedSnapshotsRepositoryPurgeTest
archivaConfiguration =
applicationContext.getBean( "archivaConfiguration#cleanup-released-snapshots", ArchivaConfiguration.class );
- listenerControl = EasyMock.createControl( );
-
- listener = listenerControl.createMock( RepositoryListener.class );
+ listener = mock( RepositoryListener.class );
List listeners = Collections.singletonList( listener );
- sessionControl.reset();
- sessionFactoryControl.reset();
- EasyMock.expect( sessionFactory.createSession( ) ).andStubReturn( repositorySession );
- EasyMock.expect( repositorySession.getRepository()).andStubReturn( metadataRepository );
+ Mockito.when( sessionFactory.createSession( ) ).thenReturn( repositorySession );
+ Mockito.when( repositorySession.getRepository()).thenReturn( metadataRepository );
repositorySession.save();
- EasyMock.expectLastCall().anyTimes();
- sessionFactoryControl.replay();
- sessionControl.replay();
repoPurge = new CleanupReleasedSnapshotsRepositoryPurge( getRepository(), metadataTools,
applicationContext.getBean(
ArchivaRepositoryRegistry.class ),
@@ -135,7 +128,6 @@ public class CleanupReleasedSnapshotsRepositoryPurgeTest
// test listeners for the correct artifacts
listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.apache.maven.plugins",
"maven-plugin-plugin", "2.3-SNAPSHOT", "maven-plugin-plugin-2.3-SNAPSHOT.jar" );
- listenerControl.replay();
// Provide the metadata list
List ml = getArtifactMetadataFromDir(TEST_REPO_ID , projectName, repo.getParent(), vDir );
@@ -145,8 +137,6 @@ public class CleanupReleasedSnapshotsRepositoryPurgeTest
repoPurge.process( PATH_TO_RELEASED_SNAPSHOT_IN_SAME_REPO );
- listenerControl.verify();
-
// Verify the metadataRepository invocations
// complete snapshot version removal for released
verify(metadataRepository, times(1)).removeProjectVersion(eq(repositorySession) , eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion) );
@@ -209,8 +199,6 @@ public class CleanupReleasedSnapshotsRepositoryPurgeTest
String repoRoot = prepareTestRepos();
// test listeners for the correct artifacts
- listenerControl.replay();
-
Path file = Paths.get(repoRoot, INDEX_PATH );
if ( !Files.exists(file) )
{
@@ -222,8 +210,6 @@ public class CleanupReleasedSnapshotsRepositoryPurgeTest
repoPurge.process( INDEX_PATH );
- listenerControl.verify();
-
assertTrue( Files.exists(file) );
}
@@ -260,8 +246,6 @@ public class CleanupReleasedSnapshotsRepositoryPurgeTest
listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.apache.archiva",
"released-artifact-in-diff-repo", "1.0-SNAPSHOT",
"released-artifact-in-diff-repo-1.0-SNAPSHOT.jar" );
- listenerControl.replay();
-
// Provide the metadata list
List ml = getArtifactMetadataFromDir(TEST_REPO_ID , projectName, repo.getParent(), vDir );
when(metadataRepository.getArtifacts(repositorySession , TEST_REPO_ID,
@@ -274,8 +258,6 @@ public class CleanupReleasedSnapshotsRepositoryPurgeTest
repoPurge.process( PATH_TO_RELEASED_SNAPSHOT_IN_DIFF_REPO );
- listenerControl.verify();
-
// Verify the metadataRepository invocations
// Complete version removal for cleanup
verify(metadataRepository, times(1)).removeProjectVersion(eq(repositorySession) , eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion) );
@@ -331,8 +313,6 @@ public class CleanupReleasedSnapshotsRepositoryPurgeTest
Path vDir3 = repo.resolve(projectPath).resolve(projectName).resolve("2.0.4-SNAPSHOT");
// test listeners for the correct artifacts - no deletions
- listenerControl.replay();
-
// Provide the metadata list
List ml = getArtifactMetadataFromDir(TEST_REPO_ID , projectName, repo.getParent(), vDir );
when(metadataRepository.getArtifacts(repositorySession , TEST_REPO_ID,
@@ -347,8 +327,6 @@ public class CleanupReleasedSnapshotsRepositoryPurgeTest
repoPurge.process( CleanupReleasedSnapshotsRepositoryPurgeTest.PATH_TO_HIGHER_SNAPSHOT_EXISTS_IN_SAME_REPO );
- listenerControl.verify();
-
// Verify the metadataRepository invocations
// No removal
verify(metadataRepository, never()).removeProjectVersion(eq(repositorySession) , eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion) );
diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/DaysOldRepositoryPurgeTest.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/DaysOldRepositoryPurgeTest.java
index 0deb60d6e..62a894f0c 100644
--- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/DaysOldRepositoryPurgeTest.java
+++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/DaysOldRepositoryPurgeTest.java
@@ -22,7 +22,6 @@ package org.apache.archiva.consumers.core.repository;
import org.apache.archiva.metadata.model.ArtifactMetadata;
import org.apache.archiva.metadata.audit.RepositoryListener;
import org.apache.archiva.repository.features.ArtifactCleanupFeature;
-import org.easymock.EasyMock;
import org.junit.After;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
@@ -36,7 +35,7 @@ import java.text.SimpleDateFormat;
import java.util.*;
import static org.junit.Assert.assertTrue;
-import static org.mockito.Matchers.eq;
+import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.*;
/**
@@ -73,14 +72,9 @@ public class DaysOldRepositoryPurgeTest
ArtifactCleanupFeature atf = repoConfiguration.getFeature( ArtifactCleanupFeature.class ).get();
- sessionControl.reset();
- sessionFactoryControl.reset();
- EasyMock.expect( sessionFactory.createSession( ) ).andStubReturn( repositorySession );
- EasyMock.expect( repositorySession.getRepository()).andStubReturn( metadataRepository );
+ when( sessionFactory.createSession( ) ).thenReturn( repositorySession );
+ when( repositorySession.getRepository()).thenReturn( metadataRepository );
repositorySession.save();
- EasyMock.expectLastCall().anyTimes();
- sessionFactoryControl.replay();
- sessionControl.replay();
repoPurge = new DaysOldRepositoryPurge( getRepository(), atf.getRetentionPeriod().getDays(),
atf.getRetentionCount(), repositorySession,
@@ -115,7 +109,6 @@ public class DaysOldRepositoryPurgeTest
"maven-install-plugin", "2.2-SNAPSHOT",
"maven-install-plugin-2.2-20061118.060401-2.pom"+exts[i]);
}
- listenerControl.replay();
// Provide the metadata list
List ml = getArtifactMetadataFromDir(TEST_REPO_ID , projectName, repo.getParent(), vDir );
@@ -124,8 +117,6 @@ public class DaysOldRepositoryPurgeTest
repoPurge.process( PATH_TO_BY_DAYS_OLD_ARTIFACT );
- listenerControl.verify();
-
// Verify the metadataRepository invocations
verify(metadataRepository, never()).removeProjectVersion(eq(repositorySession) , eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion) );
ArgumentCaptor metadataArg = ArgumentCaptor.forClass(ArtifactMetadata.class);
@@ -175,14 +166,9 @@ public class DaysOldRepositoryPurgeTest
ArtifactCleanupFeature atf = repoConfiguration.getFeature( ArtifactCleanupFeature.class ).get();
List listeners = Collections.singletonList( listener );
- sessionControl.reset();
- sessionFactoryControl.reset();
- EasyMock.expect( sessionFactory.createSession( ) ).andStubReturn( repositorySession );
- EasyMock.expect( repositorySession.getRepository()).andStubReturn( metadataRepository );
+ when( sessionFactory.createSession( ) ).thenReturn( repositorySession );
+ when( repositorySession.getRepository()).thenReturn( metadataRepository );
repositorySession.save();
- EasyMock.expectLastCall().anyTimes();
- sessionFactoryControl.replay();
- sessionControl.replay();
repoPurge = new DaysOldRepositoryPurge( getRepository(), atf.getRetentionPeriod().getDays(),
atf.getRetentionCount(), repositorySession, listeners );
@@ -209,8 +195,6 @@ public class DaysOldRepositoryPurgeTest
"maven-assembly-plugin", "1.1.2-SNAPSHOT",
"maven-assembly-plugin-1.1.2-20070427.065136-1.pom"+exts[i]);
}
- listenerControl.replay();
-
// Provide the metadata list
List ml = getArtifactMetadataFromDir(TEST_REPO_ID , projectName, repo.getParent(), vDir );
when(metadataRepository.getArtifacts(repositorySession , TEST_REPO_ID,
@@ -219,8 +203,6 @@ public class DaysOldRepositoryPurgeTest
repoPurge.process( PATH_TO_TEST_ORDER_OF_DELETION );
- listenerControl.verify();
-
// Verify the metadataRepository invocations
verify(metadataRepository, never()).removeProjectVersion(eq(repositorySession) , eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion) );
ArgumentCaptor metadataArg = ArgumentCaptor.forClass(ArtifactMetadata.class);
@@ -263,14 +245,9 @@ public class DaysOldRepositoryPurgeTest
ArtifactCleanupFeature atf = repoConfiguration.getFeature( ArtifactCleanupFeature.class ).get();
List listeners = Collections.singletonList( listener );
- sessionControl.reset();
- sessionFactoryControl.reset();
- EasyMock.expect( sessionFactory.createSession( ) ).andStubReturn( repositorySession );
- EasyMock.expect( repositorySession.getRepository()).andStubReturn( metadataRepository );
+ when( sessionFactory.createSession( ) ).thenReturn( repositorySession );
+ when( repositorySession.getRepository()).thenReturn( metadataRepository );
repositorySession.save();
- EasyMock.expectLastCall().anyTimes();
- sessionFactoryControl.replay();
- sessionControl.replay();
repoPurge = new DaysOldRepositoryPurge( getRepository(), atf.getRetentionPeriod().getDays(),
atf.getRetentionCount(), repositorySession, listeners );
@@ -317,7 +294,6 @@ public class DaysOldRepositoryPurgeTest
listener.deleteArtifact(metadataRepository, getRepository().getId(), "org.codehaus.plexus", "plexus-utils",
"1.4.3-SNAPSHOT", "plexus-utils-1.4.3-20070113.163208-4.pom"+exts[i]);
}
- listenerControl.replay();
// Provide the metadata list
List ml = getArtifactMetadataFromDir(TEST_REPO_ID , projectName, repo.getParent(), vDir );
@@ -327,8 +303,6 @@ public class DaysOldRepositoryPurgeTest
repoPurge.process( PATH_TO_BY_DAYS_OLD_METADATA_DRIVEN_ARTIFACT );
- listenerControl.verify();
-
// Verify the metadataRepository invocations
verify(metadataRepository, never()).removeProjectVersion(eq(repositorySession) , eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion) );
ArgumentCaptor metadataArg = ArgumentCaptor.forClass(ArtifactMetadata.class);
diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/RepositoryPurgeConsumerTest.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/RepositoryPurgeConsumerTest.java
index 3af6a44b3..e4f42d8ad 100644
--- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/RepositoryPurgeConsumerTest.java
+++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/RepositoryPurgeConsumerTest.java
@@ -30,7 +30,6 @@ import org.apache.archiva.metadata.model.MetadataFacet;
import org.apache.archiva.repository.base.ArchivaRepositoryRegistry;
import org.apache.archiva.repository.RepositoryRegistry;
import org.apache.archiva.repository.features.ArtifactCleanupFeature;
-import org.easymock.EasyMock;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -52,8 +51,8 @@ import java.util.List;
import java.util.Set;
import static org.junit.Assert.*;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.eq;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.*;
/**
@@ -142,7 +141,7 @@ public class RepositoryPurgeConsumerTest
private void setLastModified( String path ) throws IOException
{
Path dir = Paths.get( path );
- Path[] contents = new Path[0];
+ Path[] contents;
try
{
contents = Files.list( dir ).toArray(Path[]::new);
@@ -152,9 +151,9 @@ public class RepositoryPurgeConsumerTest
log.error("Could not list files {}: {}", dir, e.getMessage(), e);
contents = new Path[0];
}
- for ( int i = 0; i < contents.length; i++ )
+ for ( Path content : contents )
{
- Files.setLastModifiedTime( contents[i], FileTime.fromMillis( 1179382029 ) );
+ Files.setLastModifiedTime( content, FileTime.fromMillis( 1179382029 ) );
}
}
@@ -172,14 +171,9 @@ public class RepositoryPurgeConsumerTest
atf.setRetentionCount( TEST_RETENTION_COUNT );
addRepoToConfiguration( "retention-count", repoConfiguration );
- sessionControl.reset();
- sessionFactoryControl.reset();
- EasyMock.expect( sessionFactory.createSession( ) ).andStubReturn( repositorySession );
- EasyMock.expect( repositorySession.getRepository()).andStubReturn( metadataRepository );
+ when( sessionFactory.createSession( ) ).thenReturn( repositorySession );
+ when( repositorySession.getRepository()).thenReturn( metadataRepository );
repositorySession.save();
- EasyMock.expectLastCall().anyTimes();
- sessionFactoryControl.replay();
- sessionControl.replay();
repoPurgeConsumer.beginScan( repoConfiguration, null );
@@ -287,14 +281,9 @@ public class RepositoryPurgeConsumerTest
atf.setRetentionPeriod( Period.ofDays( TEST_DAYS_OLDER ) );
addRepoToConfiguration( "days-old", repoConfiguration );
- sessionControl.reset();
- sessionFactoryControl.reset();
- EasyMock.expect( sessionFactory.createSession( ) ).andStubReturn( repositorySession );
- EasyMock.expect( repositorySession.getRepository()).andStubReturn( metadataRepository );
+ when( sessionFactory.createSession( ) ).thenReturn( repositorySession );
+ when( repositorySession.getRepository()).thenReturn( metadataRepository );
repositorySession.save();
- EasyMock.expectLastCall().anyTimes();
- sessionFactoryControl.replay();
- sessionControl.replay();
repoPurgeConsumer.beginScan( repoConfiguration, null );
String repoRoot = prepareTestRepos();
@@ -402,7 +391,6 @@ public class RepositoryPurgeConsumerTest
CleanupReleasedSnapshotsRepositoryPurgeTest.PATH_TO_RELEASED_SNAPSHOT_IN_SAME_REPO );
verify(metadataRepository, never()).removeProjectVersion( eq(repositorySession), eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion) );
- ArgumentCaptor metadataArg = ArgumentCaptor.forClass(ArtifactMetadata.class);
verify(metadataRepository, never()).removeTimestampedArtifact( eq(repositorySession), any(), any() );
verify(metadataRepository, never()).removeFacetFromArtifact( eq(repositorySession), any(), any(), any(), any(), any(MetadataFacet.class) );
@@ -441,14 +429,9 @@ public class RepositoryPurgeConsumerTest
acf.setDeleteReleasedSnapshots( true );
addRepoToConfiguration( "days-old", repoConfiguration );
- sessionControl.reset();
- sessionFactoryControl.reset();
- EasyMock.expect( sessionFactory.createSession( ) ).andStubReturn( repositorySession );
- EasyMock.expect( repositorySession.getRepository()).andStubReturn( metadataRepository );
+ when( sessionFactory.createSession( ) ).thenReturn( repositorySession );
+ when( repositorySession.getRepository()).thenReturn( metadataRepository );
repositorySession.save();
- EasyMock.expectLastCall().anyTimes();
- sessionFactoryControl.replay();
- sessionControl.replay();
repoPurgeConsumer.beginScan( repoConfiguration, null );
String repoRoot = prepareTestRepos();
@@ -469,7 +452,6 @@ public class RepositoryPurgeConsumerTest
CleanupReleasedSnapshotsRepositoryPurgeTest.PATH_TO_RELEASED_SNAPSHOT_IN_SAME_REPO );
verify(metadataRepository, times(1)).removeProjectVersion( eq(repositorySession), eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion) );
- ArgumentCaptor metadataArg = ArgumentCaptor.forClass(ArtifactMetadata.class);
verify(metadataRepository, never()).removeTimestampedArtifact( eq(repositorySession), any(), any() );
// check if the snapshot was removed
@@ -486,9 +468,6 @@ public class RepositoryPurgeConsumerTest
String metadataXml = org.apache.archiva.common.utils.FileUtils.readFileToString( artifactMetadataFile, Charset.defaultCharset() );
- String expectedVersions =
- "2.2" + "2.3";
-
XmlAssert.assertThat( metadataXml ).valueByXPath( "//metadata/versioning/latest" ).isEqualTo( "2.3" );
// XMLAssert.assertXpathEvaluatesTo( "2.3", "//metadata/versioning/latest", metadataXml );
XmlAssert.assertThat( metadataXml ).nodesByXPath( "//metadata/versioning/versions/version" ).hasSize( 2 );
diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/RetentionCountRepositoryPurgeTest.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/RetentionCountRepositoryPurgeTest.java
index 97afa7b92..1081380d9 100644
--- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/RetentionCountRepositoryPurgeTest.java
+++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/RetentionCountRepositoryPurgeTest.java
@@ -22,11 +22,11 @@ package org.apache.archiva.consumers.core.repository;
import org.apache.archiva.metadata.model.ArtifactMetadata;
import org.apache.archiva.metadata.audit.RepositoryListener;
import org.apache.archiva.repository.features.ArtifactCleanupFeature;
-import org.easymock.EasyMock;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
+import org.mockito.Mockito;
import java.nio.file.Path;
import java.util.Collections;
@@ -35,7 +35,7 @@ import java.util.List;
import java.util.Set;
import static org.junit.Assert.assertTrue;
-import static org.mockito.Matchers.eq;
+import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.*;
/**
@@ -55,14 +55,9 @@ public class RetentionCountRepositoryPurgeTest
List listeners = Collections.singletonList( listener );
ArtifactCleanupFeature acf = repoConfiguration.getFeature( ArtifactCleanupFeature.class ).get();
- sessionControl.reset();
- sessionFactoryControl.reset();
- EasyMock.expect( sessionFactory.createSession( ) ).andStubReturn( repositorySession );
- EasyMock.expect( repositorySession.getRepository()).andStubReturn( metadataRepository );
+ Mockito.when( sessionFactory.createSession( ) ).thenReturn( repositorySession );
+ Mockito.when( repositorySession.getRepository()).thenReturn( metadataRepository );
repositorySession.save();
- EasyMock.expectLastCall().anyTimes();
- sessionFactoryControl.replay();
- sessionControl.replay();
repoPurge = new RetentionCountRepositoryPurge( getRepository(), acf.getRetentionCount(),
repositorySession, listeners );
@@ -122,8 +117,6 @@ public class RetentionCountRepositoryPurgeTest
listener.deleteArtifact(metadataRepository, getRepository().getId(), "org.jruby.plugins", "jruby-rake-plugin",
"1.0RC1-SNAPSHOT", "jruby-rake-plugin-1.0RC1-20070504.153317-1-javadoc.zip");
- listenerControl.replay();
-
// Provide the metadata list
List ml = getArtifactMetadataFromDir(TEST_REPO_ID , projectName, repo.getParent(), vDir );
when(metadataRepository.getArtifacts( repositorySession, TEST_REPO_ID,
@@ -132,8 +125,6 @@ public class RetentionCountRepositoryPurgeTest
repoPurge.process( PATH_TO_BY_RETENTION_COUNT_ARTIFACT );
- listenerControl.verify();
-
// Verify the metadataRepository invocations
verify(metadataRepository, never()).removeProjectVersion( eq(repositorySession), eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion) );
ArgumentCaptor metadataArg = ArgumentCaptor.forClass(ArtifactMetadata.class);
@@ -209,8 +200,6 @@ public class RetentionCountRepositoryPurgeTest
"1.1.2-SNAPSHOT", "castor-anttasks-1.1.2-20070427.065136-1.pom.sha1" );
listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.codehaus.castor", "castor-anttasks",
"1.1.2-SNAPSHOT", "castor-anttasks-1.1.2-20070427.065136-1.pom" );
- listenerControl.replay();
-
// Provide the metadata list
List ml = getArtifactMetadataFromDir(TEST_REPO_ID , projectName, repo.getParent(), vDir );
when(metadataRepository.getArtifacts( repositorySession, TEST_REPO_ID,
@@ -218,8 +207,6 @@ public class RetentionCountRepositoryPurgeTest
repoPurge.process( PATH_TO_BY_RETENTION_COUNT_POM );
- listenerControl.verify();
-
// Verify the metadataRepository invocations
verify(metadataRepository, never()).removeProjectVersion( eq(repositorySession), eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion) );
ArgumentCaptor metadataArg = ArgumentCaptor.forClass(ArtifactMetadata.class);
@@ -297,8 +284,6 @@ public class RetentionCountRepositoryPurgeTest
listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.apache.maven.plugins",
"maven-assembly-plugin", "1.1.2-SNAPSHOT",
"maven-assembly-plugin-1.1.2-20070427.065136-1.pom" );
- listenerControl.replay();
-
// Provide the metadata list
List ml = getArtifactMetadataFromDir(TEST_REPO_ID , projectName, repo.getParent(), vDir );
when(metadataRepository.getArtifacts( repositorySession, TEST_REPO_ID,
@@ -306,8 +291,6 @@ public class RetentionCountRepositoryPurgeTest
repoPurge.process( PATH_TO_TEST_ORDER_OF_DELETION );
- listenerControl.verify();
-
// Verify the metadataRepository invocations
verify(metadataRepository, never()).removeProjectVersion( eq(repositorySession), eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion) );
ArgumentCaptor metadataArg = ArgumentCaptor.forClass(ArtifactMetadata.class);
diff --git a/archiva-modules/archiva-base/archiva-repository-scanner/pom.xml b/archiva-modules/archiva-base/archiva-repository-scanner/pom.xml
index bde634ef1..c57a4ba1e 100644
--- a/archiva-modules/archiva-base/archiva-repository-scanner/pom.xml
+++ b/archiva-modules/archiva-base/archiva-repository-scanner/pom.xml
@@ -111,6 +111,11 @@
+
+ org.mockito
+ mockito-core
+ test
+
commons-io
commons-io
@@ -126,11 +131,6 @@
archiva-maven-metadata
test
-
- org.easymock
- easymock
- test
-
commons-beanutils
commons-beanutils
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 37989d9b3..8d0964082 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
@@ -29,9 +29,9 @@ import org.apache.archiva.repository.ManagedRepository;
import org.apache.archiva.repository.RemoteRepository;
import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
import org.apache.commons.lang3.SystemUtils;
-import org.easymock.IMocksControl;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.mockito.Mockito;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
@@ -62,7 +62,7 @@ import java.util.Locale;
import java.util.Map;
import java.util.function.Function;
-import static org.easymock.EasyMock.*;
+import static org.mockito.Mockito.*;
/**
* RepositoryContentConsumersTest
@@ -245,27 +245,23 @@ public class RepositoryContentConsumersTest
public void testExecution()
throws Exception
{
- IMocksControl knownControl = createNiceControl();
-
RepositoryContentConsumers consumers = lookupRepositoryConsumers();
KnownRepositoryContentConsumer selectedKnownConsumer =
- knownControl.createMock( KnownRepositoryContentConsumer.class );
+ mock( KnownRepositoryContentConsumer.class );
KnownRepositoryContentConsumer unselectedKnownConsumer =
- createNiceControl().createMock( KnownRepositoryContentConsumer.class );
+ mock( KnownRepositoryContentConsumer.class );
consumers.setApplicationContext(
new MockApplicationContext( Arrays.asList( selectedKnownConsumer, unselectedKnownConsumer ), null ) );
consumers.setSelectedKnownConsumers( Collections.singletonList( selectedKnownConsumer ) );
- IMocksControl invalidControl = createControl();
-
InvalidRepositoryContentConsumer selectedInvalidConsumer =
- invalidControl.createMock( InvalidRepositoryContentConsumer.class );
+ mock( InvalidRepositoryContentConsumer.class );
InvalidRepositoryContentConsumer unselectedInvalidConsumer =
- createControl().createMock( InvalidRepositoryContentConsumer.class );
+ mock( InvalidRepositoryContentConsumer.class );
consumers.setApplicationContext(
new MockApplicationContext( null, Arrays.asList( selectedInvalidConsumer, unselectedInvalidConsumer ) ) );
@@ -279,59 +275,37 @@ public class RepositoryContentConsumersTest
startTime.setTime( 12345678 );
selectedKnownConsumer.beginScan( repo, startTime, false );
- expect( selectedKnownConsumer.getIncludes() ).andReturn( Collections.singletonList( "**/*.txt" ) );
+ when( selectedKnownConsumer.getIncludes() ).thenReturn( Collections.singletonList( "**/*.txt" ) );
selectedKnownConsumer.processFile( _OS( "path/to/test-file.txt" ), false );
- knownControl.replay();
-
selectedInvalidConsumer.beginScan( repo, startTime, false );
- invalidControl.replay();
consumers.executeConsumers( repo, testFile, true );
- knownControl.verify();
- invalidControl.verify();
-
- knownControl.reset();
- invalidControl.reset();
-
Path notIncludedTestFile = Paths.get( "target/test-repo/path/to/test-file.xml" );
selectedKnownConsumer.beginScan( repo, startTime, false );
- expect( selectedKnownConsumer.getExcludes() ).andReturn( Collections.emptyList() );
+ when( selectedKnownConsumer.getExcludes() ).thenReturn( Collections.emptyList() );
- expect( selectedKnownConsumer.getIncludes() ).andReturn( Collections.singletonList( "**/*.txt" ) );
-
- knownControl.replay();
+ when( selectedKnownConsumer.getIncludes() ).thenReturn( Collections.singletonList( "**/*.txt" ) );
selectedInvalidConsumer.beginScan( repo, startTime, false );
selectedInvalidConsumer.processFile( _OS( "path/to/test-file.xml" ), false );
- expect( selectedInvalidConsumer.getId() ).andReturn( "invalid" );
- invalidControl.replay();
+ when( selectedInvalidConsumer.getId() ).thenReturn( "invalid" );
consumers.executeConsumers( repo, notIncludedTestFile, true );
- knownControl.verify();
- invalidControl.verify();
-
- knownControl.reset();
- invalidControl.reset();
-
Path excludedTestFile = Paths.get( "target/test-repo/path/to/test-file.txt" );
selectedKnownConsumer.beginScan( repo, startTime, false );
- expect( selectedKnownConsumer.getExcludes() ).andReturn( Collections.singletonList( "**/test-file.txt" ) );
- knownControl.replay();
+ when( selectedKnownConsumer.getExcludes() ).thenReturn( Collections.singletonList( "**/test-file.txt" ) );
selectedInvalidConsumer.beginScan( repo, startTime, false );
selectedInvalidConsumer.processFile( _OS( "path/to/test-file.txt" ), false );
- expect( selectedInvalidConsumer.getId() ).andReturn( "invalid" );
- invalidControl.replay();
+ when( selectedInvalidConsumer.getId() ).thenReturn( "invalid" );
consumers.executeConsumers( repo, excludedTestFile, true );
- knownControl.verify();
- invalidControl.verify();
}
/**
diff --git a/archiva-modules/archiva-maven/archiva-maven-indexer/pom.xml b/archiva-modules/archiva-maven/archiva-maven-indexer/pom.xml
index 265ac6417..f2855f681 100644
--- a/archiva-modules/archiva-maven/archiva-maven-indexer/pom.xml
+++ b/archiva-modules/archiva-maven/archiva-maven-indexer/pom.xml
@@ -150,6 +150,11 @@
+
+ org.mockito
+ mockito-core
+ test
+
org.apache.archiva
archiva-proxy
@@ -185,11 +190,6 @@
repository-statistics
test
-
- org.easymock
- easymock
- test
-
org.apache.archiva.redback
redback-common-jpa
diff --git a/archiva-modules/archiva-maven/archiva-maven-indexer/src/test/java/org/apache/archiva/maven/indexer/search/AbstractMavenRepositorySearch.java b/archiva-modules/archiva-maven/archiva-maven-indexer/src/test/java/org/apache/archiva/maven/indexer/search/AbstractMavenRepositorySearch.java
index 81f518d3e..4cdc10dba 100644
--- a/archiva-modules/archiva-maven/archiva-maven-indexer/src/test/java/org/apache/archiva/maven/indexer/search/AbstractMavenRepositorySearch.java
+++ b/archiva-modules/archiva-maven/archiva-maven-indexer/src/test/java/org/apache/archiva/maven/indexer/search/AbstractMavenRepositorySearch.java
@@ -27,7 +27,6 @@ import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
import org.apache.archiva.indexer.ArchivaIndexingContext;
import org.apache.archiva.indexer.search.SearchResultHit;
import org.apache.archiva.indexer.search.SearchResults;
-import org.apache.archiva.maven.indexer.search.MavenRepositorySearch;
import org.apache.archiva.proxy.ProxyRegistry;
import org.apache.archiva.repository.Repository;
import org.apache.archiva.repository.base.ArchivaRepositoryRegistry;
@@ -47,8 +46,6 @@ import org.apache.maven.index.ScanningRequest;
import org.apache.maven.index.ScanningResult;
import org.apache.maven.index.context.IndexingContext;
import org.apache.maven.index_shaded.lucene.index.IndexUpgrader;
-import org.easymock.EasyMock;
-import org.easymock.IMocksControl;
import org.junit.After;
import org.junit.Before;
import org.junit.runner.RunWith;
@@ -65,6 +62,9 @@ import java.util.List;
import java.util.Locale;
import static org.apache.archiva.indexer.ArchivaIndexManager.DEFAULT_INDEX_PATH;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.*;
/**
* @author Olivier Lamy
@@ -104,8 +104,6 @@ public abstract class AbstractMavenRepositorySearch
@Inject
private IndexerEngine indexerEngine;
- IMocksControl archivaConfigControl;
-
Configuration config;
@Inject
@@ -132,9 +130,7 @@ public abstract class AbstractMavenRepositorySearch
assertFalse( Files.exists(Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(), "/target/repos/" + TEST_REPO_2 + "/.indexer" )) );
Files.createDirectories( Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(), "/target/repos/" + TEST_REPO_2 + "/.indexer" ) );
- archivaConfigControl = EasyMock.createControl();
-
- archivaConfig = archivaConfigControl.createMock( ArchivaConfiguration.class );
+ archivaConfig = mock( ArchivaConfiguration.class );
repositoryRegistry.setArchivaConfiguration( archivaConfig );
@@ -148,12 +144,9 @@ public abstract class AbstractMavenRepositorySearch
config.addManagedRepository( createRepositoryConfig( TEST_REPO_2 ) );
config.addManagedRepository( createRepositoryConfig( REPO_RELEASE ) );
- archivaConfig.addListener( EasyMock.anyObject( ConfigurationListener.class ) );
- EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes();
- EasyMock.expect( archivaConfig.getConfiguration() ).andReturn(config).anyTimes();
- archivaConfig.save(EasyMock.anyObject(Configuration.class), EasyMock.anyString());
- EasyMock.expectLastCall().anyTimes();
- archivaConfigControl.replay();
+ when( archivaConfig.getDefaultLocale() ).thenReturn( Locale.getDefault( ) );
+ when( archivaConfig.getConfiguration() ).thenReturn(config);
+ archivaConfig.save(any(Configuration.class), anyString());
repositoryRegistry.reload();
}
@@ -163,12 +156,10 @@ public abstract class AbstractMavenRepositorySearch
public void tearDown()
throws Exception
{
- archivaConfigControl.reset();
- EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes();
- EasyMock.expect( archivaConfig.getConfiguration() ).andReturn(config).anyTimes();
- archivaConfig.save(EasyMock.anyObject(Configuration.class), EasyMock.anyString());
- EasyMock.expectLastCall().anyTimes();
- archivaConfigControl.replay();
+ reset( archivaConfig );
+ when( archivaConfig.getDefaultLocale() ).thenReturn( Locale.getDefault( ) );
+ when( archivaConfig.getConfiguration() ).thenReturn(config);
+ archivaConfig.save(any(Configuration.class), anyString());
repositoryRegistry.removeRepository(TEST_REPO_1);
repositoryRegistry.removeRepository(TEST_REPO_2);
repositoryRegistry.removeRepository(REPO_RELEASE);
@@ -273,16 +264,10 @@ public abstract class AbstractMavenRepositorySearch
}
-
-
- archivaConfigControl.reset();
- archivaConfig.addListener( EasyMock.anyObject( ConfigurationListener.class ) );
- EasyMock.expect( archivaConfig.getConfiguration() ).andReturn(config).anyTimes();
- archivaConfig.save(EasyMock.anyObject(Configuration.class), EasyMock.anyString());
- EasyMock.expectLastCall().anyTimes();
- archivaConfigControl.replay();
+ reset( archivaConfig );
+ when( archivaConfig.getConfiguration() ).thenReturn(config);
+ archivaConfig.save(any(Configuration.class), anyString());
repositoryRegistry.reload();
- archivaConfigControl.reset();
Repository rRepo2 = repositoryRegistry.getRepository( repository );
icf = rRepo2.getFeature(IndexCreationFeature.class).get();
diff --git a/archiva-modules/archiva-maven/archiva-maven-indexer/src/test/java/org/apache/archiva/maven/indexer/search/MavenRepositorySearchOSGITest.java b/archiva-modules/archiva-maven/archiva-maven-indexer/src/test/java/org/apache/archiva/maven/indexer/search/MavenRepositorySearchOSGITest.java
index 080063ed5..d0cf2b948 100644
--- a/archiva-modules/archiva-maven/archiva-maven-indexer/src/test/java/org/apache/archiva/maven/indexer/search/MavenRepositorySearchOSGITest.java
+++ b/archiva-modules/archiva-maven/archiva-maven-indexer/src/test/java/org/apache/archiva/maven/indexer/search/MavenRepositorySearchOSGITest.java
@@ -23,7 +23,6 @@ import org.apache.archiva.indexer.search.SearchResultHit;
import org.apache.archiva.indexer.search.SearchResults;
import org.apache.archiva.repository.base.ArchivaRepositoryRegistry;
import org.apache.archiva.repository.base.RepositoryHandlerDependencies;
-import org.easymock.EasyMock;
import org.junit.After;
import org.junit.Test;
@@ -33,6 +32,8 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.List;
+import static org.mockito.Mockito.when;
+
/**
* @author Olivier Lamy
*/
@@ -66,9 +67,7 @@ public class MavenRepositorySearchOSGITest
// search artifactId
// EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes();
- EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes();
-
- archivaConfigControl.replay();
+ when( archivaConfig.getConfiguration()).thenReturn(config);
SearchFields searchFields = new SearchFields();
searchFields.setBundleSymbolicName( "org.apache.felix.bundlerepository" );
@@ -77,8 +76,6 @@ public class MavenRepositorySearchOSGITest
SearchResults results = search.search( "user", searchFields, null );
- archivaConfigControl.verify();
-
assertNotNull( results );
assertEquals( 1, results.getTotalHits() );
diff --git a/archiva-modules/archiva-maven/archiva-maven-indexer/src/test/java/org/apache/archiva/maven/indexer/search/MavenRepositorySearchTest.java b/archiva-modules/archiva-maven/archiva-maven-indexer/src/test/java/org/apache/archiva/maven/indexer/search/MavenRepositorySearchTest.java
index 74df0a23c..0439a4def 100644
--- a/archiva-modules/archiva-maven/archiva-maven-indexer/src/test/java/org/apache/archiva/maven/indexer/search/MavenRepositorySearchTest.java
+++ b/archiva-modules/archiva-maven/archiva-maven-indexer/src/test/java/org/apache/archiva/maven/indexer/search/MavenRepositorySearchTest.java
@@ -26,7 +26,6 @@ import org.apache.archiva.indexer.search.SearchResultLimits;
import org.apache.archiva.indexer.search.SearchResults;
import org.apache.archiva.maven.indexer.util.SearchUtil;
import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
-import org.easymock.EasyMock;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
@@ -40,6 +39,9 @@ import java.util.Collections;
import java.util.List;
import java.util.Locale;
+import static org.mockito.Mockito.reset;
+import static org.mockito.Mockito.when;
+
@RunWith( ArchivaSpringJUnit4ClassRunner.class )
@ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } )
@@ -110,15 +112,11 @@ public class MavenRepositorySearchTest
List selectedRepos = Arrays.asList( TEST_REPO_1 );
// search artifactId
- EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes();
- EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes();
-
- archivaConfigControl.replay();
+ when( archivaConfig.getDefaultLocale() ).thenReturn( Locale.getDefault( ) );
+ when( archivaConfig.getConfiguration()).thenReturn(config);
SearchResults results = search.search( "user", selectedRepos, "archiva-search", null, null );
- archivaConfigControl.verify();
-
assertNotNull( results );
SearchResultHit hit =
@@ -128,18 +126,15 @@ public class MavenRepositorySearchTest
assertEquals( "archiva-search", hit.getArtifactId() );
assertEquals( "1.0", hit.getVersions().get( 0 ) );
- archivaConfigControl.reset();
+ reset( archivaConfig );
- EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes();
- EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes();
+ when( archivaConfig.getDefaultLocale() ).thenReturn( Locale.getDefault( ) );
+ when( archivaConfig.getConfiguration()).thenReturn(config);
// search groupId
- archivaConfigControl.replay();
results = search.search( "user", selectedRepos, "org.apache.archiva", null, null );
- archivaConfigControl.verify();
-
assertNotNull( results );
assertEquals( "total hints not 3", 3, results.getTotalHits() );
@@ -155,15 +150,11 @@ public class MavenRepositorySearchTest
List selectedRepos = Arrays.asList( TEST_REPO_1 );
// search artifactId
- EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes();
- EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes();
-
- archivaConfigControl.replay();
+ when( archivaConfig.getDefaultLocale() ).thenReturn( Locale.getDefault( ) );
+ when( archivaConfig.getConfiguration()).thenReturn(config);
SearchResults results = search.search( "user", selectedRepos, "archiva-search", null, null );
- archivaConfigControl.verify();
-
assertNotNull( results );
SearchResultHit hit =
@@ -173,18 +164,14 @@ public class MavenRepositorySearchTest
assertEquals( "archiva-search", hit.getArtifactId() );
assertEquals( "1.0", hit.getVersions().get( 0 ) );
- archivaConfigControl.reset();
+ reset( archivaConfig );
// search groupId
- EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes();
- EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes();
-
- archivaConfigControl.replay();
+ when( archivaConfig.getDefaultLocale() ).thenReturn( Locale.getDefault( ) );
+ when( archivaConfig.getConfiguration()).thenReturn(config);
results = search.search( "user", selectedRepos, "archiva-search", null, null );
- archivaConfigControl.verify();
-
assertNotNull( results );
assertEquals( "total hints not 3 hits " + results.getHits(), 3, results.getTotalHits() );
@@ -201,15 +188,10 @@ public class MavenRepositorySearchTest
selectedRepos.add( TEST_REPO_1 );
// search artifactId
- EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes();
- EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes();
-
- archivaConfigControl.replay();
+ when( archivaConfig.getDefaultLocale() ).thenReturn( Locale.getDefault( ) );
+ when( archivaConfig.getConfiguration()).thenReturn(config);
SearchResults results = search.search( "user", selectedRepos, "archiva-search", null, null );
-
- archivaConfigControl.verify();
-
assertNotNull( results );
assertEquals( 3, results.getTotalHits() );
@@ -232,10 +214,8 @@ public class MavenRepositorySearchTest
selectedRepos.add( TEST_REPO_1 );
// search artifactId
- EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes();
- EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes();
-
- archivaConfigControl.replay();
+ when( archivaConfig.getDefaultLocale() ).thenReturn( Locale.getDefault( ) );
+ when( archivaConfig.getConfiguration()).thenReturn(config);
SearchFields searchFields = new SearchFields();
searchFields.setGroupId( "org.apache.archiva" );
@@ -245,8 +225,6 @@ public class MavenRepositorySearchTest
SearchResults results = search.search( "user", searchFields, null );
- archivaConfigControl.verify();
-
assertNotNull( results );
assertEquals( 1, results.getTotalHits() );
@@ -269,14 +247,10 @@ public class MavenRepositorySearchTest
List selectedRepos = new ArrayList<>();
selectedRepos.add( TEST_REPO_1 );
- EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes();
- EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes();
- archivaConfigControl.replay();
-
+ when( archivaConfig.getDefaultLocale() ).thenReturn( Locale.getDefault( ) );
+ when( archivaConfig.getConfiguration()).thenReturn(config);
SearchResults results = search.search( "user", selectedRepos, "archiva search", null, null );
- archivaConfigControl.verify();
-
assertNotNull( results );
assertEquals( 1, results.getTotalHits() );
}
@@ -294,36 +268,28 @@ public class MavenRepositorySearchTest
SearchResultLimits limits = new SearchResultLimits( 0 );
limits.setPageSize( 1 );
- EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes();
- EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes();
-
- archivaConfigControl.replay();
+ when( archivaConfig.getDefaultLocale() ).thenReturn( Locale.getDefault( ) );
+ when( archivaConfig.getConfiguration()).thenReturn(config);
SearchResults results = search.search( "user", selectedRepos, "org", limits, Collections.emptyList() );
- archivaConfigControl.verify();
-
assertNotNull( results );
assertEquals( 1, results.getHits().size() );
assertEquals( "total hits not 9 for page1 " + results, 9, results.getTotalHits() );
assertEquals( "returned hits not 1 for page1 " + results, 1, results.getReturnedHitsCount() );
assertEquals( limits, results.getLimits() );
- archivaConfigControl.reset();
+ reset( archivaConfig );
// page 2
limits = new SearchResultLimits( 1 );
limits.setPageSize( 1 );
- EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes();
- EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes();
-
- archivaConfigControl.replay();
+ when( archivaConfig.getDefaultLocale() ).thenReturn( Locale.getDefault( ) );
+ when( archivaConfig.getConfiguration()).thenReturn(config);
results = search.search( "user", selectedRepos, "org", limits, null );
- archivaConfigControl.verify();
-
assertNotNull( results );
assertEquals( "hits not 1", 1, results.getHits().size() );
@@ -351,18 +317,14 @@ public class MavenRepositorySearchTest
config.addManagedRepository( createRepositoryConfig( TEST_REPO_2 ) );
- EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes();
- EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes();
-
- archivaConfigControl.replay();
+ when( archivaConfig.getDefaultLocale() ).thenReturn( Locale.getDefault( ) );
+ when( archivaConfig.getConfiguration()).thenReturn(config);
// wait lucene flush.....
Thread.sleep( 2000 );
SearchResults results = search.search( "user", selectedRepos, "archiva-search", null, null );
- archivaConfigControl.verify();
-
assertNotNull( results );
SearchResultHit hit =
@@ -373,9 +335,6 @@ public class MavenRepositorySearchTest
assertEquals( "not 2 version for hit " + hit + "::" + niceDisplay( results ), 2, hit.getVersions().size() );
assertTrue( hit.getVersions().contains( "1.0" ) );
assertTrue( hit.getVersions().contains( "1.1" ) );
-
- archivaConfigControl.reset();
-
// TODO: [BROWSE] in artifact info from browse, display all the repositories where the artifact is found
}
@@ -388,15 +347,11 @@ public class MavenRepositorySearchTest
List selectedRepos = new ArrayList<>();
selectedRepos.add( TEST_REPO_1 );
- EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes();
- EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes();
-
- archivaConfigControl.replay();
+ when( archivaConfig.getDefaultLocale() ).thenReturn( Locale.getDefault( ) );
+ when( archivaConfig.getConfiguration()).thenReturn(config);
SearchResults results = search.search( "user", selectedRepos, "dfghdfkweriuasndsaie", null, null );
- archivaConfigControl.verify();
-
assertNotNull( results );
assertEquals( 0, results.getTotalHits() );
}
@@ -408,8 +363,8 @@ public class MavenRepositorySearchTest
List selectedRepos = new ArrayList<>();
selectedRepos.add( TEST_REPO_1 );
- // EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes();
- // EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes();
+ // when( archivaConfig.getDefaultLocale() ).thenReturn( Locale.getDefault( ) );
+ // when( archivaConfig.getConfiguration()).thenReturn(config);
// archivaConfigControl.replay();
@@ -417,7 +372,6 @@ public class MavenRepositorySearchTest
assertNotNull( results );
assertEquals( 0, results.getTotalHits() );
- archivaConfigControl.verify();
}
@Test
@@ -433,7 +387,6 @@ public class MavenRepositorySearchTest
assertNotNull( results );
assertEquals( 0, results.getTotalHits() );
- archivaConfigControl.verify();
}
@Test
@@ -448,15 +401,11 @@ public class MavenRepositorySearchTest
List previousSearchTerms = new ArrayList<>();
previousSearchTerms.add( "archiva-test" );
- EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes();
- EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes();
-
- archivaConfigControl.replay();
+ when( archivaConfig.getDefaultLocale() ).thenReturn( Locale.getDefault( ) );
+ when( archivaConfig.getConfiguration()).thenReturn(config);
SearchResults results = search.search( "user", selectedRepos, "1.0", null, previousSearchTerms );
- archivaConfigControl.verify();
-
assertNotNull( results );
assertEquals( "total hints not 1", 1, results.getTotalHits() );
@@ -487,15 +436,11 @@ public class MavenRepositorySearchTest
searchFields.setVersion( "1.0" );
searchFields.setRepositories( selectedRepos );
- EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes();
- EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes();
-
- archivaConfigControl.replay();
+ when( archivaConfig.getDefaultLocale() ).thenReturn( Locale.getDefault( ) );
+ when( archivaConfig.getConfiguration()).thenReturn(config);
SearchResults results = search.search( "user", searchFields, null );
- archivaConfigControl.verify();
-
assertNotNull( results );
assertEquals( 1, results.getTotalHits() );
@@ -523,34 +468,26 @@ public class MavenRepositorySearchTest
SearchResultLimits limits = new SearchResultLimits( 0 );
limits.setPageSize( 1 );
- EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes();
- EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes();
-
- archivaConfigControl.replay();
+ when( archivaConfig.getDefaultLocale() ).thenReturn( Locale.getDefault( ) );
+ when( archivaConfig.getConfiguration()).thenReturn(config);
SearchResults results = search.search( "user", searchFields, limits );
- archivaConfigControl.verify();
-
assertNotNull( results );
assertEquals( 4, results.getTotalHits() );
assertEquals( 1, results.getHits().size() );
// page 2
- archivaConfigControl.reset();
+ reset( archivaConfig );
limits = new SearchResultLimits( 1 );
limits.setPageSize( 1 );
- EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes();
- EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes();
-
- archivaConfigControl.replay();
+ when( archivaConfig.getDefaultLocale() ).thenReturn( Locale.getDefault( ) );
+ when( archivaConfig.getConfiguration()).thenReturn(config);
results = search.search( "user", searchFields, limits );
- archivaConfigControl.verify();
-
assertNotNull( results );
assertEquals( 4, results.getTotalHits() );
assertEquals( 1, results.getHits().size() );
@@ -575,15 +512,11 @@ public class MavenRepositorySearchTest
searchFields.setArtifactId( "artifactid-numeric" );
searchFields.setRepositories( selectedRepos );
- EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes();
- EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes();
-
- archivaConfigControl.replay();
+ when( archivaConfig.getDefaultLocale() ).thenReturn( Locale.getDefault( ) );
+ when( archivaConfig.getConfiguration()).thenReturn(config);
SearchResults results = search.search( "user", searchFields, null );
- archivaConfigControl.verify();
-
assertNotNull( results );
assertEquals( 2, results.getTotalHits() );
}
@@ -619,15 +552,13 @@ public class MavenRepositorySearchTest
try
{
- // EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes();
- // EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes();
+ // when( archivaConfig.getDefaultLocale() ).thenReturn( Locale.getDefault( ) );
+ // when( archivaConfig.getConfiguration()).thenReturn(config);
// archivaConfigControl.replay();
search.search( "user", searchFields, null );
- archivaConfigControl.verify();
-
fail( "A RepositorySearchExcecption should have been thrown." );
}
catch ( RepositorySearchException e )
@@ -655,14 +586,12 @@ public class MavenRepositorySearchTest
try
{
- // EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes();
- // EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes();
+ // when( archivaConfig.getDefaultLocale() ).thenReturn( Locale.getDefault( ) );
+ // when( archivaConfig.getConfiguration()).thenReturn(config);
// archivaConfigControl.replay();
search.search( "user", searchFields, null );
- archivaConfigControl.verify();
-
fail( "A RepositorySearchException should have been thrown." );
}
catch ( RepositorySearchException e )
@@ -688,15 +617,11 @@ public class MavenRepositorySearchTest
searchFields.setClassName( "org.apache.archiva.test.App" );
searchFields.setRepositories( selectedRepos );
- EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes();
- EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes();
-
- archivaConfigControl.replay();
+ when( archivaConfig.getDefaultLocale() ).thenReturn( Locale.getDefault( ) );
+ when( archivaConfig.getConfiguration()).thenReturn(config);
SearchResults results = search.search( "user", searchFields, null );
- archivaConfigControl.verify();
-
assertNotNull( results );
assertEquals( "total hints not 1" + results, 1, results.getTotalHits() );
@@ -720,15 +645,11 @@ public class MavenRepositorySearchTest
searchFields.setPackaging( "jar" );
searchFields.setRepositories( selectedRepos );
- EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes();
- EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes();
-
- archivaConfigControl.replay();
+ when( archivaConfig.getDefaultLocale() ).thenReturn( Locale.getDefault( ) );
+ when( archivaConfig.getConfiguration()).thenReturn(config);
SearchResults results = search.search( "user", searchFields, null );
- archivaConfigControl.verify();
-
assertNotNull( results );
assertEquals( "not 8 but " + results.getTotalHits() + ":" + niceDisplay( results ), 8, results.getTotalHits() );
}
@@ -749,15 +670,11 @@ public class MavenRepositorySearchTest
searchFields.setPackaging( "war" );
searchFields.setRepositories( selectedRepos );
- EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes();
- EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes();
-
- archivaConfigControl.replay();
+ when( archivaConfig.getDefaultLocale() ).thenReturn( Locale.getDefault( ) );
+ when( archivaConfig.getConfiguration()).thenReturn(config);
SearchResults results = search.search( "user", searchFields, null );
- archivaConfigControl.verify();
-
assertNotNull( results );
assertEquals( 0, results.getTotalHits() );
}
@@ -774,15 +691,11 @@ public class MavenRepositorySearchTest
searchFields.setClassName( "com.classname.search.App" );
searchFields.setRepositories( selectedRepos );
- EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes();
- EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes();
-
- archivaConfigControl.replay();
+ when( archivaConfig.getDefaultLocale() ).thenReturn( Locale.getDefault( ) );
+ when( archivaConfig.getConfiguration()).thenReturn(config);
SearchResults results = search.search( "user", searchFields, null );
- archivaConfigControl.verify();
-
assertNotNull( results );
assertEquals( "totalHits not 1 results " + results, 1, results.getTotalHits() );
@@ -803,15 +716,13 @@ public class MavenRepositorySearchTest
searchFields.setGroupId( "org.apache.archiva" );
searchFields.setRepositories( selectedRepos );
- // EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes();
- // EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes();
+ // when( archivaConfig.getDefaultLocale() ).thenReturn( Locale.getDefault( ) );
+ // when( archivaConfig.getConfiguration()).thenReturn(config);
// archivaConfigControl.replay();
SearchResults results = search.search( "user", searchFields, null );
- archivaConfigControl.verify();
-
assertNotNull( results );
assertEquals( 0, results.getTotalHits() );
}
@@ -828,15 +739,11 @@ public class MavenRepositorySearchTest
searchFields.setClassName( "SomeClass" );
searchFields.setRepositories( selectedRepos );
- EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes();
- EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes();
-
- archivaConfigControl.replay();
+ when( archivaConfig.getDefaultLocale() ).thenReturn( Locale.getDefault( ) );
+ when( archivaConfig.getConfiguration()).thenReturn(config);
SearchResults results = search.search( "user", searchFields, null );
- archivaConfigControl.verify();
-
assertNotNull( results );
assertEquals( 1, results.getHits().size() );
assertEquals( "test-webapp", results.getHits().get( 0 ).getArtifactId() );
@@ -850,14 +757,10 @@ public class MavenRepositorySearchTest
List selectedRepos = Arrays.asList( TEST_REPO_1 );
- EasyMock.expect( archivaConfig.getConfiguration() ).andReturn( config ).times( 0, 2 );
-
- archivaConfigControl.replay();
+ when( archivaConfig.getConfiguration() ).thenReturn( config );
Collection groupIds = search.getAllGroupIds( "user", selectedRepos );
- archivaConfigControl.verify();
-
log.info( "groupIds: {}", groupIds );
assertEquals( 3, groupIds.size() );
@@ -878,12 +781,8 @@ public class MavenRepositorySearchTest
searchFields.setClassName( "SomeClass" );
searchFields.setRepositories( selectedRepos );
- archivaConfigControl.replay();
-
SearchResults results = search.search( "user", searchFields, null );
- archivaConfigControl.verify();
-
assertNotNull( results );
assertEquals( 0, results.getHits().size() );
}
@@ -909,10 +808,8 @@ public class MavenRepositorySearchTest
SearchResultLimits limits = new SearchResultLimits(SearchResultLimits.ALL_PAGES);
limits.setPageSize(300);
- // EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes();
- EasyMock.expect(archivaConfig.getConfiguration()).andReturn(config).anyTimes();
-
- archivaConfigControl.replay();
+ // when( archivaConfig.getDefaultLocale() ).thenReturn( Locale.getDefault( ) );
+ when(archivaConfig.getConfiguration()).thenReturn(config);
SearchResults searchResults = search.search(null, Arrays.asList(REPO_RELEASE), //
"org.example", limits, //
@@ -931,8 +828,6 @@ public class MavenRepositorySearchTest
log.info("results: {}", searchResults.getHits().size());
assertEquals(255, searchResults.getHits().size());
-
- archivaConfigControl.verify();
} finally {
FileUtils.deleteQuietly(repo);
}
diff --git a/archiva-modules/archiva-maven/archiva-maven-proxy/pom.xml b/archiva-modules/archiva-maven/archiva-maven-proxy/pom.xml
index c7f26a14e..1e0ef5db9 100644
--- a/archiva-modules/archiva-maven/archiva-maven-proxy/pom.xml
+++ b/archiva-modules/archiva-maven/archiva-maven-proxy/pom.xml
@@ -166,6 +166,11 @@
+
+ org.mockito
+ mockito-core
+ test
+
jakarta.persistence
jakarta.persistence-api
@@ -186,11 +191,6 @@
xmlunit-core
test
-
- org.easymock
- easymock
- test
-
jakarta.transaction
jakarta.transaction-api
diff --git a/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/maven/proxy/AbstractProxyTestCase.java b/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/maven/proxy/AbstractProxyTestCase.java
index da72e9eaa..156f188ce 100644
--- a/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/maven/proxy/AbstractProxyTestCase.java
+++ b/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/maven/proxy/AbstractProxyTestCase.java
@@ -42,8 +42,6 @@ import org.apache.archiva.repository.base.managed.BasicManagedRepository;
import org.apache.archiva.repository.storage.StorageAsset;
import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
import org.apache.maven.wagon.Wagon;
-import org.easymock.EasyMock;
-import org.easymock.IMocksControl;
import org.junit.Before;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
@@ -72,6 +70,7 @@ import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import static org.junit.Assert.*;
+import static org.mockito.Mockito.mock;
/**
* AbstractProxyTestCase
@@ -115,8 +114,6 @@ public abstract class AbstractProxyTestCase
// protected static final String REPOPATH_DEFAULT_MANAGED_TARGET = "target/test-repository/managed";
- protected IMocksControl wagonMockControl;
-
protected Wagon wagonMock;
@@ -185,8 +182,7 @@ public abstract class AbstractProxyTestCase
// Setup the wagon mock.
- wagonMockControl = EasyMock.createNiceControl();
- wagonMock = wagonMockControl.createMock( Wagon.class );
+ wagonMock = mock( Wagon.class );
delegate = (WagonDelegate) applicationContext.getBean( "wagon#http", Wagon.class );
diff --git a/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/maven/proxy/CacheFailuresTransferTest.java b/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/maven/proxy/CacheFailuresTransferTest.java
index 6be8aeacd..fe93b5cd4 100644
--- a/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/maven/proxy/CacheFailuresTransferTest.java
+++ b/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/maven/proxy/CacheFailuresTransferTest.java
@@ -28,7 +28,6 @@ import org.apache.archiva.repository.content.Artifact;
import org.apache.archiva.repository.content.BaseRepositoryContentLayout;
import org.apache.archiva.repository.storage.StorageAsset;
import org.apache.maven.wagon.ResourceDoesNotExistException;
-import org.easymock.EasyMock;
import org.junit.Test;
import javax.inject.Inject;
@@ -39,6 +38,9 @@ import java.nio.file.Paths;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.*;
/**
* CacheFailuresTransferTest
@@ -77,23 +79,11 @@ public class CacheFailuresTransferTest
saveConnector( ID_DEFAULT_MANAGED, "badproxied2", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.YES, false );
- wagonMock.get( EasyMock.eq( path ), EasyMock.anyObject( File.class ) );
-
- EasyMock.expectLastCall( ).andThrow( new ResourceDoesNotExistException( "resource does not exist." ) ).times( 2 );
-
-
- wagonMockControl.replay( );
+ doThrow(new ResourceDoesNotExistException( "resource does not exist." )).when(wagonMock).get( eq( path ), any( ) );
//noinspection UnusedAssignment
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository( ), artifact );
-
- wagonMockControl.verify( );
-
- // Second attempt to download same artifact use cache
- wagonMockControl.reset( );
- wagonMockControl.replay( );
downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository( ), artifact );
- wagonMockControl.verify( );
assertNotDownloaded( downloadedFile );
assertNoTempFiles( expectedFile );
@@ -123,26 +113,16 @@ public class CacheFailuresTransferTest
saveConnector( ID_DEFAULT_MANAGED, "badproxied2", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
- wagonMock.get( EasyMock.eq( path ), EasyMock.anyObject( File.class ) );
- EasyMock.expectLastCall( ).andThrow( new ResourceDoesNotExistException( "resource does not exist." ) ).times( 2 );
-
- wagonMockControl.replay( );
+ doThrow( new ResourceDoesNotExistException( "resource does not exist." ) ).when( wagonMock ).get( eq( path ), any( ) );
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository( ), artifact );
+ verify( wagonMock, times( 2 ) ).get( eq( path ), any( ) );
- wagonMockControl.verify( );
-
- // Second attempt to download same artifact DOES NOT use cache
- wagonMockControl.reset( );
-
- wagonMock.get( EasyMock.eq( path ), EasyMock.anyObject( File.class ) );
- EasyMock.expectLastCall( ).andThrow( new ResourceDoesNotExistException( "resource does not exist." ) ).times( 2 );
-
- wagonMockControl.replay( );
+ reset( wagonMock );
+ doThrow( new ResourceDoesNotExistException( "resource does not exist." ) ).when( wagonMock ).get( eq( path ), any( ) );
downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository( ), artifact );
-
- wagonMockControl.verify( );
+ verify( wagonMock, times( 2 ) ).get( eq( path ), any( ) );
assertNotDownloaded( downloadedFile );
assertNoTempFiles( expectedFile );
diff --git a/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/maven/proxy/ChecksumTransferTest.java b/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/maven/proxy/ChecksumTransferTest.java
index 2d9c155e9..def94b23e 100644
--- a/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/maven/proxy/ChecksumTransferTest.java
+++ b/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/maven/proxy/ChecksumTransferTest.java
@@ -27,7 +27,6 @@ import org.apache.archiva.repository.content.BaseRepositoryContentLayout;
import org.apache.archiva.repository.content.Artifact;
import org.apache.archiva.repository.storage.StorageAsset;
import org.apache.maven.wagon.ResourceDoesNotExistException;
-import org.easymock.EasyMock;
import org.junit.Test;
import java.io.File;
@@ -38,6 +37,9 @@ import java.nio.file.StandardCopyOption;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.*;
/**
* ChecksumTransferTest
@@ -457,20 +459,12 @@ public class ChecksumTransferTest
saveConnector( ID_DEFAULT_MANAGED, "badproxied", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
- wagonMock.get( EasyMock.eq( path ), EasyMock.anyObject( File.class ) );
- EasyMock.expectLastCall( ).once( );
-
- wagonMock.get( EasyMock.eq( path + ".sha1" ), EasyMock.anyObject( File.class ) );
- EasyMock.expectLastCall( ).once( );
-
- wagonMock.get( EasyMock.eq( path + ".md5" ), EasyMock.anyObject( File.class ) );
- EasyMock.expectLastCall( ).andThrow( new ResourceDoesNotExistException( "Resource does not exist." ) ).once( );
-
- wagonMockControl.replay( );
+ doThrow( new ResourceDoesNotExistException( "Resource does not exist." ) ).when( wagonMock ).get( eq( path + ".md5" ), any( ) );
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository( ), artifact );
-
- wagonMockControl.verify( );
+ verify( wagonMock, times( 1 ) ).get( eq( path ), any( ) );
+ verify( wagonMock, times( 1 ) ).get( eq( path + ".sha1"), any( ) );
+ verify( wagonMock, times( 1 ) ).get( eq( path + ".md5"), any( ) );
// Do what the mock doesn't do.
Path proxyPath = Paths.get( REPOPATH_PROXIED1, path ).toAbsolutePath( );
diff --git a/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/maven/proxy/ErrorHandlingTest.java b/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/maven/proxy/ErrorHandlingTest.java
index 53fb8f36b..d85bdd4bd 100644
--- a/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/maven/proxy/ErrorHandlingTest.java
+++ b/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/maven/proxy/ErrorHandlingTest.java
@@ -18,23 +18,34 @@ package org.apache.archiva.maven.proxy;
* under the License.
*/
-import org.apache.archiva.policies.*;
+import org.apache.archiva.policies.CachedFailuresPolicy;
+import org.apache.archiva.policies.ChecksumPolicy;
+import org.apache.archiva.policies.PolicyOption;
+import org.apache.archiva.policies.PropagateErrorsDownloadPolicy;
+import org.apache.archiva.policies.PropagateErrorsOnUpdateDownloadPolicy;
+import org.apache.archiva.policies.ProxyDownloadException;
+import org.apache.archiva.policies.ReleasesPolicy;
+import org.apache.archiva.policies.SnapshotsPolicy;
import org.apache.archiva.repository.content.BaseRepositoryContentLayout;
import org.apache.archiva.repository.content.LayoutException;
import org.apache.archiva.repository.storage.StorageAsset;
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 org.mockito.stubbing.Stubber;
-import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
+import java.util.Arrays;
+import java.util.List;
import static org.junit.Assert.*;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doThrow;
/**
* ErrorHandlingTest
@@ -68,7 +79,7 @@ public class ErrorHandlingTest
createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.STOP );
saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, false );
- simulateGetError( path, expectedFile, createTransferException() );
+ simulateGetError( path, expectedFile, Arrays.asList( createTransferException( ) ) );
confirmSingleFailure( path, ID_MOCKED_PROXIED1 );
}
@@ -83,9 +94,7 @@ public class ErrorHandlingTest
createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.STOP );
createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.STOP );
- simulateGetError( path, expectedFile, createResourceNotFoundException() );
-
- simulateGetError( path, expectedFile, createTransferException() );
+ simulateGetError( path, expectedFile, Arrays.asList( createResourceNotFoundException( ), createTransferException( ) ) );
confirmSingleFailure( path, ID_MOCKED_PROXIED2 );
}
@@ -115,7 +124,7 @@ public class ErrorHandlingTest
saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, false );
- simulateGetError( path, expectedFile, createResourceNotFoundException() );
+ simulateGetError( path, expectedFile, Arrays.asList( createResourceNotFoundException( ) ) );
confirmSuccess( path, expectedFile, REPOPATH_PROXIED2 );
}
@@ -131,7 +140,7 @@ public class ErrorHandlingTest
saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, false );
- simulateGetError( path, expectedFile, createTransferException() );
+ simulateGetError( path, expectedFile, Arrays.asList( createTransferException( ) ) );
confirmSingleFailure( path, ID_MOCKED_PROXIED1 );
}
@@ -161,9 +170,7 @@ public class ErrorHandlingTest
createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.QUEUE );
- simulateGetError( path, expectedFile, createResourceNotFoundException() );
-
- simulateGetError( path, expectedFile, createTransferException() );
+ simulateGetError( path, expectedFile, Arrays.asList( createResourceNotFoundException( ), createTransferException( ) ) );
confirmSingleFailure( path, ID_MOCKED_PROXIED2 );
}
@@ -179,9 +186,7 @@ public class ErrorHandlingTest
createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.QUEUE );
- simulateGetError( path, expectedFile, createTransferException() );
-
- simulateGetError( path, expectedFile, createResourceNotFoundException() );
+ simulateGetError( path, expectedFile, Arrays.asList( createTransferException( ), createResourceNotFoundException( ) ) );
confirmSingleFailure( path, ID_MOCKED_PROXIED1 );
}
@@ -197,9 +202,7 @@ public class ErrorHandlingTest
createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.QUEUE );
- simulateGetError( path, expectedFile, createTransferException() );
-
- simulateGetError( path, expectedFile, createTransferException() );
+ simulateGetError( path, expectedFile, Arrays.asList( createTransferException( ), createTransferException( ) ) );
confirmFailures( path, new String[]{ID_MOCKED_PROXIED1, ID_MOCKED_PROXIED2} );
}
@@ -215,7 +218,7 @@ public class ErrorHandlingTest
saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, false );
- simulateGetError( path, expectedFile, createResourceNotFoundException() );
+ simulateGetError( path, expectedFile, Arrays.asList( createResourceNotFoundException( ) ) );
confirmSuccess( path, expectedFile, REPOPATH_PROXIED2 );
}
@@ -231,7 +234,7 @@ public class ErrorHandlingTest
saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, false );
- simulateGetError( path, expectedFile, createTransferException() );
+ simulateGetError( path, expectedFile, Arrays.asList( createTransferException( ) ) );
confirmSuccess( path, expectedFile, REPOPATH_PROXIED2 );
}
@@ -261,9 +264,7 @@ public class ErrorHandlingTest
createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.IGNORE );
- simulateGetError( path, expectedFile, createResourceNotFoundException() );
-
- simulateGetError( path, expectedFile, createTransferException() );
+ simulateGetError( path, expectedFile, Arrays.asList( createResourceNotFoundException( ), createTransferException( ) ) );
confirmNotDownloadedNoError( path );
}
@@ -279,9 +280,7 @@ public class ErrorHandlingTest
createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.IGNORE );
- simulateGetError( path, expectedFile, createTransferException() );
-
- simulateGetError( path, expectedFile, createResourceNotFoundException() );
+ simulateGetError( path, expectedFile, Arrays.asList( createTransferException( ), createResourceNotFoundException( ) ) );
confirmNotDownloadedNoError( path );
}
@@ -297,9 +296,7 @@ public class ErrorHandlingTest
createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.IGNORE );
- simulateGetError( path, expectedFile, createTransferException() );
-
- simulateGetError( path, expectedFile, createTransferException() );
+ simulateGetError( path, expectedFile, Arrays.asList( createTransferException( ), createTransferException( ) ) );
confirmNotDownloadedNoError( path );
}
@@ -316,7 +313,7 @@ public class ErrorHandlingTest
createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.STOP,
PropagateErrorsOnUpdateDownloadPolicy.ALWAYS );
- simulateGetError( path, expectedFile, createTransferException() );
+ simulateGetError( path, expectedFile, Arrays.asList( createTransferException( ) ) );
confirmSingleFailure( path, ID_MOCKED_PROXIED1 );
}
@@ -350,8 +347,7 @@ public class ErrorHandlingTest
createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.QUEUE,
PropagateErrorsOnUpdateDownloadPolicy.ALWAYS );
- simulateGetError( path, expectedFile, createTransferException() );
- simulateGetError( path, expectedFile, createTransferException() );
+ simulateGetError( path, expectedFile, Arrays.asList( createTransferException( ), createTransferException( ) ) );
confirmFailures( path, new String[] { ID_MOCKED_PROXIED1, ID_MOCKED_PROXIED2 } );
}
@@ -386,8 +382,7 @@ public class ErrorHandlingTest
createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.IGNORE,
PropagateErrorsOnUpdateDownloadPolicy.ALWAYS );
- simulateGetError( path, expectedFile, createTransferException() );
- simulateGetError( path, expectedFile, createTransferException() );
+ simulateGetError( path, expectedFile, Arrays.asList( createTransferException( ), createTransferException( ) ) );
confirmNotDownloadedNoError( path );
}
@@ -423,7 +418,7 @@ public class ErrorHandlingTest
createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.STOP,
PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT );
- simulateGetError( path, expectedFile, createTransferException() );
+ simulateGetError( path, expectedFile, Arrays.asList( createTransferException( ) ) );
confirmSingleFailure( path, ID_MOCKED_PROXIED1 );
}
@@ -458,8 +453,7 @@ public class ErrorHandlingTest
createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.QUEUE,
PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT );
- simulateGetError( path, expectedFile, createTransferException() );
- simulateGetError( path, expectedFile, createTransferException() );
+ simulateGetError( path, expectedFile, Arrays.asList( createTransferException( ), createTransferException( ) ) );
confirmFailures( path, new String[] { ID_MOCKED_PROXIED1, ID_MOCKED_PROXIED2 } );
}
@@ -495,9 +489,7 @@ public class ErrorHandlingTest
createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.IGNORE,
PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT );
- simulateGetError( path, expectedFile, createTransferException() );
- simulateGetError( path, expectedFile, createTransferException() );
-
+ simulateGetError( path, expectedFile, Arrays.asList( createTransferException( ), createTransferException( ) ) );
confirmNotDownloadedNoError( path );
}
@@ -562,18 +554,23 @@ public class ErrorHandlingTest
return file;
}
- private void simulateGetError( String path, Path expectedFile, Exception throwable )
+ private void simulateGetError( String path, Path expectedFile, List throwables )
throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
{
- wagonMock.get( EasyMock.eq( path ), EasyMock.anyObject( File.class ));
- EasyMock.expectLastCall().andThrow(throwable );
+ Stubber stubber = doThrow( throwables.get( 0 ) );
+ if (throwables.size()>1) {
+ for(int i=1; i configListeners = new HashSet();
- private IMocksControl registryControl;
private Registry registryMock;
public MockConfiguration()
{
- registryControl = EasyMock.createNiceControl( );
- registryMock = registryControl.createMock( Registry.class );
+ registryMock = mock( Registry.class );
}
@PostConstruct
diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/pom.xml b/archiva-modules/archiva-maven/archiva-maven-repository/pom.xml
index 8561777cb..a065afd01 100644
--- a/archiva-modules/archiva-maven/archiva-maven-repository/pom.xml
+++ b/archiva-modules/archiva-maven/archiva-maven-repository/pom.xml
@@ -276,11 +276,6 @@
xmlunit-assertj
test
-
- org.easymock
- easymock
- test
-
org.springframework
diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/maven/repository/metadata/storage/mock/MockConfiguration.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/maven/repository/metadata/storage/mock/MockConfiguration.java
index a9dd1e419..a5de3eaeb 100644
--- a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/maven/repository/metadata/storage/mock/MockConfiguration.java
+++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/maven/repository/metadata/storage/mock/MockConfiguration.java
@@ -29,7 +29,6 @@ import org.apache.archiva.configuration.FileType;
import org.apache.archiva.configuration.IndeterminateConfigurationException;
import org.apache.archiva.configuration.RepositoryScanningConfiguration;
import org.apache.commons.lang3.StringUtils;
-import org.easymock.IMocksControl;
import org.springframework.stereotype.Service;
import java.nio.file.Path;
@@ -40,7 +39,7 @@ import java.util.List;
import java.util.Locale;
import java.util.Set;
-import static org.easymock.EasyMock.createNiceControl;
+import static org.mockito.Mockito.mock;
/**
* MockConfiguration
@@ -57,14 +56,11 @@ public class MockConfiguration
private Set registryListeners = new HashSet();
private Set configListeners = new HashSet();
- private IMocksControl registryControl;
-
private Registry registryMock;
public MockConfiguration()
{
- registryControl = createNiceControl();
- registryMock = registryControl.createMock( Registry.class );
+ registryMock = mock( Registry.class );
configuration.setArchivaRuntimeConfiguration(new ArchivaRuntimeConfiguration());
configuration.getArchivaRuntimeConfiguration().addChecksumType("sha1");
configuration.getArchivaRuntimeConfiguration().addChecksumType("sha256");
diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/pom.xml b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/pom.xml
index 3b5f3891d..7dd8dad50 100644
--- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/pom.xml
+++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/pom.xml
@@ -358,6 +358,11 @@
+
+ org.mockito
+ mockito-core
+ test
+
org.hsqldb
hsqldb
@@ -369,11 +374,6 @@
jakarta.persistence-api
test
-
- org.easymock
- easymock
- test
-
jakarta.transaction
jakarta.transaction-api
diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/utils/ArtifactBuilderTest.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/utils/ArtifactBuilderTest.java
index 5bc1d9b28..07588dad9 100644
--- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/utils/ArtifactBuilderTest.java
+++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/utils/ArtifactBuilderTest.java
@@ -22,8 +22,8 @@ import org.apache.archiva.common.filelock.DefaultFileLockManager;
import org.apache.archiva.repository.storage.fs.FilesystemAsset;
import org.apache.archiva.repository.storage.fs.FilesystemStorage;
import org.apache.archiva.repository.storage.StorageAsset;
-import org.easymock.TestSubject;
import org.junit.Test;
+import org.mockito.InjectMocks;
import java.io.IOException;
import java.nio.file.Path;
@@ -33,7 +33,7 @@ import static org.assertj.core.api.Assertions.assertThat;
public class ArtifactBuilderTest
{
- @TestSubject
+ @InjectMocks
private ArtifactBuilder builder = new ArtifactBuilder();
StorageAsset getFile(String path) throws IOException {
diff --git a/archiva-modules/archiva-web/archiva-rss/pom.xml b/archiva-modules/archiva-web/archiva-rss/pom.xml
index f67f8a4ee..d74c24847 100644
--- a/archiva-modules/archiva-web/archiva-rss/pom.xml
+++ b/archiva-modules/archiva-web/archiva-rss/pom.xml
@@ -91,11 +91,6 @@
archiva-filelock
test
-
- org.easymock
- easymock
- test
-
org.apache.archiva
archiva-test-utils
@@ -107,6 +102,11 @@
spring-test
test
+
+ org.mockito
+ mockito-core
+ test
+
diff --git a/archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/processor/NewArtifactsRssFeedProcessorTest.java b/archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/processor/NewArtifactsRssFeedProcessorTest.java
index 2e5913108..a92721477 100644
--- a/archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/processor/NewArtifactsRssFeedProcessorTest.java
+++ b/archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/processor/NewArtifactsRssFeedProcessorTest.java
@@ -28,23 +28,19 @@ import org.apache.archiva.metadata.repository.RepositorySession;
import org.apache.archiva.metadata.repository.RepositorySessionFactory;
import org.apache.archiva.rss.RssFeedGenerator;
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.time.LocalDateTime;
-import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.TimeZone;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
@RunWith (ArchivaBlockJUnit4ClassRunner.class)
public class NewArtifactsRssFeedProcessorTest
@@ -56,10 +52,8 @@ public class NewArtifactsRssFeedProcessorTest
private MetadataRepositoryMock metadataRepository;
- private IMocksControl sessionFactoryControl;
private RepositorySessionFactory sessionFactory;
- private IMocksControl sessionControl;
private RepositorySession session;
@Before
@@ -74,18 +68,11 @@ public class NewArtifactsRssFeedProcessorTest
metadataRepository = new MetadataRepositoryMock();
- sessionFactoryControl = EasyMock.createControl();
- sessionControl = EasyMock.createControl();
- sessionControl.resetToNice();
+ sessionFactory = mock( RepositorySessionFactory.class );
+ session = mock( RepositorySession.class );
- sessionFactory = sessionFactoryControl.createMock( RepositorySessionFactory.class );
- session = sessionControl.createMock( RepositorySession.class );
-
- EasyMock.expect( sessionFactory.createSession() ).andStubReturn( session );
- EasyMock.expect( session.getRepository( ) ).andStubReturn( metadataRepository );
-
- sessionFactoryControl.replay();
- sessionControl.replay();
+ when( sessionFactory.createSession() ).thenReturn( session );
+ when( session.getRepository( ) ).thenReturn( metadataRepository );
newArtifactsProcessor.setRepositorySessionFactory( sessionFactory );
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 28b679a25..ddb35ff33 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
@@ -34,8 +34,6 @@ import org.apache.archiva.repository.RepositoryRegistry;
import org.apache.archiva.repository.storage.fs.FilesystemStorage;
import org.apache.archiva.rss.RssFeedGenerator;
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;
@@ -51,8 +49,9 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import static org.easymock.EasyMock.createControl;
-import static org.easymock.EasyMock.expect;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
@RunWith(ArchivaBlockJUnit4ClassRunner.class)
public class NewVersionsOfArtifactRssFeedProcessorTest
@@ -66,17 +65,12 @@ public class NewVersionsOfArtifactRssFeedProcessorTest
private static final String ARTIFACT_ID = "artifact-two";
- private IMocksControl metadataRepositoryControl;
-
private MetadataRepository metadataRepository;
- private IMocksControl sessionFactoryControl;
private RepositorySessionFactory sessionFactory;
- private IMocksControl sessionControl;
private RepositorySession session;
- private IMocksControl repositoryRegistryControl;
private RepositoryRegistry repositoryRegistry;
@@ -90,28 +84,20 @@ public class NewVersionsOfArtifactRssFeedProcessorTest
newVersionsProcessor = new NewVersionsOfArtifactRssFeedProcessor();
newVersionsProcessor.setGenerator( new RssFeedGenerator() );
- metadataRepositoryControl = createControl();
- metadataRepository = metadataRepositoryControl.createMock( MetadataRepository.class );
+ metadataRepository = mock( MetadataRepository.class );
- sessionFactoryControl = EasyMock.createControl();
- sessionControl = EasyMock.createControl();
- sessionControl.resetToNice();
- sessionFactory = sessionFactoryControl.createMock( RepositorySessionFactory.class );
- session = sessionControl.createMock( RepositorySession.class );
+ sessionFactory = mock( RepositorySessionFactory.class );
+ session = mock( RepositorySession.class );
- EasyMock.expect( sessionFactory.createSession() ).andStubReturn( session );
- EasyMock.expect( session.getRepository( ) ).andStubReturn( metadataRepository );
- sessionFactoryControl.replay();
- sessionControl.replay();
+ when( sessionFactory.createSession() ).thenReturn( session );
+ when( session.getRepository( ) ).thenReturn( metadataRepository );
- repositoryRegistryControl = EasyMock.createControl();
- repositoryRegistry = repositoryRegistryControl.createMock( ArchivaRepositoryRegistry.class );
+ repositoryRegistry = mock( ArchivaRepositoryRegistry.class );
List reg = new ArrayList<>( );
reg.add( new BasicManagedRepository( TEST_REPO, TEST_REPO, new FilesystemStorage( Paths.get("target/test-storage"), new DefaultFileLockManager() ) ) );
- EasyMock.expect( repositoryRegistry.getRepositories() ).andStubReturn( reg );
- repositoryRegistryControl.replay();
+ when( repositoryRegistry.getRepositories() ).thenReturn( reg );
newVersionsProcessor.setRepositorySessionFactory( sessionFactory );
newVersionsProcessor.setRepositoryRegistry( repositoryRegistry );
@@ -137,15 +123,14 @@ public class NewVersionsOfArtifactRssFeedProcessorTest
reqParams.put( RssFeedProcessor.KEY_GROUP_ID, GROUP_ID );
reqParams.put( RssFeedProcessor.KEY_ARTIFACT_ID, ARTIFACT_ID );
- expect(metadataRepository.getProjectVersions(session, TEST_REPO, GROUP_ID, ARTIFACT_ID)).andReturn(
+ when(metadataRepository.getProjectVersions(session, TEST_REPO, GROUP_ID, ARTIFACT_ID)).thenReturn(
Arrays.asList("1.0.1", "1.0.2", "1.0.3-SNAPSHOT"));
- expect(metadataRepository.getArtifacts(session, TEST_REPO, GROUP_ID, ARTIFACT_ID, "1.0.1")).andReturn(
+ when(metadataRepository.getArtifacts(session, TEST_REPO, GROUP_ID, ARTIFACT_ID, "1.0.1")).thenReturn(
Collections.singletonList(artifact1));
- expect(metadataRepository.getArtifacts(session, TEST_REPO, GROUP_ID, ARTIFACT_ID, "1.0.2")).andReturn(
+ when(metadataRepository.getArtifacts(session, TEST_REPO, GROUP_ID, ARTIFACT_ID, "1.0.2")).thenReturn(
Collections.singletonList(artifact2));
- expect(metadataRepository.getArtifacts(session, TEST_REPO, GROUP_ID, ARTIFACT_ID, "1.0.3-SNAPSHOT")).andReturn(
+ when(metadataRepository.getArtifacts(session, TEST_REPO, GROUP_ID, ARTIFACT_ID, "1.0.3-SNAPSHOT")).thenReturn(
Collections.singletonList(artifact3));
- metadataRepositoryControl.replay();
SyndFeed feed = newVersionsProcessor.process( reqParams );
@@ -166,7 +151,6 @@ public class NewVersionsOfArtifactRssFeedProcessorTest
assertEquals( whenGatheredNext.toInstant(), entries.get( 1 ).getPublishedDate().toInstant() );
- metadataRepositoryControl.verify();
}
private ArtifactMetadata createArtifact(ZonedDateTime whenGathered, String version )
diff --git a/archiva-modules/archiva-web/archiva-security/pom.xml b/archiva-modules/archiva-web/archiva-security/pom.xml
index c56bd89bb..e84139a5c 100644
--- a/archiva-modules/archiva-web/archiva-security/pom.xml
+++ b/archiva-modules/archiva-web/archiva-security/pom.xml
@@ -146,6 +146,11 @@
+
+ org.mockito
+ mockito-core
+ test
+
org.apache.archiva.maven
archiva-maven-proxy
@@ -161,11 +166,6 @@
jakarta.persistence-api
test
-
- org.easymock
- easymock
- test
-
org.apache.archiva.redback
redback-keys-jpa
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 9258abea8..75a1887b2 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
@@ -27,8 +27,6 @@ import org.apache.archiva.redback.system.SecuritySession;
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;
@@ -36,6 +34,9 @@ import javax.inject.Inject;
import javax.inject.Named;
import javax.servlet.http.HttpServletRequest;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
/**
* ArchivaServletAuthenticatorTest
*/
@@ -46,8 +47,6 @@ public class ArchivaServletAuthenticatorTest
@Named( value = "servletAuthenticator#test" )
private ServletAuthenticator servletAuth;
- private IMocksControl httpServletRequestControl;
-
private HttpServletRequest request;
@Before
@@ -57,8 +56,7 @@ public class ArchivaServletAuthenticatorTest
{
super.setUp();
- httpServletRequestControl = EasyMock.createControl( );
- request = httpServletRequestControl.createMock( HttpServletRequest.class );
+ request = mock( HttpServletRequest.class );
setupRepository( "corporate" );
}
@@ -126,7 +124,7 @@ public class ArchivaServletAuthenticatorTest
assignRepositoryObserverRole( USER_ALPACA, "corporate" );
//httpServletRequestControl.expectAndReturn( request.getRemoteAddr(), "192.168.111.111" );
- EasyMock.expect( request.getRemoteAddr() ).andReturn( "192.168.111.111" );
+ when( request.getRemoteAddr() ).thenReturn( "192.168.111.111" );
UserManager userManager = securitySystem.getUserManager();
User user = userManager.findUser( USER_ALPACA );
@@ -135,8 +133,6 @@ public class ArchivaServletAuthenticatorTest
SecuritySession session = new DefaultSecuritySession( result, user );
- httpServletRequestControl.replay();
-
try
{
servletAuth.isAuthorized( request, session, "corporate", ArchivaRoleConstants.OPERATION_ADD_ARTIFACT );
@@ -147,8 +143,6 @@ public class ArchivaServletAuthenticatorTest
assertEquals( "Access denied for repository corporate", e.getMessage() );
}
- httpServletRequestControl.verify();
-
restoreGuestInitialValues( USER_ALPACA );
}
diff --git a/archiva-modules/archiva-web/archiva-webdav/pom.xml b/archiva-modules/archiva-web/archiva-webdav/pom.xml
index dcfacf75c..747293b41 100644
--- a/archiva-modules/archiva-web/archiva-webdav/pom.xml
+++ b/archiva-modules/archiva-web/archiva-webdav/pom.xml
@@ -278,8 +278,8 @@
test
- org.easymock
- easymock
+ org.mockito
+ mockito-core
test
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 2de2b9a78..3650a9704 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
@@ -56,12 +56,11 @@ 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.EasyMock;
-import org.easymock.IMocksControl;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.mockito.Mockito;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
@@ -78,7 +77,8 @@ import java.util.Locale;
import java.util.Set;
import java.util.concurrent.atomic.AtomicReference;
-import static org.easymock.EasyMock.*;
+import static org.mockito.Mockito.*;
+
/**
* ArchivaDavResourceFactoryTest
@@ -102,26 +102,16 @@ public class ArchivaDavResourceFactoryTest
private OverridingArchivaDavResourceFactory resourceFactory;
- private IMocksControl requestControl;
-
private DavServletRequest request;
- private IMocksControl repoRequestControl;
-
private MavenRepositoryRequestInfo repoRequest;
- private IMocksControl responseControl;
-
private DavServletResponse response;
- private IMocksControl archivaConfigurationControl;
-
private ArchivaConfiguration archivaConfiguration;
private Configuration config;
- private IMocksControl repoContentFactoryControl;
-
private RepositoryContentFactory repoFactory;
@Inject
@@ -184,26 +174,19 @@ public class ArchivaDavResourceFactoryTest
{
super.setUp();
- requestControl = createControl();
- request = requestControl.createMock( DavServletRequest.class );
+ request = mock( DavServletRequest.class );
- responseControl = createControl();
- response = responseControl.createMock( DavServletResponse.class );
+ response = mock( DavServletResponse.class );
//responseControl.setDefaultMatcher( MockControl.ALWAYS_MATCHER );
- archivaConfigurationControl = createControl();
- archivaConfiguration = archivaConfigurationControl.createMock( ArchivaConfiguration.class );
+ archivaConfiguration = mock( ArchivaConfiguration.class );
config = new Configuration();
- expect( archivaConfiguration.getConfiguration() ).andReturn( config ).times( 2, 25 );
- expect (archivaConfiguration.getDefaultLocale()).andReturn( Locale.getDefault() ).anyTimes();
- archivaConfiguration.addListener( EasyMock.anyObject( ) );
- expectLastCall().times(0, 4);
+ when( archivaConfiguration.getConfiguration() ).thenReturn( config );
+ when(archivaConfiguration.getDefaultLocale()).thenReturn( Locale.getDefault() );
+ archivaConfiguration.addListener( any() );
archivaConfiguration.save( eq(config));
- expectLastCall().times( 0, 5 );
- archivaConfiguration.save( eq(config), EasyMock.anyString());
- expectLastCall().times( 0, 5 );
- archivaConfigurationControl.replay();
+ archivaConfiguration.save( eq(config), anyString());
defaultManagedRepositoryAdmin.setArchivaConfiguration( archivaConfiguration );
repositoryRegistry.setArchivaConfiguration( archivaConfiguration );
@@ -233,11 +216,9 @@ public class ArchivaDavResourceFactoryTest
defaultRepositoryGroupAdmin.addRepositoryGroup( repoGroupConfig, null );
}
- repoContentFactoryControl = createControl();
- repoFactory = repoContentFactoryControl.createMock( RepositoryContentFactory.class );
+ repoFactory = mock( RepositoryContentFactory.class );
- repoRequestControl = createControl();
- repoRequest = repoRequestControl.createMock( MavenRepositoryRequestInfo.class );
+ repoRequest = mock( MavenRepositoryRequestInfo.class );
resourceFactory =
new OverridingArchivaDavResourceFactory( applicationContext, archivaConfiguration );
@@ -248,6 +229,12 @@ public class ArchivaDavResourceFactoryTest
resourceFactory.setRemoteRepositoryAdmin( remoteRepositoryAdmin );
resourceFactory.setManagedRepositoryAdmin( defaultManagedRepositoryAdmin );
resourceFactory.setRepositoryRegistry( repositoryRegistry );
+ verify( archivaConfiguration, atLeast( 2 )).getConfiguration();
+ verify( archivaConfiguration, atMost( 25 )).getConfiguration();
+ verify( archivaConfiguration, atMost( 4 ) ).addListener( any() );
+ verify( archivaConfiguration, atMost( 5 ) ).save( eq(config) );
+ verify( archivaConfiguration, atMost( 5 ) ).save( eq(config), anyString() );
+
}
private ManagedRepository createManagedRepository( String id, String location, String layout )
@@ -349,51 +336,51 @@ public class ArchivaDavResourceFactoryTest
try
{
- archivaConfigurationControl.reset();
+ reset( archivaConfiguration );
+ reset( request );
+ reset( repoFactory );
+ when( archivaConfiguration.getConfiguration( ) ).thenReturn( config );
- expect( archivaConfiguration.getConfiguration() ).andReturn( config ).times( 3 );
+ when( request.getMethod() ).thenReturn( "GET" );
- expect( request.getMethod() ).andReturn( "GET" ).times( 3 );
+ when( request.getPathInfo() ).thenReturn( "org/apache/archiva" );
- expect( request.getPathInfo() ).andReturn( "org/apache/archiva" ).times( 0, 2 );
+ when( repoFactory.getManagedRepositoryContent( RELEASES_REPO ) ).thenReturn( releasesRepo );
- expect( repoFactory.getManagedRepositoryContent( RELEASES_REPO ) ).andReturn( releasesRepo );
+ when( request.getRemoteAddr( ) ).thenReturn( "http://localhost:8080" );
- expect( request.getRemoteAddr() ).andReturn( "http://localhost:8080" ).times( 2 );
+ when( request.getDavSession( ) ).thenReturn( new ArchivaDavSession( ) );
- expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 2 );
+ when( request.getContextPath( ) ).thenReturn( "" );
- expect( request.getContextPath() ).andReturn( "" ).times( 2 );
+ when( repoRequest.isSupportFile( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).thenReturn( true );
- expect( repoRequest.isSupportFile( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( true );
-
- expect(
- repoRequest.getLayout( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn(
+ when(
+ repoRequest.getLayout( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).thenReturn(
"legacy" );
- expect( repoRequest.toItemSelector(
- "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( null );
+ when( repoRequest.toItemSelector(
+ "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).thenReturn( null );
- expect( repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar"
- ) ).andReturn(
+ when( repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar"
+ ) ).thenReturn(
Paths.get( config.findManagedRepositoryById( INTERNAL_REPO ).getLocation(),
"target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ).toString());
- expect( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ) ).andReturn( internalRepo );
+ when( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ) ).thenReturn( internalRepo );
- expect( repoRequest.isArchetypeCatalog(
- "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( false );
- archivaConfigurationControl.replay();
- requestControl.replay();
- repoContentFactoryControl.replay();
- repoRequestControl.replay();
+ when( repoRequest.isArchetypeCatalog(
+ "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).thenReturn( false );
resourceFactory.createResource( locator, request, response );
- archivaConfigurationControl.verify();
- requestControl.verify();
- repoContentFactoryControl.verify();
- repoRequestControl.verify();
+ verify(archivaConfiguration, times( 3 )).getConfiguration();
+ verify( request, times( 3 ) ).getMethod( );
+ verify( request, atMost( 2 ) ).getPathInfo( );
+ verify(request,times( 2 )).getRemoteAddr();
+ verify( request, times( 2 ) ).getDavSession( );
+ verify( request, times( 2 ) ).getContextPath( );
+
fail( "A DavException with 401 error code should have been thrown." );
}
@@ -427,52 +414,51 @@ public class ArchivaDavResourceFactoryTest
try
{
- archivaConfigurationControl.reset();
+ reset( archivaConfiguration );
+ reset( request );
+ reset( repoFactory );
- expect( archivaConfiguration.getConfiguration() ).andReturn( config ).times( 3 );
+ when( archivaConfiguration.getConfiguration( ) ).thenReturn( config );
- expect( request.getMethod() ).andReturn( "GET" ).times( 3 );
+ when( request.getMethod() ).thenReturn( "GET" );
- expect( request.getPathInfo() ).andReturn( "org/apache/archiva" ).times( 0, 2 );
+ when( request.getPathInfo() ).thenReturn( "org/apache/archiva" );
- expect( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ) ).andReturn( internalRepo );
+ when( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ) ).thenReturn( internalRepo );
- expect( repoFactory.getManagedRepositoryContent( RELEASES_REPO ) ).andReturn( releasesRepo );
+ when( repoFactory.getManagedRepositoryContent( RELEASES_REPO ) ).thenReturn( releasesRepo );
- expect( request.getRemoteAddr() ).andReturn( "http://localhost:8080" ).times( 2 );
+ when( request.getRemoteAddr() ).thenReturn( "http://localhost:8080" );
- expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 2 );
+ when( request.getDavSession() ).thenReturn( new ArchivaDavSession() );
- expect( request.getContextPath() ).andReturn( "" ).times( 2 );
+ when( request.getContextPath() ).thenReturn( "" );
- expect( repoRequest.isSupportFile( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( false );
+ when( repoRequest.isSupportFile( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).thenReturn( false );
- expect(
- repoRequest.getLayout( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn(
+ when(
+ repoRequest.getLayout( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).thenReturn(
"legacy" );
- expect( repoRequest.toItemSelector(
- "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( null );
+ when( repoRequest.toItemSelector(
+ "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).thenReturn( null );
- expect( repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar"
- ) ).andReturn(
+ when( repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar"
+ ) ).thenReturn(
Paths.get( config.findManagedRepositoryById( INTERNAL_REPO ).getLocation(),
"target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ).toString());
- expect( repoRequest.isArchetypeCatalog(
- "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( false );
- archivaConfigurationControl.replay();
- requestControl.replay();
- repoContentFactoryControl.replay();
- repoRequestControl.replay();
+ when( repoRequest.isArchetypeCatalog(
+ "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).thenReturn( false );
resourceFactory.createResource( locator, request, response );
-
- archivaConfigurationControl.verify();
- requestControl.verify();
- repoContentFactoryControl.verify();
- repoRequestControl.verify();
+ verify( archivaConfiguration, times( 3 ) ).getConfiguration( );
+ verify( request, times( 3 ) ).getMethod();
+ verify( request, atMost( 2 ) ).getPathInfo( );
+ verify( request, times( 2 ) ).getRemoteAddr( );
+ verify( request, times( 2 ) ).getDavSession( );
+ verify( request, times( 2 ) ).getContextPath( );
fail( "A DavException with 401 error code should have been thrown." );
}
@@ -511,55 +497,59 @@ public class ArchivaDavResourceFactoryTest
try
{
- archivaConfigurationControl.reset();
+ reset( archivaConfiguration );
+ reset( request );
+ reset( repoFactory );
- expect( archivaConfiguration.getConfiguration() ).andReturn( config ).times( 3 );
+ when( archivaConfiguration.getConfiguration() ).thenReturn( config );
- expect( request.getMethod() ).andReturn( "GET" ).times( 5 );
+ when( request.getMethod() ).thenReturn( "GET" );
- expect( request.getPathInfo() ).andReturn( "org/apache/archiva" ).times( 0, 2 );
+ when( request.getPathInfo() ).thenReturn( "org/apache/archiva" );
- expect( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ) ).andReturn( internalRepo );
+ when( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ) ).thenReturn( internalRepo );
- expect( repoFactory.getManagedRepositoryContent( LOCAL_MIRROR_REPO ) ).andReturn( localMirrorRepo );
+ when( repoFactory.getManagedRepositoryContent( LOCAL_MIRROR_REPO ) ).thenReturn( localMirrorRepo );
- expect( request.getRemoteAddr() ).andReturn( "http://localhost:8080" ).times( 4 );
+ when( request.getRemoteAddr() ).thenReturn( "http://localhost:8080" );
- expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 4 );
+ when( request.getDavSession() ).thenReturn( new ArchivaDavSession() );
- expect( request.getContextPath() ).andReturn( "" ).times( 2 );
+ when( request.getContextPath() ).thenReturn( "" );
- expect( repoRequest.isSupportFile( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( false ).times( 2 );
+ when( repoRequest.isSupportFile( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).thenReturn( false );
- expect(
- repoRequest.getLayout( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn(
- "legacy" ).times( 2 );
+ when(
+ repoRequest.getLayout( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).thenReturn(
+ "legacy" );
- expect( repoRequest.toItemSelector(
- "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( null ).times( 2 );
+ when( repoRequest.toItemSelector(
+ "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).thenReturn( null );
- expect( repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar"
- ) ).andReturn(
+ when( repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar"
+ ) ).thenReturn(
Paths.get( config.findManagedRepositoryById( INTERNAL_REPO ).getLocation(),
"target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ).toString() );
- expect( repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar"
+ when( repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar"
) )
- .andReturn( Paths.get( config.findManagedRepositoryById( LOCAL_MIRROR_REPO ).getLocation(),
+ .thenReturn( Paths.get( config.findManagedRepositoryById( LOCAL_MIRROR_REPO ).getLocation(),
"target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ).toString());
- 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();
- repoRequestControl.replay();
+ when( repoRequest.isArchetypeCatalog( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).thenReturn( false );
resourceFactory.createResource( locator, request, response );
-
- archivaConfigurationControl.verify();
- requestControl.verify();
- repoContentFactoryControl.verify();
- repoRequestControl.verify();
+ verify( archivaConfiguration, times( 3 ) ).getConfiguration( );
+ verify( request, times( 5 ) ).getMethod( );
+ verify( request, atMost( 2 ) ).getPathInfo( );
+ verify( request, times( 4 ) ).getRemoteAddr( );
+ verify( request, times( 4 ) ).getDavSession( );
+ verify( request, times( 2 ) ).getContextPath( );
+ verify( repoRequest, times( 2 ) ).isSupportFile( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" );
+ verify(repoRequest, times( 2 )).getLayout( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" );
+ verify( repoRequest, times( 2 ) ).toItemSelector(
+ "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" );
+ verify( repoRequest, times( 2 ) ).isArchetypeCatalog( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" );
fail( "A DavException with 404 error code should have been thrown." );
}
@@ -586,39 +576,27 @@ public class ArchivaDavResourceFactoryTest
try
{
- archivaConfigurationControl.reset();
+ reset( request );
- expect( request.getMethod() ).andReturn( "GET" ).times( 4 );
+ when( request.getMethod() ).thenReturn( "GET" );
- expect( request.getRemoteAddr() ).andReturn( "http://localhost:8080" ).times( 3 );
+ when( request.getRemoteAddr() ).thenReturn( "http://localhost:8080" );
- expect( request.getContextPath() ).andReturn( "" ).times( 1 );
+ when( request.getContextPath() ).thenReturn( "" );
- expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 2 );
+ when( request.getDavSession() ).thenReturn( new ArchivaDavSession() );
- expect( request.getRequestURI() ).andReturn( "http://localhost:8080/archiva/repository/" + INTERNAL_REPO + "/eclipse/jdtcore/maven-metadata.xml" );
+ when( request.getRequestURI() ).thenReturn( "http://localhost:8080/archiva/repository/" + INTERNAL_REPO + "/eclipse/jdtcore/maven-metadata.xml" );
response.setHeader( "Pragma", "no-cache" );
-
- expectLastCall();
-
response.setHeader( "Cache-Control", "no-cache" );
-
- expectLastCall();
-
response.setDateHeader( eq("Last-Modified"), anyLong() );
- expectLastCall();
-
- archivaConfigurationControl.replay();
- repoContentFactoryControl.replay();
- requestControl.replay();
- responseControl.replay();
resourceFactory.createResource( locator, request, response );
+ verify( request, times( 4 ) ).getMethod( );
+ verify( request, times( 3 ) ).getRemoteAddr( );
+ verify( request, times( 1 ) ).getContextPath( );
+ verify( request, times( 2 ) ).getDavSession( );
- archivaConfigurationControl.verify();
- repoContentFactoryControl.verify();
- requestControl.verify();
- responseControl.verify();
}
catch ( DavException e )
{
@@ -640,29 +618,28 @@ public class ArchivaDavResourceFactoryTest
try
{
- archivaConfigurationControl.reset();
+ reset( archivaConfiguration );
+ reset( request );
+ reset( repoFactory );
- expect( archivaConfiguration.getConfiguration() ).andReturn( config ).times( 2 );
+ when( archivaConfiguration.getConfiguration() ).thenReturn( config );
- expect( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ) ).andReturn( internalRepo );
+ when( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ) ).thenReturn( internalRepo );
- expect( request.getMethod() ).andReturn( "GET" ).times( 3 );
+ when( request.getMethod() ).thenReturn( "GET" );
- expect( request.getRemoteAddr() ).andReturn( "http://localhost:8080" ).times( 3 );
+ when( request.getRemoteAddr() ).thenReturn( "http://localhost:8080" );
- expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 2 );
+ when( request.getDavSession() ).thenReturn( new ArchivaDavSession() );
- expect( request.getContextPath() ).andReturn( "" ).times( 2 );
-
- archivaConfigurationControl.replay();
- repoContentFactoryControl.replay();
- requestControl.replay();
+ when( request.getContextPath() ).thenReturn( "" );
resourceFactory.createResource( locator, request, response );
-
- archivaConfigurationControl.verify();
- repoContentFactoryControl.verify();
- requestControl.verify();
+ verify( archivaConfiguration, times( 2 ) ).getConfiguration( );
+ verify( request, times( 3 ) ).getMethod( );
+ verify( request, times( 3 ) ).getRemoteAddr( );
+ verify( request, times( 2 ) ).getDavSession( );
+ verify( request, times( 2 ) ).getContextPath( );
fail( "A 404 error should have been thrown!" );
}
@@ -693,29 +670,30 @@ public class ArchivaDavResourceFactoryTest
try
{
- archivaConfigurationControl.reset();
+ reset( archivaConfiguration );
+ reset( request );
+ reset( repoFactory );
- expect( archivaConfiguration.getConfiguration() ).andReturn( config ).times( 2 );
+ when( archivaConfiguration.getConfiguration() ).thenReturn( config );
- expect( repoFactory.getManagedRepositoryContent( LEGACY_REPO ) ).andReturn( legacyRepo );
+ when( repoFactory.getManagedRepositoryContent( LEGACY_REPO ) ).thenReturn( legacyRepo );
- expect( request.getMethod() ).andReturn( "GET" ).times( 3 );
+ when( request.getMethod() ).thenReturn( "GET" );
- expect( request.getRemoteAddr() ).andReturn( "http://localhost:8080" ).times( 3 );
+ when( request.getRemoteAddr() ).thenReturn( "http://localhost:8080" );
- expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 2 );
+ when( request.getDavSession() ).thenReturn( new ArchivaDavSession() );
- expect( request.getContextPath() ).andReturn( "" ).times( 2 );
-
- archivaConfigurationControl.replay();
- repoContentFactoryControl.replay();
- requestControl.replay();
+ when( request.getContextPath() ).thenReturn( "" );
resourceFactory.createResource( locator, request, response );
- archivaConfigurationControl.verify();
- repoContentFactoryControl.verify();
- requestControl.verify();
+ verify( archivaConfiguration,
+ times( 2 ) ).getConfiguration( );
+ verify( request, times( 3 ) ).getMethod( );
+ verify( request, times( 3 ) ).getRemoteAddr( );
+ verify( request, times( 2 ) ).getDavSession( );
+ verify( request, times( 2 ) ).getContextPath( );
fail( "A 404 error should have been thrown!" );
}
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 36e1f1dca..bba326e65 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
@@ -43,13 +43,12 @@ import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.jackrabbit.webdav.DavSessionProvider;
-import org.easymock.EasyMock;
-import org.easymock.IMocksControl;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.mockito.Mockito;
import org.springframework.context.ApplicationContext;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
@@ -72,8 +71,11 @@ import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
-import static org.easymock.EasyMock.anyObject;
-import static org.easymock.EasyMock.eq;
+import static org.mockito.AdditionalMatchers.not;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.*;
+
/**
* RepositoryServletSecurityTest Test the flow of the authentication and authorization checks. This does not necessarily
@@ -98,12 +100,8 @@ public class RepositoryServletSecurityTest
private DavSessionProvider davSessionProvider;
- private IMocksControl servletAuthControl;
-
private ServletAuthenticator servletAuth;
- private IMocksControl httpAuthControl;
-
private HttpAuthenticator httpAuth;
private RepositoryServlet servlet;
@@ -164,13 +162,9 @@ public class RepositoryServletSecurityTest
CacheManager.getInstance().clearAll();
- servletAuthControl = EasyMock.createControl();
+ servletAuth = mock( ServletAuthenticator.class );
- servletAuth = servletAuthControl.createMock( ServletAuthenticator.class );
-
- httpAuthControl = EasyMock.createControl();
-
- httpAuth = httpAuthControl.createMock( HttpAuthenticator.class );
+ httpAuth = mock( HttpAuthenticator.class );
davSessionProvider = new ArchivaDavSessionProvider( servletAuth, httpAuth );
@@ -257,20 +251,16 @@ public class RepositoryServletSecurityTest
AuthenticationResult result = new AuthenticationResult();
- EasyMock.expect( httpAuth.getAuthenticationResult( anyObject( HttpServletRequest.class ),
- anyObject( HttpServletResponse.class ) ) ).andReturn(
+ when( httpAuth.getAuthenticationResult( any( ),
+ any( ) ) ).thenReturn(
result );
- servletAuth.isAuthenticated( EasyMock.anyObject( HttpServletRequest.class ),
- EasyMock.anyObject( AuthenticationResult.class ) );
- EasyMock.expectLastCall().andThrow( new AuthenticationException( "Authentication error" ) );
+ when(servletAuth.isAuthenticated( any( ),
+ any( ) )).thenThrow( new AuthenticationException( "Authentication error" ) );
- servletAuth.isAuthorized( "guest", "internal", ArchivaRoleConstants.OPERATION_ADD_ARTIFACT );
+ when(servletAuth.isAuthorized( "guest", "internal", ArchivaRoleConstants.OPERATION_ADD_ARTIFACT ))
+ .thenThrow( 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();
MockHttpServletRequest mockHttpServletRequest = new MockHttpServletRequest();
mockHttpServletRequest.addHeader( "User-Agent", "foo" );
mockHttpServletRequest.setMethod( "PUT" );
@@ -282,9 +272,6 @@ public class RepositoryServletSecurityTest
servlet.service( mockHttpServletRequest, mockHttpServletResponse );
- httpAuthControl.verify();
- servletAuthControl.verify();
-
assertEquals( HttpServletResponse.SC_UNAUTHORIZED, mockHttpServletResponse.getStatus() );
}
@@ -293,7 +280,6 @@ public class RepositoryServletSecurityTest
public void testPutWithInvalidUserAndGuestHasWriteAccess()
throws Exception
{
-
servlet.setDavSessionProvider( davSessionProvider );
ArchivaDavResourceFactory archivaDavResourceFactory = (ArchivaDavResourceFactory) servlet.getResourceFactory();
@@ -304,40 +290,35 @@ public class RepositoryServletSecurityTest
AuthenticationResult result = new AuthenticationResult();
- EasyMock.expect( httpAuth.getAuthenticationResult( anyObject( HttpServletRequest.class ),
- anyObject( HttpServletResponse.class ) ) ).andReturn(
+ when( httpAuth.getAuthenticationResult( any( ),
+ any( ) ) ).thenReturn(
result );
- EasyMock.expect( servletAuth.isAuthenticated( anyObject( HttpServletRequest.class ),
- anyObject( AuthenticationResult.class ) ) ).andThrow(
- new AuthenticationException( "Authentication error" ) );
- EasyMock.expect( servletAuth.isAuthorized( "guest", "internal",
- ArchivaRoleConstants.OPERATION_ADD_ARTIFACT ) ).andReturn(
+ when( servletAuth.isAuthorized( "guest", "internal",
+ ArchivaRoleConstants.OPERATION_ADD_ARTIFACT ) ).thenReturn(
true );
// ArchivaDavResourceFactory#isAuthorized()
SecuritySession session = new DefaultSecuritySession();
- EasyMock.expect( httpAuth.getAuthenticationResult( anyObject( HttpServletRequest.class ),
- anyObject( HttpServletResponse.class ) ) ).andReturn(
+ when( httpAuth.getAuthenticationResult( any( ),
+ any( ) ) ).thenReturn(
result );
- EasyMock.expect( httpAuth.getSecuritySession( anyObject( HttpSession.class ) ) ).andReturn( session );
+ when( httpAuth.getSecuritySession( any( ) ) ).thenReturn( session );
- EasyMock.expect( servletAuth.isAuthenticated( anyObject( HttpServletRequest.class ), eq( result ) ) ).andThrow(
+ when( servletAuth.isAuthenticated( any( ),
+ any( ) ) ).thenThrow(
new AuthenticationException( "Authentication error" ) );
- EasyMock.expect( httpAuth.getSessionUser( anyObject( HttpSession.class ) ) ).andReturn( null );
+ when( httpAuth.getSessionUser( any( ) ) ).thenReturn( null );
// check if guest has write access
- EasyMock.expect( servletAuth.isAuthorized( "guest", "internal",
- ArchivaRoleConstants.OPERATION_ADD_ARTIFACT ) ).andReturn(
+ when( servletAuth.isAuthorized( "guest", "internal",
+ ArchivaRoleConstants.OPERATION_ADD_ARTIFACT ) ).thenReturn(
true );
- httpAuthControl.replay();
- servletAuthControl.replay();
-
InputStream is = getClass().getResourceAsStream( "/artifact.jar" );
assertNotNull( "artifact.jar inputstream", is );
@@ -352,9 +333,6 @@ public class RepositoryServletSecurityTest
servlet.service( mockHttpServletRequest, mockHttpServletResponse );
- httpAuthControl.verify();
- servletAuthControl.verify();
-
assertEquals( HttpServletResponse.SC_CREATED, mockHttpServletResponse.getStatus() );
}
@@ -373,37 +351,34 @@ public class RepositoryServletSecurityTest
AuthenticationResult result = new AuthenticationResult();
- EasyMock.expect( httpAuth.getAuthenticationResult( anyObject( HttpServletRequest.class ),
- anyObject( HttpServletResponse.class ) ) ).andReturn(
+ when( httpAuth.getAuthenticationResult( any( ),
+ any( ) ) ).thenReturn(
result );
- EasyMock.expect( servletAuth.isAuthenticated( anyObject( HttpServletRequest.class ),
- anyObject( AuthenticationResult.class ) ) ).andReturn( true );
+ when( servletAuth.isAuthenticated( any( ),
+ any( ) ) ).thenReturn( true );
// ArchivaDavResourceFactory#isAuthorized()
SecuritySession session = new DefaultSecuritySession();
- EasyMock.expect( httpAuth.getAuthenticationResult( anyObject( HttpServletRequest.class ),
- anyObject( HttpServletResponse.class ) ) ).andReturn(
+ when( httpAuth.getAuthenticationResult( any( ),
+ any( ) ) ).thenReturn(
result );
MockHttpServletRequest mockHttpServletRequest = new MockHttpServletRequest();
- EasyMock.expect( httpAuth.getSecuritySession( mockHttpServletRequest.getSession( true ) ) ).andReturn(
+ when( httpAuth.getSecuritySession( mockHttpServletRequest.getSession( true ) ) ).thenReturn(
session );
- EasyMock.expect( httpAuth.getSessionUser( mockHttpServletRequest.getSession() ) ).andReturn( new SimpleUser() );
+ when( httpAuth.getSessionUser( mockHttpServletRequest.getSession() ) ).thenReturn( new SimpleUser() );
- EasyMock.expect( servletAuth.isAuthenticated( anyObject( HttpServletRequest.class ), eq( result ) ) ).andReturn(
+ when( servletAuth.isAuthenticated( any( ), eq( result ) ) ).thenReturn(
true );
- EasyMock.expect(
- servletAuth.isAuthorized( anyObject( HttpServletRequest.class ), eq( session ), eq( "internal" ),
- eq( ArchivaRoleConstants.OPERATION_ADD_ARTIFACT ) ) ).andThrow(
+ when(
+ servletAuth.isAuthorized( any( ), eq( session ), eq( "internal" ),
+ eq( ArchivaRoleConstants.OPERATION_ADD_ARTIFACT ) ) ).thenThrow(
new UnauthorizedException( "User not authorized" ) );
- httpAuthControl.replay();
- servletAuthControl.replay();
-
InputStream is = getClass().getResourceAsStream( "/artifact.jar" );
assertNotNull( "artifact.jar inputstream", is );
@@ -416,10 +391,6 @@ public class RepositoryServletSecurityTest
MockHttpServletResponse mockHttpServletResponse = new MockHttpServletResponse();
servlet.service( mockHttpServletRequest, mockHttpServletResponse );
-
- httpAuthControl.verify();
- servletAuthControl.verify();
-
assertEquals( HttpServletResponse.SC_UNAUTHORIZED, mockHttpServletResponse.getStatus() );
}
@@ -447,12 +418,12 @@ public class RepositoryServletSecurityTest
AuthenticationResult result = new AuthenticationResult();
- EasyMock.expect( httpAuth.getAuthenticationResult( anyObject( HttpServletRequest.class ),
- anyObject( HttpServletResponse.class ) ) ).andReturn(
+ when( httpAuth.getAuthenticationResult( any( ),
+ any( ) ) ).thenReturn(
result );
- EasyMock.expect( servletAuth.isAuthenticated( anyObject( HttpServletRequest.class ),
- anyObject( AuthenticationResult.class ) ) ).andReturn( true );
+ when( servletAuth.isAuthenticated( any( ),
+ any( ) ) ).thenReturn( true );
User user = new SimpleUser();
user.setUsername( "admin" );
@@ -460,23 +431,20 @@ public class RepositoryServletSecurityTest
// ArchivaDavResourceFactory#isAuthorized()
SecuritySession session = new DefaultSecuritySession();
- EasyMock.expect( httpAuth.getAuthenticationResult( anyObject( HttpServletRequest.class ),
- anyObject( HttpServletResponse.class ) ) ).andReturn(
+ when( httpAuth.getAuthenticationResult( any( ),
+ any( ) ) ).thenReturn(
result );
- EasyMock.expect( httpAuth.getSecuritySession( mockHttpServletRequest.getSession() ) ).andReturn( session );
+ when( httpAuth.getSecuritySession( mockHttpServletRequest.getSession() ) ).thenReturn( session );
- EasyMock.expect( httpAuth.getSessionUser( mockHttpServletRequest.getSession() ) ).andReturn( user );
+ when( httpAuth.getSessionUser( mockHttpServletRequest.getSession() ) ).thenReturn( user );
- EasyMock.expect( servletAuth.isAuthenticated( anyObject( HttpServletRequest.class ), eq( result ) ) ).andReturn(
+ when( servletAuth.isAuthenticated( any( ), eq( result ) ) ).thenReturn(
true );
- EasyMock.expect(
- servletAuth.isAuthorized( anyObject( HttpServletRequest.class ), eq( session ), eq( "internal" ),
- eq( ArchivaRoleConstants.OPERATION_ADD_ARTIFACT ) ) ).andReturn( true );
-
- httpAuthControl.replay();
- servletAuthControl.replay();
+ when(
+ servletAuth.isAuthorized( any( ), eq( session ), eq( "internal" ),
+ eq( ArchivaRoleConstants.OPERATION_ADD_ARTIFACT ) ) ).thenReturn( true );
mockHttpServletRequest.addHeader( "User-Agent", "foo" );
mockHttpServletRequest.setMethod( "PUT" );
@@ -487,10 +455,6 @@ public class RepositoryServletSecurityTest
MockHttpServletResponse mockHttpServletResponse = new MockHttpServletResponse();
servlet.service( mockHttpServletRequest, mockHttpServletResponse );
-
- httpAuthControl.verify();
- servletAuthControl.verify();
-
assertEquals( HttpServletResponse.SC_CREATED, mockHttpServletResponse.getStatus() );
assertEquals( "admin", listener.getEvents().get( 0 ).getUserId() );
@@ -519,38 +483,31 @@ public class RepositoryServletSecurityTest
AuthenticationResult result = new AuthenticationResult();
- EasyMock.expect( httpAuth.getAuthenticationResult( anyObject( HttpServletRequest.class ),
- anyObject( HttpServletResponse.class ) ) ).andReturn(
+ when( httpAuth.getAuthenticationResult( any( ),
+ any( ) ) ).thenReturn(
result );
- EasyMock.expect( servletAuth.isAuthenticated( anyObject( HttpServletRequest.class ),
- anyObject( AuthenticationResult.class ) ) ).andThrow(
- new AuthenticationException( "Authentication error" ) );
- EasyMock.expect( servletAuth.isAuthorized( "guest", "internal",
- ArchivaRoleConstants.OPERATION_READ_REPOSITORY ) ).andReturn(
+ when( servletAuth.isAuthorized( "guest", "internal",
+ ArchivaRoleConstants.OPERATION_READ_REPOSITORY ) ).thenReturn(
true );
// ArchivaDavResourceFactory#isAuthorized()
SecuritySession session = new DefaultSecuritySession();
- EasyMock.expect( httpAuth.getAuthenticationResult( anyObject( HttpServletRequest.class ),
- anyObject( HttpServletResponse.class ) ) ).andReturn(
- result );
+ when( httpAuth.getSecuritySession( any( ) ) ).thenReturn( session );
- EasyMock.expect( httpAuth.getSecuritySession( anyObject( HttpSession.class ) ) ).andReturn( session );
+ when( httpAuth.getSessionUser( any( ) ) ).thenReturn( null );
- EasyMock.expect( httpAuth.getSessionUser( anyObject( HttpSession.class ) ) ).andReturn( null );
-
- EasyMock.expect( servletAuth.isAuthenticated( anyObject( HttpServletRequest.class ), eq( result ) ) ).andReturn(
+ when( servletAuth.isAuthenticated( any( ), eq( result ) ) ).thenReturn(
true );
+ when( servletAuth.isAuthenticated( any( ),
+ not(eq(result)) ) ).thenThrow(
+ new AuthenticationException( "Authentication error" ) );
- EasyMock.expect(
- servletAuth.isAuthorized( anyObject( HttpServletRequest.class ), eq( session ), eq( "internal" ),
- eq( ArchivaRoleConstants.OPERATION_READ_REPOSITORY ) ) ).andReturn( true );
- httpAuthControl.replay();
- servletAuthControl.replay();
-
+ when(
+ servletAuth.isAuthorized( any( ), eq( session ), eq( "internal" ),
+ eq( ArchivaRoleConstants.OPERATION_READ_REPOSITORY ) ) ).thenReturn( true );
MockHttpServletRequest mockHttpServletRequest = new MockHttpServletRequest();
mockHttpServletRequest.addHeader( "User-Agent", "foo" );
mockHttpServletRequest.setMethod( "GET" );
@@ -559,10 +516,6 @@ public class RepositoryServletSecurityTest
MockHttpServletResponse mockHttpServletResponse = new MockHttpServletResponse();
servlet.service( mockHttpServletRequest, mockHttpServletResponse );
-
- httpAuthControl.verify();
- servletAuthControl.verify();
-
assertEquals( HttpServletResponse.SC_OK, mockHttpServletResponse.getStatus() );
assertEquals( "Expected file contents", expectedArtifactContents, mockHttpServletResponse.getContentAsString() );
@@ -585,20 +538,17 @@ public class RepositoryServletSecurityTest
AuthenticationResult result = new AuthenticationResult();
- EasyMock.expect( httpAuth.getAuthenticationResult( anyObject( HttpServletRequest.class ),
- anyObject( HttpServletResponse.class ) ) ).andReturn(
+ when( httpAuth.getAuthenticationResult( any( ),
+ any( ) ) ).thenReturn(
result );
- EasyMock.expect( servletAuth.isAuthenticated( anyObject( HttpServletRequest.class ),
- anyObject( AuthenticationResult.class ) ) ).andThrow(
+ when( servletAuth.isAuthenticated( any( ),
+ any( ) ) ).thenThrow(
new AuthenticationException( "Authentication error" ) );
- EasyMock.expect( servletAuth.isAuthorized( "guest", "internal",
- ArchivaRoleConstants.OPERATION_READ_REPOSITORY ) ).andReturn(
+ when( servletAuth.isAuthorized( "guest", "internal",
+ ArchivaRoleConstants.OPERATION_READ_REPOSITORY ) ).thenReturn(
false );
- httpAuthControl.replay();
- servletAuthControl.replay();
-
MockHttpServletRequest mockHttpServletRequest = new MockHttpServletRequest();
mockHttpServletRequest.addHeader( "User-Agent", "foo" );
mockHttpServletRequest.setMethod( "GET" );
@@ -607,10 +557,6 @@ public class RepositoryServletSecurityTest
MockHttpServletResponse mockHttpServletResponse = new MockHttpServletResponse();
servlet.service( mockHttpServletRequest, mockHttpServletResponse );
-
- httpAuthControl.verify();
- servletAuthControl.verify();
-
assertEquals( HttpServletResponse.SC_UNAUTHORIZED, mockHttpServletResponse.getStatus() );
}
@@ -637,32 +583,29 @@ public class RepositoryServletSecurityTest
AuthenticationResult result = new AuthenticationResult();
- EasyMock.expect( httpAuth.getAuthenticationResult( anyObject( HttpServletRequest.class ),
- anyObject( HttpServletResponse.class ) ) ).andReturn(
+ when( httpAuth.getAuthenticationResult( any( ),
+ any( ) ) ).thenReturn(
result );
- EasyMock.expect( servletAuth.isAuthenticated( anyObject( HttpServletRequest.class ),
- anyObject( AuthenticationResult.class ) ) ).andReturn( true );
+ when( servletAuth.isAuthenticated( any( ),
+ any( ) ) ).thenReturn( true );
// ArchivaDavResourceFactory#isAuthorized()
SecuritySession session = new DefaultSecuritySession();
- EasyMock.expect( httpAuth.getAuthenticationResult( anyObject( HttpServletRequest.class ),
- anyObject( HttpServletResponse.class ) ) ).andReturn(
+ when( httpAuth.getAuthenticationResult( any( ),
+ any( ) ) ).thenReturn(
result );
- EasyMock.expect( httpAuth.getSecuritySession( anyObject( HttpSession.class ) ) ).andReturn( session );
+ when( httpAuth.getSecuritySession( any( ) ) ).thenReturn( session );
- EasyMock.expect( httpAuth.getSessionUser( anyObject( HttpSession.class ) ) ).andReturn( new SimpleUser() );
+ when( httpAuth.getSessionUser( any( ) ) ).thenReturn( new SimpleUser() );
- EasyMock.expect( servletAuth.isAuthenticated( anyObject( HttpServletRequest.class ), eq( result ) ) ).andReturn(
+ when( servletAuth.isAuthenticated( any( ), eq( result ) ) ).thenReturn(
true );
- EasyMock.expect(
- servletAuth.isAuthorized( anyObject( HttpServletRequest.class ), eq( session ), eq( "internal" ),
- eq( ArchivaRoleConstants.OPERATION_READ_REPOSITORY ) ) ).andReturn( true );
-
- httpAuthControl.replay();
- servletAuthControl.replay();
+ when(
+ servletAuth.isAuthorized( any( ), eq( session ), eq( "internal" ),
+ eq( ArchivaRoleConstants.OPERATION_READ_REPOSITORY ) ) ).thenReturn( true );
MockHttpServletRequest mockHttpServletRequest = new MockHttpServletRequest();
mockHttpServletRequest.addHeader( "User-Agent", "foo" );
@@ -672,10 +615,6 @@ public class RepositoryServletSecurityTest
MockHttpServletResponse mockHttpServletResponse = new MockHttpServletResponse();
servlet.service( mockHttpServletRequest, mockHttpServletResponse );
-
- httpAuthControl.verify();
- servletAuthControl.verify();
-
assertEquals( HttpServletResponse.SC_OK, mockHttpServletResponse.getStatus() );
assertEquals( "Expected file contents", expectedArtifactContents, mockHttpServletResponse.getContentAsString() );
}
@@ -703,34 +642,31 @@ public class RepositoryServletSecurityTest
AuthenticationResult result = new AuthenticationResult();
- EasyMock.expect( httpAuth.getAuthenticationResult( anyObject( HttpServletRequest.class ),
- anyObject( HttpServletResponse.class ) ) ).andReturn(
+ when( httpAuth.getAuthenticationResult( any( ),
+ any( ) ) ).thenReturn(
result );
- EasyMock.expect( servletAuth.isAuthenticated( anyObject( HttpServletRequest.class ),
- anyObject( AuthenticationResult.class ) ) ).andReturn( true );
+ when( servletAuth.isAuthenticated( any( ),
+ any( ) ) ).thenReturn( true );
// ArchivaDavResourceFactory#isAuthorized()
SecuritySession session = new DefaultSecuritySession();
- EasyMock.expect( httpAuth.getAuthenticationResult( anyObject( HttpServletRequest.class ),
- anyObject( HttpServletResponse.class ) ) ).andReturn(
+ when( httpAuth.getAuthenticationResult( any( ),
+ any( ) ) ).thenReturn(
result );
- EasyMock.expect( httpAuth.getSecuritySession( anyObject( HttpSession.class ) ) ).andReturn( session );
+ when( httpAuth.getSecuritySession( any( ) ) ).thenReturn( session );
- EasyMock.expect( httpAuth.getSessionUser( anyObject( HttpSession.class ) ) ).andReturn( new SimpleUser() );
+ when( httpAuth.getSessionUser( any( ) ) ).thenReturn( new SimpleUser() );
- EasyMock.expect( servletAuth.isAuthenticated( anyObject( HttpServletRequest.class ), eq( result ) ) ).andReturn(
+ when( servletAuth.isAuthenticated( any( ), eq( result ) ) ).thenReturn(
true );
- EasyMock.expect(
- servletAuth.isAuthorized( anyObject( HttpServletRequest.class ), eq( session ), eq( "internal" ),
- eq( ArchivaRoleConstants.OPERATION_READ_REPOSITORY ) ) ).andThrow(
+ when(
+ servletAuth.isAuthorized( any( ), eq( session ), eq( "internal" ),
+ eq( ArchivaRoleConstants.OPERATION_READ_REPOSITORY ) ) ).thenThrow(
new UnauthorizedException( "User not authorized to read repository." ) );
- httpAuthControl.replay();
- servletAuthControl.replay();
-
MockHttpServletRequest mockHttpServletRequest = new MockHttpServletRequest();
mockHttpServletRequest.addHeader( "User-Agent", "foo" );
mockHttpServletRequest.setMethod( "GET" );
@@ -740,10 +676,6 @@ public class RepositoryServletSecurityTest
MockHttpServletResponse mockHttpServletResponse = new MockHttpServletResponse();
servlet.service( mockHttpServletRequest, mockHttpServletResponse );
-
- httpAuthControl.verify();
- servletAuthControl.verify();
-
assertEquals( HttpServletResponse.SC_UNAUTHORIZED, mockHttpServletResponse.getStatus() );
}
diff --git a/archiva-modules/metadata/metadata-store-provider/metadata-store-cassandra/pom.xml b/archiva-modules/metadata/metadata-store-provider/metadata-store-cassandra/pom.xml
index 58bb31b62..c5be4d834 100644
--- a/archiva-modules/metadata/metadata-store-provider/metadata-store-cassandra/pom.xml
+++ b/archiva-modules/metadata/metadata-store-provider/metadata-store-cassandra/pom.xml
@@ -31,7 +31,7 @@
${project.parent.parent.basedir}
- 3.11.10
+ 3.11.11
4.13.0
@@ -139,8 +139,8 @@
- org.easymock
- easymock
+ org.mockito
+ mockito-core
test
@@ -213,7 +213,7 @@
org.codehaus.mojo
cassandra-maven-plugin
- 3.6
+ 3.7-SNAPSHOT
start-cassandra
@@ -334,4 +334,15 @@ num_tokens: 1
+
+
+ jdk9+
+
+ [1.9,)
+
+
+ true
+
+
+
diff --git a/archiva-modules/metadata/metadata-store-provider/metadata-store-cassandra/src/test/java/org/apache/archiva/metadata/repository/cassandra/CassandraMetadataRepositoryTest.java b/archiva-modules/metadata/metadata-store-provider/metadata-store-cassandra/src/test/java/org/apache/archiva/metadata/repository/cassandra/CassandraMetadataRepositoryTest.java
index a6c4bf0fe..c1e07a07a 100644
--- a/archiva-modules/metadata/metadata-store-provider/metadata-store-cassandra/src/test/java/org/apache/archiva/metadata/repository/cassandra/CassandraMetadataRepositoryTest.java
+++ b/archiva-modules/metadata/metadata-store-provider/metadata-store-cassandra/src/test/java/org/apache/archiva/metadata/repository/cassandra/CassandraMetadataRepositoryTest.java
@@ -27,8 +27,6 @@ import org.apache.archiva.metadata.repository.MetadataService;
import org.apache.archiva.metadata.repository.RepositorySession;
import org.apache.archiva.metadata.repository.RepositorySessionFactory;
import org.apache.archiva.metadata.repository.cassandra.model.ProjectVersionMetadataModel;
-import org.easymock.EasyMock;
-import org.easymock.IMocksControl;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -50,8 +48,9 @@ import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;
import static com.datastax.oss.driver.api.querybuilder.QueryBuilder.truncate;
-import static com.datastax.oss.driver.api.querybuilder.SchemaBuilder.dropTable;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
/**
* @author Olivier Lamy
@@ -67,10 +66,8 @@ public class CassandraMetadataRepositoryTest
CassandraMetadataRepository cmr;
- IMocksControl sessionFactoryControl;
RepositorySessionFactory sessionFactory;
- IMocksControl sessionControl;
RepositorySession session;
long cTime;
@@ -111,14 +108,10 @@ public class CassandraMetadataRepositoryTest
this.cmr = new CassandraMetadataRepository( metadataService, cassandraArchivaManager );
- sessionFactoryControl = EasyMock.createControl( );
- sessionFactory = sessionFactoryControl.createMock( RepositorySessionFactory.class );
- sessionControl = EasyMock.createControl( );
- session = sessionControl.createMock( RepositorySession.class );
+ sessionFactory = mock( RepositorySessionFactory.class );
+ session = mock( RepositorySession.class );
- EasyMock.expect( sessionFactory.createSession( ) ).andStubReturn( session );
-
- sessionFactoryControl.replay();
+ when( sessionFactory.createSession( ) ).thenReturn( session );
if (!clearedTables.get())
{
diff --git a/archiva-modules/metadata/metadata-store-provider/metadata-store-cassandra/src/test/java/org/apache/archiva/metadata/repository/cassandra/RepositoriesNamespaceTest.java b/archiva-modules/metadata/metadata-store-provider/metadata-store-cassandra/src/test/java/org/apache/archiva/metadata/repository/cassandra/RepositoriesNamespaceTest.java
index c67e4d348..7bcc68758 100644
--- a/archiva-modules/metadata/metadata-store-provider/metadata-store-cassandra/src/test/java/org/apache/archiva/metadata/repository/cassandra/RepositoriesNamespaceTest.java
+++ b/archiva-modules/metadata/metadata-store-provider/metadata-store-cassandra/src/test/java/org/apache/archiva/metadata/repository/cassandra/RepositoriesNamespaceTest.java
@@ -22,7 +22,6 @@ package org.apache.archiva.metadata.repository.cassandra;
import org.apache.archiva.metadata.model.ProjectMetadata;
import org.apache.archiva.metadata.repository.cassandra.model.Namespace;
import org.apache.archiva.metadata.repository.cassandra.model.Repository;
-import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
diff --git a/archiva-modules/plugins/audit/pom.xml b/archiva-modules/plugins/audit/pom.xml
index c3eea17de..af5c0b949 100644
--- a/archiva-modules/plugins/audit/pom.xml
+++ b/archiva-modules/plugins/audit/pom.xml
@@ -55,14 +55,14 @@
- org.apache.archiva
- archiva-test-utils
- ${project.version}
+ org.mockito
+ mockito-core
test
- org.easymock
- easymock
+ org.apache.archiva
+ archiva-test-utils
+ ${project.version}
test
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 4622b1b3f..f0cb5d2cc 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
@@ -25,10 +25,7 @@ import org.apache.archiva.metadata.model.facets.AuditEvent;
import org.apache.archiva.metadata.repository.MetadataRepository;
import org.apache.archiva.metadata.repository.RepositorySession;
import org.apache.archiva.metadata.repository.RepositorySessionFactory;
-import org.apache.archiva.repository.Repository;
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;
@@ -45,14 +42,15 @@ import java.util.List;
import java.util.Map;
import java.util.TimeZone;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
@RunWith(ArchivaBlockJUnit4ClassRunner.class)
public class AuditManagerTest
extends TestCase
{
private DefaultAuditManager auditManager;
- private IMocksControl metadataRepositoryControl;
-
private MetadataRepository metadataRepository;
private RepositorySessionFactory repositorySessionFactory;
@@ -74,8 +72,6 @@ public class AuditManagerTest
private static final SimpleDateFormat TIMESTAMP_FORMAT = createTimestampFormat();
private static final DecimalFormat MILLIS_FORMAT = new DecimalFormat( "000" );
- private IMocksControl factoryControl;
- private IMocksControl sessionControl;
private static SimpleDateFormat createTimestampFormat()
{
@@ -93,14 +89,11 @@ public class AuditManagerTest
auditManager = new DefaultAuditManager();
- metadataRepositoryControl = EasyMock.createControl();
- metadataRepository = metadataRepositoryControl.createMock( MetadataRepository.class );
+ metadataRepository = mock( MetadataRepository.class );
- factoryControl = EasyMock.createControl();
- repositorySessionFactory = factoryControl.createMock(RepositorySessionFactory.class);
+ repositorySessionFactory = mock(RepositorySessionFactory.class);
- sessionControl = EasyMock.createControl( );
- session = sessionControl.createMock( RepositorySession.class );
+ session = mock( RepositorySession.class );
auditManager.setRepositorySessionFactory( repositorySessionFactory );
@@ -121,19 +114,15 @@ public class AuditManagerTest
expectedEvents.add( event );
}
- sessionControl.reset();
- factoryControl.reset();
- EasyMock.expect( repositorySessionFactory.createSession() ).andStubReturn( session );
- factoryControl.replay();
- EasyMock.expect(metadataRepository.getMetadataFacets(session, TEST_REPO_ID, AuditEvent.FACET_ID)).andReturn(
+ when( repositorySessionFactory.createSession() ).thenReturn( session );
+ when(metadataRepository.getMetadataFacets(session, TEST_REPO_ID, AuditEvent.FACET_ID)).thenReturn(
getEventNames(expectedEvents));
for (AuditEvent event : expectedEvents.subList(1, expectedEvents.size())) {
- EasyMock.expect(
- metadataRepository.getMetadataFacet(session, TEST_REPO_ID, AuditEvent.FACET_ID, event.getName())).andReturn(
+ when(
+ metadataRepository.getMetadataFacet(session, TEST_REPO_ID, AuditEvent.FACET_ID, event.getName())).thenReturn(
event);
}
- metadataRepositoryControl.replay();
List events =
auditManager.getMostRecentAuditEvents( metadataRepository, Collections.singletonList( TEST_REPO_ID ) );
@@ -147,7 +136,6 @@ public class AuditManagerTest
expectedTimestampCounter--;
}
- metadataRepositoryControl.verify();
}
@Test
@@ -161,18 +149,14 @@ public class AuditManagerTest
expectedEvents.add( createEvent( AUDIT_EVENT_BASE + MILLIS_FORMAT.format( i ) ) );
}
- sessionControl.reset();
- factoryControl.reset();
- EasyMock.expect( repositorySessionFactory.createSession() ).andStubReturn( session );
- factoryControl.replay();
- EasyMock.expect(metadataRepository.getMetadataFacets(session, TEST_REPO_ID, AuditEvent.FACET_ID)).andReturn(
+ when( repositorySessionFactory.createSession() ).thenReturn( session );
+ when(metadataRepository.getMetadataFacets(session, TEST_REPO_ID, AuditEvent.FACET_ID)).thenReturn(
getEventNames(expectedEvents));
for (AuditEvent event : expectedEvents) {
- EasyMock.expect(
- metadataRepository.getMetadataFacet(session, TEST_REPO_ID, AuditEvent.FACET_ID, event.getName())).andReturn(
+ when(
+ metadataRepository.getMetadataFacet(session, TEST_REPO_ID, AuditEvent.FACET_ID, event.getName())).thenReturn(
event);
}
- metadataRepositoryControl.replay();
List events =
auditManager.getMostRecentAuditEvents( metadataRepository, Collections.singletonList( TEST_REPO_ID ) );
@@ -186,7 +170,6 @@ public class AuditManagerTest
expectedTimestampCounter--;
}
- metadataRepositoryControl.verify();
}
@Test
@@ -194,10 +177,10 @@ public class AuditManagerTest
throws Exception
{
int numEvents = 11;
- Map> eventNames = new LinkedHashMap>();
+ Map> eventNames = new LinkedHashMap<>( );
List events = new ArrayList<>();
- eventNames.put( TEST_REPO_ID, new ArrayList() );
- eventNames.put( TEST_REPO_ID_2, new ArrayList() );
+ eventNames.put( TEST_REPO_ID, new ArrayList<>( ) );
+ eventNames.put( TEST_REPO_ID_2, new ArrayList<>( ) );
for ( int i = 0; i < numEvents; i++ )
{
String repositoryId = i % 2 == 0 ? TEST_REPO_ID : TEST_REPO_ID_2;
@@ -206,20 +189,16 @@ public class AuditManagerTest
events.add( event );
eventNames.get( repositoryId ).add( event.getName() );
}
- sessionControl.reset();
- factoryControl.reset();
- EasyMock.expect( repositorySessionFactory.createSession() ).andStubReturn( session );
- factoryControl.replay();
- EasyMock.expect(metadataRepository.getMetadataFacets(session, TEST_REPO_ID, AuditEvent.FACET_ID)).andReturn(
+ when( repositorySessionFactory.createSession() ).thenReturn( session );
+ when(metadataRepository.getMetadataFacets(session, TEST_REPO_ID, AuditEvent.FACET_ID)).thenReturn(
eventNames.get(TEST_REPO_ID));
- EasyMock.expect(metadataRepository.getMetadataFacets(session, TEST_REPO_ID_2, AuditEvent.FACET_ID)).andReturn(
+ when(metadataRepository.getMetadataFacets(session, TEST_REPO_ID_2, AuditEvent.FACET_ID)).thenReturn(
eventNames.get(TEST_REPO_ID_2));
for (AuditEvent event : events.subList(1, events.size())) {
- EasyMock.expect(metadataRepository.getMetadataFacet(session, event.getRepositoryId(),
- AuditEvent.FACET_ID, event.getName())).andReturn(event);
+ when(metadataRepository.getMetadataFacet(session, event.getRepositoryId(),
+ AuditEvent.FACET_ID, event.getName())).thenReturn(event);
}
- metadataRepositoryControl.replay();
events =
auditManager.getMostRecentAuditEvents( metadataRepository, Arrays.asList( TEST_REPO_ID, TEST_REPO_ID_2 ) );
@@ -234,7 +213,6 @@ public class AuditManagerTest
expectedTimestampCounter--;
}
- metadataRepositoryControl.verify();
}
@Test
@@ -242,18 +220,13 @@ public class AuditManagerTest
throws Exception
{
- sessionControl.reset();
- factoryControl.reset();
- EasyMock.expect( repositorySessionFactory.createSession() ).andStubReturn( session );
- factoryControl.replay();
- EasyMock.expect(metadataRepository.getMetadataFacets(session, TEST_REPO_ID, AuditEvent.FACET_ID)).andReturn(
- Collections.emptyList());
- metadataRepositoryControl.replay();
+ when( repositorySessionFactory.createSession() ).thenReturn( session );
+ when(metadataRepository.getMetadataFacets(session, TEST_REPO_ID, AuditEvent.FACET_ID)).thenReturn(
+ Collections.emptyList());
assertTrue( auditManager.getMostRecentAuditEvents( metadataRepository,
Collections.singletonList( TEST_REPO_ID ) ).isEmpty() );
- metadataRepositoryControl.verify();
}
@Test
@@ -263,17 +236,12 @@ public class AuditManagerTest
{
AuditEvent event = createEvent( new Date() );
- sessionControl.reset();
- factoryControl.reset();
- EasyMock.expect( repositorySessionFactory.createSession() ).andStubReturn( session );
- factoryControl.replay();
+ when( repositorySessionFactory.createSession() ).thenReturn( session );
metadataRepository.addMetadataFacet(session, TEST_REPO_ID, event);
- metadataRepositoryControl.replay();
auditManager.addAuditEvent( metadataRepository, event );
- metadataRepositoryControl.verify();
}
@Test
@@ -285,11 +253,7 @@ public class AuditManagerTest
// should just be ignored
- metadataRepositoryControl.replay();
-
auditManager.addAuditEvent( metadataRepository, event );
-
- metadataRepositoryControl.verify();
}
@Test
@@ -298,18 +262,12 @@ public class AuditManagerTest
{
- sessionControl.reset();
- factoryControl.reset();
- EasyMock.expect( repositorySessionFactory.createSession() ).andStubReturn( session );
- factoryControl.replay();
+ when( repositorySessionFactory.createSession() ).thenReturn( session );
metadataRepository.removeMetadataFacets(session, TEST_REPO_ID, AuditEvent.FACET_ID);
- metadataRepositoryControl.replay();
-
auditManager.deleteAuditEvents( metadataRepository, TEST_REPO_ID );
- metadataRepositoryControl.verify();
}
@Test
@@ -323,19 +281,13 @@ public class AuditManagerTest
Date expectedTimestamp = new Date( current.getTime() - 3000 );
AuditEvent expectedEvent = createEvent( expectedTimestamp );
AuditEvent event3 = createEvent( new Date( current.getTime() - 1000 ) );
- sessionControl.reset();
- factoryControl.reset();
- EasyMock.expect( repositorySessionFactory.createSession() ).andStubReturn( session );
- factoryControl.replay();
-
- EasyMock.expect(metadataRepository.getMetadataFacets(session, TEST_REPO_ID, AuditEvent.FACET_ID)).andReturn(
+ when( repositorySessionFactory.createSession() ).thenReturn( session );
+ when(metadataRepository.getMetadataFacets(session, TEST_REPO_ID, AuditEvent.FACET_ID)).thenReturn(
Arrays.asList(event1.getName(), expectedEvent.getName(), event3.getName()));
// only match the middle one
- EasyMock.expect(metadataRepository.getMetadataFacet(session, TEST_REPO_ID,
- AuditEvent.FACET_ID, expectedEvent.getName())).andReturn(expectedEvent);
-
- metadataRepositoryControl.replay();
+ when(metadataRepository.getMetadataFacet(session, TEST_REPO_ID,
+ AuditEvent.FACET_ID, expectedEvent.getName())).thenReturn(expectedEvent);
List events =
auditManager.getAuditEventsInRange( metadataRepository, Collections.singletonList( TEST_REPO_ID ),
@@ -345,7 +297,6 @@ public class AuditManagerTest
assertEquals( 1, events.size() );
assertTestEvent( events.get( 0 ), TIMESTAMP_FORMAT.format( expectedTimestamp ), expectedEvent.getResource() );
- metadataRepositoryControl.verify();
}
@Test
@@ -360,19 +311,14 @@ public class AuditManagerTest
Date ts3 = new Date( current.getTime() - 1000 );
AuditEvent expectedEvent3 = createEvent( ts3 );
- sessionControl.reset();
- factoryControl.reset();
- EasyMock.expect( repositorySessionFactory.createSession() ).andStubReturn( session );
- factoryControl.replay();
-
- EasyMock.expect(metadataRepository.getMetadataFacets(session, TEST_REPO_ID, AuditEvent.FACET_ID)).andReturn(
+ when( repositorySessionFactory.createSession() ).thenReturn( session );
+ when(metadataRepository.getMetadataFacets(session, TEST_REPO_ID, AuditEvent.FACET_ID)).thenReturn(
Arrays.asList(event1.getName(), expectedEvent2.getName(), expectedEvent3.getName()));
- EasyMock.expect(metadataRepository.getMetadataFacet(session, TEST_REPO_ID,
- AuditEvent.FACET_ID, expectedEvent2.getName())).andReturn(expectedEvent2);
- EasyMock.expect(metadataRepository.getMetadataFacet(session, TEST_REPO_ID,
- AuditEvent.FACET_ID, expectedEvent3.getName())).andReturn(expectedEvent3);
- metadataRepositoryControl.replay();
+ when(metadataRepository.getMetadataFacet(session, TEST_REPO_ID,
+ AuditEvent.FACET_ID, expectedEvent2.getName())).thenReturn(expectedEvent2);
+ when(metadataRepository.getMetadataFacet(session, TEST_REPO_ID,
+ AuditEvent.FACET_ID, expectedEvent3.getName())).thenReturn(expectedEvent3);
List events =
auditManager.getAuditEventsInRange( metadataRepository, Collections.singletonList( TEST_REPO_ID ),
@@ -381,8 +327,6 @@ public class AuditManagerTest
assertEquals( 2, events.size() );
assertTestEvent( events.get( 0 ), TIMESTAMP_FORMAT.format( ts3 ), expectedEvent3.getResource() );
assertTestEvent( events.get( 1 ), TIMESTAMP_FORMAT.format( expectedTimestamp ), expectedEvent2.getResource() );
-
- metadataRepositoryControl.verify();
}
@Test
@@ -397,20 +341,16 @@ public class AuditManagerTest
AuditEvent expectedEvent2 = createEvent( expectedTimestamp );
AuditEvent event3 = createEvent( new Date( current.getTime() - 1000 ) );
- sessionControl.reset();
- factoryControl.reset();
- EasyMock.expect( repositorySessionFactory.createSession() ).andStubReturn( session );
- factoryControl.replay();
+ when( repositorySessionFactory.createSession() ).thenReturn( session );
- EasyMock.expect(metadataRepository.getMetadataFacets(session, TEST_REPO_ID, AuditEvent.FACET_ID)).andReturn(
+ when(metadataRepository.getMetadataFacets(session, TEST_REPO_ID, AuditEvent.FACET_ID)).thenReturn(
Arrays.asList(expectedEvent1.getName(), expectedEvent2.getName(), event3.getName()));
- EasyMock.expect(metadataRepository.getMetadataFacet(session, TEST_REPO_ID,
- AuditEvent.FACET_ID, expectedEvent1.getName())).andReturn(expectedEvent1);
+ when(metadataRepository.getMetadataFacet(session, TEST_REPO_ID,
+ AuditEvent.FACET_ID, expectedEvent1.getName())).thenReturn(expectedEvent1);
- EasyMock.expect(metadataRepository.getMetadataFacet(session, TEST_REPO_ID,
- AuditEvent.FACET_ID, expectedEvent2.getName())).andReturn(expectedEvent2);
- metadataRepositoryControl.replay();
+ when(metadataRepository.getMetadataFacet(session, TEST_REPO_ID,
+ AuditEvent.FACET_ID, expectedEvent2.getName())).thenReturn(expectedEvent2);
List events =
auditManager.getAuditEventsInRange( metadataRepository, Collections.singletonList( TEST_REPO_ID ),
@@ -420,8 +360,6 @@ public class AuditManagerTest
assertEquals( 2, events.size() );
assertTestEvent( events.get( 0 ), TIMESTAMP_FORMAT.format( expectedTimestamp ), expectedEvent2.getResource() );
assertTestEvent( events.get( 1 ), TIMESTAMP_FORMAT.format( ts1 ), expectedEvent1.getResource() );
-
- metadataRepositoryControl.verify();
}
@Test
@@ -437,22 +375,18 @@ public class AuditManagerTest
Date ts3 = new Date( current.getTime() - 1000 );
AuditEvent expectedEvent3 = createEvent( ts3 );
- sessionControl.reset();
- factoryControl.reset();
- EasyMock.expect( repositorySessionFactory.createSession() ).andStubReturn( session );
- factoryControl.replay();
- EasyMock.expect(metadataRepository.getMetadataFacets(session, TEST_REPO_ID, AuditEvent.FACET_ID)).andReturn(
+ when( repositorySessionFactory.createSession() ).thenReturn( session );
+ when(metadataRepository.getMetadataFacets(session, TEST_REPO_ID, AuditEvent.FACET_ID)).thenReturn(
Arrays.asList(expectedEvent1.getName(), expectedEvent2.getName(), expectedEvent3.getName()));
- EasyMock.expect(metadataRepository.getMetadataFacet(session, TEST_REPO_ID,
- AuditEvent.FACET_ID, expectedEvent1.getName())).andReturn(expectedEvent1);
+ when(metadataRepository.getMetadataFacet(session, TEST_REPO_ID,
+ AuditEvent.FACET_ID, expectedEvent1.getName())).thenReturn(expectedEvent1);
- EasyMock.expect(metadataRepository.getMetadataFacet(session, TEST_REPO_ID,
- AuditEvent.FACET_ID, expectedEvent2.getName())).andReturn(expectedEvent2);
+ when(metadataRepository.getMetadataFacet(session, TEST_REPO_ID,
+ AuditEvent.FACET_ID, expectedEvent2.getName())).thenReturn(expectedEvent2);
- EasyMock.expect(metadataRepository.getMetadataFacet(session, TEST_REPO_ID,
- AuditEvent.FACET_ID, expectedEvent3.getName())).andReturn(expectedEvent3);
- metadataRepositoryControl.replay();
+ when(metadataRepository.getMetadataFacet(session, TEST_REPO_ID,
+ AuditEvent.FACET_ID, expectedEvent3.getName())).thenReturn(expectedEvent3);
List events =
auditManager.getAuditEventsInRange( metadataRepository, Collections.singletonList( TEST_REPO_ID ),
@@ -463,7 +397,6 @@ public class AuditManagerTest
assertTestEvent( events.get( 1 ), TIMESTAMP_FORMAT.format( expectedTimestamp ), expectedEvent2.getResource() );
assertTestEvent( events.get( 2 ), TIMESTAMP_FORMAT.format( ts1 ), expectedEvent1.getResource() );
- metadataRepositoryControl.verify();
}
@Test
@@ -480,23 +413,19 @@ public class AuditManagerTest
Date ts3 = new Date( current.getTime() - 1000 );
AuditEvent expectedEvent3 = createEvent( ts3 );
- sessionControl.reset();
- factoryControl.reset();
- EasyMock.expect( repositorySessionFactory.createSession() ).andStubReturn( session );
- factoryControl.replay();
- EasyMock.expect(metadataRepository.getMetadataFacets(session, TEST_REPO_ID, AuditEvent.FACET_ID)).andReturn(
+ when( repositorySessionFactory.createSession() ).thenReturn( session );
+ when(metadataRepository.getMetadataFacets(session, TEST_REPO_ID, AuditEvent.FACET_ID)).thenReturn(
Arrays.asList(expectedEvent1.getName(), expectedEvent2.getName(), expectedEvent3.getName()));
- EasyMock.expect(metadataRepository.getMetadataFacet(session, TEST_REPO_ID,
- AuditEvent.FACET_ID, expectedEvent1.getName())).andReturn(expectedEvent1);
+ when(metadataRepository.getMetadataFacet(session, TEST_REPO_ID,
+ AuditEvent.FACET_ID, expectedEvent1.getName())).thenReturn(expectedEvent1);
- EasyMock.expect(metadataRepository.getMetadataFacet(session, TEST_REPO_ID,
- AuditEvent.FACET_ID, expectedEvent2.getName())).andReturn(expectedEvent2);
+ when(metadataRepository.getMetadataFacet(session, TEST_REPO_ID,
+ AuditEvent.FACET_ID, expectedEvent2.getName())).thenReturn(expectedEvent2);
- EasyMock.expect(metadataRepository.getMetadataFacet(session, TEST_REPO_ID,
- AuditEvent.FACET_ID, expectedEvent3.getName())).andReturn(expectedEvent3);
- metadataRepositoryControl.replay();
+ when(metadataRepository.getMetadataFacet(session, TEST_REPO_ID,
+ AuditEvent.FACET_ID, expectedEvent3.getName())).thenReturn(expectedEvent3);
List events =
auditManager.getAuditEventsInRange( metadataRepository, Collections.singletonList( TEST_REPO_ID ),
@@ -506,7 +435,6 @@ public class AuditManagerTest
assertTestEvent( events.get( 0 ), TIMESTAMP_FORMAT.format( ts3 ), expectedEvent3.getResource() );
assertTestEvent( events.get( 1 ), TIMESTAMP_FORMAT.format( ts1 ), expectedEvent1.getResource() );
- metadataRepositoryControl.verify();
}
@Test
@@ -521,21 +449,17 @@ public class AuditManagerTest
expectedEvent2.setResource( "different-resource" );
AuditEvent expectedEvent3 = createEvent( new Date( current.getTime() - 1000 ) );
- sessionControl.reset();
- factoryControl.reset();
- EasyMock.expect( repositorySessionFactory.createSession() ).andStubReturn( session );
- factoryControl.replay();
- EasyMock.expect(metadataRepository.getMetadataFacets(session, TEST_REPO_ID, AuditEvent.FACET_ID)).andReturn(
+ when( repositorySessionFactory.createSession() ).thenReturn( session );
+ when(metadataRepository.getMetadataFacets(session, TEST_REPO_ID, AuditEvent.FACET_ID)).thenReturn(
Arrays.asList(expectedEvent1.getName(), expectedEvent2.getName(), expectedEvent3.getName()));
- EasyMock.expect(metadataRepository.getMetadataFacet(session, TEST_REPO_ID, AuditEvent.FACET_ID, expectedEvent1.getName())).andReturn(expectedEvent1);
+ when(metadataRepository.getMetadataFacet(session, TEST_REPO_ID, AuditEvent.FACET_ID, expectedEvent1.getName())).thenReturn(expectedEvent1);
- EasyMock.expect(metadataRepository.getMetadataFacet(session, TEST_REPO_ID, AuditEvent.FACET_ID, expectedEvent2.getName())).andReturn(expectedEvent2);
+ when(metadataRepository.getMetadataFacet(session, TEST_REPO_ID, AuditEvent.FACET_ID, expectedEvent2.getName())).thenReturn(expectedEvent2);
- EasyMock.expect(metadataRepository.getMetadataFacet(session, TEST_REPO_ID, AuditEvent.FACET_ID, expectedEvent3.getName())).andReturn(expectedEvent3);
+ when(metadataRepository.getMetadataFacet(session, TEST_REPO_ID, AuditEvent.FACET_ID, expectedEvent3.getName())).thenReturn(expectedEvent3);
- metadataRepositoryControl.replay();
List events =
auditManager.getAuditEventsInRange( metadataRepository, Collections.singletonList( TEST_REPO_ID ), "foo",
@@ -543,7 +467,6 @@ public class AuditManagerTest
assertEquals( 0, events.size() );
- metadataRepositoryControl.verify();
}
@Test
@@ -560,26 +483,22 @@ public class AuditManagerTest
Date ts3 = new Date( current.getTime() - 1000 );
AuditEvent expectedEvent3 = createEvent( ts3 );
- sessionControl.reset();
- factoryControl.reset();
- EasyMock.expect( repositorySessionFactory.createSession() ).andStubReturn( session );
- factoryControl.replay();
- EasyMock.expect(metadataRepository.getMetadataFacets(session, TEST_REPO_ID, AuditEvent.FACET_ID))
- .andReturn(Arrays.asList(expectedEvent1.getName(), expectedEvent3.getName()));
+ when( repositorySessionFactory.createSession() ).thenReturn( session );
+ when(metadataRepository.getMetadataFacets(session, TEST_REPO_ID, AuditEvent.FACET_ID))
+ .thenReturn(Arrays.asList(expectedEvent1.getName(), expectedEvent3.getName()));
- EasyMock.expect(metadataRepository.getMetadataFacets(session, TEST_REPO_ID_2, AuditEvent.FACET_ID))
- .andReturn(Arrays.asList(expectedEvent2.getName()));
+ when(metadataRepository.getMetadataFacets(session, TEST_REPO_ID_2, AuditEvent.FACET_ID))
+ .thenReturn( Collections.singletonList( expectedEvent2.getName( ) ) );
- EasyMock.expect(metadataRepository.getMetadataFacet(session, TEST_REPO_ID, AuditEvent.FACET_ID, expectedEvent1.getName()))
- .andReturn(expectedEvent1);
+ when(metadataRepository.getMetadataFacet(session, TEST_REPO_ID, AuditEvent.FACET_ID, expectedEvent1.getName()))
+ .thenReturn(expectedEvent1);
- EasyMock.expect(metadataRepository.getMetadataFacet(session, TEST_REPO_ID_2, AuditEvent.FACET_ID, expectedEvent2.getName()))
- .andReturn(expectedEvent2);
+ when(metadataRepository.getMetadataFacet(session, TEST_REPO_ID_2, AuditEvent.FACET_ID, expectedEvent2.getName()))
+ .thenReturn(expectedEvent2);
- EasyMock.expect(metadataRepository.getMetadataFacet(session, TEST_REPO_ID, AuditEvent.FACET_ID, expectedEvent3.getName()))
- .andReturn(expectedEvent3);
- metadataRepositoryControl.replay();
+ when(metadataRepository.getMetadataFacet(session, TEST_REPO_ID, AuditEvent.FACET_ID, expectedEvent3.getName()))
+ .thenReturn(expectedEvent3);
List events =
auditManager.getAuditEventsInRange( metadataRepository, Arrays.asList( TEST_REPO_ID, TEST_REPO_ID_2 ),
@@ -591,7 +510,6 @@ public class AuditManagerTest
expectedEvent2.getResource() );
assertTestEvent( events.get( 2 ), TEST_REPO_ID, TIMESTAMP_FORMAT.format( ts1 ), expectedEvent1.getResource() );
- metadataRepositoryControl.verify();
}
@Test
@@ -605,13 +523,9 @@ public class AuditManagerTest
String name2 = createEvent( expectedTimestamp ).getName();
String name3 = createEvent( new Date( current.getTime() - 1000 ) ).getName();
- sessionControl.reset();
- factoryControl.reset();
- EasyMock.expect( repositorySessionFactory.createSession() ).andStubReturn( session );
- factoryControl.replay();
- EasyMock.expect(metadataRepository.getMetadataFacets(session, TEST_REPO_ID, AuditEvent.FACET_ID))
- .andReturn(Arrays.asList(name1, name2, name3));
- metadataRepositoryControl.replay();
+ when( repositorySessionFactory.createSession() ).thenReturn( session );
+ when(metadataRepository.getMetadataFacets(session, TEST_REPO_ID, AuditEvent.FACET_ID))
+ .thenReturn(Arrays.asList(name1, name2, name3));
List events =
auditManager.getAuditEventsInRange( metadataRepository, Collections.singletonList( TEST_REPO_ID ),
@@ -620,7 +534,6 @@ public class AuditManagerTest
assertEquals( 0, events.size() );
- metadataRepositoryControl.verify();
}
private static String getDefaultTestResourceName( String num )
diff --git a/archiva-modules/plugins/repository-statistics/pom.xml b/archiva-modules/plugins/repository-statistics/pom.xml
index 7fc78285c..0b117723a 100644
--- a/archiva-modules/plugins/repository-statistics/pom.xml
+++ b/archiva-modules/plugins/repository-statistics/pom.xml
@@ -70,8 +70,8 @@
- org.easymock
- easymock
+ org.mockito
+ mockito-core
test
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 f12a17ae8..4760135a9 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
@@ -19,19 +19,16 @@ package org.apache.archiva.metadata.repository.stats;
* under the License.
*/
-import junit.framework.TestCase;
-import org.apache.archiva.metadata.model.ArtifactMetadata;
import org.apache.archiva.maven.metadata.model.MavenArtifactFacet;
+import org.apache.archiva.metadata.model.ArtifactMetadata;
import org.apache.archiva.metadata.repository.MetadataRepository;
import org.apache.archiva.metadata.repository.RepositorySession;
import org.apache.archiva.metadata.repository.RepositorySessionFactory;
import org.apache.archiva.metadata.repository.stats.model.DefaultRepositoryStatistics;
import org.apache.archiva.metadata.repository.stats.model.RepositoryStatistics;
-import org.apache.archiva.test.utils.ArchivaBlockJUnit4ClassRunner;
-import org.easymock.IMocksControl;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
@@ -43,17 +40,16 @@ import java.util.List;
import java.util.Map;
import java.util.TimeZone;
-import static org.easymock.EasyMock.*;
+import static org.junit.jupiter.api.Assertions.*;
+import static org.mockito.Mockito.*;
+
-@RunWith( ArchivaBlockJUnit4ClassRunner.class )
public class RepositoryStatisticsManagerTest
- extends TestCase
{
private DefaultRepositoryStatisticsManager repositoryStatisticsManager;
private static final String TEST_REPO_ID = "test-repo";
- private IMocksControl metadataRepositoryControl;
private MetadataRepository metadataRepository;
@@ -66,8 +62,6 @@ public class RepositoryStatisticsManagerTest
private static final SimpleDateFormat TIMESTAMP_FORMAT = createTimestampFormat();
private RepositorySessionFactory repositorySessionFactory;
- private IMocksControl factoryControl;
- private IMocksControl sessionControl;
private RepositorySession session;
private static SimpleDateFormat createTimestampFormat()
@@ -77,25 +71,19 @@ public class RepositoryStatisticsManagerTest
return fmt;
}
- @Override
- @Before
+ @BeforeEach
public void setUp()
throws Exception
{
- super.setUp();
-
repositoryStatisticsManager = new DefaultRepositoryStatisticsManager();
- metadataRepositoryControl = createControl();
- metadataRepository = metadataRepositoryControl.createMock( MetadataRepository.class );
+ metadataRepository = mock( MetadataRepository.class );
- factoryControl = createControl();
- repositorySessionFactory = factoryControl.createMock(RepositorySessionFactory.class);
+ repositorySessionFactory = mock(RepositorySessionFactory.class);
repositoryStatisticsManager.setRepositorySessionFactory( repositorySessionFactory );
- sessionControl = createControl( );
- session = sessionControl.createMock( RepositorySession.class );
+ session = mock( RepositorySession.class );
}
@@ -117,22 +105,16 @@ public class RepositoryStatisticsManagerTest
stats.setTotalGroupCount( 529 );
stats.setTotalFileCount( 56229 );
-
- sessionControl.reset();
- factoryControl.reset();
- expect( repositorySessionFactory.createSession( ) ).andStubReturn( session );
- expect( session.getRepository() ).andStubReturn( metadataRepository );
+ when( repositorySessionFactory.createSession( ) ).thenReturn( session );
+ when( session.getRepository() ).thenReturn( metadataRepository );
session.close();
- expectLastCall( ).anyTimes( );
- factoryControl.replay();
- sessionControl.replay();
- expect(metadataRepository.getMetadataFacets(session, TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID)).andReturn(
+
+ when(metadataRepository.getMetadataFacets(session, TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID)).thenReturn(
Arrays.asList(FIRST_TEST_SCAN, SECOND_TEST_SCAN));
- expect(metadataRepository.getMetadataFacet(session, TEST_REPO_ID,
- DefaultRepositoryStatistics.FACET_ID, SECOND_TEST_SCAN)).andReturn(stats);
- metadataRepositoryControl.replay();
+ when(metadataRepository.getMetadataFacet(session, TEST_REPO_ID,
+ DefaultRepositoryStatistics.FACET_ID, SECOND_TEST_SCAN)).thenReturn(stats);
stats = repositoryStatisticsManager.getLastStatistics( TEST_REPO_ID );
assertNotNull( stats );
@@ -146,7 +128,6 @@ public class RepositoryStatisticsManagerTest
assertEquals( SECOND_TEST_SCAN, stats.getName() );
assertEquals( endTime, stats.getScanEndTime() );
- metadataRepositoryControl.verify();
}
@Test
@@ -154,23 +135,16 @@ public class RepositoryStatisticsManagerTest
throws Exception
{
- sessionControl.reset();
- factoryControl.reset();
- expect( repositorySessionFactory.createSession( ) ).andStubReturn( session );
- expect( session.getRepository() ).andStubReturn( metadataRepository );
+ when( repositorySessionFactory.createSession( ) ).thenReturn( session );
+ when( session.getRepository() ).thenReturn( metadataRepository );
session.close();
- expectLastCall( ).anyTimes( );
- factoryControl.replay();
- sessionControl.replay();
- expect( metadataRepository.getMetadataFacets(session , TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID ) ).andReturn(
+ when( metadataRepository.getMetadataFacets(session , TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID ) ).thenReturn(
Collections.emptyList() );
- metadataRepositoryControl.replay();
RepositoryStatistics stats = repositoryStatisticsManager.getLastStatistics( TEST_REPO_ID );
assertNull( stats );
- metadataRepositoryControl.verify();
}
@Test
@@ -184,24 +158,17 @@ public class RepositoryStatisticsManagerTest
walkRepository( 1 );
- sessionControl.reset();
- factoryControl.reset();
- expect( repositorySessionFactory.createSession( ) ).andStubReturn( session );
- expect( session.getRepository() ).andStubReturn( metadataRepository );
+ when( repositorySessionFactory.createSession( ) ).thenReturn( session );
+ when( session.getRepository() ).thenReturn( metadataRepository );
session.close();
- expectLastCall( ).anyTimes( );
- factoryControl.replay();
- sessionControl.replay();
metadataRepository.addMetadataFacet(session , TEST_REPO_ID, stats );
- expect( metadataRepository.getMetadataFacets(session , TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID ) ).andReturn(
+ when( metadataRepository.getMetadataFacets(session , TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID ) ).thenReturn(
Arrays.asList( stats.getName() ) );
- expect( metadataRepository.getMetadataFacet(session , TEST_REPO_ID,
- DefaultRepositoryStatistics.FACET_ID, stats.getName() ) ).andReturn( stats );
-
- metadataRepositoryControl.replay();
+ when( metadataRepository.getMetadataFacet(session , TEST_REPO_ID,
+ DefaultRepositoryStatistics.FACET_ID, stats.getName() ) ).thenReturn( stats );
repositoryStatisticsManager.addStatisticsAfterScan( TEST_REPO_ID, startTime, current, 56345,
45 );
@@ -217,7 +184,6 @@ public class RepositoryStatisticsManagerTest
assertEquals( current.getTime() - 12345, stats.getScanStartTime().getTime() );
assertEquals( current, stats.getScanEndTime() );
- metadataRepositoryControl.verify();
}
@Test
@@ -230,15 +196,9 @@ public class RepositoryStatisticsManagerTest
Date startTime1 = new Date( current.getTime() - 12345 );
DefaultRepositoryStatistics stats1 = createTestStats( startTime1, new Date( current.getTime() - 6000 ) );
-
- sessionControl.reset();
- factoryControl.reset();
- expect( repositorySessionFactory.createSession( ) ).andStubReturn( session );
- expect( session.getRepository() ).andStubReturn( metadataRepository );
+ when( repositorySessionFactory.createSession( ) ).thenReturn( session );
+ when( session.getRepository() ).thenReturn( metadataRepository );
session.close();
- expectLastCall( ).anyTimes( );
- factoryControl.replay();
- sessionControl.replay();
metadataRepository.addMetadataFacet(session , TEST_REPO_ID, stats1 );
@@ -247,20 +207,16 @@ public class RepositoryStatisticsManagerTest
metadataRepository.addMetadataFacet(session , TEST_REPO_ID, stats2 );
- expect( metadataRepository.getMetadataFacets(session , TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID ) ).andReturn(
- Arrays.asList( stats1.getName(), stats2.getName() ) );
+ when( metadataRepository.getMetadataFacets(session , TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID ) ).thenReturn(
+ Arrays.asList( stats1.getName(), stats2.getName() ) ).thenReturn( Collections.emptyList() );
- expect( metadataRepository.getMetadataFacet(session , TEST_REPO_ID,
- DefaultRepositoryStatistics.FACET_ID, stats2.getName() ) ).andReturn( stats2 );
+ when( metadataRepository.getMetadataFacet(session , TEST_REPO_ID,
+ DefaultRepositoryStatistics.FACET_ID, stats2.getName() ) ).thenReturn( stats2 );
metadataRepository.removeMetadataFacets(session , TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID );
- expect( metadataRepository.getMetadataFacets(session , TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID ) ).andReturn(
- Collections.emptyList() );
-
- metadataRepositoryControl.replay();
-
repositoryStatisticsManager.addStatisticsAfterScan( TEST_REPO_ID, startTime1,
- stats1.getScanEndTime(), 56345, 45 );
+ stats1.getScanEndTime(), 56345, 45 );
+
repositoryStatisticsManager.addStatisticsAfterScan( TEST_REPO_ID, startTime2,
stats2.getScanEndTime(), 56345, 45 );
@@ -270,35 +226,27 @@ public class RepositoryStatisticsManagerTest
assertNull( repositoryStatisticsManager.getLastStatistics( TEST_REPO_ID ) );
- metadataRepositoryControl.verify();
}
@Test
public void testDeleteStatsWhenEmpty()
throws Exception
{
- sessionControl.reset();
- factoryControl.reset();
- expect( repositorySessionFactory.createSession( ) ).andStubReturn( session );
- expect( session.getRepository() ).andStubReturn( metadataRepository );
+ when( repositorySessionFactory.createSession( ) ).thenReturn( session );
+ when( session.getRepository() ).thenReturn( metadataRepository );
session.close();
- expectLastCall( ).anyTimes( );
- factoryControl.replay();
- sessionControl.replay();
- expect( metadataRepository.getMetadataFacets(session , TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID ) ).andReturn(
- Collections.emptyList() ).times( 2 );
+ when( metadataRepository.getMetadataFacets( session, TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID ) ).thenReturn(
+ Collections.emptyList( ) );
metadataRepository.removeMetadataFacets(session , TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID );
- metadataRepositoryControl.replay();
-
assertNull( repositoryStatisticsManager.getLastStatistics( TEST_REPO_ID ) );
repositoryStatisticsManager.deleteStatistics( TEST_REPO_ID );
assertNull( repositoryStatisticsManager.getLastStatistics( TEST_REPO_ID ) );
+ verify( metadataRepository, times( 2 ) ).getMetadataFacets( session, TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID );
- metadataRepositoryControl.verify();
}
@Test
@@ -309,33 +257,24 @@ public class RepositoryStatisticsManagerTest
Date current = new Date();
- sessionControl.reset();
- factoryControl.reset();
- expect( repositorySessionFactory.createSession( ) ).andStubReturn( session );
- expect( session.getRepository() ).andStubReturn( metadataRepository );
+ when( repositorySessionFactory.createSession( ) ).thenReturn( session );
+ when( session.getRepository() ).thenReturn( metadataRepository );
session.close();
- expectLastCall( ).anyTimes( );
- factoryControl.replay();
- sessionControl.replay();
-
-
addStats( new Date( current.getTime() - 12345 ), new Date( current.getTime() - 6000 ) );
addStats( new Date( current.getTime() - 3000 ), new Date( current.getTime() - 2000 ) );
addStats( new Date( current.getTime() - 1000 ), current );
ArrayList keys = new ArrayList<>( statsCreated.keySet() );
- expect( metadataRepository.getMetadataFacets(session , TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID ) ).andReturn( keys );
+ when( metadataRepository.getMetadataFacets(session , TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID ) ).thenReturn( keys );
// only match the middle one
String key = keys.get( 1 );
- expect( metadataRepository.getMetadataFacet(session , TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID, key ) ).andReturn(
+ when( metadataRepository.getMetadataFacet(session , TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID, key ) ).thenReturn(
statsCreated.get( key ) );
- metadataRepositoryControl.replay();
-
for ( RepositoryStatistics stats : statsCreated.values() )
{
repositoryStatisticsManager.addStatisticsAfterScan( TEST_REPO_ID,
@@ -351,7 +290,6 @@ public class RepositoryStatisticsManagerTest
assertEquals( 1, list.size() );
assertEquals( new Date( current.getTime() - 3000 ), list.get( 0 ).getScanStartTime() );
- metadataRepositoryControl.verify();
}
@Test
@@ -362,14 +300,9 @@ public class RepositoryStatisticsManagerTest
Date current = new Date();
- sessionControl.reset();
- factoryControl.reset();
- expect( repositorySessionFactory.createSession( ) ).andStubReturn( session );
- expect( session.getRepository() ).andStubReturn( metadataRepository );
+ when( repositorySessionFactory.createSession( ) ).thenReturn( session );
+ when( session.getRepository() ).thenReturn( metadataRepository );
session.close();
- expectLastCall( ).anyTimes( );
- factoryControl.replay();
- sessionControl.replay();
addStats( new Date( current.getTime() - 12345 ), new Date( current.getTime() - 6000 ) );
addStats( new Date( current.getTime() - 3000 ), new Date( current.getTime() - 2000 ) );
@@ -377,22 +310,20 @@ public class RepositoryStatisticsManagerTest
List keys = new ArrayList<>( statsCreated.keySet() );
- expect( metadataRepository.getMetadataFacets(session , TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID ) ).andReturn( keys );
+ when( metadataRepository.getMetadataFacets(session , TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID ) ).thenReturn( keys );
String key = keys.get( 1 );
- expect( metadataRepository.getMetadataFacet(session, TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID, key ) ).andReturn(
+ when( metadataRepository.getMetadataFacet(session, TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID, key ) ).thenReturn(
statsCreated.get( key ) );
key = keys.get( 2 );
- expect( metadataRepository.getMetadataFacet(session , TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID, key ) ).andReturn(
+ when( metadataRepository.getMetadataFacet(session , TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID, key ) ).thenReturn(
statsCreated.get( key ) );
- metadataRepositoryControl.replay();
-
for ( RepositoryStatistics stats : statsCreated.values() )
{
repositoryStatisticsManager.addStatisticsAfterScan( TEST_REPO_ID,
@@ -408,7 +339,6 @@ public class RepositoryStatisticsManagerTest
assertEquals( new Date( current.getTime() - 3000 ), list.get( 1 ).getScanStartTime() );
assertEquals( new Date( current.getTime() - 1000 ), list.get( 0 ).getScanStartTime() );
- metadataRepositoryControl.verify();
}
@Test
@@ -419,14 +349,9 @@ public class RepositoryStatisticsManagerTest
Date current = new Date();
- sessionControl.reset();
- factoryControl.reset();
- expect( repositorySessionFactory.createSession( ) ).andStubReturn( session );
- expect( session.getRepository() ).andStubReturn( metadataRepository );
+ when( repositorySessionFactory.createSession( ) ).thenReturn( session );
+ when( session.getRepository() ).thenReturn( metadataRepository );
session.close();
- expectLastCall( ).anyTimes( );
- factoryControl.replay();
- sessionControl.replay();
addStats( new Date( current.getTime() - 12345 ), new Date( current.getTime() - 6000 ) );
addStats( new Date( current.getTime() - 3000 ), new Date( current.getTime() - 2000 ) );
@@ -434,19 +359,17 @@ public class RepositoryStatisticsManagerTest
List keys = new ArrayList<>( statsCreated.keySet() );
- expect( metadataRepository.getMetadataFacets(session , TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID ) ).andReturn( keys );
+ when( metadataRepository.getMetadataFacets(session , TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID ) ).thenReturn( keys );
String key = keys.get( 0 );
- expect( metadataRepository.getMetadataFacet(session , TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID, key ) ).andReturn(
+ when( metadataRepository.getMetadataFacet(session , TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID, key ) ).thenReturn(
statsCreated.get( key ) );
key = keys.get( 1 );
- expect( metadataRepository.getMetadataFacet(session , TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID, key ) ).andReturn(
+ when( metadataRepository.getMetadataFacet(session , TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID, key ) ).thenReturn(
statsCreated.get( key ) );
- metadataRepositoryControl.replay();
-
for ( RepositoryStatistics stats : statsCreated.values() )
{
repositoryStatisticsManager.addStatisticsAfterScan( TEST_REPO_ID,
@@ -463,7 +386,6 @@ public class RepositoryStatisticsManagerTest
assertEquals( new Date( current.getTime() - 12345 ), list.get( 1 ).getScanStartTime() );
assertEquals( new Date( current.getTime() - 3000 ), list.get( 0 ).getScanStartTime() );
- metadataRepositoryControl.verify();
}
@Test
@@ -474,14 +396,9 @@ public class RepositoryStatisticsManagerTest
Date current = new Date();
- sessionControl.reset();
- factoryControl.reset();
- expect( repositorySessionFactory.createSession( ) ).andStubReturn( session );
- expect( session.getRepository() ).andStubReturn( metadataRepository );
+ when( repositorySessionFactory.createSession( ) ).thenReturn( session );
+ when( session.getRepository() ).thenReturn( metadataRepository );
session.close();
- expectLastCall( ).anyTimes( );
- factoryControl.replay();
- sessionControl.replay();
addStats( new Date( current.getTime() - 12345 ), new Date( current.getTime() - 6000 ) );
addStats( new Date( current.getTime() - 3000 ), new Date( current.getTime() - 2000 ) );
@@ -489,23 +406,21 @@ public class RepositoryStatisticsManagerTest
ArrayList keys = new ArrayList<>( statsCreated.keySet() );
- expect( metadataRepository.getMetadataFacets(session , TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID ) ).andReturn( keys );
+ when( metadataRepository.getMetadataFacets(session , TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID ) ).thenReturn( keys );
String key = keys.get( 0 );
- expect( metadataRepository.getMetadataFacet(session , TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID, key ) ).andReturn(
+ when( metadataRepository.getMetadataFacet(session , TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID, key ) ).thenReturn(
statsCreated.get( key ) );
key = keys.get( 1 );
- expect( metadataRepository.getMetadataFacet(session , TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID, key ) ).andReturn(
+ when( metadataRepository.getMetadataFacet(session , TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID, key ) ).thenReturn(
statsCreated.get( key ) );
key = keys.get( 2 );
- expect( metadataRepository.getMetadataFacet(session , TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID, key ) ).andReturn(
+ when( metadataRepository.getMetadataFacet(session , TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID, key ) ).thenReturn(
statsCreated.get( key ) );
- metadataRepositoryControl.replay();
-
for ( RepositoryStatistics stats : statsCreated.values() )
{
repositoryStatisticsManager.addStatisticsAfterScan( TEST_REPO_ID,
@@ -522,7 +437,6 @@ public class RepositoryStatisticsManagerTest
assertEquals( new Date( current.getTime() - 3000 ), list.get( 1 ).getScanStartTime() );
assertEquals( new Date( current.getTime() - 1000 ), list.get( 0 ).getScanStartTime() );
- metadataRepositoryControl.verify();
}
@Test
@@ -532,14 +446,9 @@ public class RepositoryStatisticsManagerTest
walkRepository( 3 );
Date current = new Date();
- sessionControl.reset();
- factoryControl.reset();
- expect( repositorySessionFactory.createSession( ) ).andStubReturn( session );
- expect( session.getRepository() ).andStubReturn( metadataRepository );
+ when( repositorySessionFactory.createSession( ) ).thenReturn( session );
+ when( session.getRepository() ).thenReturn( metadataRepository );
session.close();
- expectLastCall( ).anyTimes( );
- factoryControl.replay();
- sessionControl.replay();
addStats( new Date( current.getTime() - 12345 ), new Date( current.getTime() - 6000 ) );
addStats( new Date( current.getTime() - 3000 ), new Date( current.getTime() - 2000 ) );
@@ -547,9 +456,7 @@ public class RepositoryStatisticsManagerTest
ArrayList keys = new ArrayList<>( statsCreated.keySet() );
- expect( metadataRepository.getMetadataFacets(session , TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID ) ).andReturn( keys );
-
- metadataRepositoryControl.replay();
+ when( metadataRepository.getMetadataFacets(session , TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID ) ).thenReturn( keys );
for ( RepositoryStatistics stats : statsCreated.values() )
{
@@ -565,7 +472,6 @@ public class RepositoryStatisticsManagerTest
assertEquals( 0, list.size() );
- metadataRepositoryControl.verify();
}
private void addStats( Date startTime, Date endTime )
@@ -616,114 +522,112 @@ public class RepositoryStatisticsManagerTest
private void walkRepository( int count )
throws Exception
{
- sessionControl.reset();
- expect( repositorySessionFactory.createSession( ) ).andStubReturn( session );
- factoryControl.replay();
+ when( repositorySessionFactory.createSession( ) ).thenReturn( session );
for ( int i = 0; i < count; i++ )
{
- expect( metadataRepository.getRootNamespaces(session , TEST_REPO_ID ) ).andReturn( Arrays.asList( "com", "org" ) );
+ when( metadataRepository.getRootNamespaces(session , TEST_REPO_ID ) ).thenReturn( Arrays.asList( "com", "org" ) );
- expect( metadataRepository.getProjects(session , TEST_REPO_ID, "com" ) ).andReturn( Arrays.asList() );
+ when( metadataRepository.getProjects(session , TEST_REPO_ID, "com" ) ).thenReturn( Arrays.asList() );
- expect( metadataRepository.getChildNamespaces(session , TEST_REPO_ID, "com" ) ).andReturn( Arrays.asList( "example" ) );
+ when( metadataRepository.getChildNamespaces(session , TEST_REPO_ID, "com" ) ).thenReturn( Arrays.asList( "example" ) );
- expect( metadataRepository.getChildNamespaces(session , TEST_REPO_ID, "com.example" ) ).andReturn(
+ when( metadataRepository.getChildNamespaces(session , TEST_REPO_ID, "com.example" ) ).thenReturn(
Arrays.asList() );
- expect( metadataRepository.getProjects(session , TEST_REPO_ID, "com.example" ) ).andReturn(
+ when( metadataRepository.getProjects(session , TEST_REPO_ID, "com.example" ) ).thenReturn(
Arrays.asList( "example-project" ) );
- expect( metadataRepository.getProjectVersions(session , TEST_REPO_ID, "com.example", "example-project" ) ).andReturn(
+ when( metadataRepository.getProjectVersions(session , TEST_REPO_ID, "com.example", "example-project" ) ).thenReturn(
Arrays.asList( "1.0", "1.1" ) );
- expect(
- metadataRepository.getArtifacts(session , TEST_REPO_ID, "com.example", "example-project", "1.0" ) ).andReturn(
+ when(
+ metadataRepository.getArtifacts(session , TEST_REPO_ID, "com.example", "example-project", "1.0" ) ).thenReturn(
Arrays.asList( createArtifact( "com.example", "example-project", "1.0", "jar" ),
createArtifact( "com.example", "example-project", "1.0", "pom" ) ) );
- expect(
- metadataRepository.getArtifacts(session , TEST_REPO_ID, "com.example", "example-project", "1.1" ) ).andReturn(
+ when(
+ metadataRepository.getArtifacts(session , TEST_REPO_ID, "com.example", "example-project", "1.1" ) ).thenReturn(
Arrays.asList( createArtifact( "com.example", "example-project", "1.1", "jar" ),
createArtifact( "com.example", "example-project", "1.1", "pom" ) ) );
- expect( metadataRepository.getChildNamespaces(session , TEST_REPO_ID, "org" ) ).andReturn( Arrays.asList( "apache", "codehaus" ) );
+ when( metadataRepository.getChildNamespaces(session , TEST_REPO_ID, "org" ) ).thenReturn( Arrays.asList( "apache", "codehaus" ) );
- expect( metadataRepository.getChildNamespaces(session , TEST_REPO_ID, "org.apache" ) ).andReturn( Arrays.asList( "archiva", "maven" ) );
+ when( metadataRepository.getChildNamespaces(session , TEST_REPO_ID, "org.apache" ) ).thenReturn( Arrays.asList( "archiva", "maven" ) );
- expect( metadataRepository.getProjects(session , TEST_REPO_ID, "org.apache" ) ).andReturn( Arrays.asList() );
+ when( metadataRepository.getProjects(session , TEST_REPO_ID, "org.apache" ) ).thenReturn( Arrays.asList() );
- expect( metadataRepository.getChildNamespaces(session , TEST_REPO_ID, "org.apache.archiva" ) ).andReturn( Arrays.asList() );
+ when( metadataRepository.getChildNamespaces(session , TEST_REPO_ID, "org.apache.archiva" ) ).thenReturn( Arrays.asList() );
- expect( metadataRepository.getProjects(session , TEST_REPO_ID, "org.apache.archiva" ) ).andReturn( Arrays.asList( "metadata-repository-api", "metadata-model" ) );
+ when( metadataRepository.getProjects(session , TEST_REPO_ID, "org.apache.archiva" ) ).thenReturn( Arrays.asList( "metadata-repository-api", "metadata-model" ) );
- expect( metadataRepository.getProjectVersions(session , TEST_REPO_ID, "org.apache.archiva", "metadata-repository-api" ) )
- .andReturn( Arrays.asList( "1.3-SNAPSHOT", "1.3" ) );
+ when( metadataRepository.getProjectVersions(session , TEST_REPO_ID, "org.apache.archiva", "metadata-repository-api" ) )
+ .thenReturn( Arrays.asList( "1.3-SNAPSHOT", "1.3" ) );
- expect( metadataRepository.getArtifacts(session , 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" ),
+ when( metadataRepository.getArtifacts(session , TEST_REPO_ID, "org.apache.archiva", "metadata-repository-api", "1.3-SNAPSHOT" ) )
+ .thenReturn( 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(session , TEST_REPO_ID, "org.apache.archiva", "metadata-repository-api", "1.3" ) )
- .andReturn( Arrays.asList( createArtifact( "org.apache.archiva", "metadata-repository-api", "1.3", "jar" ),
+ when( metadataRepository.getArtifacts(session , TEST_REPO_ID, "org.apache.archiva", "metadata-repository-api", "1.3" ) )
+ .thenReturn( Arrays.asList( createArtifact( "org.apache.archiva", "metadata-repository-api", "1.3", "jar" ),
createArtifact( "org.apache.archiva", "metadata-repository-api", "1.3", "pom" ) ) );
- expect( metadataRepository.getProjectVersions(session , TEST_REPO_ID, "org.apache.archiva", "metadata-model" ) )
- .andReturn( Arrays.asList( "1.3-SNAPSHOT", "1.3" ) );
+ when( metadataRepository.getProjectVersions(session , TEST_REPO_ID, "org.apache.archiva", "metadata-model" ) )
+ .thenReturn( Arrays.asList( "1.3-SNAPSHOT", "1.3" ) );
- expect( metadataRepository.getArtifacts(session , TEST_REPO_ID, "org.apache.archiva", "metadata-model", "1.3-SNAPSHOT" ) )
- .andReturn( Arrays.asList( createArtifact( "org.apache.archiva", "metadata-model", "1.3-SNAPSHOT", "jar" ),
+ when( metadataRepository.getArtifacts(session , TEST_REPO_ID, "org.apache.archiva", "metadata-model", "1.3-SNAPSHOT" ) )
+ .thenReturn( 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(session , TEST_REPO_ID, "org.apache.archiva", "metadata-model", "1.3" ) )
- .andReturn( Arrays.asList( createArtifact( "org.apache.archiva", "metadata-model", "1.3", "jar" ),
+ when( metadataRepository.getArtifacts(session , TEST_REPO_ID, "org.apache.archiva", "metadata-model", "1.3" ) )
+ .thenReturn( Arrays.asList( createArtifact( "org.apache.archiva", "metadata-model", "1.3", "jar" ),
createArtifact( "org.apache.archiva", "metadata-model", "1.3", "pom" ) ) );
- expect( metadataRepository.getChildNamespaces(session , TEST_REPO_ID, "org.apache.maven" ) ).andReturn( Arrays.asList() );
+ when( metadataRepository.getChildNamespaces(session , TEST_REPO_ID, "org.apache.maven" ) ).thenReturn( Arrays.asList() );
- expect( metadataRepository.getProjects(session , TEST_REPO_ID, "org.apache.maven" ) )
- .andReturn( Arrays.asList( "maven-model" ) );
+ when( metadataRepository.getProjects(session , TEST_REPO_ID, "org.apache.maven" ) )
+ .thenReturn( Arrays.asList( "maven-model" ) );
- expect( metadataRepository.getProjectVersions(session , TEST_REPO_ID, "org.apache.maven", "maven-model" ) )
- .andReturn( Arrays.asList( "2.2.1" ) );
+ when( metadataRepository.getProjectVersions(session , TEST_REPO_ID, "org.apache.maven", "maven-model" ) )
+ .thenReturn( Arrays.asList( "2.2.1" ) );
- expect( metadataRepository.getArtifacts(session , TEST_REPO_ID, "org.apache.maven", "maven-model", "2.2.1" ) )
- .andReturn( Arrays.asList( createArtifact( "org.apache.archiva", "maven-model", "2.2.1", "jar" ),
+ when( metadataRepository.getArtifacts(session , TEST_REPO_ID, "org.apache.maven", "maven-model", "2.2.1" ) )
+ .thenReturn( Arrays.asList( createArtifact( "org.apache.archiva", "maven-model", "2.2.1", "jar" ),
createArtifact( "org.apache.archiva", "maven-model", "2.2.1", "pom" ) ) );
- expect( metadataRepository.getChildNamespaces(session , TEST_REPO_ID, "org.codehaus" ) ).andReturn( Arrays.asList( "plexus" ) );
+ when( metadataRepository.getChildNamespaces(session , TEST_REPO_ID, "org.codehaus" ) ).thenReturn( Arrays.asList( "plexus" ) );
- expect( metadataRepository.getProjects(session , TEST_REPO_ID, "org" ) ).andReturn( Arrays.asList( ) );
+ when( metadataRepository.getProjects(session , TEST_REPO_ID, "org" ) ).thenReturn( Arrays.asList( ) );
- expect( metadataRepository.getProjects(session , TEST_REPO_ID, "org.codehaus" ) )
- .andReturn( Arrays.asList( ) );
+ when( metadataRepository.getProjects(session , TEST_REPO_ID, "org.codehaus" ) )
+ .thenReturn( Arrays.asList( ) );
- expect( metadataRepository.getChildNamespaces(session , TEST_REPO_ID, "org.codehaus.plexus" ) )
- .andReturn( Arrays.asList( ) );
+ when( metadataRepository.getChildNamespaces(session , TEST_REPO_ID, "org.codehaus.plexus" ) )
+ .thenReturn( Arrays.asList( ) );
- expect( metadataRepository.getProjects(session , TEST_REPO_ID, "org.codehaus.plexus" ) )
- .andReturn( Arrays.asList( "plexus-spring" ) );
+ when( metadataRepository.getProjects(session , TEST_REPO_ID, "org.codehaus.plexus" ) )
+ .thenReturn( Arrays.asList( "plexus-spring" ) );
- expect( metadataRepository.getProjectVersions(session, TEST_REPO_ID, "org.codehaus.plexus", "plexus-spring" ) )
- .andReturn( Arrays.asList( "1.0", "1.1", "1.2" ) );
+ when( metadataRepository.getProjectVersions(session, TEST_REPO_ID, "org.codehaus.plexus", "plexus-spring" ) )
+ .thenReturn( Arrays.asList( "1.0", "1.1", "1.2" ) );
- expect( metadataRepository.getArtifacts(session , TEST_REPO_ID, "org.codehaus.plexus", "plexus-spring", "1.0" ) )
- .andReturn( Arrays.asList( createArtifact( "org.codehaus.plexus", "plexus-spring", "1.0", "jar" ),
+ when( metadataRepository.getArtifacts(session , TEST_REPO_ID, "org.codehaus.plexus", "plexus-spring", "1.0" ) )
+ .thenReturn( Arrays.asList( createArtifact( "org.codehaus.plexus", "plexus-spring", "1.0", "jar" ),
createArtifact( "org.codehaus.plexus", "plexus-spring", "1.0", "pom" ) ) );
- expect( metadataRepository.getArtifacts(session, TEST_REPO_ID, "org.codehaus.plexus", "plexus-spring", "1.1" ) )
- .andReturn( Arrays.asList( createArtifact( "org.codehaus.plexus", "plexus-spring", "1.1", "jar" ),
+ when( metadataRepository.getArtifacts(session, TEST_REPO_ID, "org.codehaus.plexus", "plexus-spring", "1.1" ) )
+ .thenReturn( Arrays.asList( createArtifact( "org.codehaus.plexus", "plexus-spring", "1.1", "jar" ),
createArtifact( "org.codehaus.plexus", "plexus-spring", "1.1", "pom" ) ) );
- expect( metadataRepository.getArtifacts(session , TEST_REPO_ID, "org.codehaus.plexus", "plexus-spring", "1.2" ) )
- .andReturn( Arrays.asList( createArtifact( "org.codehaus.plexus", "plexus-spring", "1.2", "jar" ),
+ when( metadataRepository.getArtifacts(session , TEST_REPO_ID, "org.codehaus.plexus", "plexus-spring", "1.2" ) )
+ .thenReturn( 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 a61ecc51d..3885563fb 100644
--- a/pom.xml
+++ b/pom.xml
@@ -86,7 +86,7 @@
3.1.1
- 2.3.5
+ 2.4.5
0.3.3
3.2.1
@@ -94,8 +94,6 @@
1.0.9
- 4.1
-
0.7.9
1.5.2
@@ -1784,13 +1782,6 @@
test
-
- org.easymock
- easymock
- ${easymock.version}
- test
-
-
org.json
json
@@ -1851,20 +1842,6 @@
-