|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +package org.apache.commons.vfs2.provider.cczip; |
| 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 = "commonscompresszip:" + file.getAbsolutePath() + "!/read-tests/file1.txt"; |
| 44 | + try (final FileObject fileObject = VFS.getManager().resolveFile(nestedPath); |
| 45 | + final FileObject wrappedFileObject = new OnCallRefreshFileObject(fileObject)) { |
| 46 | + // VFS.getManager().getFilesCache().close(); |
| 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 = "commonscompresszip:" + 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 CommonsCompressZipFileObject); |
| 61 | + @SuppressWarnings({"unused", "resource"}) final CommonsCompressZipFileObject zipFileObject = (CommonsCompressZipFileObject) fileObject; |
| 62 | + Assert.assertNotNull("getParentLayer() 1", wrappedFileObject.getFileSystem().getParentLayer()); |
| 63 | + consumer.accept(wrappedFileObject); |
| 64 | + Assert.assertNotNull("getParentLayer() 2", wrappedFileObject.getFileSystem().getParentLayer()); |
| 65 | + } |
| 66 | + } |
| 67 | + |
| 68 | + @Test |
| 69 | + public void testZipParentLayer_exists() throws Exception { |
| 70 | + testZipParentLayer(FileObject::exists); |
| 71 | + } |
| 72 | + |
| 73 | + @Test |
| 74 | + public void testZipParentLayer_exists_getContents() throws Exception { |
| 75 | + testZipParentLayer(fileObject -> { |
| 76 | + fileObject.exists(); |
| 77 | + fileObject.getContent(); |
| 78 | + }); |
| 79 | + } |
| 80 | + |
| 81 | + @Test |
| 82 | + public void testZipParentLayer_getChildren() throws Exception { |
| 83 | + testZipParentLayer(fileObject -> fileObject.getParent().getChildren()); |
| 84 | + } |
| 85 | + |
| 86 | + @Test |
| 87 | + public void testZipParentLayer_getContents() throws Exception { |
| 88 | + testZipParentLayer(FileObject::getContent); |
| 89 | + } |
| 90 | + |
| 91 | + @Test |
| 92 | + public void testZipParentLayer_getType() throws Exception { |
| 93 | + testZipParentLayer(FileObject::getType); |
| 94 | + } |
| 95 | + |
| 96 | + @Test |
| 97 | + public void testZipParentLayer_isAttached() throws Exception { |
| 98 | + testZipParentLayer(FileObject::isAttached); |
| 99 | + } |
| 100 | + |
| 101 | + @Test |
| 102 | + public void testZipParentLayer_isContentOpen() throws Exception { |
| 103 | + testZipParentLayer(FileObject::isContentOpen); |
| 104 | + } |
| 105 | + |
| 106 | + @Test |
| 107 | + public void testZipParentLayer_isExecutable() throws Exception { |
| 108 | + testZipParentLayer(FileObject::isExecutable); |
| 109 | + } |
| 110 | + |
| 111 | + @Test |
| 112 | + public void testZipParentLayer_isFile() throws Exception { |
| 113 | + testZipParentLayer(FileObject::isFile); |
| 114 | + } |
| 115 | + |
| 116 | + @Test |
| 117 | + public void testZipParentLayer_isFolder() throws Exception { |
| 118 | + testZipParentLayer(FileObject::isFolder); |
| 119 | + } |
| 120 | + |
| 121 | + @Test |
| 122 | + public void testZipParentLayer_isHidden() throws Exception { |
| 123 | + testZipParentLayer(FileObject::isHidden); |
| 124 | + } |
| 125 | + |
| 126 | + @Test |
| 127 | + public void testZipParentLayer_isReadable() throws Exception { |
| 128 | + testZipParentLayer(FileObject::isReadable); |
| 129 | + } |
| 130 | + |
| 131 | + @Test |
| 132 | + public void testZipParentLayer_isWriteable() throws Exception { |
| 133 | + testZipParentLayer(FileObject::isWriteable); |
| 134 | + } |
| 135 | +} |
0 commit comments