Search in sources :

Example 1 with DependenciesDownloaderHelper

use of org.jfrog.build.extractor.clientConfiguration.util.DependenciesDownloaderHelper in project build-info by JFrogDev.

the class DownloadTest method testBulkAndConcurrentDownload.

/**
 * Tests download of files - both bulk and concurrently.
 * @param uploadedChecksum checksums of the artifact uploaded to Artifactory, used to compare with the downloaded artifact.
 * @param fileName
 * @param fileSize
 */
@Test(dataProvider = "testDownloadFilesProvider")
public void testBulkAndConcurrentDownload(Map<String, String> uploadedChecksum, String fileName, long fileSize) throws Exception {
    String uriWithParams = dependenciesClient.getArtifactoryUrl() + "/" + localRepo + "/" + TEST_REPO_PATH + "/" + fileName;
    String fileDestination = tempWorkspace.getPath() + File.separatorChar + "download" + File.separatorChar + fileName;
    DependenciesDownloaderHelper helper = new DependenciesDownloaderHelper(dependenciesClient, tempWorkspace.getPath(), log);
    DependenciesDownloaderHelper.ArtifactMetaData artifactMetaData = helper.downloadArtifactMetaData(uriWithParams);
    Assert.assertEquals(artifactMetaData.getSize(), fileSize);
    Map<String, String> downloadedChecksum;
    if (fileSize >= MIN_SIZE_FOR_CONCURRENT_DOWNLOAD && artifactMetaData.isAcceptRange()) {
        // Perform concurrent download.
        downloadedChecksum = helper.downloadFileConcurrently(uriWithParams, fileSize, fileDestination, fileName);
    } else {
        // Perform bulk download.
        downloadedChecksum = helper.downloadFile(uriWithParams, fileDestination);
    }
    // Verify the downloaded file.
    Assert.assertEquals(uploadedChecksum.get(MD5_ALGORITHM_NAME), downloadedChecksum.get(MD5_ALGORITHM_NAME));
    Assert.assertEquals(uploadedChecksum.get(SHA1_ALGORITHM_NAME), downloadedChecksum.get(SHA1_ALGORITHM_NAME));
}
Also used : DependenciesDownloaderHelper(org.jfrog.build.extractor.clientConfiguration.util.DependenciesDownloaderHelper) Test(org.testng.annotations.Test)

Example 2 with DependenciesDownloaderHelper

use of org.jfrog.build.extractor.clientConfiguration.util.DependenciesDownloaderHelper in project build-info by JFrogDev.

the class DownloadTest method testDownloadArtifact.

@Test(dataProvider = "testDownloadFilesProvider")
public void testDownloadArtifact(Map<String, String> uploadedChecksum, String fileName, long fileSize) throws Exception {
    DependenciesDownloaderHelper dependenciesDownloaderHelper = new DependenciesDownloaderHelper(dependenciesClient, ".", log);
    String repoUrl = dependenciesClient.getArtifactoryUrl() + "/" + localRepo + "/" + TEST_REPO_PATH;
    String targetDirPath = tempWorkspace.getPath() + File.separatorChar + "download" + File.separatorChar;
    String url = repoUrl + "/" + fileName;
    ArtifactMetaData artifactMetaData = dependenciesDownloaderHelper.downloadArtifactMetaData(url);
    Assert.assertEquals(artifactMetaData.getMd5(), uploadedChecksum.get(MD5_ALGORITHM_NAME));
    Assert.assertEquals(artifactMetaData.getSha1(), uploadedChecksum.get(SHA1_ALGORITHM_NAME));
    Assert.assertEquals(artifactMetaData.getSize(), fileSize);
    DownloadableArtifact downloadableArtifact = new DownloadableArtifact(repoUrl, targetDirPath, fileName, "", fileName, PatternType.NORMAL);
    Dependency dependency = dependenciesDownloaderHelper.downloadArtifact(downloadableArtifact, artifactMetaData, url, fileName);
    Assert.assertEquals(dependency.getId(), fileName);
    Assert.assertEquals(dependency.getMd5(), uploadedChecksum.get(MD5_ALGORITHM_NAME));
    Assert.assertEquals(dependency.getSha1(), uploadedChecksum.get(SHA1_ALGORITHM_NAME));
    Assert.assertEquals((new File(targetDirPath + fileName)).length(), fileSize);
}
Also used : DependenciesDownloaderHelper(org.jfrog.build.extractor.clientConfiguration.util.DependenciesDownloaderHelper) DownloadableArtifact(org.jfrog.build.api.dependency.DownloadableArtifact) Dependency(org.jfrog.build.api.Dependency) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) Test(org.testng.annotations.Test)

Example 3 with DependenciesDownloaderHelper

use of org.jfrog.build.extractor.clientConfiguration.util.DependenciesDownloaderHelper in project build-info by JFrogDev.

the class DownloadTest method testDownloadArtifactWithoutContentLength.

@Test(dataProvider = "testDownloadFilesProvider")
public void testDownloadArtifactWithoutContentLength(Map<String, String> uploadedChecksum, String fileName, long fileSize) throws Exception {
    DependenciesDownloaderHelper dependenciesDownloaderHelper = new DependenciesDownloaderHelper(dependenciesClient, ".", log);
    String repoUrl = dependenciesClient.getArtifactoryUrl() + "/" + localRepo + "/" + TEST_REPO_PATH;
    String targetDirPath = tempWorkspace.getPath() + File.separatorChar + "download" + File.separatorChar;
    String url = repoUrl + "/" + fileName;
    ArtifactMetaData artifactMetaData = dependenciesDownloaderHelper.downloadArtifactMetaData(url);
    Assert.assertEquals(artifactMetaData.getMd5(), uploadedChecksum.get(MD5_ALGORITHM_NAME));
    Assert.assertEquals(artifactMetaData.getSha1(), uploadedChecksum.get(SHA1_ALGORITHM_NAME));
    Assert.assertEquals(artifactMetaData.getSize(), fileSize);
    // When content-length is missing
    artifactMetaData.setSize(0);
    DownloadableArtifact downloadableArtifact = new DownloadableArtifact(repoUrl, targetDirPath, fileName, "", fileName, PatternType.NORMAL);
    Dependency dependency = dependenciesDownloaderHelper.downloadArtifact(downloadableArtifact, artifactMetaData, url, fileName);
    Assert.assertEquals(dependency.getId(), fileName);
    Assert.assertEquals(dependency.getMd5(), uploadedChecksum.get(MD5_ALGORITHM_NAME));
    Assert.assertEquals(dependency.getSha1(), uploadedChecksum.get(SHA1_ALGORITHM_NAME));
    Assert.assertEquals((new File(targetDirPath + fileName)).length(), fileSize);
}
Also used : DependenciesDownloaderHelper(org.jfrog.build.extractor.clientConfiguration.util.DependenciesDownloaderHelper) DownloadableArtifact(org.jfrog.build.api.dependency.DownloadableArtifact) Dependency(org.jfrog.build.api.Dependency) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) Test(org.testng.annotations.Test)

Aggregations

DependenciesDownloaderHelper (org.jfrog.build.extractor.clientConfiguration.util.DependenciesDownloaderHelper)3 Test (org.testng.annotations.Test)3 File (java.io.File)2 RandomAccessFile (java.io.RandomAccessFile)2 Dependency (org.jfrog.build.api.Dependency)2 DownloadableArtifact (org.jfrog.build.api.dependency.DownloadableArtifact)2