1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.vfs2.filter;
18
19 import java.io.File;
20 import java.io.IOException;
21 import java.nio.file.Files;
22
23 import org.apache.commons.io.FileUtils;
24 import org.apache.commons.vfs2.FileFilter;
25 import org.apache.commons.vfs2.FileFilterSelector;
26 import org.apache.commons.vfs2.FileObject;
27 import org.apache.commons.vfs2.FileSelectInfo;
28 import org.apache.commons.vfs2.FileSystemException;
29 import org.junit.AfterClass;
30 import org.junit.Assert;
31 import org.junit.Assume;
32 import org.junit.BeforeClass;
33 import org.junit.Test;
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52 public class SymbolicLinkFileFilterTest extends BaseFilterTest {
53
54 private static File testDir;
55
56 private static File targetFile;
57
58 private static FileSelectInfo targetFileInfo;
59
60 private static File linkFile;
61
62 private static FileSelectInfo linkFileInfo;
63
64 private static File notExistingFile;
65
66 private static FileSelectInfo notExistingFileInfo;
67
68 private static File zipFile;
69
70 private static FileObject zipFileObject;
71
72 @AfterClass
73 public static void afterClass() throws IOException {
74 targetFile = null;
75 targetFileInfo = null;
76 linkFile = null;
77 linkFileInfo = null;
78 notExistingFile = null;
79 notExistingFileInfo = null;
80 if (zipFileObject != null) {
81 zipFileObject.close();
82 }
83 if (zipFile != null) {
84 FileUtils.deleteQuietly(zipFile);
85 zipFile = null;
86 }
87 if (testDir != null) {
88 FileUtils.deleteDirectory(testDir);
89 testDir = null;
90 }
91 }
92
93 @BeforeClass
94 public static void beforeClass() throws IOException {
95 Assume.assumeTrue(Boolean.getBoolean(SymbolicLinkFileFilterTest.class.getSimpleName() + ".Enable"));
96
97 testDir = getTestDir(SymbolicLinkFileFilterTest.class.getName());
98 testDir.mkdir();
99
100 linkFile = new File(testDir, "visible.txt");
101 linkFileInfo = createFileSelectInfo(linkFile);
102
103 targetFile = new File(testDir, "symbolic.txt");
104 Files.deleteIfExists(targetFile.toPath());
105 FileUtils.touch(targetFile);
106 Files.createSymbolicLink(linkFile.toPath(), targetFile.toPath());
107 targetFileInfo = createFileSelectInfo(targetFile);
108
109 notExistingFile = new File(testDir, "not-existing-file.txt");
110 notExistingFileInfo = createFileSelectInfo(notExistingFile);
111
112
113 zipFile = new File(getTempDir(), SymbolicLinkFileFilterTest.class.getName() + ".zip");
114 zipDir(testDir, "", zipFile);
115 zipFileObject = getZipFileObject(zipFile);
116 }
117
118 @Test
119 public void testAcceptActual() throws FileSystemException {
120 final FileFilter testee = SymbolicLinkFileFilter.ACTUAL;
121 Assert.assertTrue(targetFileInfo.getBaseFolder().exists());
122 Assert.assertTrue(targetFileInfo.getFile().exists());
123 Assert.assertTrue(targetFileInfo.toString(), testee.accept(targetFileInfo));
124 Assert.assertTrue(notExistingFileInfo.toString(), testee.accept(notExistingFileInfo));
125 }
126
127 @Test
128 public void testAcceptSymbolic() throws FileSystemException {
129 final FileFilter testee = SymbolicLinkFileFilter.SYMBOLIC;
130 Assert.assertTrue(linkFileInfo.toString(), testee.accept(linkFileInfo));
131 Assert.assertFalse(notExistingFileInfo.toString(), testee.accept(notExistingFileInfo));
132 }
133
134 @Test
135 public void testZipFile() throws FileSystemException {
136 final FileObject[] files = zipFileObject.findFiles(new FileFilterSelector(SymbolicLinkFileFilter.SYMBOLIC));
137 Assert.assertEquals(0, files.length);
138 }
139
140 }
141