1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.vfs2.provider.tar;
18
19 import java.io.File;
20
21 import org.apache.commons.vfs2.FileObject;
22 import org.apache.commons.vfs2.FileSystemException;
23 import org.apache.commons.vfs2.FileSystemManager;
24 import org.apache.commons.vfs2.VFS;
25 import org.junit.Assert;
26 import org.junit.Test;
27
28
29 public class TarFileObjectTestCase {
30
31 private void testReadSpecialNameFileInFile(final String testFilePath, final String scheme) throws FileSystemException {
32
33 final File testFile = new File(testFilePath);
34 final String[] fileNames = {"file.txt", "file^.txt", "file~.txt", "file?.txt", "file@.txt", "file$.txt",
35 "file*.txt", "file&.txt", "file#.txt", "file%.txt", "file!.txt"};
36 final FileSystemManager manager = VFS.getManager();
37 final String baseUrl = scheme + ":file:" + testFile.getAbsolutePath();
38
39
40 try (final FileObject fileObject = manager.resolveFile(baseUrl)) {
41
42 Assert.assertEquals(fileObject.getChildren().length, fileNames.length);
43
44
45 for (final String fileName : fileNames) {
46 Assert.assertNotNull("can't read file " + fileName, fileObject.getChild(fileName));
47 }
48 }
49 }
50
51
52
53
54 @Test
55 public void testReadSpecialNameFileInTarFile() throws FileSystemException {
56
57 testReadSpecialNameFileInFile("src/test/resources/test-data/special_fileName.tar", "tar");
58 }
59
60
61
62
63 @Test
64 public void testReadSpecialNameFileInTbz2File() throws FileSystemException {
65
66 testReadSpecialNameFileInFile("src/test/resources/test-data/special_fileName.tbz2", "tbz2");
67 }
68
69
70
71
72 @Test
73 public void testReadSpecialNameFileInTgzFile() throws FileSystemException {
74
75 testReadSpecialNameFileInFile("src/test/resources/test-data/special_fileName.tgz", "tgz");
76 }
77 }