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