protected void setUp()
throws Exception
{
super.setUp();
RepositoryContentIndexFactory indexFactory =
(RepositoryContentIndexFactory) lookup( RepositoryContentIndexFactory.class
.getName(), "lucene" );
File repoDir = new File( getBasedir(), "src/test/managed-repository" );
assertTrue( "Default Test Repository should exist.", repoDir.exists() && repoDir.isDirectory() );
String repoUri = "file://" + StringUtils.replace( repoDir.getAbsolutePath(), "\\", "/" );
ArchivaRepository repository =
new ArchivaRepository( TEST_DEFAULT_REPO_ID, TEST_DEFAULT_REPOSITORY_NAME, repoUri );
File indexLocation = new File( "target/index-crossrepo-" + getName() + "/" );
MockConfiguration config = (MockConfiguration) lookup( ArchivaConfiguration.class.getName(), "mock" );
ManagedRepositoryConfiguration repoConfig = new ManagedRepositoryConfiguration();
repoConfig.setId( TEST_DEFAULT_REPO_ID );
repoConfig.setName( TEST_DEFAULT_REPOSITORY_NAME );
repoConfig.setLocation( repoDir.getAbsolutePath() );
repoConfig.setIndexDir( indexLocation.getAbsolutePath() );
repoConfig.setScanned( true );
if ( indexLocation.exists() )
{
FileUtils.deleteDirectory( indexLocation );
}
config.getConfiguration().addManagedRepository( repoConfig );
// Create the (empty) indexes.
RepositoryContentIndex indexHashcode = indexFactory.createHashcodeIndex( repository );
RepositoryContentIndex indexBytecode = indexFactory.createBytecodeIndex( repository );
RepositoryContentIndex indexContents = indexFactory.createFileContentIndex( repository );
// Now populate them.
Map hashcodesMap = ( new HashcodesIndexPopulator() ).populate( new File( getBasedir() ) );
indexHashcode.indexRecords( hashcodesMap.values() );
assertEquals( "Hashcode Key Count", hashcodesMap.size(), indexHashcode.getAllRecordKeys().size() );