use of org.apache.archiva.rest.api.services.ManagedRepositoriesService in project archiva by apache.
the class DownloadSnapshotTest method downloadSNAPSHOT.
@Test
public void downloadSNAPSHOT() throws Exception {
Path tmpIndexDir = Paths.get(System.getProperty("java.io.tmpdir") + "/tmpIndex");
if (Files.exists(tmpIndexDir)) {
org.apache.archiva.common.utils.FileUtils.deleteDirectory(tmpIndexDir);
}
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/snapshot-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);
RoleManagementService roleManagementService = getRoleManagementService(authorizationHeader);
if (!roleManagementService.templatedRoleExists(ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, id)) {
roleManagementService.createTemplatedRole(ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, id);
}
getUserService(authorizationHeader).createGuestUser();
roleManagementService.assignRole(ArchivaRoleConstants.TEMPLATE_GUEST, "guest");
roleManagementService.assignTemplatedRole(ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, id, "guest");
getUserService(authorizationHeader).removeFromCache("guest");
Path file = Paths.get("target/archiva-model-1.4-M4-SNAPSHOT.jar");
Files.deleteIfExists(file);
HttpWagon httpWagon = new HttpWagon();
httpWagon.connect(new Repository("foo", "http://localhost:" + port));
httpWagon.get("/repository/" + id + "/org/apache/archiva/archiva-model/1.4-M4-SNAPSHOT/archiva-model-1.4-M4-SNAPSHOT.jar", file.toFile());
ZipFile zipFile = new ZipFile(file.toFile());
List<String> entries = getZipEntriesNames(zipFile);
ZipEntry zipEntry = zipFile.getEntry("org/apache/archiva/model/ArchivaArtifact.class");
assertNotNull("cannot find zipEntry org/apache/archiva/model/ArchivaArtifact.class, entries: " + entries + ", content is: " + FileUtils.readFileToString(file.toFile(), Charset.forName("UTF-8")), zipEntry);
zipFile.close();
file.toFile().deleteOnExit();
}
use of org.apache.archiva.rest.api.services.ManagedRepositoriesService in project archiva by apache.
the class AbstractDownloadTest method getManagedRepositoriesService.
protected ManagedRepositoriesService getManagedRepositoriesService() {
ManagedRepositoriesService service = JAXRSClientFactory.create(getBaseUrl() + "/" + getRestServicesPath() + "/archivaServices/", ManagedRepositoriesService.class, Collections.singletonList(new JacksonJaxbJsonProvider()));
WebClient.client(service).header("Authorization", authorizationHeader);
WebClient.client(service).header("Referer", "http://localhost:" + port);
WebClient.getConfig(service).getHttpConduit().getClient().setReceiveTimeout(300000L);
return service;
}
use of org.apache.archiva.rest.api.services.ManagedRepositoriesService in project archiva by apache.
the class DownloadArtifactFromQueryTest method createAndScanRepo.
protected String createAndScanRepo() 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;
}
return id;
}
use of org.apache.archiva.rest.api.services.ManagedRepositoriesService 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.services.ManagedRepositoriesService in project archiva by apache.
the class ManagedRepositoriesServiceTest method addManagedRepo.
@Test
public void addManagedRepo() throws Exception {
ManagedRepositoriesService service = getManagedRepositoriesService(authorizationHeader);
ManagedRepository repo = getTestManagedRepository();
if (service.getManagedRepository(repo.getId()) != null) {
service.deleteManagedRepository(repo.getId(), true);
assertNull(service.getManagedRepository(repo.getId()));
}
service.addManagedRepository(repo);
repo = service.getManagedRepository(repo.getId());
assertNotNull(repo);
assertEquals(getTestManagedRepository().getDescription(), repo.getDescription());
RepositoriesService repositoriesService = getRepositoriesService(authorizationHeader);
int timeout = 20000;
while (timeout > 0 && repositoriesService.alreadyScanning(repo.getId())) {
Thread.sleep(500);
timeout -= 500;
}
service.deleteManagedRepository(repo.getId(), true);
assertNull(service.getManagedRepository(repo.getId()));
}
Aggregations