forked from gooddata/gooddata-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathZipUtilsTest.java
More file actions
67 lines (59 loc) · 2.47 KB
/
Copy pathZipUtilsTest.java
File metadata and controls
67 lines (59 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package com.gooddata;
import static org.junit.Assert.*;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
public class ZipUtilsTest {
@Rule
public TemporaryFolder temporaryFolder = new TemporaryFolder();
@Test
public void shouldZipSingleFile() throws Exception {
final File file = temporaryFolder.newFile("someFile.zip");
try (ByteArrayOutputStream output = new ByteArrayOutputStream()) {
ZipUtils.zip(file, output);
output.close();
try (ZipInputStream zipInputStream = new ZipInputStream(new ByteArrayInputStream(output.toByteArray()))) {
ZipEntry entry = zipInputStream.getNextEntry();
assertNotNull(entry);
assertEquals("someFile.zip", entry.getName());
}
}
}
@Test
public void shouldZipDir() throws Exception {
File toZipDir = temporaryFolder.newFolder("toZip");
File toZipFile = toZipDir.toPath().resolve("a/b/someFile.zip").toFile();
toZipFile.getParentFile().mkdirs();
toZipFile.createNewFile();
try (ByteArrayOutputStream output = new ByteArrayOutputStream()) {
ZipUtils.zip(toZipDir, output, true);
output.close();
try (ZipInputStream zipInputStream = new ZipInputStream(new ByteArrayInputStream(output.toByteArray()))) {
ZipEntry entry = zipInputStream.getNextEntry();
assertNotNull(entry);
assertEquals("toZip/a/b/someFile.zip", entry.getName());
}
}
}
@Test
public void shouldZipDirWithoutRoot() throws Exception {
File toZipDir = temporaryFolder.newFolder("toZip");
File toZipFile = toZipDir.toPath().resolve("a/b/someFile.zip").toFile();
toZipFile.getParentFile().mkdirs();
toZipFile.createNewFile();
try (ByteArrayOutputStream output = new ByteArrayOutputStream()) {
ZipUtils.zip(toZipDir, output);
output.close();
try (ZipInputStream zipInputStream = new ZipInputStream(new ByteArrayInputStream(output.toByteArray()))) {
ZipEntry entry = zipInputStream.getNextEntry();
assertNotNull(entry);
assertEquals("a/b/someFile.zip", entry.getName());
}
}
}
}