KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > vfs > provider > test > JunctionTests


1 /*
2  * Copyright 2002-2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.commons.vfs.provider.test;
17
18 import org.apache.commons.AbstractVfsTestCase;
19 import org.apache.commons.vfs.FileObject;
20 import org.apache.commons.vfs.FileSystem;
21 import org.apache.commons.vfs.FileSystemException;
22 import org.apache.commons.vfs.test.AbstractProviderTestCase;
23
24 import java.io.File JavaDoc;
25
26 /**
27  * Additional junction test cases.
28  *
29  * @author <a HREF="mailto:adammurdoch@apache.org">Adam Murdoch</a>
30  */

31 public class JunctionTests
32     extends AbstractProviderTestCase
33 {
34     private FileObject getBaseDir() throws FileSystemException
35     {
36         final File JavaDoc file = AbstractVfsTestCase.getTestDirectoryFile();
37         assertTrue(file.exists());
38         return getManager().toFileObject(file);
39     }
40
41     /**
42      * Checks nested junctions are not supported.
43      */

44     public void testNestedJunction() throws Exception JavaDoc
45     {
46         final FileSystem fs = getManager().createVirtualFileSystem("vfs:").getFileSystem();
47         final FileObject baseDir = getBaseDir();
48         fs.addJunction("/a", baseDir);
49
50         // Nested
51
try
52         {
53             fs.addJunction("/a/b", baseDir);
54             fail();
55         }
56         catch (final Exception JavaDoc e)
57         {
58             assertSameMessage("vfs.impl/nested-junction.error", "vfs:/a/b", e);
59         }
60
61         // At same point
62
try
63         {
64             fs.addJunction("/a", baseDir);
65             fail();
66         }
67         catch (final Exception JavaDoc e)
68         {
69             assertSameMessage("vfs.impl/nested-junction.error", "vfs:/a", e);
70         }
71     }
72
73     /**
74      * Checks ancestors are created when a junction is created.
75      */

76     public void testAncestors() throws Exception JavaDoc
77     {
78         final FileSystem fs = getManager().createVirtualFileSystem("vfs://").getFileSystem();
79         final FileObject baseDir = getBaseDir();
80
81         // Make sure the file at the junction point and its ancestors do not exist
82
FileObject file = fs.resolveFile("/a/b");
83         assertFalse(file.exists());
84         file = file.getParent();
85         assertFalse(file.exists());
86         file = file.getParent();
87         assertFalse(file.exists());
88
89         // Add the junction
90
fs.addJunction("/a/b", baseDir);
91
92         // Make sure the file at the junction point and its ancestors exist
93
file = fs.resolveFile("/a/b");
94         assertTrue("Does not exist", file.exists());
95         file = file.getParent();
96         assertTrue("Does not exist", file.exists());
97         file = file.getParent();
98         assertTrue("Does not exist", file.exists());
99     }
100
101     // Check that file @ junction point exists only when backing file exists
102
// Add 2 junctions with common parent
103
// Compare real and virtual files
104
// Events
105
// Remove junctions
106

107 }
108
Popular Tags