[jboss-cvs] JBossAS SVN: r57230 - in projects/microcontainer/trunk: container/src/main/org/jboss/virtual container/src/main/org/jboss/virtual/classloading container/src/main/org/jboss/virtual/plugins/context container/src/main/org/jboss/virtual/plugins/vfs/helpers container/src/tests/org/jboss/test/virtual container/src/tests/org/jboss/test/virtual/support container/src/tests/org/jboss/test/virtual/test osgi-int/src/main/org/jboss/vfs/bundle
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Sep 27 06:42:57 EDT 2006
Author: adrian at jboss.org
Date: 2006-09-27 06:42:40 -0400 (Wed, 27 Sep 2006)
New Revision: 57230
Added:
projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/vfs/helpers/AbstractVirtualFileFilterWithAttributes.java
projects/microcontainer/trunk/container/src/tests/org/jboss/test/virtual/support/
projects/microcontainer/trunk/container/src/tests/org/jboss/test/virtual/support/AbstractMockVirtualFileHandler.java
projects/microcontainer/trunk/container/src/tests/org/jboss/test/virtual/support/MockInputStream.java
projects/microcontainer/trunk/container/src/tests/org/jboss/test/virtual/support/MockSimpleVirtualFileHandler.java
projects/microcontainer/trunk/container/src/tests/org/jboss/test/virtual/support/MockStructuredVirtualFileHandler.java
projects/microcontainer/trunk/container/src/tests/org/jboss/test/virtual/support/MockVFSContext.java
projects/microcontainer/trunk/container/src/tests/org/jboss/test/virtual/support/MockVFSContextFactory.java
projects/microcontainer/trunk/container/src/tests/org/jboss/test/virtual/support/MockVirtualFileFilter.java
projects/microcontainer/trunk/container/src/tests/org/jboss/test/virtual/test/AbstractMockVFSTest.java
projects/microcontainer/trunk/container/src/tests/org/jboss/test/virtual/test/VFSUnitTestCase.java
projects/microcontainer/trunk/container/src/tests/org/jboss/test/virtual/test/VirtualFileUnitTestCase.java
Modified:
projects/microcontainer/trunk/container/src/main/org/jboss/virtual/VFS.java
projects/microcontainer/trunk/container/src/main/org/jboss/virtual/VFSUtils.java
projects/microcontainer/trunk/container/src/main/org/jboss/virtual/VirtualFile.java
projects/microcontainer/trunk/container/src/main/org/jboss/virtual/classloading/VFSClassLoader.java
projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/AbstractVirtualFileHandler.java
projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/vfs/helpers/AbstractVirtualFileVisitor.java
projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/vfs/helpers/SuffixMatchFilter.java
projects/microcontainer/trunk/container/src/tests/org/jboss/test/virtual/test/FileVFSUnitTestCase.java
projects/microcontainer/trunk/container/src/tests/org/jboss/test/virtual/test/TestClassLoading.java
projects/microcontainer/trunk/container/src/tests/org/jboss/test/virtual/test/VFSAllTestSuite.java
projects/microcontainer/trunk/osgi-int/src/main/org/jboss/vfs/bundle/VFSBundle.java
Log:
Basic tests for the VFS api (not the spi).
Fixed some bugs found, mostly error handling.
"Removed" a couple of VFS methods that are redundant because they are effectively:
public void doSomething(VirtualFile file) { file.doSomething() }
Deprecated findChildFromRoot(String path), replaced with the simpler name findChild().
Updated all uses in the Microcontainer project.
Also added a static helper to get the root file.
VFS.getRoot(URI) { getVFS(URI).getRoot() }
which I found I was doing a lot in the tests.
Modified: projects/microcontainer/trunk/container/src/main/org/jboss/virtual/VFS.java
===================================================================
--- projects/microcontainer/trunk/container/src/main/org/jboss/virtual/VFS.java 2006-09-27 10:12:24 UTC (rev 57229)
+++ projects/microcontainer/trunk/container/src/main/org/jboss/virtual/VFS.java 2006-09-27 10:42:40 UTC (rev 57230)
@@ -45,6 +45,52 @@
private final VFSContext context;
/**
+ * Get the virtual file system for a root uri
+ *
+ * @param rootURI the root URI
+ * @return the virtual file system
+ * @throws IOException if there is a problem accessing the VFS
+ * @throws IllegalArgumentException if the rootURL is null
+ */
+ public static VFS getVFS(URI rootURI) throws IOException
+ {
+ VFSContextFactory factory = VFSContextFactoryLocator.getFactory(rootURI);
+ if (factory == null)
+ throw new IOException("No context factory for " + rootURI);
+ VFSContext context = factory.getVFS(rootURI);
+ return context.getVFS();
+ }
+
+ /**
+ * Get the root virtual file
+ *
+ * @param rootURI the root uri
+ * @return the virtual file
+ * @throws IOException if there is a problem accessing the VFS
+ * @throws IllegalArgumentException if the rootURL
+ */
+ public static VirtualFile getRoot(URI rootURI) throws IOException
+ {
+ VFS vfs = getVFS(rootURI);
+ return vfs.getRoot();
+ }
+
+ /**
+ * Get a virtual file
+ *
+ * @param rootURI the root uri
+ * @param name the path name
+ * @return the virtual file
+ * @throws IOException if there is a problem accessing the VFS
+ * @throws IllegalArgumentException if the rootURL or name is null
+ */
+ public static VirtualFile getVirtualFile(URI rootURI, String name) throws IOException
+ {
+ VFS vfs = getVFS(rootURI);
+ return vfs.findChild(name);
+ }
+
+ /**
* Get the virtual file system for a root url
*
* @param rootURL the root url
@@ -55,22 +101,24 @@
public static VFS getVFS(URL rootURL) throws IOException
{
VFSContextFactory factory = VFSContextFactoryLocator.getFactory(rootURL);
+ if (factory == null)
+ throw new IOException("No context factory for " + rootURL);
VFSContext context = factory.getVFS(rootURL);
return context.getVFS();
}
+
/**
- * Get the virtual file system for a root uri
+ * Get the root virtual file
*
- * @param rootURI the root URI
- * @return the virtual file system
+ * @param rootURL the root url
+ * @return the virtual file
* @throws IOException if there is a problem accessing the VFS
- * @throws IllegalArgumentException if the rootURL is null
+ * @throws IllegalArgumentException if the rootURL
*/
- public static VFS getVFS(URI rootURI) throws IOException
+ public static VirtualFile getRoot(URL rootURL) throws IOException
{
- VFSContextFactory factory = VFSContextFactoryLocator.getFactory(rootURI);
- VFSContext context = factory.getVFS(rootURI);
- return context.getVFS();
+ VFS vfs = getVFS(rootURL);
+ return vfs.getRoot();
}
/**
@@ -85,7 +133,7 @@
public static VirtualFile getVirtualFile(URL rootURL, String name) throws IOException
{
VFS vfs = getVFS(rootURL);
- return vfs.findChildFromRoot(name);
+ return vfs.findChild(name);
}
/**
@@ -114,63 +162,37 @@
}
/**
- * Get a parent
+ * Find a child from the root
*
- * @param child the child
- * @return the parent or null if there is no parent
- * @throws IOException for any problem accessing the VFS (including the child does not exist)
- * @throws IllegalArgumentException if the child is null
- */
- public VirtualFile getParent(VirtualFile child) throws IOException
- {
- if (child == null)
- throw new IllegalArgumentException("Null parent");
-
- VirtualFileHandler handler = child.getHandler();
- VirtualFileHandler parent = handler.getParent();
- return parent.getVirtualFile();
- }
-
- /**
- * Find a child
- *
- * @param parent the context file
* @param path the child path
* @return the child
* @throws IOException for any problem accessing the VFS (including the child does not exist)
- * @throws IllegalArgumentException if the parent or path is null
+ * @throws IllegalArgumentException if the path is null
*/
- public VirtualFile findChild(VirtualFile parent, String path) throws IOException
+ public VirtualFile findChild(String path) throws IOException
{
- if (parent == null)
- throw new IllegalArgumentException("Null parent");
if (path == null)
throw new IllegalArgumentException("Null path");
- VirtualFileHandler handler = parent.getHandler();
- VFSContext handlerContext = handler.getVFSContext();
+ VirtualFileHandler handler = context.getRoot();
path = VFSUtils.fixName(path);
- VirtualFileHandler result = handlerContext.findChild(handler, path);
+ VirtualFileHandler result = context.findChild(handler, path);
return result.getVirtualFile();
}
/**
* Find a child from the root
*
+ * @Deprecated use {@link #findChild(String)}
* @param path the child path
* @return the child
* @throws IOException for any problem accessing the VFS (including the child does not exist)
* @throws IllegalArgumentException if the path is null
*/
+ @Deprecated
public VirtualFile findChildFromRoot(String path) throws IOException
{
- if (path == null)
- throw new IllegalArgumentException("Null path");
-
- VirtualFileHandler handler = context.getRoot();
- path = VFSUtils.fixName(path);
- VirtualFileHandler result = context.findChild(handler, path);
- return result.getVirtualFile();
+ return findChild(path);
}
/**
@@ -178,7 +200,7 @@
*
* @return the children
* @throws IOException for any problem accessing the virtual file system
- * @throws IllegalStateException if the file is closed
+ * @throws IllegalStateException if the root is not a directory
*/
public List<VirtualFile> getChildren() throws IOException
{
@@ -191,7 +213,7 @@
* @param filter to filter the children
* @return the children
* @throws IOException for any problem accessing the virtual file system
- * @throws IllegalStateException if the file is closed or it is not a directory
+ * @throws IllegalStateException if the root is not a directory
*/
public List<VirtualFile> getChildren(VirtualFileFilter filter) throws IOException
{
@@ -205,7 +227,7 @@
*
* @return the children
* @throws IOException for any problem accessing the virtual file system
- * @throws IllegalStateException if the file is closed
+ * @throws IllegalStateException if the root is not a directory
*/
public List<VirtualFile> getChildrenRecursively() throws IOException
{
@@ -220,7 +242,7 @@
* @param filter to filter the children
* @return the children
* @throws IOException for any problem accessing the virtual file system
- * @throws IllegalStateException if the file is closed or it is not a directory
+ * @throws IllegalStateException if the root is not a directory
*/
public List<VirtualFile> getChildrenRecursively(VirtualFileFilter filter) throws IOException
{
@@ -233,10 +255,13 @@
* @param visitor the visitor
* @throws IOException for any problem accessing the VFS
* @throws IllegalArgumentException if the visitor is null
+ * @throws IllegalStateException if the root is not a directory
*/
public void visit(VirtualFileVisitor visitor) throws IOException
{
VirtualFileHandler handler = context.getRoot();
+ if (handler.isDirectory() == false)
+ throw new IllegalStateException("Not a directory");
WrappingVirtualFileHandlerVisitor wrapper = new WrappingVirtualFileHandlerVisitor(visitor);
context.visit(handler, wrapper);
}
@@ -248,8 +273,9 @@
* @param visitor the visitor
* @throws IOException for any problem accessing the VFS
* @throws IllegalArgumentException if the file or visitor is null
+ * @throws IllegalStateException if the root is not a directory
*/
- public void visit(VirtualFile file, VirtualFileVisitor visitor) throws IOException
+ protected void visit(VirtualFile file, VirtualFileVisitor visitor) throws IOException
{
if (file == null)
throw new IllegalArgumentException("Null file");
Modified: projects/microcontainer/trunk/container/src/main/org/jboss/virtual/VFSUtils.java
===================================================================
--- projects/microcontainer/trunk/container/src/main/org/jboss/virtual/VFSUtils.java 2006-09-27 10:12:24 UTC (rev 57229)
+++ projects/microcontainer/trunk/container/src/main/org/jboss/virtual/VFSUtils.java 2006-09-27 10:42:40 UTC (rev 57230)
@@ -200,9 +200,13 @@
*
* @param name the name to fix
* @return the fixed name
+ * @throws IllegalArgumentException for a null name
*/
public static String fixName(String name)
{
+ if (name == null)
+ throw new IllegalArgumentException("Null name");
+
int length = name.length();
if (length <= 1)
return name;
Modified: projects/microcontainer/trunk/container/src/main/org/jboss/virtual/VirtualFile.java
===================================================================
--- projects/microcontainer/trunk/container/src/main/org/jboss/virtual/VirtualFile.java 2006-09-27 10:12:24 UTC (rev 57229)
+++ projects/microcontainer/trunk/container/src/main/org/jboss/virtual/VirtualFile.java 2006-09-27 10:42:40 UTC (rev 57230)
@@ -46,8 +46,7 @@
* @author adrian at jboss.org
* @version $Revision: 44334 $
*/
-public class VirtualFile
- implements Serializable
+public class VirtualFile implements Serializable
{
private static final long serialVersionUID = 1L;
@@ -120,6 +119,7 @@
{
return getHandler().toURL();
}
+
/**
* Get the VF URI (file://root/org/jboss/X.java)
*
@@ -267,14 +267,16 @@
/**
* Get the parent
*
- * @return the parent
+ * @return the parent or null if there is no parent
* @throws IOException for any problem accessing the virtual file system
* @throws IllegalStateException if the file is closed
*/
public VirtualFile getParent() throws IOException
{
VirtualFileHandler parent = getHandler().getParent();
- return parent.getVirtualFile();
+ if (parent != null)
+ return parent.getVirtualFile();
+ return null;
}
/**
Modified: projects/microcontainer/trunk/container/src/main/org/jboss/virtual/classloading/VFSClassLoader.java
===================================================================
--- projects/microcontainer/trunk/container/src/main/org/jboss/virtual/classloading/VFSClassLoader.java 2006-09-27 10:12:24 UTC (rev 57229)
+++ projects/microcontainer/trunk/container/src/main/org/jboss/virtual/classloading/VFSClassLoader.java 2006-09-27 10:42:40 UTC (rev 57230)
@@ -144,7 +144,8 @@
}
/**
- * TODO
+ * TODO getPackageNames
+ *
* @see org.jboss.classloading.spi.DomainClassLoader#getPackageNames()
*/
public String[] getPackageNames()
@@ -290,7 +291,7 @@
for(String ctx : cp.searchCtxs)
{
String path = ctx + '/' + name;
- vf = cp.vfs.findChildFromRoot(path);
+ vf = cp.vfs.findChild(path);
if( vf != null )
{
break outer;
@@ -348,7 +349,7 @@
String dir = "";
if( slash > 0 )
dir = ctx.substring(0, slash);
- VirtualFile dirFile = vfs.findChildFromRoot(dir);
+ VirtualFile dirFile = vfs.findChild(dir);
List<VirtualFile> children = dirFile.getChildren();
StringBuilder sb = new StringBuilder(dir);
sb.append('/');
Modified: projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/AbstractVirtualFileHandler.java
===================================================================
--- projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/AbstractVirtualFileHandler.java 2006-09-27 10:12:24 UTC (rev 57229)
+++ projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/AbstractVirtualFileHandler.java 2006-09-27 10:42:40 UTC (rev 57230)
@@ -157,7 +157,7 @@
return new VirtualFile(this);
}
- public VirtualFileHandler getParent()
+ public VirtualFileHandler getParent() throws IOException
{
checkClosed();
return parent;
@@ -287,7 +287,7 @@
buffer.append('@');
buffer.append(System.identityHashCode(this));
buffer.append("[path=").append(getPathName());
- buffer.append(" context=").append(getVFSContext());
+ buffer.append(" context=").append(getVFSContext().getRootURI());
buffer.append(" real=").append(safeToURLString());
buffer.append(']');
return buffer.toString();
Added: projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/vfs/helpers/AbstractVirtualFileFilterWithAttributes.java
===================================================================
--- projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/vfs/helpers/AbstractVirtualFileFilterWithAttributes.java 2006-09-27 10:12:24 UTC (rev 57229)
+++ projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/vfs/helpers/AbstractVirtualFileFilterWithAttributes.java 2006-09-27 10:42:40 UTC (rev 57230)
@@ -0,0 +1,63 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, 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.plugins.vfs.helpers;
+
+import org.jboss.virtual.VirtualFileFilterWithAttributes;
+import org.jboss.virtual.VisitorAttributes;
+
+/**
+ * AbstractVirtualFileFilterWithAttributes
+ *
+ * @author adrian at jboss.org
+ * @version $Revision: 44223 $
+ */
+public abstract class AbstractVirtualFileFilterWithAttributes implements VirtualFileFilterWithAttributes
+{
+ /** The attributes */
+ private VisitorAttributes attributes;
+
+ /**
+ * Create a new AbstractVirtualFileFilterWithAttributes,
+ * using {@link VisitorAttributes#DEFAULT}
+ */
+ public AbstractVirtualFileFilterWithAttributes()
+ {
+ this(null);
+ }
+
+ /**
+ * Create a new AbstractVirtualFileFilterWithAttributes.
+ *
+ * @param attributes the attributes, pass null to use {@link VisitorAttributes#DEFAULT}
+ */
+ public AbstractVirtualFileFilterWithAttributes(VisitorAttributes attributes)
+ {
+ if (attributes == null)
+ attributes = VisitorAttributes.DEFAULT;
+ this.attributes = attributes;
+ }
+
+ public VisitorAttributes getAttributes()
+ {
+ return attributes;
+ }
+}
Modified: projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/vfs/helpers/AbstractVirtualFileVisitor.java
===================================================================
--- projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/vfs/helpers/AbstractVirtualFileVisitor.java 2006-09-27 10:12:24 UTC (rev 57229)
+++ projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/vfs/helpers/AbstractVirtualFileVisitor.java 2006-09-27 10:42:40 UTC (rev 57230)
@@ -32,6 +32,7 @@
*/
public abstract class AbstractVirtualFileVisitor implements VirtualFileVisitor
{
+ /** The attributes */
private final VisitorAttributes attributes;
/**
Modified: projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/vfs/helpers/SuffixMatchFilter.java
===================================================================
--- projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/vfs/helpers/SuffixMatchFilter.java 2006-09-27 10:12:24 UTC (rev 57229)
+++ projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/vfs/helpers/SuffixMatchFilter.java 2006-09-27 10:42:40 UTC (rev 57230)
@@ -22,7 +22,6 @@
package org.jboss.virtual.plugins.vfs.helpers;
import org.jboss.virtual.VirtualFile;
-import org.jboss.virtual.VirtualFileFilterWithAttributes;
import org.jboss.virtual.VisitorAttributes;
/**
@@ -32,16 +31,13 @@
* @author adrian at jboss.org
* @version $Revision: 44223 $
*/
-public class SuffixMatchFilter implements VirtualFileFilterWithAttributes
+public class SuffixMatchFilter extends AbstractVirtualFileFilterWithAttributes
{
/** The suffix */
private String suffix;
- /** The attributes */
- private VisitorAttributes attributes;
-
/**
- * Create a new SuffixMatchVisitor,
+ * Create a new SuffixMatchFilter,
* using {@link VisitorAttributes#RECURSE_NO_DIRECTORIES}
*
* @param suffix the suffix
@@ -53,7 +49,7 @@
}
/**
- * Create a new SuffixMatchVisitor.
+ * Create a new SuffixMatchFilter.
*
* @param suffix the suffix
* @param attributes the attributes, pass null to use {@link VisitorAttributes#RECURSE_NO_DIRECTORIES}
@@ -61,18 +57,11 @@
*/
public SuffixMatchFilter(String suffix, VisitorAttributes attributes)
{
+ super(attributes == null ? VisitorAttributes.RECURSE_NO_DIRECTORIES : attributes);
if (suffix == null)
throw new IllegalArgumentException("Null suffix");
this.suffix = suffix;
- if (attributes == null)
- attributes = VisitorAttributes.RECURSE_NO_DIRECTORIES;
- this.attributes = attributes;
}
-
- public VisitorAttributes getAttributes()
- {
- return attributes;
- }
public boolean accepts(VirtualFile file)
{
Added: projects/microcontainer/trunk/container/src/tests/org/jboss/test/virtual/support/AbstractMockVirtualFileHandler.java
===================================================================
--- projects/microcontainer/trunk/container/src/tests/org/jboss/test/virtual/support/AbstractMockVirtualFileHandler.java 2006-09-27 10:12:24 UTC (rev 57229)
+++ projects/microcontainer/trunk/container/src/tests/org/jboss/test/virtual/support/AbstractMockVirtualFileHandler.java 2006-09-27 10:42:40 UTC (rev 57230)
@@ -0,0 +1,283 @@
+/*
+* 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;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import org.jboss.util.UnexpectedThrowable;
+import org.jboss.virtual.plugins.context.AbstractVirtualFileHandler;
+import org.jboss.virtual.spi.VFSContext;
+import org.jboss.virtual.spi.VirtualFileHandler;
+
+/**
+ * AbstractMockVirtualFileHandler.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class AbstractMockVirtualFileHandler extends AbstractVirtualFileHandler
+{
+ /** The serialVersionUID */
+ private static final long serialVersionUID = -7967261672121081602L;
+
+ /** The URI */
+ private URI uri;
+
+ /** The children */
+ private List<VirtualFileHandler> children = new CopyOnWriteArrayList<VirtualFileHandler>();
+
+ /** Last modified */
+ private long lastModified;
+
+ /** Size */
+ private long size;
+
+ /** Is a directory */
+ private boolean directory;
+
+ /** Is an archive */
+ private boolean archive;
+
+ /** Is a hidden */
+ private boolean hidden;
+
+ /** The stream */
+ private byte[] stream;
+
+ /** When to throw an IOException */
+ private String ioException = "";
+
+ /**
+ * Create a root mock uri
+ *
+ * @param context the vfs context
+ * @param parent the parent file
+ * @param name the name
+ * @return the uri
+ */
+ public static URI createMockURI(VFSContext context, VirtualFileHandler parent, String name)
+ {
+ try
+ {
+ String uri = null;
+ if (parent != null)
+ uri = parent.toURI().toString();
+ else
+ uri = context.getRootURI().toString();
+ if (name.length() != 0)
+ uri = uri + "/" + name;
+ return new URI(uri);
+ }
+ catch (URISyntaxException e)
+ {
+ throw new UnexpectedThrowable("Unexpected", e);
+ }
+ }
+
+ /**
+ * Create a new AbstractMockVirtualFileHandler.
+ *
+ * @param context the context
+ * @param parent the parent
+ * @param name the name
+ */
+ protected AbstractMockVirtualFileHandler(MockVFSContext context, AbstractMockVirtualFileHandler parent, String name)
+ {
+ super(context, parent, name);
+ this.uri = createMockURI(context, parent, name);
+ if (parent != null)
+ parent.addChild(this);
+ }
+
+ /**
+ * Set the ioException.
+ *
+ * @param ioException the ioException.
+ */
+ public void setIOException(String ioException)
+ {
+ this.ioException = ioException;
+ }
+
+ /**
+ * Check whether we should throw an IOException
+ *
+ * @param when when to throw
+ * @throws IOException when requested
+ */
+ public void throwIOException(String when) throws IOException
+ {
+ if (ioException.equals(when))
+ throw new IOException("Throwing IOException from " + when);
+ }
+
+ public List<VirtualFileHandler> getChildren(boolean ignoreErrors) throws IOException
+ {
+ checkClosed();
+ if (ignoreErrors == false)
+ throwIOException("getChildren");
+ return Collections.unmodifiableList(children);
+ }
+
+ public void addChild(VirtualFileHandler child)
+ {
+ checkClosed();
+ if (child == null)
+ throw new IllegalArgumentException("Null child");
+ if (children.contains(child) == false)
+ children.add(child);
+ directory = true;
+ }
+
+ public long getLastModified() throws IOException
+ {
+ checkClosed();
+ throwIOException("getLastModified");
+ return lastModified;
+ }
+
+ /**
+ * Set the lastModified.
+ *
+ * @param lastModified the lastModified.
+ */
+ public void setLastModified(long lastModified)
+ {
+ this.lastModified = lastModified;
+ }
+
+ public long getSize() throws IOException
+ {
+ checkClosed();
+ throwIOException("getSize");
+ return size;
+ }
+
+ /**
+ * Set the size.
+ *
+ * @param size the size.
+ */
+ public void setSize(long size)
+ {
+ this.size = size;
+ }
+
+ public boolean isArchive() throws IOException
+ {
+ checkClosed();
+ throwIOException("isArchive");
+ return archive;
+ }
+
+ /**
+ * Set the archive.
+ *
+ * @param archive the archive.
+ */
+ public void setArchive(boolean archive)
+ {
+ this.archive = archive;
+ }
+
+ public boolean isDirectory() throws IOException
+ {
+ checkClosed();
+ throwIOException("isDirectory");
+ return directory;
+ }
+
+ /**
+ * Set directory.
+ *
+ * @param directory whether it is a directory.
+ */
+ public void setDirectory(boolean directory)
+ {
+ this.directory = directory;
+ }
+
+ public boolean isFile() throws IOException
+ {
+ checkClosed();
+ throwIOException("isFile");
+ return directory == false;
+ }
+
+ public boolean isHidden() throws IOException
+ {
+ checkClosed();
+ throwIOException("isHidden");
+ return hidden;
+ }
+
+ /**
+ * Set the hidden.
+ *
+ * @param hidden the hidden.
+ */
+ public void setHidden(boolean hidden)
+ {
+ this.hidden = hidden;
+ }
+
+ /**
+ * Set the stream.
+ *
+ * @param stream the stream.
+ */
+ public void setStream(byte[] stream)
+ {
+ this.stream = stream;
+ }
+
+ public InputStream openStream() throws IOException
+ {
+ checkClosed();
+ throwIOException("openStream");
+ return new MockInputStream(stream);
+ }
+
+ public URI toURI()
+ {
+ return uri;
+ }
+
+ @Override
+ public VirtualFileHandler getParent() throws IOException
+ {
+ throwIOException("getParent");
+ return super.getParent();
+ }
+
+ private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException
+ {
+ in.defaultReadObject();
+ }
+}
Added: projects/microcontainer/trunk/container/src/tests/org/jboss/test/virtual/support/MockInputStream.java
===================================================================
--- projects/microcontainer/trunk/container/src/tests/org/jboss/test/virtual/support/MockInputStream.java 2006-09-27 10:12:24 UTC (rev 57229)
+++ projects/microcontainer/trunk/container/src/tests/org/jboss/test/virtual/support/MockInputStream.java 2006-09-27 10:42:40 UTC (rev 57230)
@@ -0,0 +1,73 @@
+/*
+* 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;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+/**
+ * MockInputStream.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class MockInputStream extends ByteArrayInputStream
+{
+ /** Whether we are closed */
+ private AtomicBoolean closed = new AtomicBoolean(false);
+
+ /**
+ * Create a new MockInputStream.
+ *
+ * @param buf
+ * @param offset
+ * @param length
+ */
+ public MockInputStream(byte[] buf, int offset, int length)
+ {
+ super(buf, offset, length);
+ }
+
+ /**
+ * Create a new MockInputStream.
+ *
+ * @param buf
+ */
+ public MockInputStream(byte[] buf)
+ {
+ super(buf);
+ }
+
+ public void close() throws IOException
+ {
+ closed.set(true);
+ }
+
+ public int read()
+ {
+ if (closed.get())
+ return -1;
+ else
+ return super.read();
+ }
+}
Added: projects/microcontainer/trunk/container/src/tests/org/jboss/test/virtual/support/MockSimpleVirtualFileHandler.java
===================================================================
--- projects/microcontainer/trunk/container/src/tests/org/jboss/test/virtual/support/MockSimpleVirtualFileHandler.java 2006-09-27 10:12:24 UTC (rev 57229)
+++ projects/microcontainer/trunk/container/src/tests/org/jboss/test/virtual/support/MockSimpleVirtualFileHandler.java 2006-09-27 10:42:40 UTC (rev 57230)
@@ -0,0 +1,56 @@
+/*
+* 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;
+
+import java.io.IOException;
+
+import org.jboss.virtual.spi.VirtualFileHandler;
+
+/**
+ * MockSimpleVirtualFileHandler.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class MockSimpleVirtualFileHandler extends AbstractMockVirtualFileHandler
+{
+ /** The serialVersionUID */
+ private static final long serialVersionUID = -7967261672121081602L;
+
+ /**
+ * Create a new MockSimpleVirtualFileHandler.
+ *
+ * @param context the context
+ * @param parent the parent
+ * @param name the name
+ */
+ public MockSimpleVirtualFileHandler(MockVFSContext context, MockSimpleVirtualFileHandler parent, String name)
+ {
+ super(context, parent, name);
+ }
+
+ public VirtualFileHandler findChild(String path) throws IOException
+ {
+ throwIOException("findChild");
+ return simpleFindChild(path);
+ }
+}
Added: projects/microcontainer/trunk/container/src/tests/org/jboss/test/virtual/support/MockStructuredVirtualFileHandler.java
===================================================================
--- projects/microcontainer/trunk/container/src/tests/org/jboss/test/virtual/support/MockStructuredVirtualFileHandler.java 2006-09-27 10:12:24 UTC (rev 57229)
+++ projects/microcontainer/trunk/container/src/tests/org/jboss/test/virtual/support/MockStructuredVirtualFileHandler.java 2006-09-27 10:42:40 UTC (rev 57230)
@@ -0,0 +1,66 @@
+/*
+* 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;
+
+import java.io.IOException;
+
+import org.jboss.virtual.plugins.context.StructuredVirtualFileHandler;
+import org.jboss.virtual.spi.VirtualFileHandler;
+
+/**
+ * MockStructuredVirtualFileHandler.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class MockStructuredVirtualFileHandler extends AbstractMockVirtualFileHandler implements StructuredVirtualFileHandler
+{
+ /** The serialVersionUID */
+ private static final long serialVersionUID = -7967261672121081602L;
+
+ /**
+ * Create a new MockStructuredVirtualFileHandler.
+ *
+ * @param context the context
+ * @param parent the parent
+ * @param name the name
+ */
+ public MockStructuredVirtualFileHandler(MockVFSContext context, MockStructuredVirtualFileHandler parent, String name)
+ {
+ super(context, parent, name);
+ }
+
+ public VirtualFileHandler findChild(String path) throws IOException
+ {
+ return structuredFindChild(path);
+ }
+
+ public VirtualFileHandler createChildHandler(String name) throws IOException
+ {
+ for (VirtualFileHandler child : getChildren(false))
+ {
+ if (name.equals(child.getName()))
+ return child;
+ }
+ throw new IOException("Child not found: " + name + " for " + toURI());
+ }
+}
Added: projects/microcontainer/trunk/container/src/tests/org/jboss/test/virtual/support/MockVFSContext.java
===================================================================
--- projects/microcontainer/trunk/container/src/tests/org/jboss/test/virtual/support/MockVFSContext.java 2006-09-27 10:12:24 UTC (rev 57229)
+++ projects/microcontainer/trunk/container/src/tests/org/jboss/test/virtual/support/MockVFSContext.java 2006-09-27 10:42:40 UTC (rev 57230)
@@ -0,0 +1,130 @@
+/*
+* 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;
+
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import org.jboss.util.UnexpectedThrowable;
+import org.jboss.virtual.VirtualFile;
+import org.jboss.virtual.plugins.context.AbstractVFSContext;
+import org.jboss.virtual.spi.VirtualFileHandler;
+
+/**
+ * MockVFSContext.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class MockVFSContext extends AbstractVFSContext
+{
+ /** The root handler */
+ private VirtualFileHandler root;
+
+ /** The root virtual file */
+ private VirtualFile rootFile;
+
+ /** When to throw an IOException */
+ private String ioException = "";
+
+ /**
+ * Create a root mock uri
+ *
+ * @param name the name
+ * @return the uri
+ */
+ public static final URI createRootMockURI(String name)
+ {
+ try
+ {
+ return new URI("mock", "", "/" + name, null);
+ }
+ catch (URISyntaxException e)
+ {
+ throw new UnexpectedThrowable("Unexpected", e);
+ }
+ }
+
+ /**
+ * Create a new MockVFSContext.
+ *
+ * @param name the name
+ */
+ public MockVFSContext(String name)
+ {
+ super(createRootMockURI(name));
+ }
+
+ /**
+ * Set the ioException.
+ *
+ * @param ioException the ioException.
+ */
+ public void setIOException(String ioException)
+ {
+ this.ioException = ioException;
+ }
+
+ /**
+ * Check whether we should throw an IOException
+ *
+ * @param when when to throw
+ * @throws IOException when requested
+ */
+ public void throwIOException(String when) throws IOException
+ {
+ if (ioException.equals(when))
+ throw new IOException("Throwing IOException from " + when);
+ }
+
+ public VirtualFileHandler getRoot() throws IOException
+ {
+ throwIOException("getRoot");
+ return root;
+ }
+
+ public AbstractMockVirtualFileHandler getMockRoot() throws IOException
+ {
+ return (AbstractMockVirtualFileHandler) root;
+ }
+
+ /**
+ * Set the root.
+ *
+ * @param root the root.
+ */
+ public void setRoot(VirtualFileHandler root)
+ {
+ this.root = root;
+ if (root != null)
+ rootFile = root.getVirtualFile();
+ }
+
+ @Override
+ protected void finalize() throws Throwable
+ {
+ if (rootFile != null)
+ rootFile.close();
+ super.finalize();
+ }
+}
Added: projects/microcontainer/trunk/container/src/tests/org/jboss/test/virtual/support/MockVFSContextFactory.java
===================================================================
--- projects/microcontainer/trunk/container/src/tests/org/jboss/test/virtual/support/MockVFSContextFactory.java 2006-09-27 10:12:24 UTC (rev 57229)
+++ projects/microcontainer/trunk/container/src/tests/org/jboss/test/virtual/support/MockVFSContextFactory.java 2006-09-27 10:42:40 UTC (rev 57230)
@@ -0,0 +1,126 @@
+/*
+* 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;
+
+import java.io.IOException;
+import java.net.URI;
+import java.net.URL;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.jboss.util.NotImplementedException;
+import org.jboss.virtual.spi.VFSContext;
+import org.jboss.virtual.spi.VFSContextFactory;
+
+/**
+ * MockVFSContextFactory.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class MockVFSContextFactory implements VFSContextFactory
+{
+ /** The protocols */
+ public static final String[] protocols = { "mock" };
+
+ /** The contexts */
+ private Map<URI, VFSContext> contexts = new ConcurrentHashMap<URI, VFSContext>();
+
+ /** When to throw an IOException */
+ private String ioException = "";
+
+ public String[] getProtocols()
+ {
+ return protocols;
+ }
+
+ /**
+ * Set the ioException.
+ *
+ * @param ioException the ioException.
+ */
+ public void setIOException(String ioException)
+ {
+ this.ioException = ioException;
+ }
+
+ /**
+ * Check whether we should throw an IOException
+ *
+ * @param when when to throw
+ * @throws IOException when requested
+ */
+ public void throwIOException(String when) throws IOException
+ {
+ if (ioException.equals(when))
+ throw new IOException("Throwing IOException from " + when);
+ }
+
+ public VFSContext getVFS(URI rootURI) throws IOException
+ {
+ throwIOException("getVFSURI");
+ VFSContext context = contexts.get(rootURI);
+ if (context == null)
+ throw new IOException("No such context " + rootURI);
+ return context;
+ }
+
+ /**
+ * Add a context
+ *
+ * @param context the context
+ * @throws IllegalArgumentException for a null context
+ */
+ public void addVFSContext(VFSContext context)
+ {
+ if (context == null)
+ throw new IllegalArgumentException("Null context");
+ contexts.put(context.getRootURI(), context);
+ }
+
+ /**
+ * Remove a context
+ *
+ * @param context the context
+ * @throws IllegalArgumentException for a null context
+ */
+ public void removeVFSContext(VFSContext context)
+ {
+ if (context == null)
+ throw new IllegalArgumentException("Null context");
+ contexts.remove(context.getRootURI());
+ }
+
+ /**
+ * Reset
+ */
+ public void reset()
+ {
+ contexts.clear();
+ ioException = "";
+ }
+
+ public VFSContext getVFS(URL rootURL) throws IOException
+ {
+ throw new NotImplementedException("URLs are not implemented for the mock virtual file system");
+ }
+}
Added: projects/microcontainer/trunk/container/src/tests/org/jboss/test/virtual/support/MockVirtualFileFilter.java
===================================================================
--- projects/microcontainer/trunk/container/src/tests/org/jboss/test/virtual/support/MockVirtualFileFilter.java 2006-09-27 10:12:24 UTC (rev 57229)
+++ projects/microcontainer/trunk/container/src/tests/org/jboss/test/virtual/support/MockVirtualFileFilter.java 2006-09-27 10:42:40 UTC (rev 57230)
@@ -0,0 +1,75 @@
+/*
+* 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;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.virtual.VirtualFile;
+import org.jboss.virtual.VisitorAttributes;
+import org.jboss.virtual.plugins.vfs.helpers.AbstractVirtualFileFilterWithAttributes;
+
+/**
+ * MockVirtualFileFilter.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class MockVirtualFileFilter extends AbstractVirtualFileFilterWithAttributes
+{
+ /** The visited files */
+ private List<VirtualFile> visited = new ArrayList<VirtualFile>();
+
+ /**
+ * Create a new MockVirtualFileFilter.
+ */
+ public MockVirtualFileFilter()
+ {
+ super();
+ }
+
+ /**
+ * Create a new MockVirtualFileFilter.
+ *
+ * @param attributes the visitor attributes
+ */
+ public MockVirtualFileFilter(VisitorAttributes attributes)
+ {
+ super(attributes);
+ }
+
+ /**
+ * Get the visited files
+ *
+ * @return the files
+ */
+ public List<VirtualFile> getVisited()
+ {
+ return visited;
+ }
+
+ public boolean accepts(VirtualFile file)
+ {
+ visited.add(file);
+ return true;
+ }
+}
Added: projects/microcontainer/trunk/container/src/tests/org/jboss/test/virtual/test/AbstractMockVFSTest.java
===================================================================
--- projects/microcontainer/trunk/container/src/tests/org/jboss/test/virtual/test/AbstractMockVFSTest.java 2006-09-27 10:12:24 UTC (rev 57229)
+++ projects/microcontainer/trunk/container/src/tests/org/jboss/test/virtual/test/AbstractMockVFSTest.java 2006-09-27 10:42:40 UTC (rev 57230)
@@ -0,0 +1,190 @@
+/*
+* 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.io.IOException;
+import java.net.URI;
+
+import org.jboss.test.BaseTestCase;
+import org.jboss.test.virtual.support.MockSimpleVirtualFileHandler;
+import org.jboss.test.virtual.support.MockStructuredVirtualFileHandler;
+import org.jboss.test.virtual.support.MockVFSContext;
+import org.jboss.test.virtual.support.MockVFSContextFactory;
+import org.jboss.virtual.VFS;
+import org.jboss.virtual.VirtualFile;
+import org.jboss.virtual.spi.VFSContext;
+import org.jboss.virtual.spi.VFSContextFactoryLocator;
+import org.jboss.virtual.spi.VirtualFileHandler;
+
+/**
+ * AbstractMockVFSTest.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class AbstractMockVFSTest extends BaseTestCase
+{
+ /** The vfs context factory */
+ protected static MockVFSContextFactory mockVFSContextFactory = new MockVFSContextFactory();
+
+ /**
+ * Create a new AbstractMockVFSTest.
+ *
+ * @param name the name
+ */
+ protected AbstractMockVFSTest(String name)
+ {
+ super(name);
+ }
+
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ VFSContextFactoryLocator.registerFactory(mockVFSContextFactory);
+ }
+
+ protected void tearDown() throws Exception
+ {
+ mockVFSContextFactory.reset();
+ VFSContextFactoryLocator.unregisterFactory(mockVFSContextFactory);
+ super.tearDown();
+ }
+
+ protected MockVFSContext createSimpleVFSContext()
+ {
+ MockVFSContext context = new MockVFSContext("simple");
+ MockSimpleVirtualFileHandler root = new MockSimpleVirtualFileHandler(context, null, "");
+ context.setRoot(root);
+ return context;
+ }
+
+ protected MockVFSContext registerSimpleVFSContext()
+ {
+ MockVFSContext context = createSimpleVFSContext();
+ mockVFSContextFactory.addVFSContext(context);
+ return context;
+ }
+
+ protected MockVFSContext createSimple2VFSContext()
+ {
+ MockVFSContext context = new MockVFSContext("simple2");
+ MockSimpleVirtualFileHandler root = new MockSimpleVirtualFileHandler(context, null, "");
+ context.setRoot(root);
+ return context;
+ }
+
+ protected MockVFSContext registerSimple2VFSContext()
+ {
+ MockVFSContext context = createSimple2VFSContext();
+ mockVFSContextFactory.addVFSContext(context);
+ return context;
+ }
+
+ protected MockVFSContext createSimpleVFSContextWithChildren()
+ {
+ MockVFSContext context = new MockVFSContext("simpleWithChildren");
+ MockSimpleVirtualFileHandler root = new MockSimpleVirtualFileHandler(context, null, "");
+ context.setRoot(root);
+ new MockSimpleVirtualFileHandler(context, root, "child1");
+ new MockSimpleVirtualFileHandler(context, root, "child2");
+ new MockSimpleVirtualFileHandler(context, root, "child3");
+ return context;
+ }
+
+ protected MockVFSContext registerSimpleVFSContextWithChildren()
+ {
+ MockVFSContext context = createSimpleVFSContextWithChildren();
+ mockVFSContextFactory.addVFSContext(context);
+ return context;
+ }
+
+ protected MockVFSContext createStructuredVFSContextWithSubChildren()
+ {
+ MockVFSContext context = new MockVFSContext("simpleWithChildren");
+ MockStructuredVirtualFileHandler root = new MockStructuredVirtualFileHandler(context, null, "");
+ context.setRoot(root);
+ MockStructuredVirtualFileHandler child1 = new MockStructuredVirtualFileHandler(context, root, "child1");
+ new MockStructuredVirtualFileHandler(context, child1, "child1,1");
+ MockStructuredVirtualFileHandler child2 = new MockStructuredVirtualFileHandler(context, root, "child2");
+ new MockStructuredVirtualFileHandler(context, child2, "child2,1");
+ new MockStructuredVirtualFileHandler(context, child2, "child2,2");
+ MockStructuredVirtualFileHandler child3 = new MockStructuredVirtualFileHandler(context, root, "child3");
+ new MockStructuredVirtualFileHandler(context, child3, "child3,1");
+ new MockStructuredVirtualFileHandler(context, child3, "child3,2");
+ new MockStructuredVirtualFileHandler(context, child3, "child3,3");
+ return context;
+ }
+
+ protected MockVFSContext registerStructuredVFSContextWithSubChildren()
+ {
+ MockVFSContext context = createStructuredVFSContextWithSubChildren();
+ mockVFSContextFactory.addVFSContext(context);
+ return context;
+ }
+
+ protected VirtualFileHandler getChildHandler(VFSContext context, String path) throws IOException
+ {
+ if (context == null)
+ throw new IllegalArgumentException("Null context");
+ if (path == null)
+ throw new IllegalArgumentException("Null path");
+
+ VirtualFileHandler root = context.getRoot();
+ assertNotNull(root);
+ VirtualFileHandler handler = context.findChild(root, path);
+ assertNotNull(handler);
+ return handler;
+ }
+
+ protected void assertGetName(URI uri, String name) throws Exception
+ {
+ assertGetName(uri, name, name);
+ }
+
+ protected void assertGetName(URI uri, String path, String name) throws Exception
+ {
+ VirtualFile file = VFS.getVirtualFile(uri, path);
+ assertEquals(name, file.getName());
+ }
+
+ protected void assertGetPathName(URI uri, String path) throws Exception
+ {
+ VirtualFile file = VFS.getVirtualFile(uri, path);
+ assertEquals(path, file.getPathName());
+ }
+
+ protected VirtualFile assertFindChild(VFS vfs, String path, VirtualFile expected) throws Exception
+ {
+ VirtualFile found = vfs.findChild(path);
+ assertNotNull(found);
+ assertEquals(expected, found);
+ return found;
+ }
+
+ protected VirtualFile assertFindChild(VirtualFile file, String path, VirtualFile expected) throws Exception
+ {
+ VirtualFile found = file.findChild(path);
+ assertNotNull(found);
+ assertEquals(expected, found);
+ return found;
+ }
+}
Modified: projects/microcontainer/trunk/container/src/tests/org/jboss/test/virtual/test/FileVFSUnitTestCase.java
===================================================================
--- projects/microcontainer/trunk/container/src/tests/org/jboss/test/virtual/test/FileVFSUnitTestCase.java 2006-09-27 10:12:24 UTC (rev 57229)
+++ projects/microcontainer/trunk/container/src/tests/org/jboss/test/virtual/test/FileVFSUnitTestCase.java 2006-09-27 10:42:40 UTC (rev 57230)
@@ -131,7 +131,7 @@
{
URL rootURL = getResource("/vfs/test");
VFS vfs = VFS.getVFS(rootURL);
- VirtualFile jar = vfs.findChildFromRoot("outer.jar");
+ VirtualFile jar = vfs.findChild("outer.jar");
assertTrue("outer.jar != null", jar != null);
/*
@@ -155,7 +155,7 @@
{
URL rootURL = getResource("/vfs/test");
VFS vfs = VFS.getVFS(rootURL);
- VirtualFile jar = vfs.findChildFromRoot("unpacked-outer.jar");
+ VirtualFile jar = vfs.findChild("unpacked-outer.jar");
assertTrue("unpacked-outer.jar != null", jar != null);
/**
@@ -186,24 +186,24 @@
VFS vfs = VFS.getVFS(rootURL);
// Check resolving the root file
- VirtualFile root = vfs.findChildFromRoot("");
+ VirtualFile root = vfs.findChild("");
assertEquals("root name", "test", root.getName());
assertEquals("root path", "", root.getPathName());
assertTrue("root isDirectory", root.isDirectory());
// Find the outer.jar
- VirtualFile outerJar = vfs.findChildFromRoot("outer.jar");
+ VirtualFile outerJar = vfs.findChild("outer.jar");
assertNotNull("outer.jar", outerJar);
assertEquals("outer.jar name", "outer.jar", outerJar.getName());
assertEquals("outer.jar path", "outer.jar", outerJar.getPathName());
- VirtualFile outerJarMF = vfs.findChildFromRoot("outer.jar/META-INF/MANIFEST.MF");
+ VirtualFile outerJarMF = vfs.findChild("outer.jar/META-INF/MANIFEST.MF");
assertNotNull("outer.jar/META-INF/MANIFEST.MF", outerJarMF);
// Test a non-canonical path
rootURL = getResource("/vfs/sundry/../test");
// Check resolving the root file
- root = vfs.findChildFromRoot("");
+ root = vfs.findChild("");
assertEquals("root name", "test", root.getName());
assertEquals("root path", "", root.getPathName());
assertTrue("root isDirectory", root.isDirectory());
@@ -223,7 +223,7 @@
VFS vfs = VFS.getVFS(rootURL);
// Find ClassInJar1.class
- VirtualFile vf = vfs.findChildFromRoot("jar1.jar");
+ VirtualFile vf = vfs.findChild("jar1.jar");
VirtualFile c1 = vf.findChild("org/jboss/test/vfs/support/jar1/ClassInJar1.class");
assertNotNull("ClassInJar1.class VF", c1);
log.debug("Found ClassInJar1.class: "+c1);
@@ -234,7 +234,7 @@
log.debug("Found ClassInJar1$InnerClass.class: "+c1i);
// Find ClassInJar2.class
- vf = vfs.findChildFromRoot("jar2.jar");
+ vf = vfs.findChild("jar2.jar");
VirtualFile c2 = vf.findChild("org/jboss/test/vfs/support/jar2/ClassInJar2.class");
assertNotNull("ClassInJar2.class VF", c2);
log.debug("Found ClassInJar2.class: "+c2);
@@ -248,24 +248,24 @@
VFS vfs = VFS.getVFS(rootURL);
// Check resolving the root file
- VirtualFile root = vfs.findChildFromRoot("");
+ VirtualFile root = vfs.findChild("");
assertEquals("root name", "test", root.getName());
assertEquals("root path", "", root.getPathName());
assertTrue("root isDirectory", root.isDirectory());
// Find the outer.jar
- VirtualFile outerJar = vfs.findChildFromRoot("unpacked-outer.jar");
+ VirtualFile outerJar = vfs.findChild("unpacked-outer.jar");
assertNotNull("unpacked-outer.jar", outerJar);
assertEquals("unpacked-outer.jar name", "unpacked-outer.jar", outerJar.getName());
assertEquals("unpacked-outer.jar path", "unpacked-outer.jar", outerJar.getPathName());
- VirtualFile outerJarMF = vfs.findChildFromRoot("unpacked-outer.jar/META-INF/MANIFEST.MF");
+ VirtualFile outerJarMF = vfs.findChild("unpacked-outer.jar/META-INF/MANIFEST.MF");
assertNotNull("unpacked-outer.jar/META-INF/MANIFEST.MF", outerJarMF);
// Test a non-canonical path
rootURL = getResource("/test/sundry/../test");
// Check resolving the root file
- root = vfs.findChildFromRoot("");
+ root = vfs.findChild("");
assertEquals("root name", "test", root.getName());
assertEquals("root path", "", root.getPathName());
assertTrue("root isDirectory", root.isDirectory());
@@ -280,7 +280,7 @@
{
URL rootURL = getResource("/vfs/test");
VFS vfs = VFS.getVFS(rootURL);
- VirtualFile inner = vfs.findChildFromRoot("outer.jar/jar1.jar");
+ VirtualFile inner = vfs.findChild("outer.jar/jar1.jar");
log.info("IsFile: "+inner.isFile());
log.info(inner.getLastModified());
List<VirtualFile> contents = inner.getChildren();
@@ -290,7 +290,7 @@
{
log.info(" "+vf.getName());
}
- VirtualFile vf = vfs.findChildFromRoot("outer.jar/jar1.jar");
+ VirtualFile vf = vfs.findChild("outer.jar/jar1.jar");
VirtualFile jar1MF = vf.findChild("META-INF/MANIFEST.MF");
InputStream mfIS = jar1MF.openStream();
Manifest mf = new Manifest(mfIS);
@@ -347,7 +347,7 @@
log.info("+++ testVFSerialization, tmp="+tmp.getCanonicalPath());
URL rootURL = tmpRoot.toURL();
VFS vfs = VFS.getVFS(rootURL);
- VirtualFile tmpVF = vfs.findChildFromRoot("vfs.ser");
+ VirtualFile tmpVF = vfs.findChild("vfs.ser");
FileOutputStream fos = new FileOutputStream(tmp);
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(tmpVF);
@@ -424,7 +424,7 @@
vfsSer.createNewFile();
vfsSer.deleteOnExit();
- VirtualFile tmpVF = vfs.findChildFromRoot("tst.jar");
+ VirtualFile tmpVF = vfs.findChild("tst.jar");
// Validate the vf jar against the tmp file attributes
long lastModified = tmpJar.lastModified();
long size = tmpJar.length();
@@ -482,7 +482,7 @@
// this expects to be run with a working dir of the container root
URL rootURL = getResource("/vfs/test");
VFS vfs = VFS.getVFS(rootURL);
- VirtualFile inner = vfs.findChildFromRoot("outer.jar/jar1.jar");
+ VirtualFile inner = vfs.findChild("outer.jar/jar1.jar");
File vfsSer = File.createTempFile("testVFNestedJarSerialization", ".ser");
vfsSer.deleteOnExit();
@@ -505,7 +505,7 @@
{
log.info(" "+vf.getName());
}
- VirtualFile vf = vfs.findChildFromRoot("outer.jar/jar1.jar");
+ VirtualFile vf = vfs.findChild("outer.jar/jar1.jar");
VirtualFile jar1MF = vf.findChild("META-INF/MANIFEST.MF");
InputStream mfIS = jar1MF.openStream();
Manifest mf = new Manifest(mfIS);
@@ -579,7 +579,7 @@
VFS vfs = VFS.getVFS(vfsRoot.toURI());
// We should find the test-link.war the link represents
- VirtualFile war = vfs.findChildFromRoot("test-link.war");
+ VirtualFile war = vfs.findChild("test-link.war");
assertNotNull("war", war);
// Validate the WEB-INF/classes child link
@@ -619,7 +619,7 @@
URL rootURL = getResource("/vfs/test");
VFS vfs = VFS.getVFS(rootURL);
- VirtualFile outerJar = vfs.findChildFromRoot("unpacked-outer.jar");
+ VirtualFile outerJar = vfs.findChild("unpacked-outer.jar");
URL outerURL = outerJar.toURL();
log.debug("outerURL: "+outerURL);
assertTrue(outerURL+" ends in '/'", outerURL.getPath().endsWith("/"));
Modified: projects/microcontainer/trunk/container/src/tests/org/jboss/test/virtual/test/TestClassLoading.java
===================================================================
--- projects/microcontainer/trunk/container/src/tests/org/jboss/test/virtual/test/TestClassLoading.java 2006-09-27 10:12:24 UTC (rev 57229)
+++ projects/microcontainer/trunk/container/src/tests/org/jboss/test/virtual/test/TestClassLoading.java 2006-09-27 10:42:40 UTC (rev 57230)
@@ -1,11 +1,11 @@
package org.jboss.test.virtual.test;
-import java.io.File;
import java.net.URL;
import org.jboss.test.BaseTestCase;
import org.jboss.virtual.VFS;
import org.jboss.virtual.classloading.VFSClassLoader;
+import org.jboss.virtual.plugins.context.jar.JarUtils;
public class TestClassLoading extends BaseTestCase
{
@@ -18,9 +18,8 @@
throws Exception
{
super.enableTrace("org.jboss");
- File libDir = new File("output/lib");
- URL libURL = libDir.toURL();
- VFS vfs = VFS.getVFS(libURL);
+ URL url = getResource("/vfs/test/");
+ VFS vfs = VFS.getVFS(url);
String[] searchCtxts = {"jar1.jar"};
ClassLoader parent = null;
@@ -28,7 +27,11 @@
URL mf = cl.findResource("META-INF/MANIFEST.MF");
assertTrue("META-INF/application.xml != null", mf != null);
log.info(mf);
- assertEquals("jar:file:/C:/svn/JBossMC/jbossmc/container/output/lib/jar1.jar!/META-INF/MANIFEST.MF", mf.toString());
+
+ URL expected = new URL(url, "jar1.jar");
+ expected = JarUtils.createJarURL(expected);
+ expected = new URL(expected, "META-INF/MANIFEST.MF");
+ assertEquals(expected, mf);
Class c = cl.loadClass("org.jboss.test.vfs.support.jar1.ClassInJar1");
assertEquals("org.jboss.test.vfs.support.jar1.ClassInJar1", c.getName());
Modified: projects/microcontainer/trunk/container/src/tests/org/jboss/test/virtual/test/VFSAllTestSuite.java
===================================================================
--- projects/microcontainer/trunk/container/src/tests/org/jboss/test/virtual/test/VFSAllTestSuite.java 2006-09-27 10:12:24 UTC (rev 57229)
+++ projects/microcontainer/trunk/container/src/tests/org/jboss/test/virtual/test/VFSAllTestSuite.java 2006-09-27 10:42:40 UTC (rev 57230)
@@ -42,6 +42,8 @@
{
TestSuite suite = new TestSuite("VFS Tests");
+ suite.addTest(VFSUnitTestCase.suite());
+ suite.addTest(VirtualFileUnitTestCase.suite());
suite.addTest(FileVFSUnitTestCase.suite());
suite.addTest(SundryVFSUnitTestCase.suite());
Added: projects/microcontainer/trunk/container/src/tests/org/jboss/test/virtual/test/VFSUnitTestCase.java
===================================================================
--- projects/microcontainer/trunk/container/src/tests/org/jboss/test/virtual/test/VFSUnitTestCase.java 2006-09-27 10:12:24 UTC (rev 57229)
+++ projects/microcontainer/trunk/container/src/tests/org/jboss/test/virtual/test/VFSUnitTestCase.java 2006-09-27 10:42:40 UTC (rev 57230)
@@ -0,0 +1,1392 @@
+/*
+* 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.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.MockVFSContext;
+import org.jboss.test.virtual.support.MockVirtualFileFilter;
+import org.jboss.virtual.VFS;
+import org.jboss.virtual.VirtualFile;
+import org.jboss.virtual.plugins.vfs.helpers.FilterVirtualFileVisitor;
+
+/**
+ * VFSUnitTestCase.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class VFSUnitTestCase extends AbstractMockVFSTest
+{
+ public VFSUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public static Test suite()
+ {
+ return new TestSuite(VFSUnitTestCase.class);
+ }
+
+ public void testGetVFSURI() throws Exception
+ {
+ MockVFSContext context = registerSimpleVFSContext();
+ MockVFSContext context2 = registerSimple2VFSContext();
+
+ VFS vfs = VFS.getVFS(context.getRootURI());
+ assertNotNull(vfs);
+ assertEquals(context.getVFS(), vfs);
+
+ VFS vfs2 = VFS.getVFS(context2.getRootURI());
+ assertNotNull(vfs2);
+ assertEquals(context2.getVFS(), vfs2);
+ }
+
+ public void testGetVFSURINull() throws Exception
+ {
+ try
+ {
+ VFS.getVFS((URI) null);
+ fail("Should not be here");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalArgumentException.class, t);
+ }
+ }
+
+ public void testGetVFSURINoFactory() throws Exception
+ {
+ try
+ {
+ URI uri = new URI("doesnotexist:///");
+ VFS.getVFS(uri);
+ fail("Should not be here");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IOException.class, t);
+ }
+ }
+
+ 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);
+ }
+ }
+
+ /* TODO URL testing
+ public void testGetVFSURL() throws Exception
+ {
+ MockVFSContext context = registerSimpleVFSContext();
+ MockVFSContext context2 = registerSimple2VFSContext();
+
+ VFS vfs = VFS.getVFS(context.getRootURI().toURL());
+ assertNotNull(vfs);
+ assertEquals(context.getVFS(), vfs);
+
+ VFS vfs2 = VFS.getVFS(context2.getRootURI().toURL());
+ assertNotNull(vfs2);
+ assertEquals(context2.getVFS(), vfs2);
+ }
+ */
+
+ public void testGetVFSURLNull() throws Exception
+ {
+ try
+ {
+ VFS.getVFS((URL) null);
+ fail("Should not be here");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalArgumentException.class, t);
+ }
+ }
+
+ /* TODO URL Testing
+ public void testGetVFSURLNoFactory() throws Exception
+ {
+ try
+ {
+ URL url = new URL("doesnotexist:///");
+ 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.getRootURI().toURL());
+ 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("findChild");
+
+ try
+ {
+ VFS.getVirtualFile(context.getRootURI(), "child1");
+ fail("Should not be here");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IOException.class, t);
+ }
+ }
+
+ /* TODO URL testing
+ public void testGetRootURL() throws Exception
+ {
+ MockVFSContext context = registerSimpleVFSContextWithChildren();
+
+ VirtualFile file = VFS.getRoot(context.getRootURI().toURL());
+ 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);
+ }
+ }
+
+ /* TODO URL testing
+ public void testGetRootURLNoFactory() throws Exception
+ {
+ URL url = new URL("doesnotexist:///");
+ 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.getRootURI().toURL();
+ 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.getRootURI().toURL();
+ 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.getRootURI().toURL(), "");
+ 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.getRootURI().toURL(), "child1");
+ assertNotNull(file1);
+ assertEquals(child1, file1);
+
+ VirtualFile file2 = VFS.getVirtualFile(context.getRootURI().toURL(), "child2");
+ assertNotNull(file2);
+ assertEquals(child2, file2);
+
+ VirtualFile file3 = VFS.getVirtualFile(context.getRootURI().toURL(), "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);
+ }
+ }
+
+ /* TODO URL testing
+ public void testGetVirtualFileURLNullPath() throws Exception
+ {
+ MockVFSContext context = registerSimpleVFSContextWithChildren();
+
+ try
+ {
+ VFS.getVirtualFile(context.getRootURI().toURL(), null);
+ fail("Should not be here");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalArgumentException.class, t);
+ }
+ }
+
+ public void testGetVirtualFileURLNoFactory() throws Exception
+ {
+ try
+ {
+ URL uri = new URL("doesnotexist:///");
+ VFS.getVirtualFile(uri, "");
+ 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.getRootURI().toURL(), "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("findChild");
+
+ 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().setDirectory(true);
+
+ 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 testFindChildSimpleDoesNotExist() throws Exception
+ {
+ MockVFSContext context = registerSimpleVFSContextWithChildren();
+
+ try
+ {
+ VFS vfs = VFS.getVFS(context.getRootURI());
+ vfs.findChild("doesnotexist");
+ fail("Should not be here");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IOException.class, t);
+ }
+ }
+
+ public void testFindChildStructuredDoesNotExist() throws Exception
+ {
+ MockVFSContext context = registerStructuredVFSContextWithSubChildren();
+
+ try
+ {
+ VFS vfs = VFS.getVFS(context.getRootURI());
+ vfs.findChild("child1/doesnotexist");
+ fail("Should not be here");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IOException.class, t);
+ }
+ }
+
+ public void testFindChildIOException() throws Exception
+ {
+ MockVFSContext context = registerSimpleVFSContextWithChildren();
+ context.getMockRoot().setIOException("findChild");
+
+ try
+ {
+ VFS vfs = VFS.getVFS(context.getRootURI());
+ vfs.findChild("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().setDirectory(true);
+
+ VFS vfs = VFS.getVFS(context.getRootURI());
+ List<VirtualFile> children = vfs.getChildren();
+ assertNotNull(children);
+
+ assertEmpty(children);
+ }
+
+ public void testGetAllChildrenNotADirectory() throws Exception
+ {
+ MockVFSContext context = registerSimpleVFSContext();
+
+ VFS vfs = VFS.getVFS(context.getRootURI());
+ try
+ {
+ vfs.getChildren();
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalStateException.class, t);
+ }
+ }
+
+ 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().setDirectory(true);
+
+ VFS vfs = VFS.getVFS(context.getRootURI());
+ List<VirtualFile> children = vfs.getChildren(null);
+ assertNotNull(children);
+
+ assertEmpty(children);
+ }
+
+ public void testGetAllChildrenWithNullFilterNotADirectory() throws Exception
+ {
+ MockVFSContext context = registerSimpleVFSContext();
+
+ VFS vfs = VFS.getVFS(context.getRootURI());
+ try
+ {
+ vfs.getChildren(null);
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalStateException.class, t);
+ }
+ }
+
+ 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().setDirectory(true);
+
+ 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 testGetAllChildrenWithFilterNotADirectory() throws Exception
+ {
+ MockVFSContext context = registerSimpleVFSContext();
+
+ VFS vfs = VFS.getVFS(context.getRootURI());
+ MockVirtualFileFilter filter = new MockVirtualFileFilter();
+ try
+ {
+ vfs.getChildren(filter);
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalStateException.class, t);
+ }
+ }
+
+ 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().setDirectory(true);
+
+ VFS vfs = VFS.getVFS(context.getRootURI());
+ List<VirtualFile> children = vfs.getChildrenRecursively();
+ assertNotNull(children);
+
+ assertEmpty(children);
+ }
+
+ public void testGetAllChildrenRecursivelyNotADirectory() throws Exception
+ {
+ MockVFSContext context = registerSimpleVFSContext();
+
+ VFS vfs = VFS.getVFS(context.getRootURI());
+ try
+ {
+ vfs.getChildrenRecursively();
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalStateException.class, t);
+ }
+ }
+
+ 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().setDirectory(true);
+
+ VFS vfs = VFS.getVFS(context.getRootURI());
+ List<VirtualFile> children = vfs.getChildrenRecursively(null);
+ assertNotNull(children);
+
+ assertEmpty(children);
+ }
+
+ public void testGetAllChildrenRecursivelyWithNullFilterNotADirectory() throws Exception
+ {
+ MockVFSContext context = registerSimpleVFSContext();
+
+ VFS vfs = VFS.getVFS(context.getRootURI());
+ try
+ {
+ vfs.getChildrenRecursively(null);
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalStateException.class, t);
+ }
+ }
+
+ 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().setDirectory(true);
+
+ 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 testGetAllChildrenRecursivelyWithFilterNotADirectory() throws Exception
+ {
+ MockVFSContext context = registerSimpleVFSContext();
+
+ VFS vfs = VFS.getVFS(context.getRootURI());
+ MockVirtualFileFilter filter = new MockVirtualFileFilter();
+ try
+ {
+ vfs.getChildren(filter);
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalStateException.class, t);
+ }
+ }
+
+ 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().setDirectory(true);
+
+ VFS vfs = VFS.getVFS(context.getRootURI());
+ MockVirtualFileFilter filter = new MockVirtualFileFilter();
+ FilterVirtualFileVisitor visitor = new FilterVirtualFileVisitor(filter);
+ vfs.visit(visitor);
+
+ assertEmpty(filter.getVisited());
+ }
+
+ public void testVisitAllChildrenNotADirectory() throws Exception
+ {
+ MockVFSContext context = registerSimpleVFSContext();
+
+ 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(IllegalStateException.class, t);
+ }
+ }
+
+ 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()));
+ }
+}
Added: projects/microcontainer/trunk/container/src/tests/org/jboss/test/virtual/test/VirtualFileUnitTestCase.java
===================================================================
--- projects/microcontainer/trunk/container/src/tests/org/jboss/test/virtual/test/VirtualFileUnitTestCase.java 2006-09-27 10:12:24 UTC (rev 57229)
+++ projects/microcontainer/trunk/container/src/tests/org/jboss/test/virtual/test/VirtualFileUnitTestCase.java 2006-09-27 10:42:40 UTC (rev 57230)
@@ -0,0 +1,1440 @@
+/*
+* 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.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+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.plugins.vfs.helpers.FilterVirtualFileVisitor;
+import org.jboss.virtual.spi.VirtualFileHandler;
+
+/**
+ * VirtualFileUnitTestCase.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class VirtualFileUnitTestCase extends AbstractMockVFSTest
+{
+ public VirtualFileUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public static Test suite()
+ {
+ return new TestSuite(VirtualFileUnitTestCase.class);
+ }
+
+ public void testGetNameRoot() throws Exception
+ {
+ MockVFSContext context = registerSimpleVFSContextWithChildren();
+
+ URI uri = context.getRootURI();
+ assertGetName(uri, "");
+ }
+
+ public void testGetNameChildren() throws Exception
+ {
+ MockVFSContext context = registerSimpleVFSContextWithChildren();
+
+ URI uri = context.getRootURI();
+ assertGetName(uri, "child1");
+ assertGetName(uri, "child2");
+ assertGetName(uri, "child3");
+ }
+
+ public void testGetNameSubChildren() throws Exception
+ {
+ MockVFSContext context = registerStructuredVFSContextWithSubChildren();
+
+ URI uri = context.getRootURI();
+ assertGetName(uri, "child1/child1,1", "child1,1");
+ assertGetName(uri, "child2/child2,1", "child2,1");
+ assertGetName(uri, "child2/child2,2", "child2,2");
+ assertGetName(uri, "child3/child3,1", "child3,1");
+ assertGetName(uri, "child3/child3,2", "child3,2");
+ assertGetName(uri, "child3/child3,3", "child3,3");
+ }
+
+ public void testGetPathNameRoot() throws Exception
+ {
+ MockVFSContext context = registerSimpleVFSContext();
+
+ URI uri = context.getRootURI();
+ assertGetPathName(uri, "");
+ }
+
+ public void testGetPathNameChildren() throws Exception
+ {
+ MockVFSContext context = registerSimpleVFSContextWithChildren();
+
+ URI uri = context.getRootURI();
+ assertGetPathName(uri, "");
+ assertGetPathName(uri, "child1");
+ assertGetPathName(uri, "child2");
+ assertGetPathName(uri, "child3");
+ }
+
+ public void testGetPathNameSubChildren() throws Exception
+ {
+ MockVFSContext context = registerStructuredVFSContextWithSubChildren();
+
+ URI uri = context.getRootURI();
+ assertGetPathName(uri, "");
+ assertGetPathName(uri, "child1");
+ assertGetPathName(uri, "child1/child1,1");
+ assertGetPathName(uri, "child2");
+ assertGetPathName(uri, "child2/child2,1");
+ assertGetPathName(uri, "child2/child2,2");
+ assertGetPathName(uri, "child3");
+ assertGetPathName(uri, "child3/child3,1");
+ assertGetPathName(uri, "child3/child3,2");
+ assertGetPathName(uri, "child3/child3,3");
+ }
+
+ public void testToURI() throws Exception
+ {
+ MockVFSContext context = registerStructuredVFSContextWithSubChildren();
+ URI uri = context.getRootURI();
+ VirtualFile child1 = getChildHandler(context, "child1").getVirtualFile();
+ VirtualFile child11 = getChildHandler(context, "child1/child1,1").getVirtualFile();
+
+ VirtualFile root = VFS.getRoot(uri);
+ assertEquals(uri, root.toURI());
+
+ VirtualFile found1 = root.findChild("child1");
+ assertEquals(child1.toURI(), found1.toURI());
+
+ VirtualFile found11 = root.findChild("child1/child1,1");
+ assertEquals(child11.toURI(), found11.toURI());
+ }
+
+ /* TODO URL testing
+ public void testToURL() throws Exception
+ {
+ MockVFSContext context = registerStructuredVFSContextWithSubChildren();
+ URL url = context.getRootURI().toURL();
+ VirtualFile child1 = getChildHandler(context, "child1").getVirtualFile();
+ VirtualFile child11 = getChildHandler(context, "child1/child1,1").getVirtualFile();
+
+ VirtualFile root = VFS.getRoot(url);
+ assertEquals(url, root.toURL());
+
+ VirtualFile found1 = root.findChild("child1");
+ assertEquals(child1.toURL(), found1.toURL());
+
+ VirtualFile found11 = root.findChild("child1/child1,1");
+ assertEquals(child11.toURL(), found11.toURL());
+ }
+ */
+
+ public void testGetLastModfied() throws Exception
+ {
+ MockVFSContext context = registerSimpleVFSContext();
+ context.getMockRoot().setLastModified(12345l);
+
+ VirtualFile file = VFS.getRoot(context.getRootURI());
+ assertEquals(12345l, file.getLastModified());
+
+ context.getMockRoot().setLastModified(67890l);
+ assertEquals(67890l, file.getLastModified());
+ }
+
+ public void testGetLastModfiedIOException() throws Exception
+ {
+ MockVFSContext context = registerSimpleVFSContext();
+ context.getMockRoot().setIOException("getLastModified");
+
+ VirtualFile file = VFS.getRoot(context.getRootURI());
+ try
+ {
+ file.getLastModified();
+ fail("Should not be here");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IOException.class, t);
+ }
+ }
+
+ public void testGetLastModfiedClosed() throws Exception
+ {
+ MockVFSContext context = registerSimpleVFSContext();
+
+ VirtualFile file = VFS.getRoot(context.getRootURI());
+ file.close();
+ try
+ {
+ file.getLastModified();
+ fail("Should not be here");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalStateException.class, t);
+ }
+ }
+
+ public void testGetSize() throws Exception
+ {
+ MockVFSContext context = registerSimpleVFSContext();
+ context.getMockRoot().setSize(12345l);
+
+ VirtualFile file = VFS.getRoot(context.getRootURI());
+ assertEquals(12345l, file.getSize());
+
+ context.getMockRoot().setSize(67890l);
+ assertEquals(67890l, file.getSize());
+ }
+
+ public void testGetSizeIOException() throws Exception
+ {
+ MockVFSContext context = registerSimpleVFSContext();
+ context.getMockRoot().setIOException("getSize");
+
+ VirtualFile file = VFS.getRoot(context.getRootURI());
+ try
+ {
+ file.getSize();
+ fail("Should not be here");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IOException.class, t);
+ }
+ }
+
+ public void testGetSizeClosed() throws Exception
+ {
+ MockVFSContext context = registerSimpleVFSContext();
+
+ VirtualFile file = VFS.getRoot(context.getRootURI());
+ file.close();
+ try
+ {
+ file.getSize();
+ fail("Should not be here");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalStateException.class, t);
+ }
+ }
+
+ public void testIsDirectory() throws Exception
+ {
+ MockVFSContext context = registerSimpleVFSContext();
+ context.getMockRoot().setDirectory(true);
+
+ VirtualFile file = VFS.getRoot(context.getRootURI());
+ assertEquals(true, file.isDirectory());
+
+ context.getMockRoot().setDirectory(false);
+ assertEquals(false, file.isDirectory());
+ }
+
+ public void testIsDirectoryIOException() throws Exception
+ {
+ MockVFSContext context = registerSimpleVFSContext();
+ context.getMockRoot().setIOException("isDirectory");
+
+ VirtualFile file = VFS.getRoot(context.getRootURI());
+ try
+ {
+ file.isDirectory();
+ fail("Should not be here");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IOException.class, t);
+ }
+ }
+
+ public void testIsDirectoryClosed() throws Exception
+ {
+ MockVFSContext context = registerSimpleVFSContext();
+
+ VirtualFile file = VFS.getRoot(context.getRootURI());
+ file.close();
+ try
+ {
+ file.isDirectory();
+ fail("Should not be here");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalStateException.class, t);
+ }
+ }
+
+ public void testIsFile() throws Exception
+ {
+ MockVFSContext context = registerSimpleVFSContext();
+ context.getMockRoot().setDirectory(true);
+
+ VirtualFile file = VFS.getRoot(context.getRootURI());
+ assertEquals(false, file.isFile());
+
+ context.getMockRoot().setDirectory(false);
+ assertEquals(true, file.isFile());
+ }
+
+ public void testIsFileIOException() throws Exception
+ {
+ MockVFSContext context = registerSimpleVFSContext();
+ context.getMockRoot().setIOException("isFile");
+
+ VirtualFile file = VFS.getRoot(context.getRootURI());
+ try
+ {
+ file.isFile();
+ fail("Should not be here");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IOException.class, t);
+ }
+ }
+
+ public void testIsFileClosed() throws Exception
+ {
+ MockVFSContext context = registerSimpleVFSContext();
+
+ VirtualFile file = VFS.getRoot(context.getRootURI());
+ file.close();
+ try
+ {
+ file.isFile();
+ fail("Should not be here");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalStateException.class, t);
+ }
+ }
+
+ public void testIsArchive() throws Exception
+ {
+ MockVFSContext context = registerSimpleVFSContext();
+ context.getMockRoot().setArchive(true);
+
+ VirtualFile file = VFS.getRoot(context.getRootURI());
+ assertEquals(true, file.isArchive());
+
+ context.getMockRoot().setArchive(false);
+ assertEquals(false, file.isArchive());
+ }
+
+ public void testIsArchiveIOException() throws Exception
+ {
+ MockVFSContext context = registerSimpleVFSContext();
+ context.getMockRoot().setIOException("isArchive");
+
+ VirtualFile file = VFS.getRoot(context.getRootURI());
+ try
+ {
+ file.isArchive();
+ fail("Should not be here");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IOException.class, t);
+ }
+ }
+
+ public void testIsArchiveClosed() throws Exception
+ {
+ MockVFSContext context = registerSimpleVFSContext();
+
+ VirtualFile file = VFS.getRoot(context.getRootURI());
+ file.close();
+ try
+ {
+ file.isArchive();
+ fail("Should not be here");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalStateException.class, t);
+ }
+ }
+
+ public void testIsHidden() throws Exception
+ {
+ MockVFSContext context = registerSimpleVFSContext();
+ context.getMockRoot().setHidden(true);
+
+ VirtualFile file = VFS.getRoot(context.getRootURI());
+ assertEquals(true, file.isHidden());
+
+ context.getMockRoot().setHidden(false);
+ assertEquals(false, file.isHidden());
+ }
+
+ public void testIsHiddenIOException() throws Exception
+ {
+ MockVFSContext context = registerSimpleVFSContext();
+ context.getMockRoot().setIOException("isHidden");
+
+ VirtualFile file = VFS.getRoot(context.getRootURI());
+ try
+ {
+ file.isHidden();
+ fail("Should not be here");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IOException.class, t);
+ }
+ }
+
+ public void testIsHiddenClosed() throws Exception
+ {
+ MockVFSContext context = registerSimpleVFSContext();
+
+ VirtualFile file = VFS.getRoot(context.getRootURI());
+ file.close();
+ try
+ {
+ file.isHidden();
+ fail("Should not be here");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalStateException.class, t);
+ }
+ }
+
+ public void testOpenStream() throws Exception
+ {
+ byte[] bytes = new byte[] { 1, 2, 3, 4, 5 };
+ MockVFSContext context = registerSimpleVFSContext();
+ context.getMockRoot().setStream(bytes);
+
+ VirtualFile file = VFS.getRoot(context.getRootURI());
+ InputStream stream = file.openStream();
+ byte[] buffer = new byte[bytes.length];
+ stream.read(buffer);
+
+ assertTrue(stream.read() == -1);
+ assertTrue(Arrays.equals(bytes, buffer));
+ }
+
+ public void testOpenStreamIOException() throws Exception
+ {
+ MockVFSContext context = registerSimpleVFSContext();
+ context.getMockRoot().setIOException("openStream");
+
+ VirtualFile file = VFS.getRoot(context.getRootURI());
+ try
+ {
+ file.openStream();
+ fail("Should not be here");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IOException.class, t);
+ }
+ }
+
+ public void testOpenStreamClosed() throws Exception
+ {
+ MockVFSContext context = registerSimpleVFSContext();
+
+ VirtualFile file = VFS.getRoot(context.getRootURI());
+ file.close();
+ try
+ {
+ file.openStream();
+ fail("Should not be here");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalStateException.class, t);
+ }
+ }
+
+ public void testCloseStreams() throws Exception
+ {
+ byte[] bytes = new byte[] { 1, 2, 3, 4, 5 };
+ MockVFSContext context = registerSimpleVFSContext();
+ context.getMockRoot().setStream(bytes);
+
+ VirtualFile file = VFS.getRoot(context.getRootURI());
+ InputStream stream = file.openStream();
+ assertEquals(1, stream.read());
+
+ file.closeStreams();
+ assertEquals(-1, stream.read());
+ }
+
+ public void testCloseStreamViaClose() throws Exception
+ {
+ byte[] bytes = new byte[] { 1, 2, 3, 4, 5 };
+ MockVFSContext context = registerSimpleVFSContext();
+ context.getMockRoot().setStream(bytes);
+
+ VirtualFile file = VFS.getRoot(context.getRootURI());
+ InputStream stream = file.openStream();
+ assertEquals(1, stream.read());
+
+ file.close();
+ assertEquals(-1, stream.read());
+ }
+
+ public void testClose() throws Exception
+ {
+ MockVFSContext context = registerSimpleVFSContext();
+
+ VirtualFile file = VFS.getRoot(context.getRootURI());
+ file.close();
+ }
+
+ public void testCloseDuplicate() throws Exception
+ {
+ MockVFSContext context = registerSimpleVFSContext();
+
+ VirtualFile file = VFS.getRoot(context.getRootURI());
+ file.close();
+ file.close();
+ }
+
+ public void testGetVFS() throws Exception
+ {
+ MockVFSContext context = registerSimpleVFSContext();
+
+ VirtualFile file = VFS.getRoot(context.getRootURI());
+ assertEquals(context.getVFS(), file.getVFS());
+ }
+
+ public void testGetVFSClosed() throws Exception
+ {
+ MockVFSContext context = registerSimpleVFSContext();
+
+ VirtualFile file = VFS.getRoot(context.getRootURI());
+ file.close();
+ try
+ {
+ file.getVFS();
+ fail("Should not be here");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalStateException.class, t);
+ }
+ }
+
+ public void testGetParentRoot() throws Exception
+ {
+ MockVFSContext context = registerSimpleVFSContext();
+
+ VirtualFile file = VFS.getRoot(context.getRootURI());
+ assertNull(file.getParent());
+ }
+
+ public void testGetParentSimpleChild() throws Exception
+ {
+ MockVFSContext context = registerSimpleVFSContextWithChildren();
+
+ VirtualFile root = VFS.getRoot(context.getRootURI());
+ VirtualFile child = root.findChild("child1");
+ VirtualFile parent = child.getParent();
+ assertEquals(root, parent);
+ }
+
+ public void testGetParentStructuredChild() throws Exception
+ {
+ MockVFSContext context = registerStructuredVFSContextWithSubChildren();
+
+ VirtualFile root = VFS.getRoot(context.getRootURI());
+ VirtualFile child = root.findChild("child1");
+ VirtualFile subChild = child.findChild("child1,1");
+ VirtualFile parent = child.getParent();
+ assertEquals(root, parent);
+ parent = subChild.getParent();
+ assertEquals(child, parent);
+ }
+
+ public void testGetParentIOException() throws Exception
+ {
+ MockVFSContext context = registerSimpleVFSContext();
+ context.getMockRoot().setIOException("getParent");
+
+ VirtualFile file = VFS.getRoot(context.getRootURI());
+ try
+ {
+ file.getParent();
+ fail("Should not be here");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IOException.class, t);
+ }
+ }
+
+ public void testGetParentClosed() throws Exception
+ {
+ MockVFSContext context = registerSimpleVFSContext();
+
+ VirtualFile file = VFS.getRoot(context.getRootURI());
+ file.close();
+ try
+ {
+ file.getParent();
+ fail("Should not be here");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalStateException.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();
+
+ VirtualFile file = VFS.getRoot(context.getRootURI());
+ List<VirtualFile> children = file.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();
+
+ VirtualFile file = VFS.getRoot(context.getRootURI());
+ List<VirtualFile> children = file.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().setDirectory(true);
+
+ VirtualFile file = VFS.getRoot(context.getRootURI());
+ List<VirtualFile> children = file.getChildren();
+ assertNotNull(children);
+
+ assertEmpty(children);
+ }
+
+ public void testGetAllChildrenNotADirectory() throws Exception
+ {
+ MockVFSContext context = registerSimpleVFSContext();
+
+ VirtualFile file = VFS.getRoot(context.getRootURI());
+ try
+ {
+ file.getChildren();
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalStateException.class, t);
+ }
+ }
+
+ public void testGetAllChildrenIOException() throws Exception
+ {
+ MockVFSContext context = registerSimpleVFSContextWithChildren();
+ context.getMockRoot().setIOException("getChildren");
+
+ VirtualFile file = VFS.getRoot(context.getRootURI());
+ try
+ {
+ file.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();
+
+ VirtualFile file = VFS.getRoot(context.getRootURI());
+ List<VirtualFile> children = file.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();
+
+ VirtualFile file = VFS.getRoot(context.getRootURI());
+ List<VirtualFile> children = file.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().setDirectory(true);
+
+ VirtualFile file = VFS.getRoot(context.getRootURI());
+ List<VirtualFile> children = file.getChildren(null);
+ assertNotNull(children);
+
+ assertEmpty(children);
+ }
+
+ public void testGetAllChildrenWithNullFilterNotADirectory() throws Exception
+ {
+ MockVFSContext context = registerSimpleVFSContext();
+
+ VirtualFile file = VFS.getRoot(context.getRootURI());
+ try
+ {
+ file.getChildren(null);
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalStateException.class, t);
+ }
+ }
+
+ public void testGetAllChildrenWithNullFilterIOException() throws Exception
+ {
+ MockVFSContext context = registerSimpleVFSContextWithChildren();
+ context.getMockRoot().setIOException("getChildren");
+
+ VirtualFile file = VFS.getRoot(context.getRootURI());
+ try
+ {
+ file.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();
+
+ VirtualFile file = VFS.getRoot(context.getRootURI());
+ MockVirtualFileFilter filter = new MockVirtualFileFilter();
+ List<VirtualFile> children = file.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();
+
+ VirtualFile file = VFS.getRoot(context.getRootURI());
+ MockVirtualFileFilter filter = new MockVirtualFileFilter();
+ List<VirtualFile> children = file.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().setDirectory(true);
+
+ VirtualFile file = VFS.getRoot(context.getRootURI());
+ MockVirtualFileFilter filter = new MockVirtualFileFilter();
+ List<VirtualFile> children = file.getChildren(filter);
+ assertNotNull(children);
+
+ assertEmpty(children);
+ assertEmpty(filter.getVisited());
+ }
+
+ public void testGetAllChildrenWithFilterNotADirectory() throws Exception
+ {
+ MockVFSContext context = registerSimpleVFSContext();
+
+ VirtualFile file = VFS.getRoot(context.getRootURI());
+ MockVirtualFileFilter filter = new MockVirtualFileFilter();
+ try
+ {
+ file.getChildren(filter);
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalStateException.class, t);
+ }
+ }
+
+ public void testGetAllChildrenWithFilterIOException() throws Exception
+ {
+ MockVFSContext context = registerSimpleVFSContextWithChildren();
+ context.getMockRoot().setIOException("getChildren");
+
+ VirtualFile file = VFS.getRoot(context.getRootURI());
+ MockVirtualFileFilter filter = new MockVirtualFileFilter();
+ try
+ {
+ file.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();
+
+ VirtualFile file = VFS.getRoot(context.getRootURI());
+ List<VirtualFile> children = file.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();
+
+ VirtualFile file = VFS.getRoot(context.getRootURI());
+ List<VirtualFile> children = file.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().setDirectory(true);
+
+ VirtualFile file = VFS.getRoot(context.getRootURI());
+ List<VirtualFile> children = file.getChildrenRecursively();
+ assertNotNull(children);
+
+ assertEmpty(children);
+ }
+
+ public void testGetAllChildrenRecursivelyNotADirectory() throws Exception
+ {
+ MockVFSContext context = registerSimpleVFSContext();
+
+ VirtualFile file = VFS.getRoot(context.getRootURI());
+ try
+ {
+ file.getChildrenRecursively();
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalStateException.class, t);
+ }
+ }
+
+ public void testGetAllChildrenIOExceptionRecursively() throws Exception
+ {
+ MockVFSContext context = registerSimpleVFSContextWithChildren();
+ context.getMockRoot().setIOException("getChildren");
+
+ VirtualFile file = VFS.getRoot(context.getRootURI());
+ try
+ {
+ file.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();
+
+ VirtualFile file = VFS.getRoot(context.getRootURI());
+ List<VirtualFile> children = file.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();
+
+ VirtualFile file = VFS.getRoot(context.getRootURI());
+ List<VirtualFile> children = file.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().setDirectory(true);
+
+ VirtualFile file = VFS.getRoot(context.getRootURI());
+ List<VirtualFile> children = file.getChildrenRecursively(null);
+ assertNotNull(children);
+
+ assertEmpty(children);
+ }
+
+ public void testGetAllChildrenRecursivelyWithNullFilterNotADirectory() throws Exception
+ {
+ MockVFSContext context = registerSimpleVFSContext();
+
+ VirtualFile file = VFS.getRoot(context.getRootURI());
+ try
+ {
+ file.getChildrenRecursively(null);
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalStateException.class, t);
+ }
+ }
+
+ public void testGetAllChildrenRecursivelyWithNullFilterIOException() throws Exception
+ {
+ MockVFSContext context = registerSimpleVFSContextWithChildren();
+ context.getMockRoot().setIOException("getChildren");
+
+ VirtualFile file = VFS.getRoot(context.getRootURI());
+ try
+ {
+ file.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();
+
+ VirtualFile file = VFS.getRoot(context.getRootURI());
+ MockVirtualFileFilter filter = new MockVirtualFileFilter();
+ List<VirtualFile> children = file.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();
+
+ VirtualFile file = VFS.getRoot(context.getRootURI());
+ MockVirtualFileFilter filter = new MockVirtualFileFilter();
+ List<VirtualFile> children = file.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().setDirectory(true);
+
+ VirtualFile file = VFS.getRoot(context.getRootURI());
+ MockVirtualFileFilter filter = new MockVirtualFileFilter();
+ List<VirtualFile> children = file.getChildrenRecursively(filter);
+ assertNotNull(children);
+
+ assertEmpty(children);
+ assertEmpty(filter.getVisited());
+ }
+
+ public void testGetAllChildrenRecursivelyWithFilterNotADirectory() throws Exception
+ {
+ MockVFSContext context = registerSimpleVFSContext();
+
+ VirtualFile file = VFS.getRoot(context.getRootURI());
+ MockVirtualFileFilter filter = new MockVirtualFileFilter();
+ try
+ {
+ file.getChildren(filter);
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalStateException.class, t);
+ }
+ }
+
+ public void testGetAllChildrenRecursivelyWithFilterIOException() throws Exception
+ {
+ MockVFSContext context = registerSimpleVFSContextWithChildren();
+ context.getMockRoot().setIOException("getChildren");
+
+ VirtualFile file = VFS.getRoot(context.getRootURI());
+ MockVirtualFileFilter filter = new MockVirtualFileFilter();
+ try
+ {
+ file.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();
+
+ VirtualFile file = VFS.getRoot(context.getRootURI());
+ MockVirtualFileFilter filter = new MockVirtualFileFilter();
+ List<VirtualFile> children = file.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 testVisitAllChildrenStructured() throws Exception
+ {
+ MockVFSContext context = registerStructuredVFSContextWithSubChildren();
+ VirtualFile child1 = getChildHandler(context, "child1").getVirtualFile();
+ VirtualFile child2 = getChildHandler(context, "child2").getVirtualFile();
+ VirtualFile child3 = getChildHandler(context, "child3").getVirtualFile();
+
+ VirtualFile file = VFS.getRoot(context.getRootURI());
+ MockVirtualFileFilter filter = new MockVirtualFileFilter();
+ FilterVirtualFileVisitor visitor = new FilterVirtualFileVisitor(filter);
+ file.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().setDirectory(true);
+
+ VirtualFile file = VFS.getRoot(context.getRootURI());
+ MockVirtualFileFilter filter = new MockVirtualFileFilter();
+ FilterVirtualFileVisitor visitor = new FilterVirtualFileVisitor(filter);
+ file.visit(visitor);
+
+ assertEmpty(filter.getVisited());
+ }
+
+ public void testVisitAllChildrenNotADirectory() throws Exception
+ {
+ MockVFSContext context = registerSimpleVFSContext();
+
+ VirtualFile file = VFS.getRoot(context.getRootURI());
+ MockVirtualFileFilter filter = new MockVirtualFileFilter();
+ FilterVirtualFileVisitor visitor = new FilterVirtualFileVisitor(filter);
+ try
+ {
+ file.visit(visitor);
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalStateException.class, t);
+ }
+ }
+
+ public void testVisitAllChildrenNullVisitor() throws Exception
+ {
+ MockVFSContext context = registerSimpleVFSContextWithChildren();
+
+ VirtualFile file = VFS.getRoot(context.getRootURI());
+ try
+ {
+ file.visit(null);
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalArgumentException.class, t);
+ }
+ }
+
+ public void testVisitChildrenIOException() throws Exception
+ {
+ MockVFSContext context = registerSimpleVFSContextWithChildren();
+ context.getMockRoot().setIOException("getChildren");
+
+ VirtualFile file = VFS.getRoot(context.getRootURI());
+ MockVirtualFileFilter filter = new MockVirtualFileFilter();
+ FilterVirtualFileVisitor visitor = new FilterVirtualFileVisitor(filter);
+ try
+ {
+ file.visit(visitor);
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IOException.class, t);
+ }
+ }
+
+ public void testFindChildSame() throws Exception
+ {
+ MockVFSContext context = registerSimpleVFSContext();
+ context.getMockRoot().setDirectory(true);
+
+ VirtualFile root = VFS.getRoot(context.getRootURI());
+
+ assertFindChild(root, "", root);
+ }
+
+ 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();
+
+ VirtualFile root = VFS.getRoot(context.getRootURI());
+
+ assertFindChild(root, "", root);
+ assertFindChild(root, "child1", child1);
+ assertFindChild(root, "child2", child2);
+ assertFindChild(root, "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();
+
+ VirtualFile root = VFS.getRoot(context.getRootURI());
+
+ assertFindChild(root, "", root);
+ VirtualFile found1 = assertFindChild(root, "child1", child1);
+ assertFindChild(root, "child1/child1,1", child11);
+ assertFindChild(found1, "child1,1", child11);
+ VirtualFile found2 = assertFindChild(root, "child2", child2);
+ assertFindChild(root, "child2/child2,1", child21);
+ assertFindChild(found2, "child2,1", child21);
+ assertFindChild(root, "child2/child2,2", child22);
+ assertFindChild(found2, "child2,2", child22);
+ VirtualFile found3 = assertFindChild(root, "child3", child3);
+ assertFindChild(root, "child3/child3,1", child31);
+ assertFindChild(found3, "child3,1", child31);
+ assertFindChild(root, "child3/child3,2", child32);
+ assertFindChild(found3, "child3,2", child32);
+ assertFindChild(root, "child3/child3,3", child33);
+ assertFindChild(found3, "child3,3", child33);
+ }
+
+ public void testFindChildNullPath() throws Exception
+ {
+ MockVFSContext context = registerSimpleVFSContextWithChildren();
+
+ VirtualFile file = VFS.getRoot(context.getRootURI());
+ try
+ {
+ file.findChild(null);
+ fail("Should not be here");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalArgumentException.class, t);
+ }
+ }
+
+ public void testFindChildSimpleDoesNotExist() throws Exception
+ {
+ MockVFSContext context = registerSimpleVFSContextWithChildren();
+
+ VirtualFile file = VFS.getRoot(context.getRootURI());
+ try
+ {
+ file.findChild("doesnotexist");
+ fail("Should not be here");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IOException.class, t);
+ }
+ }
+
+ public void testFindChildStructuredDoesNotExist() throws Exception
+ {
+ MockVFSContext context = registerStructuredVFSContextWithSubChildren();
+
+ VirtualFile file = VFS.getRoot(context.getRootURI());
+ try
+ {
+ file.findChild("child1/doesnotexist");
+ fail("Should not be here");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IOException.class, t);
+ }
+ }
+
+ public void testFindChildIOException() throws Exception
+ {
+ MockVFSContext context = registerSimpleVFSContextWithChildren();
+ context.getMockRoot().setIOException("findChild");
+
+ VirtualFile file = VFS.getRoot(context.getRootURI());
+ try
+ {
+ file.findChild("child1");
+ fail("Should not be here");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IOException.class, t);
+ }
+ }
+
+ public void testToString() throws Exception
+ {
+ MockVFSContext context = registerSimpleVFSContext();
+ VirtualFileHandler handler = context.getRoot();
+
+ VirtualFile file = VFS.getRoot(context.getRootURI());
+ assertEquals(handler.toString(), file.toString());
+ }
+
+ public void testHashCode() throws Exception
+ {
+ MockVFSContext context = registerSimpleVFSContext();
+ VirtualFileHandler handler = context.getRoot();
+
+ VirtualFile file = VFS.getRoot(context.getRootURI());
+ assertEquals(handler.hashCode(), file.hashCode());
+ }
+
+ public void testEquals() throws Exception
+ {
+ MockVFSContext context1 = createSimpleVFSContext();
+ MockVFSContext context2 = createSimpleVFSContext();
+
+ VirtualFile file1 = context1.getVFS().getRoot();
+ VirtualFile file2 = context2.getVFS().getRoot();
+
+ assertEquals(file1, file2);
+
+ MockVFSContext context3 = createSimple2VFSContext();
+ VirtualFile file3 = context3.getVFS().getRoot();
+
+ assertFalse(file1.equals(file3));
+ assertFalse(file2.equals(file3));
+
+ assertFalse(file1.equals(null));
+
+ assertFalse(file1.equals(new Object()));
+ }
+}
Modified: projects/microcontainer/trunk/osgi-int/src/main/org/jboss/vfs/bundle/VFSBundle.java
===================================================================
--- projects/microcontainer/trunk/osgi-int/src/main/org/jboss/vfs/bundle/VFSBundle.java 2006-09-27 10:12:24 UTC (rev 57229)
+++ projects/microcontainer/trunk/osgi-int/src/main/org/jboss/vfs/bundle/VFSBundle.java 2006-09-27 10:42:40 UTC (rev 57230)
@@ -358,7 +358,7 @@
try
{
- VirtualFile bundleFile = vfs.findChildFromRoot(this.vfsPath);
+ VirtualFile bundleFile = vfs.findChild(this.vfsPath);
update(bundleFile);
}
catch(IOException e)
More information about the jboss-cvs-commits
mailing list