adammurdoch    2003/01/22 20:41:56

  Modified:    vfs/src/test/org/apache/commons/vfs/test
                        AbstractProviderTestCase.java FileInfo.java
                        ProviderReadTests.java ProviderTestSuite.java
                        ProviderWriteTests.java UrlTests.java
  Added:       vfs/src/test/org/apache/commons/vfs/test ContentTests.java
                        NamingTests.java UrlStructureTests.java
  Log:
  Split up ProviderReadTests and UrlTests into separate content and structure tests, 
which means that the URL provider tests now pass.
  
  Revision  Changes    Path
  1.7       +23 -1     
jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/test/AbstractProviderTestCase.java
  
  Index: AbstractProviderTestCase.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/test/AbstractProviderTestCase.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- AbstractProviderTestCase.java     21 Jan 2003 23:58:24 -0000      1.6
  +++ AbstractProviderTestCase.java     23 Jan 2003 04:41:55 -0000      1.7
  @@ -97,6 +97,9 @@
       // Expected contents of "file1.txt"
       public static final String FILE1_CONTENT = "This is a test file.";
   
  +    // Expected contents of test files
  +    public static final String TEST_FILE_CONTENT = "A test file.";
  +
       /** Sets the provider test config, if any. */
       public void setConfig( final Method method,
                              final ProviderTestConfig providerConfig )
  @@ -326,5 +329,24 @@
   
           // Compare
           assertTrue( "same binary content", Arrays.equals( expectedBin, 
outstr.toByteArray() ) );
  +    }
  +
  +    /**
  +     * Builds the expected structure of the read tests folder.
  +     */
  +    protected FileInfo buildExpectedStructure()
  +    {
  +        // Build the expected structure
  +        final FileInfo base = new FileInfo( 
getReadFolder().getName().getBaseName(), FileType.FOLDER );
  +        base.addFile( "file1.txt", FILE1_CONTENT );
  +        base.addFile( "empty.txt", "" );
  +        base.addFolder( "emptydir" );
  +
  +        final FileInfo dir = base.addFolder( "dir1" );
  +        dir.addFile( "file1.txt", TEST_FILE_CONTENT );
  +        dir.addFile( "file2.txt", TEST_FILE_CONTENT );
  +        dir.addFile( "file3.txt", TEST_FILE_CONTENT );
  +
  +        return base;
       }
   }
  
  
  
  1.6       +17 -10    
jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/test/FileInfo.java
  
  Index: FileInfo.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/test/FileInfo.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- FileInfo.java     25 Nov 2002 05:51:15 -0000      1.5
  +++ FileInfo.java     23 Jan 2003 04:41:55 -0000      1.6
  @@ -66,6 +66,7 @@
   {
       String baseName;
       FileType type;
  +    String content;
       Map children = new HashMap();
       FileInfo parent;
   
  @@ -73,6 +74,14 @@
       {
           baseName = name;
           this.type = type;
  +        this.content = null;
  +    }
  +
  +    public FileInfo( final String name, final FileType type, final String content )
  +    {
  +        baseName = name;
  +        this.type = type;
  +        this.content = content;
       }
   
       public FileInfo getParent()
  @@ -87,21 +96,19 @@
           child.parent = this;
       }
   
  -    /** Adds a child. */
  -    public FileInfo addChild( final String baseName, final FileType type )
  +    /** Adds a child file. */
  +    public FileInfo addFile( final String baseName, final String content )
       {
  -        final FileInfo child = new FileInfo( baseName, type );
  +        final FileInfo child = new FileInfo( baseName, FileType.FILE, content );
           addChild( child );
           return child;
       }
   
  -    /** Adds a bunch of children. */
  -    public void addChildren( final String[] baseNames, final FileType type )
  +    /** Adds a child folder. */
  +    public FileInfo addFolder( final String baseName )
       {
  -        for ( int i = 0; i < baseNames.length; i++ )
  -        {
  -            String baseName = baseNames[ i ];
  -            addChild( new FileInfo( baseName, type ) );
  -        }
  +        final FileInfo child = new FileInfo( baseName, FileType.FOLDER, null );
  +        addChild( child );
  +        return child;
       }
   }
  
  
  
  1.7       +19 -645   
jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/test/ProviderReadTests.java
  
  Index: ProviderReadTests.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/test/ProviderReadTests.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ProviderReadTests.java    21 Jan 2003 23:58:24 -0000      1.6
  +++ ProviderReadTests.java    23 Jan 2003 04:41:55 -0000      1.7
  @@ -55,450 +55,36 @@
    */
   package org.apache.commons.vfs.test;
   
  +import java.io.InputStream;
   import java.util.ArrayList;
   import java.util.List;
  -import java.io.InputStream;
  -import org.apache.commons.vfs.FileContent;
  -import org.apache.commons.vfs.FileName;
  +import org.apache.commons.vfs.Capability;
   import org.apache.commons.vfs.FileObject;
  -import org.apache.commons.vfs.FileSystem;
   import org.apache.commons.vfs.FileSystemException;
   import org.apache.commons.vfs.FileType;
  -import org.apache.commons.vfs.NameScope;
   
   /**
    * Read-only test cases for file providers.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Adam Murdoch</a>
    * @version $Revision$ $Date$
  + *
  + * @todo Test getLastModified(), getAttribute()
    */
   public class ProviderReadTests
       extends AbstractProviderTestCase
   {
       /**
  -     * Tests resolution of absolute URI.
  -     */
  -    public void testAbsoluteURI() throws Exception
  -    {
  -        // Try fetching base folder again by its URI
  -        final String uri = getReadFolder().getName().getURI();
  -        final FileObject file = getManager().resolveFile( uri );
  -
  -        assertSame( "file object", getReadFolder(), file );
  -    }
  -
  -    /**
  -     * Tests resolution of relative file names via the FS manager
  -     */
  -    public void testRelativeURI() throws Exception
  -    {
  -        // Build base dir
  -        getManager().setBaseFile( getReadFolder() );
  -
  -        // Locate the base dir
  -        FileObject file = getManager().resolveFile( "." );
  -        assertSame( "file object", getReadFolder(), file );
  -
  -        // Locate a child
  -        file = getManager().resolveFile( "some-child" );
  -        assertSame( "file object", getReadFolder(), file.getParent() );
  -
  -        // Locate a descendent
  -        file = getManager().resolveFile( "some-folder/some-file" );
  -        assertSame( "file object", getReadFolder(), file.getParent().getParent() );
  -
  -        // Locate parent
  -        file = getManager().resolveFile( ".." );
  -        assertSame( "file object", getReadFolder().getParent(), file );
  -    }
  -
  -    /**
  -     * Tests encoding of relative URI.
  -     */
  -    public void testRelativeUriEncoding() throws Exception
  -    {
  -        // Build base dir
  -        getManager().setBaseFile( getReadFolder() );
  -        final String path = getReadFolder().getName().getPath();
  -
  -        // Encode "some file"
  -        FileObject file = getManager().resolveFile( "%73%6f%6d%65%20%66%69%6c%65" );
  -        assertEquals( path + "/some file", file.getName().getPath() );
  -
  -        // Encode "."
  -        file = getManager().resolveFile( "%2e" );
  -        assertEquals( path, file.getName().getPath() );
  -
  -        // Encode '%'
  -        file = getManager().resolveFile( "a%25" );
  -        assertEquals( path + "/a%", file.getName().getPath() );
  -
  -        // Encode /
  -        file = getManager().resolveFile( "dir%2fchild" );
  -        assertEquals( path + "/dir/child", file.getName().getPath() );
  -
  -        // Encode \
  -        file = getManager().resolveFile( "dir%5cchild" );
  -        assertEquals( path + "/dir/child", file.getName().getPath() );
  -
  -        // Use "%" literal
  -        try
  -        {
  -            getManager().resolveFile( "%" );
  -            fail();
  -        }
  -        catch ( FileSystemException e )
  -        {
  -        }
  -
  -        // Not enough digits in encoded char
  -        try
  -        {
  -            getManager().resolveFile( "%5" );
  -            fail();
  -        }
  -        catch ( FileSystemException e )
  -        {
  -        }
  -
  -        // Invalid digit in encoded char
  -        try
  -        {
  -            getManager().resolveFile( "%q" );
  -            fail();
  -        }
  -        catch ( FileSystemException e )
  -        {
  -        }
  -    }
  -
  -    /**
  -     * Tests the root file name.
  -     */
  -    public void testRootFileName() throws Exception
  -    {
  -        // Locate the root file
  -        final FileName rootName = 
getReadFolder().getFileSystem().getRoot().getName();
  -
  -        // Test that the root path is "/"
  -        assertEquals( "root path", "/", rootName.getPath() );
  -
  -        // Test that the root basname is ""
  -        assertEquals( "root base name", "", rootName.getBaseName() );
  -
  -        // Test that the root name has no parent
  -        assertNull( "root parent", rootName.getParent() );
  -    }
  -
  -    /**
  -     * Tests child file names.
  -     */
  -    public void testChildName() throws Exception
  -    {
  -        final FileName baseName = getReadFolder().getName();
  -        final String basePath = baseName.getPath();
  -        final FileName name = baseName.resolveName( "some-child", NameScope.CHILD );
  -
  -        // Test path is absolute
  -        assertTrue( "is absolute", basePath.startsWith( "/" ) );
  -
  -        // Test base name
  -        assertEquals( "base name", "some-child", name.getBaseName() );
  -
  -        // Test absolute path
  -        assertEquals( "absolute path", basePath + "/some-child", name.getPath() );
  -
  -        // Test parent path
  -        assertEquals( "parent absolute path", basePath, name.getParent().getPath() 
);
  -
  -        // Try using a compound name to find a child
  -        assertBadName( name, "a/b", NameScope.CHILD );
  -
  -        // Check other invalid names
  -        checkDescendentNames( name, NameScope.CHILD );
  -    }
  -
  -    /**
  -     * Name resolution tests that are common for CHILD or DESCENDENT scope.
  -     */
  -    private void checkDescendentNames( final FileName name,
  -                                       final NameScope scope )
  -        throws Exception
  -    {
  -        // Make some assumptions about the name
  -        assertTrue( !name.getPath().equals( "/" ) );
  -        assertTrue( !name.getPath().endsWith( "/a" ) );
  -        assertTrue( !name.getPath().endsWith( "/a/b" ) );
  -
  -        // Test names with the same prefix
  -        String path = name.getPath() + "/a";
  -        assertSameName( path, name, path, scope );
  -        assertSameName( path, name, "../" + name.getBaseName() + "/a", scope );
  -
  -        // Test an empty name
  -        assertBadName( name, "", scope );
  -
  -        // Test . name
  -        assertBadName( name, ".", scope );
  -        assertBadName( name, "./", scope );
  -
  -        // Test ancestor names
  -        assertBadName( name, "..", scope );
  -        assertBadName( name, "../a", scope );
  -        assertBadName( name, "../" + name.getBaseName() + "a", scope );
  -        assertBadName( name, "a/..", scope );
  -
  -        // Test absolute names
  -        assertBadName( name, "/", scope );
  -        assertBadName( name, "/a", scope );
  -        assertBadName( name, "/a/b", scope );
  -        assertBadName( name, name.getPath(), scope );
  -        assertBadName( name, name.getPath() + "a", scope );
  -    }
  -
  -    /**
  -     * Checks that a relative name resolves to the expected absolute path.
  -     * Tests both forward and back slashes.
  +     * Returns the capabilities required by the tests of this test case.
        */
  -    private void assertSameName( final String expectedPath,
  -                                 final FileName baseName,
  -                                 final String relName,
  -                                 final NameScope scope )
  -        throws Exception
  -    {
  -        // Try the supplied name
  -        FileName name = baseName.resolveName( relName, scope );
  -        assertEquals( expectedPath, name.getPath() );
  -
  -        // Replace the separators
  -        relName.replace( '\\', '/' );
  -        name = baseName.resolveName( relName, scope );
  -        assertEquals( expectedPath, name.getPath() );
  -
  -        // And again
  -        relName.replace( '/', '\\' );
  -        name = baseName.resolveName( relName, scope );
  -        assertEquals( expectedPath, name.getPath() );
  -    }
  -
  -    /**
  -     * Checks that a relative name resolves to the expected absolute path.
  -     * Tests both forward and back slashes.
  -     */
  -    private void assertSameName( String expectedPath,
  -                                 FileName baseName,
  -                                 String relName ) throws Exception
  +    protected Capability[] getRequiredCaps()
       {
  -        assertSameName( expectedPath, baseName, relName, NameScope.FILE_SYSTEM );
  -    }
  -
  -    /**
  -     * Tests relative name resolution, relative to the base folder.
  -     */
  -    public void testNameResolution() throws Exception
  -    {
  -        final FileName baseName = getReadFolder().getName();
  -        final String parentPath = baseName.getParent().getPath();
  -        final String path = baseName.getPath();
  -        final String childPath = path + "/some-child";
  -
  -        // Test empty relative path
  -        assertSameName( path, baseName, "" );
  -
  -        // Test . relative path
  -        assertSameName( path, baseName, "." );
  -
  -        // Test ./ relative path
  -        assertSameName( path, baseName, "./" );
  -
  -        // Test .// relative path
  -        assertSameName( path, baseName, ".//" );
  -
  -        // Test .///.///. relative path
  -        assertSameName( path, baseName, ".///.///." );
  -        assertSameName( path, baseName, "./\\/.\\//." );
  -
  -        // Test <elem>/.. relative path
  -        assertSameName( path, baseName, "a/.." );
  -
  -        // Test .. relative path
  -        assertSameName( parentPath, baseName, ".." );
  -
  -        // Test ../ relative path
  -        assertSameName( parentPath, baseName, "../" );
  -
  -        // Test ..//./ relative path
  -        assertSameName( parentPath, baseName, "..//./" );
  -        assertSameName( parentPath, baseName, "..//.\\" );
  -
  -        // Test <elem>/../.. relative path
  -        assertSameName( parentPath, baseName, "a/../.." );
  -
  -        // Test <elem> relative path
  -        assertSameName( childPath, baseName, "some-child" );
  -
  -        // Test ./<elem> relative path
  -        assertSameName( childPath, baseName, "./some-child" );
  -
  -        // Test ./<elem>/ relative path
  -        assertSameName( childPath, baseName, "./some-child/" );
  -
  -        // Test <elem>/././././ relative path
  -        assertSameName( childPath, baseName, "./some-child/././././" );
  -
  -        // Test <elem>/../<elem> relative path
  -        assertSameName( childPath, baseName, "a/../some-child" );
  -
  -        // Test <elem>/<elem>/../../<elem> relative path
  -        assertSameName( childPath, baseName, "a/b/../../some-child" );
  -    }
  -
  -    /**
  -     * Tests descendent name resolution.
  -     */
  -    public void testDescendentName()
  -        throws Exception
  -    {
  -        final FileName baseName = getReadFolder().getName();
  -
  -        // Test direct child
  -        String path = baseName.getPath() + "/some-child";
  -        assertSameName( path, baseName, "some-child", NameScope.DESCENDENT );
  -
  -        // Test compound name
  -        path = path + "/grand-child";
  -        assertSameName( path, baseName, "some-child/grand-child", 
NameScope.DESCENDENT );
  -
  -        // Test relative names
  -        assertSameName( path, baseName, "./some-child/grand-child", 
NameScope.DESCENDENT );
  -        assertSameName( path, baseName, "./nada/../some-child/grand-child", 
NameScope.DESCENDENT );
  -        assertSameName( path, baseName, "some-child/./grand-child", 
NameScope.DESCENDENT );
  -
  -        // Test badly formed descendent names
  -        checkDescendentNames( baseName, NameScope.DESCENDENT );
  -    }
  -
  -    /**
  -     * Tests resolution of absolute names.
  -     */
  -    public void testAbsoluteNames() throws Exception
  -    {
  -        // Test against the base folder
  -        FileName name = getReadFolder().getName();
  -        checkAbsoluteNames( name );
  -
  -        // Test against the root
  -        name = getReadFolder().getFileSystem().getRoot().getName();
  -        checkAbsoluteNames( name );
  -
  -        // Test against some unknown file
  -        name = name.resolveName( "a/b/unknown" );
  -        checkAbsoluteNames( name );
  -    }
  -
  -    /**
  -     * Tests resolution of absolute names.
  -     */
  -    private void checkAbsoluteNames( final FileName name ) throws Exception
  -    {
  -        // Root
  -        assertSameName( "/", name, "/" );
  -        assertSameName( "/", name, "//" );
  -        assertSameName( "/", name, "/." );
  -        assertSameName( "/", name, "/some file/.." );
  -
  -        // Some absolute names
  -        assertSameName( "/a", name, "/a" );
  -        assertSameName( "/a", name, "/./a" );
  -        assertSameName( "/a", name, "/a/." );
  -        assertSameName( "/a/b", name, "/a/b" );
  -
  -        // Some bad names
  -        assertBadName( name, "/..", NameScope.FILE_SYSTEM );
  -        assertBadName( name, "/a/../..", NameScope.FILE_SYSTEM );
  -    }
  -
  -    /**
  -     * Asserts that a particular relative name is invalid for a particular
  -     * scope.
  -     */
  -    private void assertBadName( final FileName name,
  -                                final String relName,
  -                                final NameScope scope )
  -    {
  -        try
  -        {
  -            name.resolveName( relName, scope );
  -            fail( "expected failure" );
  -        }
  -        catch ( FileSystemException e )
  +        return new Capability[]
           {
  -            // TODO - should check error message
  -        }
  -    }
  -
  -    /**
  -     * Tests conversion from absolute to relative names.
  -     */
  -    public void testAbsoluteNameConvert() throws Exception
  -    {
  -        final FileName baseName = getReadFolder().getName();
  -
  -        String path = "/test1/test2";
  -        FileName name = baseName.resolveName( path );
  -        assertEquals( path, name.getPath() );
  -
  -        // Try child and descendent names
  -        testRelName( name, "child" );
  -        testRelName( name, "child1/child2" );
  -
  -        // Try own name
  -        testRelName( name, "." );
  -
  -        // Try parent, and root
  -        testRelName( name, ".." );
  -        testRelName( name, "../.." );
  -
  -        // Try sibling and descendent of sibling
  -        testRelName( name, "../sibling" );
  -        testRelName( name, "../sibling/child" );
  -
  -        // Try siblings with similar names
  -        testRelName( name, "../test2_not" );
  -        testRelName( name, "../test2_not/child" );
  -        testRelName( name, "../test" );
  -        testRelName( name, "../test/child" );
  -
  -        // Try unrelated
  -        testRelName( name, "../../unrelated" );
  -        testRelName( name, "../../test" );
  -        testRelName( name, "../../test/child" );
  -
  -        // Test against root
  -        path = "/";
  -        name = baseName.resolveName( path );
  -        assertEquals( path, name.getPath() );
  -
  -        // Try child and descendent names (against root)
  -        testRelName( name, "child" );
  -        testRelName( name, "child1/child2" );
  -
  -        // Try own name (against root)
  -        testRelName( name, "." );
  -    }
  -
  -    /**
  -     * Checks that a file name converts to an expected relative path
  -     */
  -    private void testRelName( final FileName baseName,
  -                              final String relPath )
  -        throws Exception
  -    {
  -        final FileName expectedName = baseName.resolveName( relPath );
  -
  -        // Convert to relative path, and check
  -        final String actualRelPath = baseName.getRelativeName( expectedName );
  -        assertEquals( relPath, actualRelPath );
  +            Capability.GET_TYPE,
  +            Capability.LIST_CHILDREN,
  +            Capability.READ_CONTENT
  +        };
       }
   
       /**
  @@ -512,25 +98,6 @@
       }
   
       /**
  -     * Builds the expected folder structure.
  -     */
  -    private FileInfo buildExpectedStructure()
  -    {
  -        // Build the expected structure
  -        final FileInfo base = new FileInfo( 
getReadFolder().getName().getBaseName(), FileType.FOLDER );
  -        base.addChild( "file1.txt", FileType.FILE );
  -        base.addChild( "empty.txt", FileType.FILE );
  -        base.addChild( "emptydir", FileType.FOLDER );
  -
  -        final FileInfo dir = base.addChild( "dir1", FileType.FOLDER );
  -        dir.addChild( "file1.txt", FileType.FILE );
  -        dir.addChild( "file2.txt", FileType.FILE );
  -        dir.addChild( "file3.txt", FileType.FILE );
  -
  -        return base;
  -    }
  -
  -    /**
        * Walks a folder structure, asserting it contains exactly the
        * expected files and folders.
        */
  @@ -582,28 +149,6 @@
       }
   
       /**
  -     * Tests existence determination.
  -     */
  -    public void testExists() throws Exception
  -    {
  -        // Test a file
  -        FileObject file = getReadFolder().resolveFile( "file1.txt" );
  -        assertTrue( "file exists", file.exists() );
  -
  -        // Test a folder
  -        file = getReadFolder().resolveFile( "dir1" );
  -        assertTrue( "folder exists", file.exists() );
  -
  -        // Test an unknown file
  -        file = getReadFolder().resolveFile( "unknown-child" );
  -        assertTrue( "unknown file does not exist", !file.exists() );
  -
  -        // Test an unknown file in an unknown folder
  -        file = getReadFolder().resolveFile( "unknown-folder/unknown-child" );
  -        assertTrue( "unknown file does not exist", !file.exists() );
  -    }
  -
  -    /**
        * Tests type determination.
        */
       public void testType() throws Exception
  @@ -630,104 +175,9 @@
       }
   
       /**
  -     * Tests parent identity
  -     */
  -    public void testParent() throws FileSystemException
  -    {
  -        // Test when both exist
  -        FileObject folder = getReadFolder().resolveFile( "dir1" );
  -        FileObject child = folder.resolveFile( "file3.txt" );
  -        assertTrue( "folder exists", folder.exists() );
  -        assertTrue( "child exists", child.exists() );
  -        assertSame( folder, child.getParent() );
  -
  -        // Test when file does not exist
  -        child = folder.resolveFile( "unknown-file" );
  -        assertTrue( "folder exists", folder.exists() );
  -        assertTrue( "child does not exist", !child.exists() );
  -        assertSame( folder, child.getParent() );
  -
  -        // Test when neither exists
  -        folder = getReadFolder().resolveFile( "unknown-folder" );
  -        child = folder.resolveFile( "unknown-file" );
  -        assertTrue( "folder does not exist", !folder.exists() );
  -        assertTrue( "child does not exist", !child.exists() );
  -        assertSame( folder, child.getParent() );
  -
  -        // Test the parent of the root of the file system
  -        // TODO - refactor out test cases for layered vs originating fs
  -        final FileSystem fileSystem = getReadFolder().getFileSystem();
  -        FileObject root = fileSystem.getRoot();
  -        if ( fileSystem.getParentLayer() == null )
  -        {
  -            // No parent layer, so parent should be null
  -            assertNull( "root has null parent", root.getParent() );
  -        }
  -        else
  -        {
  -            // Parent should be parent of parent layer.
  -            assertSame( fileSystem.getParentLayer().getParent(), root.getParent() );
  -        }
  -    }
  -
  -    /**
  -     * Tests that children cannot be listed for non-folders.
  -     */
  -    public void testChildren() throws FileSystemException
  -    {
  -        // Check for file
  -        FileObject file = getReadFolder().resolveFile( "file1.txt" );
  -        assertSame( FileType.FILE, file.getType() );
  -        try
  -        {
  -            file.getChildren();
  -            fail();
  -        }
  -        catch ( FileSystemException e )
  -        {
  -            assertSameMessage( "vfs.provider/list-children-not-folder.error", file, 
e );
  -        }
  -
  -        // Should be able to get child by name
  -        file = file.resolveFile( "some-child" );
  -        assertNotNull( file );
  -
  -        // Check for unknown file
  -        file = getReadFolder().resolveFile( "unknown-file" );
  -        assertTrue( !file.exists() );
  -        try
  -        {
  -            file.getChildren();
  -            fail();
  -        }
  -        catch ( FileSystemException e )
  -        {
  -            assertSameMessage( "vfs.provider/list-children-no-exist.error", file, e 
);
  -        }
  -
  -        // Should be able to get child by name
  -        FileObject child = file.resolveFile( "some-child" );
  -        assertNotNull( child );
  -    }
  -
  -    /**
  -     * Tests content.
  +     * Tests that folders have no content.
        */
  -    public void testContent() throws Exception
  -    {
  -        // Test non-empty file
  -        FileObject file = getReadFolder().resolveFile( "file1.txt" );
  -        assertSameContent( FILE1_CONTENT, file );
  -
  -        // Test empty file
  -        file = getReadFolder().resolveFile( "empty.txt" );
  -        assertSameContent( "", file );
  -    }
  -
  -    /**
  -     * Tests that folders and unknown files have no content.
  -     */
  -    public void testNoContent() throws Exception
  +    public void testFolderContent() throws Exception
       {
           // Try getting the content of a folder
           FileObject folder = getReadFolder().resolveFile( "dir1" );
  @@ -740,67 +190,15 @@
           {
               assertSameMessage( "vfs.provider/read-folder.error", folder, e );
           }
  -
  -        // Try getting the content of an unknown file
  -        FileObject unknownFile = getReadFolder().resolveFile( "unknown-file" );
  -        FileContent content = unknownFile.getContent();
  -        try
  -        {
  -            content.getInputStream();
  -            fail();
  -        }
  -        catch ( FileSystemException e )
  -        {
  -            assertSameMessage( "vfs.provider/read-no-exist.error", unknownFile, e );
  -        }
  -        try
  -        {
  -            content.getSize();
  -            fail();
  -        }
  -        catch ( FileSystemException e )
  -        {
  -            assertSameMessage( "vfs.provider/get-size-no-exist.error", unknownFile, 
e );
  -        }
       }
   
       /**
  -     * Tests concurrent reads on a file fail.
  -     *
  -     * @todo Change model so that concurrent reads are allowed (maybe optional)
  +     * Tests can perform operations on a folder while reading from a different 
files.
        */
  -    public void testConcurrentRead() throws Exception
  +    public void testConcurrentReadFolder() throws Exception
       {
           final FileObject file = getReadFolder().resolveFile( "file1.txt" );
           assertTrue( file.exists() );
  -
  -        // Start reading from the file
  -        final InputStream instr = file.getContent().getInputStream();
  -        try
  -        {
  -            // Start reading again
  -            file.getContent().getInputStream();
  -            fail();
  -        }
  -        catch ( final Exception e )
  -        {
  -            assertSameMessage( "vfs.provider/read-in-use.error", file, e );
  -        }
  -        finally
  -        {
  -            instr.close();
  -        }
  -    }
  -
  -    /**
  -     * Tests concurrent reads on different files works.
  -     */
  -    public void testConcurrentReadFiles() throws Exception
  -    {
  -        final FileObject file = getReadFolder().resolveFile( "file1.txt" );
  -        assertTrue( file.exists() );
  -        final FileObject emptyFile = getReadFolder().resolveFile( "empty.txt" );
  -        assertTrue( emptyFile.exists() );
           final FileObject folder = getReadFolder().resolveFile( "dir1" );
           assertTrue( folder.exists() );
   
  @@ -808,39 +206,15 @@
           final InputStream instr = file.getContent().getInputStream();
           try
           {
  -            // Try to read from other file
  -            assertSameContent( "", emptyFile );
  -
  -            // Try to list children of other folder
  +            // Do some operations
  +            folder.exists();
  +            folder.getType();
               folder.getChildren();
           }
           finally
           {
               instr.close();
           }
  -    }
  -
  -    /**
  -     * Tests that content and file objects are usable after being closed.
  -     */
  -    public void testReuse() throws Exception
  -    {
  -        // Get the test file
  -        FileObject file = getReadFolder().resolveFile( "file1.txt" );
  -        assertEquals( FileType.FILE, file.getType() );
  -
  -        // Get the file content
  -        assertSameContent( FILE1_CONTENT, file );
  -
  -        // Read the content again
  -        assertSameContent( FILE1_CONTENT, file );
  -
  -        // Close the content + file
  -        file.getContent().close();
  -        file.close();
  -
  -        // Read the content again
  -        assertSameContent( FILE1_CONTENT, file );
       }
   
       /**
  
  
  
  1.6       +5 -1      
jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/test/ProviderTestSuite.java
  
  Index: ProviderTestSuite.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/test/ProviderTestSuite.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ProviderTestSuite.java    25 Nov 2002 05:46:03 -0000      1.5
  +++ ProviderTestSuite.java    23 Jan 2003 04:41:56 -0000      1.6
  @@ -91,6 +91,7 @@
           if ( !nested )
           {
               // Add nested tests
  +            // TODO - move nested jar and zip tests here
               // TODO - enable this again
               //addTest( new ProviderTestSuite( new JunctionProviderConfig( 
providerConfig ), "junction.", true ));
           }
  @@ -101,9 +102,12 @@
        */
       private void addBaseTests() throws Exception
       {
  +        addTests( NamingTests.class );
  +        addTests( ContentTests.class );
           addTests( ProviderReadTests.class );
           addTests( ProviderWriteTests.class );
           addTests( UrlTests.class );
  +        addTests( UrlStructureTests.class );
           addTests( VfsClassLoaderTests.class );
       }
   
  
  
  
  1.7       +1 -0      
jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/test/ProviderWriteTests.java
  
  Index: ProviderWriteTests.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/test/ProviderWriteTests.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ProviderWriteTests.java   21 Jan 2003 23:58:24 -0000      1.6
  +++ ProviderWriteTests.java   23 Jan 2003 04:41:56 -0000      1.7
  @@ -86,6 +86,7 @@
           {
               Capability.CREATE,
               Capability.DELETE,
  +            Capability.GET_TYPE,
               Capability.LIST_CHILDREN,
               Capability.READ_CONTENT,
               Capability.WRITE_CONTENT
  
  
  
  1.4       +11 -16    
jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/test/UrlTests.java
  
  Index: UrlTests.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/test/UrlTests.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- UrlTests.java     23 Nov 2002 00:41:10 -0000      1.3
  +++ UrlTests.java     23 Jan 2003 04:41:56 -0000      1.4
  @@ -107,44 +107,39 @@
       {
           // Test non-empty file
           FileObject file = getReadFolder().resolveFile( "file1.txt" );
  +        assertTrue( file.exists() );
  +
           URLConnection urlCon = file.getURL().openConnection();
           assertSameURLContent( FILE1_CONTENT, urlCon );
   
           // Test empty file
           file = getReadFolder().resolveFile( "empty.txt" );
  +        assertTrue( file.exists() );
  +
           urlCon = file.getURL().openConnection();
           assertSameURLContent( "", urlCon );
       }
   
       /**
  -     * Tests that folders and unknown files have no content.
  +     * Tests that unknown files have no content.
        */
  -    public void testNoURLContent() throws Exception
  +    public void testUnknownURL() throws Exception
       {
  -        // Try getting the content of a folder
  -        final FileObject folder = getReadFolder().resolveFile( "dir1" );
  -        try
  -        {
  -            folder.getURL().openConnection().getInputStream();
  -            fail();
  -        }
  -        catch ( IOException e )
  -        {
  -            assertSameMessage( "vfs.provider/read-folder.error", folder, e );
  -        }
  -
           // Try getting the content of an unknown file
           final FileObject unknownFile = getReadFolder().resolveFile( "unknown-file" 
);
  +        assertFalse( unknownFile.exists() );
  +
           final URLConnection connection = unknownFile.getURL().openConnection();
           try
           {
               connection.getInputStream();
               fail();
           }
  -        catch ( IOException e )
  +        catch ( final IOException e )
           {
               assertSameMessage( "vfs.provider/read-no-exist.error", unknownFile, e );
           }
           assertEquals( -1, connection.getContentLength() );
       }
  +
   }
  
  
  
  1.1                  
jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/test/ContentTests.java
  
  Index: ContentTests.java
  ===================================================================
  /* ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  package org.apache.commons.vfs.test;
  
  import org.apache.commons.vfs.FileObject;
  import org.apache.commons.vfs.NameScope;
  import org.apache.commons.vfs.FileType;
  import org.apache.commons.vfs.FileSystemException;
  import org.apache.commons.vfs.FileSystem;
  import org.apache.commons.vfs.FileContent;
  import java.util.Iterator;
  import java.io.InputStream;
  
  /**
   * Test cases for reading file content.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]";>Adam Murdoch</a>
   * @version $Revision: 1.1 $ $Date: 2003/01/23 04:41:55 $
   */
  public class ContentTests
      extends AbstractProviderTestCase
  {
      /**
       * Asserts that every expected file exists, and has the expected content.
       */
      public void testAllContent() throws Exception
      {
          final FileInfo baseInfo = buildExpectedStructure();
          final FileObject baseFolder = getReadFolder();
  
          assertSameContent( baseInfo, baseFolder );
      }
  
      /**
       * Asserts every file in a folder exists and has the expected content.
       */
      private void assertSameContent( final FileInfo expected,
                                      final FileObject folder ) throws Exception
      {
          for ( Iterator iterator = expected.children.values().iterator(); 
iterator.hasNext(); )
          {
              final FileInfo fileInfo = (FileInfo)iterator.next();
              final FileObject child = folder.resolveFile( fileInfo.baseName, 
NameScope.CHILD );
  
              assertTrue( child.exists() );
              if ( fileInfo.type == FileType.FILE )
              {
                  assertSameContent( fileInfo.content, child );
              }
              else
              {
                  assertSameContent( fileInfo, child );
              }
          }
      }
  
      /**
       * Tests existence determination.
       */
      public void testExists() throws Exception
      {
          // Test a file
          FileObject file = getReadFolder().resolveFile( "file1.txt" );
          assertTrue( "file exists", file.exists() );
  
          // Test a folder
          file = getReadFolder().resolveFile( "dir1" );
          assertTrue( "folder exists", file.exists() );
  
          // Test an unknown file
          file = getReadFolder().resolveFile( "unknown-child" );
          assertTrue( "unknown file does not exist", !file.exists() );
  
          // Test an unknown file in an unknown folder
          file = getReadFolder().resolveFile( "unknown-folder/unknown-child" );
          assertTrue( "unknown file does not exist", !file.exists() );
      }
  
      /**
       * Tests parent identity
       */
      public void testParent() throws FileSystemException
      {
          // Test when both exist
          FileObject folder = getReadFolder().resolveFile( "dir1" );
          FileObject child = folder.resolveFile( "file3.txt" );
          assertTrue( "folder exists", folder.exists() );
          assertTrue( "child exists", child.exists() );
          assertSame( folder, child.getParent() );
  
          // Test when file does not exist
          child = folder.resolveFile( "unknown-file" );
          assertTrue( "folder exists", folder.exists() );
          assertTrue( "child does not exist", !child.exists() );
          assertSame( folder, child.getParent() );
  
          // Test when neither exists
          folder = getReadFolder().resolveFile( "unknown-folder" );
          child = folder.resolveFile( "unknown-file" );
          assertTrue( "folder does not exist", !folder.exists() );
          assertTrue( "child does not exist", !child.exists() );
          assertSame( folder, child.getParent() );
  
          // Test the parent of the root of the file system
          // TODO - refactor out test cases for layered vs originating fs
          final FileSystem fileSystem = getReadFolder().getFileSystem();
          FileObject root = fileSystem.getRoot();
          if ( fileSystem.getParentLayer() == null )
          {
              // No parent layer, so parent should be null
              assertNull( "root has null parent", root.getParent() );
          }
          else
          {
              // Parent should be parent of parent layer.
              assertSame( fileSystem.getParentLayer().getParent(), root.getParent() );
          }
      }
  
      /**
       * Tests that children cannot be listed for non-folders.
       */
      public void testChildren() throws FileSystemException
      {
          // Check for file
          FileObject file = getReadFolder().resolveFile( "file1.txt" );
          assertSame( FileType.FILE, file.getType() );
          try
          {
              file.getChildren();
              fail();
          }
          catch ( FileSystemException e )
          {
              assertSameMessage( "vfs.provider/list-children-not-folder.error", file, 
e );
          }
  
          // Should be able to get child by name
          file = file.resolveFile( "some-child" );
          assertNotNull( file );
  
          // Check for unknown file
          file = getReadFolder().resolveFile( "unknown-file" );
          assertTrue( !file.exists() );
          try
          {
              file.getChildren();
              fail();
          }
          catch ( FileSystemException e )
          {
              assertSameMessage( "vfs.provider/list-children-no-exist.error", file, e 
);
          }
  
          // Should be able to get child by name
          FileObject child = file.resolveFile( "some-child" );
          assertNotNull( child );
      }
  
      /**
       * Tests content.
       */
      public void testContent() throws Exception
      {
          // Test non-empty file
          FileObject file = getReadFolder().resolveFile( "file1.txt" );
          assertSameContent( FILE1_CONTENT, file );
  
          // Test empty file
          file = getReadFolder().resolveFile( "empty.txt" );
          assertSameContent( "", file );
      }
  
      /**
       * Tests that unknown files have no content.
       */
      public void testUnknownContent() throws Exception
      {
  
          // Try getting the content of an unknown file
          FileObject unknownFile = getReadFolder().resolveFile( "unknown-file" );
          FileContent content = unknownFile.getContent();
          try
          {
              content.getInputStream();
              fail();
          }
          catch ( FileSystemException e )
          {
              assertSameMessage( "vfs.provider/read-no-exist.error", unknownFile, e );
          }
          try
          {
              content.getSize();
              fail();
          }
          catch ( FileSystemException e )
          {
              assertSameMessage( "vfs.provider/get-size-no-exist.error", unknownFile, 
e );
          }
      }
  
      /**
       * Tests concurrent reads on a file fail.
       *
       * @todo Change model so that concurrent reads are allowed (maybe optional)
       */
      public void testConcurrentRead() throws Exception
      {
          final FileObject file = getReadFolder().resolveFile( "file1.txt" );
          assertTrue( file.exists() );
  
          // Start reading from the file
          final InputStream instr = file.getContent().getInputStream();
          try
          {
              // Start reading again
              file.getContent().getInputStream();
              fail();
          }
          catch ( final Exception e )
          {
              assertSameMessage( "vfs.provider/read-in-use.error", file, e );
          }
          finally
          {
              instr.close();
          }
      }
  
      /**
       * Tests concurrent reads on different files works.
       */
      public void testConcurrentReadFiles() throws Exception
      {
          final FileObject file = getReadFolder().resolveFile( "file1.txt" );
          assertTrue( file.exists() );
          final FileObject emptyFile = getReadFolder().resolveFile( "empty.txt" );
          assertTrue( emptyFile.exists() );
  
          // Start reading from the file
          final InputStream instr = file.getContent().getInputStream();
          try
          {
              // Try to read from other file
              assertSameContent( "", emptyFile );
          }
          finally
          {
              instr.close();
          }
      }
  
      /**
       * Tests that content and file objects are usable after being closed.
       */
      public void testReuse() throws Exception
      {
          // Get the test file
          FileObject file = getReadFolder().resolveFile( "file1.txt" );
          assertEquals( FileType.FILE, file.getType() );
  
          // Get the file content
          assertSameContent( FILE1_CONTENT, file );
  
          // Read the content again
          assertSameContent( FILE1_CONTENT, file );
  
          // Close the content + file
          file.getContent().close();
          file.close();
  
          // Read the content again
          assertSameContent( FILE1_CONTENT, file );
      }
      
  }
  
  
  
  1.1                  
jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/test/NamingTests.java
  
  Index: NamingTests.java
  ===================================================================
  /* ====================================================================
  *
  * The Apache Software License, Version 1.1
  *
  * Copyright (c) 2002 The Apache Software Foundation.  All rights
  * reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
  *
  * 1. Redistributions of source code must retain the above copyright
  *    notice, this list of conditions and the following disclaimer.
  *
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in
  *    the documentation and/or other materials provided with the
  *    distribution.
  *
  * 3. The end-user documentation included with the redistribution, if
  *    any, must include the following acknowlegement:
  *       "This product includes software developed by the
  *        Apache Software Foundation (http://www.apache.org/)."
  *    Alternately, this acknowlegement may appear in the software itself,
  *    if and wherever such third-party acknowlegements normally appear.
  *
  * 4. The names "The Jakarta Project", "Commons", and "Apache Software
  *    Foundation" must not be used to endorse or promote products derived
  *    from this software without prior written permission. For written
  *    permission, please contact [EMAIL PROTECTED]
  *
  * 5. Products derived from this software may not be called "Apache"
  *    nor may "Apache" appear in their names without prior written
  *    permission of the Apache Group.
  *
  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  * ====================================================================
  *
  * This software consists of voluntary contributions made by many
  * individuals on behalf of the Apache Software Foundation.  For more
  * information on the Apache Software Foundation, please see
  * <http://www.apache.org/>.
  *
  */
  package org.apache.commons.vfs.test;
  
  import org.apache.commons.vfs.FileObject;
  import org.apache.commons.vfs.FileSystemException;
  import org.apache.commons.vfs.FileName;
  import org.apache.commons.vfs.NameScope;
  
  /**
   * Test cases for file naming.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]";>Adam Murdoch</a>
   * @version $Revision: 1.1 $ $Date: 2003/01/23 04:41:55 $
   *
   * @todo Add tests for all FileName methods 
   */
  public class NamingTests
      extends AbstractProviderTestCase
  {
      /**
       * Tests resolution of absolute URI.
       */
      public void testAbsoluteURI() throws Exception
      {
          // Try fetching base folder again by its URI
          final String uri = getReadFolder().getName().getURI();
          final FileObject file = getManager().resolveFile( uri );
  
          assertSame( "file object", getReadFolder(), file );
      }
  
      /**
       * Tests resolution of relative file names via the FS manager
       */
      public void testRelativeURI() throws Exception
      {
          // Build base dir
          getManager().setBaseFile( getReadFolder() );
  
          // Locate the base dir
          FileObject file = getManager().resolveFile( "." );
          assertSame( "file object", getReadFolder(), file );
  
          // Locate a child
          file = getManager().resolveFile( "some-child" );
          assertSame( "file object", getReadFolder(), file.getParent() );
  
          // Locate a descendent
          file = getManager().resolveFile( "some-folder/some-file" );
          assertSame( "file object", getReadFolder(), file.getParent().getParent() );
  
          // Locate parent
          file = getManager().resolveFile( ".." );
          assertSame( "file object", getReadFolder().getParent(), file );
      }
  
      /**
       * Tests encoding of relative URI.
       */
      public void testRelativeUriEncoding() throws Exception
      {
          // Build base dir
          getManager().setBaseFile( getReadFolder() );
          final String path = getReadFolder().getName().getPath();
  
          // Encode "some file"
          FileObject file = getManager().resolveFile( "%73%6f%6d%65%20%66%69%6c%65" );
          assertEquals( path + "/some file", file.getName().getPath() );
  
          // Encode "."
          file = getManager().resolveFile( "%2e" );
          assertEquals( path, file.getName().getPath() );
  
          // Encode '%'
          file = getManager().resolveFile( "a%25" );
          assertEquals( path + "/a%", file.getName().getPath() );
  
          // Encode /
          file = getManager().resolveFile( "dir%2fchild" );
          assertEquals( path + "/dir/child", file.getName().getPath() );
  
          // Encode \
          file = getManager().resolveFile( "dir%5cchild" );
          assertEquals( path + "/dir/child", file.getName().getPath() );
  
          // Use "%" literal
          try
          {
              getManager().resolveFile( "%" );
              fail();
          }
          catch ( FileSystemException e )
          {
          }
  
          // Not enough digits in encoded char
          try
          {
              getManager().resolveFile( "%5" );
              fail();
          }
          catch ( FileSystemException e )
          {
          }
  
          // Invalid digit in encoded char
          try
          {
              getManager().resolveFile( "%q" );
              fail();
          }
          catch ( FileSystemException e )
          {
          }
      }
  
      /**
       * Tests the root file name.
       */
      public void testRootFileName() throws Exception
      {
          // Locate the root file
          final FileName rootName = 
getReadFolder().getFileSystem().getRoot().getName();
  
          // Test that the root path is "/"
          assertEquals( "root path", "/", rootName.getPath() );
  
          // Test that the root basname is ""
          assertEquals( "root base name", "", rootName.getBaseName() );
  
          // Test that the root name has no parent
          assertNull( "root parent", rootName.getParent() );
      }
  
      /**
       * Tests child file names.
       */
      public void testChildName() throws Exception
      {
          final FileName baseName = getReadFolder().getName();
          final String basePath = baseName.getPath();
          final FileName name = baseName.resolveName( "some-child", NameScope.CHILD );
  
          // Test path is absolute
          assertTrue( "is absolute", basePath.startsWith( "/" ) );
  
          // Test base name
          assertEquals( "base name", "some-child", name.getBaseName() );
  
          // Test absolute path
          assertEquals( "absolute path", basePath + "/some-child", name.getPath() );
  
          // Test parent path
          assertEquals( "parent absolute path", basePath, name.getParent().getPath() );
  
          // Try using a compound name to find a child
          assertBadName( name, "a/b", NameScope.CHILD );
  
          // Check other invalid names
          checkDescendentNames( name, NameScope.CHILD );
      }
  
      /**
       * Name resolution tests that are common for CHILD or DESCENDENT scope.
       */
      private void checkDescendentNames( final FileName name,
                                         final NameScope scope )
          throws Exception
      {
          // Make some assumptions about the name
          assertTrue( !name.getPath().equals( "/" ) );
          assertTrue( !name.getPath().endsWith( "/a" ) );
          assertTrue( !name.getPath().endsWith( "/a/b" ) );
  
          // Test names with the same prefix
          String path = name.getPath() + "/a";
          assertSameName( path, name, path, scope );
          assertSameName( path, name, "../" + name.getBaseName() + "/a", scope );
  
          // Test an empty name
          assertBadName( name, "", scope );
  
          // Test . name
          assertBadName( name, ".", scope );
          assertBadName( name, "./", scope );
  
          // Test ancestor names
          assertBadName( name, "..", scope );
          assertBadName( name, "../a", scope );
          assertBadName( name, "../" + name.getBaseName() + "a", scope );
          assertBadName( name, "a/..", scope );
  
          // Test absolute names
          assertBadName( name, "/", scope );
          assertBadName( name, "/a", scope );
          assertBadName( name, "/a/b", scope );
          assertBadName( name, name.getPath(), scope );
          assertBadName( name, name.getPath() + "a", scope );
      }
  
      /**
       * Checks that a relative name resolves to the expected absolute path.
       * Tests both forward and back slashes.
       */
      private void assertSameName( final String expectedPath,
                                   final FileName baseName,
                                   final String relName,
                                   final NameScope scope )
          throws Exception
      {
          // Try the supplied name
          FileName name = baseName.resolveName( relName, scope );
          assertEquals( expectedPath, name.getPath() );
  
          // Replace the separators
          relName.replace( '\\', '/' );
          name = baseName.resolveName( relName, scope );
          assertEquals( expectedPath, name.getPath() );
  
          // And again
          relName.replace( '/', '\\' );
          name = baseName.resolveName( relName, scope );
          assertEquals( expectedPath, name.getPath() );
      }
  
      /**
       * Checks that a relative name resolves to the expected absolute path.
       * Tests both forward and back slashes.
       */
      private void assertSameName( String expectedPath,
                                   FileName baseName,
                                   String relName ) throws Exception
      {
          assertSameName( expectedPath, baseName, relName, NameScope.FILE_SYSTEM );
      }
  
      /**
       * Tests relative name resolution, relative to the base folder.
       */
      public void testNameResolution() throws Exception
      {
          final FileName baseName = getReadFolder().getName();
          final String parentPath = baseName.getParent().getPath();
          final String path = baseName.getPath();
          final String childPath = path + "/some-child";
  
          // Test empty relative path
          assertSameName( path, baseName, "" );
  
          // Test . relative path
          assertSameName( path, baseName, "." );
  
          // Test ./ relative path
          assertSameName( path, baseName, "./" );
  
          // Test .// relative path
          assertSameName( path, baseName, ".//" );
  
          // Test .///.///. relative path
          assertSameName( path, baseName, ".///.///." );
          assertSameName( path, baseName, "./\\/.\\//." );
  
          // Test <elem>/.. relative path
          assertSameName( path, baseName, "a/.." );
  
          // Test .. relative path
          assertSameName( parentPath, baseName, ".." );
  
          // Test ../ relative path
          assertSameName( parentPath, baseName, "../" );
  
          // Test ..//./ relative path
          assertSameName( parentPath, baseName, "..//./" );
          assertSameName( parentPath, baseName, "..//.\\" );
  
          // Test <elem>/../.. relative path
          assertSameName( parentPath, baseName, "a/../.." );
  
          // Test <elem> relative path
          assertSameName( childPath, baseName, "some-child" );
  
          // Test ./<elem> relative path
          assertSameName( childPath, baseName, "./some-child" );
  
          // Test ./<elem>/ relative path
          assertSameName( childPath, baseName, "./some-child/" );
  
          // Test <elem>/././././ relative path
          assertSameName( childPath, baseName, "./some-child/././././" );
  
          // Test <elem>/../<elem> relative path
          assertSameName( childPath, baseName, "a/../some-child" );
  
          // Test <elem>/<elem>/../../<elem> relative path
          assertSameName( childPath, baseName, "a/b/../../some-child" );
      }
  
      /**
       * Tests descendent name resolution.
       */
      public void testDescendentName()
          throws Exception
      {
          final FileName baseName = getReadFolder().getName();
  
          // Test direct child
          String path = baseName.getPath() + "/some-child";
          assertSameName( path, baseName, "some-child", NameScope.DESCENDENT );
  
          // Test compound name
          path = path + "/grand-child";
          assertSameName( path, baseName, "some-child/grand-child", 
NameScope.DESCENDENT );
  
          // Test relative names
          assertSameName( path, baseName, "./some-child/grand-child", 
NameScope.DESCENDENT );
          assertSameName( path, baseName, "./nada/../some-child/grand-child", 
NameScope.DESCENDENT );
          assertSameName( path, baseName, "some-child/./grand-child", 
NameScope.DESCENDENT );
  
          // Test badly formed descendent names
          checkDescendentNames( baseName, NameScope.DESCENDENT );
      }
  
      /**
       * Tests resolution of absolute names.
       */
      public void testAbsoluteNames() throws Exception
      {
          // Test against the base folder
          FileName name = getReadFolder().getName();
          checkAbsoluteNames( name );
  
          // Test against the root
          name = getReadFolder().getFileSystem().getRoot().getName();
          checkAbsoluteNames( name );
  
          // Test against some unknown file
          name = name.resolveName( "a/b/unknown" );
          checkAbsoluteNames( name );
      }
  
      /**
       * Tests resolution of absolute names.
       */
      private void checkAbsoluteNames( final FileName name ) throws Exception
      {
          // Root
          assertSameName( "/", name, "/" );
          assertSameName( "/", name, "//" );
          assertSameName( "/", name, "/." );
          assertSameName( "/", name, "/some file/.." );
  
          // Some absolute names
          assertSameName( "/a", name, "/a" );
          assertSameName( "/a", name, "/./a" );
          assertSameName( "/a", name, "/a/." );
          assertSameName( "/a/b", name, "/a/b" );
  
          // Some bad names
          assertBadName( name, "/..", NameScope.FILE_SYSTEM );
          assertBadName( name, "/a/../..", NameScope.FILE_SYSTEM );
      }
  
      /**
       * Asserts that a particular relative name is invalid for a particular
       * scope.
       */
      private void assertBadName( final FileName name,
                                  final String relName,
                                  final NameScope scope )
      {
          try
          {
              name.resolveName( relName, scope );
              fail( "expected failure" );
          }
          catch ( FileSystemException e )
          {
              // TODO - should check error message
          }
      }
  
      /**
       * Tests conversion from absolute to relative names.
       */
      public void testAbsoluteNameConvert() throws Exception
      {
          final FileName baseName = getReadFolder().getName();
  
          String path = "/test1/test2";
          FileName name = baseName.resolveName( path );
          assertEquals( path, name.getPath() );
  
          // Try child and descendent names
          testRelName( name, "child" );
          testRelName( name, "child1/child2" );
  
          // Try own name
          testRelName( name, "." );
  
          // Try parent, and root
          testRelName( name, ".." );
          testRelName( name, "../.." );
  
          // Try sibling and descendent of sibling
          testRelName( name, "../sibling" );
          testRelName( name, "../sibling/child" );
  
          // Try siblings with similar names
          testRelName( name, "../test2_not" );
          testRelName( name, "../test2_not/child" );
          testRelName( name, "../test" );
          testRelName( name, "../test/child" );
  
          // Try unrelated
          testRelName( name, "../../unrelated" );
          testRelName( name, "../../test" );
          testRelName( name, "../../test/child" );
  
          // Test against root
          path = "/";
          name = baseName.resolveName( path );
          assertEquals( path, name.getPath() );
  
          // Try child and descendent names (against root)
          testRelName( name, "child" );
          testRelName( name, "child1/child2" );
  
          // Try own name (against root)
          testRelName( name, "." );
      }
  
      /**
       * Checks that a file name converts to an expected relative path
       */
      private void testRelName( final FileName baseName,
                                final String relPath )
          throws Exception
      {
          final FileName expectedName = baseName.resolveName( relPath );
  
          // Convert to relative path, and check
          final String actualRelPath = baseName.getRelativeName( expectedName );
          assertEquals( relPath, actualRelPath );
      }
  }
  
  
  
  1.1                  
jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/test/UrlStructureTests.java
  
  Index: UrlStructureTests.java
  ===================================================================
  /* ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  package org.apache.commons.vfs.test;
  
  import org.apache.commons.vfs.FileObject;
  import org.apache.commons.vfs.Capability;
  import java.io.IOException;
  
  /**
   * URL Test cases for providers that supply structural info.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]";>Adam Murdoch</a>
   * @version $Revision: 1.1 $ $Date: 2003/01/23 04:41:56 $
   */
  public class UrlStructureTests
      extends AbstractProviderTestCase
  {
      /**
       * Returns the capabilities required by the tests of this test case.
       */
      protected Capability[] getRequiredCaps()
      {
          return new Capability[]
          {
              Capability.GET_TYPE
          };
      }
  
      /**
       * Tests that folders have no content.
       */
      public void testFolderURL() throws Exception
      {
          final FileObject folder = getReadFolder().resolveFile( "dir1" );
          assertTrue( folder.exists() );
  
          // Try getting the content of a folder
          try
          {
              folder.getURL().openConnection().getInputStream();
              fail();
          }
          catch ( final IOException e )
          {
              assertSameMessage( "vfs.provider/read-folder.error", folder, e );
          }
      }
  }
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to