mirror of https://github.com/apache/archiva.git
[MRM-1254] Add more unit tests for searching artifacts
o more unit tests for advanced search and quick search (code coverage is now 88%) git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@824257 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
5a8a5a92f8
commit
16b13f831a
|
@ -81,7 +81,12 @@ public class NexusRepositorySearchTest
|
||||||
|
|
||||||
config = new Configuration();
|
config = new Configuration();
|
||||||
config.addManagedRepository( createRepositoryConfig( TEST_REPO_1 ) );
|
config.addManagedRepository( createRepositoryConfig( TEST_REPO_1 ) );
|
||||||
|
config.addManagedRepository( createRepositoryConfig( TEST_REPO_2 ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createIndexForQuickSearch()
|
||||||
|
throws IOException, UnsupportedExistingLuceneIndexException
|
||||||
|
{
|
||||||
List<File> files = new ArrayList<File>();
|
List<File> files = new ArrayList<File>();
|
||||||
files.add( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_1 +
|
files.add( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_1 +
|
||||||
"/org/apache/archiva/archiva-search/1.0/archiva-search-1.0.jar" ) );
|
"/org/apache/archiva/archiva-search/1.0/archiva-search-1.0.jar" ) );
|
||||||
|
@ -114,6 +119,9 @@ public class NexusRepositorySearchTest
|
||||||
FileUtils.deleteDirectory( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_1 + "/.indexer" ) );
|
FileUtils.deleteDirectory( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_1 + "/.indexer" ) );
|
||||||
assertFalse( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_1 + "/.indexer" ).exists() );
|
assertFalse( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_1 + "/.indexer" ).exists() );
|
||||||
|
|
||||||
|
FileUtils.deleteDirectory( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_2 + "/.indexer" ) );
|
||||||
|
assertFalse( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_2 + "/.indexer" ).exists() );
|
||||||
|
|
||||||
super.tearDown();
|
super.tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,6 +154,8 @@ public class NexusRepositorySearchTest
|
||||||
public void testQuickSearch()
|
public void testQuickSearch()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
|
createIndexForQuickSearch();
|
||||||
|
|
||||||
List<String> selectedRepos = new ArrayList<String>();
|
List<String> selectedRepos = new ArrayList<String>();
|
||||||
selectedRepos.add( TEST_REPO_1 );
|
selectedRepos.add( TEST_REPO_1 );
|
||||||
|
|
||||||
|
@ -186,6 +196,8 @@ public class NexusRepositorySearchTest
|
||||||
public void testQuickSearchWithPagination()
|
public void testQuickSearchWithPagination()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
|
createIndexForQuickSearch();
|
||||||
|
|
||||||
List<String> selectedRepos = new ArrayList<String>();
|
List<String> selectedRepos = new ArrayList<String>();
|
||||||
selectedRepos.add( TEST_REPO_1 );
|
selectedRepos.add( TEST_REPO_1 );
|
||||||
|
|
||||||
|
@ -197,7 +209,7 @@ public class NexusRepositorySearchTest
|
||||||
|
|
||||||
archivaConfigControl.replay();
|
archivaConfigControl.replay();
|
||||||
|
|
||||||
SearchResults results = search.search( "user", selectedRepos, "org", limits, null );
|
SearchResults results = search.search( "user", selectedRepos, "org", limits, new ArrayList<String>() );
|
||||||
|
|
||||||
archivaConfigControl.verify();
|
archivaConfigControl.verify();
|
||||||
|
|
||||||
|
@ -229,6 +241,8 @@ public class NexusRepositorySearchTest
|
||||||
public void testArtifactFoundInMultipleRepositories()
|
public void testArtifactFoundInMultipleRepositories()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
|
createIndexForQuickSearch();
|
||||||
|
|
||||||
List<File> files = new ArrayList<File>();
|
List<File> files = new ArrayList<File>();
|
||||||
files.add( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_2 +
|
files.add( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_2 +
|
||||||
"/org/apache/archiva/archiva-search/1.0/archiva-search-1.0.jar" ) );
|
"/org/apache/archiva/archiva-search/1.0/archiva-search-1.0.jar" ) );
|
||||||
|
@ -262,15 +276,14 @@ public class NexusRepositorySearchTest
|
||||||
|
|
||||||
archivaConfigControl.reset();
|
archivaConfigControl.reset();
|
||||||
|
|
||||||
FileUtils.deleteDirectory( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_2 + "/.indexer" ) );
|
|
||||||
assertFalse( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_2 + "/.indexer" ).exists() );
|
|
||||||
|
|
||||||
// TODO: [BROWSE] in artifact info from browse, display all the repositories where the artifact is found
|
// TODO: [BROWSE] in artifact info from browse, display all the repositories where the artifact is found
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testNoMatchFound()
|
public void testNoMatchFound()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
|
createIndexForQuickSearch();
|
||||||
|
|
||||||
List<String> selectedRepos = new ArrayList<String>();
|
List<String> selectedRepos = new ArrayList<String>();
|
||||||
selectedRepos.add( TEST_REPO_1 );
|
selectedRepos.add( TEST_REPO_1 );
|
||||||
|
|
||||||
|
@ -288,6 +301,23 @@ public class NexusRepositorySearchTest
|
||||||
|
|
||||||
public void testNoIndexFound()
|
public void testNoIndexFound()
|
||||||
throws Exception
|
throws Exception
|
||||||
|
{
|
||||||
|
List<String> selectedRepos = new ArrayList<String>();
|
||||||
|
selectedRepos.add( TEST_REPO_1 );
|
||||||
|
|
||||||
|
archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
|
||||||
|
|
||||||
|
archivaConfigControl.replay();
|
||||||
|
|
||||||
|
SearchResults results = search.search( "user", selectedRepos, "org.apache.archiva", null, null );
|
||||||
|
assertNotNull( results );
|
||||||
|
assertEquals( 0, results.getTotalHits() );
|
||||||
|
|
||||||
|
archivaConfigControl.verify();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testRepositoryNotFound()
|
||||||
|
throws Exception
|
||||||
{
|
{
|
||||||
List<String> selectedRepos = new ArrayList<String>();
|
List<String> selectedRepos = new ArrayList<String>();
|
||||||
selectedRepos.add( "non-existing-repo" );
|
selectedRepos.add( "non-existing-repo" );
|
||||||
|
@ -306,6 +336,8 @@ public class NexusRepositorySearchTest
|
||||||
public void testSearchWithinSearchResults()
|
public void testSearchWithinSearchResults()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
|
createIndexForQuickSearch();
|
||||||
|
|
||||||
List<String> selectedRepos = new ArrayList<String>();
|
List<String> selectedRepos = new ArrayList<String>();
|
||||||
selectedRepos.add( TEST_REPO_1 );
|
selectedRepos.add( TEST_REPO_1 );
|
||||||
|
|
||||||
|
@ -330,6 +362,8 @@ public class NexusRepositorySearchTest
|
||||||
assertEquals( "1.0", hit.getVersions().get( 0 ) );
|
assertEquals( "1.0", hit.getVersions().get( 0 ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// tests for advanced search
|
||||||
|
|
||||||
public void testAdvancedSearch()
|
public void testAdvancedSearch()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
|
@ -341,17 +375,14 @@ public class NexusRepositorySearchTest
|
||||||
createIndex( TEST_REPO_2, files );
|
createIndex( TEST_REPO_2, files );
|
||||||
|
|
||||||
List<String> selectedRepos = new ArrayList<String>();
|
List<String> selectedRepos = new ArrayList<String>();
|
||||||
selectedRepos.add( TEST_REPO_1 );
|
|
||||||
selectedRepos.add( TEST_REPO_2 );
|
selectedRepos.add( TEST_REPO_2 );
|
||||||
|
|
||||||
config.addManagedRepository( createRepositoryConfig( TEST_REPO_2 ) );
|
|
||||||
|
|
||||||
SearchFields searchFields = new SearchFields();
|
SearchFields searchFields = new SearchFields();
|
||||||
searchFields.setGroupId( "org.apache.archiva" );
|
searchFields.setGroupId( "org.apache.archiva" );
|
||||||
searchFields.setVersion( "1.0" );
|
searchFields.setVersion( "1.0" );
|
||||||
searchFields.setRepositories( selectedRepos );
|
searchFields.setRepositories( selectedRepos );
|
||||||
|
|
||||||
archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 2 );
|
archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
|
||||||
|
|
||||||
archivaConfigControl.replay();
|
archivaConfigControl.replay();
|
||||||
|
|
||||||
|
@ -360,31 +391,40 @@ public class NexusRepositorySearchTest
|
||||||
archivaConfigControl.verify();
|
archivaConfigControl.verify();
|
||||||
|
|
||||||
assertNotNull( results );
|
assertNotNull( results );
|
||||||
assertEquals( 2, results.getTotalHits() );
|
assertEquals( 1, results.getTotalHits() );
|
||||||
|
|
||||||
FileUtils.deleteDirectory( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_2 + "/.indexer" ) );
|
SearchResultHit hit = results.getHits().get( 0 );
|
||||||
assertFalse( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_2 + "/.indexer" ).exists() );
|
assertEquals( "org.apache.archiva", hit.getGroupId() );
|
||||||
|
assertEquals( "archiva-search", hit.getArtifactId() );
|
||||||
|
assertEquals( "1.0", hit.getVersions().get( 0 ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAdvancedSearchWithPagination()
|
public void testAdvancedSearchWithPagination()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
List<File> files = new ArrayList<File>();
|
List<File> files = new ArrayList<File>();
|
||||||
files.add( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_2 +
|
files.add( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_1 +
|
||||||
"/org/apache/archiva/archiva-search/1.0/archiva-search-1.0.jar" ) );
|
"/org/apache/archiva/archiva-search/1.0/archiva-search-1.0.jar" ) );
|
||||||
files.add( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_2 +
|
files.add( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_1 +
|
||||||
"/org/apache/archiva/archiva-search/1.1/archiva-search-1.1.jar" ) );
|
"/org/apache/archiva/archiva-test/1.0/archiva-test-1.0.jar" ) );
|
||||||
createIndex( TEST_REPO_2, files );
|
files.add( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_1 +
|
||||||
|
"/org/apache/archiva/archiva-test/2.0/archiva-test-2.0.jar" ) );
|
||||||
|
files.add( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_1 +
|
||||||
|
"/org/apache/archiva/archiva-webapp/1.0/archiva-webapp-1.0.war" ) );
|
||||||
|
files.add( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_1 +
|
||||||
|
"/com/artifactid-numeric/1.0/artifactid-numeric-1.0.jar" ) );
|
||||||
|
files.add( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_1 +
|
||||||
|
"/com/artifactid-numeric123/1.0/artifactid-numeric123-1.0.jar" ) );
|
||||||
|
files.add( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_1 +
|
||||||
|
"/com/classname-search/1.0/classname-search-1.0.jar" ) );
|
||||||
|
|
||||||
|
createIndex( TEST_REPO_1, files );
|
||||||
|
|
||||||
List<String> selectedRepos = new ArrayList<String>();
|
List<String> selectedRepos = new ArrayList<String>();
|
||||||
selectedRepos.add( TEST_REPO_1 );
|
selectedRepos.add( TEST_REPO_1 );
|
||||||
selectedRepos.add( TEST_REPO_2 );
|
|
||||||
|
|
||||||
config.addManagedRepository( createRepositoryConfig( TEST_REPO_2 ) );
|
|
||||||
|
|
||||||
SearchFields searchFields = new SearchFields();
|
SearchFields searchFields = new SearchFields();
|
||||||
searchFields.setGroupId( "org.apache.archiva" );
|
searchFields.setGroupId( "org.apache.archiva" );
|
||||||
searchFields.setVersion( "1.0" );
|
|
||||||
searchFields.setRepositories( selectedRepos );
|
searchFields.setRepositories( selectedRepos );
|
||||||
|
|
||||||
// page 1
|
// page 1
|
||||||
|
@ -392,7 +432,7 @@ public class NexusRepositorySearchTest
|
||||||
SearchResultLimits limits = new SearchResultLimits( 0 );
|
SearchResultLimits limits = new SearchResultLimits( 0 );
|
||||||
limits.setPageSize( 1 );
|
limits.setPageSize( 1 );
|
||||||
|
|
||||||
archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 2 );
|
archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
|
||||||
|
|
||||||
archivaConfigControl.replay();
|
archivaConfigControl.replay();
|
||||||
|
|
||||||
|
@ -401,7 +441,7 @@ public class NexusRepositorySearchTest
|
||||||
archivaConfigControl.verify();
|
archivaConfigControl.verify();
|
||||||
|
|
||||||
assertNotNull( results );
|
assertNotNull( results );
|
||||||
assertEquals( 2, results.getTotalHits() );
|
assertEquals( 3, results.getTotalHits() );
|
||||||
assertEquals( 1, results.getHits().size() );
|
assertEquals( 1, results.getHits().size() );
|
||||||
|
|
||||||
// page 2
|
// page 2
|
||||||
|
@ -410,7 +450,7 @@ public class NexusRepositorySearchTest
|
||||||
limits = new SearchResultLimits( 1 );
|
limits = new SearchResultLimits( 1 );
|
||||||
limits.setPageSize( 1 );
|
limits.setPageSize( 1 );
|
||||||
|
|
||||||
archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 2 );
|
archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
|
||||||
|
|
||||||
archivaConfigControl.replay();
|
archivaConfigControl.replay();
|
||||||
|
|
||||||
|
@ -419,11 +459,8 @@ public class NexusRepositorySearchTest
|
||||||
archivaConfigControl.verify();
|
archivaConfigControl.verify();
|
||||||
|
|
||||||
assertNotNull( results );
|
assertNotNull( results );
|
||||||
assertEquals( 2, results.getTotalHits() );
|
assertEquals( 3, results.getTotalHits() );
|
||||||
assertEquals( 1, results.getHits().size() );
|
assertEquals( 1, results.getHits().size() );
|
||||||
|
|
||||||
FileUtils.deleteDirectory( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_2 + "/.indexer" ) );
|
|
||||||
assertFalse( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_2 + "/.indexer" ).exists() );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MRM-981 - artifactIds with numeric characters aren't found in advanced search
|
// MRM-981 - artifactIds with numeric characters aren't found in advanced search
|
||||||
|
@ -440,8 +477,6 @@ public class NexusRepositorySearchTest
|
||||||
List<String> selectedRepos = new ArrayList<String>();
|
List<String> selectedRepos = new ArrayList<String>();
|
||||||
selectedRepos.add( TEST_REPO_1 );
|
selectedRepos.add( TEST_REPO_1 );
|
||||||
|
|
||||||
config.addManagedRepository( createRepositoryConfig( TEST_REPO_1 ) );
|
|
||||||
|
|
||||||
SearchFields searchFields = new SearchFields();
|
SearchFields searchFields = new SearchFields();
|
||||||
searchFields.setArtifactId( "artifactid-numeric" );
|
searchFields.setArtifactId( "artifactid-numeric" );
|
||||||
searchFields.setRepositories( selectedRepos );
|
searchFields.setRepositories( selectedRepos );
|
||||||
|
@ -456,10 +491,189 @@ public class NexusRepositorySearchTest
|
||||||
|
|
||||||
assertNotNull( results );
|
assertNotNull( results );
|
||||||
assertEquals( 2, results.getTotalHits() );
|
assertEquals( 2, results.getTotalHits() );
|
||||||
|
|
||||||
FileUtils.deleteDirectory( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_1 + "/.indexer" ) );
|
|
||||||
assertFalse( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_1 + "/.indexer" ).exists() );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: add test when an existing index already exists
|
public void testAdvancedSearchNoRepositoriesConfigured()
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
SearchFields searchFields = new SearchFields();
|
||||||
|
searchFields.setArtifactId( "archiva" );
|
||||||
|
searchFields.setRepositories( null );
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
SearchResults results = search.search( "user", searchFields, null );
|
||||||
|
fail( "A RepositorySearchExcecption should have been thrown." );
|
||||||
|
}
|
||||||
|
catch( RepositorySearchException e )
|
||||||
|
{
|
||||||
|
assertEquals( "Repositories cannot be null.", e.getMessage() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testAdvancedSearchSearchFieldsAreNull()
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
List<String> selectedRepos = new ArrayList<String>();
|
||||||
|
selectedRepos.add( TEST_REPO_1 );
|
||||||
|
|
||||||
|
SearchFields searchFields = new SearchFields();
|
||||||
|
searchFields.setRepositories( selectedRepos );
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 1 );
|
||||||
|
|
||||||
|
archivaConfigControl.replay();
|
||||||
|
|
||||||
|
SearchResults results = search.search( "user", searchFields, null );
|
||||||
|
|
||||||
|
archivaConfigControl.verify();
|
||||||
|
|
||||||
|
fail( "A RepositorySearchExcecption should have been thrown." );
|
||||||
|
}
|
||||||
|
catch( RepositorySearchException e )
|
||||||
|
{
|
||||||
|
assertEquals( "No search fields set.", e.getMessage() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testAdvancedSearchSearchFieldsAreBlank()
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
List<String> selectedRepos = new ArrayList<String>();
|
||||||
|
selectedRepos.add( TEST_REPO_1 );
|
||||||
|
|
||||||
|
SearchFields searchFields = new SearchFields();
|
||||||
|
searchFields.setGroupId( "" );
|
||||||
|
searchFields.setArtifactId( "" );
|
||||||
|
searchFields.setVersion( "" );
|
||||||
|
searchFields.setPackaging( "" );
|
||||||
|
searchFields.setClassName( "" );
|
||||||
|
|
||||||
|
searchFields.setRepositories( selectedRepos );
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 1 );
|
||||||
|
|
||||||
|
archivaConfigControl.replay();
|
||||||
|
|
||||||
|
SearchResults results = search.search( "user", searchFields, null );
|
||||||
|
|
||||||
|
archivaConfigControl.verify();
|
||||||
|
|
||||||
|
fail( "A RepositorySearchExcecption should have been thrown." );
|
||||||
|
}
|
||||||
|
catch( RepositorySearchException e )
|
||||||
|
{
|
||||||
|
assertEquals( "No search fields set.", e.getMessage() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testAdvancedSearchJarArtifacts()
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
List<File> files = new ArrayList<File>();
|
||||||
|
files.add( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_1 +
|
||||||
|
"/org/apache/archiva/archiva-search/1.0/archiva-search-1.0.jar" ) );
|
||||||
|
files.add( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_1 +
|
||||||
|
"/org/apache/archiva/archiva-test/1.0/archiva-test-1.0.jar" ) );
|
||||||
|
files.add( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_1 +
|
||||||
|
"/org/apache/archiva/archiva-test/2.0/archiva-test-2.0.jar" ) );
|
||||||
|
files.add( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_1 +
|
||||||
|
"/org/apache/archiva/archiva-webapp/1.0/archiva-webapp-1.0.war" ) );
|
||||||
|
files.add( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_1 +
|
||||||
|
"/com/artifactid-numeric/1.0/artifactid-numeric-1.0.jar" ) );
|
||||||
|
files.add( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_1 +
|
||||||
|
"/com/artifactid-numeric123/1.0/artifactid-numeric123-1.0.jar" ) );
|
||||||
|
files.add( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_1 +
|
||||||
|
"/com/classname-search/1.0/classname-search-1.0.jar" ) );
|
||||||
|
|
||||||
|
createIndex( TEST_REPO_1, files );
|
||||||
|
|
||||||
|
List<String> selectedRepos = new ArrayList<String>();
|
||||||
|
selectedRepos.add( TEST_REPO_1 );
|
||||||
|
|
||||||
|
SearchFields searchFields = new SearchFields();
|
||||||
|
searchFields.setPackaging( "jar" );
|
||||||
|
searchFields.setRepositories( selectedRepos );
|
||||||
|
|
||||||
|
archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
|
||||||
|
|
||||||
|
archivaConfigControl.replay();
|
||||||
|
|
||||||
|
SearchResults results = search.search( "user", searchFields, null );
|
||||||
|
|
||||||
|
archivaConfigControl.verify();
|
||||||
|
|
||||||
|
assertNotNull( results );
|
||||||
|
assertEquals( 5, results.getTotalHits() );
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testAdvancedSearchClassname()
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
List<File> files = new ArrayList<File>();
|
||||||
|
files.add( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_1 +
|
||||||
|
"/org/apache/archiva/archiva-search/1.0/archiva-search-1.0.jar" ) );
|
||||||
|
files.add( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_1 +
|
||||||
|
"/org/apache/archiva/archiva-test/1.0/archiva-test-1.0.jar" ) );
|
||||||
|
files.add( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_1 +
|
||||||
|
"/org/apache/archiva/archiva-test/2.0/archiva-test-2.0.jar" ) );
|
||||||
|
files.add( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_1 +
|
||||||
|
"/org/apache/archiva/archiva-webapp/1.0/archiva-webapp-1.0.war" ) );
|
||||||
|
files.add( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_1 +
|
||||||
|
"/com/artifactid-numeric/1.0/artifactid-numeric-1.0.jar" ) );
|
||||||
|
files.add( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_1 +
|
||||||
|
"/com/artifactid-numeric123/1.0/artifactid-numeric123-1.0.jar" ) );
|
||||||
|
files.add( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_1 +
|
||||||
|
"/com/classname-search/1.0/classname-search-1.0.jar" ) );
|
||||||
|
|
||||||
|
createIndex( TEST_REPO_1, files );
|
||||||
|
|
||||||
|
List<String> selectedRepos = new ArrayList<String>();
|
||||||
|
selectedRepos.add( TEST_REPO_1 );
|
||||||
|
|
||||||
|
SearchFields searchFields = new SearchFields();
|
||||||
|
searchFields.setClassName( "com.classname.search.App" );
|
||||||
|
searchFields.setRepositories( selectedRepos );
|
||||||
|
|
||||||
|
archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
|
||||||
|
|
||||||
|
archivaConfigControl.replay();
|
||||||
|
|
||||||
|
SearchResults results = search.search( "user", searchFields, null );
|
||||||
|
|
||||||
|
archivaConfigControl.verify();
|
||||||
|
|
||||||
|
assertNotNull( results );
|
||||||
|
assertEquals( 1, results.getTotalHits() );
|
||||||
|
|
||||||
|
SearchResultHit hit = results.getHits().get( 0 );
|
||||||
|
assertEquals( "com", hit.getGroupId() );
|
||||||
|
assertEquals( "classname-search", hit.getArtifactId() );
|
||||||
|
assertEquals( "1.0", hit.getVersions().get( 0 ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testAdvancedSearchNoIndexFound()
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
List<String> selectedRepos = new ArrayList<String>();
|
||||||
|
selectedRepos.add( TEST_REPO_1 );
|
||||||
|
|
||||||
|
SearchFields searchFields = new SearchFields();
|
||||||
|
searchFields.setGroupId( "org.apache.archiva" );
|
||||||
|
searchFields.setRepositories( selectedRepos );
|
||||||
|
|
||||||
|
archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
|
||||||
|
|
||||||
|
archivaConfigControl.replay();
|
||||||
|
|
||||||
|
SearchResults results = search.search( "user", searchFields, null );
|
||||||
|
|
||||||
|
archivaConfigControl.verify();
|
||||||
|
|
||||||
|
assertNotNull( results );assertEquals( 0, results.getTotalHits() );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
|
@ -0,0 +1,18 @@
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>com</groupId>
|
||||||
|
<artifactId>classname-search</artifactId>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
<version>1.0</version>
|
||||||
|
<name>classname-search</name>
|
||||||
|
<url>http://maven.apache.org</url>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>junit</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
<version>3.8.1</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
|
@ -0,0 +1,23 @@
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>org.apache.archiva</groupId>
|
||||||
|
<artifactId>archiva-webapp</artifactId>
|
||||||
|
<packaging>war</packaging>
|
||||||
|
<version>1.0</version>
|
||||||
|
<name>Archiva Webapp</name>
|
||||||
|
<url>http://archiva.apache.org</url>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>junit</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
<version>3.8.1</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>log4j</groupId>
|
||||||
|
<artifactId>log4j</artifactId>
|
||||||
|
<version>1.2.8</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
Loading…
Reference in New Issue