org.apache.commons.vfs2.test
Class AbstractProviderTestCase

java.lang.Object
  extended by junit.framework.Assert
      extended by junit.framework.TestCase
          extended by org.apache.commons.AbstractVfsTestCase
              extended by org.apache.commons.vfs2.test.AbstractProviderTestCase
All Implemented Interfaces:
junit.framework.Test
Direct Known Subclasses:
AbstractProviderTestConfig, ContentTests, FileNameTests, JunctionTests, LastModifiedTests, LRUFilesCacheTests, NamingTests, NullFilesCacheTests, ProviderCacheStrategyTests, ProviderDeleteTests, ProviderRandomReadTests, ProviderRandomReadWriteTests, ProviderReadTests, ProviderRenameTests, ProviderWriteAppendTests, ProviderWriteTests, UriTests, UrlStructureTests, UrlTests, VfsClassLoaderTests, WebdavVersioningTests

public abstract class AbstractProviderTestCase
extends AbstractVfsTestCase

File system test cases, which verifies the structure and naming functionality.

Works from a base folder, and assumes a particular structure under that base folder.

Author:
Adam Murdoch

Field Summary
static String FILE1_CONTENT
           
static String TEST_FILE_CONTENT
           
 
Constructor Summary
AbstractProviderTestCase()
           
 
Method Summary
protected  void addEmptyDir(boolean addEmptyDir)
           
protected  void assertSameContent(String expected, FileObject file)
          Asserts that the content of a file is the same as expected.
protected  void assertSameURLContent(String expected, URLConnection connection)
          Asserts that the content of a file is the same as expected.
protected  org.apache.commons.vfs2.test.FileInfo buildExpectedStructure()
          Builds the expected structure of the read tests folder.
protected  DefaultFileSystemManager createManager()
          creates a new uninitialized file system manager
 FileObject getBaseFolder()
          Returns the base test folder.
 FileObject getBaseTestFolder(FileSystemManager fs)
          some provider config do some post-initialization in getBaseTestFolder.
protected  DefaultFileSystemManager getManager()
          Returns the file system manager used by this test.
 ProviderTestConfig getProviderConfig()
          get the provider configuration
protected  FileObject getReadFolder()
          Returns the read test folder.
protected  Capability[] getRequiredCaps()
          Returns the capabilities required by the tests of this test case.
protected  FileObject getWriteFolder()
          Returns the write test folder.
protected static junit.framework.Test notConfigured(Class<?> testClass)
           
protected  void runTest()
          Runs the test.
 void setConfig(DefaultFileSystemManager manager, ProviderTestConfig providerConfig, FileObject baseFolder, FileObject readFolder, FileObject writeFolder)
          Configures this test.
 void setMethod(Method method)
          Sets the test method.
protected  void setWriteFolder(FileObject folder)
          Sets the write test folder.
 
Methods inherited from class org.apache.commons.AbstractVfsTestCase
assertSameMessage, assertSameMessage, assertSameMessage, assertSameMessage, equals, getCanonicalFile, getCause, getPackageName, getResourceTestDirectory, getTestDirectory, getTestDirectory, getTestDirectoryFile, getTestResource, getTestResource
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, run, run, runBare, setName, setUp, tearDown, toString
 
Methods inherited from class junit.framework.Assert
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail, failNotEquals, failNotSame, failSame, format
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

FILE1_CONTENT

public static final String FILE1_CONTENT
See Also:
Constant Field Values

TEST_FILE_CONTENT

public static final String TEST_FILE_CONTENT
See Also:
Constant Field Values
Constructor Detail

AbstractProviderTestCase

public AbstractProviderTestCase()
Method Detail

setMethod

public void setMethod(Method method)
Sets the test method.


setConfig

public void setConfig(DefaultFileSystemManager manager,
                      ProviderTestConfig providerConfig,
                      FileObject baseFolder,
                      FileObject readFolder,
                      FileObject writeFolder)
Configures this test.


getManager

protected DefaultFileSystemManager getManager()
Returns the file system manager used by this test.


createManager

protected DefaultFileSystemManager createManager()
                                          throws Exception
creates a new uninitialized file system manager

Throws:
Exception

getBaseTestFolder

public FileObject getBaseTestFolder(FileSystemManager fs)
                             throws Exception
some provider config do some post-initialization in getBaseTestFolder. This is a hack to allow access to this code for createManager

Throws:
Exception

getBaseFolder

public FileObject getBaseFolder()
Returns the base test folder. This is the parent of both the read test and write test folders.


getProviderConfig

public ProviderTestConfig getProviderConfig()
get the provider configuration


getReadFolder

protected FileObject getReadFolder()
Returns the read test folder.


getWriteFolder

protected FileObject getWriteFolder()
Returns the write test folder.


setWriteFolder

protected void setWriteFolder(FileObject folder)
Sets the write test folder.

Parameters:
folder -

getRequiredCaps

protected Capability[] getRequiredCaps()
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.

This implementation returns null.


runTest

protected void runTest()
                throws Throwable
Runs the test. This implementation short-circuits the test if the provider being tested does not have the capabilities required by this test.

Overrides:
runTest in class junit.framework.TestCase
Throws:
Throwable
To Do:
Handle negative caps as well - ie, only run a test if the provider does not have certain caps., Figure out how to remove the test from the TestResult if the test is skipped.

assertSameURLContent

protected void assertSameURLContent(String expected,
                                    URLConnection connection)
                             throws Exception
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.

Throws:
Exception

assertSameContent

protected void assertSameContent(String expected,
                                 FileObject file)
                          throws Exception
Asserts that the content of a file is the same as expected. Checks the length reported by getSize() 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.

Throws:
Exception

buildExpectedStructure

protected org.apache.commons.vfs2.test.FileInfo buildExpectedStructure()
                                                                throws FileSystemException
Builds the expected structure of the read tests folder.

Throws:
FileSystemException - (possibly)

addEmptyDir

protected void addEmptyDir(boolean addEmptyDir)

notConfigured

protected static junit.framework.Test notConfigured(Class<?> testClass)


Copyright © 2002-2011 The Apache Software Foundation. All Rights Reserved.