[jboss-cvs] JBossAS SVN: r90787 - in projects/vfs/branches/dml-zip-rework/src: test/java/org/jboss/test/virtual/support and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Jul 2 16:21:23 EDT 2009
Author: david.lloyd at jboss.com
Date: 2009-07-02 16:21:22 -0400 (Thu, 02 Jul 2009)
New Revision: 90787
Added:
projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/virtual/support/MockFileSystem.java
Removed:
projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/LongestMatchComparator.java
projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/virtual/support/OperatingSystem.java
projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/virtual/test/AssembledContextTestCase.java
projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/virtual/test/CombinedVFSCacheTestCase.java
Modified:
projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/VFS.java
projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/VirtualFile.java
projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/virtual/test/AbstractMockVFSTest.java
projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/virtual/test/AbstractVFSTest.java
projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/virtual/test/CopyJARCacheUnitTestCase.java
projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/virtual/test/VFSAllTestSuite.java
projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/virtual/test/VFSUnitTestCase.java
Log:
Chip away at some tests; fix (?) the visitor situation; switch to a COW-hashmap approach for locating mount points (so much for the cool skiplistmap idea)
Deleted: projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/LongestMatchComparator.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/LongestMatchComparator.java 2009-07-02 20:11:29 UTC (rev 90786)
+++ projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/LongestMatchComparator.java 2009-07-02 20:21:22 UTC (rev 90787)
@@ -1,108 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2009, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.virtual;
-
-import java.util.Comparator;
-import java.util.Iterator;
-import java.io.Serializable;
-
-/**
- * A comparator which sorts longer values before their shorter initial sublists.
- *
- * @param <E> the element type
- * @param <C> the collection type
- */
-final class LongestMatchComparator<E, C extends Iterable<E>> implements Comparator<C>, Serializable
-{
- private static final long serialVersionUID = 954089122568817323L;
-
- private final Comparator<E> comparator;
-
- private LongestMatchComparator(Comparator<E> comparator)
- {
- this.comparator = comparator;
- }
-
- /**
- * Create a new instance.
- *
- * @param comparator the element comparator
- * @param <E> the element type
- * @param <C> the collection type
- * @return the new collection comparator
- */
- static <E, C extends Iterable<E>> Comparator<C> create(Comparator<E> comparator) {
- return new LongestMatchComparator<E, C>(comparator);
- }
-
- /**
- * Create a new instance which uses the native ordering of the element type.
- *
- * @param <E> the element type
- * @param <C> the collection type
- * @return the new collection comparator
- */
- static <E extends Comparable<? super E>, C extends Iterable<E>> Comparator<C> create() {
- return new LongestMatchComparator<E, C>(NativeComparator.<E>getInstance());
- }
-
- /** {@inheritDoc} */
- public int compare(C o1, C o2)
- {
- final Comparator<E> comparator = this.comparator;
- final Iterator<E> i1 = o1.iterator();
- final Iterator<E> i2 = o2.iterator();
- while (i1.hasNext() && i2.hasNext()) {
- final E t1 = i1.next();
- final E t2 = i2.next();
- final int c = comparator.compare(t1, t2);
- if (c != 0) {
- return c;
- }
- }
- return i1.hasNext() ? -1 : i2.hasNext() ? 1 : 0;
- }
-
- /**
- * A native-order comparator.
- *
- * @param <E>
- */
- private static final class NativeComparator<E extends Comparable<? super E>> implements Comparator<E>, Serializable
- {
- private static final long serialVersionUID = -4198283451912738802L;
-
- /** {@inheritDoc} */
- public int compare(E o1, E o2)
- {
- return o1.compareTo(o2);
- }
-
- private static final NativeComparator INSTANCE = new NativeComparator();
-
- @SuppressWarnings({ "unchecked" })
- private static <E extends Comparable<? super E>> Comparator<E> getInstance() {
- return INSTANCE;
- }
- }
-}
Modified: projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/VFS.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/VFS.java 2009-07-02 20:11:29 UTC (rev 90786)
+++ projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/VFS.java 2009-07-02 20:21:22 UTC (rev 90787)
@@ -26,10 +26,11 @@
import java.util.List;
import java.util.Collections;
import java.util.Map;
+import java.util.Iterator;
+import java.util.HashMap;
+import java.util.ArrayList;
import org.jboss.logging.Logger;
-import org.jboss.util.collection.ConcurrentNavigableMap;
-import org.jboss.util.collection.ConcurrentSkipListMap;
import org.jboss.virtual.spi.RealFileSystem;
import org.jboss.virtual.spi.FileSystem;
import org.jboss.virtual.plugins.vfs.helpers.PathTokenizer;
@@ -47,7 +48,7 @@
/** The log */
private static final Logger log = Logger.getLogger(VFS.class);
- private final ConcurrentNavigableMap<List<String>, Mount> activeMounts = new ConcurrentSkipListMap<List<String>, Mount>(LongestMatchComparator.<String, List<String>>create());
+ private final MountNode rootMountNode = new MountNode();
private final VirtualFile rootVirtualFile;
private static VFS instance = new VFS();
@@ -73,7 +74,7 @@
{
// By default, there's a root mount which points to the "real" FS
final List<String> emptyList = Collections.<String>emptyList();
- activeMounts.put(emptyList, new Mount(RealFileSystem.ROOT_INSTANCE, emptyList));
+ rootMountNode.mount = new Mount(rootMountNode, RealFileSystem.ROOT_INSTANCE, emptyList);
//noinspection ThisEscapedInObjectConstruction
rootVirtualFile = new VirtualFile(this, emptyList, "");
}
@@ -92,7 +93,7 @@
}
else if (pkgs.contains("org.jboss.virtual.protocol") == false)
{
- pkgs += "|org.jboss.virtual.protocol";
+ pkgs = "org.jboss.virtual.protocol|" + pkgs;
System.setProperty("java.protocol.handler.pkgs", pkgs);
}
// org.jboss.virtual.plugins.context.VfsArchiveBrowserFactory factory = org.jboss.virtual.plugins.context.VfsArchiveBrowserFactory.INSTANCE;
@@ -114,12 +115,41 @@
*/
public Closeable mount(String mountPoint, FileSystem fileSystem) throws IOException {
final List<String> realMountPoint = PathTokenizer.applySpecialPaths(PathTokenizer.getTokens(mountPoint));
- final Mount mount = new Mount(fileSystem, realMountPoint);
- if (activeMounts.putIfAbsent(realMountPoint, mount) == null) {
- throw new IOException("Filsystem already mounted at mount point \"" + mountPoint + "\"");
+ MountNode mountNode = rootMountNode;
+ for (String seg : realMountPoint)
+ {
+ synchronized (mountNode) {
+ Map<String, MountNode> childMap = mountNode.nodeMap;
+ MountNode subNode;
+ if (childMap == null) {
+ childMap = new HashMap<String, MountNode>();
+ subNode = new MountNode();
+ childMap.put(seg, subNode);
+ mountNode.nodeMap = childMap;
+ mountNode = subNode;
+ } else {
+ subNode = childMap.get(seg);
+ if (subNode != null) {
+ mountNode = subNode;
+ } else {
+ childMap = new HashMap<String, MountNode>(childMap);
+ subNode = new MountNode();
+ childMap.put(seg, subNode);
+ mountNode.nodeMap = childMap;
+ mountNode = subNode;
+ }
+ }
+ }
}
- log.debugf("Created mount %s for %s on %s at mount point '%s'", mount, fileSystem, this, mountPoint);
- return mount;
+ synchronized (mountNode) {
+ if (mountNode.mount != null) {
+ throw new IOException("Filsystem already mounted at mount point \"" + mountPoint + "\"");
+ }
+ final Mount mount = new Mount(mountNode, fileSystem, realMountPoint);
+ mountNode.mount = mount;
+ log.debugf("Created mount %s for %s on %s at mount point '%s'", mount, fileSystem, this, mountPoint);
+ return mount;
+ }
}
/**
@@ -238,29 +268,79 @@
*/
Mount getMount(List<String> pathTokens)
{
- final Map.Entry<List<String>, Mount> entry = activeMounts.floorEntry(pathTokens);
- return entry.getValue();
+ MountNode mountNode = rootMountNode;
+ Mount mount = mountNode.mount;
+ for (String pathToken : pathTokens)
+ {
+ final Map<String, MountNode> childMap = mountNode.nodeMap;
+ if (childMap != null) {
+ mountNode = childMap.get(pathToken);
+ final Mount subMount = mountNode.mount;
+ if (subMount != null) {
+ mount = subMount;
+ }
+ } else {
+ break;
+ }
+ }
+ return mount;
}
/**
+ * Get all immediate submounts for a path.
+ *
+ * @param tokens the path tokens
+ * @return the collection of present mount (simple) names
+ */
+ Iterator<String> getSubmounts(List<String> tokens)
+ {
+ MountNode mountNode = rootMountNode;
+ for (String pathToken : tokens)
+ {
+ final Map<String, MountNode> childMap = mountNode.nodeMap;
+ if (childMap != null) {
+ mountNode = childMap.get(pathToken);
+ } else {
+ return Collections.<String>emptyList().iterator();
+ }
+ }
+ final List<String> list = new ArrayList<String>();
+ for (Map.Entry<String, MountNode> entry : mountNode.nodeMap.entrySet())
+ {
+ final MountNode subNode = entry.getValue();
+ if (subNode.mount != null) {
+ list.add(entry.getKey());
+ }
+ }
+ return list.iterator();
+ }
+
+ /**
* The mount representation. This instance represents a binding between a position in the virtual filesystem and
* the backing filesystem implementation; the same {@code FileSystem} may be mounted in more than one place, however
* only one {@code FileSystem} may be bound to a specific path at a time.
*/
final class Mount implements Closeable {
+ private final MountNode mountNode;
private final FileSystem fileSystem;
private final List<String> realMountPoint;
- private Mount(FileSystem fileSystem, List<String> realMountPoint)
+ private Mount(MountNode mountNode, FileSystem fileSystem, List<String> realMountPoint)
{
+ this.mountNode = mountNode;
this.fileSystem = fileSystem;
this.realMountPoint = realMountPoint;
}
public void close() throws IOException
{
- if (activeMounts.remove(realMountPoint, this)) {
- log.debugf("Unmounted %s for %s on %s", this, fileSystem, this);
+ final MountNode mountNode = this.mountNode;
+ synchronized (mountNode) {
+ if (mountNode.mount == this) {
+ mountNode.mount = null;
+ log.debugf("Unmounted %s for %s on %s", this, fileSystem, this);
+
+ }
}
}
@@ -274,4 +354,20 @@
return realMountPoint;
}
}
+
+ /**
+ * A mount point node. These nodes form a tree of possible mount points.
+ */
+ private static final class MountNode {
+
+ /**
+ * The immutable node map. Since the map is immutable, changes to this field must be accomplished by replacing
+ * the field value with a new map (copy on write). Modifications to this field are protected by {@code this}.
+ */
+ private volatile Map<String, MountNode> nodeMap;
+ /**
+ * The current mount at this point. Modifications to this field are protected by {@code this}.
+ */
+ private volatile Mount mount;
+ }
}
Modified: projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/VirtualFile.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/VirtualFile.java 2009-07-02 20:11:29 UTC (rev 90786)
+++ projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/VirtualFile.java 2009-07-02 20:21:22 UTC (rev 90787)
@@ -28,6 +28,9 @@
import java.util.Collections;
import java.util.List;
import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.Set;
+import java.util.HashSet;
import org.jboss.virtual.plugins.vfs.helpers.FilterVirtualFileVisitor;
import org.jboss.virtual.plugins.vfs.helpers.MatchAllVirtualFileFilter;
@@ -217,16 +220,40 @@
}
/**
- * Get the children
+ * Get the children. This is the combined list of real children within this directory, as well as virtual
+ * children created by submounts.
*
* @return the children
* @throws IOException for any problem accessing the virtual file system
*/
public List<VirtualFile> getChildren() throws IOException
{
- return getChildren(null);
+ final ArrayList<VirtualFile> list = new ArrayList<VirtualFile>();
+ for (String name : getChildrenNames())
+ {
+ list.add(getChild(name));
+ }
+ return list;
}
+ private Set<String> getChildrenNames() throws IOException
+ {
+ // Add the files physically present
+ final List<String> tokens = this.tokens;
+ final VFS.Mount mount = vfs.getMount(tokens);
+ final Iterator<String> iter = mount.getFileSystem().getDirectoryEntries(tokens.subList(mount.getRealMountPoint().size(), tokens.size()));
+ final Set<String> names = new HashSet<String>();
+ while (iter.hasNext()) {
+ names.add(iter.next());
+ }
+ // Add any mounts that are logically present
+ final Iterator<String> submounts = vfs.getSubmounts(tokens);
+ while (submounts.hasNext()) {
+ names.add(submounts.next());
+ }
+ return names;
+ }
+
/**
* Get the children
*
@@ -293,8 +320,23 @@
*/
public void visit(VirtualFileVisitor visitor) throws IOException
{
- if (! isDirectory() == false)
- getVFS().visit(this, visitor);
+ final VisitorAttributes visitorAttributes = visitor.getAttributes();
+ if (isDirectory())
+ {
+ if (! visitorAttributes.isLeavesOnly())
+ {
+ visitor.visit(this);
+ }
+ if (visitorAttributes.isRecurse(this))
+ {
+ for (VirtualFile virtualFile : getChildren())
+ {
+ virtualFile.visit(visitor);
+ }
+ }
+ } else {
+ visitor.visit(this);
+ }
}
/**
Added: projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/virtual/support/MockFileSystem.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/virtual/support/MockFileSystem.java (rev 0)
+++ projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/virtual/support/MockFileSystem.java 2009-07-02 20:21:22 UTC (rev 90787)
@@ -0,0 +1,84 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.test.virtual.support;
+
+import org.jboss.virtual.spi.FileSystem;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.List;
+import java.util.Iterator;
+
+public final class MockFileSystem implements FileSystem
+{
+
+ public File getFile(List<String> pathComponents) throws IOException
+ {
+ return null;
+ }
+
+ public InputStream openInputStream(List<String> pathComponents) throws IOException
+ {
+ return null;
+ }
+
+ public boolean isReadOnly()
+ {
+ return false;
+ }
+
+ public boolean delete(List<String> pathComponents) throws IOException
+ {
+ return false;
+ }
+
+ public long getSize(List<String> pathComponents) throws IOException
+ {
+ return 0;
+ }
+
+ public long getLastModified(List<String> pathComponents) throws IOException
+ {
+ return 0;
+ }
+
+ public boolean exists(List<String> pathComponents) throws IOException
+ {
+ return false;
+ }
+
+ public boolean isDirectory(List<String> pathComponents) throws IOException
+ {
+ return false;
+ }
+
+ public Iterator<String> getDirectoryEntries(List<String> directoryPathComponents) throws IOException
+ {
+ return null;
+ }
+
+ public void close() throws IOException
+ {
+ }
+}
Deleted: projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/virtual/support/OperatingSystem.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/virtual/support/OperatingSystem.java 2009-07-02 20:11:29 UTC (rev 90786)
+++ projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/virtual/support/OperatingSystem.java 2009-07-02 20:21:22 UTC (rev 90787)
@@ -1,55 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2006, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.test.virtual.support;
-
-/**
- * OS.
- *
- * TODO - remove together with OSAwareTest
- *
- * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
- */
-public enum OperatingSystem
-{
- LINUX("linux"),
- MAC("mac"),
- WINDOWS("windows"),
- OTHER(null);
-
- private String name;
-
- OperatingSystem(String name)
- {
- this.name = name;
- }
-
- public static OperatingSystem matchOS(String osName)
- {
- OperatingSystem[] systems = values();
- for(int i = 0; i < systems.length - 1; i++)
- {
- if (osName.toLowerCase().contains(systems[i].name))
- return systems[i];
- }
- return OTHER;
- }
-}
Modified: projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/virtual/test/AbstractMockVFSTest.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/virtual/test/AbstractMockVFSTest.java 2009-07-02 20:11:29 UTC (rev 90786)
+++ projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/virtual/test/AbstractMockVFSTest.java 2009-07-02 20:21:22 UTC (rev 90787)
@@ -58,13 +58,11 @@
protected void setUp() throws Exception
{
super.setUp();
- VFSContextFactoryLocator.registerFactory(mockVFSContextFactory);
}
protected void tearDown() throws Exception
{
mockVFSContextFactory.reset();
- VFSContextFactoryLocator.unregisterFactory(mockVFSContextFactory);
super.tearDown();
}
Modified: projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/virtual/test/AbstractVFSTest.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/virtual/test/AbstractVFSTest.java 2009-07-02 20:11:29 UTC (rev 90786)
+++ projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/virtual/test/AbstractVFSTest.java 2009-07-02 20:21:22 UTC (rev 90787)
@@ -22,15 +22,9 @@
package org.jboss.test.virtual.test;
import java.net.URL;
-import java.util.Map;
-import java.lang.reflect.Field;
import junit.framework.AssertionFailedError;
import org.jboss.test.BaseTestCase;
-import org.jboss.test.virtual.support.FileOAContextFactory;
-import org.jboss.test.virtual.support.OptionsAwareURI;
-import org.jboss.virtual.VFSUtils;
-import org.jboss.virtual.VirtualFile;
/**
* AbstractVFSTest.
@@ -40,81 +34,18 @@
*/
public abstract class AbstractVFSTest extends BaseTestCase
{
- private static final VFSContextFactory fileFactory = new FileOAContextFactory();
-
- private boolean forceCopy;
- private boolean forceNoReaper;
-
public AbstractVFSTest(String name)
{
super(name);
}
- public AbstractVFSTest(String name, boolean forceCopy)
- {
- super(name);
- this.forceCopy = forceCopy;
- }
-
- public AbstractVFSTest(String name, boolean forceCopy, boolean forceNoReaper)
- {
- super(name);
- this.forceCopy = forceCopy;
- this.forceNoReaper = forceNoReaper;
- }
-
- @SuppressWarnings("unchecked")
- protected static Map<String, VFSContextFactory> getFactoryByProtocol()
- {
- try
- {
- Field field = VFSContextFactoryLocator.class.getDeclaredField("factoryByProtocol");
- field.setAccessible(true);
- return (Map<String, VFSContextFactory>) field.get(null);
- }
- catch (Exception e)
- {
- throw new RuntimeException(e);
- }
- }
-
protected void setUp() throws Exception
{
super.setUp();
-
-/*
- // LRU
- System.setProperty(VFSUtils.VFS_CACHE_KEY, LRUVFSCache.class.getName());
- System.setProperty(VFSUtils.VFS_CACHE_KEY + ".LRUPolicyCaching.min", "2");
- System.setProperty(VFSUtils.VFS_CACHE_KEY + ".LRUPolicyCaching.max", "100");
-*/
-/*
- // Timed
- System.setProperty(VFSUtils.VFS_CACHE_KEY, TimedVFSCache.class.getName());
- System.setProperty(VFSUtils.VFS_CACHE_KEY + ".TimedPolicyCaching.lifetime", "60");
-*/
-
- VFSContextFactoryLocator.registerFactory(fileFactory);
-
- getLog().info("Force copy: " + forceCopy);
- if (forceCopy)
- OptionsAwareURI.set(OptionsAwareURI.Copy);
-
- if (forceNoReaper)
- OptionsAwareURI.set(OptionsAwareURI.NoReaper);
}
protected void tearDown() throws Exception
{
- VFSContextFactoryLocator.unregisterFactory(fileFactory);
-
- if (forceCopy)
- OptionsAwareURI.clear(OptionsAwareURI.Copy);
-
- if (forceNoReaper)
- OptionsAwareURI.clear(OptionsAwareURI.NoReaper);
-
- super.tearDown();
}
// TODO move to AbstractTestCase
@@ -144,16 +75,4 @@
getLog().debug("Got expected " + expected.getName() + "(" + throwable + ")");
}
}
-
- /**
- * Do we force copy handling of jars.
- *
- * @param file the virtual file
- * @return true if we force copy handling
- */
- protected boolean isForceCopyEnabled(VirtualFile file)
- {
- boolean systemProperty = Boolean.parseBoolean(System.getProperty(VFSUtils.FORCE_COPY_KEY, "false"));
- return systemProperty || VFSUtils.getOption(file, VFSUtils.FORCE_COPY_KEY) != null;
- }
}
Deleted: projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/virtual/test/AssembledContextTestCase.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/virtual/test/AssembledContextTestCase.java 2009-07-02 20:11:29 UTC (rev 90786)
+++ projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/virtual/test/AssembledContextTestCase.java 2009-07-02 20:21:22 UTC (rev 90787)
@@ -1,277 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2006, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.test.virtual.test;
-
-import java.net.URL;
-import java.util.List;
-import java.util.regex.Pattern;
-
-import junit.framework.Test;
-import org.jboss.virtual.VirtualFile;
-
-/**
- * comment
- *
- * @author <a href="bill at jboss.com">Bill Burke</a>
- * @author Scott.Stark at jboss.org
- * @version $Revision: 1.1 $
- */
-public class AssembledContextTestCase extends AbstractVFSTest
-{
- public AssembledContextTestCase(String name)
- {
- super(name);
- }
-
- public static Test suite()
- {
- return suite(AssembledContextTestCase.class);
- }
-
- public void testRegex()
- {
- String[] files = {".java", "x.java", "FooBar.java"};
- String expression = "*.java";
- Pattern p = AssembledDirectory.getPattern(expression);
- System.out.println("pattern: " + p.pattern());
- for (String file : files)
- {
- assertTrue(p.matcher(file).matches());
- }
- System.out.println("no matches");
- p = AssembledDirectory.getPattern("?.java");
- assertTrue(p.matcher("x.java").matches());
- assertFalse(p.matcher("xyz.java").matches());
- assertFalse(p.matcher(".java").matches());
-
- p = AssembledDirectory.getPattern("x?z*.java");
- assertTrue(p.matcher("xyz.java").matches());
- assertTrue(p.matcher("xyzasdfasdf.java").matches());
- assertFalse(p.matcher("xyzadasdfasdf").matches());
- assertFalse(p.matcher("xzadasdfasdf").matches());
- System.out.println("done it");
- }
-
- public void testAntMatching()
- {
- String file;
- String exp;
- file = "xabc/foobar/test.java";
- exp = "?abc/*/*.java";
- assertTrue(AssembledDirectory.antMatch(file, exp));
- file = "abc/foobar/test.java";
- assertFalse(AssembledDirectory.antMatch(file, exp));
- file = "xabc/x/test.xml";
- assertFalse(AssembledDirectory.antMatch(file, exp));
- file = "xabc/test.java";
- assertFalse(AssembledDirectory.antMatch(file, exp));
-
-
- exp = "org/jboss/Test.java";
- file = "org/jboss/Test.java";
- assertTrue(AssembledDirectory.antMatch(file, exp));
-
- exp = "org/jboss/Test.java";
- file = "org/wrong.java";
- assertFalse(AssembledDirectory.antMatch(file, exp));
-
- exp = "test/**";
- file = "test/x.java";
- assertTrue(AssembledDirectory.antMatch(file, exp));
- file = "test/foo/bar/x.java";
- assertTrue(AssembledDirectory.antMatch(file, exp));
- file = "x.java";
- assertFalse(AssembledDirectory.antMatch(file, exp));
-
- exp = "**/CVS/*";
- file = "CVS/Repository";
- assertTrue(AssembledDirectory.antMatch(file, exp));
- file = "org/apache/CVS/Entries";
- assertTrue(AssembledDirectory.antMatch(file, exp));
- file = "org/apache/jakarta/tools/ant/CVS/Entries";
- assertTrue(AssembledDirectory.antMatch(file, exp));
- file = "org/apache/CVS/foo/bar/Entries";
- assertFalse(AssembledDirectory.antMatch(file, exp));
-
- exp = "org/apache/jakarta/**";
- file ="org/apache/jakarta/tools/ant/docs/index.html";
- assertTrue(AssembledDirectory.antMatch(file, exp));
- file ="org/apache/jakarta/test.xml";
- assertTrue(AssembledDirectory.antMatch(file, exp));
- file = "org/apache/xyz.java";
- assertFalse(AssembledDirectory.antMatch(file, exp));
-
- exp = "org/apache/**/CVS/*";
- file ="org/apache/CVS/Entries";
- assertTrue(AssembledDirectory.antMatch(file, exp));
- file ="org/apache/jakarta/tools/ant/CVS/Entries";
- assertTrue(AssembledDirectory.antMatch(file, exp));
- file = "org/apache/CVS/foo/bar/Entries";
- assertFalse(AssembledDirectory.antMatch(file, exp));
- file = "org/apache/nada/foo/bar/Entries";
- assertFalse(AssembledDirectory.antMatch(file, exp));
-
- exp = "**/test/**";
- file = "test/x.java";
- assertTrue(AssembledDirectory.antMatch(file, exp));
- file = "test/bar/x.java";
- assertTrue(AssembledDirectory.antMatch(file, exp));
- file = "test/bar/foo/x.java";
- assertTrue(AssembledDirectory.antMatch(file, exp));
- file = "foo/test/x.java";
- assertTrue(AssembledDirectory.antMatch(file, exp));
- file = "foo/bar/test/x.java";
- assertTrue(AssembledDirectory.antMatch(file, exp));
- file = "foo/test/bar/x.java";
- assertTrue(AssembledDirectory.antMatch(file, exp));
- file = "foo/bar/test/bar/foo/x.java";
- assertTrue(AssembledDirectory.antMatch(file, exp));
- file = "foo/bar/flah.java";
- assertFalse(AssembledDirectory.antMatch(file, exp));
- }
-
- public void testAddClass() throws Exception
- {
- AssembledDirectory directory = AssembledContextFactory.getInstance().create("foo.jar");
- directory.addClass(VirtualFile.class);
-
-
- List<VirtualFile> children = directory.getChildren();
- assertEquals(children.size(), 1);
- VirtualFile curr = children.get(0);
- System.out.println("test org/");
- assertEquals("org", curr.getName());
-
- System.out.println("test org/jboss");
- children = curr.getChildren();
- assertEquals(children.size(), 1);
- curr = children.get(0);
- assertEquals("jboss", curr.getName());
-
- System.out.println("test org/jboss/virtual");
- children = curr.getChildren();
- assertEquals(children.size(), 1);
- curr = children.get(0);
- assertEquals("virtual", curr.getName());
- children = curr.getChildren();
- boolean found;
- found = false;
- for (VirtualFile child: children)
- {
- if (child.getName().equals("VirtualFile.class"))
- {
- found = true;
- assertEquals("org/jboss/virtual/VirtualFile.class", child.getPathName());
- break;
- }
- }
- assertTrue("VirtualFile.class was found", found);
- }
-
- public void testAddResources() throws Exception
- {
- // Find test.classes.url location for vfs/links/war1.vfslink.properties
- URL classesURL = getClass().getProtectionDomain().getCodeSource().getLocation();
- assertNotNull("classesURL", classesURL);
- System.setProperty("test.classes.url", classesURL.toString());
- URL libURL = super.getResource("/vfs/sundry/jar");
- assertNotNull("libURL", libURL);
- System.setProperty("test.lib.url", libURL.toString());
-
- AssembledDirectory directory = AssembledContextFactory.getInstance().create("foo.jar");
- String[] includes = {"org/jboss/virtual/*.class", "org/jboss/virtual/**/context/jar/*.class"};
- String[] excludes = {"**/Nested*"};
- directory.addResources("org/jboss/virtual/VirtualFile.class", includes, excludes, Thread.currentThread().getContextClassLoader());
- List<VirtualFile> children = directory.getChildren();
- assertEquals(children.size(), 1);
- VirtualFile curr = children.get(0);
- System.out.println("test org/");
- assertEquals("org", curr.getName());
-
- System.out.println("test org/jboss");
- children = curr.getChildren();
- assertEquals(children.size(), 1);
- curr = children.get(0);
- assertEquals("jboss", curr.getName());
-
- System.out.println("test org/jboss/virtual");
- children = curr.getChildren();
- assertEquals(children.size(), 1);
- curr = children.get(0);
- assertEquals("virtual", curr.getName());
- children = curr.getChildren();
- boolean found;
- found = false;
- for (VirtualFile child: children)
- {
- if (child.getName().equals("VFS.class"))
- {
- found = true;
- break;
- }
- }
- assertTrue("VFS.class was found", found);
-
- found = false;
- for (VirtualFile child: children)
- {
- if (child.getName().equals("VirtualFile.class"))
- {
- found = true;
- assertEquals("org/jboss/virtual/VirtualFile.class", child.getPathName());
- break;
- }
- }
- assertTrue("VirtualFile.class was found", found);
-
- found = false;
- for (VirtualFile child: children)
- {
- if (child.getName().equals("plugins"))
- {
- found = true;
- break;
- }
- }
- assertTrue("plugins/", found);
-
- System.out.println("Test org/jboss/virtual/plugins/context/jar");
- VirtualFile jar = directory.findChild("org/jboss/virtual/plugins/context/jar");
- assertNotNull(jar);
- assertEquals("jar", jar.getName());
-
- children = jar.getChildren();
- for (VirtualFile child: children)
- {
- if (child.getName().startsWith("Nested")) throw new RuntimeException("did not exclude propertly");
- }
- AssembledContextFactory.getInstance().remove(directory);
- }
-
- public void testMkDir() throws Exception
- {
- AssembledDirectory directory = AssembledContextFactory.getInstance().create("foo.jar");
- directory.mkdir("META-INF");
- assertNotNull(directory.findChild("META-INF"));
-
- }
-}
Deleted: projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/virtual/test/CombinedVFSCacheTestCase.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/virtual/test/CombinedVFSCacheTestCase.java 2009-07-02 20:11:29 UTC (rev 90786)
+++ projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/virtual/test/CombinedVFSCacheTestCase.java 2009-07-02 20:21:22 UTC (rev 90787)
@@ -1,118 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2006, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.test.virtual.test;
-
-import java.net.URL;
-import java.util.Collections;
-import java.util.Map;
-
-import junit.framework.Test;
-
-/**
- * Combined VFSCache Test.
- *
- * @author <a href="ales.justin at jboss.com">Ales Justin</a>
- */
-public class CombinedVFSCacheTestCase extends VFSCacheTest
-{
- public CombinedVFSCacheTestCase(String name)
- {
- super(name);
- }
-
- public static Test suite()
- {
- return suite(CombinedVFSCacheTestCase.class);
- }
-
- @Override
- protected void configureCache(VFSCache cache) throws Exception
- {
- if (cache instanceof CombinedVFSCache)
- {
- CombinedVFSCache cvc = CombinedVFSCache.class.cast(cache);
-
- URL url = getResource("/vfs/test/nested");
- Map<URL, ExceptionHandler> map = Collections.singletonMap(url, null);
- cvc.setPermanentRoots(map);
-
- IterableTimedVFSCache realCache = new IterableTimedVFSCache(5);
- realCache.start();
- cvc.setRealCache(realCache);
-
- cvc.create();
- }
- }
-
- @Override
- protected void stopCache(VFSCache cache)
- {
- if (cache != null)
- {
- if (cache instanceof CombinedWrapperVFSCache)
- {
- CombinedWrapperVFSCache cwvc = (CombinedWrapperVFSCache)cache;
- cwvc.getTemp().stop();
- }
- cache.stop();
- }
- }
-
- @Override
- protected Class<? extends VFSCache> getCacheClass()
- {
- return CombinedVFSCache.class;
- }
-
- protected CombinedVFSCache createCache()
- {
- return new CombinedWrapperVFSCache();
- }
-
- protected Map<Object, Object> getMap()
- {
- return null;
- }
-
- protected void testCachedContexts(Iterable<VFSContext> iter)
- {
- VFSContext context = iter.iterator().next();
- assertNotNull(context);
- }
-
- private class CombinedWrapperVFSCache extends CombinedVFSCache
- {
- private VFSCache temp;
-
- @Override
- public void setRealCache(VFSCache realCache)
- {
- super.setRealCache(realCache);
- temp = realCache;
- }
-
- public VFSCache getTemp()
- {
- return temp;
- }
- }
-}
\ No newline at end of file
Modified: projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/virtual/test/CopyJARCacheUnitTestCase.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/virtual/test/CopyJARCacheUnitTestCase.java 2009-07-02 20:11:29 UTC (rev 90786)
+++ projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/virtual/test/CopyJARCacheUnitTestCase.java 2009-07-02 20:21:22 UTC (rev 90787)
@@ -21,18 +21,7 @@
*/
package org.jboss.test.virtual.test;
-import java.io.BufferedOutputStream;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.util.jar.Attributes;
-import java.util.jar.JarFile;
-import java.util.jar.JarOutputStream;
-import java.util.jar.Manifest;
-
import junit.framework.Test;
-import junit.framework.TestSuite;
-import org.jboss.virtual.VFS;
-import org.jboss.virtual.VirtualFile;
/**
* Test the caching strategy of VFS with jar files.
Modified: projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/virtual/test/VFSAllTestSuite.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/virtual/test/VFSAllTestSuite.java 2009-07-02 20:11:29 UTC (rev 90786)
+++ projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/virtual/test/VFSAllTestSuite.java 2009-07-02 20:21:22 UTC (rev 90787)
@@ -69,7 +69,6 @@
suite.addTest(ZipEntryVFSContextUnitTestCase.suite());
suite.addTest(JarOverrideTestCase.suite());
// contexts
- suite.addTest(AssembledContextTestCase.suite());
suite.addTest(MemoryTestCase.suite());
suite.addTest(SundryVFSUnitTestCase.suite());
// options / policy / path
@@ -93,7 +92,6 @@
suite.addTest(IterableTimedCacheTestCase.suite());
suite.addTest(SoftRefCacheTestCase.suite());
suite.addTest(WeakRefCacheTestCase.suite());
- suite.addTest(CombinedVFSCacheTestCase.suite());
// exception handler
suite.addTest(ExceptionHandlerTestCase.suite());
// operations
Modified: projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/virtual/test/VFSUnitTestCase.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/virtual/test/VFSUnitTestCase.java 2009-07-02 20:11:29 UTC (rev 90786)
+++ projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/virtual/test/VFSUnitTestCase.java 2009-07-02 20:21:22 UTC (rev 90787)
@@ -21,22 +21,11 @@
*/
package org.jboss.test.virtual.test;
-import java.io.IOException;
-import java.net.URI;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.List;
-
import junit.framework.Test;
import junit.framework.TestSuite;
-import org.jboss.test.virtual.support.MockURLStreamHandler;
-import org.jboss.test.virtual.support.MockVFSContext;
-import org.jboss.test.virtual.support.MockVirtualFileFilter;
import org.jboss.virtual.VFS;
import org.jboss.virtual.VirtualFile;
-import org.jboss.virtual.VFSUtils;
-import org.jboss.virtual.plugins.vfs.helpers.FilterVirtualFileVisitor;
/**
* VFSUnitTestCase.
@@ -44,7 +33,7 @@
* @author <a href="adrian at jboss.com">Adrian Brock</a>
* @version $Revision: 1.1 $
*/
-public class VFSUnitTestCase extends AbstractMockVFSTest
+public class VFSUnitTestCase extends AbstractVFSTest
{
public VFSUnitTestCase(String name)
{
@@ -56,1329 +45,34 @@
return new TestSuite(VFSUnitTestCase.class);
}
- public void testVFSOptions() throws Exception
+ public void testVFSInstance() throws Exception
{
- URL url = getResource("/vfs/test");
- VFS vfs = VFS.getVFS(url);
-
- // currently we don't test any vfs root's behavior
-
- VFSUtils.enableCopy(vfs);
- VFSUtils.disableCopy(vfs);
-
- VFSUtils.enableNoReaper(vfs);
- VFSUtils.disableNoReaper(vfs);
-
- VFSUtils.enableCaseSensitive(vfs);
- VFSUtils.disableCaseSensitive(vfs);
- }
-
-
- public void testGetVFSURI() throws Exception
- {
- MockVFSContext context = registerSimpleVFSContext();
- MockVFSContext context2 = registerSimple2VFSContext();
-
- VFS vfs = VFS.getVFS(context.getRootURI());
+ VFS vfs = VFS.getInstance();
assertNotNull(vfs);
- assertEquals(context.getVFS(), vfs);
-
- VFS vfs2 = VFS.getVFS(context2.getRootURI());
- assertNotNull(vfs2);
- assertEquals(context2.getVFS(), vfs2);
}
- public void testGetVFSURINull() throws Exception
+ public void testRootVirtualFile() throws Exception
{
- try
- {
- VFS.getVFS((URI) null);
- fail("Should not be here");
- }
- catch (Throwable t)
- {
- checkThrowable(IllegalArgumentException.class, t);
- }
+ VFS vfs = VFS.getInstance();
+ final VirtualFile virtualFile = vfs.getRootVirtualFile();
+ assertNotNull(virtualFile);
+ assertEquals("", virtualFile.getPathName());
+ assertEquals("", virtualFile.getName());
}
- public void testGetVFSURINoFactory() throws Exception
+ public void testRootVirtualFileParent() throws Exception
{
- try
- {
- URI uri = new URI("doesnotexist:///");
- VFS.getVFS(uri);
- fail("Should not be here");
- }
- catch (Throwable t)
- {
- checkThrowable(IOException.class, t);
- }
+ VFS vfs = VFS.getInstance();
+ final VirtualFile virtualFile = vfs.getRootVirtualFile();
+ assertNull(virtualFile.getParent());
+ assertSame(vfs.getChild(""), virtualFile);
}
- public void testGetVFSURIIOException() throws Exception
- {
- MockVFSContext context = registerSimpleVFSContext();
- mockVFSContextFactory.setIOException("getVFSURI");
- try
- {
- VFS.getVFS(context.getRootURI());
- fail("Should not be here");
- }
- catch (Throwable t)
- {
- checkThrowable(IOException.class, t);
- }
- }
-
- public void testGetVFSURL() throws Exception
+ public void testRootVirtualFileChildParent() throws Exception
{
- MockVFSContext context = registerSimpleVFSContext();
- MockVFSContext context2 = registerSimple2VFSContext();
-
- VFS vfs = VFS.getVFS(context.getRootURL());
- assertNotNull(vfs);
- assertEquals(context.getVFS(), vfs);
-
- VFS vfs2 = VFS.getVFS(context2.getRootURL());
- assertNotNull(vfs2);
- assertEquals(context2.getVFS(), vfs2);
+ VFS vfs = VFS.getInstance();
+ final VirtualFile virtualFile = vfs.getRootVirtualFile();
+ assertSame(vfs.getChild("x").getParent(), virtualFile);
}
-
- public void testGetVFSURLNull() throws Exception
- {
- try
- {
- VFS.getVFS((URL) null);
- fail("Should not be here");
- }
- catch (Throwable t)
- {
- checkThrowable(IllegalArgumentException.class, t);
- }
- }
-
- public void testGetVFSURLNoFactory() throws Exception
- {
- try
- {
- URL url = new URL("doesnotexist", "", 0, "", MockURLStreamHandler.INSTANCE);
- VFS.getVFS(url);
- fail("Should not be here");
- }
- catch (Throwable t)
- {
- checkThrowable(IOException.class, t);
- }
- }
-
- public void testGetVFSURLIOException() throws Exception
- {
- MockVFSContext context = registerSimpleVFSContext();
- mockVFSContextFactory.setIOException("getVFSURL");
-
- try
- {
- VFS.getVFS(context.getRootURL());
- fail("Should not be here");
- }
- catch (Throwable t)
- {
- checkThrowable(IOException.class, t);
- }
- }
-
- public void testGetRootURI() throws Exception
- {
- MockVFSContext context = registerSimpleVFSContextWithChildren();
-
- VirtualFile file = VFS.getRoot(context.getRootURI());
- assertNotNull(file);
- assertEquals(context.getRoot().getVirtualFile(), file);
- }
-
- public void testGetRootURINullURI() throws Exception
- {
- try
- {
- VFS.getRoot((URI) null);
- fail("Should not be here");
- }
- catch (Throwable t)
- {
- checkThrowable(IllegalArgumentException.class, t);
- }
- }
-
- public void testGetRootURINoFactory() throws Exception
- {
- try
- {
- URI uri = new URI("doesnotexist:///");
- VFS.getRoot(uri);
- fail("Should not be here");
- }
- catch (Throwable t)
- {
- checkThrowable(IOException.class, t);
- }
- }
-
- public void testGetRootURIIOExceptionGetVFS() throws Exception
- {
- MockVFSContext context = registerSimpleVFSContextWithChildren();
- mockVFSContextFactory.setIOException("getVFSURI");
-
- try
- {
- VFS.getRoot(context.getRootURI());
- fail("Should not be here");
- }
- catch (Throwable t)
- {
- checkThrowable(IOException.class, t);
- }
- }
-
- public void testGetRootURIIOExceptionGetRoot() throws Exception
- {
- MockVFSContext context = registerSimpleVFSContextWithChildren();
- context.setIOException("getRoot");
-
- try
- {
- VFS.getRoot(context.getRootURI());
- fail("Should not be here");
- }
- catch (Throwable t)
- {
- checkThrowable(IOException.class, t);
- }
- }
-
- public void testGetVirtualFileURIRoot() throws Exception
- {
- MockVFSContext context = registerSimpleVFSContextWithChildren();
-
- VirtualFile file = VFS.getVirtualFile(context.getRootURI(), "");
- assertNotNull(file);
- assertEquals(context.getRoot().getVirtualFile(), file);
- }
-
- public void testGetVirtualFileURIChildren() throws Exception
- {
- MockVFSContext context = registerSimpleVFSContextWithChildren();
- VirtualFile child1 = getChildHandler(context, "child1").getVirtualFile();
- VirtualFile child2 = getChildHandler(context, "child2").getVirtualFile();
- VirtualFile child3 = getChildHandler(context, "child3").getVirtualFile();
-
- VirtualFile file1 = VFS.getVirtualFile(context.getRootURI(), "child1");
- assertNotNull(file1);
- assertEquals(child1, file1);
-
- VirtualFile file2 = VFS.getVirtualFile(context.getRootURI(), "child2");
- assertNotNull(file2);
- assertEquals(child2, file2);
-
- VirtualFile file3 = VFS.getVirtualFile(context.getRootURI(), "child3");
- assertNotNull(file3);
- assertEquals(child3, file3);
- }
-
- public void testGetVirtualFileURINullURI() throws Exception
- {
- try
- {
- VFS.getVirtualFile((URI) null, "");
- fail("Should not be here");
- }
- catch (Throwable t)
- {
- checkThrowable(IllegalArgumentException.class, t);
- }
- }
-
- public void testGetVirtualFileURINullPath() throws Exception
- {
- MockVFSContext context = registerSimpleVFSContextWithChildren();
-
- try
- {
- VFS.getVirtualFile(context.getRootURI(), null);
- fail("Should not be here");
- }
- catch (Throwable t)
- {
- checkThrowable(IllegalArgumentException.class, t);
- }
- }
-
- public void testGetVirtualFileURINoFactory() throws Exception
- {
- try
- {
- URI uri = new URI("doesnotexist:///");
- VFS.getVirtualFile(uri, "");
- fail("Should not be here");
- }
- catch (Throwable t)
- {
- checkThrowable(IOException.class, t);
- }
- }
-
- public void testGetVirtualFileURIDoesNotExist() throws Exception
- {
- MockVFSContext context = registerSimpleVFSContextWithChildren();
-
- try
- {
- VFS.getVirtualFile(context.getRootURI(), "doesnotexist");
- fail("Should not be here");
- }
- catch (Throwable t)
- {
- checkThrowable(IOException.class, t);
- }
- }
-
- public void testGetVirtualFileURIIOExceptionGetVFS() throws Exception
- {
- MockVFSContext context = registerSimpleVFSContextWithChildren();
- mockVFSContextFactory.setIOException("getVFSURI");
-
- try
- {
- VFS.getVirtualFile(context.getRootURI(), "child1");
- fail("Should not be here");
- }
- catch (Throwable t)
- {
- checkThrowable(IOException.class, t);
- }
- }
-
- public void testGetVirtualFileURIIOExceptionFindChild() throws Exception
- {
- MockVFSContext context = registerSimpleVFSContextWithChildren();
- context.getMockRoot().setIOException("getChild");
-
- try
- {
- VFS.getVirtualFile(context.getRootURI(), "child1");
- fail("Should not be here");
- }
- catch (Throwable t)
- {
- checkThrowable(IOException.class, t);
- }
- }
-
- public void testGetRootURL() throws Exception
- {
- MockVFSContext context = registerSimpleVFSContextWithChildren();
-
- VirtualFile file = VFS.getRoot(context.getRootURL());
- assertNotNull(file);
- assertEquals(context.getRoot().getVirtualFile(), file);
- }
-
- public void testGetRootURLNullURL() throws Exception
- {
- try
- {
- VFS.getRoot((URL) null);
- fail("Should not be here");
- }
- catch (Throwable t)
- {
- checkThrowable(IllegalArgumentException.class, t);
- }
- }
-
- public void testGetRootURLNoFactory() throws Exception
- {
- URL url = new URL("doesnotexist", "", 0, "", MockURLStreamHandler.INSTANCE);
- try
- {
- VFS.getRoot(url);
- fail("Should not be here");
- }
- catch (Throwable t)
- {
- checkThrowable(IOException.class, t);
- }
- }
-
- public void testGetRootURLIOExceptionGetVFS() throws Exception
- {
- MockVFSContext context = registerSimpleVFSContextWithChildren();
- mockVFSContextFactory.setIOException("getVFSURL");
-
- URL url = context.getRootURL();
- try
- {
- VFS.getRoot(url);
- fail("Should not be here");
- }
- catch (Throwable t)
- {
- checkThrowable(IOException.class, t);
- }
- }
-
- public void testGetRootURLIOExceptionGetRoot() throws Exception
- {
- MockVFSContext context = registerSimpleVFSContextWithChildren();
- context.setIOException("getRoot");
-
- URL url = context.getRootURL();
- try
- {
- VFS.getRoot(url);
- fail("Should not be here");
- }
- catch (Throwable t)
- {
- checkThrowable(IOException.class, t);
- }
- }
-
- public void testGetVirtualFileURLRoot() throws Exception
- {
- MockVFSContext context = registerSimpleVFSContextWithChildren();
-
- VirtualFile file = VFS.getVirtualFile(context.getRootURL(), "");
- assertNotNull(file);
- assertEquals(context.getRoot().getVirtualFile(), file);
- }
-
- public void testGetVirtualFileURLChildren() throws Exception
- {
- MockVFSContext context = registerSimpleVFSContextWithChildren();
- VirtualFile child1 = getChildHandler(context, "child1").getVirtualFile();
- VirtualFile child2 = getChildHandler(context, "child2").getVirtualFile();
- VirtualFile child3 = getChildHandler(context, "child3").getVirtualFile();
-
- VirtualFile file1 = VFS.getVirtualFile(context.getRootURL(), "child1");
- assertNotNull(file1);
- assertEquals(child1, file1);
-
- VirtualFile file2 = VFS.getVirtualFile(context.getRootURL(), "child2");
- assertNotNull(file2);
- assertEquals(child2, file2);
-
- VirtualFile file3 = VFS.getVirtualFile(context.getRootURL(), "child3");
- assertNotNull(file3);
- assertEquals(child3, file3);
- }
-
- public void testGetVirtualFileURLNullURL() throws Exception
- {
- try
- {
- VFS.getVirtualFile((URL) null, "");
- fail("Should not be here");
- }
- catch (Throwable t)
- {
- checkThrowable(IllegalArgumentException.class, t);
- }
- }
-
- public void testGetVirtualFileURLNullPath() throws Exception
- {
- MockVFSContext context = registerSimpleVFSContextWithChildren();
-
- try
- {
- VFS.getVirtualFile(context.getRootURL(), null);
- fail("Should not be here");
- }
- catch (Throwable t)
- {
- checkThrowable(IllegalArgumentException.class, t);
- }
- }
-
- public void testGetVirtualFileURLNoFactory() throws Exception
- {
- try
- {
- URL url = new URL("doesnotexist", "", 0, "", MockURLStreamHandler.INSTANCE);
- VFS.getVirtualFile(url, "");
- fail("Should not be here");
- }
- catch (Throwable t)
- {
- checkThrowable(IOException.class, t);
- }
- }
-
- public void testGetVirtualFileURLIOExceptionGetVFS() throws Exception
- {
- MockVFSContext context = registerSimpleVFSContextWithChildren();
- mockVFSContextFactory.setIOException("getVFSURL");
-
- try
- {
- VFS.getVirtualFile(context.getRootURL(), "child1");
- fail("Should not be here");
- }
- catch (Throwable t)
- {
- checkThrowable(IOException.class, t);
- }
- }
-
- public void testGetVirtualFileURLDoesNotExist() throws Exception
- {
- MockVFSContext context = registerSimpleVFSContextWithChildren();
-
- try
- {
- VFS.getVirtualFile(context.getRootURL(), "doesnotexist");
- fail("Should not be here");
- }
- catch (Throwable t)
- {
- checkThrowable(IOException.class, t);
- }
- }
-
- public void testGetVirtualFileURLIOExceptionFindChild() throws Exception
- {
- MockVFSContext context = registerSimpleVFSContextWithChildren();
- context.getMockRoot().setIOException("getChild");
-
- try
- {
- VFS.getVirtualFile(context.getRootURL(), "child1");
- fail("Should not be here");
- }
- catch (Throwable t)
- {
- checkThrowable(IOException.class, t);
- }
- }
-
- public void testGetRoot() throws Exception
- {
- MockVFSContext context = registerSimpleVFSContext();
-
- VFS vfs = VFS.getVFS(context.getRootURI());
- assertNotNull(vfs);
-
- VirtualFile root = vfs.getRoot();
- assertNotNull(root);
-
- assertEquals(context.getRoot().getVirtualFile(), root);
- }
-
- public void testGetRootIOException() throws Exception
- {
- MockVFSContext context = registerSimpleVFSContext();
- context.setIOException("getRoot");
-
- VFS vfs = VFS.getVFS(context.getRootURI());
- assertNotNull(vfs);
-
- try
- {
- vfs.getRoot();
- fail("Should not be here");
- }
- catch (Throwable t)
- {
- checkThrowable(IOException.class, t);
- }
- }
-
- public void testFindChildRoot() throws Exception
- {
- MockVFSContext context = registerSimpleVFSContext();
- context.getMockRoot().setLeaf(false);
-
- VFS vfs = VFS.getVFS(context.getRootURI());
-
- assertFindChild(vfs, "", vfs.getRoot());
- }
-
- public void testFindChildChildren() throws Exception
- {
- MockVFSContext context = registerSimpleVFSContextWithChildren();
- VirtualFile child1 = getChildHandler(context, "child1").getVirtualFile();
- VirtualFile child2 = getChildHandler(context, "child2").getVirtualFile();
- VirtualFile child3 = getChildHandler(context, "child3").getVirtualFile();
-
- VFS vfs = VFS.getVFS(context.getRootURI());
- assertFindChild(vfs, "child1", child1);
- assertFindChild(vfs, "child2", child2);
- assertFindChild(vfs, "child3", child3);
- }
-
- public void testFindChildSubChildren() throws Exception
- {
- MockVFSContext context = registerStructuredVFSContextWithSubChildren();
- VirtualFile child1 = getChildHandler(context, "child1").getVirtualFile();
- VirtualFile child11 = getChildHandler(context, "child1/child1,1").getVirtualFile();
- VirtualFile child2 = getChildHandler(context, "child2").getVirtualFile();
- VirtualFile child21 = getChildHandler(context, "child2/child2,1").getVirtualFile();
- VirtualFile child22 = getChildHandler(context, "child2/child2,2").getVirtualFile();
- VirtualFile child3 = getChildHandler(context, "child3").getVirtualFile();
- VirtualFile child31 = getChildHandler(context, "child3/child3,1").getVirtualFile();
- VirtualFile child32 = getChildHandler(context, "child3/child3,2").getVirtualFile();
- VirtualFile child33 = getChildHandler(context, "child3/child3,3").getVirtualFile();
-
- VFS vfs = VFS.getVFS(context.getRootURI());
- assertFindChild(vfs, "child1", child1);
- assertFindChild(vfs, "child1/child1,1", child11);
- assertFindChild(vfs, "child2", child2);
- assertFindChild(vfs, "child2/child2,1", child21);
- assertFindChild(vfs, "child2/child2,2", child22);
- assertFindChild(vfs, "child3", child3);
- assertFindChild(vfs, "child3/child3,1", child31);
- assertFindChild(vfs, "child3/child3,2", child32);
- assertFindChild(vfs, "child3/child3,3", child33);
- }
-
- public void testFindChildNullPath() throws Exception
- {
- MockVFSContext context = registerSimpleVFSContextWithChildren();
-
- try
- {
- VFS vfs = VFS.getVFS(context.getRootURI());
- vfs.findChild(null);
- fail("Should not be here");
- }
- catch (Throwable t)
- {
- checkThrowable(IllegalArgumentException.class, t);
- }
- }
-
- public void testGetChildNullPath() throws Exception
- {
- MockVFSContext context = registerSimpleVFSContextWithChildren();
-
- try
- {
- VFS vfs = VFS.getVFS(context.getRootURI());
- vfs.getChild(null);
- fail("Should not be here");
- }
- catch (Throwable t)
- {
- checkThrowable(IllegalArgumentException.class, t);
- }
- }
-
- public void testFindChildSimpleDoesNotExist() throws Exception
- {
- MockVFSContext context = registerSimpleVFSContextWithChildren();
-
- VFS vfs = VFS.getVFS(context.getRootURI());
- try
- {
- vfs.findChild("doesnotexist");
- fail("Should not be here");
- }
- catch (Throwable t)
- {
- checkThrowable(IOException.class, t);
- assertNull(vfs.getChild("doesnotexist"));
- }
- }
-
- public void testFindChildStructuredDoesNotExist() throws Exception
- {
- MockVFSContext context = registerStructuredVFSContextWithSubChildren();
-
- VFS vfs = VFS.getVFS(context.getRootURI());
- try
- {
- vfs.findChild("child1/doesnotexist");
- fail("Should not be here");
- }
- catch (Throwable t)
- {
- checkThrowable(IOException.class, t);
- assertNull(vfs.getChild("child1/doesnotexist"));
- }
- }
-
- public void testFindChildIOException() throws Exception
- {
- MockVFSContext context = registerSimpleVFSContextWithChildren();
- context.getMockRoot().setIOException("getChild");
-
- try
- {
- VFS vfs = VFS.getVFS(context.getRootURI());
- vfs.findChild("child1");
- fail("Should not be here");
- }
- catch (Throwable t)
- {
- checkThrowable(IOException.class, t);
- }
- }
-
- public void testGetChildIOException() throws Exception
- {
- MockVFSContext context = registerSimpleVFSContextWithChildren();
- context.getMockRoot().setIOException("getChild");
-
- try
- {
- VFS vfs = VFS.getVFS(context.getRootURI());
- vfs.getChild("child1");
- fail("Should not be here");
- }
- catch (Throwable t)
- {
- checkThrowable(IOException.class, t);
- }
- }
-
- public void testGetAllChildren() throws Exception
- {
- MockVFSContext context = registerSimpleVFSContextWithChildren();
- VirtualFile child1 = getChildHandler(context, "child1").getVirtualFile();
- VirtualFile child2 = getChildHandler(context, "child2").getVirtualFile();
- VirtualFile child3 = getChildHandler(context, "child3").getVirtualFile();
-
- VFS vfs = VFS.getVFS(context.getRootURI());
- List<VirtualFile> children = vfs.getChildren();
- assertNotNull(children);
-
- List<VirtualFile> expected = new ArrayList<VirtualFile>();
- expected.add(child1);
- expected.add(child2);
- expected.add(child3);
-
- assertEquals(expected, children);
- }
-
- public void testGetAllChildrenStructured() throws Exception
- {
- MockVFSContext context = registerStructuredVFSContextWithSubChildren();
- VirtualFile child1 = getChildHandler(context, "child1").getVirtualFile();
- VirtualFile child2 = getChildHandler(context, "child2").getVirtualFile();
- VirtualFile child3 = getChildHandler(context, "child3").getVirtualFile();
-
- VFS vfs = VFS.getVFS(context.getRootURI());
- List<VirtualFile> children = vfs.getChildren();
- assertNotNull(children);
-
- List<VirtualFile> expected = new ArrayList<VirtualFile>();
- expected.add(child1);
- expected.add(child2);
- expected.add(child3);
-
- assertEquals(expected, children);
- }
-
- public void testGetAllChildrenNoChildren() throws Exception
- {
- MockVFSContext context = registerSimpleVFSContext();
- context.getMockRoot().setLeaf(false);
-
- VFS vfs = VFS.getVFS(context.getRootURI());
- List<VirtualFile> children = vfs.getChildren();
- assertNotNull(children);
-
- assertEmpty(children);
- }
-
- public void testGetAllChildrenIsLeaf() throws Exception
- {
- MockVFSContext context = registerSimpleVFSContext();
-
- VFS vfs = VFS.getVFS(context.getRootURI());
- assertChildrenOnLeaf(vfs);
- }
-
- public void testGetAllChildrenIOException() throws Exception
- {
- MockVFSContext context = registerSimpleVFSContextWithChildren();
- context.getMockRoot().setIOException("getChildren");
-
- VFS vfs = VFS.getVFS(context.getRootURI());
- try
- {
- vfs.getChildren();
- fail("Should not be here!");
- }
- catch (Throwable t)
- {
- checkThrowable(IOException.class, t);
- }
- }
-
- public void testGetAllChildrenWithNullFilter() throws Exception
- {
- MockVFSContext context = registerSimpleVFSContextWithChildren();
- VirtualFile child1 = getChildHandler(context, "child1").getVirtualFile();
- VirtualFile child2 = getChildHandler(context, "child2").getVirtualFile();
- VirtualFile child3 = getChildHandler(context, "child3").getVirtualFile();
-
- VFS vfs = VFS.getVFS(context.getRootURI());
- List<VirtualFile> children = vfs.getChildren(null);
- assertNotNull(children);
-
- List<VirtualFile> expected = new ArrayList<VirtualFile>();
- expected.add(child1);
- expected.add(child2);
- expected.add(child3);
-
- assertEquals(expected, children);
- }
-
- public void testGetAllChildrenWithNullFilterStructured() throws Exception
- {
- MockVFSContext context = registerStructuredVFSContextWithSubChildren();
- VirtualFile child1 = getChildHandler(context, "child1").getVirtualFile();
- VirtualFile child2 = getChildHandler(context, "child2").getVirtualFile();
- VirtualFile child3 = getChildHandler(context, "child3").getVirtualFile();
-
- VFS vfs = VFS.getVFS(context.getRootURI());
- List<VirtualFile> children = vfs.getChildren(null);
- assertNotNull(children);
-
- List<VirtualFile> expected = new ArrayList<VirtualFile>();
- expected.add(child1);
- expected.add(child2);
- expected.add(child3);
-
- assertEquals(expected, children);
- }
-
- public void testGetAllChildrenWithNullFilterNoChildren() throws Exception
- {
- MockVFSContext context = registerSimpleVFSContext();
- context.getMockRoot().setLeaf(false);
-
- VFS vfs = VFS.getVFS(context.getRootURI());
- List<VirtualFile> children = vfs.getChildren(null);
- assertNotNull(children);
-
- assertEmpty(children);
- }
-
- public void testGetAllChildrenWithNullFilterIsLeaf() throws Exception
- {
- MockVFSContext context = registerSimpleVFSContext();
-
- VFS vfs = VFS.getVFS(context.getRootURI());
- assertChildrenOnLeaf(vfs, null);
- }
-
- public void testGetAllChildrenWithNullFilterIOException() throws Exception
- {
- MockVFSContext context = registerSimpleVFSContextWithChildren();
- context.getMockRoot().setIOException("getChildren");
-
- VFS vfs = VFS.getVFS(context.getRootURI());
- try
- {
- vfs.getChildren(null);
- fail("Should not be here!");
- }
- catch (Throwable t)
- {
- checkThrowable(IOException.class, t);
- }
- }
-
- public void testGetAllChildrenWithFilter() throws Exception
- {
- MockVFSContext context = registerSimpleVFSContextWithChildren();
- VirtualFile child1 = getChildHandler(context, "child1").getVirtualFile();
- VirtualFile child2 = getChildHandler(context, "child2").getVirtualFile();
- VirtualFile child3 = getChildHandler(context, "child3").getVirtualFile();
-
- VFS vfs = VFS.getVFS(context.getRootURI());
- MockVirtualFileFilter filter = new MockVirtualFileFilter();
- List<VirtualFile> children = vfs.getChildren(filter);
- assertNotNull(children);
-
- List<VirtualFile> expected = new ArrayList<VirtualFile>();
- expected.add(child1);
- expected.add(child2);
- expected.add(child3);
-
- assertEquals(expected, children);
- assertEquals(expected, filter.getVisited());
- }
-
- public void testGetAllChildrenWithFilterStructured() throws Exception
- {
- MockVFSContext context = registerStructuredVFSContextWithSubChildren();
- VirtualFile child1 = getChildHandler(context, "child1").getVirtualFile();
- VirtualFile child2 = getChildHandler(context, "child2").getVirtualFile();
- VirtualFile child3 = getChildHandler(context, "child3").getVirtualFile();
-
- VFS vfs = VFS.getVFS(context.getRootURI());
- MockVirtualFileFilter filter = new MockVirtualFileFilter();
- List<VirtualFile> children = vfs.getChildren(filter);
- assertNotNull(children);
-
- List<VirtualFile> expected = new ArrayList<VirtualFile>();
- expected.add(child1);
- expected.add(child2);
- expected.add(child3);
-
- assertEquals(expected, children);
- assertEquals(expected, filter.getVisited());
- }
-
- public void testGetAllChildrenWithFilterNoChildren() throws Exception
- {
- MockVFSContext context = registerSimpleVFSContext();
- context.getMockRoot().setLeaf(false);
-
- VFS vfs = VFS.getVFS(context.getRootURI());
- MockVirtualFileFilter filter = new MockVirtualFileFilter();
- List<VirtualFile> children = vfs.getChildren(filter);
- assertNotNull(children);
-
- assertEmpty(children);
- assertEmpty(filter.getVisited());
- }
-
- public void testGetAllChildrenWithFilterIsLeaf() throws Exception
- {
- MockVFSContext context = registerSimpleVFSContext();
-
- VFS vfs = VFS.getVFS(context.getRootURI());
- MockVirtualFileFilter filter = new MockVirtualFileFilter();
- assertChildrenOnLeaf(vfs, filter);
- }
-
- public void testGetAllChildrenWithFilterIOException() throws Exception
- {
- MockVFSContext context = registerSimpleVFSContextWithChildren();
- context.getMockRoot().setIOException("getChildren");
-
- VFS vfs = VFS.getVFS(context.getRootURI());
- MockVirtualFileFilter filter = new MockVirtualFileFilter();
- try
- {
- vfs.getChildren(filter);
- fail("Should not be here!");
- }
- catch (Throwable t)
- {
- checkThrowable(IOException.class, t);
- }
- }
-
- public void testGetAllChildrenRecursively() throws Exception
- {
- MockVFSContext context = registerSimpleVFSContextWithChildren();
- VirtualFile child1 = getChildHandler(context, "child1").getVirtualFile();
- VirtualFile child2 = getChildHandler(context, "child2").getVirtualFile();
- VirtualFile child3 = getChildHandler(context, "child3").getVirtualFile();
-
- VFS vfs = VFS.getVFS(context.getRootURI());
- List<VirtualFile> children = vfs.getChildrenRecursively();
- assertNotNull(children);
-
- List<VirtualFile> expected = new ArrayList<VirtualFile>();
- expected.add(child1);
- expected.add(child2);
- expected.add(child3);
-
- assertEquals(expected, children);
- }
-
- public void testGetAllChildrenRecursivelyStructured() throws Exception
- {
- MockVFSContext context = registerStructuredVFSContextWithSubChildren();
- VirtualFile child1 = getChildHandler(context, "child1").getVirtualFile();
- VirtualFile child11 = getChildHandler(context, "child1/child1,1").getVirtualFile();
- VirtualFile child2 = getChildHandler(context, "child2").getVirtualFile();
- VirtualFile child21 = getChildHandler(context, "child2/child2,1").getVirtualFile();
- VirtualFile child22 = getChildHandler(context, "child2/child2,2").getVirtualFile();
- VirtualFile child3 = getChildHandler(context, "child3").getVirtualFile();
- VirtualFile child31 = getChildHandler(context, "child3/child3,1").getVirtualFile();
- VirtualFile child32 = getChildHandler(context, "child3/child3,2").getVirtualFile();
- VirtualFile child33 = getChildHandler(context, "child3/child3,3").getVirtualFile();
-
- VFS vfs = VFS.getVFS(context.getRootURI());
- List<VirtualFile> children = vfs.getChildrenRecursively();
- assertNotNull(children);
-
- List<VirtualFile> expected = new ArrayList<VirtualFile>();
- expected.add(child1);
- expected.add(child11);
- expected.add(child2);
- expected.add(child21);
- expected.add(child22);
- expected.add(child3);
- expected.add(child31);
- expected.add(child32);
- expected.add(child33);
-
- assertEquals(expected, children);
- }
-
- public void testGetAllChildrenRecursivelyNoChildren() throws Exception
- {
- MockVFSContext context = registerSimpleVFSContext();
- context.getMockRoot().setLeaf(false);
-
- VFS vfs = VFS.getVFS(context.getRootURI());
- List<VirtualFile> children = vfs.getChildrenRecursively();
- assertNotNull(children);
-
- assertEmpty(children);
- }
-
- public void testGetAllChildrenRecursivelyIsLeaf() throws Exception
- {
- MockVFSContext context = registerSimpleVFSContext();
-
- VFS vfs = VFS.getVFS(context.getRootURI());
- assertChildrenOnLeafRecursively(vfs);
- }
-
- public void testGetAllChildrenRecursivelyIOException() throws Exception
- {
- MockVFSContext context = registerSimpleVFSContextWithChildren();
- context.getMockRoot().setIOException("getChildren");
-
- VFS vfs = VFS.getVFS(context.getRootURI());
- try
- {
- vfs.getChildrenRecursively();
- fail("Should not be here!");
- }
- catch (Throwable t)
- {
- checkThrowable(IOException.class, t);
- }
- }
-
- public void testGetAllChildrenRecursivelyWithNullFilter() throws Exception
- {
- MockVFSContext context = registerSimpleVFSContextWithChildren();
- VirtualFile child1 = getChildHandler(context, "child1").getVirtualFile();
- VirtualFile child2 = getChildHandler(context, "child2").getVirtualFile();
- VirtualFile child3 = getChildHandler(context, "child3").getVirtualFile();
-
- VFS vfs = VFS.getVFS(context.getRootURI());
- List<VirtualFile> children = vfs.getChildrenRecursively(null);
- assertNotNull(children);
-
- List<VirtualFile> expected = new ArrayList<VirtualFile>();
- expected.add(child1);
- expected.add(child2);
- expected.add(child3);
-
- assertEquals(expected, children);
- }
-
- public void testGetAllChildrenRecursivelyWithNullFilterStructured() throws Exception
- {
- MockVFSContext context = registerStructuredVFSContextWithSubChildren();
- VirtualFile child1 = getChildHandler(context, "child1").getVirtualFile();
- VirtualFile child11 = getChildHandler(context, "child1/child1,1").getVirtualFile();
- VirtualFile child2 = getChildHandler(context, "child2").getVirtualFile();
- VirtualFile child21 = getChildHandler(context, "child2/child2,1").getVirtualFile();
- VirtualFile child22 = getChildHandler(context, "child2/child2,2").getVirtualFile();
- VirtualFile child3 = getChildHandler(context, "child3").getVirtualFile();
- VirtualFile child31 = getChildHandler(context, "child3/child3,1").getVirtualFile();
- VirtualFile child32 = getChildHandler(context, "child3/child3,2").getVirtualFile();
- VirtualFile child33 = getChildHandler(context, "child3/child3,3").getVirtualFile();
-
- VFS vfs = VFS.getVFS(context.getRootURI());
- List<VirtualFile> children = vfs.getChildrenRecursively(null);
- assertNotNull(children);
-
- List<VirtualFile> expected = new ArrayList<VirtualFile>();
- expected.add(child1);
- expected.add(child11);
- expected.add(child2);
- expected.add(child21);
- expected.add(child22);
- expected.add(child3);
- expected.add(child31);
- expected.add(child32);
- expected.add(child33);
-
- assertEquals(expected, children);
- }
-
- public void testGetAllChildrenRecursivelyWithNullFilterNoChildren() throws Exception
- {
- MockVFSContext context = registerSimpleVFSContext();
- context.getMockRoot().setLeaf(false);
-
- VFS vfs = VFS.getVFS(context.getRootURI());
- List<VirtualFile> children = vfs.getChildrenRecursively(null);
- assertNotNull(children);
-
- assertEmpty(children);
- }
-
- public void testGetAllChildrenRecursivelyWithNullFilterIsLeaf() throws Exception
- {
- MockVFSContext context = registerSimpleVFSContext();
-
- VFS vfs = VFS.getVFS(context.getRootURI());
- assertChildrenOnLeafRecursively(vfs, null);
- }
-
- public void testGetAllChildrenRecursivelyWithNullFilterIOException() throws Exception
- {
- MockVFSContext context = registerSimpleVFSContextWithChildren();
- context.getMockRoot().setIOException("getChildren");
-
- VFS vfs = VFS.getVFS(context.getRootURI());
- try
- {
- vfs.getChildrenRecursively(null);
- fail("Should not be here!");
- }
- catch (Throwable t)
- {
- checkThrowable(IOException.class, t);
- }
- }
-
- public void testGetAllChildrenRecursivelyWithFilter() throws Exception
- {
- MockVFSContext context = registerSimpleVFSContextWithChildren();
- VirtualFile child1 = getChildHandler(context, "child1").getVirtualFile();
- VirtualFile child2 = getChildHandler(context, "child2").getVirtualFile();
- VirtualFile child3 = getChildHandler(context, "child3").getVirtualFile();
-
- VFS vfs = VFS.getVFS(context.getRootURI());
- MockVirtualFileFilter filter = new MockVirtualFileFilter();
- List<VirtualFile> children = vfs.getChildrenRecursively(filter);
- assertNotNull(children);
-
- List<VirtualFile> expected = new ArrayList<VirtualFile>();
- expected.add(child1);
- expected.add(child2);
- expected.add(child3);
-
- assertEquals(expected, children);
- assertEquals(expected, filter.getVisited());
- }
-
- public void testGetAllChildrenRecursivelyWithFilterStructured() throws Exception
- {
- MockVFSContext context = registerStructuredVFSContextWithSubChildren();
- VirtualFile child1 = getChildHandler(context, "child1").getVirtualFile();
- VirtualFile child11 = getChildHandler(context, "child1/child1,1").getVirtualFile();
- VirtualFile child2 = getChildHandler(context, "child2").getVirtualFile();
- VirtualFile child21 = getChildHandler(context, "child2/child2,1").getVirtualFile();
- VirtualFile child22 = getChildHandler(context, "child2/child2,2").getVirtualFile();
- VirtualFile child3 = getChildHandler(context, "child3").getVirtualFile();
- VirtualFile child31 = getChildHandler(context, "child3/child3,1").getVirtualFile();
- VirtualFile child32 = getChildHandler(context, "child3/child3,2").getVirtualFile();
- VirtualFile child33 = getChildHandler(context, "child3/child3,3").getVirtualFile();
-
- VFS vfs = VFS.getVFS(context.getRootURI());
- MockVirtualFileFilter filter = new MockVirtualFileFilter();
- List<VirtualFile> children = vfs.getChildrenRecursively(filter);
- assertNotNull(children);
-
- List<VirtualFile> expected = new ArrayList<VirtualFile>();
- expected.add(child1);
- expected.add(child11);
- expected.add(child2);
- expected.add(child21);
- expected.add(child22);
- expected.add(child3);
- expected.add(child31);
- expected.add(child32);
- expected.add(child33);
-
- assertEquals(expected, children);
- assertEquals(expected, filter.getVisited());
- }
-
- public void testGetAllChildrenRecursivelyWithFilterNoChildren() throws Exception
- {
- MockVFSContext context = registerSimpleVFSContext();
- context.getMockRoot().setLeaf(false);
-
- VFS vfs = VFS.getVFS(context.getRootURI());
- MockVirtualFileFilter filter = new MockVirtualFileFilter();
- List<VirtualFile> children = vfs.getChildrenRecursively(filter);
- assertNotNull(children);
-
- assertEmpty(children);
- assertEmpty(filter.getVisited());
- }
-
- public void testGetAllChildrenRecursivelyWithFilterIsLeaf() throws Exception
- {
- MockVFSContext context = registerSimpleVFSContext();
-
- VFS vfs = VFS.getVFS(context.getRootURI());
- MockVirtualFileFilter filter = new MockVirtualFileFilter();
- assertChildrenOnLeafRecursively(vfs, filter);
- }
-
- public void testGetAllChildrenRecursivelyWithFilterIOException() throws Exception
- {
- MockVFSContext context = registerSimpleVFSContextWithChildren();
- context.getMockRoot().setIOException("getChildren");
-
- VFS vfs = VFS.getVFS(context.getRootURI());
- MockVirtualFileFilter filter = new MockVirtualFileFilter();
- try
- {
- vfs.getChildrenRecursively(filter);
- fail("Should not be here!");
- }
- catch (Throwable t)
- {
- checkThrowable(IOException.class, t);
- }
- }
-
- public void testVisitAllChildren() throws Exception
- {
- MockVFSContext context = registerSimpleVFSContextWithChildren();
- VirtualFile child1 = getChildHandler(context, "child1").getVirtualFile();
- VirtualFile child2 = getChildHandler(context, "child2").getVirtualFile();
- VirtualFile child3 = getChildHandler(context, "child3").getVirtualFile();
-
- VFS vfs = VFS.getVFS(context.getRootURI());
- MockVirtualFileFilter filter = new MockVirtualFileFilter();
- FilterVirtualFileVisitor visitor = new FilterVirtualFileVisitor(filter);
- vfs.visit(visitor);
-
- List<VirtualFile> expected = new ArrayList<VirtualFile>();
- expected.add(child1);
- expected.add(child2);
- expected.add(child3);
-
- assertEquals(expected, filter.getVisited());
- }
-
- public void testVisitAllChildrenStructured() throws Exception
- {
- MockVFSContext context = registerStructuredVFSContextWithSubChildren();
- VirtualFile child1 = getChildHandler(context, "child1").getVirtualFile();
- VirtualFile child2 = getChildHandler(context, "child2").getVirtualFile();
- VirtualFile child3 = getChildHandler(context, "child3").getVirtualFile();
-
- VFS vfs = VFS.getVFS(context.getRootURI());
- MockVirtualFileFilter filter = new MockVirtualFileFilter();
- FilterVirtualFileVisitor visitor = new FilterVirtualFileVisitor(filter);
- vfs.visit(visitor);
-
- List<VirtualFile> expected = new ArrayList<VirtualFile>();
- expected.add(child1);
- expected.add(child2);
- expected.add(child3);
-
- assertEquals(expected, filter.getVisited());
- }
-
- public void testVisitAllChildrenNoChildren() throws Exception
- {
- MockVFSContext context = registerSimpleVFSContext();
- context.getMockRoot().setLeaf(false);
-
- VFS vfs = VFS.getVFS(context.getRootURI());
- MockVirtualFileFilter filter = new MockVirtualFileFilter();
- FilterVirtualFileVisitor visitor = new FilterVirtualFileVisitor(filter);
- vfs.visit(visitor);
-
- assertEmpty(filter.getVisited());
- }
-
- public void testVisitAllChildrenIsLeaf() throws Exception
- {
- MockVFSContext context = registerSimpleVFSContext();
-
- VFS vfs = VFS.getVFS(context.getRootURI());
- MockVirtualFileFilter filter = new MockVirtualFileFilter();
- FilterVirtualFileVisitor visitor = new FilterVirtualFileVisitor(filter);
- vfs.visit(visitor);
- List<VirtualFile> matched = visitor.getMatched();
- assertNotNull(matched);
- assertEmpty(matched);
- }
-
- public void testVisitAllChildrenNullVisitor() throws Exception
- {
- MockVFSContext context = registerSimpleVFSContextWithChildren();
-
- VFS vfs = VFS.getVFS(context.getRootURI());
- try
- {
- vfs.visit(null);
- fail("Should not be here!");
- }
- catch (Throwable t)
- {
- checkThrowable(IllegalArgumentException.class, t);
- }
- }
-
- public void testVisitAllChildrenIOException() throws Exception
- {
- MockVFSContext context = registerSimpleVFSContextWithChildren();
- context.getMockRoot().setIOException("getChildren");
-
- VFS vfs = VFS.getVFS(context.getRootURI());
- MockVirtualFileFilter filter = new MockVirtualFileFilter();
- FilterVirtualFileVisitor visitor = new FilterVirtualFileVisitor(filter);
- try
- {
- vfs.visit(visitor);
- fail("Should not be here!");
- }
- catch (Throwable t)
- {
- checkThrowable(IOException.class, t);
- }
- }
-
- public void testToString() throws Exception
- {
- MockVFSContext context = registerSimpleVFSContext();
- VFS vfs = context.getVFS();
-
- assertEquals(context.toString(), vfs.toString());
- }
-
- public void testHashCode() throws Exception
- {
- MockVFSContext context = registerSimpleVFSContext();
- VFS vfs = context.getVFS();
-
- assertEquals(context.hashCode(), vfs.hashCode());
- }
-
- public void testEquals() throws Exception
- {
- MockVFSContext context1 = createSimpleVFSContext();
- MockVFSContext context2 = createSimpleVFSContext();
-
- VFS vfs1 = context1.getVFS();
- VFS vfs2 = context2.getVFS();
-
- assertEquals(vfs1, vfs2);
-
- MockVFSContext context3 = createSimple2VFSContext();
- VFS vfs3 = context3.getVFS();
-
- assertFalse(vfs1.equals(vfs3));
- assertFalse(vfs2.equals(vfs3));
-
- assertFalse(vfs1.equals(null));
-
- assertFalse(vfs1.equals(new Object()));
- }
}
More information about the jboss-cvs-commits
mailing list