1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.vfs2.provider.zip;
19
20 import java.io.File;
21
22 import org.apache.commons.vfs2.FileObject;
23 import org.apache.commons.vfs2.FileSystemException;
24 import org.apache.commons.vfs2.VFS;
25 import org.apache.commons.vfs2.cache.OnCallRefreshFileObject;
26 import org.apache.commons.vfs2.function.VfsConsumer;
27 import org.junit.After;
28 import org.junit.Assert;
29 import org.junit.Before;
30 import org.junit.Test;
31
32 public class Jira733TestCase {
33
34 @After
35 @Before
36 public void reset() throws FileSystemException {
37 VFS.reset();
38 }
39
40 @Test
41 public void testZipParentLayer() throws Exception {
42 final File file = new File("src/test/resources/test-data/test.zip");
43 final String nestedPath = "zip:" + file.getAbsolutePath() + "!/read-tests/file1.txt";
44 try (final FileObject fileObject = VFS.getManager().resolveFile(nestedPath);
45 final FileObject wrappedFileObject = new OnCallRefreshFileObject(fileObject)) {
46
47 Assert.assertNotNull("getParentLayer() 1", wrappedFileObject.getFileSystem().getParentLayer());
48 wrappedFileObject.exists();
49 wrappedFileObject.getContent();
50 Assert.assertNotNull("getParentLayer() 2", wrappedFileObject.getFileSystem().getParentLayer());
51 }
52 }
53
54 private void testZipParentLayer(final VfsConsumer<FileObject> consumer) throws Exception {
55 final File file = new File("src/test/resources/test-data/test.zip");
56 Assert.assertTrue(file.exists());
57 final String nestedPath = "zip:" + file.getAbsolutePath() + "!/read-tests/file1.txt";
58 try (final FileObject fileObject = VFS.getManager().resolveFile(nestedPath);
59 final FileObject wrappedFileObject = new OnCallRefreshFileObject(fileObject)) {
60 Assert.assertTrue(fileObject instanceof ZipFileObject);
61 @SuppressWarnings({ "unused", "resource" })
62 final
63 ZipFileObject zipFileObject = (ZipFileObject) fileObject;
64 Assert.assertNotNull("getParentLayer() 1", wrappedFileObject.getFileSystem().getParentLayer());
65 consumer.accept(wrappedFileObject);
66 Assert.assertNotNull("getParentLayer() 2", wrappedFileObject.getFileSystem().getParentLayer());
67 }
68 }
69
70 @Test
71 public void testZipParentLayer_exists() throws Exception {
72 testZipParentLayer(FileObject::exists);
73 }
74
75 @Test
76 public void testZipParentLayer_exists_getContents() throws Exception {
77 testZipParentLayer(fileObject -> {
78 fileObject.exists();
79 fileObject.getContent();
80 });
81 }
82
83 @Test
84 public void testZipParentLayer_getChildren() throws Exception {
85 testZipParentLayer(fileObject -> fileObject.getParent().getChildren());
86 }
87
88 @Test
89 public void testZipParentLayer_getContents() throws Exception {
90 testZipParentLayer(FileObject::getContent);
91 }
92
93 @Test
94 public void testZipParentLayer_getType() throws Exception {
95 testZipParentLayer(FileObject::getType);
96 }
97
98 @Test
99 public void testZipParentLayer_isAttached() throws Exception {
100 testZipParentLayer(FileObject::isAttached);
101 }
102
103 @Test
104 public void testZipParentLayer_isContentOpen() throws Exception {
105 testZipParentLayer(FileObject::isContentOpen);
106 }
107
108 @Test
109 public void testZipParentLayer_isExecutable() throws Exception {
110 testZipParentLayer(FileObject::isExecutable);
111 }
112
113 @Test
114 public void testZipParentLayer_isFile() throws Exception {
115 testZipParentLayer(FileObject::isFile);
116 }
117
118 @Test
119 public void testZipParentLayer_isFolder() throws Exception {
120 testZipParentLayer(FileObject::isFolder);
121 }
122
123 @Test
124 public void testZipParentLayer_isHidden() throws Exception {
125 testZipParentLayer(FileObject::isHidden);
126 }
127
128 @Test
129 public void testZipParentLayer_isReadable() throws Exception {
130 testZipParentLayer(FileObject::isReadable);
131 }
132
133 @Test
134 public void testZipParentLayer_isWriteable() throws Exception {
135 testZipParentLayer(FileObject::isWriteable);
136 }
137 }