<artifactId>jakarta.annotation-api</artifactId>
</dependency>
<dependency>
- <groupId>jakarta.inject</groupId>
-<artifactId>jakarta.inject-api</artifactId>
+ <groupId>jakarta.inject</groupId>
+ <artifactId>jakarta.inject-api</artifactId>
</dependency>
<dependency>
<!-- Test scope -->
- <dependency>
- <groupId>org.easymock</groupId>
- <artifactId>easymock</artifactId>
- <scope>test</scope>
- </dependency>
-
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-test-utils</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+
</dependencies>
<build>
<plugins>
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;
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.
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
private static ConfigurationListener createConfigurationListenerMockControl()
{
- return createMock( ConfigurationListener.class );// MockControl.createControl( ConfigurationListener.class );
+ return mock( ConfigurationListener.class );// MockControl.createControl( ConfigurationListener.class );
}
@Test
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) );
<artifactId>spring-test</artifactId>
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>org.easymock</groupId>
- <artifactId>easymock</artifactId>
- <scope>test</scope>
- </dependency>
<dependency>
<groupId>org.apache.archiva.redback</groupId>
<artifactId>redback-rbac-jpa</artifactId>
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;
import static org.junit.Assert.*;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
/**
*/
protected RepositoryPurge repoPurge;
- protected IMocksControl listenerControl;
-
protected RepositoryListener listener;
- protected IMocksControl sessionControl;
protected RepositorySession repositorySession;
- protected IMocksControl sessionFactoryControl;
protected RepositorySessionFactory sessionFactory;
protected MetadataRepository metadataRepository;
throws Exception
{
- listenerControl = EasyMock.createControl();
-
- listener = listenerControl.createMock( RepositoryListener.class );
-
- sessionControl = EasyMock.createControl();
- sessionFactoryControl = EasyMock.createControl( );
+ listener = mock( RepositoryListener.class );
- 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 );
}
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;
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.*;
archivaConfiguration =
applicationContext.getBean( "archivaConfiguration#cleanup-released-snapshots", ArchivaConfiguration.class );
- listenerControl = EasyMock.createControl( );
-
- listener = listenerControl.createMock( RepositoryListener.class );
+ listener = mock( RepositoryListener.class );
List<RepositoryListener> 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 ),
// 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<ArtifactMetadata> ml = getArtifactMetadataFromDir(TEST_REPO_ID , projectName, repo.getParent(), vDir );
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) );
String repoRoot = prepareTestRepos();
// test listeners for the correct artifacts
- listenerControl.replay();
-
Path file = Paths.get(repoRoot, INDEX_PATH );
if ( !Files.exists(file) )
{
repoPurge.process( INDEX_PATH );
- listenerControl.verify();
-
assertTrue( Files.exists(file) );
}
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<ArtifactMetadata> ml = getArtifactMetadataFromDir(TEST_REPO_ID , projectName, repo.getParent(), vDir );
when(metadataRepository.getArtifacts(repositorySession , TEST_REPO_ID,
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) );
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<ArtifactMetadata> ml = getArtifactMetadataFromDir(TEST_REPO_ID , projectName, repo.getParent(), vDir );
when(metadataRepository.getArtifacts(repositorySession , TEST_REPO_ID,
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) );
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;
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.*;
/**
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,
"maven-install-plugin", "2.2-SNAPSHOT",
"maven-install-plugin-2.2-20061118.060401-2.pom"+exts[i]);
}
- listenerControl.replay();
// Provide the metadata list
List<ArtifactMetadata> ml = getArtifactMetadataFromDir(TEST_REPO_ID , projectName, repo.getParent(), vDir );
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<ArtifactMetadata> metadataArg = ArgumentCaptor.forClass(ArtifactMetadata.class);
ArtifactCleanupFeature atf = repoConfiguration.getFeature( ArtifactCleanupFeature.class ).get();
List<RepositoryListener> 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 );
"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<ArtifactMetadata> ml = getArtifactMetadataFromDir(TEST_REPO_ID , projectName, repo.getParent(), vDir );
when(metadataRepository.getArtifacts(repositorySession , TEST_REPO_ID,
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<ArtifactMetadata> metadataArg = ArgumentCaptor.forClass(ArtifactMetadata.class);
ArtifactCleanupFeature atf = repoConfiguration.getFeature( ArtifactCleanupFeature.class ).get();
List<RepositoryListener> 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 );
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<ArtifactMetadata> ml = getArtifactMetadataFromDir(TEST_REPO_ID , projectName, repo.getParent(), vDir );
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<ArtifactMetadata> metadataArg = ArgumentCaptor.forClass(ArtifactMetadata.class);
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;
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.*;
/**
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);
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 ) );
}
}
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 );
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();
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<ArtifactMetadata> 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) );
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();
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<ArtifactMetadata> metadataArg = ArgumentCaptor.forClass(ArtifactMetadata.class);
verify(metadataRepository, never()).removeTimestampedArtifact( eq(repositorySession), any(), any() );
// check if the snapshot was removed
String metadataXml = org.apache.archiva.common.utils.FileUtils.readFileToString( artifactMetadataFile, Charset.defaultCharset() );
- String expectedVersions =
- "<expected><versions><version>2.2</version>" + "<version>2.3</version></versions></expected>";
-
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 );
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;
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.*;
/**
List<RepositoryListener> 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 );
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<ArtifactMetadata> ml = getArtifactMetadataFromDir(TEST_REPO_ID , projectName, repo.getParent(), vDir );
when(metadataRepository.getArtifacts( repositorySession, TEST_REPO_ID,
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<ArtifactMetadata> metadataArg = ArgumentCaptor.forClass(ArtifactMetadata.class);
"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<ArtifactMetadata> ml = getArtifactMetadataFromDir(TEST_REPO_ID , projectName, repo.getParent(), vDir );
when(metadataRepository.getArtifacts( repositorySession, TEST_REPO_ID,
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<ArtifactMetadata> metadataArg = ArgumentCaptor.forClass(ArtifactMetadata.class);
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<ArtifactMetadata> ml = getArtifactMetadataFromDir(TEST_REPO_ID , projectName, repo.getParent(), vDir );
when(metadataRepository.getArtifacts( repositorySession, TEST_REPO_ID,
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<ArtifactMetadata> metadataArg = ArgumentCaptor.forClass(ArtifactMetadata.class);
<!-- Test scope -->
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<artifactId>archiva-maven-metadata</artifactId>
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>org.easymock</groupId>
- <artifactId>easymock</artifactId>
- <scope>test</scope>
- </dependency>
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
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;
import java.util.Map;
import java.util.function.Function;
-import static org.easymock.EasyMock.*;
+import static org.mockito.Mockito.*;
/**
* 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 ) ) );
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.<String>emptyList() );
-
- expect( selectedKnownConsumer.getIncludes() ).andReturn( Collections.singletonList( "**/*.txt" ) );
+ when( selectedKnownConsumer.getExcludes() ).thenReturn( Collections.<String>emptyList() );
- 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();
}
/**
<!-- TEST Scope -->
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-proxy</artifactId>
<artifactId>repository-statistics</artifactId>
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>org.easymock</groupId>
- <artifactId>easymock</artifactId>
- <scope>test</scope>
- </dependency>
<dependency>
<groupId>org.apache.archiva.redback</groupId>
<artifactId>redback-common-jpa</artifactId>
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;
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;
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
@Inject
private IndexerEngine indexerEngine;
- IMocksControl archivaConfigControl;
-
Configuration config;
@Inject
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 );
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();
}
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);
}
-
-
- 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();
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;
import java.util.Collections;
import java.util.List;
+import static org.mockito.Mockito.when;
+
/**
* @author Olivier Lamy
*/
// 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" );
SearchResults results = search.search( "user", searchFields, null );
- archivaConfigControl.verify();
-
assertNotNull( results );
assertEquals( 1, results.getTotalHits() );
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;
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" } )
List<String> 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 =
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() );
List<String> 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 =
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() );
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() );
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" );
SearchResults results = search.search( "user", searchFields, null );
- archivaConfigControl.verify();
-
assertNotNull( results );
assertEquals( 1, results.getTotalHits() );
List<String> 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() );
}
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() );
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 =
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
}
List<String> 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() );
}
List<String> 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();
assertNotNull( results );
assertEquals( 0, results.getTotalHits() );
- archivaConfigControl.verify();
}
@Test
assertNotNull( results );
assertEquals( 0, results.getTotalHits() );
- archivaConfigControl.verify();
}
@Test
List<String> 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() );
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() );
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() );
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() );
}
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 )
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 )
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() );
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() );
}
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() );
}
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() );
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() );
}
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() );
List<String> selectedRepos = Arrays.asList( TEST_REPO_1 );
- EasyMock.expect( archivaConfig.getConfiguration() ).andReturn( config ).times( 0, 2 );
-
- archivaConfigControl.replay();
+ when( archivaConfig.getConfiguration() ).thenReturn( config );
Collection<String> groupIds = search.getAllGroupIds( "user", selectedRepos );
- archivaConfigControl.verify();
-
log.info( "groupIds: {}", groupIds );
assertEquals( 3, groupIds.size() );
searchFields.setClassName( "SomeClass" );
searchFields.setRepositories( selectedRepos );
- archivaConfigControl.replay();
-
SearchResults results = search.search( "user", searchFields, null );
- archivaConfigControl.verify();
-
assertNotNull( results );
assertEquals( 0, results.getHits().size() );
}
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, //
log.info("results: {}", searchResults.getHits().size());
assertEquals(255, searchResults.getHits().size());
-
- archivaConfigControl.verify();
} finally {
FileUtils.deleteQuietly(repo);
}
</dependency>
<!-- Test scope -->
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>jakarta.persistence</groupId>
<artifactId>jakarta.persistence-api</artifactId>
<artifactId>xmlunit-core</artifactId>
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>org.easymock</groupId>
- <artifactId>easymock</artifactId>
- <scope>test</scope>
- </dependency>
<dependency>
<groupId>jakarta.transaction</groupId>
<artifactId>jakarta.transaction-api</artifactId>
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;
import java.util.stream.Collectors;
import static org.junit.Assert.*;
+import static org.mockito.Mockito.mock;
/**
* AbstractProxyTestCase
// protected static final String REPOPATH_DEFAULT_MANAGED_TARGET = "target/test-repository/managed";
- protected IMocksControl wagonMockControl;
-
protected Wagon wagonMock;
// Setup the wagon mock.
- wagonMockControl = EasyMock.createNiceControl();
- wagonMock = wagonMockControl.createMock( Wagon.class );
+ wagonMock = mock( Wagon.class );
delegate = (WagonDelegate) applicationContext.getBean( "wagon#http", Wagon.class );
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;
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
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 );
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 );
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;
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
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( );
* 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
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 );
}
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 );
}
saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, false );
- simulateGetError( path, expectedFile, createResourceNotFoundException() );
+ simulateGetError( path, expectedFile, Arrays.asList( createResourceNotFoundException( ) ) );
confirmSuccess( path, expectedFile, REPOPATH_PROXIED2 );
}
saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, false );
- simulateGetError( path, expectedFile, createTransferException() );
+ simulateGetError( path, expectedFile, Arrays.asList( createTransferException( ) ) );
confirmSingleFailure( path, ID_MOCKED_PROXIED1 );
}
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 );
}
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 );
}
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} );
}
saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, false );
- simulateGetError( path, expectedFile, createResourceNotFoundException() );
+ simulateGetError( path, expectedFile, Arrays.asList( createResourceNotFoundException( ) ) );
confirmSuccess( path, expectedFile, REPOPATH_PROXIED2 );
}
saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, false );
- simulateGetError( path, expectedFile, createTransferException() );
+ simulateGetError( path, expectedFile, Arrays.asList( createTransferException( ) ) );
confirmSuccess( path, expectedFile, REPOPATH_PROXIED2 );
}
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 );
}
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 );
}
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 );
}
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 );
}
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 } );
}
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 );
}
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 );
}
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 } );
}
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 );
}
return file;
}
- private void simulateGetError( String path, Path expectedFile, Exception throwable )
+ private void simulateGetError( String path, Path expectedFile, List<Exception> 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<throwables.size(); i++)
+ {
+ stubber = stubber.doThrow( throwables.get( i ) );
+ }
+ }
+ stubber.when( wagonMock ).get( eq( path ), any( ) );
}
private void simulateGetIfNewerError( String path, Path expectedFile, TransferFailedException exception )
throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException, IOException
{
- wagonMock.getIfNewer( EasyMock.eq( path ), EasyMock.anyObject( File.class ), EasyMock.eq( Files.getLastModifiedTime( expectedFile ).toMillis() ));
- EasyMock.expectLastCall().andThrow( exception );
+ doThrow( exception ).when( wagonMock ).getIfNewer( eq( path ), any( ), eq( Files.getLastModifiedTime( expectedFile ).toMillis( ) ) );
}
private Path createExpectedTempFile( Path expectedFile )
private void confirmFailures( String path, String[] ids )
throws LayoutException
{
- wagonMockControl.replay();
-
// Attempt the proxy fetch.
StorageAsset downloadedFile = null;
try
assertTrue( e.getFailures().keySet().contains( id ) );
}
}
-
- wagonMockControl.verify();
-
assertNotDownloaded( downloadedFile );
}
private StorageAsset performDownload( String path )
throws ProxyDownloadException, LayoutException
{
- wagonMockControl.replay();
-
// Attempt the proxy fetch.
BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout( BaseRepositoryContentLayout.class );
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(),
layout.getArtifact( path ) );
-
- wagonMockControl.verify();
return downloadedFile;
}
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.maven.wagon.ResourceDoesNotExistException;
-import org.easymock.EasyMock;
import org.junit.Test;
import java.io.File;
import java.util.concurrent.TimeUnit;
import static org.junit.Assert.*;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.*;
/**
* ManagedDefaultTransferTest
saveRemoteRepositoryConfig( "badproxied", "Bad Proxied", "" +
"http://bad.machine.com/repo/", "default" );
- wagonMock.get( EasyMock.eq( path), EasyMock.anyObject( File.class ) );
- EasyMock.expectLastCall().andThrow( new ResourceDoesNotExistException( "transfer failed" ) );
- wagonMockControl.replay();
+ doThrow( new ResourceDoesNotExistException( "transfer failed" ) ).when( wagonMock ).get( eq( path ), any( ) );
+
// Configure Connector (usually done within archiva.xml configuration)
saveConnector( ID_DEFAULT_MANAGED, "badproxied", false );
// Attempt the proxy fetch.
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact );
-
- wagonMockControl.verify();
+ verify( wagonMock, atLeastOnce( ) ).get( eq( path ), any( ) );
Path proxied2File = Paths.get(REPOPATH_PROXIED2, path);
assertFileEquals( expectedFile, downloadedFile.getFilePath(), proxied2File );
Path tmpFile = expectedFile.getParent().resolve(expectedFile.getFileName() + ".tmp" );
- wagonMock.get( EasyMock.eq( path ), EasyMock.anyObject( File.class ) );
- EasyMock.expectLastCall().andThrow( new ResourceDoesNotExistException( "Can't find resource." ) );
-
- wagonMock.get( EasyMock.eq( path ), EasyMock.anyObject( File.class ) );
- EasyMock.expectLastCall().andThrow( new ResourceDoesNotExistException( "Can't find resource." ) );
+ doThrow( new ResourceDoesNotExistException( "Can't find resource." ) ).when( wagonMock ).get( eq( path ), any( ) );
- wagonMockControl.replay();
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact );
+ verify( wagonMock, atLeastOnce( ) ).get( eq( path ), any( ) );
assertNotDownloaded( downloadedFile );
- wagonMockControl.verify();
assertNoTempFiles( expectedFile );
// TODO: do not want failures to present as a not found [MRM-492]
import org.apache.archiva.repository.storage.fs.FilesystemStorage;
import org.apache.commons.lang3.StringUtils;
import org.apache.maven.wagon.TransferFailedException;
-import org.easymock.EasyMock;
import org.junit.Test;
import org.xmlunit.builder.DiffBuilder;
import org.xmlunit.diff.Diff;
import java.util.Arrays;
import static org.junit.Assert.*;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.when;
/**
* MetadataTransferTest - Tests the various fetching / merging concepts surrounding the maven-metadata.xml files
Path expectedFile = managedDefaultDir.resolve(
metadataTools.getRepositorySpecificName( "badproxied1", requestedResource ) );
- wagonMock.get( EasyMock.eq( requestedResource ), EasyMock.anyObject( File.class ));
- EasyMock.expectLastCall().andThrow( new TransferFailedException( "can't connect" ) );
+ doThrow( new TransferFailedException( "can't connect" )).when( wagonMock ).get( eq( requestedResource ), any( File.class ) );
- wagonMockControl.replay();
-
assertFetchProjectOrGroup( requestedResource );
- wagonMockControl.verify();
-
assertProjectMetadataContents( requestedResource, new String[]{ "1.0.1" }, "1.0.1", "1.0.1" );
assertNoRepoMetadata( "badproxied1", requestedResource );
assertRepoProjectMetadata( ID_PROXIED2, requestedResource, new String[]{ "1.0.1" } );
import org.apache.archiva.components.registry.RegistryException;
import org.apache.archiva.components.registry.RegistryListener;
import org.apache.commons.lang3.StringUtils;
-import org.easymock.EasyMock;
-import org.easymock.IMocksControl;
+import org.mockito.Mockito;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import java.nio.file.Paths;
import java.util.*;
+import static org.mockito.Mockito.mock;
+
/**
* MockConfiguration
*
private Set<ConfigurationListener> configListeners = new HashSet<ConfigurationListener>();
- private IMocksControl registryControl;
private Registry registryMock;
public MockConfiguration()
{
- registryControl = EasyMock.createNiceControl( );
- registryMock = registryControl.createMock( Registry.class );
+ registryMock = mock( Registry.class );
}
@PostConstruct
<artifactId>xmlunit-assertj</artifactId>
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>org.easymock</groupId>
- <artifactId>easymock</artifactId>
- <scope>test</scope>
- </dependency>
<dependency>
<groupId>org.springframework</groupId>
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;
import java.util.Locale;
import java.util.Set;
-import static org.easymock.EasyMock.createNiceControl;
+import static org.mockito.Mockito.mock;
/**
* MockConfiguration
private Set<RegistryListener> registryListeners = new HashSet<RegistryListener>();
private Set<ConfigurationListener> configListeners = new HashSet<ConfigurationListener>();
- 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");
<!-- TEST Scope -->
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<artifactId>jakarta.persistence-api</artifactId>
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>org.easymock</groupId>
- <artifactId>easymock</artifactId>
- <scope>test</scope>
- </dependency>
<dependency>
<groupId>jakarta.transaction</groupId>
<artifactId>jakarta.transaction-api</artifactId>
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;
public class ArtifactBuilderTest
{
- @TestSubject
+ @InjectMocks
private ArtifactBuilder builder = new ArtifactBuilder();
StorageAsset getFile(String path) throws IOException {
<artifactId>archiva-filelock</artifactId>
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>org.easymock</groupId>
- <artifactId>easymock</artifactId>
- <scope>test</scope>
- </dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-test-utils</artifactId>
<artifactId>spring-test</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
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
private MetadataRepositoryMock metadataRepository;
- private IMocksControl sessionFactoryControl;
private RepositorySessionFactory sessionFactory;
- private IMocksControl sessionControl;
private RepositorySession session;
@Before
metadataRepository = new MetadataRepositoryMock();
- sessionFactoryControl = EasyMock.createControl();
- sessionControl = EasyMock.createControl();
- sessionControl.resetToNice();
-
- sessionFactory = sessionFactoryControl.createMock( RepositorySessionFactory.class );
- session = sessionControl.createMock( RepositorySession.class );
-
- EasyMock.expect( sessionFactory.createSession() ).andStubReturn( session );
- EasyMock.expect( session.getRepository( ) ).andStubReturn( metadataRepository );
+ sessionFactory = mock( RepositorySessionFactory.class );
+ session = mock( RepositorySession.class );
- sessionFactoryControl.replay();
- sessionControl.replay();
+ when( sessionFactory.createSession() ).thenReturn( session );
+ when( session.getRepository( ) ).thenReturn( metadataRepository );
newArtifactsProcessor.setRepositorySessionFactory( sessionFactory );
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;
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
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;
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<Repository> 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 );
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 );
assertEquals( whenGatheredNext.toInstant(), entries.get( 1 ).getPublishedDate().toInstant() );
- metadataRepositoryControl.verify();
}
private ArtifactMetadata createArtifact(ZonedDateTime whenGathered, String version )
<!-- Test Scoped -->
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>org.apache.archiva.maven</groupId>
<artifactId>archiva-maven-proxy</artifactId>
<artifactId>jakarta.persistence-api</artifactId>
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>org.easymock</groupId>
- <artifactId>easymock</artifactId>
- <scope>test</scope>
- </dependency>
<dependency>
<groupId>org.apache.archiva.redback</groupId>
<artifactId>redback-keys-jpa</artifactId>
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;
import javax.inject.Named;
import javax.servlet.http.HttpServletRequest;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
/**
* ArchivaServletAuthenticatorTest
*/
@Named( value = "servletAuthenticator#test" )
private ServletAuthenticator servletAuth;
- private IMocksControl httpServletRequestControl;
-
private HttpServletRequest request;
@Before
{
super.setUp();
- httpServletRequestControl = EasyMock.createControl( );
- request = httpServletRequestControl.createMock( HttpServletRequest.class );
+ request = mock( HttpServletRequest.class );
setupRepository( "corporate" );
}
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 );
SecuritySession session = new DefaultSecuritySession( result, user );
- httpServletRequestControl.replay();
-
try
{
servletAuth.isAuthorized( request, session, "corporate", ArchivaRoleConstants.OPERATION_ADD_ARTIFACT );
assertEquals( "Access denied for repository corporate", e.getMessage() );
}
- httpServletRequestControl.verify();
-
restoreGuestInitialValues( USER_ALPACA );
}
<scope>test</scope>
</dependency>
<dependency>
- <groupId>org.easymock</groupId>
- <artifactId>easymock</artifactId>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
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;
import java.util.Set;
import java.util.concurrent.atomic.AtomicReference;
-import static org.easymock.EasyMock.*;
+import static org.mockito.Mockito.*;
+
/**
* 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
{
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 );
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 );
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 )
try
{
- archivaConfigurationControl.reset();
-
- expect( archivaConfiguration.getConfiguration() ).andReturn( config ).times( 3 );
+ reset( archivaConfiguration );
+ reset( request );
+ reset( repoFactory );
+ 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( 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( true );
+ when( repoRequest.isSupportFile( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).thenReturn( 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." );
}
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." );
}
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." );
}
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 )
{
try
{
- archivaConfigurationControl.reset();
-
- expect( archivaConfiguration.getConfiguration() ).andReturn( config ).times( 2 );
+ reset( archivaConfiguration );
+ reset( request );
+ reset( repoFactory );
- expect( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ) ).andReturn( internalRepo );
+ when( archivaConfiguration.getConfiguration() ).thenReturn( config );
- expect( request.getMethod() ).andReturn( "GET" ).times( 3 );
+ when( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ) ).thenReturn( internalRepo );
- expect( request.getRemoteAddr() ).andReturn( "http://localhost:8080" ).times( 3 );
+ when( request.getMethod() ).thenReturn( "GET" );
- expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 2 );
+ when( request.getRemoteAddr() ).thenReturn( "http://localhost:8080" );
- expect( request.getContextPath() ).andReturn( "" ).times( 2 );
+ when( request.getDavSession() ).thenReturn( new ArchivaDavSession() );
- 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!" );
}
try
{
- archivaConfigurationControl.reset();
-
- expect( archivaConfiguration.getConfiguration() ).andReturn( config ).times( 2 );
+ reset( archivaConfiguration );
+ reset( request );
+ reset( repoFactory );
- expect( repoFactory.getManagedRepositoryContent( LEGACY_REPO ) ).andReturn( legacyRepo );
+ when( archivaConfiguration.getConfiguration() ).thenReturn( config );
- expect( request.getMethod() ).andReturn( "GET" ).times( 3 );
+ when( repoFactory.getManagedRepositoryContent( LEGACY_REPO ) ).thenReturn( legacyRepo );
- expect( request.getRemoteAddr() ).andReturn( "http://localhost:8080" ).times( 3 );
+ when( request.getMethod() ).thenReturn( "GET" );
- expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 2 );
+ when( request.getRemoteAddr() ).thenReturn( "http://localhost:8080" );
- expect( request.getContextPath() ).andReturn( "" ).times( 2 );
+ when( request.getDavSession() ).thenReturn( new ArchivaDavSession() );
- 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!" );
}
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;
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
private DavSessionProvider davSessionProvider;
- private IMocksControl servletAuthControl;
-
private ServletAuthenticator servletAuth;
- private IMocksControl httpAuthControl;
-
private HttpAuthenticator httpAuth;
private RepositoryServlet servlet;
CacheManager.getInstance().clearAll();
- servletAuthControl = EasyMock.createControl();
-
- servletAuth = servletAuthControl.createMock( ServletAuthenticator.class );
-
- httpAuthControl = EasyMock.createControl();
+ servletAuth = mock( ServletAuthenticator.class );
- httpAuth = httpAuthControl.createMock( HttpAuthenticator.class );
+ httpAuth = mock( HttpAuthenticator.class );
davSessionProvider = new ArchivaDavSessionProvider( servletAuth, httpAuth );
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" );
servlet.service( mockHttpServletRequest, mockHttpServletResponse );
- httpAuthControl.verify();
- servletAuthControl.verify();
-
assertEquals( HttpServletResponse.SC_UNAUTHORIZED, mockHttpServletResponse.getStatus() );
}
public void testPutWithInvalidUserAndGuestHasWriteAccess()
throws Exception
{
-
servlet.setDavSessionProvider( davSessionProvider );
ArchivaDavResourceFactory archivaDavResourceFactory = (ArchivaDavResourceFactory) servlet.getResourceFactory();
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 );
servlet.service( mockHttpServletRequest, mockHttpServletResponse );
- httpAuthControl.verify();
- servletAuthControl.verify();
-
assertEquals( HttpServletResponse.SC_CREATED, mockHttpServletResponse.getStatus() );
}
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 );
MockHttpServletResponse mockHttpServletResponse = new MockHttpServletResponse();
servlet.service( mockHttpServletRequest, mockHttpServletResponse );
-
- httpAuthControl.verify();
- servletAuthControl.verify();
-
assertEquals( HttpServletResponse.SC_UNAUTHORIZED, mockHttpServletResponse.getStatus() );
}
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" );
// 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" );
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() );
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 );
-
- EasyMock.expect( httpAuth.getSecuritySession( anyObject( HttpSession.class ) ) ).andReturn( session );
+ when( httpAuth.getSecuritySession( any( ) ) ).thenReturn( session );
- EasyMock.expect( httpAuth.getSessionUser( anyObject( HttpSession.class ) ) ).andReturn( null );
+ when( httpAuth.getSessionUser( any( ) ) ).thenReturn( 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" );
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() );
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" );
MockHttpServletResponse mockHttpServletResponse = new MockHttpServletResponse();
servlet.service( mockHttpServletRequest, mockHttpServletResponse );
-
- httpAuthControl.verify();
- servletAuthControl.verify();
-
assertEquals( HttpServletResponse.SC_UNAUTHORIZED, mockHttpServletResponse.getStatus() );
}
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" );
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() );
}
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" );
MockHttpServletResponse mockHttpServletResponse = new MockHttpServletResponse();
servlet.service( mockHttpServletRequest, mockHttpServletResponse );
-
- httpAuthControl.verify();
- servletAuthControl.verify();
-
assertEquals( HttpServletResponse.SC_UNAUTHORIZED, mockHttpServletResponse.getStatus() );
}
<properties>
<site.staging.base>${project.parent.parent.basedir}</site.staging.base>
- <cassandraVersion>3.11.10</cassandraVersion>
+ <cassandraVersion>3.11.11</cassandraVersion>
<datastax.driver.version>4.13.0</datastax.driver.version>
</properties>
</exclusions>
</dependency>
<dependency>
- <groupId>org.easymock</groupId>
- <artifactId>easymock</artifactId>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cassandra-maven-plugin</artifactId>
- <version>3.6</version>
+ <version>3.7-SNAPSHOT</version>
<executions>
<execution>
<id>start-cassandra</id>
</pluginManagement>
</build>
+ <profiles>
+ <profile>
+ <id>jdk9+</id>
+ <activation>
+ <jdk>[1.9,)</jdk>
+ </activation>
+ <properties >
+ <cassandra.addJdk11Options>true</cassandra.addJdk11Options>
+ </properties>
+ </profile>
+ </profiles>
</project>
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;
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
CassandraMetadataRepository cmr;
- IMocksControl sessionFactoryControl;
RepositorySessionFactory sessionFactory;
- IMocksControl sessionControl;
RepositorySession session;
long cTime;
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())
{
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;
<!-- Test scope -->
<dependency>
- <groupId>org.apache.archiva</groupId>
- <artifactId>archiva-test-utils</artifactId>
- <version>${project.version}</version>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
- <groupId>org.easymock</groupId>
- <artifactId>easymock</artifactId>
+ <groupId>org.apache.archiva</groupId>
+ <artifactId>archiva-test-utils</artifactId>
+ <version>${project.version}</version>
<scope>test</scope>
</dependency>
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;
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;
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()
{
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 );
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<AuditEvent> events =
auditManager.getMostRecentAuditEvents( metadataRepository, Collections.singletonList( TEST_REPO_ID ) );
expectedTimestampCounter--;
}
- metadataRepositoryControl.verify();
}
@Test
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<AuditEvent> events =
auditManager.getMostRecentAuditEvents( metadataRepository, Collections.singletonList( TEST_REPO_ID ) );
expectedTimestampCounter--;
}
- metadataRepositoryControl.verify();
}
@Test
throws Exception
{
int numEvents = 11;
- Map<String, List<String>> eventNames = new LinkedHashMap<String, List<String>>();
+ Map<String, List<String>> eventNames = new LinkedHashMap<>( );
List<AuditEvent> events = new ArrayList<>();
- eventNames.put( TEST_REPO_ID, new ArrayList<String>() );
- eventNames.put( TEST_REPO_ID_2, new ArrayList<String>() );
+ 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;
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 ) );
expectedTimestampCounter--;
}
- metadataRepositoryControl.verify();
}
@Test
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.<String>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
{
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
// should just be ignored
- metadataRepositoryControl.replay();
-
auditManager.addAuditEvent( metadataRepository, event );
-
- metadataRepositoryControl.verify();
}
@Test
{
- 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
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<AuditEvent> events =
auditManager.getAuditEventsInRange( metadataRepository, Collections.singletonList( TEST_REPO_ID ),
assertEquals( 1, events.size() );
assertTestEvent( events.get( 0 ), TIMESTAMP_FORMAT.format( expectedTimestamp ), expectedEvent.getResource() );
- metadataRepositoryControl.verify();
}
@Test
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<AuditEvent> events =
auditManager.getAuditEventsInRange( metadataRepository, Collections.singletonList( TEST_REPO_ID ),
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
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<AuditEvent> events =
auditManager.getAuditEventsInRange( metadataRepository, Collections.singletonList( TEST_REPO_ID ),
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
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<AuditEvent> events =
auditManager.getAuditEventsInRange( metadataRepository, Collections.singletonList( TEST_REPO_ID ),
assertTestEvent( events.get( 1 ), TIMESTAMP_FORMAT.format( expectedTimestamp ), expectedEvent2.getResource() );
assertTestEvent( events.get( 2 ), TIMESTAMP_FORMAT.format( ts1 ), expectedEvent1.getResource() );
- metadataRepositoryControl.verify();
}
@Test
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<AuditEvent> events =
auditManager.getAuditEventsInRange( metadataRepository, Collections.singletonList( TEST_REPO_ID ),
assertTestEvent( events.get( 0 ), TIMESTAMP_FORMAT.format( ts3 ), expectedEvent3.getResource() );
assertTestEvent( events.get( 1 ), TIMESTAMP_FORMAT.format( ts1 ), expectedEvent1.getResource() );
- metadataRepositoryControl.verify();
}
@Test
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<AuditEvent> events =
auditManager.getAuditEventsInRange( metadataRepository, Collections.singletonList( TEST_REPO_ID ), "foo",
assertEquals( 0, events.size() );
- metadataRepositoryControl.verify();
}
@Test
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<AuditEvent> events =
auditManager.getAuditEventsInRange( metadataRepository, Arrays.asList( TEST_REPO_ID, TEST_REPO_ID_2 ),
expectedEvent2.getResource() );
assertTestEvent( events.get( 2 ), TEST_REPO_ID, TIMESTAMP_FORMAT.format( ts1 ), expectedEvent1.getResource() );
- metadataRepositoryControl.verify();
}
@Test
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<AuditEvent> events =
auditManager.getAuditEventsInRange( metadataRepository, Collections.singletonList( TEST_REPO_ID ),
assertEquals( 0, events.size() );
- metadataRepositoryControl.verify();
}
private static String getDefaultTestResourceName( String num )
<!-- Test dependencies -->
<dependency>
- <groupId>org.easymock</groupId>
- <artifactId>easymock</artifactId>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
* 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;
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;
private static final SimpleDateFormat TIMESTAMP_FORMAT = createTimestampFormat();
private RepositorySessionFactory repositorySessionFactory;
- private IMocksControl factoryControl;
- private IMocksControl sessionControl;
private RepositorySession session;
private static SimpleDateFormat createTimestampFormat()
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 );
}
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 );
assertEquals( SECOND_TEST_SCAN, stats.getName() );
assertEquals( endTime, stats.getScanEndTime() );
- metadataRepositoryControl.verify();
}
@Test
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.<String>emptyList() );
- metadataRepositoryControl.replay();
RepositoryStatistics stats = repositoryStatisticsManager.getLastStatistics( TEST_REPO_ID );
assertNull( stats );
- metadataRepositoryControl.verify();
}
@Test
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 );
assertEquals( current.getTime() - 12345, stats.getScanStartTime().getTime() );
assertEquals( current, stats.getScanEndTime() );
- metadataRepositoryControl.verify();
}
@Test
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 );
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.<String>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 );
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.<String>emptyList() ).times( 2 );
+ when( metadataRepository.getMetadataFacets( session, TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID ) ).thenReturn(
+ Collections.<String>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
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<String> 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,
assertEquals( 1, list.size() );
assertEquals( new Date( current.getTime() - 3000 ), list.get( 0 ).getScanStartTime() );
- metadataRepositoryControl.verify();
}
@Test
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 ) );
List<String> 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,
assertEquals( new Date( current.getTime() - 3000 ), list.get( 1 ).getScanStartTime() );
assertEquals( new Date( current.getTime() - 1000 ), list.get( 0 ).getScanStartTime() );
- metadataRepositoryControl.verify();
}
@Test
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 ) );
List<String> 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,
assertEquals( new Date( current.getTime() - 12345 ), list.get( 1 ).getScanStartTime() );
assertEquals( new Date( current.getTime() - 3000 ), list.get( 0 ).getScanStartTime() );
- metadataRepositoryControl.verify();
}
@Test
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 ) );
ArrayList<String> 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,
assertEquals( new Date( current.getTime() - 3000 ), list.get( 1 ).getScanStartTime() );
assertEquals( new Date( current.getTime() - 1000 ), list.get( 0 ).getScanStartTime() );
- metadataRepositoryControl.verify();
}
@Test
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 ) );
ArrayList<String> 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() )
{
assertEquals( 0, list.size() );
- metadataRepositoryControl.verify();
}
private void addStats( Date startTime, Date endTime )
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.<String>asList() );
+ when( metadataRepository.getProjects(session , TEST_REPO_ID, "com" ) ).thenReturn( Arrays.<String>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.<String>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.<String>asList() );
+ when( metadataRepository.getProjects(session , TEST_REPO_ID, "org.apache" ) ).thenReturn( Arrays.<String>asList() );
- expect( metadataRepository.getChildNamespaces(session , TEST_REPO_ID, "org.apache.archiva" ) ).andReturn( Arrays.<String>asList() );
+ when( metadataRepository.getChildNamespaces(session , TEST_REPO_ID, "org.apache.archiva" ) ).thenReturn( Arrays.<String>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.<String>asList() );
+ when( metadataRepository.getChildNamespaces(session , TEST_REPO_ID, "org.apache.maven" ) ).thenReturn( Arrays.<String>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.<String>asList( ) );
+ when( metadataRepository.getProjects(session , TEST_REPO_ID, "org" ) ).thenReturn( Arrays.<String>asList( ) );
- expect( metadataRepository.getProjects(session , TEST_REPO_ID, "org.codehaus" ) )
- .andReturn( Arrays.<String>asList( ) );
+ when( metadataRepository.getProjects(session , TEST_REPO_ID, "org.codehaus" ) )
+ .thenReturn( Arrays.<String>asList( ) );
- expect( metadataRepository.getChildNamespaces(session , TEST_REPO_ID, "org.codehaus.plexus" ) )
- .andReturn( Arrays.<String>asList( ) );
+ when( metadataRepository.getChildNamespaces(session , TEST_REPO_ID, "org.codehaus.plexus" ) )
+ .thenReturn( Arrays.<String>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" ) ) );
}
}
<openjpaVersion>3.1.1</openjpaVersion>
- <modelmapper.version>2.3.5</modelmapper.version>
+ <modelmapper.version>2.4.5</modelmapper.version>
<sisu-inject-plexus.version>0.3.3</sisu-inject-plexus.version>
<plexus-utils.version>3.2.1</plexus-utils.version>
<springockito.version>1.0.9</springockito.version>
- <easymock.version>4.1</easymock.version>
-
<jacoco.plugin.version>0.7.9</jacoco.plugin.version>
<joda.time.version>1.5.2</joda.time.version>
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>org.easymock</groupId>
- <artifactId>easymock</artifactId>
- <version>${easymock.version}</version>
- <scope>test</scope>
- </dependency>
-
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
</dependency>
- <!--
- <dependency>
- <groupId>org.easymock</groupId>
- <artifactId>easymock</artifactId>
- <version>3.2</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.easymock</groupId>
- <artifactId>easymockclassextension</artifactId>
- <version>3.2</version>
- <scope>test</scope>
- </dependency>
- -->
</dependencies>