Author: ecki
Date: Sun Nov 16 07:26:11 2014
New Revision: 1639974

URL: http://svn.apache.org/r1639974
Log:
Additional Unit Tests

Added:
    
commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/cache/DefaultFilesCacheTestCase.java
    
commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/cache/DefaultFilesCacheTests.java
    
commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/cache/FilesCacheTestsBase.java
    
commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/cache/SoftRefFilesCacheTestCase.java
    
commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/cache/SoftRefFilesCacheTests.java
    
commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/cache/WeakRefFilesCacheTestCase.java
    
commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/cache/WeakRefFilesCacheTests.java

Added: 
commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/cache/DefaultFilesCacheTestCase.java
URL: 
http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/cache/DefaultFilesCacheTestCase.java?rev=1639974&view=auto
==============================================================================
--- 
commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/cache/DefaultFilesCacheTestCase.java
 (added)
+++ 
commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/cache/DefaultFilesCacheTestCase.java
 Sun Nov 16 07:26:11 2014
@@ -0,0 +1,57 @@
+/*
+ * 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.vfs2.cache;
+
+import java.io.File;
+
+import junit.framework.Test;
+
+import org.apache.commons.AbstractVfsTestCase;
+import org.apache.commons.vfs2.FileObject;
+import org.apache.commons.vfs2.FileSystemManager;
+import org.apache.commons.vfs2.FilesCache;
+import org.apache.commons.vfs2.test.AbstractProviderTestConfig;
+import org.apache.commons.vfs2.test.CacheTestSuite;
+import org.apache.commons.vfs2.test.ProviderTestConfig;
+
+/**
+ * Tests the NullFilesCache
+ */
+public class DefaultFilesCacheTestCase
+    extends AbstractProviderTestConfig
+    implements ProviderTestConfig
+{
+    public static Test suite() throws Exception
+    {
+        final CacheTestSuite suite = new CacheTestSuite(new 
DefaultFilesCacheTestCase());
+        suite.addTests(DefaultFilesCacheTests.class);
+        return suite;
+    }
+
+    @Override
+    public FilesCache getFilesCache()
+    {
+        return new DefaultFilesCache();
+    }
+
+    @Override
+    public FileObject getBaseTestFolder(final FileSystemManager manager) 
throws Exception
+    {
+        final File testDir = AbstractVfsTestCase.getTestDirectory();
+        return manager.toFileObject(testDir);
+    }
+}

Added: 
commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/cache/DefaultFilesCacheTests.java
URL: 
http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/cache/DefaultFilesCacheTests.java?rev=1639974&view=auto
==============================================================================
--- 
commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/cache/DefaultFilesCacheTests.java
 (added)
+++ 
commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/cache/DefaultFilesCacheTests.java
 Sun Nov 16 07:26:11 2014
@@ -0,0 +1,40 @@
+/*
+ * 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.vfs2.cache;
+
+import org.apache.commons.vfs2.FileObject;
+
+/**
+ * Tests for {@link DefaultFilesCache} used by {@link 
DefaultFilesCacheTestCase}.
+ */
+public class DefaultFilesCacheTests extends FilesCacheTestsBase
+{
+    public void testFilesCache() throws Exception
+    {
+        final FileObject scratchFolder = getWriteFolder();
+
+        final FileObject dir1 = scratchFolder.resolveFile("dir1");
+        final FileObject dir1_2 = scratchFolder.resolveFile("dir1");
+
+        assertSame(dir1, dir1_2);
+
+        // now the same test, unreferenced (compare only hashCode)
+        int hc1 = getFileHashCode();
+        int hc2 = getFileHashCode();
+        assertEquals("Hashcode of file changed, so most likely new instance", 
hc1, hc2);
+    }
+}

Added: 
commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/cache/FilesCacheTestsBase.java
URL: 
http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/cache/FilesCacheTestsBase.java?rev=1639974&view=auto
==============================================================================
--- 
commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/cache/FilesCacheTestsBase.java
 (added)
+++ 
commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/cache/FilesCacheTestsBase.java
 Sun Nov 16 07:26:11 2014
@@ -0,0 +1,90 @@
+/*
+ * 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.vfs2.cache;
+
+import org.apache.commons.vfs2.FileName;
+import org.apache.commons.vfs2.FileObject;
+import org.apache.commons.vfs2.FileSystem;
+import org.apache.commons.vfs2.FileSystemException;
+import org.apache.commons.vfs2.FilesCache;
+import org.apache.commons.vfs2.test.AbstractProviderTestCase;
+
+/**
+ * NullFilesCache
+ *
+ */
+public class FilesCacheTestsBase extends AbstractProviderTestCase
+{
+       /**
+        * Will test if the cache is cleared and if it is still useable 
afterwards.
+        * It will actually ensure the test is hitting the cache.
+        */
+    public void testClearFiles() throws Exception
+    {
+       FilesCache cache = getManager().getFilesCache();
+
+       final FileObject fo1 = getWriteFolder().resolveFile("dir1");
+
+       // clean the cache for this file system
+       cache.clear(fo1.getFileSystem());
+       // make sure a empty cache clean does not fail
+       cache.clear(fo1.getFileSystem());
+
+       final FileObject fo2 = getWriteFolder().resolveFile("dir1");
+
+       assertFalse("Objects after cache clear should be different", fo1 == 
fo2);
+    }
+
+    /**
+     * Basic Cache operations, work for all caches
+     * (besides {@link NullFilesCache#testBasicCacheOps() NullFilesCache}).
+     */
+    public void testBasicCacheOps() throws Exception
+    {
+       final FilesCache cache = getManager().getFilesCache();
+       final FileObject fo = getWriteFolder().resolveFile("dir1");
+       final FileName fn = fo.getName();
+       final FileSystem fs = fo.getFileSystem();
+
+       cache.clear(fs);
+       assertNull(cache.getFile(fs, fn));
+
+       cache.putFile(fo);
+       assertSame(fo, cache.getFile(fs, fn));
+
+       assertFalse(cache.putFileIfAbsent(fo));
+       cache.clear(fs);
+       assertNull(cache.getFile(fs, fn));
+       assertTrue(cache.putFileIfAbsent(fo));
+
+       cache.removeFile(fs, fn);
+       assertNull(cache.getFile(fs, fn));
+       assertTrue(cache.putFileIfAbsent(fo));
+    }
+
+    /** Helper method, may be used in cache specific tests. */
+    protected int getFileHashCode() throws FileSystemException
+       {
+               final FileObject fo = getWriteFolder().resolveFile("file2");
+               if (!fo.exists())
+               {
+                       fo.createFile();
+               }
+
+               return fo.hashCode();
+       }
+}

Added: 
commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/cache/SoftRefFilesCacheTestCase.java
URL: 
http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/cache/SoftRefFilesCacheTestCase.java?rev=1639974&view=auto
==============================================================================
--- 
commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/cache/SoftRefFilesCacheTestCase.java
 (added)
+++ 
commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/cache/SoftRefFilesCacheTestCase.java
 Sun Nov 16 07:26:11 2014
@@ -0,0 +1,57 @@
+/*
+ * 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.vfs2.cache;
+
+import java.io.File;
+
+import junit.framework.Test;
+
+import org.apache.commons.AbstractVfsTestCase;
+import org.apache.commons.vfs2.FileObject;
+import org.apache.commons.vfs2.FileSystemManager;
+import org.apache.commons.vfs2.FilesCache;
+import org.apache.commons.vfs2.test.AbstractProviderTestConfig;
+import org.apache.commons.vfs2.test.CacheTestSuite;
+import org.apache.commons.vfs2.test.ProviderTestConfig;
+
+/**
+ * Tests the {@link SoftRefFilesCache}.
+ */
+public class SoftRefFilesCacheTestCase
+    extends AbstractProviderTestConfig
+    implements ProviderTestConfig
+{
+    public static Test suite() throws Exception
+    {
+        final CacheTestSuite suite = new CacheTestSuite(new 
SoftRefFilesCacheTestCase());
+        suite.addTests(SoftRefFilesCacheTests.class);
+        return suite;
+    }
+
+    @Override
+    public FilesCache getFilesCache()
+    {
+        return new SoftRefFilesCache();
+    }
+
+    @Override
+    public FileObject getBaseTestFolder(final FileSystemManager manager) 
throws Exception
+    {
+        final File testDir = AbstractVfsTestCase.getTestDirectory();
+        return manager.toFileObject(testDir);
+    }
+}

Added: 
commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/cache/SoftRefFilesCacheTests.java
URL: 
http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/cache/SoftRefFilesCacheTests.java?rev=1639974&view=auto
==============================================================================
--- 
commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/cache/SoftRefFilesCacheTests.java
 (added)
+++ 
commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/cache/SoftRefFilesCacheTests.java
 Sun Nov 16 07:26:11 2014
@@ -0,0 +1,42 @@
+/*
+ * 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.vfs2.cache;
+
+import org.apache.commons.vfs2.FileObject;
+
+/**
+ * Tests for {@link SoftRefFilesCache} used by {@link 
SoftRefFilesCacheTestCase}.
+ */
+public class SoftRefFilesCacheTests extends FilesCacheTestsBase
+{
+    public void testFilesCache() throws Exception
+    {
+        final FileObject scratchFolder = getWriteFolder();
+
+        final FileObject dir1 = scratchFolder.resolveFile("dir1");
+        final FileObject dir1_2 = scratchFolder.resolveFile("dir1");
+
+        // since both are still referenced they are not purged
+        assertSame(dir1, dir1_2);
+    }
+
+    public void testClass()
+    {
+       assertTrue(getManager().getFilesCache() instanceof SoftRefFilesCache);
+    }
+
+}

Added: 
commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/cache/WeakRefFilesCacheTestCase.java
URL: 
http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/cache/WeakRefFilesCacheTestCase.java?rev=1639974&view=auto
==============================================================================
--- 
commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/cache/WeakRefFilesCacheTestCase.java
 (added)
+++ 
commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/cache/WeakRefFilesCacheTestCase.java
 Sun Nov 16 07:26:11 2014
@@ -0,0 +1,57 @@
+/*
+ * 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.vfs2.cache;
+
+import java.io.File;
+
+import junit.framework.Test;
+
+import org.apache.commons.AbstractVfsTestCase;
+import org.apache.commons.vfs2.FileObject;
+import org.apache.commons.vfs2.FileSystemManager;
+import org.apache.commons.vfs2.FilesCache;
+import org.apache.commons.vfs2.test.AbstractProviderTestConfig;
+import org.apache.commons.vfs2.test.CacheTestSuite;
+import org.apache.commons.vfs2.test.ProviderTestConfig;
+
+/**
+ * Tests the {@link WeakRefFilesCache}.
+ */
+public class WeakRefFilesCacheTestCase
+    extends AbstractProviderTestConfig
+    implements ProviderTestConfig
+{
+    public static Test suite() throws Exception
+    {
+        final CacheTestSuite suite = new CacheTestSuite(new 
WeakRefFilesCacheTestCase());
+        suite.addTests(WeakRefFilesCacheTests.class);
+        return suite;
+    }
+
+    @Override
+    public FilesCache getFilesCache()
+    {
+        return new WeakRefFilesCache();
+    }
+
+    @Override
+    public FileObject getBaseTestFolder(final FileSystemManager manager) 
throws Exception
+    {
+        final File testDir = AbstractVfsTestCase.getTestDirectory();
+        return manager.toFileObject(testDir);
+    }
+}

Added: 
commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/cache/WeakRefFilesCacheTests.java
URL: 
http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/cache/WeakRefFilesCacheTests.java?rev=1639974&view=auto
==============================================================================
--- 
commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/cache/WeakRefFilesCacheTests.java
 (added)
+++ 
commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/cache/WeakRefFilesCacheTests.java
 Sun Nov 16 07:26:11 2014
@@ -0,0 +1,41 @@
+/*
+ * 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.vfs2.cache;
+
+import org.apache.commons.vfs2.FileObject;
+
+/**
+ * Tests for {@link WeakRefFilesCache} used by {@link 
WeakRefFilesCacheTestCase}.
+ */
+public class WeakRefFilesCacheTests extends FilesCacheTestsBase
+{
+    public void testFilesCache() throws Exception
+    {
+        final FileObject scratchFolder = getWriteFolder();
+
+        final FileObject dir1 = scratchFolder.resolveFile("dir1");
+        final FileObject dir1_2 = scratchFolder.resolveFile("dir1");
+
+        // since both are still referenced they are not purged
+        assertSame(dir1, dir1_2);
+    }
+
+    public void testClass()
+    {
+       assertTrue(getManager().getFilesCache() instanceof WeakRefFilesCache);
+    }
+}


Reply via email to