View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
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   * Additional junction test cases.
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       * Checks ancestors are created when a junction is created.
41       */
42      @Test
43      public void testAncestors() throws Exception {
44          final FileSystem fs = getManager().createVirtualFileSystem("vfs://").getFileSystem();
45          final FileObject baseDir = getBaseDir();
46  
47          // Make sure the file at the junction point and its ancestors do not exist
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          // Add the junction
56          fs.addJunction("/a/b", baseDir);
57  
58          // Make sure the file at the junction point and its ancestors exist
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       * Checks nested junctions are not supported.
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          // Nested
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          // At same point
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      // Check that file @ junction point exists only when backing file exists
94      // Add 2 junctions with common parent
95      // Compare real and virtual files
96      // Events
97      // Remove junctions
98  
99  }