You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by ad...@apache.org on 2002/11/23 01:32:13 UTC

cvs commit: jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/test UrlTests.java AbstractProviderTestCase.java AbstractProviderTestConfig.java FileSystemManagerFactoryTestCase.java ProviderReadTests.java ProviderTestConfig.java ProviderTestSuite.java ProviderWriteTests.java

adammurdoch    2002/11/22 16:32:13

  Modified:    vfs      maven.xml
               vfs/src/test/org/apache/commons/vfs/provider/ftp/test
                        FtpProviderTestCase.java
               vfs/src/test/org/apache/commons/vfs/provider/jar/test
                        JarProviderTestCase.java NestedJarTestCase.java
               vfs/src/test/org/apache/commons/vfs/provider/local/test
                        LocalProviderTestCase.java
               vfs/src/test/org/apache/commons/vfs/provider/smb/test
                        SmbProviderTestCase.java
               vfs/src/test/org/apache/commons/vfs/provider/temp/test
                        TemporaryProviderTestCase.java
               vfs/src/test/org/apache/commons/vfs/provider/zip/test
                        NestedZipTestCase.java ZipProviderTestCase.java
               vfs/src/test/org/apache/commons/vfs/test
                        AbstractProviderTestCase.java
                        AbstractProviderTestConfig.java
                        FileSystemManagerFactoryTestCase.java
                        ProviderReadTests.java ProviderTestConfig.java
                        ProviderTestSuite.java ProviderWriteTests.java
  Added:       vfs/src/test/org/apache/commons/vfs/impl/test
                        VfsClassLoaderTests.java
               vfs/src/test/org/apache/commons/vfs/provider/test
                        JunctionProviderConfig.java
                        VirtualProviderTestCase.java
               vfs/src/test/org/apache/commons/vfs/provider/url/test
                        UrlProviderTestCase.java
               vfs/src/test/org/apache/commons/vfs/test UrlTests.java
  Log:
  More test reorganisation:
  - Reduced ProviderTestConfig to 2 methods.
  - Changed the expected test file layout.
  - AbstractProviderTestCase uses the capabilities of the file system being
    tested to decide whether to run the test case or not.
  - Started splitting up ProviderReadTests into separate test cases based on
    the capabilities that the tests require.
  - Added test cases for the generic URL-based provider, and junctions.
  
  Revision  Changes    Path
  1.7       +7 -9      jakarta-commons-sandbox/vfs/maven.xml
  
  Index: maven.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/vfs/maven.xml,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- maven.xml	21 Oct 2002 00:46:38 -0000	1.6
  +++ maven.xml	23 Nov 2002 00:32:12 -0000	1.7
  @@ -5,15 +5,13 @@
     <!-- Set up the test files -->
     <postGoal name="test:test-resources">
   
  -    <copy todir="${test.basedir}">
  -      <fileset dir="${test.data.src}">
  -        <include name="basedir/**"/>
  -      </fileset>
  +    <copy todir="${test.basedir}/read-tests">
  +      <fileset dir="${test.data.src}/basedir"/>
       </copy>
       
       <!-- Compile the code for the class loader test -->
       <javac
  -      destdir="${test.basedir}/basedir"
  +      destdir="${test.basedir}/read-tests"
         debug="${maven.compile.debug}"
         deprecation="${maven.compile.deprecation}"
         optimize="${maven.compile.optimize}">
  @@ -24,12 +22,12 @@
         </src>
       </javac>
   
  -    <mkdir dir="${test.basedir}/basedir/emptydir"/>
  +    <mkdir dir="${test.basedir}/read-tests/emptydir"/>
   
       <!-- Create a zip file -->
       <zip zipfile="${test.basedir}/test.zip">
         <zipfileset dir="${test.basedir}">
  -        <include name="basedir/**"/>
  +        <include name="read-tests/**"/>
         </zipfileset>
       </zip>
       <zip zipfile="${test.basedir}/nested.zip">
  @@ -41,12 +39,12 @@
       <jar
         jarfile="${test.basedir}/test.jar"
         basedir="${test.basedir}"
  -      includes="basedir/**"
  +      includes="read-tests/**"
         manifest="${test.data.src}/test.mf"/>
   
       <jar
         jarfile="${test.basedir}/normal.jar"
  -      basedir="${test.basedir}/basedir"
  +      basedir="${test.basedir}/read-tests"
         manifest="${test.data.src}/normal.mf"/>
       <jar
         jarfile="${test.basedir}/nested.jar"
  
  
  
  1.1                  jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/impl/test/VfsClassLoaderTests.java
  
  Index: VfsClassLoaderTests.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 apache@apache.org.
   *
   * 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.impl.test;
  
  import java.net.URL;
  import java.net.URLConnection;
  import org.apache.commons.vfs.impl.VFSClassLoader;
  import org.apache.commons.vfs.test.AbstractProviderTestCase;
  import org.apache.commons.vfs.Capability;
  
  /**
   * VfsClassLoader test cases.
   *
   * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
   * @version $Revision: 1.1 $ $Date: 2002/11/23 00:32:12 $
   */
  public class VfsClassLoaderTests
      extends AbstractProviderTestCase
  {
      /**
       * Returns the capabilities required by the tests of this test case.
       */
      protected Capability[] getRequiredCaps()
      {
          return new Capability[]
          {
              Capability.READ_CONTENT,
              Capability.URI
          };
      }
  
      /**
       * Tests VFSClassLoader.
       */
      public void testVFSClassLoader() throws Exception
      {
          final VFSClassLoader loader =
              new VFSClassLoader( getReadFolder(), getManager() );
  
          final Class testClass = loader.loadClass( "code.ClassToLoad" );
          assertTrue( verifyPackage( testClass.getPackage() ) );
  
          final Object testObject = testClass.newInstance();
          assertSame( "**PRIVATE**", testObject.toString() );
  
          final URL resource = loader.getResource( "file1.txt" );
          assertNotNull( resource );
          final URLConnection urlCon = resource.openConnection();
          assertSameURLContent( FILE1_CONTENT, urlCon );
      }
  
      /**
       * Verify the package loaded with class loader.
       * If the provider supports attributes override this method.
       */
      protected boolean verifyPackage( final Package pack )
      {
          return "code".equals( pack.getName() ) &&
              pack.getImplementationTitle() == null &&
              pack.getImplementationVendor() == null &&
              pack.getImplementationVersion() == null &&
              pack.getSpecificationTitle() == null &&
              pack.getSpecificationVendor() == null &&
              pack.getSpecificationVersion() == null &&
              !pack.isSealed();
      }
  
  }
  
  
  
  1.2       +3 -21     jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/provider/ftp/test/FtpProviderTestCase.java
  
  Index: FtpProviderTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/provider/ftp/test/FtpProviderTestCase.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- FtpProviderTestCase.java	21 Nov 2002 04:31:37 -0000	1.1
  +++ FtpProviderTestCase.java	23 Nov 2002 00:32:12 -0000	1.2
  @@ -90,29 +90,11 @@
       }
   
       /**
  -     * Returns the base folder for read tests.
  +     * Returns the base folder for tests.
        */
  -    public FileObject getReadTestFolder( final FileSystemManager manager ) throws Exception
  +    public FileObject getBaseTestFolder( final FileSystemManager manager ) throws Exception
       {
  -        final String uri = System.getProperty( "test.ftp.uri" ) + "/read-tests";
  -        return manager.resolveFile( uri );
  -    }
  -
  -    /**
  -     * Returns true if the write tests should be run for this provider.
  -     */
  -    public boolean runWriteTests()
  -    {
  -        return true;
  -    }
  -
  -    /**
  -     * Returns the base folder for write tests.  Should return null to
  -     * skip the write tests.
  -     */
  -    public FileObject getWriteTestFolder( final FileSystemManager manager ) throws Exception
  -    {
  -        final String uri = System.getProperty( "test.ftp.uri" ) + "/write-tests";
  +        final String uri = System.getProperty( "test.ftp.uri" );
           return manager.resolveFile( uri );
       }
   }
  
  
  
  1.2       +3 -3      jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/provider/jar/test/JarProviderTestCase.java
  
  Index: JarProviderTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/provider/jar/test/JarProviderTestCase.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- JarProviderTestCase.java	21 Nov 2002 04:31:37 -0000	1.1
  +++ JarProviderTestCase.java	23 Nov 2002 00:32:12 -0000	1.2
  @@ -93,12 +93,12 @@
       }
   
       /**
  -     * Returns the base folder for read tests.
  +     * Returns the base folder for tests.
        */
  -    public FileObject getReadTestFolder( final FileSystemManager manager ) throws Exception
  +    public FileObject getBaseTestFolder( final FileSystemManager manager ) throws Exception
       {
           final File jarFile = AbstractVfsTestCase.getTestResource( "test.jar" );
  -        final String uri = "jar:" + jarFile.getAbsolutePath() + "!basedir";
  +        final String uri = "jar:" + jarFile.getAbsolutePath() + "!/";
           return manager.resolveFile( uri );
       }
   
  
  
  
  1.2       +3 -3      jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/provider/jar/test/NestedJarTestCase.java
  
  Index: NestedJarTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/provider/jar/test/NestedJarTestCase.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- NestedJarTestCase.java	21 Nov 2002 04:31:37 -0000	1.1
  +++ NestedJarTestCase.java	23 Nov 2002 00:32:12 -0000	1.2
  @@ -93,9 +93,9 @@
       }
   
       /**
  -     * Returns the base folder for read tests.
  +     * Returns the base folder for tests.
        */
  -    public FileObject getReadTestFolder( final FileSystemManager manager ) throws Exception
  +    public FileObject getBaseTestFolder( final FileSystemManager manager ) throws Exception
       {
           // Locate the Jar file
           final File outerFile = AbstractVfsTestCase.getTestResource( "nested.jar" );
  @@ -104,7 +104,7 @@
   
           // Now build the nested file system
           final FileObject nestedFS = manager.createFileSystem( "jar", jarFile );
  -        return nestedFS.resolveFile( "/basedir" );
  +        return nestedFS.resolveFile( "/" );
       }
   
       /**
  
  
  
  1.2       +3 -23     jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/provider/local/test/LocalProviderTestCase.java
  
  Index: LocalProviderTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/provider/local/test/LocalProviderTestCase.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- LocalProviderTestCase.java	21 Nov 2002 04:31:37 -0000	1.1
  +++ LocalProviderTestCase.java	23 Nov 2002 00:32:12 -0000	1.2
  @@ -90,31 +90,11 @@
       }
   
       /**
  -     * Returns the base folder for read tests.
  +     * Returns the base folder for tests.
        */
  -    public FileObject getReadTestFolder( final FileSystemManager manager ) throws Exception
  +    public FileObject getBaseTestFolder( final FileSystemManager manager ) throws Exception
       {
  -        final File testDir = AbstractVfsTestCase.getTestDirectory( "basedir" );
  -        final File emptyDir = new File( testDir, "emptydir" );
  -        emptyDir.mkdirs();
  -        return manager.toFileObject( testDir );
  -    }
  -
  -    /**
  -     * Returns true if the write tests should be run for this provider.
  -     */
  -    public boolean runWriteTests()
  -    {
  -        return true;
  -    }
  -
  -    /**
  -     * Returns the base folder for write tests.  Should return null to
  -     * skip the write tests.
  -     */
  -    public FileObject getWriteTestFolder( final FileSystemManager manager ) throws Exception
  -    {
  -        final File testDir = AbstractVfsTestCase.getTestDirectory( "write-tests" );
  +        final File testDir = AbstractVfsTestCase.getTestDirectory();
           return manager.toFileObject( testDir );
       }
   }
  
  
  
  1.2       +3 -22     jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/provider/smb/test/SmbProviderTestCase.java
  
  Index: SmbProviderTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/provider/smb/test/SmbProviderTestCase.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SmbProviderTestCase.java	21 Nov 2002 04:31:37 -0000	1.1
  +++ SmbProviderTestCase.java	23 Nov 2002 00:32:12 -0000	1.2
  @@ -88,30 +88,11 @@
       }
   
       /**
  -     * Returns the base folder for read tests.
  +     * Returns the base folder for tests.
        */
  -    public FileObject getReadTestFolder( final FileSystemManager manager ) throws Exception
  +    public FileObject getBaseTestFolder( final FileSystemManager manager ) throws Exception
       {
  -        final String uri = System.getProperty( "test.smb.uri" ) + "/read-tests";
  -        return manager.resolveFile( uri );
  -    }
  -
  -    /**
  -     * Returns true if the write tests should be run for this provider.
  -     */
  -    public boolean runWriteTests()
  -    {
  -        return true;
  -    }
  -
  -    /**
  -     * Returns the base folder for write tests.  This implementation returns
  -     * null.
  -     */
  -    public FileObject getWriteTestFolder( final FileSystemManager manager )
  -        throws Exception
  -    {
  -        final String uri = System.getProperty( "test.smb.uri" ) + "/write-tests";
  +        final String uri = System.getProperty( "test.smb.uri" );
           return manager.resolveFile( uri );
       }
   }
  
  
  
  1.2       +5 -24     jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/provider/temp/test/TemporaryProviderTestCase.java
  
  Index: TemporaryProviderTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/provider/temp/test/TemporaryProviderTestCase.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TemporaryProviderTestCase.java	21 Nov 2002 04:31:37 -0000	1.1
  +++ TemporaryProviderTestCase.java	23 Nov 2002 00:32:12 -0000	1.2
  @@ -91,33 +91,14 @@
           throws Exception
       {
           final File baseDir = AbstractVfsTestCase.getTestDirectory();
  -        manager.addProvider( "tmp-read", new TemporaryFileProvider( baseDir ) );
  -        manager.addProvider( "tmp-write", new TemporaryFileProvider() );
  +        manager.addProvider( "tmp", new TemporaryFileProvider( baseDir ) );
       }
   
       /**
  -     * Returns the base folder for read tests.
  +     * Returns the base folder for tests.
        */
  -    public FileObject getReadTestFolder( final FileSystemManager manager ) throws Exception
  +    public FileObject getBaseTestFolder( final FileSystemManager manager ) throws Exception
       {
  -        return manager.resolveFile( "tmp-read:/basedir" );
  -    }
  -
  -    /**
  -     * Returns true if the write tests should be run for this provider.
  -     */
  -    public boolean runWriteTests()
  -    {
  -        return true;
  -    }
  -
  -    /**
  -     * Returns the base folder for write tests.  This implementation returns
  -     * null.
  -     */
  -    public FileObject getWriteTestFolder( final FileSystemManager manager )
  -        throws Exception
  -    {
  -        return manager.resolveFile( "tmp-write:/write-tests" );
  +        return manager.resolveFile( "tmp:/" );
       }
   }
  
  
  
  1.1                  jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/provider/test/JunctionProviderConfig.java
  
  Index: JunctionProviderConfig.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 apache@apache.org.
   *
   * 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.provider.test;
  
  import org.apache.commons.vfs.FileObject;
  import org.apache.commons.vfs.FileSystem;
  import org.apache.commons.vfs.FileSystemManager;
  import org.apache.commons.vfs.impl.DefaultFileSystemManager;
  import org.apache.commons.vfs.test.ProviderTestConfig;
  
  /**
   * A provider config that wraps another provider, to run the tests via
   * junctions.
   *
   * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
   * @version $Revision: 1.1 $ $Date: 2002/11/23 00:32:12 $
   */
  public class JunctionProviderConfig
      implements ProviderTestConfig
  {
      private final ProviderTestConfig config;
  
      public JunctionProviderConfig( final ProviderTestConfig config )
      {
          this.config = config;
      }
  
      /**
       * Prepares the file system manager.
       */
      public void prepare( final DefaultFileSystemManager manager ) throws Exception
      {
          config.prepare( manager );
      }
  
      /**
       * Returns the base folder for tests.
       */
      public FileObject getBaseTestFolder( final FileSystemManager manager ) throws Exception
      {
          final FileObject baseFolder = config.getBaseTestFolder( manager );
  
          // Create an empty file system, then link in read-tests and write-tests
          final FileSystem newFs = manager.createFileSystem( "vfs:" ).getFileSystem();
          final String junctionPoint = "/some/dir";
          newFs.addJunction( junctionPoint + "/read-tests", baseFolder.resolveFile( "read-tests") );
          newFs.addJunction( junctionPoint + "/write-tests", baseFolder.resolveFile( "write-tests/subdir") );
  
          return newFs.resolveFile( junctionPoint );
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/provider/test/VirtualProviderTestCase.java
  
  Index: VirtualProviderTestCase.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 apache@apache.org.
   *
   * 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.provider.test;
  
  import org.apache.commons.vfs.test.AbstractProviderTestCase;
  import org.apache.commons.vfs.FileObject;
  import org.apache.commons.vfs.FileSystem;
  import org.apache.commons.vfs.FileSystemException;
  import java.io.File;
  
  /**
   * Test cases for the virtual file system provider.
   *
   * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
   * @version $Revision: 1.1 $ $Date: 2002/11/23 00:32:12 $
   */
  public class VirtualProviderTestCase
      extends AbstractProviderTestCase
  {
      private FileObject getBaseDir() throws FileSystemException
      {
          final File localDir = getTestDirectory( "read-tests" );
          return getManager().toFileObject( localDir );
      }
  
      /**
       * Checks nested junctions are not supported.
       */
      public void testNestedJunction() throws Exception
      {
          final FileSystem fs = getManager().createFileSystem( "vfs:" ).getFileSystem();
          final FileObject baseDir = getBaseDir();
          fs.addJunction( "/a", baseDir );
  
          // Nested
          try
          {
              fs.addJunction( "/a/b", baseDir );
              fail();
          }
          catch ( final Exception e )
          {
              assertSameMessage( "impl/nested-junction.error", "vfs:/a/b", e );
          }
  
          // At same point
          try
          {
              fs.addJunction( "/a", baseDir );
              fail();
          }
          catch ( final Exception e )
          {
              assertSameMessage( "impl/nested-junction.error", "vfs:/a", e );
          }
      }
  
      /**
       * Checks ancestors are created when a junction is created.
       */
      public void testAncestors() throws Exception
      {
          final FileSystem fs = getManager().createFileSystem( "vfs://" ).getFileSystem();
          final FileObject baseDir = getBaseDir();
          assertTrue( baseDir.exists() );
  
          // Make sure the file at the junction point and its ancestors do not exist
          FileObject file = fs.resolveFile( "/a/b" );
          assertFalse( file.exists() );
          file = file.getParent();
          assertFalse( file.exists() );
          file = file.getParent();
          assertFalse( file.exists() );
  
          // Add the junction
          fs.addJunction( "/a/b", baseDir );
  
          // Make sure the file at the junction point and its ancestors exist
          file = fs.resolveFile( "/a/b" );
          assertTrue( "Does not exist", file.exists() );
          file = file.getParent();
          assertTrue( "Does not exist", file.exists() );
          file = file.getParent();
          assertTrue( "Does not exist", file.exists() );
      }
  
      // Check that file @ junction point exists only when backing file exists
      // Add 2 junctions with common parent
      // Compare real and virtual files
      // Events
      // Remove junctions
  }
  
  
  
  1.1                  jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/provider/url/test/UrlProviderTestCase.java
  
  Index: UrlProviderTestCase.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 apache@apache.org.
   *
   * 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.provider.url.test;
  
  import org.apache.commons.vfs.test.AbstractProviderTestConfig;
  import org.apache.commons.vfs.test.ProviderTestSuite;
  import org.apache.commons.vfs.FileObject;
  import org.apache.commons.vfs.FileSystemManager;
  import org.apache.commons.vfs.provider.url.UrlFileProvider;
  import org.apache.commons.vfs.impl.DefaultFileSystemManager;
  import org.apache.commons.AbstractVfsTestCase;
  import junit.framework.Test;
  import java.io.File;
  import java.net.URL;
  
  /**
   * Test cases for the generic provider.
   *
   * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
   * @version $Revision: 1.1 $ $Date: 2002/11/23 00:32:12 $
   */
  public class UrlProviderTestCase
      extends AbstractProviderTestConfig
  {
      public static Test suite() throws Exception
      {
          return new ProviderTestSuite( new UrlProviderTestCase() );
      }
  
      /**
       * Prepares the file system manager.  This implementation does nothing.
       */
      public void prepare( final DefaultFileSystemManager manager )
          throws Exception
      {
          manager.addProvider( "jar", new UrlFileProvider() );
      }
  
      /**
       * Returns the base folder for tests.
       */
      public FileObject getBaseTestFolder( final FileSystemManager manager )
          throws Exception
      {
          final File jarFile = AbstractVfsTestCase.getTestResource( "test.jar" );
          final String uri = "jar:" + jarFile.toURL().toExternalForm() + "!/";
          final URL url = new URL( uri );
          return manager.resolveFile( url.toExternalForm() );
      }
  }
  
  
  
  1.2       +3 -3      jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/provider/zip/test/NestedZipTestCase.java
  
  Index: NestedZipTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/provider/zip/test/NestedZipTestCase.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- NestedZipTestCase.java	21 Nov 2002 04:31:37 -0000	1.1
  +++ NestedZipTestCase.java	23 Nov 2002 00:32:12 -0000	1.2
  @@ -92,9 +92,9 @@
       }
   
       /**
  -     * Returns the base folder for read tests.
  +     * Returns the base folder for tests.
        */
  -    public FileObject getReadTestFolder( FileSystemManager manager ) throws Exception
  +    public FileObject getBaseTestFolder( final FileSystemManager manager ) throws Exception
       {
           // Locate the base Zip file
           final String zipFilePath = AbstractVfsTestCase.getTestResource( "nested.zip" ).getAbsolutePath();
  @@ -103,6 +103,6 @@
   
           // Now build the nested file system
           final FileObject nestedFS = manager.createFileSystem( "zip", zipFile );
  -        return nestedFS.resolveFile( "/basedir" );
  +        return nestedFS.resolveFile( "/" );
       }
   }
  
  
  
  1.2       +2 -2      jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/provider/zip/test/ZipProviderTestCase.java
  
  Index: ZipProviderTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/provider/zip/test/ZipProviderTestCase.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ZipProviderTestCase.java	21 Nov 2002 04:31:37 -0000	1.1
  +++ ZipProviderTestCase.java	23 Nov 2002 00:32:12 -0000	1.2
  @@ -94,10 +94,10 @@
       /**
        * Returns the base folder for read tests.
        */
  -    public FileObject getReadTestFolder( final FileSystemManager manager ) throws Exception
  +    public FileObject getBaseTestFolder( final FileSystemManager manager ) throws Exception
       {
           final File zipFile = AbstractVfsTestCase.getTestResource( "test.zip" );
  -        final String uri = "zip:" + zipFile.getAbsolutePath() + "!basedir";
  +        final String uri = "zip:" + zipFile.getAbsolutePath() + "!/";
           return manager.resolveFile( uri );
       }
   }
  
  
  
  1.2       +139 -9    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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AbstractProviderTestCase.java	21 Nov 2002 04:31:38 -0000	1.1
  +++ AbstractProviderTestCase.java	23 Nov 2002 00:32:12 -0000	1.2
  @@ -55,9 +55,17 @@
    */
   package org.apache.commons.vfs.test;
   
  +import java.io.ByteArrayOutputStream;
   import java.io.File;
  +import java.io.InputStream;
  +import java.net.URLConnection;
  +import java.util.Arrays;
  +import java.lang.reflect.Method;
  +import java.lang.reflect.InvocationTargetException;
   import org.apache.commons.AbstractVfsTestCase;
  +import org.apache.commons.vfs.FileName;
   import org.apache.commons.vfs.FileObject;
  +import org.apache.commons.vfs.Capability;
   import org.apache.commons.vfs.impl.DefaultFileReplicator;
   import org.apache.commons.vfs.impl.DefaultFileSystemManager;
   import org.apache.commons.vfs.impl.PrivilegedFileReplicator;
  @@ -73,7 +81,7 @@
    * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
    * @version $Revision$ $Date$
    */
  -public class AbstractProviderTestCase
  +public abstract class AbstractProviderTestCase
       extends AbstractVfsTestCase
   {
       private FileObject readFolder;
  @@ -81,14 +89,28 @@
       private DefaultFileSystemManager manager;
       private ProviderTestConfig providerConfig;
       private File tempDir;
  +    private Method method;
  +
  +    // Expected contents of "file1.txt"
  +    public static final String FILE1_CONTENT = "This is a test file.";
   
       /** Sets the provider test config, if any. */
  -    public void setConfig( final ProviderTestConfig providerConfig )
  +    public void setConfig( final Method method,
  +                           final ProviderTestConfig providerConfig )
       {
  +        this.method = method;
           this.providerConfig = providerConfig;
       }
   
       /**
  +     * Returns the provider config for this test.
  +     */
  +    public ProviderTestConfig getProviderConfig()
  +    {
  +        return providerConfig;
  +    }
  +
  +    /**
        * Returns the file system manager used by this test.
        */
       protected DefaultFileSystemManager getManager()
  @@ -113,15 +135,31 @@
       }
   
       /**
  +     * Returns the capabilities required by the tests of this test case.  The
  +     * tests are not run if the provider being tested does not support all
  +     * the required capabilities.  Return null or an empty array to always
  +     * run the tests.
  +     *
  +     * <p>This implementation returns null.
  +     */
  +    protected Capability[] getRequiredCaps()
  +    {
  +        return null;
  +    }
  +
  +    /**
        * Sets up the test
        */
       protected void setUp() throws Exception
       {
  +        // Locate the temp directory, and clean it up
  +        tempDir = getTestDirectory( "temp" );
  +        checkTempDir( "Temp dir not empty before test" );
  +
           // Create the file system manager
           manager = new DefaultFileSystemManager();
           manager.addProvider( "file", new DefaultLocalFileSystemProvider() );
   
  -        tempDir = getTestDirectory( "temp" );
           final DefaultFileReplicator replicator = new DefaultFileReplicator( tempDir );
           manager.setReplicator( new PrivilegedFileReplicator( replicator ) );
           manager.setTemporaryFileStore( replicator );
  @@ -136,11 +174,55 @@
           if ( providerConfig != null )
           {
               // Locate the base folder
  -            readFolder = providerConfig.getReadTestFolder( manager );
  -            writeFolder = providerConfig.getWriteTestFolder( manager );
  +            final FileObject baseFolder = providerConfig.getBaseTestFolder( manager );
  +            readFolder = baseFolder.resolveFile( "read-tests" );
  +            writeFolder = baseFolder.resolveFile( "write-tests" );
  +
  +            // Make some assumptions about the name
  +            assertFalse( readFolder.getName().getPath().equals( FileName.ROOT_PATH ) );
  +        }
  +    }
  +
  +    /**
  +     * Runs the test.  This implementation short-circuits the test if the
  +     * provider being tested does not have the capabilities required by this
  +     * test.
  +     *
  +     * @todo Handle negative caps as well - ie, only run a test if the provider does not have certain caps.
  +     * @todo Figure out how to remove the test from the TestResult if the test is skipped.
  +     */
  +    protected void runTest() throws Throwable
  +    {
  +        // Check the capabilities
  +        final Capability[] caps = getRequiredCaps();
  +        if ( caps != null )
  +        {
  +            for ( int i = 0; i < caps.length; i++ )
  +            {
  +                final Capability cap = caps[ i ];
  +                if ( !readFolder.getFileSystem().hasCapability( cap ) )
  +                {
  +                    System.out.println( "skipping " + getName() + " because fs does not have cap " + cap );
  +                    return;
  +                }
  +            }
  +        }
   
  -            // Make some assumptions absout the name
  -            assertTrue( !readFolder.getName().getPath().equals( "/" ) );
  +        // Provider has all the capabilities - execute the test
  +        if ( method != null )
  +        {
  +            try
  +            {
  +                method.invoke( this, null );
  +            }
  +            catch ( final InvocationTargetException e )
  +            {
  +                throw e.getTargetException();
  +            }
  +        }
  +        else
  +        {
  +            super.runTest();
           }
       }
   
  @@ -152,6 +234,54 @@
           manager.close();
   
           // Make sure temp directory is empty or gone
  -        assertTrue( ( ! tempDir.exists() ) || ( tempDir.isDirectory() && tempDir.list().length == 0 ) );
  +        checkTempDir( "Temp dir not empty after test" );
  +    }
  +
  +    /** Asserts that the temp dir is empty or gone. */
  +    private void checkTempDir( final String assertMsg )
  +    {
  +        if ( tempDir.exists() )
  +        {
  +            assertTrue( assertMsg, tempDir.isDirectory() && tempDir.list().length == 0 );
  +        }
  +    }
  +
  +    /**
  +     * Asserts that the content of a file is the same as expected. Checks the
  +     * length reported by getContentLength() is correct, then reads the content
  +     * as a byte stream and compares the result with the expected content.
  +     * Assumes files are encoded using UTF-8.
  +     */
  +    protected void assertSameURLContent( final String expected,
  +                                         final URLConnection connection )
  +        throws Exception
  +    {
  +        // Get file content as a binary stream
  +        final byte[] expectedBin = expected.getBytes( "utf-8" );
  +
  +        // Check lengths
  +        assertEquals( "same content length", expectedBin.length, connection.getContentLength() );
  +
  +        // Read content into byte array
  +        final InputStream instr = connection.getInputStream();
  +        final ByteArrayOutputStream outstr;
  +        try
  +        {
  +            outstr = new ByteArrayOutputStream();
  +            final byte[] buffer = new byte[ 256 ];
  +            int nread = 0;
  +            while ( nread >= 0 )
  +            {
  +                outstr.write( buffer, 0, nread );
  +                nread = instr.read( buffer );
  +            }
  +        }
  +        finally
  +        {
  +            instr.close();
  +        }
  +
  +        // Compare
  +        assertTrue( "same binary content", Arrays.equals( expectedBin, outstr.toByteArray() ) );
       }
   }
  
  
  
  1.2       +1 -19     jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/test/AbstractProviderTestConfig.java
  
  Index: AbstractProviderTestConfig.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/test/AbstractProviderTestConfig.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AbstractProviderTestConfig.java	21 Nov 2002 04:25:58 -0000	1.1
  +++ AbstractProviderTestConfig.java	23 Nov 2002 00:32:12 -0000	1.2
  @@ -75,22 +75,4 @@
           throws Exception
       {
       }
  -
  -    /**
  -     * Returns true if the write tests should be run for this provider.
  -     */
  -    public boolean runWriteTests()
  -    {
  -        return false;
  -    }
  -
  -    /**
  -     * Returns the base folder for write tests.  This implementation returns
  -     * null.
  -     */
  -    public FileObject getWriteTestFolder( final FileSystemManager manager )
  -        throws Exception
  -    {
  -        return null;
  -    }
   }
  
  
  
  1.6       +2 -2      jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/test/FileSystemManagerFactoryTestCase.java
  
  Index: FileSystemManagerFactoryTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/test/FileSystemManagerFactoryTestCase.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- FileSystemManagerFactoryTestCase.java	21 Nov 2002 04:25:58 -0000	1.5
  +++ FileSystemManagerFactoryTestCase.java	23 Nov 2002 00:32:12 -0000	1.6
  @@ -79,7 +79,7 @@
           final FileSystemManager manager = VFS.getManager();
   
           // Lookup a test file
  -        final File testDir = getTestResource( "basedir" );
  +        final File testDir = getTestResource( "read-tests" );
           final FileObject file = manager.toFileObject( testDir );
           assertNotNull( file );
           assertTrue( file.exists() );
  
  
  
  1.3       +14 -162   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.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ProviderReadTests.java	21 Nov 2002 04:31:38 -0000	1.2
  +++ ProviderReadTests.java	23 Nov 2002 00:32:12 -0000	1.3
  @@ -55,22 +55,18 @@
    */
   package org.apache.commons.vfs.test;
   
  +import java.io.ByteArrayOutputStream;
  +import java.io.InputStream;
  +import java.util.ArrayList;
  +import java.util.Arrays;
  +import java.util.List;
  +import org.apache.commons.vfs.FileContent;
  +import org.apache.commons.vfs.FileName;
   import org.apache.commons.vfs.FileObject;
  +import org.apache.commons.vfs.FileSystem;
   import org.apache.commons.vfs.FileSystemException;
  -import org.apache.commons.vfs.FileName;
  -import org.apache.commons.vfs.NameScope;
   import org.apache.commons.vfs.FileType;
  -import org.apache.commons.vfs.FileSystem;
  -import org.apache.commons.vfs.FileContent;
  -import org.apache.commons.vfs.impl.VFSClassLoader;
  -import java.util.List;
  -import java.util.ArrayList;
  -import java.util.Arrays;
  -import java.net.URL;
  -import java.net.URLConnection;
  -import java.io.InputStream;
  -import java.io.ByteArrayOutputStream;
  -import java.io.IOException;
  +import org.apache.commons.vfs.NameScope;
   
   /**
    * Read-only test cases for file providers.
  @@ -81,9 +77,6 @@
   public class ProviderReadTests
       extends AbstractProviderTestCase
   {
  -    // Contents of "file1.txt"
  -    private String charContent = "This is a test file.";
  -
       /**
        * Tests resolution of absolute URI.
        */
  @@ -724,147 +717,6 @@
       }
   
       /**
  -     * Tests VFSClassLoader.
  -     */
  -    public void testVFSClassLoader() throws Exception
  -    {
  -        final FileObject[] objects = {getReadFolder()};
  -        VFSClassLoader loader =
  -            new VFSClassLoader( objects, getManager() );
  -
  -        Class testClass = loader.loadClass( "code.ClassToLoad" );
  -        assertTrue( verifyPackage( testClass.getPackage() ) );
  -
  -        Object testObject = testClass.newInstance();
  -        assertSame( "**PRIVATE**", testObject.toString() );
  -
  -        URL resource = loader.getResource( "file1.txt" );
  -        assertNotNull( resource );
  -        URLConnection urlCon = resource.openConnection();
  -        assertSameURLContent( charContent, urlCon );
  -    }
  -
  -    /**
  -     * Verify the package loaded with class loader.
  -     * If the provider supports attributes override this method.
  -     */
  -    protected boolean verifyPackage( Package pack )
  -    {
  -        return "code".equals( pack.getName() ) &&
  -            pack.getImplementationTitle() == null &&
  -            pack.getImplementationVendor() == null &&
  -            pack.getImplementationVersion() == null &&
  -            pack.getSpecificationTitle() == null &&
  -            pack.getSpecificationVendor() == null &&
  -            pack.getSpecificationVersion() == null &&
  -            !pack.isSealed();
  -    }
  -
  -    /**
  -     * Tests url.
  -     */
  -    public void testURL() throws Exception
  -    {
  -        FileObject file = getReadFolder().resolveFile( "some-dir/" );
  -        URL url = file.getURL();
  -
  -        assertEquals( file.getName().getURI(), url.toExternalForm() );
  -
  -        URL parentURL = new URL( url, ".." );
  -        assertEquals( getReadFolder().getURL(), parentURL );
  -
  -        URL rootURL = new URL( url, "/" );
  -        assertEquals( file.getFileSystem().getRoot().getURL(), rootURL );
  -    }
  -
  -    /**
  -     * Tests content.
  -     */
  -    public void testURLContent() throws Exception
  -    {
  -        // Test non-empty file
  -        FileObject file = getReadFolder().resolveFile( "file1.txt" );
  -        URLConnection urlCon = file.getURL().openConnection();
  -        assertSameURLContent( charContent, urlCon );
  -
  -        // Test empty file
  -        file = getReadFolder().resolveFile( "empty.txt" );
  -        urlCon = file.getURL().openConnection();
  -        assertSameURLContent( "", urlCon );
  -    }
  -
  -    /**
  -     * Asserts that the content of a file is the same as expected. Checks the
  -     * length reported by getContentLength() is correct, then reads the content
  -     * as a byte stream and compares the result with the expected content.
  -     * Assumes files are encoded using UTF-8.
  -     */
  -    protected void assertSameURLContent( final String expected,
  -                                         final URLConnection connection )
  -        throws Exception
  -    {
  -        // Get file content as a binary stream
  -        final byte[] expectedBin = expected.getBytes( "utf-8" );
  -
  -        // Check lengths
  -        assertEquals( "same content length", expectedBin.length, connection.getContentLength() );
  -
  -        // Read content into byte array
  -        final InputStream instr = connection.getInputStream();
  -        final ByteArrayOutputStream outstr;
  -        try
  -        {
  -            outstr = new ByteArrayOutputStream();
  -            final byte[] buffer = new byte[ 256 ];
  -            int nread = 0;
  -            while ( nread >= 0 )
  -            {
  -                outstr.write( buffer, 0, nread );
  -                nread = instr.read( buffer );
  -            }
  -        }
  -        finally
  -        {
  -            instr.close();
  -        }
  -
  -        // Compare
  -        assertTrue( "same binary content", Arrays.equals( expectedBin, outstr.toByteArray() ) );
  -    }
  -
  -    /**
  -     * Tests that folders and unknown files have no content.
  -     */
  -    public void testNoURLContent() throws Exception
  -    {
  -        // Try getting the content of a folder
  -        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
  -        FileObject unknownFile = getReadFolder().resolveFile( "unknown-file" );
  -        URLConnection connection = unknownFile.getURL().openConnection();
  -        try
  -        {
  -            connection.getInputStream();
  -            fail();
  -        }
  -        catch ( IOException e )
  -        {
  -            assertSameMessage( "vfs.provider/read-no-exist.error", unknownFile, e );
  -        }
  -        assertEquals( -1, connection.getContentLength() );
  -    }
  -
  -    /**
        * Tests content.
        */
       public void testContent() throws Exception
  @@ -872,7 +724,7 @@
           // Test non-empty file
           FileObject file = getReadFolder().resolveFile( "file1.txt" );
           FileContent content = file.getContent();
  -        assertSameContent( charContent, content );
  +        assertSameContent( FILE1_CONTENT, content );
   
           // Test empty file
           file = getReadFolder().resolveFile( "empty.txt" );
  @@ -970,11 +822,11 @@
   
           // Get the file content
           FileContent content = file.getContent();
  -        assertSameContent( charContent, content );
  +        assertSameContent( FILE1_CONTENT, content );
   
           // Read the content again
           content = file.getContent();
  -        assertSameContent( charContent, content );
  +        assertSameContent( FILE1_CONTENT, content );
   
           // Close the content + file
           content.close();
  @@ -982,7 +834,7 @@
   
           // Read the content again
           content = file.getContent();
  -        assertSameContent( charContent, content );
  +        assertSameContent( FILE1_CONTENT, content );
       }
   
       /**
  
  
  
  1.2       +5 -9      jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/test/ProviderTestConfig.java
  
  Index: ProviderTestConfig.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/test/ProviderTestConfig.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ProviderTestConfig.java	21 Nov 2002 04:25:58 -0000	1.1
  +++ ProviderTestConfig.java	23 Nov 2002 00:32:12 -0000	1.2
  @@ -57,6 +57,7 @@
   
   import org.apache.commons.vfs.FileObject;
   import org.apache.commons.vfs.FileSystemManager;
  +import org.apache.commons.vfs.Capability;
   import org.apache.commons.vfs.impl.DefaultFileSystemManager;
   
   /**
  @@ -75,15 +76,10 @@
       /**
        * Returns the base folder for read tests.
        */
  -    FileObject getReadTestFolder( FileSystemManager manager ) throws Exception;
  +    FileObject getBaseTestFolder( FileSystemManager manager ) throws Exception;
   
       /**
  -     * Returns true if the write tests should be run for this provider.
  +     * Returns the expected file system capabilities.
        */
  -    boolean runWriteTests();
  -
  -    /**
  -     * Returns the base folder for write tests.
  -     */
  -    FileObject getWriteTestFolder( FileSystemManager manager ) throws Exception;
  +    //Capability[] getExpectedCapabilities();
   }
  
  
  
  1.3       +35 -9     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.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ProviderTestSuite.java	21 Nov 2002 04:31:38 -0000	1.2
  +++ ProviderTestSuite.java	23 Nov 2002 00:32:12 -0000	1.3
  @@ -58,6 +58,7 @@
   import java.lang.reflect.Method;
   import java.lang.reflect.Modifier;
   import junit.framework.TestSuite;
  +import org.apache.commons.vfs.impl.test.VfsClassLoaderTests;
   
   /**
    * The suite of tests for a file system.
  @@ -69,21 +70,44 @@
       extends TestSuite
   {
       private final ProviderTestConfig providerConfig;
  +    private final String prefix;
   
       /**
        * Adds the tests for a file system to this suite.
        */
  -    public ProviderTestSuite( final ProviderTestConfig fsConfig ) throws Exception
  +    public ProviderTestSuite( final ProviderTestConfig providerConfig ) throws Exception
       {
  -        providerConfig = fsConfig;
  -        addTestClass( ProviderReadTests.class );
  -        if ( providerConfig.runWriteTests() )
  +        this( providerConfig, "", false );
  +    }
  +
  +    private ProviderTestSuite( final ProviderTestConfig providerConfig,
  +                               final String prefix,
  +                               final boolean nested )
  +        throws Exception
  +    {
  +        this.providerConfig = providerConfig;
  +        this.prefix = prefix;
  +        addBaseTests();
  +        if ( !nested )
           {
  -            addTestClass( ProviderWriteTests.class );
  +            // Add nested tests
  +            // TODO - enable this again
  +            //addTest( new ProviderTestSuite( new JunctionProviderConfig( providerConfig ), "junction.", true ));
           }
       }
   
       /**
  +     * Adds base tests - excludes the nested test cases.
  +     */
  +    private void addBaseTests() throws Exception
  +    {
  +        addTestClass( ProviderReadTests.class );
  +        addTestClass( ProviderWriteTests.class );
  +        addTestClass( UrlTests.class );
  +        addTestClass( VfsClassLoaderTests.class );
  +    }
  +
  +    /**
        * Adds the tests from a class to this suite.  Looks for a no-args constructor
        * which it uses to create instances of the test class.  Adds an instance
        * for each public test method provided by the class.
  @@ -96,15 +120,17 @@
           {
               final Method method = methods[ i ];
               if ( ! method.getName().startsWith( "test")
  -                || Modifier.isStatic( method.getModifiers() ) )
  +                || Modifier.isStatic( method.getModifiers() )
  +                || method.getReturnType() != Void.TYPE
  +                || method.getParameterTypes().length != 0 )
               {
                   continue;
               }
   
               // Create instance
               final AbstractProviderTestCase testCase = (AbstractProviderTestCase)testClass.newInstance();
  -            testCase.setConfig( providerConfig );
  -            testCase.setName( method.getName() );
  +            testCase.setConfig( method, providerConfig );
  +            testCase.setName( prefix + method.getName() );
               addTest( testCase );
           }
       }
  
  
  
  1.2       +16 -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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ProviderWriteTests.java	21 Nov 2002 04:31:38 -0000	1.1
  +++ ProviderWriteTests.java	23 Nov 2002 00:32:12 -0000	1.2
  @@ -66,6 +66,7 @@
   import org.apache.commons.vfs.FileSystem;
   import org.apache.commons.vfs.FileListener;
   import org.apache.commons.vfs.FileChangeEvent;
  +import org.apache.commons.vfs.Capability;
   
   /**
    * File system test that check that a file system can be modified.
  @@ -75,6 +76,21 @@
   public class ProviderWriteTests
       extends AbstractProviderTestCase
   {
  +    /**
  +     * Returns the capabilities required by the tests of this test case.
  +     */
  +    protected Capability[] getRequiredCaps()
  +    {
  +        return new Capability[]
  +        {
  +            Capability.CREATE,
  +            Capability.DELETE,
  +            Capability.LIST_CHILDREN,
  +            Capability.READ_CONTENT,
  +            Capability.WRITE_CONTENT
  +        };
  +    }
  +
       /**
        * Sets up a scratch folder for the test to use.
        */
  
  
  
  1.1                  jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/test/UrlTests.java
  
  Index: UrlTests.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 apache@apache.org.
   *
   * 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.net.URL;
  import java.net.URLConnection;
  import java.io.IOException;
  
  /**
   * URL test cases for providers.
   *
   * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
   * @version $Revision: 1.1 $ $Date: 2002/11/23 00:32:12 $
   */
  public class UrlTests
      extends AbstractProviderTestCase
  {
      /**
       * Returns the capabilities required by the tests of this test case.  The
       * tests are not run if the provider being tested does not support all
       * the required capabilities.  Return null or an empty array to always
       * run the tests.
       *
       * <p>This implementation returns null.
       */
      protected Capability[] getRequiredCaps()
      {
          return new Capability[] { Capability.URI };
      }
  
      /**
       * Tests url.
       */
      public void testURL() throws Exception
      {
          final FileObject file = getReadFolder().resolveFile( "some-dir/" );
          final URL url = file.getURL();
  
          assertEquals( file.getName().getURI(), url.toExternalForm() );
  
          final URL parentURL = new URL( url, ".." );
          assertEquals( file.getParent().getURL(), parentURL );
  
          final URL rootURL = new URL( url, "/" );
          assertEquals( file.getFileSystem().getRoot().getURL(), rootURL );
      }
  
      /**
       * Tests content.
       */
      public void testURLContent() throws Exception
      {
          // Test non-empty file
          FileObject file = getReadFolder().resolveFile( "file1.txt" );
          URLConnection urlCon = file.getURL().openConnection();
          assertSameURLContent( FILE1_CONTENT, urlCon );
  
          // Test empty file
          file = getReadFolder().resolveFile( "empty.txt" );
          urlCon = file.getURL().openConnection();
          assertSameURLContent( "", urlCon );
      }
  
      /**
       * Tests that folders and unknown files have no content.
       */
      public void testNoURLContent() 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" );
          final URLConnection connection = unknownFile.getURL().openConnection();
          try
          {
              connection.getInputStream();
              fail();
          }
          catch ( IOException e )
          {
              assertSameMessage( "vfs.provider/read-no-exist.error", unknownFile, e );
          }
          assertEquals( -1, connection.getContentLength() );
      }
  }
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>