1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.vfs2;
18
19 import java.nio.file.Path;
20 import java.nio.file.Paths;
21
22 import org.junit.Test;
23
24
25
26
27 public class PathTests extends AbstractProviderTestCase {
28
29
30
31
32
33 @Override
34 protected Capability[] getRequiredCapabilities() {
35 return new Capability[] {Capability.URI};
36 }
37
38
39
40
41 @Test
42 public void testAbsoluteURI() throws Exception {
43 final FileObject readFolder = getReadFolder();
44
45
46 final String pathStr = readFolder.getPath().toString();
47 try (FileObject fileObject = getManager().resolveFile(pathStr,
48 readFolder.getFileSystem().getFileSystemOptions())) {
49 assertSame("file object", readFolder, fileObject);
50 }
51
52
53 final Path rootPath = Paths.get(readFolder.getName().getRootURI());
54 try (FileObject fileObject = getManager().resolveFile(rootPath.toString(),
55 readFolder.getFileSystem().getFileSystemOptions())) {
56 assertSame(readFolder.getFileSystem().getRoot(), fileObject);
57 assertEquals(rootPath, Paths.get(fileObject.getName().getRootURI()));
58 assertEquals(rootPath, fileObject.getName().getPath());
59 assertEquals(FileName.ROOT_PATH, fileObject.getName().getPath());
60 }
61 }
62
63 @Test
64 public void testGetPath() throws Exception {
65 try (final FileObject fileObject = getReadFolder().resolveFile("some-dir/")) {
66 final Path path = fileObject.getPath();
67
68
69 assertEquals(Paths.get(fileObject.getName().getURI()).toString(), path.toString());
70 assertEquals(Paths.get(fileObject.getName().getURI()), path);
71
72 assertEquals(fileObject.getPath().toString(), fileObject.getURI().toString());
73 }
74 }
75
76 @Test
77 public void testReservedCharacterSpace() throws FileSystemException {
78 try (final FileObject fileObject = getReadFolder().resolveFile("file with spaces.txt")) {
79 final Path path = fileObject.getPath();
80 final String string = path.toString();
81 assertTrue(string, string.contains("file%20with%20spaces.txt"));
82 }
83 try (final FileObject fileObject = getReadFolder().resolveFile("file%20with%20spaces.txt")) {
84 final Path path = fileObject.getPath();
85 final String string = path.toString();
86 assertTrue(string, string.contains("file%20with%20spaces.txt"));
87 }
88 }
89
90
91
92
93 @Test
94 public void testURIContentProvider() throws Exception {
95
96 try (final FileObject fileObject = getReadFolder().resolveFile("file1.txt")) {
97 assertTrue(fileObject.exists());
98
99 final Path path = fileObject.getPath();
100 final String pathStr = path.toString();
101 final FileSystemOptions options = getReadFolder().getFileSystem().getFileSystemOptions();
102
103 try (final FileObject f1 = getManager().resolveFile(pathStr, options);
104 final FileObject f2 = getManager().resolveFile(pathStr, options)) {
105
106 assertEquals("Two files resolved by URI must be equals on " + pathStr, f1, f2);
107 assertSame("Resolving two times should not produce new filesystem on " + pathStr, f1.getFileSystem(),
108 f2.getFileSystem());
109 }
110 }
111 }
112 }