diff options
author | Brett Porter <brett@apache.org> | 2009-12-04 00:05:01 +0000 |
---|---|---|
committer | Brett Porter <brett@apache.org> | 2009-12-04 00:05:01 +0000 |
commit | 3e47fdca1a98f346cc6a74a5fdb054c815bd17e0 (patch) | |
tree | 7d5468df2fb2cd0ac4161e828cd5b7d61ca3722c | |
parent | 5996457bf23bb7f435f1911fbce85ac4ed15f911 (diff) | |
download | archiva-3e47fdca1a98f346cc6a74a5fdb054c815bd17e0.tar.gz archiva-3e47fdca1a98f346cc6a74a5fdb054c815bd17e0.zip |
test case refactoring for clarity
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@887005 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | archiva-modules/archiva-scheduled/src/test/java/org/apache/maven/archiva/scheduled/executors/ArchivaRepositoryScanningTaskExecutorTest.java | 203 |
1 files changed, 90 insertions, 113 deletions
diff --git a/archiva-modules/archiva-scheduled/src/test/java/org/apache/maven/archiva/scheduled/executors/ArchivaRepositoryScanningTaskExecutorTest.java b/archiva-modules/archiva-scheduled/src/test/java/org/apache/maven/archiva/scheduled/executors/ArchivaRepositoryScanningTaskExecutorTest.java index 103d53dd9..1438af0a5 100644 --- a/archiva-modules/archiva-scheduled/src/test/java/org/apache/maven/archiva/scheduled/executors/ArchivaRepositoryScanningTaskExecutorTest.java +++ b/archiva-modules/archiva-scheduled/src/test/java/org/apache/maven/archiva/scheduled/executors/ArchivaRepositoryScanningTaskExecutorTest.java @@ -25,7 +25,6 @@ import java.util.Calendar; 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.codehaus.plexus.util.FileUtils; 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 @@ public class ArchivaRepositoryScanningTaskExecutorTest 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 @@ public class ArchivaRepositoryScanningTaskExecutorTest 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 @@ public class ArchivaRepositoryScanningTaskExecutorTest 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 ); + ManagedRepositoryConfiguration repositoryConfiguration = new ManagedRepositoryConfiguration(); + repositoryConfiguration.setId( TEST_REPO_ID ); + repositoryConfiguration.setName( "Test Repository" ); + repositoryConfiguration.setLocation( repoDir.getAbsolutePath() ); archivaConfig.getConfiguration().getManagedRepositories().clear(); - archivaConfig.getConfiguration().addManagedRepository( repo ); + 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() ); } } |