aboutsummaryrefslogtreecommitdiffstats
path: root/archiva-base/archiva-indexer/src/test
diff options
context:
space:
mode:
authorJoakim Erdfelt <joakime@apache.org>2007-04-24 05:40:19 +0000
committerJoakim Erdfelt <joakime@apache.org>2007-04-24 05:40:19 +0000
commitc5839cb7f11a01b54db926d5f1159db6ff28bf69 (patch)
treeee1c86ee04bf6d5432822eb36d786ff112d690ae /archiva-base/archiva-indexer/src/test
parentd9e4b87d608b07d5f74b58f19cc74d8540a5e2af (diff)
downloadarchiva-c5839cb7f11a01b54db926d5f1159db6ff28bf69.tar.gz
archiva-c5839cb7f11a01b54db926d5f1159db6ff28bf69.zip
* Adding CrossRepositorySearch component.
git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/branches/archiva-jpox-database-refactor@531746 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-base/archiva-indexer/src/test')
-rw-r--r--archiva-base/archiva-indexer/src/test/java/org/apache/maven/archiva/indexer/AbstractIndexerTestCase.java40
-rw-r--r--archiva-base/archiva-indexer/src/test/java/org/apache/maven/archiva/indexer/MockConfiguration.java40
-rw-r--r--archiva-base/archiva-indexer/src/test/java/org/apache/maven/archiva/indexer/search/BytecodeIndexPopulator.java141
-rw-r--r--archiva-base/archiva-indexer/src/test/java/org/apache/maven/archiva/indexer/search/DefaultCrossRepositorySearchTest.java131
-rw-r--r--archiva-base/archiva-indexer/src/test/java/org/apache/maven/archiva/indexer/search/FileContentIndexPopulator.java82
-rw-r--r--archiva-base/archiva-indexer/src/test/java/org/apache/maven/archiva/indexer/search/HashcodesIndexPopulator.java114
-rw-r--r--archiva-base/archiva-indexer/src/test/java/org/apache/maven/archiva/indexer/search/IndexPopulator.java36
-rw-r--r--archiva-base/archiva-indexer/src/test/resources/org/apache/maven/archiva/indexer/search/DefaultCrossRepositorySearchTest.xml40
8 files changed, 611 insertions, 13 deletions
diff --git a/archiva-base/archiva-indexer/src/test/java/org/apache/maven/archiva/indexer/AbstractIndexerTestCase.java b/archiva-base/archiva-indexer/src/test/java/org/apache/maven/archiva/indexer/AbstractIndexerTestCase.java
index 709f544fe..62b7b1b6f 100644
--- a/archiva-base/archiva-indexer/src/test/java/org/apache/maven/archiva/indexer/AbstractIndexerTestCase.java
+++ b/archiva-base/archiva-indexer/src/test/java/org/apache/maven/archiva/indexer/AbstractIndexerTestCase.java
@@ -46,7 +46,8 @@ import java.util.Map;
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
* @version $Id$
*/
-public abstract class AbstractIndexerTestCase extends PlexusTestCase
+public abstract class AbstractIndexerTestCase
+ extends PlexusTestCase
{
protected RepositoryContentIndex index;
@@ -72,14 +73,32 @@ public abstract class AbstractIndexerTestCase extends PlexusTestCase
public abstract LuceneIndexHandlers getIndexHandler();
- protected void setUp() throws Exception
+ protected void setUp()
+ throws Exception
{
super.setUp();
- RepositoryContentIndexFactory indexFactory =
- (RepositoryContentIndexFactory) lookup( RepositoryContentIndexFactory.class.getName(), "lucene" );
+ RepositoryContentIndexFactory indexFactory = (RepositoryContentIndexFactory) lookup(
+ RepositoryContentIndexFactory.class
+ .getName(), "lucene" );
+ ArchivaRepository repository = createTestIndex( getIndexName() );
+
+ index = createIndex( indexFactory, repository );
+
+ indexHandlers = getIndexHandler();
+ }
+
+ private ArchivaRepository createTestIndex( String indexName )
+ throws Exception, IOException
+ {
File repoDir = new File( getBasedir(), "src/test/managed-repository" );
+ File testIndexesDir = new File( getBasedir(), "target/test-indexes" );
+
+ if ( !testIndexesDir.exists() )
+ {
+ testIndexesDir.mkdirs();
+ }
assertTrue( "Default Test Repository should exist.", repoDir.exists() && repoDir.isDirectory() );
@@ -87,7 +106,7 @@ public abstract class AbstractIndexerTestCase extends PlexusTestCase
ArchivaRepository repository = new ArchivaRepository( "testDefaultRepo", "Test Default Repository", repoUri );
- File indexLocation = new File( "target/index-" + getIndexName() + "-" + getName() + "/" );
+ File indexLocation = new File( testIndexesDir, "/index-" + indexName + "-" + getName() + "/" );
MockConfiguration config = (MockConfiguration) lookup( ArchivaConfiguration.class.getName(), "mock" );
@@ -103,10 +122,7 @@ public abstract class AbstractIndexerTestCase extends PlexusTestCase
}
config.getConfiguration().addRepository( repoConfig );
-
- index = createIndex( indexFactory, repository );
-
- indexHandlers = getIndexHandler();
+ return repository;
}
protected Map getArchivaArtifactDumpMap()
@@ -189,12 +205,14 @@ public abstract class AbstractIndexerTestCase extends PlexusTestCase
return artifact;
}
- protected void createEmptyIndex() throws IOException
+ protected void createEmptyIndex()
+ throws IOException
{
createIndex( Collections.EMPTY_LIST );
}
- protected void createIndex( List documents ) throws IOException
+ protected void createIndex( List documents )
+ throws IOException
{
IndexWriter writer = new IndexWriter( index.getIndexDirectory(), indexHandlers.getAnalyzer(), true );
for ( Iterator i = documents.iterator(); i.hasNext(); )
diff --git a/archiva-base/archiva-indexer/src/test/java/org/apache/maven/archiva/indexer/MockConfiguration.java b/archiva-base/archiva-indexer/src/test/java/org/apache/maven/archiva/indexer/MockConfiguration.java
index c856f5499..249b4d7ae 100644
--- a/archiva-base/archiva-indexer/src/test/java/org/apache/maven/archiva/indexer/MockConfiguration.java
+++ b/archiva-base/archiva-indexer/src/test/java/org/apache/maven/archiva/indexer/MockConfiguration.java
@@ -21,8 +21,14 @@ package org.apache.maven.archiva.indexer;
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.configuration.Configuration;
+import org.codehaus.plexus.registry.Registry;
import org.codehaus.plexus.registry.RegistryException;
import org.codehaus.plexus.registry.RegistryListener;
+import org.easymock.MockControl;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
/**
* MockConfiguration
@@ -37,9 +43,21 @@ public class MockConfiguration implements ArchivaConfiguration
{
private Configuration configuration = new Configuration();
+ private List listeners = new ArrayList();
+
+ private MockControl registryControl;
+
+ private Registry registryMock;
+
+ public MockConfiguration()
+ {
+ registryControl = MockControl.createNiceControl( Registry.class );
+ registryMock = (Registry) registryControl.getMock();
+ }
+
public void addChangeListener( RegistryListener listener )
{
- /* do nothing */
+ listeners.add( listener );
}
public Configuration getConfiguration()
@@ -47,8 +65,26 @@ public class MockConfiguration implements ArchivaConfiguration
return configuration;
}
- public void save( Configuration configuration ) throws RegistryException
+ public void save( Configuration configuration )
+ throws RegistryException
{
/* do nothing */
}
+
+ public void triggerChange( String name, String value )
+ {
+ Iterator it = listeners.iterator();
+ while ( it.hasNext() )
+ {
+ RegistryListener listener = (RegistryListener) it.next();
+ try
+ {
+ listener.afterConfigurationChange( registryMock, name, value );
+ }
+ catch ( Exception e )
+ {
+ e.printStackTrace();
+ }
+ }
+ }
}
diff --git a/archiva-base/archiva-indexer/src/test/java/org/apache/maven/archiva/indexer/search/BytecodeIndexPopulator.java b/archiva-base/archiva-indexer/src/test/java/org/apache/maven/archiva/indexer/search/BytecodeIndexPopulator.java
new file mode 100644
index 000000000..f79f115f2
--- /dev/null
+++ b/archiva-base/archiva-indexer/src/test/java/org/apache/maven/archiva/indexer/search/BytecodeIndexPopulator.java
@@ -0,0 +1,141 @@
+package org.apache.maven.archiva.indexer.search;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.archiva.indexer.bytecode.BytecodeRecord;
+import org.apache.maven.archiva.indexer.bytecode.BytecodeRecordLoader;
+import org.apache.maven.archiva.model.ArchivaArtifact;
+
+import java.io.File;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import junit.framework.AssertionFailedError;
+
+/**
+ * BytecodeIndexPopulator
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class BytecodeIndexPopulator
+ implements IndexPopulator
+{
+
+ public Map getObjectMap()
+ {
+
+ Map dumps = new HashMap();
+
+ // archiva-common-1.0.jar.txt
+ dumps.put( "archiva-common", createArchivaArtifact( "org.apache.maven.archiva", "archiva-common", "1.0", "",
+ "jar" ) );
+
+ // continuum-webapp-1.0.3-SNAPSHOT.war.txt
+ dumps.put( "continuum-webapp", createArchivaArtifact( "org.apache.maven.continuum", "continuum-webapp",
+ "1.0.3-SNAPSHOT", "", "war" ) );
+
+ // daytrader-ear-1.1.ear.txt
+ dumps.put( "daytrader-ear", createArchivaArtifact( "org.apache.geronimo", "daytrader-ear", "1.1", "", "ear" ) );
+
+ // maven-archetype-simple-1.0-alpha-4.jar.txt
+ dumps.put( "maven-archetype-simple", createArchivaArtifact( "org.apache.maven", "maven-archetype-simple",
+ "1.0-alpha-4", "", "maven-archetype" ) );
+
+ // maven-help-plugin-2.0.2-20070119.121239-2.jar.txt
+ dumps.put( "maven-help-plugin", createArchivaArtifact( "org.apache.maven.plugins", "maven-help-plugin",
+ "2.0.2-20070119.121239-2", "", "maven-plugin" ) );
+
+ // redback-authorization-open-1.0-alpha-1-SNAPSHOT.jar.txt
+ dumps.put( "redback-authorization-open", createArchivaArtifact( "org.codehaus.plexus.redback",
+ "redback-authorization-open",
+ "1.0-alpha-1-SNAPSHOT", "", "jar" ) );
+
+ // testng-5.1-jdk15.jar.txt
+ dumps.put( "testng", createArchivaArtifact( "org.testng", "testng", "5.1", "jdk15", "jar" ) );
+
+ // wagon-provider-api-1.0-beta-3-20070209.213958-2.jar.txt
+ dumps.put( "wagon-provider-api", createArchivaArtifact( "org.apache.maven.wagon", "wagon-provider-api",
+ "1.0-beta-3-20070209.213958-2", "", "jar" ) );
+
+ return dumps;
+
+ }
+
+ private ArchivaArtifact createArchivaArtifact( String groupId, String artifactId, String version,
+ String classifier, String type )
+ {
+ ArchivaArtifact artifact = new ArchivaArtifact( groupId, artifactId, version, classifier, type );
+ return artifact;
+ }
+
+ public Map populate( File basedir )
+ {
+ Map records = new HashMap();
+
+ Map artifactDumps = getObjectMap();
+ for ( Iterator iter = artifactDumps.entrySet().iterator(); iter.hasNext(); )
+ {
+ Map.Entry entry = (Map.Entry) iter.next();
+ ArchivaArtifact artifact = (ArchivaArtifact) entry.getValue();
+ File dumpFile = getDumpFile( basedir, artifact );
+ BytecodeRecord record = BytecodeRecordLoader.loadRecord( dumpFile, artifact );
+ records.put( entry.getKey(), record );
+ }
+
+ return records;
+ }
+
+ protected File getDumpFile( File basedir, ArchivaArtifact artifact )
+ {
+ File dumpDir = new File( basedir, "src/test/artifact-dumps" );
+ StringBuffer filename = new StringBuffer();
+
+ filename.append( artifact.getArtifactId() ).append( "-" ).append( artifact.getVersion() );
+
+ if ( artifact.hasClassifier() )
+ {
+ filename.append( "-" ).append( artifact.getClassifier() );
+ }
+
+ filename.append( "." );
+
+ // TODO: use the ArtifactExtensionMapping object!
+ if ( "maven-plugin".equals( artifact.getType() ) || "maven-archetype".equals( artifact.getType() ) )
+ {
+ filename.append( "jar" );
+ }
+ else
+ {
+ filename.append( artifact.getType() );
+ }
+ filename.append( ".txt" );
+
+ File dumpFile = new File( dumpDir, filename.toString() );
+
+ if ( !dumpFile.exists() )
+ {
+ throw new AssertionFailedError( "Dump file " + dumpFile.getAbsolutePath() + " does not exist (should it?)." );
+ }
+
+ return dumpFile;
+ }
+}
diff --git a/archiva-base/archiva-indexer/src/test/java/org/apache/maven/archiva/indexer/search/DefaultCrossRepositorySearchTest.java b/archiva-base/archiva-indexer/src/test/java/org/apache/maven/archiva/indexer/search/DefaultCrossRepositorySearchTest.java
new file mode 100644
index 000000000..821ba572d
--- /dev/null
+++ b/archiva-base/archiva-indexer/src/test/java/org/apache/maven/archiva/indexer/search/DefaultCrossRepositorySearchTest.java
@@ -0,0 +1,131 @@
+package org.apache.maven.archiva.indexer.search;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.maven.archiva.configuration.ArchivaConfiguration;
+import org.apache.maven.archiva.configuration.RepositoryConfiguration;
+import org.apache.maven.archiva.indexer.MockConfiguration;
+import org.apache.maven.archiva.indexer.RepositoryContentIndex;
+import org.apache.maven.archiva.indexer.RepositoryContentIndexFactory;
+import org.apache.maven.archiva.model.ArchivaRepository;
+import org.codehaus.plexus.PlexusTestCase;
+import org.codehaus.plexus.util.FileUtils;
+
+import java.io.File;
+import java.util.Map;
+
+/**
+ * DefaultCrossRepositorySearchTest
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class DefaultCrossRepositorySearchTest
+ extends PlexusTestCase
+{
+
+ 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( "testDefaultRepo", "Test Default Repository", repoUri );
+
+ File indexLocation = new File( "target/index-crossrepo-" + getName() + "/" );
+
+ MockConfiguration config = (MockConfiguration) lookup( ArchivaConfiguration.class.getName(), "mock" );
+
+ RepositoryConfiguration repoConfig = new RepositoryConfiguration();
+ repoConfig.setId( repository.getId() );
+ repoConfig.setName( repository.getModel().getName() );
+ repoConfig.setUrl( repository.getModel().getUrl() );
+ repoConfig.setIndexDir( indexLocation.getAbsolutePath() );
+
+ if ( indexLocation.exists() )
+ {
+ FileUtils.deleteDirectory( indexLocation );
+ }
+
+ config.getConfiguration().addRepository( 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() );
+ Map bytecodeMap = ( new BytecodeIndexPopulator() ).populate( new File( getBasedir() ) );
+ indexBytecode.indexRecords( bytecodeMap.values() );
+ Map contentMap = ( new FileContentIndexPopulator() ).populate( new File( getBasedir() ) );
+ indexContents.indexRecords( contentMap.values() );
+ }
+
+ private CrossRepositorySearch lookupCrossRepositorySearch()
+ throws Exception
+ {
+ CrossRepositorySearch search = (CrossRepositorySearch) lookup( CrossRepositorySearch.class.getName(), "default" );
+ assertNotNull( "CrossRepositorySearch:default should not be null.", search );
+ return search;
+ }
+
+ public void testSearchTerm()
+ throws Exception
+ {
+ CrossRepositorySearch search = lookupCrossRepositorySearch();
+
+ SearchResults results = search.searchForTerm( "org" );
+ assertHitCounts( 1, 8, 8, 1, results );
+
+ results = search.searchForTerm( "junit" );
+ assertHitCounts( 1, 1, 0, 1, results );
+
+ results = search.searchForTerm( "monosodium" );
+ assertHitCounts( 1, 0, 0, 0, results );
+ }
+
+ private void assertHitCounts( int repoCount, int bytecodeCount, int hashcodeCount, int contentCount,
+ SearchResults results )
+ {
+ assertNotNull( "Search Results should not be null.", results );
+ assertEquals( "Repository Hits", repoCount, results.getRepositories().size() );
+
+ if ( ( bytecodeCount != results.getBytecodeHits().size() )
+ || ( hashcodeCount != results.getHashcodeHits().size() )
+ || ( contentCount != results.getContentHits().size() ) )
+ {
+ fail( "Failed to get expected results hit count. Expected: (bytecode,hashcode,content) <" + bytecodeCount
+ + "," + hashcodeCount + "," + contentCount + ">, but got <" + results.getBytecodeHits().size() + ","
+ + results.getHashcodeHits().size() + "," + results.getContentHits().size() + "> instead." );
+ }
+ }
+}
diff --git a/archiva-base/archiva-indexer/src/test/java/org/apache/maven/archiva/indexer/search/FileContentIndexPopulator.java b/archiva-base/archiva-indexer/src/test/java/org/apache/maven/archiva/indexer/search/FileContentIndexPopulator.java
new file mode 100644
index 000000000..9a8bdb44d
--- /dev/null
+++ b/archiva-base/archiva-indexer/src/test/java/org/apache/maven/archiva/indexer/search/FileContentIndexPopulator.java
@@ -0,0 +1,82 @@
+package org.apache.maven.archiva.indexer.search;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.commons.io.FileUtils;
+import org.apache.maven.archiva.indexer.filecontent.FileContentRecord;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import junit.framework.AssertionFailedError;
+
+/**
+ * FileContentIndexPopulator
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class FileContentIndexPopulator
+ implements IndexPopulator
+{
+ public Map getObjectMap()
+ {
+ return null;
+ }
+
+ public Map populate( File basedir )
+ {
+ Map map = new HashMap();
+
+ File repoDir = new File( basedir, "src/test/managed-repository" );
+
+ map.put( "parent-pom-1",
+ createFileContentRecord( repoDir, "org/apache/maven/archiva/record/parent-pom/1/parent-pom-1.pom" ) );
+
+ return map;
+ }
+
+ private FileContentRecord createFileContentRecord( File repoDir, String path )
+ {
+ File pathToFile = new File( repoDir, path );
+
+ if ( !pathToFile.exists() )
+ {
+ throw new AssertionFailedError( "Can't find test file: " + pathToFile.getAbsolutePath() );
+ }
+
+ FileContentRecord record = new FileContentRecord();
+ record.setFile( pathToFile );
+
+ try
+ {
+ record.setContents( FileUtils.readFileToString( pathToFile, null ) );
+ }
+ catch ( IOException e )
+ {
+ e.printStackTrace();
+ throw new AssertionFailedError( "Can't load test file contents: " + pathToFile.getAbsolutePath() );
+ }
+
+ return record;
+ }
+}
diff --git a/archiva-base/archiva-indexer/src/test/java/org/apache/maven/archiva/indexer/search/HashcodesIndexPopulator.java b/archiva-base/archiva-indexer/src/test/java/org/apache/maven/archiva/indexer/search/HashcodesIndexPopulator.java
new file mode 100644
index 000000000..f61ce86e4
--- /dev/null
+++ b/archiva-base/archiva-indexer/src/test/java/org/apache/maven/archiva/indexer/search/HashcodesIndexPopulator.java
@@ -0,0 +1,114 @@
+package org.apache.maven.archiva.indexer.search;
+
+import org.apache.maven.archiva.indexer.hashcodes.HashcodesRecord;
+import org.apache.maven.archiva.indexer.hashcodes.HashcodesRecordLoader;
+import org.apache.maven.archiva.model.ArchivaArtifact;
+
+import java.io.File;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import junit.framework.AssertionFailedError;
+
+public class HashcodesIndexPopulator
+ implements IndexPopulator
+{
+
+ public Map getObjectMap()
+ {
+ Map dumps = new HashMap();
+
+ // archiva-common-1.0.jar.txt
+ dumps.put( "archiva-common", createArchivaArtifact( "org.apache.maven.archiva", "archiva-common", "1.0", "",
+ "jar" ) );
+
+ // continuum-webapp-1.0.3-SNAPSHOT.war.txt
+ dumps.put( "continuum-webapp", createArchivaArtifact( "org.apache.maven.continuum", "continuum-webapp",
+ "1.0.3-SNAPSHOT", "", "war" ) );
+
+ // daytrader-ear-1.1.ear.txt
+ dumps.put( "daytrader-ear", createArchivaArtifact( "org.apache.geronimo", "daytrader-ear", "1.1", "", "ear" ) );
+
+ // maven-archetype-simple-1.0-alpha-4.jar.txt
+ dumps.put( "maven-archetype-simple", createArchivaArtifact( "org.apache.maven", "maven-archetype-simple",
+ "1.0-alpha-4", "", "maven-archetype" ) );
+
+ // maven-help-plugin-2.0.2-20070119.121239-2.jar.txt
+ dumps.put( "maven-help-plugin", createArchivaArtifact( "org.apache.maven.plugins", "maven-help-plugin",
+ "2.0.2-20070119.121239-2", "", "maven-plugin" ) );
+
+ // redback-authorization-open-1.0-alpha-1-SNAPSHOT.jar.txt
+ dumps.put( "redback-authorization-open", createArchivaArtifact( "org.codehaus.plexus.redback",
+ "redback-authorization-open",
+ "1.0-alpha-1-SNAPSHOT", "", "jar" ) );
+
+ // testng-5.1-jdk15.jar.txt
+ dumps.put( "testng", createArchivaArtifact( "org.testng", "testng", "5.1", "jdk15", "jar" ) );
+
+ // wagon-provider-api-1.0-beta-3-20070209.213958-2.jar.txt
+ dumps.put( "wagon-provider-api", createArchivaArtifact( "org.apache.maven.wagon", "wagon-provider-api",
+ "1.0-beta-3-20070209.213958-2", "", "jar" ) );
+
+ return dumps;
+ }
+
+ public Map populate( File basedir )
+ {
+ Map records = new HashMap();
+
+ Map artifactDumps = getObjectMap();
+ for ( Iterator iter = artifactDumps.entrySet().iterator(); iter.hasNext(); )
+ {
+ Map.Entry entry = (Map.Entry) iter.next();
+ ArchivaArtifact artifact = (ArchivaArtifact) entry.getValue();
+ File dumpFile = getDumpFile( basedir, artifact );
+ HashcodesRecord record = HashcodesRecordLoader.loadRecord( dumpFile, artifact );
+ records.put( entry.getKey(), record );
+ }
+
+ return records;
+ }
+
+ protected File getDumpFile( File basedir, ArchivaArtifact artifact )
+ {
+ File dumpDir = new File( basedir, "src/test/artifact-dumps" );
+ StringBuffer filename = new StringBuffer();
+
+ filename.append( artifact.getArtifactId() ).append( "-" ).append( artifact.getVersion() );
+
+ if ( artifact.hasClassifier() )
+ {
+ filename.append( "-" ).append( artifact.getClassifier() );
+ }
+
+ filename.append( "." );
+
+ // TODO: use the ArtifactExtensionMapping object!
+ if ( "maven-plugin".equals( artifact.getType() ) || "maven-archetype".equals( artifact.getType() ) )
+ {
+ filename.append( "jar" );
+ }
+ else
+ {
+ filename.append( artifact.getType() );
+ }
+ filename.append( ".txt" );
+
+ File dumpFile = new File( dumpDir, filename.toString() );
+
+ if ( !dumpFile.exists() )
+ {
+ throw new AssertionFailedError( "Dump file " + dumpFile.getAbsolutePath() + " does not exist (should it?)." );
+ }
+
+ return dumpFile;
+ }
+
+ private ArchivaArtifact createArchivaArtifact( String groupId, String artifactId, String version,
+ String classifier, String type )
+ {
+ ArchivaArtifact artifact = new ArchivaArtifact( groupId, artifactId, version, classifier, type );
+ return artifact;
+ }
+}
diff --git a/archiva-base/archiva-indexer/src/test/java/org/apache/maven/archiva/indexer/search/IndexPopulator.java b/archiva-base/archiva-indexer/src/test/java/org/apache/maven/archiva/indexer/search/IndexPopulator.java
new file mode 100644
index 000000000..66897393e
--- /dev/null
+++ b/archiva-base/archiva-indexer/src/test/java/org/apache/maven/archiva/indexer/search/IndexPopulator.java
@@ -0,0 +1,36 @@
+package org.apache.maven.archiva.indexer.search;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.File;
+import java.util.Map;
+
+/**
+ * IndexPopulator
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public interface IndexPopulator
+{
+ public Map getObjectMap();
+
+ public Map populate( File basedir );
+}
diff --git a/archiva-base/archiva-indexer/src/test/resources/org/apache/maven/archiva/indexer/search/DefaultCrossRepositorySearchTest.xml b/archiva-base/archiva-indexer/src/test/resources/org/apache/maven/archiva/indexer/search/DefaultCrossRepositorySearchTest.xml
new file mode 100644
index 000000000..61a859c7a
--- /dev/null
+++ b/archiva-base/archiva-indexer/src/test/resources/org/apache/maven/archiva/indexer/search/DefaultCrossRepositorySearchTest.xml
@@ -0,0 +1,40 @@
+<component-set>
+ <components>
+ <component>
+ <role>org.apache.maven.archiva.configuration.ArchivaConfiguration</role>
+ <role-hint>mock</role-hint>
+ <implementation>org.apache.maven.archiva.indexer.MockConfiguration</implementation>
+ </component>
+ <component>
+ <role>org.apache.maven.archiva.indexer.RepositoryContentIndexFactory</role>
+ <role-hint>lucene</role-hint>
+ <implementation>org.apache.maven.archiva.indexer.lucene.LuceneRepositoryContentIndexFactory</implementation>
+ <description>Factory for Lucene repository content index instances.</description>
+ <requirements>
+ <requirement>
+ <role>org.apache.maven.archiva.configuration.ArchivaConfiguration</role>
+ <role-hint>mock</role-hint>
+ <field-name>configuration</field-name>
+ </requirement>
+ </requirements>
+ </component>
+ <component>
+ <role>org.apache.maven.archiva.indexer.search.CrossRepositorySearch</role>
+ <role-hint>default</role-hint>
+ <implementation>org.apache.maven.archiva.indexer.search.DefaultCrossRepositorySearch</implementation>
+ <description>DefaultCrossRepositorySearch</description>
+ <requirements>
+ <requirement>
+ <role>org.apache.maven.archiva.indexer.RepositoryContentIndexFactory</role>
+ <role-hint>lucene</role-hint>
+ <field-name>indexFactory</field-name>
+ </requirement>
+ <requirement>
+ <role>org.apache.maven.archiva.configuration.ArchivaConfiguration</role>
+ <role-hint>mock</role-hint>
+ <field-name>configuration</field-name>
+ </requirement>
+ </requirements>
+ </component>
+ </components>
+</component-set>