From 82af0fb5622f9f913d3cad39c04eb21a2184bef8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20Gond=C5=BEa?= Date: Thu, 26 Sep 2013 16:34:39 +0200 Subject: [PATCH] [JENKINS-19752] Test --- .../model/DirectoryBrowserSupportTest.java | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/test/src/test/java/hudson/model/DirectoryBrowserSupportTest.java b/test/src/test/java/hudson/model/DirectoryBrowserSupportTest.java index a342c88ab50b..02441fef14b7 100644 --- a/test/src/test/java/hudson/model/DirectoryBrowserSupportTest.java +++ b/test/src/test/java/hudson/model/DirectoryBrowserSupportTest.java @@ -29,17 +29,29 @@ import hudson.FilePath; import hudson.Functions; import hudson.Launcher; +import hudson.Util; +import hudson.tasks.ArtifactArchiver; import hudson.tasks.BatchFile; import hudson.tasks.Shell; +import java.io.File; +import java.io.FileOutputStream; import java.io.IOException; +import java.io.InputStream; +import java.util.zip.ZipFile; import org.junit.Rule; import org.junit.Test; +import org.jvnet.hudson.test.Bug; import org.jvnet.hudson.test.Email; import org.jvnet.hudson.test.JenkinsRule; +import org.jvnet.hudson.test.SingleFileSCM; import org.jvnet.hudson.test.TestBuilder; +import com.gargoylesoftware.htmlunit.Page; +import com.gargoylesoftware.htmlunit.UnexpectedPage; +import com.gargoylesoftware.htmlunit.html.HtmlPage; + /** * @author Kohsuke Kawaguchi */ @@ -133,4 +145,36 @@ public void glob() throws Exception { assertFalse(text, text.contains("x.txt")); } + @Bug(19752) + @Test + public void zipDownload() throws Exception { + FreeStyleProject p = j.createFreeStyleProject(); + p.setScm(new SingleFileSCM("artifact.out", "Hello world!")); + p.getPublishersList().add(new ArtifactArchiver("*", "", true)); + assertEquals(Result.SUCCESS, p.scheduleBuild2(0).get().getResult()); + + HtmlPage page = j.createWebClient().goTo("job/"+p.getName()+"/lastSuccessfulBuild/artifact/"); + Page download = page.getAnchorByHref("./*zip*/archive.zip").click(); + File zipfile = download((UnexpectedPage) download); + + ZipFile readzip = new ZipFile(zipfile); + + InputStream is = readzip.getInputStream(readzip.getEntry("artifact.out")); + + // ZipException in case of JENKINS-19752 + assertFalse("Downloaded zip file must not be empty", is.read() == -1); + + is.close(); + readzip.close(); + zipfile.delete(); + } + + private File download(UnexpectedPage page) throws IOException { + + File file = new File("/home/ogondza/zipfile");//File.createTempFile("DirectoryBrowserSupport", "zipDownload"); + file.delete(); + Util.copyStreamAndClose(page.getInputStream(), new FileOutputStream(file)); + + return file; + } }