use of org.apache.archiva.rest.api.model.SearchRequest in project archiva by apache.
the class DownloadMergedIndexTest method downloadMergedIndex.
@Test
public void downloadMergedIndex() throws Exception {
Path tmpIndexDir = Paths.get(System.getProperty("java.io.tmpdir"), "tmpIndex");
if (Files.exists(tmpIndexDir)) {
FileUtils.deleteDirectory(tmpIndexDir.toFile());
}
String id = Long.toString(System.currentTimeMillis());
ManagedRepository managedRepository = new ManagedRepository(Locale.getDefault());
managedRepository.setId(id);
managedRepository.setName("name of " + id);
managedRepository.setLocation(System.getProperty("basedir") + "/src/test/repositories/test-repo");
managedRepository.setIndexDirectory(System.getProperty("java.io.tmpdir") + "/tmpIndex/" + id);
ManagedRepositoriesService managedRepositoriesService = getManagedRepositoriesService();
if (managedRepositoriesService.getManagedRepository(id) != null) {
managedRepositoriesService.deleteManagedRepository(id, false);
}
getManagedRepositoriesService().addManagedRepository(managedRepository);
RepositoriesService repositoriesService = getRepositoriesService();
repositoriesService.scanRepositoryNow(id, true);
// wait a bit to ensure index is finished
int timeout = 20000;
while (timeout > 0 && repositoriesService.alreadyScanning(id)) {
Thread.sleep(500);
timeout -= 500;
}
RepositoryGroupService repositoryGroupService = getRepositoryGroupService();
String repoGroupId = "test-group";
if (repositoryGroupService.getRepositoryGroup(repoGroupId) != null) {
repositoryGroupService.deleteRepositoryGroup(repoGroupId);
}
RepositoryGroup repositoryGroup = new RepositoryGroup();
repositoryGroup.setId(repoGroupId);
repositoryGroup.setRepositories(Arrays.asList(id));
repositoryGroupService.addRepositoryGroup(repositoryGroup);
// create a repo with a remote on the one with index
id = Long.toString(System.currentTimeMillis());
managedRepository = new ManagedRepository(Locale.getDefault());
managedRepository.setId(id);
managedRepository.setName("name of " + id);
managedRepository.setLocation(System.getProperty("basedir") + "/src/test/repositories/test-repo");
managedRepository.setIndexDirectory(System.getProperty("java.io.tmpdir") + "/tmpIndex/" + id);
if (managedRepositoriesService.getManagedRepository(id) != null) {
managedRepositoriesService.deleteManagedRepository(id, false);
}
getManagedRepositoriesService().addManagedRepository(managedRepository);
RemoteRepository remoteRepository = new RemoteRepository(Locale.getDefault());
remoteRepository.setId("all-merged");
remoteRepository.setName("all-merged");
remoteRepository.setDownloadRemoteIndex(true);
remoteRepository.setUrl("http://localhost:" + port + "/repository/test-group");
remoteRepository.setRemoteIndexUrl("http://localhost:" + port + "/repository/test-group/.index");
remoteRepository.setUserName(RedbackRoleConstants.ADMINISTRATOR_ACCOUNT_NAME);
remoteRepository.setPassword(FakeCreateAdminService.ADMIN_TEST_PWD);
if (getRemoteRepositoriesService().getRemoteRepository(remoteRepository.getId()) != null) {
getRemoteRepositoriesService().deleteRemoteRepository(remoteRepository.getId());
}
getRemoteRepositoriesService().addRemoteRepository(remoteRepository);
ProxyConnectorService proxyConnectorService = getProxyConnectorService();
ProxyConnector proxyConnector = new ProxyConnector();
proxyConnector.setProxyId("foo-bar1");
proxyConnector.setSourceRepoId(id);
proxyConnector.setTargetRepoId("all-merged");
proxyConnectorService.addProxyConnector(proxyConnector);
repositoriesService.scheduleDownloadRemoteIndex("all-merged", true, true);
// wait a bit
timeout = 20000;
while (timeout > 0) {
Thread.sleep(500);
timeout -= 500;
}
SearchService searchService = getSearchService();
SearchRequest request = new SearchRequest();
request.setRepositories(Arrays.asList(id));
request.setGroupId("org.apache.felix");
List<Artifact> artifacts = searchService.searchArtifacts(request);
assertThat(artifacts).isNotNull().isNotEmpty().hasSize(1);
}
use of org.apache.archiva.rest.api.model.SearchRequest in project archiva by apache.
the class SearchServiceTest method searchWithSearchRequestBundleSymbolicNameOneVersion.
@Test
public void searchWithSearchRequestBundleSymbolicNameOneVersion() throws Exception {
SearchService searchService = getSearchService(authorizationHeader);
// START SNIPPET: searchservice-with-osgi
SearchRequest searchRequest = new SearchRequest();
searchRequest.setBundleSymbolicName("org.apache.karaf.features.command");
// END SNIPPET: searchservice-with-osgi
List<Artifact> artifacts = searchService.searchArtifacts(searchRequest);
assertNotNull(artifacts);
assertTrue(" not 1 results for Bundle Symbolic Name org.apache.karaf.features.command but " + artifacts.size() + ":" + artifacts, artifacts.size() == 1);
}
use of org.apache.archiva.rest.api.model.SearchRequest in project archiva by apache.
the class SearchServiceTest method searchWithSearchRequestGroupIdAndArtifactIdAndClassifier.
@Test
public void searchWithSearchRequestGroupIdAndArtifactIdAndClassifier() throws Exception {
SearchService searchService = getSearchService(authorizationHeader);
// START SNIPPET: searchservice-with-classifier
SearchRequest searchRequest = new SearchRequest();
searchRequest.setGroupId("commons-logging");
searchRequest.setArtifactId("commons-logging");
searchRequest.setClassifier("sources");
List<Artifact> artifacts = searchService.searchArtifacts(searchRequest);
// END SNIPPET: searchservice-with-classifier
assertNotNull(artifacts);
assertTrue(" not 2 results for commons-logging search but " + artifacts.size() + ":" + artifacts, artifacts.size() == 2);
log.info("artifacts for commons-logging size {} search {}", artifacts.size(), artifacts);
}
use of org.apache.archiva.rest.api.model.SearchRequest in project archiva by apache.
the class SearchServiceTest method searchWithSearchUnknwownRepoId.
@Test
public /**
* ensure we don't return response for an unknown repo
*/
void searchWithSearchUnknwownRepoId() throws Exception {
SearchService searchService = getSearchService(authorizationHeader);
SearchRequest searchRequest = new SearchRequest();
searchRequest.setBundleExportPackage("org.apache.karaf.features.command.completers");
searchRequest.setRepositories(Arrays.asList("tototititata"));
List<Artifact> artifacts = searchService.searchArtifacts(searchRequest);
assertNotNull(artifacts);
assertTrue(" not 0 results for Bundle ExportPackage org.apache.karaf.features.command.completers but " + artifacts.size() + ":" + artifacts, artifacts.size() == 0);
}
Aggregations