You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@synapse.apache.org by ra...@apache.org on 2010/09/23 08:04:34 UTC

svn commit: r1000332 [22/27] - in /synapse/branches/commons-vfs-2-synapse-2.0: ./ core/ core/src/ core/src/main/ core/src/main/java/ core/src/main/java/org/ core/src/main/java/org/apache/ core/src/main/java/org/apache/commons/ core/src/main/java/org/ap...

Added: synapse/branches/commons-vfs-2-synapse-2.0/core/src/test/java/org/apache/commons/vfs/provider/webdav/test/WebdavVersioningTests.java
URL: http://svn.apache.org/viewvc/synapse/branches/commons-vfs-2-synapse-2.0/core/src/test/java/org/apache/commons/vfs/provider/webdav/test/WebdavVersioningTests.java?rev=1000332&view=auto
==============================================================================
--- synapse/branches/commons-vfs-2-synapse-2.0/core/src/test/java/org/apache/commons/vfs/provider/webdav/test/WebdavVersioningTests.java (added)
+++ synapse/branches/commons-vfs-2-synapse-2.0/core/src/test/java/org/apache/commons/vfs/provider/webdav/test/WebdavVersioningTests.java Thu Sep 23 06:04:21 2010
@@ -0,0 +1,165 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.vfs.provider.webdav.test;
+
+import java.io.OutputStream;
+import java.util.Map;
+
+import org.apache.commons.vfs.FileObject;
+import org.apache.commons.vfs.FileSystemOptions;
+import org.apache.commons.vfs.FileType;
+import org.apache.commons.vfs.Selectors;
+import org.apache.commons.vfs.provider.webdav.WebdavFileSystemConfigBuilder;
+import org.apache.commons.vfs.provider.URLFileName;
+import org.apache.commons.vfs.test.AbstractProviderTestCase;
+import org.apache.jackrabbit.webdav.version.DeltaVConstants;
+import org.apache.jackrabbit.webdav.version.VersionControlledResource;
+
+/**
+ * Test to verify Webdav Versioning support
+ */
+public class WebdavVersioningTests extends AbstractProviderTestCase
+{
+    /**
+     *
+     */
+    public void testVersioning() throws Exception
+    {
+        FileObject scratchFolder = createScratchFolder();
+        FileSystemOptions opts = scratchFolder.getFileSystem().getFileSystemOptions();
+        WebdavFileSystemConfigBuilder builder =
+            (WebdavFileSystemConfigBuilder)getManager().getFileSystemConfigBuilder("webdav");
+        builder.setVersioning(opts, true);
+        FileObject file = getManager().resolveFile(scratchFolder, "file1.txt", opts);
+        FileSystemOptions newOpts = file.getFileSystem().getFileSystemOptions();
+        assertTrue(opts == newOpts);
+        assertTrue(builder.isVersioning(newOpts));
+        assertTrue(!file.exists());
+        file.createFile();
+        assertTrue(file.exists());
+        assertSame(FileType.FILE, file.getType());
+        assertEquals(0, file.getContent().getSize());
+        assertFalse(file.isHidden());
+        assertTrue(file.isReadable());
+        assertTrue(file.isWriteable());
+        Map map = file.getContent().getAttributes();
+        String name = ((URLFileName)file.getName()).getUserName();
+        assertTrue(map.containsKey(DeltaVConstants.CREATOR_DISPLAYNAME.toString()));
+        if (name != null)
+        {
+            assertEquals(name, map.get(DeltaVConstants.CREATOR_DISPLAYNAME.toString()));
+        }
+        assertTrue(map.containsKey(VersionControlledResource.CHECKED_IN.toString()));
+
+        // Create the source file
+        final String content = "Here is some sample content for the file.  Blah Blah Blah.";
+        final String contentAppend = content + content;
+
+        final OutputStream os = file.getContent().getOutputStream();
+        try
+        {
+            os.write(content.getBytes("utf-8"));
+        }
+        finally
+        {
+            os.close();
+        }
+        assertSameContent(content, file);
+        map = file.getContent().getAttributes();
+        assertTrue(map.containsKey(DeltaVConstants.CREATOR_DISPLAYNAME.toString()));
+        if (name != null)
+        {
+            assertEquals(name, map.get(DeltaVConstants.CREATOR_DISPLAYNAME.toString()));
+        }
+        assertTrue(map.containsKey(VersionControlledResource.CHECKED_IN.toString()));
+        builder.setVersioning(opts, false);
+    }
+    /**
+     *
+     */
+    public void testVersioningWithCreator() throws Exception
+    {
+        FileObject scratchFolder = createScratchFolder();
+        FileSystemOptions opts = scratchFolder.getFileSystem().getFileSystemOptions();
+        WebdavFileSystemConfigBuilder builder =
+            (WebdavFileSystemConfigBuilder)getManager().getFileSystemConfigBuilder("webdav");
+        builder.setVersioning(opts, true);
+        builder.setCreatorName(opts, "testUser");
+        FileObject file = getManager().resolveFile(scratchFolder, "file1.txt", opts);
+        FileSystemOptions newOpts = file.getFileSystem().getFileSystemOptions();
+        assertTrue(opts == newOpts);
+        assertTrue(builder.isVersioning(newOpts));
+        assertTrue(!file.exists());
+        file.createFile();
+        assertTrue(file.exists());
+        assertSame(FileType.FILE, file.getType());
+        assertEquals(0, file.getContent().getSize());
+        assertFalse(file.isHidden());
+        assertTrue(file.isReadable());
+        assertTrue(file.isWriteable());
+        Map map = file.getContent().getAttributes();
+        String name = ((URLFileName)file.getName()).getUserName();
+        assertTrue(map.containsKey(DeltaVConstants.CREATOR_DISPLAYNAME.toString()));
+        assertEquals(map.get(DeltaVConstants.CREATOR_DISPLAYNAME.toString()),"testUser");
+        if (name != null)
+        {
+            assertTrue(map.containsKey(DeltaVConstants.COMMENT.toString()));
+            assertEquals("Modified by user " + name, map.get(DeltaVConstants.COMMENT.toString()));
+        }
+        assertTrue(map.containsKey(VersionControlledResource.CHECKED_IN.toString()));
+
+        // Create the source file
+        final String content = "Here is some sample content for the file.  Blah Blah Blah.";
+        final String contentAppend = content + content;
+
+        final OutputStream os = file.getContent().getOutputStream();
+        try
+        {
+            os.write(content.getBytes("utf-8"));
+        }
+        finally
+        {
+            os.close();
+        }
+        assertSameContent(content, file);
+        map = file.getContent().getAttributes();
+        assertTrue(map.containsKey(DeltaVConstants.CREATOR_DISPLAYNAME.toString()));
+        assertEquals(map.get(DeltaVConstants.CREATOR_DISPLAYNAME.toString()),"testUser");
+        if (name != null)
+        {
+            assertTrue(map.containsKey(DeltaVConstants.COMMENT.toString()));
+            assertEquals("Modified by user " + name, map.get(DeltaVConstants.COMMENT.toString()));
+        }
+        assertTrue(map.containsKey(VersionControlledResource.CHECKED_IN.toString()));
+        builder.setVersioning(opts, false);
+        builder.setCreatorName(opts, null);
+    }
+        /**
+     * Sets up a scratch folder for the test to use.
+     */
+    protected FileObject createScratchFolder() throws Exception
+    {
+        FileObject scratchFolder = getWriteFolder();
+
+        // Make sure the test folder is empty
+        scratchFolder.delete(Selectors.EXCLUDE_SELF);
+        scratchFolder.createFolder();
+
+        return scratchFolder;
+    }
+
+}

Added: synapse/branches/commons-vfs-2-synapse-2.0/core/src/test/java/org/apache/commons/vfs/provider/zip/test/NestedZipTestCase.java
URL: http://svn.apache.org/viewvc/synapse/branches/commons-vfs-2-synapse-2.0/core/src/test/java/org/apache/commons/vfs/provider/zip/test/NestedZipTestCase.java?rev=1000332&view=auto
==============================================================================
--- synapse/branches/commons-vfs-2-synapse-2.0/core/src/test/java/org/apache/commons/vfs/provider/zip/test/NestedZipTestCase.java (added)
+++ synapse/branches/commons-vfs-2-synapse-2.0/core/src/test/java/org/apache/commons/vfs/provider/zip/test/NestedZipTestCase.java Thu Sep 23 06:04:21 2010
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.vfs.provider.zip.test;
+
+import junit.framework.Test;
+import org.apache.commons.AbstractVfsTestCase;
+import org.apache.commons.vfs.FileObject;
+import org.apache.commons.vfs.FileSystemManager;
+import org.apache.commons.vfs.impl.DefaultFileSystemManager;
+import org.apache.commons.vfs.provider.zip.ZipFileProvider;
+import org.apache.commons.vfs.test.AbstractProviderTestConfig;
+import org.apache.commons.vfs.test.ProviderTestConfig;
+import org.apache.commons.vfs.test.ProviderTestSuite;
+
+/**
+ * Tests for the Zip file system, using a zip file nested inside another zip file.
+ *
+ * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
+ */
+public class NestedZipTestCase
+    extends AbstractProviderTestConfig
+    implements ProviderTestConfig
+{
+    /**
+     * Creates the test suite for nested zip files.
+     */
+    public static Test suite() throws Exception
+    {
+        return new ProviderTestSuite(new NestedZipTestCase(), true);
+    }
+
+    /**
+     * Prepares the file system manager.
+     */
+    public void prepare(final DefaultFileSystemManager manager)
+        throws Exception
+    {
+        manager.addProvider("zip", new ZipFileProvider());
+        manager.addExtensionMap("zip", "zip");
+        manager.addMimeTypeMap("application/zip", "zip");
+    }
+
+    /**
+     * Returns the base folder for tests.
+     */
+    public FileObject getBaseTestFolder(final FileSystemManager manager) throws Exception
+    {
+        // Locate the base Zip file
+        final String zipFilePath = AbstractVfsTestCase.getTestResource("nested.zip").getAbsolutePath();
+        String uri = "zip:file:" + zipFilePath + "!/test.zip";
+        final FileObject zipFile = manager.resolveFile(uri);
+
+        // Now build the nested file system
+        final FileObject nestedFS = manager.createFileSystem(zipFile);
+        return nestedFS.resolveFile("/");
+    }
+}

Added: synapse/branches/commons-vfs-2-synapse-2.0/core/src/test/java/org/apache/commons/vfs/provider/zip/test/ZipProviderTestCase.java
URL: http://svn.apache.org/viewvc/synapse/branches/commons-vfs-2-synapse-2.0/core/src/test/java/org/apache/commons/vfs/provider/zip/test/ZipProviderTestCase.java?rev=1000332&view=auto
==============================================================================
--- synapse/branches/commons-vfs-2-synapse-2.0/core/src/test/java/org/apache/commons/vfs/provider/zip/test/ZipProviderTestCase.java (added)
+++ synapse/branches/commons-vfs-2-synapse-2.0/core/src/test/java/org/apache/commons/vfs/provider/zip/test/ZipProviderTestCase.java Thu Sep 23 06:04:21 2010
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.vfs.provider.zip.test;
+
+import junit.framework.Test;
+import org.apache.commons.AbstractVfsTestCase;
+import org.apache.commons.vfs.FileObject;
+import org.apache.commons.vfs.FileSystemManager;
+import org.apache.commons.vfs.impl.DefaultFileSystemManager;
+import org.apache.commons.vfs.provider.zip.ZipFileProvider;
+import org.apache.commons.vfs.test.AbstractProviderTestConfig;
+import org.apache.commons.vfs.test.ProviderTestConfig;
+import org.apache.commons.vfs.test.ProviderTestSuite;
+
+import java.io.File;
+
+/**
+ * Tests for the Zip file system.
+ *
+ * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
+ */
+public class ZipProviderTestCase
+    extends AbstractProviderTestConfig
+    implements ProviderTestConfig
+{
+    /**
+     * Creates the test suite for the zip file system.
+     */
+    public static Test suite() throws Exception
+    {
+        return new ProviderTestSuite(new ZipProviderTestCase(), true);
+    }
+
+    /**
+     * Prepares the file system manager.
+     */
+    public void prepare(final DefaultFileSystemManager manager) throws Exception
+    {
+        manager.addProvider("zip", new ZipFileProvider());
+        manager.addExtensionMap("zip", "zip");
+        manager.addMimeTypeMap("application/zip", "zip");
+    }
+
+    /**
+     * Returns the base folder for read tests.
+     */
+    public FileObject getBaseTestFolder(final FileSystemManager manager) throws Exception
+    {
+        final File zipFile = AbstractVfsTestCase.getTestResource("test.zip");
+        final String uri = "zip:file:" + zipFile.getAbsolutePath() + "!/";
+        return manager.resolveFile(uri);
+    }
+}

Added: synapse/branches/commons-vfs-2-synapse-2.0/core/src/test/java/org/apache/commons/vfs/test/AbstractProviderTestCase.java
URL: http://svn.apache.org/viewvc/synapse/branches/commons-vfs-2-synapse-2.0/core/src/test/java/org/apache/commons/vfs/test/AbstractProviderTestCase.java?rev=1000332&view=auto
==============================================================================
--- synapse/branches/commons-vfs-2-synapse-2.0/core/src/test/java/org/apache/commons/vfs/test/AbstractProviderTestCase.java (added)
+++ synapse/branches/commons-vfs-2-synapse-2.0/core/src/test/java/org/apache/commons/vfs/test/AbstractProviderTestCase.java Thu Sep 23 06:04:21 2010
@@ -0,0 +1,394 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.vfs.test;
+
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.net.URLConnection;
+import java.util.Arrays;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+
+import org.apache.commons.AbstractVfsTestCase;
+import org.apache.commons.vfs.Capability;
+import org.apache.commons.vfs.FileContent;
+import org.apache.commons.vfs.FileObject;
+import org.apache.commons.vfs.FileSystem;
+import org.apache.commons.vfs.FileSystemException;
+import org.apache.commons.vfs.FileSystemManager;
+import org.apache.commons.vfs.FileType;
+import org.apache.commons.vfs.impl.DefaultFileSystemManager;
+import org.apache.commons.vfs.provider.AbstractFileSystem;
+import org.apache.commons.vfs.provider.local.DefaultLocalFileProvider;
+
+/**
+ * File system test cases, which verifies the structure and naming
+ * functionality.
+ * <p/>
+ * Works from a base folder, and assumes a particular structure under
+ * that base folder.
+ *
+ * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
+ * @version $Revision: 833829 $ $Date: 2009-11-08 10:46:14 +0530 (Sun, 08 Nov 2009) $
+ */
+public abstract class AbstractProviderTestCase
+    extends AbstractVfsTestCase
+{
+    private FileObject baseFolder;
+    private FileObject readFolder;
+    private FileObject writeFolder;
+    private DefaultFileSystemManager manager;
+    private ProviderTestConfig providerConfig;
+    private Method method;
+    private boolean addEmptyDir;
+
+    // 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 test method.
+     */
+    public void setMethod(final Method method)
+    {
+        this.method = method;
+    }
+
+    /**
+     * Configures this test.
+     */
+    public void setConfig(final DefaultFileSystemManager manager,
+    					  final ProviderTestConfig providerConfig,
+                          final FileObject baseFolder,
+                          final FileObject readFolder,
+                          final FileObject writeFolder)
+    {
+        this.manager = manager;
+        this.providerConfig = providerConfig;
+        this.baseFolder = baseFolder;
+        this.readFolder = readFolder;
+        this.writeFolder = writeFolder;
+    }
+
+    /**
+     * Returns the file system manager used by this test.
+     */
+    protected DefaultFileSystemManager getManager()
+    {
+        return manager;
+    }
+
+    /**
+     * creates a new uninitialized file system manager
+     * @throws Exception
+     */
+    protected DefaultFileSystemManager createManager() throws Exception
+    {
+	    DefaultFileSystemManager fs = getProviderConfig().getDefaultFileSystemManager();
+	    fs.setFilesCache(getProviderConfig().getFilesCache());
+	    getProviderConfig().prepare(fs);
+	    if (!fs.hasProvider("file"))
+	    {
+	        fs.addProvider("file", new DefaultLocalFileProvider());
+	    }
+	    return fs;
+    }
+
+    /**
+     * some provider config do some post-initialization in getBaseTestFolder.
+     * This is a hack to allow access to this code for <code>createManager</code>
+     */
+    public FileObject getBaseTestFolder(FileSystemManager fs) throws Exception
+    {
+        return providerConfig.getBaseTestFolder(fs);
+    }
+
+    /**
+     * Returns the base test folder.  This is the parent of both the read
+     * test and write test folders.
+     */
+    public FileObject getBaseFolder()
+    {
+        return baseFolder;
+    }
+
+    /**
+     * get the provider configuration
+     */
+    public ProviderTestConfig getProviderConfig()
+	{
+		return providerConfig;
+	}
+
+	/**
+     * Returns the read test folder.
+     */
+    protected FileObject getReadFolder()
+    {
+        return readFolder;
+    }
+
+    /**
+     * Returns the write test folder.
+     */
+    protected FileObject getWriteFolder()
+    {
+        return writeFolder;
+    }
+
+    /**
+     * Sets the write test folder.
+     * @param folder
+     */
+    protected void setWriteFolder(FileObject folder)
+    {
+        writeFolder = folder;
+    }
+
+    /**
+     * 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/>
+     * <p>This implementation returns null.
+     */
+    protected Capability[] getRequiredCaps()
+    {
+        return null;
+    }
+
+    /**
+     * 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];
+                FileSystem fs = readFolder.getFileSystem();
+                String name = fs.getClass().getName();
+                int index = name.lastIndexOf('.');
+                String fsName = (index > 0) ? name.substring(index + 1) : name;
+                if (!fs.hasCapability(cap))
+                {
+                    System.out.println("skipping " + getName() + " because " +
+                        fsName + " does not have capability " + cap);
+                    return;
+                }
+            }
+        }
+
+        // Provider has all the capabilities - execute the test
+        if (method != null)
+        {
+            try
+            {
+                method.invoke(this, (Object[]) null);
+            }
+            catch (final InvocationTargetException e)
+            {
+                throw e.getTargetException();
+            }
+        }
+        else
+        {
+            super.runTest();
+        }
+
+        if (((AbstractFileSystem) readFolder.getFileSystem()).isOpen())
+        {
+            String name = "unknown";
+            if (method != null)
+            {
+                name = method.getName();
+            }
+
+            throw new IllegalStateException(getClass().getName() + ": filesystem has open streams after: " + name);
+        }
+    }
+
+    /**
+     * 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()));
+    }
+
+    /**
+     * 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.
+     */
+    protected void assertSameContent(final String expected,
+                                     final FileObject file)
+        throws Exception
+    {
+        // Check the file exists, and is a file
+        assertTrue(file.exists());
+        assertSame(FileType.FILE, file.getType());
+
+        // Get file content as a binary stream
+        final byte[] expectedBin = expected.getBytes("utf-8");
+
+        // Check lengths
+        final FileContent content = file.getContent();
+        assertEquals("same content length", expectedBin.length, content.getSize());
+
+        // Read content into byte array
+        final InputStream instr = content.getInputStream();
+        final ByteArrayOutputStream outstr;
+        try
+        {
+            outstr = new ByteArrayOutputStream(expectedBin.length);
+            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()));
+    }
+
+    /**
+     * Builds the expected structure of the read tests folder.
+     */
+    protected FileInfo buildExpectedStructure() throws FileSystemException
+    {
+        // Build the expected structure
+        final FileInfo base = new FileInfo(getReadFolder().getName().getBaseName(), FileType.FOLDER);
+        base.addFile("file1.txt", FILE1_CONTENT);
+        // file%.txt - test out encoding
+        base.addFile("file%25.txt", FILE1_CONTENT);
+
+        // file?test.txt - test out encoding (test.txt is not the queryString)
+        // as we do not know if the current file provider we need to
+        // ask it to normalize the name
+        // todo: move this into the FileInfo class to do it generally?
+        /* webdav-bug?: didnt manage to get the "?" correctly through webdavlib
+        FileSystemManager fsm = getReadFolder().getFileSystem().getFileSystemManager();
+        FileName fn = fsm.resolveName(getReadFolder().getName(), "file%3ftest.txt");
+        String baseName = fn.getBaseName();
+        base.addFile(baseName, FILE1_CONTENT);
+        */
+        base.addFile("file space.txt", FILE1_CONTENT);
+
+        base.addFile("empty.txt", "");
+        if (addEmptyDir)
+        {
+            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);
+
+        final FileInfo subdir1 = dir.addFolder("subdir1");
+        subdir1.addFile("file1.txt", TEST_FILE_CONTENT);
+        subdir1.addFile("file2.txt", TEST_FILE_CONTENT);
+        subdir1.addFile("file3.txt", TEST_FILE_CONTENT);
+
+        final FileInfo subdir2 = dir.addFolder("subdir2");
+        subdir2.addFile("file1.txt", TEST_FILE_CONTENT);
+        subdir2.addFile("file2.txt", TEST_FILE_CONTENT);
+        subdir2.addFile("file3.txt", TEST_FILE_CONTENT);
+
+        final FileInfo subdir3 = dir.addFolder("subdir3");
+        subdir3.addFile("file1.txt", TEST_FILE_CONTENT);
+        subdir3.addFile("file2.txt", TEST_FILE_CONTENT);
+        subdir3.addFile("file3.txt", TEST_FILE_CONTENT);
+
+        return base;
+    }
+
+    protected void addEmptyDir(boolean addEmptyDir)
+    {
+        this.addEmptyDir = addEmptyDir;
+    }
+
+    protected static Test notConfigured(Class testClass)
+    {
+        return warning(testClass + " is not configured for tests, skipping");
+    }
+
+    private static Test warning(final String message)
+    {
+        return new TestCase("warning")
+        {
+            protected void runTest()
+            {
+  		        System.out.println(message);
+   			}
+   		};
+   	}
+}

Added: synapse/branches/commons-vfs-2-synapse-2.0/core/src/test/java/org/apache/commons/vfs/test/AbstractProviderTestConfig.java
URL: http://svn.apache.org/viewvc/synapse/branches/commons-vfs-2-synapse-2.0/core/src/test/java/org/apache/commons/vfs/test/AbstractProviderTestConfig.java?rev=1000332&view=auto
==============================================================================
--- synapse/branches/commons-vfs-2-synapse-2.0/core/src/test/java/org/apache/commons/vfs/test/AbstractProviderTestConfig.java (added)
+++ synapse/branches/commons-vfs-2-synapse-2.0/core/src/test/java/org/apache/commons/vfs/test/AbstractProviderTestConfig.java Thu Sep 23 06:04:21 2010
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.vfs.test;
+
+import org.apache.commons.vfs.FilesCache;
+import org.apache.commons.vfs.cache.SoftRefFilesCache;
+import org.apache.commons.vfs.impl.DefaultFileSystemManager;
+
+/**
+ * A partial {@link org.apache.commons.vfs.test.ProviderTestConfig} implementation.
+ *
+ * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
+ * @version $Revision: 833829 $ $Date: 2009-11-08 10:46:14 +0530 (Sun, 08 Nov 2009) $
+ */
+public abstract class AbstractProviderTestConfig extends AbstractProviderTestCase
+    implements ProviderTestConfig
+{
+    private FilesCache cache = null;
+    
+    /**
+	 * Returns a DefaultFileSystemManager instance (or subclass instance).
+	 */
+	public DefaultFileSystemManager getDefaultFileSystemManager() {
+		return new DefaultFileSystemManager();
+	}
+
+    /**
+     * Prepares the file system manager.  This implementation does nothing.
+     */
+    public void prepare(final DefaultFileSystemManager manager)
+        throws Exception
+    {
+    }
+
+    public FilesCache getFilesCache()
+    {
+        if (cache == null)
+        {
+            // cache = new DefaultFilesCache();
+            cache = new SoftRefFilesCache();
+        }
+
+        return cache;
+    }
+}

Added: synapse/branches/commons-vfs-2-synapse-2.0/core/src/test/java/org/apache/commons/vfs/test/AbstractTestSuite.java
URL: http://svn.apache.org/viewvc/synapse/branches/commons-vfs-2-synapse-2.0/core/src/test/java/org/apache/commons/vfs/test/AbstractTestSuite.java?rev=1000332&view=auto
==============================================================================
--- synapse/branches/commons-vfs-2-synapse-2.0/core/src/test/java/org/apache/commons/vfs/test/AbstractTestSuite.java (added)
+++ synapse/branches/commons-vfs-2-synapse-2.0/core/src/test/java/org/apache/commons/vfs/test/AbstractTestSuite.java Thu Sep 23 06:04:21 2010
@@ -0,0 +1,357 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.vfs.test;
+
+import junit.extensions.TestSetup;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import org.apache.commons.AbstractVfsTestCase;
+import org.apache.commons.vfs.FileName;
+import org.apache.commons.vfs.FileObject;
+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;
+
+import java.io.File;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.List;
+
+/**
+ * The suite of tests for a file system.
+ *
+ * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
+ * @author Gary D. Gregory
+ * @version $Id: AbstractTestSuite.java 833829 2009-11-08 05:16:14Z rgoers $
+ */
+public abstract class AbstractTestSuite
+    extends TestSetup
+{
+    private final ProviderTestConfig providerConfig;
+    private final String prefix;
+    private TestSuite testSuite;
+
+    private FileObject baseFolder;
+    private FileObject readFolder;
+    private FileObject writeFolder;
+    private DefaultFileSystemManager manager;
+    private File tempDir;
+
+    private Thread[] startThreadSnapshot;
+    private Thread[] endThreadSnapshot;
+    private boolean addEmptyDir;
+
+    /**
+     * Adds the tests for a file system to this suite.
+     */
+    public AbstractTestSuite(final ProviderTestConfig providerConfig) throws Exception
+    {
+        this(providerConfig, "", false, false);
+    }
+
+    protected AbstractTestSuite(final ProviderTestConfig providerConfig,
+                                final String prefix,
+                                final boolean nested) throws Exception
+    {
+        this(providerConfig, prefix, nested, false);
+    }
+
+
+    protected AbstractTestSuite(final ProviderTestConfig providerConfig,
+                                final String prefix,
+                                final boolean nested,
+                                final boolean addEmptyDir)
+        throws Exception
+    {
+        super(new TestSuite());
+        testSuite = (TestSuite) fTest;
+        this.providerConfig = providerConfig;
+        this.prefix = prefix;
+        this.addEmptyDir = addEmptyDir;
+        addBaseTests();
+        if (!nested)
+        {
+            // Add nested tests
+            // TODO - move nested jar and zip tests here
+            // TODO - enable this again
+            //testSuite.addTest( new ProviderTestSuite( new JunctionProviderConfig( providerConfig ), "junction.", true ));
+        }
+    }
+
+    /**
+     * Adds base tests - excludes the nested test cases.
+     */
+    protected void addBaseTests() throws Exception
+    {
+    }
+
+    /**
+     * Adds the tests from a class to this suite.  The supplied class must be
+     * a subclass of {@link AbstractProviderTestCase} and have a public a
+     * no-args constructor.  This method creates an instance of the supplied
+     * class for each public 'testNnnn' method provided by the class.
+     */
+    public void addTests(final Class testClass) throws Exception
+    {
+        // Verify the class
+        if (!AbstractProviderTestCase.class.isAssignableFrom(testClass))
+        {
+            throw new Exception("Test class " + testClass.getName() + " is not assignable to " + AbstractProviderTestCase.class.getName());
+        }
+
+        // Locate the test methods
+        final Method[] methods = testClass.getMethods();
+        for (int i = 0; i < methods.length; i++)
+        {
+            final Method method = methods[i];
+            if (!method.getName().startsWith("test")
+                || Modifier.isStatic(method.getModifiers())
+                || method.getReturnType() != Void.TYPE
+                || method.getParameterTypes().length != 0)
+            {
+                continue;
+            }
+
+            // Create instance
+            final AbstractProviderTestCase testCase = (AbstractProviderTestCase) testClass.newInstance();
+            testCase.setMethod(method);
+            testCase.setName(prefix + method.getName());
+            testCase.addEmptyDir(this.addEmptyDir);
+            testSuite.addTest(testCase);
+        }
+    }
+
+    protected void setUp() throws Exception
+    {
+        startThreadSnapshot = createThreadSnapshot();
+
+        // 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 = providerConfig.getDefaultFileSystemManager();
+        manager.setFilesCache(providerConfig.getFilesCache());
+
+        final DefaultFileReplicator replicator = new DefaultFileReplicator(tempDir);
+        manager.setReplicator(new PrivilegedFileReplicator(replicator));
+        manager.setTemporaryFileStore(replicator);
+
+        providerConfig.prepare(manager);
+
+        if (!manager.hasProvider("file"))
+        {
+            manager.addProvider("file", new DefaultLocalFileProvider());
+        }
+
+        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("Folder does not exist: " + readFolder, readFolder.exists());
+        assertFalse(readFolder.getName().getPath().equals(FileName.ROOT_PATH));
+
+        // Configure the tests
+        final Enumeration tests = testSuite.tests();
+        while (tests.hasMoreElements())
+        {
+            final Test test = (Test) tests.nextElement();
+            if (test instanceof AbstractProviderTestCase)
+            {
+                final AbstractProviderTestCase providerTestCase = (AbstractProviderTestCase) test;
+                providerTestCase.setConfig(manager, providerConfig, baseFolder, readFolder, writeFolder);
+            }
+        }
+    }
+
+    protected void tearDown() throws Exception
+    {
+        readFolder.close();
+        writeFolder.close();
+        baseFolder.close();
+
+        readFolder = null;
+        writeFolder = null;
+        baseFolder = null;
+        testSuite = null;
+        fTest = null;
+
+        // force the SoftRefFilesChache to free all files
+        System.err.println(".");
+        System.gc();
+        Thread.sleep(1000);
+        System.err.println(".");
+        System.gc();
+        Thread.sleep(1000);
+        System.err.println(".");
+        System.gc();
+        Thread.sleep(1000);
+        System.err.println(".");
+        System.gc();
+        Thread.sleep(1000);
+
+        manager.freeUnusedResources();
+        endThreadSnapshot = createThreadSnapshot();
+
+        Thread[] diffThreadSnapshot = diffThreadSnapshot(startThreadSnapshot, endThreadSnapshot);
+        if (diffThreadSnapshot.length > 0)
+        {
+            String message = dumpThreadSnapshot(diffThreadSnapshot);
+            /*
+            if (providerConfig.checkCleanThreadState())
+            {
+                // close the manager to do a "not thread safe" release of all resources
+                // and allow the vm to shutdown
+                manager.close();
+                fail(message);
+            }
+            else
+            {
+            */
+            System.out.println(message);
+            // }
+        }
+        // System.in.read();
+
+        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.getAbsolutePath() + ")", tempDir.isDirectory() && tempDir.list().length == 0);
+        }
+    }
+
+    private String dumpThreadSnapshot(Thread[] threadSnapshot)
+    {
+        StringBuffer sb = new StringBuffer(256);
+        sb.append("created threads still running:\n");
+
+        Field threadTargetField = null;
+        try
+        {
+            threadTargetField = Thread.class.getDeclaredField("target");
+            threadTargetField.setAccessible(true);
+        }
+        catch (NoSuchFieldException e)
+        {
+            // ignored
+        }
+
+        for (int iter = 0; iter < threadSnapshot.length; iter++)
+        {
+            Thread thread = threadSnapshot[iter];
+            if (thread == null)
+            {
+                continue;
+            }
+
+            sb.append("#");
+            sb.append(iter + 1);
+            sb.append(": ");
+            sb.append(thread.getThreadGroup().getName());
+            sb.append("\t");
+            sb.append(thread.getName());
+            sb.append("\t");
+            if (thread.isDaemon())
+            {
+                sb.append("daemon");
+            }
+            else
+            {
+                sb.append("not_a_daemon");
+            }
+
+            if (threadTargetField != null)
+            {
+                sb.append("\t");
+                try
+                {
+                    Object threadTarget = threadTargetField.get(thread);
+                    if (threadTarget != null)
+                    {
+                        sb.append(threadTarget.getClass());
+                    }
+                    else
+                    {
+                        sb.append("null");
+                    }
+                }
+                catch (IllegalAccessException e)
+                {
+                    sb.append("unknown class");
+                }
+            }
+
+            sb.append("\n");
+        }
+
+        return sb.toString();
+    }
+
+    private Thread[] diffThreadSnapshot(Thread[] startThreadSnapshot, Thread[] endThreadSnapshot)
+    {
+        List diff = new ArrayList(10);
+
+        nextEnd: for (int iterEnd = 0; iterEnd < endThreadSnapshot.length; iterEnd++)
+        {
+            nextStart: for (int iterStart = 0; iterStart < startThreadSnapshot.length; iterStart++)
+            {
+                if (startThreadSnapshot[iterStart] == endThreadSnapshot[iterEnd])
+                {
+                    continue nextEnd;
+                }
+            }
+
+            diff.add(endThreadSnapshot[iterEnd]);
+        }
+
+        Thread ret[] = new Thread[diff.size()];
+        diff.toArray(ret);
+        return ret;
+    }
+
+    private Thread[] createThreadSnapshot()
+    {
+        ThreadGroup tg = Thread.currentThread().getThreadGroup();
+        while (tg.getParent() != null)
+        {
+            tg = tg.getParent();
+        }
+
+        Thread snapshot[] = new Thread[200];
+        tg.enumerate(snapshot, true);
+
+        return snapshot;
+    }
+}

Added: synapse/branches/commons-vfs-2-synapse-2.0/core/src/test/java/org/apache/commons/vfs/test/CacheTestSuite.java
URL: http://svn.apache.org/viewvc/synapse/branches/commons-vfs-2-synapse-2.0/core/src/test/java/org/apache/commons/vfs/test/CacheTestSuite.java?rev=1000332&view=auto
==============================================================================
--- synapse/branches/commons-vfs-2-synapse-2.0/core/src/test/java/org/apache/commons/vfs/test/CacheTestSuite.java (added)
+++ synapse/branches/commons-vfs-2-synapse-2.0/core/src/test/java/org/apache/commons/vfs/test/CacheTestSuite.java Thu Sep 23 06:04:21 2010
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.vfs.test;
+
+
+/**
+ * The suite of tests for a file system.
+ *
+ * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
+ * @author Gary D. Gregory
+ * @version $Id: CacheTestSuite.java 480428 2006-11-29 06:15:24Z bayard $
+ */
+public class CacheTestSuite
+    extends AbstractTestSuite
+{
+    /**
+     * Adds the tests for a file system to this suite.
+     */
+    public CacheTestSuite(final ProviderTestConfig providerConfig) throws Exception
+    {
+        this(providerConfig, "", false);
+    }
+
+    protected CacheTestSuite(final ProviderTestConfig providerConfig,
+                             final String prefix,
+                             final boolean nested)
+        throws Exception
+    {
+        super(providerConfig, prefix, nested);
+    }
+}

Added: synapse/branches/commons-vfs-2-synapse-2.0/core/src/test/java/org/apache/commons/vfs/test/ContentTests.java
URL: http://svn.apache.org/viewvc/synapse/branches/commons-vfs-2-synapse-2.0/core/src/test/java/org/apache/commons/vfs/test/ContentTests.java?rev=1000332&view=auto
==============================================================================
--- synapse/branches/commons-vfs-2-synapse-2.0/core/src/test/java/org/apache/commons/vfs/test/ContentTests.java (added)
+++ synapse/branches/commons-vfs-2-synapse-2.0/core/src/test/java/org/apache/commons/vfs/test/ContentTests.java Thu Sep 23 06:04:21 2010
@@ -0,0 +1,326 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.vfs.test;
+
+import org.apache.commons.vfs.FileContent;
+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;
+
+import java.io.InputStream;
+import java.util.Iterator;
+
+/**
+ * Test cases for reading file content.
+ *
+ * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
+ * @version $Revision: 773234 $ $Date: 2009-05-09 20:57:59 +0530 (Sat, 09 May 2009) $
+ */
+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.getName().toString(), 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());
+        assertTrue("file exists", file.getType() != FileType.IMAGINARY);
+
+        // Test a folder
+        file = getReadFolder().resolveFile("dir1");
+        assertTrue("folder exists", file.exists());
+        assertTrue("folder exists", file.getType() != FileType.IMAGINARY);
+
+        // Test an unknown file
+        file = getReadFolder().resolveFile("unknown-child");
+        assertTrue("unknown file does not exist", !file.exists());
+        assertTrue("unknown file does not exist",
+            file.getType() == FileType.IMAGINARY);
+
+        // Test an unknown file in an unknown folder
+        file = getReadFolder().resolveFile("unknown-folder/unknown-child");
+        assertTrue("unknown file does not exist", !file.exists());
+        assertTrue("unknown file does not exist",
+            file.getType() == FileType.IMAGINARY);
+    }
+
+    /**
+     * Tests root of file system exists.
+     */
+    public void testRoot() throws FileSystemException
+    {
+        FileSystem fs = getReadFolder().getFileSystem();
+        String uri = fs.getRootURI();
+        final FileObject file = getManager().resolveFile(uri);
+        //final FileObject file = getReadFolder().getFileSystem().getRoot();
+        assertTrue(file.exists());
+        assertTrue(file.getType() != FileType.IMAGINARY);
+    }
+
+    /**
+     * 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 (final FileSystemException e)
+        {
+            assertSameMessage("vfs.provider/list-children-not-folder.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-not-file.error", unknownFile, e);
+        }
+        try
+        {
+            content.getSize();
+            fail();
+        }
+        catch (final FileSystemException e)
+        {
+            assertSameMessage("vfs.provider/get-size-not-file.error", unknownFile, e);
+        }
+    }
+
+    /**
+     * Tests concurrent reads on a file.
+     */
+    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().close();
+        }
+        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);
+    }
+
+    /**
+     * Tests that input streams are cleaned up on file close.
+     */
+    public void testInstrCleanup() throws Exception
+    {
+        // Get the test file
+        FileObject file = getReadFolder().resolveFile("file1.txt");
+        assertEquals(FileType.FILE, file.getType());
+
+        // Open some input streams
+        final InputStream instr1 = file.getContent().getInputStream();
+        assertTrue(instr1.read() == FILE1_CONTENT.charAt(0));
+        final InputStream instr2 = file.getContent().getInputStream();
+        assertTrue(instr2.read() == FILE1_CONTENT.charAt(0));
+
+        // Close the file
+        file.close();
+
+        // Check
+        assertTrue(instr1.read() == -1);
+        assertTrue(instr2.read() == -1);
+    }
+}

Added: synapse/branches/commons-vfs-2-synapse-2.0/core/src/test/java/org/apache/commons/vfs/test/FileInfo.java
URL: http://svn.apache.org/viewvc/synapse/branches/commons-vfs-2-synapse-2.0/core/src/test/java/org/apache/commons/vfs/test/FileInfo.java?rev=1000332&view=auto
==============================================================================
--- synapse/branches/commons-vfs-2-synapse-2.0/core/src/test/java/org/apache/commons/vfs/test/FileInfo.java (added)
+++ synapse/branches/commons-vfs-2-synapse-2.0/core/src/test/java/org/apache/commons/vfs/test/FileInfo.java Thu Sep 23 06:04:21 2010
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.vfs.test;
+
+import org.apache.commons.vfs.FileType;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Info about a file.
+ */
+class FileInfo
+{
+    String baseName;
+    FileType type;
+    String content;
+    Map children = new HashMap();
+    FileInfo parent;
+
+    public FileInfo(final String name, final FileType type)
+    {
+        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()
+    {
+        return parent;
+    }
+
+    /**
+     * Adds a child.
+     */
+    public void addChild(final FileInfo child)
+    {
+        children.put(child.baseName, child);
+        child.parent = this;
+    }
+
+    /**
+     * Adds a child file.
+     */
+    public FileInfo addFile(final String baseName, final String content)
+    {
+        final FileInfo child = new FileInfo(baseName, FileType.FILE, content);
+        addChild(child);
+        return child;
+    }
+
+    /**
+     * Adds a child folder.
+     */
+    public FileInfo addFolder(final String baseName)
+    {
+        final FileInfo child = new FileInfo(baseName, FileType.FOLDER, null);
+        addChild(child);
+        return child;
+    }
+}

Added: synapse/branches/commons-vfs-2-synapse-2.0/core/src/test/java/org/apache/commons/vfs/test/FileSystemManagerFactoryTestCase.java
URL: http://svn.apache.org/viewvc/synapse/branches/commons-vfs-2-synapse-2.0/core/src/test/java/org/apache/commons/vfs/test/FileSystemManagerFactoryTestCase.java?rev=1000332&view=auto
==============================================================================
--- synapse/branches/commons-vfs-2-synapse-2.0/core/src/test/java/org/apache/commons/vfs/test/FileSystemManagerFactoryTestCase.java (added)
+++ synapse/branches/commons-vfs-2-synapse-2.0/core/src/test/java/org/apache/commons/vfs/test/FileSystemManagerFactoryTestCase.java Thu Sep 23 06:04:21 2010
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.vfs.test;
+
+import org.apache.commons.AbstractVfsTestCase;
+import org.apache.commons.vfs.FileObject;
+import org.apache.commons.vfs.FileSystemManager;
+import org.apache.commons.vfs.FileType;
+import org.apache.commons.vfs.VFS;
+
+import java.io.File;
+
+/**
+ * Test cases for the VFS factory.
+ *
+ * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
+ * @version $Revision: 480428 $ $Date: 2006-11-29 11:45:24 +0530 (Wed, 29 Nov 2006) $
+ */
+public class FileSystemManagerFactoryTestCase
+    extends AbstractVfsTestCase
+{
+    /**
+     * Sanity test.
+     */
+    public void testDefaultInstance() throws Exception
+    {
+        // Locate the default manager
+        final FileSystemManager manager = VFS.getManager();
+
+        // Lookup a test jar file
+        final File jarFile = getTestResource("test.jar");
+        FileObject file = manager.toFileObject(jarFile);
+        assertNotNull(file);
+        assertTrue(file.exists());
+        assertSame(FileType.FILE, file.getType());
+
+        // Expand it
+        file = manager.createFileSystem(file);
+        assertNotNull(file);
+        assertTrue(file.exists());
+        assertSame(FileType.FOLDER, file.getType());
+    }
+
+}

Added: synapse/branches/commons-vfs-2-synapse-2.0/core/src/test/java/org/apache/commons/vfs/test/LastModifiedTests.java
URL: http://svn.apache.org/viewvc/synapse/branches/commons-vfs-2-synapse-2.0/core/src/test/java/org/apache/commons/vfs/test/LastModifiedTests.java?rev=1000332&view=auto
==============================================================================
--- synapse/branches/commons-vfs-2-synapse-2.0/core/src/test/java/org/apache/commons/vfs/test/LastModifiedTests.java (added)
+++ synapse/branches/commons-vfs-2-synapse-2.0/core/src/test/java/org/apache/commons/vfs/test/LastModifiedTests.java Thu Sep 23 06:04:21 2010
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.vfs.test;
+
+import junit.framework.AssertionFailedError;
+import org.apache.commons.vfs.Capability;
+import org.apache.commons.vfs.FileObject;
+
+/**
+ * Test cases for getting and setting file last modified time.
+ *
+ * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
+ * @version $Revision: 480428 $ $Date: 2006-11-29 11:45:24 +0530 (Wed, 29 Nov 2006) $
+ */
+public class LastModifiedTests
+    extends AbstractProviderTestCase
+{
+    /**
+     * Returns the capabilities required by the tests of this test case.
+     */
+    protected Capability[] getRequiredCaps()
+    {
+        return new Capability[]{
+            Capability.GET_LAST_MODIFIED
+        };
+    }
+
+    /**
+     * Tests getting the last modified time of a file.
+     */
+    public void testGetLastModified() throws Exception
+    {
+        // Try a file.
+        final FileObject file = getReadFolder().resolveFile("file1.txt");
+        file.getContent().getLastModifiedTime();
+
+        // TODO - switch this on
+        // Try a folder
+        //final FileObject folder = getReadFolder().resolveFile( "dir1" );
+        //folder.getContent().getLastModifiedTime();
+    }
+
+    /**
+     * Tests setting the last modified time of file.
+     */
+    public void testSetLastModified() throws Exception
+    {
+        final long now = System.currentTimeMillis();
+
+        if (getReadFolder().getFileSystem().hasCapability(Capability.SET_LAST_MODIFIED_FILE))
+        {
+            // Try a file
+            final FileObject file = getReadFolder().resolveFile("file1.txt");
+            file.getContent().setLastModifiedTime(now);
+            try
+            {
+                assertEquals(now, file.getContent().getLastModifiedTime(), file.getFileSystem().getLastModTimeAccuracy());
+            }
+            catch (AssertionFailedError e)
+            {
+                // on linux ext3 the above check is not necessarily true
+                if (file.getFileSystem().getLastModTimeAccuracy() < 1000L)
+                {
+                    assertEquals(now, file.getContent().getLastModifiedTime(), 1000L);
+                }
+                else
+                {
+                    throw e;
+                }
+            }
+        }
+
+        if (getReadFolder().getFileSystem().hasCapability(Capability.SET_LAST_MODIFIED_FOLDER))
+        {
+            // Try a folder
+            final FileObject folder = getReadFolder().resolveFile("dir1");
+            folder.getContent().setLastModifiedTime(now);
+            try
+            {
+                assertEquals(now, folder.getContent().getLastModifiedTime(), folder.getFileSystem().getLastModTimeAccuracy());
+            }
+            catch (AssertionFailedError e)
+            {
+                // on linux ext3 the above check is not necessarily true
+                if (folder.getFileSystem().getLastModTimeAccuracy() < 1000L)
+                {
+                    assertEquals(now, folder.getContent().getLastModifiedTime(), 1000L);
+                }
+                else
+                {
+                    throw e;
+                }
+            }
+        }
+    }
+}

Added: synapse/branches/commons-vfs-2-synapse-2.0/core/src/test/java/org/apache/commons/vfs/test/NamingTests.java
URL: http://svn.apache.org/viewvc/synapse/branches/commons-vfs-2-synapse-2.0/core/src/test/java/org/apache/commons/vfs/test/NamingTests.java?rev=1000332&view=auto
==============================================================================
--- synapse/branches/commons-vfs-2-synapse-2.0/core/src/test/java/org/apache/commons/vfs/test/NamingTests.java (added)
+++ synapse/branches/commons-vfs-2-synapse-2.0/core/src/test/java/org/apache/commons/vfs/test/NamingTests.java Thu Sep 23 06:04:21 2010
@@ -0,0 +1,461 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.vfs.test;
+
+import org.apache.commons.vfs.FileName;
+import org.apache.commons.vfs.FileObject;
+import org.apache.commons.vfs.FileSystemException;
+import org.apache.commons.vfs.NameScope;
+
+/**
+ * Test cases for file naming.
+ *
+ * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
+ * @version $Revision: 755295 $ $Date: 2009-03-17 21:41:28 +0530 (Tue, 17 Mar 2009) $
+ * @todo Add tests for all FileName methods
+ */
+public class NamingTests
+    extends AbstractProviderTestCase
+{
+    /**
+     * 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);
+
+        // free basefile
+        getManager().setBaseFile((FileObject) null);
+    }
+
+    /**
+     * Tests encoding of relative URI.
+     */
+    public void testRelativeUriEncoding() throws Exception
+    {
+        // Build base dir
+        getManager().setBaseFile(getReadFolder());
+        final String path = getReadFolder().getName().getPath();
+
+        // §1 Encode "some file"
+        FileObject file = getManager().resolveFile("%73%6f%6d%65%20%66%69%6c%65");
+        assertEquals(path + "/some file", file.getName().getPathDecoded());
+
+        // §2 Encode "."
+        file = getManager().resolveFile("%2e");
+        // 18-6-2005 imario@apache.org: no need to keep the "current directory"
+        // assertEquals(path + "/.", file.getName().getPathDecoded());
+        assertEquals(path, file.getName().getPathDecoded());
+
+        // §3 Encode '%'
+        file = getManager().resolveFile("a%25");
+        assertEquals(path + "/a%", file.getName().getPathDecoded());
+
+        // §4 Encode /
+        file = getManager().resolveFile("dir%2fchild");
+        assertEquals(path + "/dir/child", file.getName().getPathDecoded());
+
+        // §5 Encode \
+        file = getManager().resolveFile("dir%5cchild");
+        // 18-6-2005 imario@apache.org: all file separators normalized to "/"
+        // decided to do this to get the same behaviour as in §4 on windows
+        // platforms
+        // assertEquals(path + "/dir\\child", file.getName().getPathDecoded());
+        assertEquals(path + "/dir/child", file.getName().getPathDecoded());
+
+        // §6 Use "%" literal
+        try
+        {
+            getManager().resolveFile("%");
+            fail();
+        }
+        catch (FileSystemException e)
+        {
+        }
+
+        // §7 Not enough digits in encoded char
+        try
+        {
+            getManager().resolveFile("%5");
+            fail();
+        }
+        catch (FileSystemException e)
+        {
+        }
+
+        // §8 Invalid digit in encoded char
+        try
+        {
+            getManager().resolveFile("%q");
+            fail();
+        }
+        catch (FileSystemException e)
+        {
+        }
+
+        // free basefile
+        getManager().setBaseFile((FileObject) null);
+    }
+
+    /**
+     * 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 = getManager().resolveName(baseName, "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 = getManager().resolveName(baseName, relName, scope);
+        assertEquals(expectedPath, name.getPath());
+
+        String temp;
+        
+        // Replace the separators
+        temp = relName.replace('\\', '/');
+        name = getManager().resolveName(baseName, temp, scope);
+        assertEquals(expectedPath, name.getPath());
+
+        // And again
+        temp = relName.replace('/', '\\');
+        name = getManager().resolveName(baseName, temp, 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 = getManager().resolveName(name, "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
+        {
+            getManager().resolveName(name, 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 = getManager().resolveName(baseName, 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 = getManager().resolveName(baseName, 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 = getManager().resolveName(baseName, relPath);
+
+        // Convert to relative path, and check
+        final String actualRelPath = baseName.getRelativeName(expectedName);
+        assertEquals(relPath, actualRelPath);
+    }
+}