Search in sources :

Example 11 with SearchResults

use of org.apache.archiva.indexer.search.SearchResults in project archiva by apache.

the class MavenRepositorySearchTest method testAdvancedSearchWithPagination.

@Test
public void testAdvancedSearchWithPagination() throws Exception {
    createIndexContainingMoreArtifacts(false);
    List<String> selectedRepos = new ArrayList<>();
    selectedRepos.add(TEST_REPO_1);
    SearchFields searchFields = new SearchFields();
    searchFields.setGroupId("org.apache.archiva");
    searchFields.setRepositories(selectedRepos);
    // page 1
    SearchResultLimits limits = new SearchResultLimits(0);
    limits.setPageSize(1);
    EasyMock.expect(archivaConfig.getDefaultLocale()).andReturn(Locale.getDefault()).anyTimes();
    EasyMock.expect(archivaConfig.getConfiguration()).andReturn(config).anyTimes();
    archivaConfigControl.replay();
    SearchResults results = search.search("user", searchFields, limits);
    archivaConfigControl.verify();
    assertNotNull(results);
    assertEquals(4, results.getTotalHits());
    assertEquals(1, results.getHits().size());
    // page 2
    archivaConfigControl.reset();
    limits = new SearchResultLimits(1);
    limits.setPageSize(1);
    EasyMock.expect(archivaConfig.getDefaultLocale()).andReturn(Locale.getDefault()).anyTimes();
    EasyMock.expect(archivaConfig.getConfiguration()).andReturn(config).anyTimes();
    archivaConfigControl.replay();
    results = search.search("user", searchFields, limits);
    archivaConfigControl.verify();
    assertNotNull(results);
    assertEquals(4, results.getTotalHits());
    assertEquals(1, results.getHits().size());
}
Also used : SearchResultLimits(org.apache.archiva.indexer.search.SearchResultLimits) SearchFields(org.apache.archiva.indexer.search.SearchFields) ArrayList(java.util.ArrayList) SearchResults(org.apache.archiva.indexer.search.SearchResults) Test(org.junit.Test)

Example 12 with SearchResults

use of org.apache.archiva.indexer.search.SearchResults in project archiva by apache.

the class MavenRepositorySearchTest method testMultipleArtifactsSameVersionWithClassifier.

@Test
public void testMultipleArtifactsSameVersionWithClassifier() throws Exception {
    createIndexContainingMultipleArtifactsSameVersion(true);
    List<String> selectedRepos = new ArrayList<>();
    selectedRepos.add(TEST_REPO_1);
    // search artifactId
    EasyMock.expect(archivaConfig.getDefaultLocale()).andReturn(Locale.getDefault()).anyTimes();
    EasyMock.expect(archivaConfig.getConfiguration()).andReturn(config).anyTimes();
    archivaConfigControl.replay();
    SearchFields searchFields = new SearchFields();
    searchFields.setGroupId("org.apache.archiva");
    searchFields.setArtifactId("archiva-search");
    searchFields.setClassifier("sources");
    searchFields.setRepositories(selectedRepos);
    SearchResults results = search.search("user", searchFields, null);
    archivaConfigControl.verify();
    assertNotNull(results);
    assertEquals(1, results.getTotalHits());
    SearchResultHit hit = results.getHits().get(0);
    assertEquals("org.apache.archiva", hit.getGroupId());
    assertEquals("archiva-search", hit.getArtifactId());
    assertEquals("1.0", hit.getVersions().get(0));
    // only 1 version of 1.0 is retrieved
    assertEquals(1, hit.getVersions().size());
}
Also used : SearchFields(org.apache.archiva.indexer.search.SearchFields) SearchResultHit(org.apache.archiva.indexer.search.SearchResultHit) ArrayList(java.util.ArrayList) SearchResults(org.apache.archiva.indexer.search.SearchResults) Test(org.junit.Test)

Example 13 with SearchResults

use of org.apache.archiva.indexer.search.SearchResults in project archiva by apache.

the class MavenRepositorySearchTest method testRepositoryNotFound.

@Test
public void testRepositoryNotFound() throws Exception {
    List<String> selectedRepos = new ArrayList<>();
    selectedRepos.add("non-existing-repo");
    archivaConfigControl.replay();
    SearchResults results = search.search("user", selectedRepos, "org.apache.archiva", null, null);
    assertNotNull(results);
    assertEquals(0, results.getTotalHits());
    archivaConfigControl.verify();
}
Also used : ArrayList(java.util.ArrayList) SearchResults(org.apache.archiva.indexer.search.SearchResults) Test(org.junit.Test)

Example 14 with SearchResults

use of org.apache.archiva.indexer.search.SearchResults in project archiva by apache.

the class MavenRepositorySearchTest method testAdvancedSearchClassNameInWar.

@Test
public void testAdvancedSearchClassNameInWar() throws Exception {
    createIndexContainingMoreArtifacts(true);
    List<String> selectedRepos = Arrays.asList(TEST_REPO_1);
    SearchFields searchFields = new SearchFields();
    searchFields.setClassName("SomeClass");
    searchFields.setRepositories(selectedRepos);
    EasyMock.expect(archivaConfig.getDefaultLocale()).andReturn(Locale.getDefault()).anyTimes();
    EasyMock.expect(archivaConfig.getConfiguration()).andReturn(config).anyTimes();
    archivaConfigControl.replay();
    SearchResults results = search.search("user", searchFields, null);
    archivaConfigControl.verify();
    assertNotNull(results);
    assertEquals(1, results.getHits().size());
    assertEquals("test-webapp", results.getHits().get(0).getArtifactId());
}
Also used : SearchFields(org.apache.archiva.indexer.search.SearchFields) SearchResults(org.apache.archiva.indexer.search.SearchResults) Test(org.junit.Test)

Example 15 with SearchResults

use of org.apache.archiva.indexer.search.SearchResults in project archiva by apache.

the class MavenRepositorySearchTest method testAdvancedSearch.

// tests for advanced search
@Test
public void testAdvancedSearch() throws Exception {
    List<Path> files = new ArrayList<>();
    files.add(Paths.get(org.apache.archiva.common.utils.FileUtils.getBasedir(), "target/repos/" + TEST_REPO_2 + "/org/apache/archiva/archiva-search/1.0/archiva-search-1.0.jar"));
    files.add(Paths.get(org.apache.archiva.common.utils.FileUtils.getBasedir(), "target/repos/" + TEST_REPO_2 + "/org/apache/archiva/archiva-search/1.1/archiva-search-1.1.jar"));
    createIndex(TEST_REPO_2, files, false);
    List<String> selectedRepos = new ArrayList<>();
    selectedRepos.add(TEST_REPO_2);
    SearchFields searchFields = new SearchFields();
    searchFields.setGroupId("org.apache.archiva");
    searchFields.setVersion("1.0");
    searchFields.setRepositories(selectedRepos);
    EasyMock.expect(archivaConfig.getDefaultLocale()).andReturn(Locale.getDefault()).anyTimes();
    EasyMock.expect(archivaConfig.getConfiguration()).andReturn(config).anyTimes();
    archivaConfigControl.replay();
    SearchResults results = search.search("user", searchFields, null);
    archivaConfigControl.verify();
    assertNotNull(results);
    assertEquals(1, results.getTotalHits());
    SearchResultHit hit = results.getHits().get(0);
    assertEquals("org.apache.archiva", hit.getGroupId());
    assertEquals("archiva-search", hit.getArtifactId());
    assertEquals("1.0", hit.getVersions().get(0));
}
Also used : Path(java.nio.file.Path) SearchFields(org.apache.archiva.indexer.search.SearchFields) SearchResultHit(org.apache.archiva.indexer.search.SearchResultHit) ArrayList(java.util.ArrayList) SearchResults(org.apache.archiva.indexer.search.SearchResults) Test(org.junit.Test)

Aggregations

SearchResults (org.apache.archiva.indexer.search.SearchResults)35 Test (org.junit.Test)26 ArrayList (java.util.ArrayList)17 SearchFields (org.apache.archiva.indexer.search.SearchFields)16 SearchResultHit (org.apache.archiva.indexer.search.SearchResultHit)13 SearchResultLimits (org.apache.archiva.indexer.search.SearchResultLimits)9 RepositorySearchException (org.apache.archiva.indexer.search.RepositorySearchException)6 Path (java.nio.file.Path)4 ArchivaRestServiceException (org.apache.archiva.rest.api.services.ArchivaRestServiceException)4 IOException (java.io.IOException)1 URI (java.net.URI)1 TreeMap (java.util.TreeMap)1 RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)1 Artifact (org.apache.archiva.maven2.model.Artifact)1 MetadataRepositoryException (org.apache.archiva.metadata.repository.MetadataRepositoryException)1 ArtifactInfo (org.apache.maven.index.ArtifactInfo)1 FlatSearchRequest (org.apache.maven.index.FlatSearchRequest)1 FlatSearchResponse (org.apache.maven.index.FlatSearchResponse)1 SourcedSearchExpression (org.apache.maven.index.expr.SourcedSearchExpression)1 UserInputSearchExpression (org.apache.maven.index.expr.UserInputSearchExpression)1