View Javadoc
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  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   * Test for {@link CanExecuteFileFilter}.
34   */
35  // CHECKSTYLE:OFF Test code
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 // CHECKSTYLE:ON