/** * Download the required file from artifactory */ private static java.io.File downloadFile(Artifactory artifactory, String repo, String filePath, String fileDownloadToLocation) throws Exception { if (artifactory == null || StringUtils.isEmpty(repo) || StringUtils.isEmpty(filePath)){ throw new IllegalArgumentException("Arguments passed to downloadFile are not valid"); } InputStream inputStream = artifactory.repository(repo) .download(filePath) .doDownload(); java.io.File targetFile = new java.io.File(fileDownloadToLocation); FileUtils.copyInputStreamToFile(inputStream, targetFile); return targetFile; }
@Test(dependsOnMethods = "testUploadWithMultipleProperties") public void testDownloadWithMandatoryAndNonMandatoryProperties() throws IOException { InputStream inputStream = artifactory.repository(localRepository.getKey()).download(PATH).withProperty("released", false) .withProperty("foo", "bar").withMandatoryProperty("colors", "red").doDownload(); assertEquals(textFrom(inputStream), textFrom(this.getClass().getResourceAsStream("/sample.txt"))); } }
@Test(dependsOnMethods = "testUploadWithMultipleProperties", expectedExceptions = IOException.class) public void testDownloadWithNonExistingMandatoryProperties() throws IOException { // Property doesn't exist, will fail artifactory.repository(localRepository.getKey()).download(PATH).withMandatoryProperty("foo", "bar").doDownload(); }
@Test(dependsOnMethods = "testUploadWithMultipleProperties", expectedExceptions = HttpResponseException.class) public void testDownloadWithWrongNonMandatoryProperties() throws IOException { //property doesn't match, will fail artifactory.repository(localRepository.getKey()).download(PATH).withProperty("colors", "black").doDownload(); }
@Test(dependsOnMethods = "testUploadWithMultipleProperties") public void testDownloadWithMatchingNonMandatoryProperties() throws IOException { //property matches InputStream inputStream = artifactory.repository(localRepository.getKey()).download(PATH).withProperty("colors", "red") .doDownload(); assertEquals(textFrom(inputStream), textFrom(this.getClass().getResourceAsStream("/sample.txt"))); }
@Test(dependsOnMethods = "testUploadWithMultipleProperties", expectedExceptions = HttpResponseException.class) public void testDownloadWithWrongMandatoryProperties() throws IOException { // Property doesn't match, will fail artifactory.repository(localRepository.getKey()).download(PATH).withMandatoryProperty("colors", "black").doDownload(); }
InputStream response = client.repository(repoName).download(metadataStr).doDownload(); LOGGER.info("download complete"); Files.copy(response, tempFilePath, StandardCopyOption.REPLACE_EXISTING);
@Test(dependsOnMethods = "testUploadWithMultipleProperties") public void testDownloadWithNonExistingNonMandatoryProperties() throws IOException { //property doesn't exist InputStream inputStream = artifactory.repository(localRepository.getKey()).download(PATH).withProperty("foo", "bar").doDownload(); assertEquals(textFrom(inputStream), textFrom(this.getClass().getResourceAsStream("/sample.txt"))); }
@Test(dependsOnMethods = "testUploadWithMultipleProperties") public void testDownloadWithMatchingMandatoryProperties() throws IOException { // Property matches InputStream inputStream = artifactory.repository(localRepository.getKey()).download(PATH).withMandatoryProperty("colors", "red").doDownload(); assertEquals(textFrom(inputStream), textFrom(this.getClass().getResourceAsStream("/sample.txt"))); }
@Test(dependsOnMethods = "testUploadWithSingleProperty") public void testDownloadWithoutProperties() throws IOException { InputStream inputStream = artifactory.repository(localRepository.getKey()).download(PATH).doDownload(); String actual = textFrom(inputStream); assertEquals(actual, textFrom(this.getClass().getResourceAsStream("/sample.txt"))); }
@Test(dependsOnMethods = "testUploadWithSingleProperty") public void testUploadCopyBySha1WithSingleProperty() throws IOException { InputStream inputStream = this.getClass().getResourceAsStream("/sample.txt"); assertNotNull(inputStream); String refPath = "r/a/b/c.txt"; String sha1 = calcSha1(inputStream); File deployed = artifactory.repository(localRepository.getKey()) .copyBySha1(refPath, sha1) .withProperty("color", "red") .doUpload(); assertNotNull(deployed); inputStream = artifactory.repository(localRepository.getKey()).download(refPath).doDownload(); String actual = textFrom(inputStream); assertEquals(actual, textFrom(this.getClass().getResourceAsStream("/sample.txt"))); assertTrue(curlAndStrip("api/storage/" + localRepository.getKey() + "/" + refPath + "?properties").contains("\"color\":[\"red\"]")); }
@Test public void testFolderInfo() throws IOException { // Get the folder to the cache artifactory.repository(getJCenterRepoName()).download("junit/junit/4.10/junit-4.10-sources.jar").doDownload(); Folder folder = artifactory.repository(getJcenterCacheName()).folder("junit").info(); assertNotNull(folder); assertTrue(folder.isFolder()); assertEquals(folder.getChildren().size(), 1); assertEquals(folder.getRepo(), getJcenterCacheName()); assertEquals(folder.getPath(), "/junit"); }
@Test public void testFileInfo() throws IOException { // Get the file to the cache artifactory.repository(getJCenterRepoName()).download("junit/junit/4.10/junit-4.10-sources.jar").doDownload(); File file = artifactory.repository(getJcenterCacheName()).file("junit/junit/4.10/junit-4.10-sources.jar").info(); assertNotNull(file); assertFalse(file.isFolder()); assertEquals(file.getSize(), 141185); assertEquals(file.getDownloadUri(), url + getJcenterCacheName() + "/junit/junit/4.10/junit-4.10-sources.jar"); assertEquals(file.getChecksums().getMd5(), "8f17d4271b86478a2731deebdab8c846"); assertEquals(file.getChecksums().getSha1(), "6c98d6766e72d5575f96c9479d1c1d3b865c6e25"); }