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