@Override public BuildCommand toDownloadCommand(String locator, String checksumUrl, File checksumPath) { return BuildCommand.downloadFile(map( "url", format("/remoting/files/%s", locator), "checksumUrl", checksumUrl, "checksumFile", checksumPath.getPath(), "dest", artifact.getPath(), "src", srcFile )); }
@Test public void downloadFilePrintErrorWhenFailed() { runBuild(downloadFile(map( "url", "http://far.far.away/foo.jar", "dest", new File(sandbox, "bar.jar").getPath())), Failed); assertThat(console.output(), containsString("Could not fetch artifact")); }
@Test public void downloadFileWithMD5Check() throws IOException { httpService.setupDownload("http://far.far.away/foo.jar", "some content"); httpService.setupDownload("http://far.far.away/foo.jar.md5", "foo.jar=9893532233caff98cd083a116b013c0b"); runBuild(downloadFile(map( "url", "http://far.far.away/foo.jar", "dest", "dest.jar", "src", "foo.jar", "checksumUrl", "http://far.far.away/foo.jar.md5")), Passed); assertThat(console.output(), containsString(String.format("Saved artifact to [%s] after verifying the integrity of its contents", new File(sandbox, "dest.jar").getPath()))); assertThat(FileUtils.readFileToString(new File(sandbox, "dest.jar"), UTF_8), is("some content")); }
@Test public void downloadFileShouldAppendSha1IntoDownloadUrlIfDestFileAlreadyExists() throws IOException { File dest = new File(sandbox, "bar.jar"); Files.write(Paths.get(dest.getPath()), "foobar".getBytes()); String sha1 = java.net.URLEncoder.encode(FileUtil.sha1Digest(dest), "UTF-8"); httpService.setupDownload("http://far.far.away/foo.jar", "content without sha1"); httpService.setupDownload("http://far.far.away/foo.jar?sha1=" + sha1, "content with sha1"); runBuild(downloadFile(map( "url", "http://far.far.away/foo.jar", "dest", "bar.jar")), Passed); assertThat(console.output(), containsString("Saved artifact")); assertThat(FileUtils.readFileToString(dest, UTF_8), is("content with sha1")); } }
@Test public void downloadFileWithoutMD5Check() throws IOException { File dest = new File(sandbox, "bar.jar"); httpService.setupDownload("http://far.far.away/foo.jar", "some content"); runBuild(downloadFile(map( "url", "http://far.far.away/foo.jar", "dest", "bar.jar")), Passed); assertThat(console.output(), containsString("without verifying the integrity")); assertThat(FileUtils.readFileToString(dest, UTF_8), is("some content")); }