commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adammurd...@apache.org
Subject cvs commit: jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/test AbstractProviderTestCase.java ProviderTestSuite.java
Date Thu, 20 Feb 2003 09:22:13 GMT
adammurdoch    2003/02/20 01:22:13

  Modified:    vfs/src/test/org/apache/commons/vfs/test
                        AbstractProviderTestCase.java
                        ProviderTestSuite.java
  Log:
  Create the FileSystemManager once per provider test suite, rather than once per test case.
  Allows connections to be pooled/reused/etc, making the tests heaps faster.
  
  Revision  Changes    Path
  1.10      +15 -63    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.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- AbstractProviderTestCase.java	17 Feb 2003 09:22:16 -0000	1.9
  +++ AbstractProviderTestCase.java	20 Feb 2003 09:22:13 -0000	1.10
  @@ -56,7 +56,6 @@
   package org.apache.commons.vfs.test;
   
   import java.io.ByteArrayOutputStream;
  -import java.io.File;
   import java.io.InputStream;
   import java.lang.reflect.InvocationTargetException;
   import java.lang.reflect.Method;
  @@ -67,11 +66,7 @@
   import org.apache.commons.vfs.FileContent;
   import org.apache.commons.vfs.FileObject;
   import org.apache.commons.vfs.FileType;
  -import org.apache.commons.vfs.FileName;
  -import org.apache.commons.vfs.impl.DefaultFileReplicator;
   import org.apache.commons.vfs.impl.DefaultFileSystemManager;
  -import org.apache.commons.vfs.impl.PrivilegedFileReplicator;
  -import org.apache.commons.vfs.provider.local.DefaultLocalFileProvider;
   
   /**
    * File system test cases, which verifies the structure and naming
  @@ -90,8 +85,6 @@
       private FileObject readFolder;
       private FileObject writeFolder;
       private DefaultFileSystemManager manager;
  -    private ProviderTestConfig providerConfig;
  -    private File tempDir;
       private Method method;
   
       // Expected contents of "file1.txt"
  @@ -100,12 +93,22 @@
       // 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 )
  +    /** Sets the test method. */
  +    public void setMethod( final Method method )
       {
           this.method = method;
  -        this.providerConfig = providerConfig;
  +    }
  +
  +    /** Configures this test. */
  +    public void setConfig( final DefaultFileSystemManager manager,
  +                           final FileObject baseFolder,
  +                           final FileObject readFolder,
  +                           final FileObject writeFolder )
  +    {
  +        this.manager = manager;
  +        this.baseFolder = baseFolder;
  +        this.readFolder = readFolder;
  +        this.writeFolder = writeFolder;
       }
   
       /**
  @@ -155,37 +158,6 @@
       }
   
       /**
  -     * 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 DefaultLocalFileProvider() );
  -
  -        final DefaultFileReplicator replicator = new DefaultFileReplicator( tempDir );
  -        manager.setReplicator( new PrivilegedFileReplicator( replicator ) );
  -        manager.setTemporaryFileStore( replicator );
  -
  -        providerConfig.prepare( manager );
  -
  -        manager.init();
  -
  -        // Locate the base folders
  -        baseFolder = providerConfig.getBaseTestFolder( manager );
  -        readFolder = baseFolder.resolveFile( "read-tests" );
  -        writeFolder = baseFolder.resolveFile( "write-tests" );
  -
  -        // Make some assumptions about the read folder
  -        assertTrue( readFolder.exists() );
  -        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.
  @@ -225,26 +197,6 @@
           else
           {
               super.runTest();
  -        }
  -    }
  -
  -    /**
  -     * Cleans-up test.
  -     */
  -    protected void tearDown() throws Exception
  -    {
  -        manager.close();
  -
  -        // Make sure temp directory is empty or gone
  -        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 );
           }
       }
   
  
  
  
  1.8       +77 -4     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.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- ProviderTestSuite.java	12 Feb 2003 07:56:19 -0000	1.7
  +++ ProviderTestSuite.java	20 Feb 2003 09:22:13 -0000	1.8
  @@ -57,8 +57,18 @@
   
   import java.lang.reflect.Method;
   import java.lang.reflect.Modifier;
  +import java.io.File;
  +import java.util.Enumeration;
  +import junit.extensions.TestSetup;
   import junit.framework.TestSuite;
   import org.apache.commons.vfs.impl.test.VfsClassLoaderTests;
  +import org.apache.commons.vfs.impl.DefaultFileSystemManager;
  +import org.apache.commons.vfs.impl.DefaultFileReplicator;
  +import org.apache.commons.vfs.impl.PrivilegedFileReplicator;
  +import org.apache.commons.vfs.provider.local.DefaultLocalFileProvider;
  +import org.apache.commons.vfs.FileName;
  +import org.apache.commons.vfs.FileObject;
  +import org.apache.commons.AbstractVfsTestCase;
   
   /**
    * The suite of tests for a file system.
  @@ -67,10 +77,17 @@
    * @version $Revision$ $Date$
    */
   public class ProviderTestSuite
  -    extends TestSuite
  +    extends TestSetup
   {
       private final ProviderTestConfig providerConfig;
       private final String prefix;
  +    private final TestSuite testSuite;
  +
  +    private FileObject baseFolder;
  +    private FileObject readFolder;
  +    private FileObject writeFolder;
  +    private DefaultFileSystemManager manager;
  +    private File tempDir;
   
       /**
        * Adds the tests for a file system to this suite.
  @@ -85,6 +102,8 @@
                                  final boolean nested )
           throws Exception
       {
  +        super( new TestSuite() );
  +        testSuite = (TestSuite)fTest;
           this.providerConfig = providerConfig;
           this.prefix = prefix;
           addBaseTests();
  @@ -140,9 +159,63 @@
   
               // Create instance
               final AbstractProviderTestCase testCase = (AbstractProviderTestCase)testClass.newInstance();
  -            testCase.setConfig( method, providerConfig );
  +            testCase.setMethod( method );
               testCase.setName( prefix + method.getName() );
  -            addTest( testCase );
  +            testSuite.addTest( testCase );
  +        }
  +    }
  +
  +    protected void setUp() throws Exception
  +    {
  +        // Locate the temp directory, and clean it up
  +        tempDir = AbstractVfsTestCase.getTestDirectory( "temp" );
  +        checkTempDir( "Temp dir not empty before test" );
  +
  +        // Create the file system manager
  +        manager = new DefaultFileSystemManager();
  +        manager.addProvider( "file", new DefaultLocalFileProvider() );
  +
  +        final DefaultFileReplicator replicator = new DefaultFileReplicator( tempDir );
  +        manager.setReplicator( new PrivilegedFileReplicator( replicator ) );
  +        manager.setTemporaryFileStore( replicator );
  +
  +        providerConfig.prepare( manager );
  +
  +        manager.init();
  +
  +        // Locate the base folders
  +        baseFolder = providerConfig.getBaseTestFolder( manager );
  +        readFolder = baseFolder.resolveFile( "read-tests" );
  +        writeFolder = baseFolder.resolveFile( "write-tests" );
  +
  +        // Make some assumptions about the read folder
  +        assertTrue( readFolder.exists() );
  +        assertFalse( readFolder.getName().getPath().equals( FileName.ROOT_PATH ) );
  +
  +        // Configure the tests
  +        final Enumeration tests = testSuite.tests();
  +        while ( tests.hasMoreElements() )
  +        {
  +            final AbstractProviderTestCase test = (AbstractProviderTestCase)tests.nextElement();
  +            test.setConfig( manager, baseFolder, readFolder, writeFolder );
  +        }
  +    }
  +
  +    protected void tearDown() throws Exception
  +    {
  +        manager.close();
  +
  +        // Make sure temp directory is empty or gone
  +        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 );
           }
       }
  +
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message