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
22 import org.apache.commons.io.FileUtils;
23 import org.apache.commons.vfs2.FileObject;
24 import org.apache.commons.vfs2.FileSelectInfo;
25 import org.apache.commons.vfs2.FileSystemException;
26 import org.junit.AfterClass;
27 import org.junit.Assert;
28 import org.junit.BeforeClass;
29 import org.junit.Ignore;
30 import org.junit.Test;
31
32
33
34
35
36 @Ignore
37 public class CanExecuteFileFilterTest extends BaseFilterTest {
38
39 private static final String EXECUTABLE = "executable.txt";
40
41 private static final String NOT_EXECUTABLE = "notexecutable.txt";
42
43 private static File testDir;
44
45 private static File executableFile;
46
47 private static FileSelectInfo executableFileInfo;
48
49 private static File notExecutableFile;
50
51 private static FileSelectInfo notExecutableFileInfo;
52
53 private static File notExistingFile;
54
55 private static FileSelectInfo notExistingFileInfo;
56
57 private static File zipFile;
58
59 private static FileObject zipFileObj;
60
61 @AfterClass
62 public static void afterClass() throws IOException {
63
64 executableFileInfo = null;
65 executableFile.delete();
66 executableFile = null;
67
68 notExecutableFileInfo = null;
69 notExecutableFile.delete();
70 notExecutableFile = null;
71
72 notExistingFileInfo = null;
73 notExistingFile = null;
74
75 zipFileObj.close();
76 FileUtils.deleteQuietly(zipFile);
77 zipFile = null;
78
79 FileUtils.deleteDirectory(testDir);
80 testDir = null;
81
82 }
83
84 @BeforeClass
85 public static void beforeClass() throws IOException {
86
87 testDir = getTestDir(CanExecuteFileFilterTest.class.getName());
88
89 executableFile = new File(testDir, EXECUTABLE);
90 executableFileInfo = createFileSelectInfo(executableFile);
91 FileUtils.touch(executableFile);
92 executableFile.setExecutable(true);
93
94 notExecutableFile = new File(testDir, NOT_EXECUTABLE);
95 notExecutableFileInfo = createFileSelectInfo(notExecutableFile);
96 FileUtils.touch(notExecutableFile);
97 notExecutableFile.setExecutable(false);
98
99 notExistingFile = new File(testDir, "not-existing-file.txt");
100 notExistingFileInfo = createFileSelectInfo(notExistingFile);
101
102 zipFile = new File(getTempDir(), CanExecuteFileFilterTest.class.getName() + ".zip");
103 zipDir(testDir, "", zipFile);
104 zipFileObj = getZipFileObject(zipFile);
105
106 }
107
108 @Test
109 public void testAcceptCanExecute() throws FileSystemException {
110 Assert.assertTrue(CanExecuteFileFilter.CAN_EXECUTE.accept(executableFileInfo));
111 Assert.assertTrue(CanExecuteFileFilter.CAN_EXECUTE.accept(notExecutableFileInfo));
112 Assert.assertFalse(CanExecuteFileFilter.CAN_EXECUTE.accept(notExistingFileInfo));
113 }
114
115 @Test
116 public void testAcceptCannotExecute() throws FileSystemException {
117 Assert.assertFalse(CanExecuteFileFilter.CANNOT_EXECUTE.accept(executableFileInfo));
118 Assert.assertFalse(CanExecuteFileFilter.CANNOT_EXECUTE.accept(notExecutableFileInfo));
119 Assert.assertTrue(CanExecuteFileFilter.CANNOT_EXECUTE.accept(notExistingFileInfo));
120 }
121
122 }
123