Search in sources :

Example 1 with SearchFields

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

the class MavenRepositorySearchOSGITest method searchFelixWithSymbolicName.

@Test
public void searchFelixWithSymbolicName() throws Exception {
    createIndex(TEST_REPO_1, Collections.<Path>emptyList(), true);
    List<String> selectedRepos = Arrays.asList(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.setBundleSymbolicName("org.apache.felix.bundlerepository");
    searchFields.setBundleVersion("1.6.6");
    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.felix", hit.getGroupId());
    assertEquals("org.apache.felix.bundlerepository", hit.getArtifactId());
    assertEquals("1.6.6", hit.getVersions().get(0));
    assertEquals("org.apache.felix.bundlerepository;uses:=\"org.osgi.framework\";version=\"2.0\"", hit.getBundleExportPackage());
    assertEquals("org.apache.felix.bundlerepository.RepositoryAdmin,org.osgi.service.obr.RepositoryAdmin", hit.getBundleExportService());
    assertEquals("org.apache.felix.bundlerepository", hit.getBundleSymbolicName());
    assertEquals("1.6.6", hit.getBundleVersion());
}
Also used : SearchFields(org.apache.archiva.indexer.search.SearchFields) SearchResultHit(org.apache.archiva.indexer.search.SearchResultHit) SearchResults(org.apache.archiva.indexer.search.SearchResults) Test(org.junit.Test)

Example 2 with SearchFields

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

the class MavenRepositorySearchTest method nolimitedResult.

@Test
public void nolimitedResult() throws Exception {
    Path repo = Paths.get("target/repo-release");
    FileUtils.deleteDirectory(repo.toFile());
    Path indexDirectory = repo.resolve(".index");
    FileUtils.copyDirectoryStructure(Paths.get("src/test/repo-release").toFile(), repo.toFile());
    IndexUpgrader.main(new String[] { indexDirectory.toAbsolutePath().toString() });
    createIndex(REPO_RELEASE, Collections.emptyList(), false, indexDirectory);
    // indexer.addIndexingContext( REPO_RELEASE, REPO_RELEASE, repo.toFile(), indexDirectory.toFile(),
    // repo.toUri().toURL().toExternalForm(),
    // indexDirectory.toUri().toURL().toString(), indexCreators );
    SearchResultLimits limits = new SearchResultLimits(SearchResultLimits.ALL_PAGES);
    limits.setPageSize(300);
    EasyMock.expect(archivaConfig.getDefaultLocale()).andReturn(Locale.getDefault()).anyTimes();
    EasyMock.expect(archivaConfig.getConfiguration()).andReturn(config).anyTimes();
    archivaConfigControl.replay();
    SearchResults searchResults = // 
    search.search(// 
    null, // 
    Arrays.asList(REPO_RELEASE), // 
    "org.example", // 
    limits, Collections.emptyList());
    log.info("results: {}", searchResults.getHits().size());
    assertEquals(255, searchResults.getHits().size());
    SearchFields searchFields = new SearchFields();
    searchFields.setGroupId("org.example");
    searchFields.setRepositories(Arrays.asList(REPO_RELEASE));
    searchResults = search.search(null, searchFields, limits);
    log.info("results: {}", searchResults.getHits().size());
    assertEquals(255, searchResults.getHits().size());
    archivaConfigControl.verify();
}
Also used : Path(java.nio.file.Path) SearchResultLimits(org.apache.archiva.indexer.search.SearchResultLimits) SearchFields(org.apache.archiva.indexer.search.SearchFields) SearchResults(org.apache.archiva.indexer.search.SearchResults) Test(org.junit.Test)

Example 3 with SearchFields

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

the class MavenRepositorySearchTest method testAdvancedSearchJarArtifacts.

@Test
public void testAdvancedSearchJarArtifacts() throws Exception {
    createIndexContainingMoreArtifacts(true);
    List<String> selectedRepos = new ArrayList<>();
    selectedRepos.add(TEST_REPO_1);
    SearchFields searchFields = new SearchFields();
    searchFields.setPackaging("jar");
    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("not 8 but " + results.getTotalHits() + ":" + niceDisplay(results), 8, 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 4 with SearchFields

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

the class MavenRepositorySearchTest method testAdvancedSearchSearchFieldsAreBlank.

@Test
public void testAdvancedSearchSearchFieldsAreBlank() throws Exception {
    List<String> selectedRepos = new ArrayList<>();
    selectedRepos.add(TEST_REPO_1);
    SearchFields searchFields = new SearchFields();
    searchFields.setGroupId("");
    searchFields.setArtifactId("");
    searchFields.setVersion("");
    searchFields.setPackaging("");
    searchFields.setClassName("");
    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 RepositorySearchException 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)

Example 5 with SearchFields

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

the class MavenRepositorySearchTest method testAdvancedSearchClassname.

@Test
public void testAdvancedSearchClassname() throws Exception {
    createIndexContainingMoreArtifacts(true);
    List<String> selectedRepos = Arrays.asList(TEST_REPO_1);
    SearchFields searchFields = new SearchFields();
    searchFields.setClassName("com.classname.search.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("totalHits not 1 results " + results, 1, results.getTotalHits());
    SearchResultHit hit = results.getHits().get(0);
    assertEquals("groupId not com", "com", hit.getGroupId());
    assertEquals("arttifactId not classname-search", "classname-search", hit.getArtifactId());
    assertEquals(" hits.version(0) not 1.0", "1.0", hit.getVersions().get(0));
}
Also used : SearchFields(org.apache.archiva.indexer.search.SearchFields) SearchResultHit(org.apache.archiva.indexer.search.SearchResultHit) SearchResults(org.apache.archiva.indexer.search.SearchResults) 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