1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.vfs.provider.test;
18
19 import org.apache.commons.AbstractVfsTestCase;
20 import org.apache.commons.vfs.FileObject;
21 import org.apache.commons.vfs.FileSystem;
22 import org.apache.commons.vfs.FileSystemException;
23 import org.apache.commons.vfs.test.AbstractProviderTestCase;
24
25 import java.io.File;
26
27 /***
28 * Additional junction test cases.
29 *
30 * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
31 * @version $Revision: 480428 $ $Date: 2006-11-29 07:15:24 +0100 (Mi, 29 Nov 2006) $
32 */
33 public class JunctionTests
34 extends AbstractProviderTestCase
35 {
36 private FileObject getBaseDir() throws FileSystemException
37 {
38 final File file = AbstractVfsTestCase.getTestDirectoryFile();
39 assertTrue(file.exists());
40 return getManager().toFileObject(file);
41 }
42
43 /***
44 * Checks nested junctions are not supported.
45 */
46 public void testNestedJunction() throws Exception
47 {
48 final FileSystem fs = getManager().createVirtualFileSystem("vfs:").getFileSystem();
49 final FileObject baseDir = getBaseDir();
50 fs.addJunction("/a", baseDir);
51
52
53 try
54 {
55 fs.addJunction("/a/b", baseDir);
56 fail();
57 }
58 catch (final Exception e)
59 {
60 assertSameMessage("vfs.impl/nested-junction.error", "vfs:/a/b", e);
61 }
62
63
64 try
65 {
66 fs.addJunction("/a", baseDir);
67 fail();
68 }
69 catch (final Exception e)
70 {
71 assertSameMessage("vfs.impl/nested-junction.error", "vfs:/a", e);
72 }
73 }
74
75 /***
76 * Checks ancestors are created when a junction is created.
77 */
78 public void testAncestors() throws Exception
79 {
80 final FileSystem fs = getManager().createVirtualFileSystem("vfs://").getFileSystem();
81 final FileObject baseDir = getBaseDir();
82
83
84 FileObject file = fs.resolveFile("/a/b");
85 assertFalse(file.exists());
86 file = file.getParent();
87 assertFalse(file.exists());
88 file = file.getParent();
89 assertFalse(file.exists());
90
91
92 fs.addJunction("/a/b", baseDir);
93
94
95 file = fs.resolveFile("/a/b");
96 assertTrue("Does not exist", file.exists());
97 file = file.getParent();
98 assertTrue("Does not exist", file.exists());
99 file = file.getParent();
100 assertTrue("Does not exist", file.exists());
101 }
102
103
104
105
106
107
108
109 }