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.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          // Nested
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          // At same point
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          // Make sure the file at the junction point and its ancestors do not exist
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          // Add the junction
92          fs.addJunction("/a/b", baseDir);
93  
94          // Make sure the file at the junction point and its ancestors exist
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     // Check that file @ junction point exists only when backing file exists
104     // Add 2 junctions with common parent
105     // Compare real and virtual files
106     // Events
107     // Remove junctions
108 
109 }