diff options
author | Joakim Erdfelt <joakime@apache.org> | 2007-05-25 15:05:51 +0000 |
---|---|---|
committer | Joakim Erdfelt <joakime@apache.org> | 2007-05-25 15:05:51 +0000 |
commit | 0c61521ddeacaa239a4dede80efabe0642e9f463 (patch) | |
tree | 19905f2c11e5814fbdb048c910bafde9e7c56196 /archiva-base/archiva-indexer/src/test | |
parent | cb92f4907fd38a99468204d83c7ab257a69eda8c (diff) | |
download | archiva-0c61521ddeacaa239a4dede80efabe0642e9f463.tar.gz archiva-0c61521ddeacaa239a4dede80efabe0642e9f463.zip |
[MRM-330]: Searching gives an HTTP 500
Next phase of work towards a search/find fix.
Many improvements in indexer / configuration
git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@541680 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-base/archiva-indexer/src/test')
12 files changed, 300 insertions, 82 deletions
diff --git a/archiva-base/archiva-indexer/src/test/java/org/apache/maven/archiva/indexer/AbstractSearchTestCase.java b/archiva-base/archiva-indexer/src/test/java/org/apache/maven/archiva/indexer/AbstractSearchTestCase.java index 5d4d62cb4..0cf046f86 100644 --- a/archiva-base/archiva-indexer/src/test/java/org/apache/maven/archiva/indexer/AbstractSearchTestCase.java +++ b/archiva-base/archiva-indexer/src/test/java/org/apache/maven/archiva/indexer/AbstractSearchTestCase.java @@ -19,14 +19,19 @@ package org.apache.maven.archiva.indexer; * under the License. */ +import org.apache.lucene.document.Document; import org.apache.lucene.index.Term; import org.apache.lucene.queryParser.ParseException; import org.apache.lucene.queryParser.QueryParser; +import org.apache.lucene.search.Hit; +import org.apache.lucene.search.Hits; import org.apache.lucene.search.Query; +import org.apache.lucene.search.Searcher; import org.apache.lucene.search.TermQuery; -import org.apache.maven.archiva.indexer.lucene.LuceneQuery; import org.apache.maven.archiva.indexer.lucene.LuceneRepositoryContentRecord; +import java.io.IOException; +import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -39,13 +44,15 @@ import junit.framework.ComparisonFailure; * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a> * @version $Id$ */ -public abstract class AbstractSearchTestCase extends AbstractIndexerTestCase +public abstract class AbstractSearchTestCase + extends AbstractIndexerTestCase { protected Map records; protected abstract Map createSampleRecordsMap(); - protected void setUp() throws Exception + protected void setUp() + throws Exception { super.setUp(); @@ -59,7 +66,8 @@ public abstract class AbstractSearchTestCase extends AbstractIndexerTestCase return new TermQuery( new Term( field, value ) ); } - protected Query createMatchQuery( String field, String value ) throws ParseException + protected Query createMatchQuery( String field, String value ) + throws ParseException { QueryParser queryParser = new QueryParser( field, indexHandlers.getAnalyzer() ); queryParser.setLowercaseExpandedTerms( true ); @@ -81,8 +89,8 @@ public abstract class AbstractSearchTestCase extends AbstractIndexerTestCase if ( expectedKeys.length != actualResults.size() ) { dumpResults( actualResults ); - throw new ComparisonFailure( "Results count", String.valueOf( expectedKeys.length ), - String.valueOf( actualResults.size() ) ); + throw new ComparisonFailure( "Results count", String.valueOf( expectedKeys.length ), String + .valueOf( actualResults.size() ) ); } assertEquals( "Results count", expectedKeys.length, actualResults.size() ); @@ -96,8 +104,7 @@ public abstract class AbstractSearchTestCase extends AbstractIndexerTestCase { dumpResults( actualResults ); fail( "Expected record <" + key - + "> not in records map (smack the unit test developer, tell them to fix method " - + getName() + ")" ); + + "> not in records map (smack the unit test developer, tell them to fix method " + getName() + ")" ); } if ( !actualResults.contains( record ) ) @@ -133,31 +140,56 @@ public abstract class AbstractSearchTestCase extends AbstractIndexerTestCase } } - protected void assertQueryExactMatchNoResults( String key, String term ) throws RepositoryIndexSearchException + protected void assertQueryExactMatchNoResults( String key, String term ) + throws Exception { Query query = createExactMatchQuery( key, term ); - List results = index.search( new LuceneQuery( query ) ); + List results = search( query ); assertNoResults( results ); } - protected void assertQueryExactMatch( String key, String names[], String term ) throws RepositoryIndexSearchException + protected void assertQueryExactMatch( String key, String names[], String term ) + throws Exception { Query query = createExactMatchQuery( key, term ); - List results = index.search( new LuceneQuery( query ) ); + List results = search( query ); assertResults( names, results ); } - protected void assertQueryMatch( String key, String names[], String term ) throws Exception + protected void assertQueryMatch( String key, String names[], String term ) + throws Exception { Query query = createMatchQuery( key, term ); - List results = index.search( new LuceneQuery( query ) ); + List results = search( query ); assertResults( names, results ); } - protected void assertQueryMatchNoResults( String key, String term ) throws Exception + protected void assertQueryMatchNoResults( String key, String term ) + throws Exception { Query query = createMatchQuery( key, term ); - List results = index.search( new LuceneQuery( query ) ); + + List results = search( query ); + assertNoResults( results ); } + + protected List search( Query query ) + throws RepositoryIndexSearchException, IOException, java.text.ParseException + { + Searcher searcher = (Searcher) index.getSearchable();; // this shouldn't cause a problem. + + Hits hits = searcher.search( query ); + + List results = new ArrayList(); + Iterator it = hits.iterator(); + while ( it.hasNext() ) + { + Hit hit = (Hit) it.next(); + Document doc = hit.getDocument(); + LuceneRepositoryContentRecord record = index.getEntryConverter().convert( doc ); + results.add( record ); + } + return results; + } } diff --git a/archiva-base/archiva-indexer/src/test/java/org/apache/maven/archiva/indexer/AllTests.java b/archiva-base/archiva-indexer/src/test/java/org/apache/maven/archiva/indexer/AllTests.java index 2cd47bfc6..82bcb2158 100644 --- a/archiva-base/archiva-indexer/src/test/java/org/apache/maven/archiva/indexer/AllTests.java +++ b/archiva-base/archiva-indexer/src/test/java/org/apache/maven/archiva/indexer/AllTests.java @@ -38,6 +38,7 @@ public class AllTests suite.addTest( org.apache.maven.archiva.indexer.bytecode.AllTests.suite() ); suite.addTest( org.apache.maven.archiva.indexer.hashcodes.AllTests.suite() ); suite.addTest( org.apache.maven.archiva.indexer.query.AllTests.suite() ); + suite.addTest( org.apache.maven.archiva.indexer.search.AllTests.suite() ); //$JUnit-END$ return suite; } diff --git a/archiva-base/archiva-indexer/src/test/java/org/apache/maven/archiva/indexer/bytecode/BytecodeSearchTest.java b/archiva-base/archiva-indexer/src/test/java/org/apache/maven/archiva/indexer/bytecode/BytecodeSearchTest.java index 47b22721e..0dadb2761 100644 --- a/archiva-base/archiva-indexer/src/test/java/org/apache/maven/archiva/indexer/bytecode/BytecodeSearchTest.java +++ b/archiva-base/archiva-indexer/src/test/java/org/apache/maven/archiva/indexer/bytecode/BytecodeSearchTest.java @@ -26,9 +26,7 @@ import org.apache.maven.archiva.indexer.AbstractSearchTestCase; import org.apache.maven.archiva.indexer.ArtifactKeys; import org.apache.maven.archiva.indexer.RepositoryContentIndex; import org.apache.maven.archiva.indexer.RepositoryContentIndexFactory; -import org.apache.maven.archiva.indexer.RepositoryIndexSearchException; import org.apache.maven.archiva.indexer.lucene.LuceneIndexHandlers; -import org.apache.maven.archiva.indexer.lucene.LuceneQuery; import org.apache.maven.archiva.model.ArchivaArtifact; import org.apache.maven.archiva.model.ArchivaRepository; @@ -72,96 +70,97 @@ public class BytecodeSearchTest extends AbstractSearchTestCase ArchivaArtifact artifact = (ArchivaArtifact) entry.getValue(); File dumpFile = getDumpFile( artifact ); BytecodeRecord record = BytecodeRecordLoader.loadRecord( dumpFile, artifact ); + record.setRepositoryId( "test-repo" ); records.put( entry.getKey(), record ); } return records; } - public void testExactMatchVersionSimple() throws RepositoryIndexSearchException + public void testExactMatchVersionSimple() throws Exception { assertQueryExactMatch( ArtifactKeys.VERSION_EXACT, new String[] { "archiva-common" }, "1.0" ); } - public void testExactMatchVersionSnapshot() throws RepositoryIndexSearchException + public void testExactMatchVersionSnapshot() throws Exception { assertQueryExactMatch( ArtifactKeys.VERSION_EXACT, new String[] { "continuum-webapp" }, "1.0.3-SNAPSHOT" ); } - public void testExactMatchVersionAlphaSnapshot() throws RepositoryIndexSearchException + public void testExactMatchVersionAlphaSnapshot() throws Exception { assertQueryExactMatch( ArtifactKeys.VERSION_EXACT, new String[] { "redback-authorization-open" }, "1.0-alpha-1-SNAPSHOT" ); } - public void testExactMatchVersionTimestampedSnapshot() throws RepositoryIndexSearchException + public void testExactMatchVersionTimestampedSnapshot() throws Exception { assertQueryExactMatch( ArtifactKeys.VERSION_EXACT, new String[] { "wagon-provider-api" }, "1.0-beta-3-20070209.213958-2" ); } - public void testExactMatchVersionInvalid() throws RepositoryIndexSearchException + public void testExactMatchVersionInvalid() throws Exception { assertQueryExactMatchNoResults( ArtifactKeys.VERSION_EXACT, "foo" ); } - public void testExactMatchGroupIdOrgApacheMavenArchiva() throws RepositoryIndexSearchException + public void testExactMatchGroupIdOrgApacheMavenArchiva() throws Exception { assertQueryExactMatch( ArtifactKeys.GROUPID_EXACT, new String[] { "archiva-common" }, "org.apache.maven.archiva" ); } - public void testExactMatchGroupIdOrgApacheMaven() throws RepositoryIndexSearchException + public void testExactMatchGroupIdOrgApacheMaven() throws Exception { assertQueryExactMatch( ArtifactKeys.GROUPID_EXACT, new String[] { "maven-archetype-simple" }, "org.apache.maven" ); } - public void testExactMatchGroupIdInvalid() throws RepositoryIndexSearchException + public void testExactMatchGroupIdInvalid() throws Exception { assertQueryExactMatchNoResults( ArtifactKeys.GROUPID_EXACT, "foo" ); } - public void testExactMatchArtifactIdArchivaCommon() throws RepositoryIndexSearchException + public void testExactMatchArtifactIdArchivaCommon() throws Exception { assertQueryExactMatch( ArtifactKeys.ARTIFACTID_EXACT, new String[] { "archiva-common" }, "archiva-common" ); } - public void testExactMatchArtifactIdTestNg() throws RepositoryIndexSearchException + public void testExactMatchArtifactIdTestNg() throws Exception { assertQueryExactMatch( ArtifactKeys.ARTIFACTID_EXACT, new String[] { "testng" }, "testng" ); } - public void testExactMatchArtifactIdInvalid() throws RepositoryIndexSearchException + public void testExactMatchArtifactIdInvalid() throws Exception { assertQueryExactMatchNoResults( ArtifactKeys.ARTIFACTID_EXACT, "foo" ); } - public void testExactMatchTypeJar() throws RepositoryIndexSearchException + public void testExactMatchTypeJar() throws Exception { assertQueryExactMatch( ArtifactKeys.TYPE, ( new String[] { "archiva-common", "redback-authorization-open", "testng", "wagon-provider-api" } ), "jar" ); } - public void testExactMatchTypeWar() throws RepositoryIndexSearchException + public void testExactMatchTypeWar() throws Exception { assertQueryExactMatch( ArtifactKeys.TYPE, ( new String[] { "continuum-webapp" } ), "war" ); } /* TODO: Fix 'maven-plugin' type - public void testExactMatchTypePlugin() throws RepositoryIndexSearchException + public void testExactMatchTypePlugin() throws Exception { assertQueryExactMatch( ArtifactKeys.TYPE, ( new String[] { "maven-help-plugin" } ), "maven-plugin" ); } */ /* TODO: Fix 'maven-archetype' type - public void testExactMatchTypeArchetype() throws RepositoryIndexSearchException + public void testExactMatchTypeArchetype() throws Exception { assertQueryExactMatch( ArtifactKeys.TYPE, ( new String[] { "maven-archetype-simple" } ), "maven-archetype" ); } */ - public void testExactMatchTypeInvalid() throws RepositoryIndexSearchException + public void testExactMatchTypeInvalid() throws Exception { assertQueryExactMatchNoResults( ArtifactKeys.TYPE, "foo" ); } @@ -250,7 +249,7 @@ public class BytecodeSearchTest extends AbstractSearchTestCase BooleanQuery bQuery = new BooleanQuery(); bQuery.add( new MatchAllDocsQuery(), BooleanClause.Occur.MUST ); bQuery.add( createMatchQuery( ArtifactKeys.CLASSIFIER, "jdk15" ), BooleanClause.Occur.MUST_NOT ); - List results = index.search( new LuceneQuery( bQuery ) ); + List results = search( bQuery ); assertResults( new String[] { "archiva-common", "continuum-webapp", "redback-authorization-open", "daytrader-ear", "maven-archetype-simple", "maven-help-plugin", "wagon-provider-api" }, results ); diff --git a/archiva-base/archiva-indexer/src/test/java/org/apache/maven/archiva/indexer/hashcodes/HashcodesIndexTest.java b/archiva-base/archiva-indexer/src/test/java/org/apache/maven/archiva/indexer/hashcodes/HashcodesIndexTest.java index 8693f23ee..abacb665a 100644 --- a/archiva-base/archiva-indexer/src/test/java/org/apache/maven/archiva/indexer/hashcodes/HashcodesIndexTest.java +++ b/archiva-base/archiva-indexer/src/test/java/org/apache/maven/archiva/indexer/hashcodes/HashcodesIndexTest.java @@ -55,6 +55,7 @@ public class HashcodesIndexTest extends AbstractIndexCreationTestCase ArchivaArtifact artifact = new ArchivaArtifact( "com.foo", "projfoo", "1.0", "", "jar" ); HashcodesRecord record = new HashcodesRecord(); + record.setRepositoryId( "test-repo" ); record.setArtifact( artifact ); artifact.getModel().setChecksumSHA1( "c66f18bf192cb613fc2febb4da541a34133eedc2" ); diff --git a/archiva-base/archiva-indexer/src/test/java/org/apache/maven/archiva/indexer/hashcodes/HashcodesSearchTest.java b/archiva-base/archiva-indexer/src/test/java/org/apache/maven/archiva/indexer/hashcodes/HashcodesSearchTest.java index c25a06e2b..d32d0d605 100644 --- a/archiva-base/archiva-indexer/src/test/java/org/apache/maven/archiva/indexer/hashcodes/HashcodesSearchTest.java +++ b/archiva-base/archiva-indexer/src/test/java/org/apache/maven/archiva/indexer/hashcodes/HashcodesSearchTest.java @@ -26,9 +26,7 @@ import org.apache.maven.archiva.indexer.AbstractSearchTestCase; import org.apache.maven.archiva.indexer.ArtifactKeys; import org.apache.maven.archiva.indexer.RepositoryContentIndex; import org.apache.maven.archiva.indexer.RepositoryContentIndexFactory; -import org.apache.maven.archiva.indexer.RepositoryIndexSearchException; import org.apache.maven.archiva.indexer.lucene.LuceneIndexHandlers; -import org.apache.maven.archiva.indexer.lucene.LuceneQuery; import org.apache.maven.archiva.model.ArchivaArtifact; import org.apache.maven.archiva.model.ArchivaRepository; @@ -72,118 +70,119 @@ public class HashcodesSearchTest extends AbstractSearchTestCase ArchivaArtifact artifact = (ArchivaArtifact) entry.getValue(); File dumpFile = getDumpFile( artifact ); HashcodesRecord record = HashcodesRecordLoader.loadRecord( dumpFile, artifact ); + record.setRepositoryId( "test-repo" ); records.put( entry.getKey(), record ); } return records; } - public void testExactMatchVersionSimple() throws RepositoryIndexSearchException + public void testExactMatchVersionSimple() throws Exception { assertQueryExactMatch( ArtifactKeys.VERSION_EXACT, new String[] { "archiva-common" }, "1.0" ); } - public void testExactMatchVersionSnapshot() throws RepositoryIndexSearchException + public void testExactMatchVersionSnapshot() throws Exception { assertQueryExactMatch( ArtifactKeys.VERSION_EXACT, new String[] { "continuum-webapp" }, "1.0.3-SNAPSHOT" ); } - public void testExactMatchVersionAlphaSnapshot() throws RepositoryIndexSearchException + public void testExactMatchVersionAlphaSnapshot() throws Exception { assertQueryExactMatch( ArtifactKeys.VERSION_EXACT, new String[] { "redback-authorization-open" }, "1.0-alpha-1-SNAPSHOT" ); } - public void testExactMatchVersionTimestampedSnapshot() throws RepositoryIndexSearchException + public void testExactMatchVersionTimestampedSnapshot() throws Exception { assertQueryExactMatch( ArtifactKeys.VERSION_EXACT, new String[] { "wagon-provider-api" }, "1.0-beta-3-20070209.213958-2" ); } - public void testExactMatchVersionInvalid() throws RepositoryIndexSearchException + public void testExactMatchVersionInvalid() throws Exception { assertQueryExactMatchNoResults( ArtifactKeys.VERSION_EXACT, "foo" ); } - public void testExactMatchGroupIdOrgApacheMavenArchiva() throws RepositoryIndexSearchException + public void testExactMatchGroupIdOrgApacheMavenArchiva() throws Exception { assertQueryExactMatch( ArtifactKeys.GROUPID_EXACT, new String[] { "archiva-common" }, "org.apache.maven.archiva" ); } - public void testExactMatchGroupIdOrgApacheMaven() throws RepositoryIndexSearchException + public void testExactMatchGroupIdOrgApacheMaven() throws Exception { assertQueryExactMatch( ArtifactKeys.GROUPID_EXACT, new String[] { "maven-archetype-simple" }, "org.apache.maven" ); } - public void testExactMatchGroupIdInvalid() throws RepositoryIndexSearchException + public void testExactMatchGroupIdInvalid() throws Exception { assertQueryExactMatchNoResults( ArtifactKeys.GROUPID_EXACT, "foo" ); } - public void testExactMatchArtifactIdArchivaCommon() throws RepositoryIndexSearchException + public void testExactMatchArtifactIdArchivaCommon() throws Exception { assertQueryExactMatch( ArtifactKeys.ARTIFACTID_EXACT, new String[] { "archiva-common" }, "archiva-common" ); } - public void testExactMatchArtifactIdTestNg() throws RepositoryIndexSearchException + public void testExactMatchArtifactIdTestNg() throws Exception { assertQueryExactMatch( ArtifactKeys.ARTIFACTID_EXACT, new String[] { "testng" }, "testng" ); } - public void testExactMatchArtifactIdInvalid() throws RepositoryIndexSearchException + public void testExactMatchArtifactIdInvalid() throws Exception { assertQueryExactMatchNoResults( ArtifactKeys.ARTIFACTID_EXACT, "foo" ); } - public void testExactMatchTypeJar() throws RepositoryIndexSearchException + public void testExactMatchTypeJar() throws Exception { assertQueryExactMatch( ArtifactKeys.TYPE, ( new String[] { "archiva-common", "redback-authorization-open", "testng", "wagon-provider-api" } ), "jar" ); } - public void testExactMatchTypeWar() throws RepositoryIndexSearchException + public void testExactMatchTypeWar() throws Exception { assertQueryExactMatch( ArtifactKeys.TYPE, ( new String[] { "continuum-webapp" } ), "war" ); } /* TODO: Fix 'maven-plugin' type - public void testExactMatchTypePlugin() throws RepositoryIndexSearchException + public void testExactMatchTypePlugin() throws Exception { assertQueryExactMatch( ArtifactKeys.TYPE, ( new String[] { "maven-help-plugin" } ), "maven-plugin" ); } */ /* TODO: Fix 'maven-archetype' type - public void testExactMatchTypeArchetype() throws RepositoryIndexSearchException + public void testExactMatchTypeArchetype() throws Exception { assertQueryExactMatch( ArtifactKeys.TYPE, ( new String[] { "maven-archetype-simple" } ), "maven-archetype" ); } */ - public void testExactMatchTypeInvalid() throws RepositoryIndexSearchException + public void testExactMatchTypeInvalid() throws Exception { assertQueryExactMatchNoResults( ArtifactKeys.TYPE, "foo" ); } - public void testExactMatchMd5() throws RepositoryIndexSearchException + public void testExactMatchMd5() throws Exception { assertQueryExactMatch( HashcodesKeys.MD5, ( new String[] { "redback-authorization-open" } ), "f42047fe2e177ac04d0df7aa44d408be" ); } - public void testExactMatchMd5Invalid() throws RepositoryIndexSearchException + public void testExactMatchMd5Invalid() throws Exception { assertQueryExactMatchNoResults( HashcodesKeys.MD5, "foo" ); } - public void testExactMatchSha1() throws RepositoryIndexSearchException + public void testExactMatchSha1() throws Exception { assertQueryExactMatch( HashcodesKeys.SHA1, ( new String[] { "archiva-common" } ), "c2635a1b38bd4520a6604664c04b2b3c32330864" ); } - public void testExactMatchSha1Invalid() throws RepositoryIndexSearchException + public void testExactMatchSha1Invalid() throws Exception { assertQueryExactMatchNoResults( HashcodesKeys.SHA1, "foo" ); } @@ -272,7 +271,7 @@ public class HashcodesSearchTest extends AbstractSearchTestCase BooleanQuery bQuery = new BooleanQuery(); bQuery.add( new MatchAllDocsQuery(), BooleanClause.Occur.MUST ); bQuery.add( createMatchQuery( ArtifactKeys.CLASSIFIER, "jdk15" ), BooleanClause.Occur.MUST_NOT ); - List results = index.search( new LuceneQuery( bQuery ) ); + List results = search( bQuery ); assertResults( new String[] { "archiva-common", "continuum-webapp", "redback-authorization-open", "daytrader-ear", "maven-archetype-simple", "maven-help-plugin", "wagon-provider-api" }, results ); diff --git a/archiva-base/archiva-indexer/src/test/java/org/apache/maven/archiva/indexer/search/AllTests.java b/archiva-base/archiva-indexer/src/test/java/org/apache/maven/archiva/indexer/search/AllTests.java new file mode 100644 index 000000000..2f65f1d4b --- /dev/null +++ b/archiva-base/archiva-indexer/src/test/java/org/apache/maven/archiva/indexer/search/AllTests.java @@ -0,0 +1,41 @@ +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 junit.framework.Test; +import junit.framework.TestSuite; + +/** + * AllTests - conveinence test suite for IDE users. + * + * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a> + * @version $Id$ + */ +public class AllTests +{ + public static Test suite() + { + TestSuite suite = new TestSuite( "Test for org.apache.maven.archiva.indexer.search" ); + //$JUnit-BEGIN$ + suite.addTestSuite( DefaultCrossRepositorySearchTest.class ); + //$JUnit-END$ + return suite; + } +} 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 index f79f115f2..69e3d891d 100644 --- 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 @@ -98,6 +98,7 @@ public class BytecodeIndexPopulator ArchivaArtifact artifact = (ArchivaArtifact) entry.getValue(); File dumpFile = getDumpFile( basedir, artifact ); BytecodeRecord record = BytecodeRecordLoader.loadRecord( dumpFile, artifact ); + record.setRepositoryId( "test-repo" ); records.put( entry.getKey(), record ); } 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 index 21fe15121..892838128 100644 --- 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 @@ -20,11 +20,16 @@ package org.apache.maven.archiva.indexer.search; */ import org.apache.commons.lang.StringUtils; +import org.apache.lucene.search.Hits; +import org.apache.lucene.search.MatchAllDocsQuery; +import org.apache.lucene.search.Query; +import org.apache.lucene.search.Searcher; 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.indexer.RepositoryIndexSearchException; import org.apache.maven.archiva.model.ArchivaRepository; import org.codehaus.plexus.PlexusTestCase; import org.codehaus.plexus.util.FileUtils; @@ -68,6 +73,7 @@ public class DefaultCrossRepositorySearchTest repoConfig.setName( repository.getModel().getName() ); repoConfig.setUrl( repository.getModel().getUrl() ); repoConfig.setIndexDir( indexLocation.getAbsolutePath() ); + repoConfig.setIndexed( true ); if ( indexLocation.exists() ) { @@ -84,10 +90,27 @@ public class DefaultCrossRepositorySearchTest // Now populate them. Map hashcodesMap = ( new HashcodesIndexPopulator() ).populate( new File( getBasedir() ) ); indexHashcode.indexRecords( hashcodesMap.values() ); + assertEquals( "Hashcode Key Count", hashcodesMap.size(), indexHashcode.getAllRecordKeys().size() ); + assertRecordCount( indexHashcode, hashcodesMap.size() ); + Map bytecodeMap = ( new BytecodeIndexPopulator() ).populate( new File( getBasedir() ) ); indexBytecode.indexRecords( bytecodeMap.values() ); + assertEquals( "Bytecode Key Count", bytecodeMap.size(), indexBytecode.getAllRecordKeys().size() ); + assertRecordCount( indexBytecode, bytecodeMap.size() ); + Map contentMap = ( new FileContentIndexPopulator() ).populate( new File( getBasedir() ) ); indexContents.indexRecords( contentMap.values() ); + assertEquals( "File Content Key Count", contentMap.size(), indexContents.getAllRecordKeys().size() ); + assertRecordCount( indexContents, contentMap.size() ); + } + + private void assertRecordCount( RepositoryContentIndex index, int expectedCount ) + throws Exception + { + Query query = new MatchAllDocsQuery(); + Searcher searcher = (Searcher) index.getSearchable(); + Hits hits = searcher.search( query ); + assertEquals( "Expected Record Count for " + index.getId(), expectedCount, hits.length() ); } private CrossRepositorySearch lookupCrossRepositorySearch() @@ -98,34 +121,47 @@ public class DefaultCrossRepositorySearchTest return search; } - public void testSearchTerm() + public void testSearchTerm_Org() + throws Exception + { + CrossRepositorySearch search = lookupCrossRepositorySearch(); + + SearchResultLimits limits = new SearchResultLimits( 0 ); + limits.setPageSize( 20 ); + + SearchResults results = search.searchForTerm( "org", limits ); + assertResults( 1, 7, results ); + } + + public void testSearchTerm_Junit() throws Exception { CrossRepositorySearch search = lookupCrossRepositorySearch(); - SearchResults results = search.searchForTerm( "org" ); - assertHitCounts( 1, 8, 8, 1, results ); + SearchResultLimits limits = new SearchResultLimits( 0 ); + limits.setPageSize( 20 ); - results = search.searchForTerm( "junit" ); - assertHitCounts( 1, 1, 0, 1, results ); - - results = search.searchForTerm( "monosodium" ); - assertHitCounts( 1, 0, 0, 0, results ); + SearchResults results = search.searchForTerm( "junit", limits ); + assertResults( 1, 3, results ); } - private void assertHitCounts( int repoCount, int bytecodeCount, int hashcodeCount, int contentCount, - SearchResults results ) + public void testSearchInvalidTerm() + throws Exception + { + CrossRepositorySearch search = lookupCrossRepositorySearch(); + + SearchResultLimits limits = new SearchResultLimits( 0 ); + limits.setPageSize( 20 ); + + SearchResults results = search.searchForTerm( "monosodium", limits ); + assertResults( 1, 0, results ); + } + + private void assertResults( int repoCount, int hitCount, 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." ); - } + assertEquals( "Search Result Hits", hitCount, results.getHits().size() ); } } 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 index 9a8bdb44d..a098c4c13 100644 --- 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 @@ -49,8 +49,18 @@ public class FileContentIndexPopulator 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" ) ); + String prefix = "org/apache/maven/archiva/record/"; + + map.put( "parent-pom-1", createFileContentRecord( repoDir, prefix + "parent-pom/1/parent-pom-1.pom" ) ); + map.put( "child-pom-1.0-SNAPSHOT", createFileContentRecord( repoDir, prefix + + "test-child-pom/1.0-SNAPSHOT/test-child-pom-1.0-20060728.121314-1.pom" ) ); + map.put( "test-archetype-1.0", createFileContentRecord( repoDir, prefix + + "test-archetype/1.0/test-archetype-1.0.pom" ) ); + map.put( "test-jar-and-pom-1.0-alpha-1", createFileContentRecord( repoDir, prefix + + "test-jar-and-pom/1.0-alpha-1/test-jar-and-pom-1.0-alpha-1.pom" ) ); + map.put( "test-plugin-1.0", createFileContentRecord( repoDir, prefix + "test-plugin/1.0/test-plugin-1.0.pom" ) ); + map.put( "test-pom-1.0", createFileContentRecord( repoDir, prefix + "test-pom/1.0/test-pom-1.0.pom" ) ); + map.put( "test-skin-1.0", createFileContentRecord( repoDir, prefix + "test-skin/1.0/test-skin-1.0.pom" ) ); return map; } @@ -65,7 +75,8 @@ public class FileContentIndexPopulator } FileContentRecord record = new FileContentRecord(); - record.setFile( pathToFile ); + record.setRepositoryId( "test-repo" ); + record.setFilename( path ); try { 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 index f61ce86e4..686d6d838 100644 --- 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 @@ -64,6 +64,7 @@ public class HashcodesIndexPopulator ArchivaArtifact artifact = (ArchivaArtifact) entry.getValue(); File dumpFile = getDumpFile( basedir, artifact ); HashcodesRecord record = HashcodesRecordLoader.loadRecord( dumpFile, artifact ); + record.setRepositoryId( "test-repo" ); records.put( entry.getKey(), record ); } diff --git a/archiva-base/archiva-indexer/src/test/resources/log4j.xml b/archiva-base/archiva-indexer/src/test/resources/log4j.xml new file mode 100644 index 000000000..a11494a31 --- /dev/null +++ b/archiva-base/archiva-indexer/src/test/resources/log4j.xml @@ -0,0 +1,76 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> + +<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"> + + <appender name="console" class="org.apache.log4j.ConsoleAppender"> + <param name="Target" value="System.out"/> + <layout class="org.apache.log4j.PatternLayout"> + <param name="ConversionPattern" value="%d [%t] %-5p %-30c{1} - %m%n"/> + </layout> + </appender> + + <!-- Help identify bugs during testing --> + <logger name="org.apache.maven"> + <level value="debug"/> + </logger> + + <logger name="org.codehaus.plexus.security"> + <level value="info"/> + </logger> + + <!-- squelch noisy objects (for now) --> + <logger name="org.codehaus.plexus.mailsender.MailSender"> + <level value="info"/> + </logger> + + <logger name="org.quartz"> + <level value="info"/> + </logger> + + <logger name="org.apache.jasper"> + <level value="info"/> + </logger> + + <logger name="com.opensymphony.xwork"> + <level value="info"/> + </logger> + + <logger name="com.opensymphony.webwork"> + <level value="info"/> + </logger> + + <logger name="org.codehaus.plexus.PlexusContainer"> + <level value="info"/> + </logger> + + <logger name="JPOX"> + <level value="warn"/> + </logger> + + <logger name="JPOX.MetaData"> + <level value="error"/> + </logger> + + <logger name="JPOX.RDBMS.SQL"> + <level value="error"/> + </logger> + + <logger name="SQL"> + <level value="error"/> + </logger> + + <logger name="freemarker"> + <level value="warn"/> + </logger> + + <logger name="org.codehaus.plexus.component.manager.ClassicSingletonComponentManager"> + <level value="error"/> + </logger> + + <root> + <priority value="debug" /> + <appender-ref ref="console" /> + </root> + +</log4j:configuration> 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 index 61a859c7a..4b078f6a8 100644 --- 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 @@ -25,9 +25,29 @@ <description>DefaultCrossRepositorySearch</description> <requirements> <requirement> - <role>org.apache.maven.archiva.indexer.RepositoryContentIndexFactory</role> - <role-hint>lucene</role-hint> - <field-name>indexFactory</field-name> + <role>org.apache.commons.collections.Transformer</role> + <role-hint>bytecode</role-hint> + <field-name>bytecodeIndexTransformer</field-name> + </requirement> + <requirement> + <role>org.apache.commons.collections.Transformer</role> + <role-hint>filecontent</role-hint> + <field-name>filecontentIndexTransformer</field-name> + </requirement> + <requirement> + <role>org.apache.commons.collections.Transformer</role> + <role-hint>hashcodes</role-hint> + <field-name>hashcodesIndexTransformer</field-name> + </requirement> + <requirement> + <role>org.apache.commons.collections.Transformer</role> + <role-hint>searchable</role-hint> + <field-name>searchableTransformer</field-name> + </requirement> + <requirement> + <role>org.apache.commons.collections.Predicate</role> + <role-hint>index-exists</role-hint> + <field-name>indexExistsPredicate</field-name> </requirement> <requirement> <role>org.apache.maven.archiva.configuration.ArchivaConfiguration</role> |