Skip to content

Commit

Permalink
[JENKINS-19752] Test
Browse files Browse the repository at this point in the history
(cherry picked from commit 82af0fb)
  • Loading branch information
olivergondza committed Oct 18, 2013
1 parent ab9b58e commit 2652a3a
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions test/src/test/java/hudson/model/DirectoryBrowserSupportTest.java
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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;
}
}

0 comments on commit 2652a3a

Please sign in to comment.