Search in sources :

Example 31 with SearchResults

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

the class MavenRepositorySearchTest method testAdvancedSearchArtifactIdHasNumericChar.

// MRM-981 - artifactIds with numeric characters aren't found in advanced search
@Test
public void testAdvancedSearchArtifactIdHasNumericChar() throws Exception {
    List<Path> files = new ArrayList<>();
    files.add(Paths.get(org.apache.archiva.common.utils.FileUtils.getBasedir(), "target/repos/" + TEST_REPO_1 + "/com/artifactid-numeric/1.0/artifactid-numeric-1.0.jar"));
    files.add(Paths.get(org.apache.archiva.common.utils.FileUtils.getBasedir(), "target/repos/" + TEST_REPO_1 + "/com/artifactid-numeric123/1.0/artifactid-numeric123-1.0.jar"));
    createIndex(TEST_REPO_1, files, true);
    List<String> selectedRepos = new ArrayList<>();
    selectedRepos.add(TEST_REPO_1);
    SearchFields searchFields = new SearchFields();
    searchFields.setArtifactId("artifactid-numeric");
    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(2, results.getTotalHits());
}
Also used : Path(java.nio.file.Path) SearchFields(org.apache.archiva.indexer.search.SearchFields) ArrayList(java.util.ArrayList) SearchResults(org.apache.archiva.indexer.search.SearchResults) Test(org.junit.Test)

Example 32 with SearchResults

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

the class MavenRepositorySearchTest method testAdvancedSearchWithIncorrectPackaging.

@Test
public void testAdvancedSearchWithIncorrectPackaging() throws Exception {
    createSimpleIndex(true);
    List<String> selectedRepos = new ArrayList<>();
    selectedRepos.add(TEST_REPO_1);
    SearchFields searchFields = new SearchFields();
    searchFields.setGroupId("org.apache.archiva");
    searchFields.setArtifactId("archiva-test");
    searchFields.setVersion("2.0");
    searchFields.setPackaging("war");
    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(0, results.getTotalHits());
}
Also used : SearchFields(org.apache.archiva.indexer.search.SearchFields) ArrayList(java.util.ArrayList) SearchResults(org.apache.archiva.indexer.search.SearchResults) Test(org.junit.Test)

Example 33 with SearchResults

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

the class MavenRepositorySearchPaginateTest method build.

SearchResults build(int number, SearchResultLimits limits) {
    SearchResults searchResults = new SearchResults();
    searchResults.setLimits(limits);
    for (int i = 0; i < number; i++) {
        SearchResultHit hit = new SearchResultHit();
        hit.setGroupId("commons-foo");
        hit.setArtifactId("commons-bar-" + i);
        hit.setPackaging("jar");
        hit.setVersions(Arrays.asList("1.0"));
        String id = SearchUtil.getHitId(hit.getGroupId(), hit.getArtifactId(), hit.getClassifier(), hit.getPackaging());
        searchResults.addHit(id, hit);
    }
    searchResults.setTotalHits(number);
    return searchResults;
}
Also used : SearchResultHit(org.apache.archiva.indexer.search.SearchResultHit) SearchResults(org.apache.archiva.indexer.search.SearchResults)

Example 34 with SearchResults

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

the class MavenRepositorySearchPaginateTest method paginatedResult.

@Test
public void paginatedResult() throws Exception {
    MavenRepositorySearch search = new MavenRepositorySearch();
    SearchResults searchResults = build(32, new SearchResultLimits(1));
    searchResults = search.paginate(searchResults);
    assertEquals(2, searchResults.getReturnedHitsCount());
}
Also used : SearchResultLimits(org.apache.archiva.indexer.search.SearchResultLimits) SearchResults(org.apache.archiva.indexer.search.SearchResults) Test(org.junit.Test)

Example 35 with SearchResults

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

the class MavenRepositorySearchPaginateTest method nonPaginatedHugeResult.

@Test
public void nonPaginatedHugeResult() throws Exception {
    MavenRepositorySearch search = new MavenRepositorySearch();
    SearchResults origSearchResults = build(63, new SearchResultLimits(0));
    SearchResults searchResults = search.paginate(origSearchResults);
    assertEquals(30, searchResults.getReturnedHitsCount());
    origSearchResults = build(63, new SearchResultLimits(1));
    searchResults = search.paginate(origSearchResults);
    assertEquals(30, searchResults.getReturnedHitsCount());
}
Also used : SearchResultLimits(org.apache.archiva.indexer.search.SearchResultLimits) 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