mirror of
https://github.com/apache/archiva.git
synced 2025-03-03 06:59:16 +00:00
test case refactoring for clarity
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@887005 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
5996457bf2
commit
3e47fdca1a
@ -25,7 +25,6 @@
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.jdo.PersistenceManager;
|
||||
import javax.jdo.PersistenceManagerFactory;
|
||||
|
||||
@ -45,7 +44,7 @@
|
||||
import org.jpox.SchemaTool;
|
||||
|
||||
/**
|
||||
* ArchivaRepositoryScanningTaskExecutorTest
|
||||
* ArchivaRepositoryScanningTaskExecutorTest
|
||||
*
|
||||
* @version $Id$
|
||||
*/
|
||||
@ -55,42 +54,44 @@ public class ArchivaRepositoryScanningTaskExecutorTest
|
||||
private TaskExecutor taskExecutor;
|
||||
|
||||
protected ArchivaDAO dao;
|
||||
|
||||
|
||||
private File repoDir;
|
||||
|
||||
|
||||
private static final String TEST_REPO_ID = "testRepo";
|
||||
|
||||
protected void setUp()
|
||||
throws Exception
|
||||
{
|
||||
super.setUp();
|
||||
|
||||
|
||||
DefaultConfigurableJdoFactory jdoFactory = (DefaultConfigurableJdoFactory) lookup( JdoFactory.ROLE, "archiva" );
|
||||
assertEquals( DefaultConfigurableJdoFactory.class.getName(), jdoFactory.getClass().getName() );
|
||||
|
||||
jdoFactory.setPersistenceManagerFactoryClass( "org.jpox.PersistenceManagerFactoryImpl" );
|
||||
jdoFactory.setPersistenceManagerFactoryClass( "org.jpox.PersistenceManagerFactoryImpl" );
|
||||
|
||||
/* derby version
|
||||
File derbyDbDir = new File( "target/plexus-home/testdb" );
|
||||
if ( derbyDbDir.exists() )
|
||||
{
|
||||
FileUtils.deleteDirectory( derbyDbDir );
|
||||
}
|
||||
File derbyDbDir = new File( "target/plexus-home/testdb" );
|
||||
if ( derbyDbDir.exists() )
|
||||
{
|
||||
FileUtils.deleteDirectory( derbyDbDir );
|
||||
}
|
||||
|
||||
jdoFactory.setDriverName( System.getProperty( "jdo.test.driver", "org.apache.derby.jdbc.EmbeddedDriver" ) );
|
||||
jdoFactory.setUrl( System.getProperty( "jdo.test.url", "jdbc:derby:" + derbyDbDir.getAbsolutePath() + ";create=true" ) );
|
||||
*/
|
||||
jdoFactory.setDriverName( System.getProperty( "jdo.test.driver", "org.apache.derby.jdbc.EmbeddedDriver" ) );
|
||||
jdoFactory.setUrl( System.getProperty( "jdo.test.url", "jdbc:derby:" + derbyDbDir.getAbsolutePath() + ";create=true" ) );
|
||||
*/
|
||||
|
||||
jdoFactory.setDriverName( System.getProperty( "jdo.test.driver", "org.hsqldb.jdbcDriver" ) );
|
||||
jdoFactory.setDriverName( System.getProperty( "jdo.test.driver", "org.hsqldb.jdbcDriver" ) );
|
||||
jdoFactory.setUrl( System.getProperty( "jdo.test.url", "jdbc:hsqldb:mem:" + getName() ) );
|
||||
|
||||
jdoFactory.setUserName( System.getProperty( "jdo.test.user", "sa" ) );
|
||||
|
||||
jdoFactory.setPassword( System.getProperty( "jdo.test.pass", "" ) );
|
||||
jdoFactory.setUserName( System.getProperty( "jdo.test.user", "sa" ) );
|
||||
|
||||
jdoFactory.setProperty( "org.jpox.transactionIsolation", "READ_COMMITTED" );
|
||||
jdoFactory.setPassword( System.getProperty( "jdo.test.pass", "" ) );
|
||||
|
||||
jdoFactory.setProperty( "org.jpox.poid.transactionIsolation", "READ_COMMITTED" );
|
||||
jdoFactory.setProperty( "org.jpox.transactionIsolation", "READ_COMMITTED" );
|
||||
|
||||
jdoFactory.setProperty( "org.jpox.autoCreateSchema", "true" );
|
||||
jdoFactory.setProperty( "org.jpox.poid.transactionIsolation", "READ_COMMITTED" );
|
||||
|
||||
jdoFactory.setProperty( "org.jpox.autoCreateSchema", "true" );
|
||||
|
||||
jdoFactory.setProperty( "javax.jdo.option.RetainValues", "true" );
|
||||
|
||||
@ -111,8 +112,7 @@ protected void setUp()
|
||||
System.setProperty( (String) entry.getKey(), (String) entry.getValue() );
|
||||
}
|
||||
|
||||
URL jdoFileUrls[] = new URL[] { getClass()
|
||||
.getResource( "/org/apache/maven/archiva/model/package.jdo" ) };
|
||||
URL jdoFileUrls[] = new URL[]{getClass().getResource( "/org/apache/maven/archiva/model/package.jdo" )};
|
||||
|
||||
if ( ( jdoFileUrls == null ) || ( jdoFileUrls[0] == null ) )
|
||||
{
|
||||
@ -122,8 +122,8 @@ protected void setUp()
|
||||
File propsFile = null; // intentional
|
||||
boolean verbose = true;
|
||||
|
||||
SchemaTool.deleteSchemaTables( jdoFileUrls, new URL[] {}, propsFile, verbose );
|
||||
SchemaTool.createSchemaTables( jdoFileUrls, new URL[] {}, propsFile, verbose, null );
|
||||
SchemaTool.deleteSchemaTables( jdoFileUrls, new URL[]{}, propsFile, verbose );
|
||||
SchemaTool.createSchemaTables( jdoFileUrls, new URL[]{}, propsFile, verbose, null );
|
||||
|
||||
PersistenceManagerFactory pmf = jdoFactory.getPersistenceManagerFactory();
|
||||
|
||||
@ -136,156 +136,133 @@ protected void setUp()
|
||||
this.dao = (ArchivaDAO) lookup( ArchivaDAO.class.getName(), "jdo" );
|
||||
|
||||
taskExecutor = (TaskExecutor) lookup( TaskExecutor.class, "test-repository-scanning" );
|
||||
|
||||
|
||||
File sourceRepoDir = new File( getBasedir(), "src/test/repositories/default-repository" );
|
||||
repoDir = new File( getBasedir(), "target/default-repository" );
|
||||
|
||||
repoDir = new File( getBasedir(), "target/default-repository" );
|
||||
|
||||
repoDir.mkdir();
|
||||
|
||||
|
||||
FileUtils.copyDirectoryStructure( sourceRepoDir, repoDir );
|
||||
|
||||
assertTrue( repoDir.exists() );
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception
|
||||
{
|
||||
FileUtils.deleteDirectory( repoDir );
|
||||
|
||||
assertFalse( repoDir.exists() );
|
||||
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
public void testExecutor() throws Exception
|
||||
{
|
||||
|
||||
assertTrue( "Default Test Repository should exist.", repoDir.exists() && repoDir.isDirectory() );
|
||||
|
||||
ArchivaConfiguration archivaConfig = (ArchivaConfiguration) lookup( ArchivaConfiguration.class );
|
||||
assertNotNull( archivaConfig );
|
||||
|
||||
// Create it
|
||||
ManagedRepositoryConfiguration repo = createRepository( "testRepo", "Test Repository", repoDir );
|
||||
assertNotNull( repo );
|
||||
archivaConfig.getConfiguration().getManagedRepositories().clear();
|
||||
archivaConfig.getConfiguration().addManagedRepository( repo );
|
||||
|
||||
// Create it
|
||||
ManagedRepositoryConfiguration repositoryConfiguration = new ManagedRepositoryConfiguration();
|
||||
repositoryConfiguration.setId( TEST_REPO_ID );
|
||||
repositoryConfiguration.setName( "Test Repository" );
|
||||
repositoryConfiguration.setLocation( repoDir.getAbsolutePath() );
|
||||
archivaConfig.getConfiguration().getManagedRepositories().clear();
|
||||
archivaConfig.getConfiguration().addManagedRepository( repositoryConfiguration );
|
||||
}
|
||||
|
||||
protected void tearDown()
|
||||
throws Exception
|
||||
{
|
||||
FileUtils.deleteDirectory( repoDir );
|
||||
|
||||
assertFalse( repoDir.exists() );
|
||||
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
public void testExecutor()
|
||||
throws Exception
|
||||
{
|
||||
RepositoryTask repoTask = new RepositoryTask();
|
||||
|
||||
repoTask.setRepositoryId( "testRepo" );
|
||||
|
||||
|
||||
repoTask.setRepositoryId( TEST_REPO_ID );
|
||||
|
||||
taskExecutor.executeTask( repoTask );
|
||||
|
||||
ArtifactDAO adao = dao.getArtifactDAO();
|
||||
List<ArchivaArtifact> unprocessedResultList = adao.queryArtifacts( new ArtifactsProcessedConstraint( false ) );
|
||||
|
||||
|
||||
assertNotNull( unprocessedResultList );
|
||||
assertEquals("Incorrect number of unprocessed artifacts detected.", 8, unprocessedResultList.size() );
|
||||
assertEquals( "Incorrect number of unprocessed artifacts detected.", 8, unprocessedResultList.size() );
|
||||
}
|
||||
|
||||
|
||||
public void testExecutorScanOnlyNewArtifacts()
|
||||
throws Exception
|
||||
{
|
||||
assertTrue( "Default Test Repository should exist.", repoDir.exists() && repoDir.isDirectory() );
|
||||
|
||||
ArchivaConfiguration archivaConfig = (ArchivaConfiguration) lookup( ArchivaConfiguration.class );
|
||||
assertNotNull( archivaConfig );
|
||||
|
||||
// Create it
|
||||
ManagedRepositoryConfiguration repo = createRepository( "testRepo", "Test Repository", repoDir );
|
||||
assertNotNull( repo );
|
||||
archivaConfig.getConfiguration().getManagedRepositories().clear();
|
||||
archivaConfig.getConfiguration().addManagedRepository( repo );
|
||||
|
||||
{
|
||||
RepositoryTask repoTask = new RepositoryTask();
|
||||
|
||||
repoTask.setRepositoryId( "testRepo" );
|
||||
|
||||
repoTask.setRepositoryId( TEST_REPO_ID );
|
||||
repoTask.setScanAll( false );
|
||||
|
||||
|
||||
RepositoryContentStatistics stats = new RepositoryContentStatistics();
|
||||
stats.setDuration( 1234567 );
|
||||
stats.setNewFileCount( 8 );
|
||||
stats.setRepositoryId( "testRepo" );
|
||||
stats.setRepositoryId( TEST_REPO_ID );
|
||||
stats.setTotalArtifactCount( 8 );
|
||||
stats.setTotalFileCount( 8 );
|
||||
stats.setTotalGroupCount( 3 );
|
||||
stats.setTotalProjectCount( 5 );
|
||||
stats.setTotalSize( 999999 );
|
||||
stats.setWhenGathered( Calendar.getInstance().getTime() );
|
||||
|
||||
|
||||
dao.getRepositoryContentStatisticsDAO().saveRepositoryContentStatistics( stats );
|
||||
|
||||
|
||||
taskExecutor.executeTask( repoTask );
|
||||
|
||||
ArtifactDAO adao = dao.getArtifactDAO();
|
||||
List<ArchivaArtifact> unprocessedResultList = adao.queryArtifacts( new ArtifactsProcessedConstraint( false ) );
|
||||
|
||||
|
||||
assertNotNull( unprocessedResultList );
|
||||
assertEquals("Incorrect number of unprocessed artifacts detected. No new artifacts should have been found.", 0, unprocessedResultList.size() );
|
||||
|
||||
File newArtifactGroup = new File( repoDir, "org/apache/archiva");
|
||||
|
||||
FileUtils.copyDirectoryStructure( new File( getBasedir(), "target/test-classes/test-repo/org/apache/archiva"), newArtifactGroup );
|
||||
|
||||
assertEquals( "Incorrect number of unprocessed artifacts detected. No new artifacts should have been found.", 0,
|
||||
unprocessedResultList.size() );
|
||||
|
||||
File newArtifactGroup = new File( repoDir, "org/apache/archiva" );
|
||||
|
||||
FileUtils.copyDirectoryStructure( new File( getBasedir(), "target/test-classes/test-repo/org/apache/archiva" ),
|
||||
newArtifactGroup );
|
||||
|
||||
// update last modified date
|
||||
new File( newArtifactGroup, "archiva-index-methods-jar-test/1.0/pom.xml" ).setLastModified( Calendar.getInstance().getTimeInMillis() + 1000 );
|
||||
new File( newArtifactGroup, "archiva-index-methods-jar-test/1.0/archiva-index-methods-jar-test-1.0.jar" ).setLastModified( Calendar.getInstance().getTimeInMillis() + 1000 );
|
||||
new File( newArtifactGroup, "archiva-index-methods-jar-test/1.0/pom.xml" ).setLastModified(
|
||||
Calendar.getInstance().getTimeInMillis() + 1000 );
|
||||
new File( newArtifactGroup,
|
||||
"archiva-index-methods-jar-test/1.0/archiva-index-methods-jar-test-1.0.jar" ).setLastModified(
|
||||
Calendar.getInstance().getTimeInMillis() + 1000 );
|
||||
|
||||
assertTrue( newArtifactGroup.exists() );
|
||||
|
||||
|
||||
taskExecutor.executeTask( repoTask );
|
||||
|
||||
|
||||
unprocessedResultList = adao.queryArtifacts( new ArtifactsProcessedConstraint( false ) );
|
||||
assertNotNull( unprocessedResultList );
|
||||
assertEquals( "Incorrect number of unprocessed artifacts detected. One new artifact should have been found.", 1, unprocessedResultList.size() );
|
||||
assertEquals( "Incorrect number of unprocessed artifacts detected. One new artifact should have been found.", 1,
|
||||
unprocessedResultList.size() );
|
||||
}
|
||||
|
||||
|
||||
public void testExecutorForceScanAll()
|
||||
throws Exception
|
||||
{
|
||||
assertTrue( "Default Test Repository should exist.", repoDir.exists() && repoDir.isDirectory() );
|
||||
|
||||
ArchivaConfiguration archivaConfig = (ArchivaConfiguration) lookup( ArchivaConfiguration.class );
|
||||
assertNotNull( archivaConfig );
|
||||
|
||||
// Create it
|
||||
ManagedRepositoryConfiguration repo = createRepository( "testRepo", "Test Repository", repoDir );
|
||||
assertNotNull( repo );
|
||||
archivaConfig.getConfiguration().getManagedRepositories().clear();
|
||||
archivaConfig.getConfiguration().addManagedRepository( repo );
|
||||
|
||||
RepositoryTask repoTask = new RepositoryTask();
|
||||
|
||||
repoTask.setRepositoryId( "testRepo" );
|
||||
|
||||
repoTask.setRepositoryId( TEST_REPO_ID );
|
||||
repoTask.setScanAll( true );
|
||||
|
||||
|
||||
RepositoryContentStatistics stats = new RepositoryContentStatistics();
|
||||
stats.setDuration( 1234567 );
|
||||
stats.setNewFileCount( 8 );
|
||||
stats.setRepositoryId( "testRepo" );
|
||||
stats.setRepositoryId( TEST_REPO_ID );
|
||||
stats.setTotalArtifactCount( 8 );
|
||||
stats.setTotalFileCount( 8 );
|
||||
stats.setTotalGroupCount( 3 );
|
||||
stats.setTotalProjectCount( 5 );
|
||||
stats.setTotalSize( 999999 );
|
||||
stats.setWhenGathered( Calendar.getInstance().getTime() );
|
||||
|
||||
|
||||
dao.getRepositoryContentStatisticsDAO().saveRepositoryContentStatistics( stats );
|
||||
|
||||
|
||||
taskExecutor.executeTask( repoTask );
|
||||
|
||||
ArtifactDAO adao = dao.getArtifactDAO();
|
||||
List<ArchivaArtifact> unprocessedResultList = adao.queryArtifacts( new ArtifactsProcessedConstraint( false ) );
|
||||
|
||||
|
||||
assertNotNull( unprocessedResultList );
|
||||
assertEquals("Incorrect number of unprocessed artifacts detected.", 8, unprocessedResultList.size() );
|
||||
}
|
||||
|
||||
protected ManagedRepositoryConfiguration createRepository( String id, String name, File location )
|
||||
{
|
||||
ManagedRepositoryConfiguration repo = new ManagedRepositoryConfiguration();
|
||||
repo.setId( id );
|
||||
repo.setName( name );
|
||||
repo.setLocation( location.getAbsolutePath() );
|
||||
return repo;
|
||||
assertEquals( "Incorrect number of unprocessed artifacts detected.", 8, unprocessedResultList.size() );
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user