use of org.apache.maven.wagon.providers.http.HttpWagon 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.maven.wagon.providers.http.HttpWagon in project archiva by apache.
the class DownloadArtifactsTest method downloadWithRemoteRedirect.
@Test
public void downloadWithRemoteRedirect() throws Exception {
RemoteRepository remoteRepository = getRemoteRepositoriesService().getRemoteRepository("central");
remoteRepository.setUrl("http://localhost:" + redirectPort);
getRemoteRepositoriesService().updateRemoteRepository(remoteRepository);
RoleManagementService roleManagementService = getRoleManagementService(authorizationHeader);
if (!roleManagementService.templatedRoleExists(ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, "internal")) {
roleManagementService.createTemplatedRole(ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, "internal");
}
getUserService(authorizationHeader).createGuestUser();
roleManagementService.assignRole(ArchivaRoleConstants.TEMPLATE_GUEST, "guest");
roleManagementService.assignTemplatedRole(ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, "internal", "guest");
getUserService(authorizationHeader).removeFromCache("guest");
Path file = Paths.get("target/junit-4.9.jar");
Files.deleteIfExists(file);
HttpWagon httpWagon = new HttpWagon();
httpWagon.connect(new Repository("foo", "http://localhost:" + port));
httpWagon.get("repository/internal/junit/junit/4.9/junit-4.9.jar", file.toFile());
ZipFile zipFile = new ZipFile(file.toFile());
List<String> entries = getZipEntriesNames(zipFile);
ZipEntry zipEntry = zipFile.getEntry("org/junit/runners/JUnit4.class");
assertNotNull("cannot find zipEntry org/junit/runners/JUnit4.class, entries: " + entries + ", content is: " + FileUtils.readFileToString(file.toFile(), Charset.forName("UTF-8")), zipEntry);
zipFile.close();
file.toFile().deleteOnExit();
}
Aggregations