Search in sources :

Example 6 with SearchFields

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

the class MavenRepositorySearchTest method testAdvancedSearchNoRepositoriesConfigured.

@Test
public void testAdvancedSearchNoRepositoriesConfigured() throws Exception {
    SearchFields searchFields = new SearchFields();
    searchFields.setArtifactId("archiva");
    searchFields.setRepositories(null);
    try {
        search.search("user", searchFields, null);
        fail("A RepositorySearchExcecption should have been thrown.");
    } catch (RepositorySearchException e) {
        assertEquals("Repositories cannot be null.", e.getMessage());
    }
}
Also used : SearchFields(org.apache.archiva.indexer.search.SearchFields) RepositorySearchException(org.apache.archiva.indexer.search.RepositorySearchException) Test(org.junit.Test)

Example 7 with SearchFields

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

the class MavenRepositorySearchTest method testAdvancedSearchAllSearchCriteriaSpecified.

@Test
public void testAdvancedSearchAllSearchCriteriaSpecified() 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("jar");
    searchFields.setClassName("org.apache.archiva.test.App");
    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("total hints not 1" + results, 1, results.getTotalHits());
    SearchResultHit hit = results.getHits().get(0);
    assertEquals("org.apache.archiva", hit.getGroupId());
    assertEquals("archiva-test", hit.getArtifactId());
    assertEquals("version not 2.0", "2.0", hit.getVersions().get(0));
}
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 8 with SearchFields

use of org.apache.archiva.indexer.search.SearchFields 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 9 with SearchFields

use of org.apache.archiva.indexer.search.SearchFields 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 10 with SearchFields

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

the class MavenRepositorySearchTest method testAdvancedSearchSearchFieldsAreNull.

@Test
public void testAdvancedSearchSearchFieldsAreNull() throws Exception {
    List<String> selectedRepos = new ArrayList<>();
    selectedRepos.add(TEST_REPO_1);
    SearchFields searchFields = new SearchFields();
    searchFields.setRepositories(selectedRepos);
    try {
        EasyMock.expect(archivaConfig.getDefaultLocale()).andReturn(Locale.getDefault()).anyTimes();
        EasyMock.expect(archivaConfig.getConfiguration()).andReturn(config).anyTimes();
        archivaConfigControl.replay();
        search.search("user", searchFields, null);
        archivaConfigControl.verify();
        fail("A RepositorySearchExcecption should have been thrown.");
    } catch (RepositorySearchException e) {
        assertEquals("No search fields set.", e.getMessage());
    }
}
Also used : SearchFields(org.apache.archiva.indexer.search.SearchFields) ArrayList(java.util.ArrayList) RepositorySearchException(org.apache.archiva.indexer.search.RepositorySearchException) Test(org.junit.Test)

Aggregations

SearchFields (org.apache.archiva.indexer.search.SearchFields)19 SearchResults (org.apache.archiva.indexer.search.SearchResults)16 Test (org.junit.Test)16 ArrayList (java.util.ArrayList)11 RepositorySearchException (org.apache.archiva.indexer.search.RepositorySearchException)6 SearchResultHit (org.apache.archiva.indexer.search.SearchResultHit)5 Path (java.nio.file.Path)3 SearchResultLimits (org.apache.archiva.indexer.search.SearchResultLimits)3 ArchivaRestServiceException (org.apache.archiva.rest.api.services.ArchivaRestServiceException)3 URI (java.net.URI)1 TreeMap (java.util.TreeMap)1 Artifact (org.apache.archiva.maven2.model.Artifact)1 MetadataRepositoryException (org.apache.archiva.metadata.repository.MetadataRepositoryException)1