1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.vfs2.provider.test;
18
19 import java.io.File;
20
21 import org.apache.commons.vfs2.AbstractProviderTestCase;
22 import org.apache.commons.vfs2.AbstractVfsTestCase;
23 import org.apache.commons.vfs2.FileObject;
24 import org.apache.commons.vfs2.FileSystem;
25 import org.apache.commons.vfs2.FileSystemException;
26 import org.junit.Test;
27
28
29
30
31 public class JunctionTests extends AbstractProviderTestCase {
32
33 private FileObject getBaseDir() throws FileSystemException {
34 final File file = AbstractVfsTestCase.getTestDirectoryFile();
35 assertTrue(file.exists());
36 return getManager().toFileObject(file);
37 }
38
39
40
41
42 @Test
43 public void testAncestors() throws Exception {
44 final FileSystem fs = getManager().createVirtualFileSystem("vfs://").getFileSystem();
45 final FileObject baseDir = getBaseDir();
46
47
48 FileObject file = fs.resolveFile("/a/b");
49 assertFalse(file.exists());
50 file = file.getParent();
51 assertFalse(file.exists());
52 file = file.getParent();
53 assertFalse(file.exists());
54
55
56 fs.addJunction("/a/b", baseDir);
57
58
59 file = fs.resolveFile("/a/b");
60 assertTrue("Does not exist", file.exists());
61 file = file.getParent();
62 assertTrue("Does not exist", file.exists());
63 file = file.getParent();
64 assertTrue("Does not exist", file.exists());
65 }
66
67
68
69
70 @Test
71 public void testNestedJunction() throws Exception {
72 final FileSystem fs = getManager().createVirtualFileSystem("vfs:").getFileSystem();
73 final FileObject baseDir = getBaseDir();
74 fs.addJunction("/a", baseDir);
75
76
77 try {
78 fs.addJunction("/a/b", baseDir);
79 fail();
80 } catch (final Exception e) {
81 assertSameMessage("vfs.impl/nested-junction.error", "vfs:/a/b", e);
82 }
83
84
85 try {
86 fs.addJunction("/a", baseDir);
87 fail();
88 } catch (final Exception e) {
89 assertSameMessage("vfs.impl/nested-junction.error", "vfs:/a", e);
90 }
91 }
92
93
94
95
96
97
98
99 }