[jboss-cvs] JBossAS SVN: r98948 - in projects/vfs/branches/dml-zip-rework/src: main/java/org/jboss/vfs/spi and 2 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Dec 29 12:36:55 EST 2009
Author: johnbailey
Date: 2009-12-29 12:36:55 -0500 (Tue, 29 Dec 2009)
New Revision: 98948
Added:
projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/spi/OneWaySynchronizedCopyFileSystem.java
projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/vfs/AutomounterTestCase.java
projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/vfs/OneWaySynchronizedCopyFileSystemTestCase.java
projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/vfs/VFSUtilsTestCase.java
projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/vfs/VirtualJarInputStreamTestCase.java
Removed:
projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/vfs/AutomounterTest.java
projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/vfs/VirtualJarInputStreamTest.java
Modified:
projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/VFSUtils.java
projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/VirtualFileAssembly.java
projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/util/Automounter.java
projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/vfs/AbstractVFSTest.java
projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/vfs/AssemblyFileSystemTest.java
projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/vfs/FileVFSUnitTestCase.java
projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/vfs/JARSerializationUnitTestCase.java
projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/vfs/URLConnectionUnitTestCase.java
Log:
Added functionality to Automounter to manage backing up original VirtualFile locations. Also some test cleanup
Modified: projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/VFSUtils.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/VFSUtils.java 2009-12-29 17:12:56 UTC (rev 98947)
+++ projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/VFSUtils.java 2009-12-29 17:36:55 UTC (rev 98948)
@@ -21,6 +21,7 @@
*/
package org.jboss.vfs;
+import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -34,6 +35,7 @@
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLDecoder;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Enumeration;
import java.util.HashSet;
@@ -53,6 +55,7 @@
import org.jboss.util.collection.CollectionsFactory;
import org.jboss.vfs.util.PathTokenizer;
+
/**
* VFS Utilities
*
@@ -340,7 +343,30 @@
public static URL sanitizeURL(URL url) throws URISyntaxException, MalformedURLException {
return toURI(url).toURL();
}
+
+ public static void copyChildrenRecursive(VirtualFile original, VirtualFile target) throws IOException {
+ if(original == null) throw new IllegalArgumentException("Original VirtualFile must not be null");
+ if(target == null) throw new IllegalArgumentException("Target VirtualFile must not be null");
+ List<VirtualFile> children = original.getChildren();
+ for(VirtualFile child : children) {
+ VirtualFile targetChild = target.getChild(child.getName());
+ File childFile = child.getPhysicalFile();
+ if(childFile.isDirectory()) {
+ if(!targetChild.getPhysicalFile().mkdir()) {
+ throw new IllegalArgumentException("Problems creating new directory: " + targetChild);
+ }
+ copyChildrenRecursive(child, targetChild);
+ } else {
+ FileInputStream is = new FileInputStream(childFile);
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ copyStreamAndClose(is, bos);
+ writeFile(targetChild, bos.toByteArray());
+ }
+ }
+ }
+
+
/**
* Copy input stream to output stream and close them both
*
@@ -501,6 +527,15 @@
log.trace("Failed to close resource", e);
}
}
+
+ /**
+ * Safely close some resource without throwing an exception. Any exception will be logged at TRACE level.
+ *
+ * @param closeables the resources
+ */
+ public static void safeClose(final Closeable... closeables) {
+ safeClose(Arrays.asList(closeables));
+ }
/**
* Safely close some resources without throwing an exception. Any exception will be logged at TRACE level.
Modified: projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/VirtualFileAssembly.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/VirtualFileAssembly.java 2009-12-29 17:12:56 UTC (rev 98947)
+++ projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/VirtualFileAssembly.java 2009-12-29 17:36:55 UTC (rev 98948)
@@ -26,13 +26,11 @@
import java.io.File;
import java.io.IOException;
import java.security.SecureRandom;
-import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.Random;
-import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.Executors;
Added: projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/spi/OneWaySynchronizedCopyFileSystem.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/spi/OneWaySynchronizedCopyFileSystem.java (rev 0)
+++ projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/spi/OneWaySynchronizedCopyFileSystem.java 2009-12-29 17:36:55 UTC (rev 98948)
@@ -0,0 +1,319 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.vfs.spi;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.security.CodeSigner;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+import org.jboss.vfs.VFSUtils;
+import org.jboss.vfs.VirtualFile;
+
+/**
+ * {@inheritDoc}
+ * <p/>
+ * An implementation {@link FileSystem} that represents a temporary copy of an existing {@link VirtualFile} as its root.
+ * The temporary {@link FileSystem} will be synchronized with changes to the original {@link VirtualFile} root and children.
+ *
+ * @author <a href="jbailey at redhat.com">John Bailey</a>
+ */
+public class OneWaySynchronizedCopyFileSystem implements FileSystem
+{
+ /* The original root to use as a base for synchronization */
+ private final VirtualFile originalRoot;
+
+ /* Temporary file system holding local copies */
+ private final RealFileSystem temporaryFileSystem;
+
+ /* Map holding information about the state of a giving temporary file location */
+ private final ConcurrentMap<String, SynchInfo> synchInfoMap = new ConcurrentHashMap<String, SynchInfo>();
+
+ /**
+ * Constructs a new {@link OneWaySynchronizedCopyFileSystem}.
+ *
+ * @param originalRoot the root file to base the synchronization
+ * @param temporaryRoot the file to use as the root of the temporary file system
+ */
+ public OneWaySynchronizedCopyFileSystem(VirtualFile originalRoot, File temporaryRoot)
+ {
+ this.originalRoot = originalRoot;
+ this.temporaryFileSystem = new RealFileSystem(temporaryRoot);
+ }
+
+ /** {@inheritDoc} */
+ public boolean delete(VirtualFile mountPoint, VirtualFile target)
+ {
+ getSynchInfo(mountPoint, target).setState(SynchState.DELETED_LOCAL);
+ return temporaryFileSystem.delete(mountPoint, target);
+ }
+
+ /** {@inheritDoc} */
+ public boolean exists(VirtualFile mountPoint, VirtualFile target)
+ {
+ return getFile(mountPoint, target).exists();
+ }
+
+ /** {@inheritDoc} */
+ public File getFile(VirtualFile mountPoint, VirtualFile target)
+ {
+ File file = temporaryFileSystem.getFile(mountPoint, target);
+ VirtualFile originalChild = getOriginalTarget(mountPoint, target);
+ synch(originalChild, file, getSynchInfo(mountPoint, target));
+ return file;
+ }
+
+ /**
+ * Synchronize the temporary file with the contents of the original.
+ *
+ * @param original the original {@link VirtualFile} to synchronize with the temporary file
+ * @param file the temporary file to synchronize with the original
+ * @param info the synchronization info for this file location
+ */
+ private void synch(VirtualFile original, File file, SynchInfo info)
+ {
+ if (file.exists()) {
+
+ if (original.exists()) {
+ long origModTime = original.getLastModified();
+ long copyModTime = file.lastModified();
+ if (origModTime > copyModTime) {
+ copyOriginal(original, file, info);
+ }
+ } else {
+ if (info.isInState(SynchState.COPIED)) {
+ file.delete();
+ } else {
+ info.setState(SynchState.ADDED_LOCAL);
+ }
+ }
+ } else if (info.isInState(SynchState.DELETED_LOCAL) == false) {
+ if (original.exists() && info.isInState(SynchState.UNKNOWN)) {
+ if (original.isDirectory()) {
+ file.mkdirs();
+ info.setState(SynchState.COPIED);
+ } else {
+ copyOriginal(original, file, info);
+ }
+ }
+ }
+
+ }
+
+ /**
+ * Copy the original content over to the temporary location
+ *
+ * @param original the original {@link VirtualFile} to copy contents from
+ * @param file the temporary file to copy contents to
+ * @param info the synchronization info for the file locaiton
+ */
+ private void copyOriginal(VirtualFile original, File file, SynchInfo info)
+ {
+ try {
+ VFSUtils.copyStreamAndClose(original.openStream(), new FileOutputStream(file));
+ file.setLastModified(original.getLastModified());
+ info.setState(SynchState.COPIED);
+ }
+ catch (IOException e) {
+ throw new RuntimeException("Failed to create temporary copy of file: " + original, e);
+ }
+ }
+
+ /** {@inheritDoc} */
+ public List<String> getDirectoryEntries(VirtualFile mountPoint, VirtualFile target)
+ {
+ File file = getFile(mountPoint, target);
+ if (file.isFile()) {
+ return null;
+ }
+
+ List<String> directoryEntries = new LinkedList<String>();
+
+ VirtualFile originalTarget = getOriginalTarget(mountPoint, target);
+ for (VirtualFile origChild : originalTarget.getChildren()) {
+ directoryEntries.add(origChild.getName());
+ }
+
+ String[] tempedFiles = file.list();
+ for (String name : tempedFiles) {
+ SynchInfo info = getSynchInfo(mountPoint, target, name);
+ if (directoryEntries.contains(name) == false && info.isInState(SynchState.COPIED) == false) {
+ directoryEntries.add(name);
+ }
+ }
+ return directoryEntries;
+ }
+
+ /** {@inheritDoc} */
+ public long getLastModified(VirtualFile mountPoint, VirtualFile target)
+ {
+ return getFile(mountPoint, target).lastModified();
+ }
+
+ /** {@inheritDoc} */
+ public long getSize(VirtualFile mountPoint, VirtualFile target)
+ {
+ return getFile(mountPoint, target).length();
+ }
+
+ /** {@inheritDoc} */
+ public boolean isDirectory(VirtualFile mountPoint, VirtualFile target)
+ {
+ return getFile(mountPoint, target).isDirectory();
+ }
+
+ /** {@inheritDoc} */
+ public boolean isFile(VirtualFile mountPoint, VirtualFile target)
+ {
+ return getFile(mountPoint, target).isDirectory();
+ }
+
+ /** {@inheritDoc} */
+ public boolean isReadOnly()
+ {
+ return false;
+ }
+
+ /** {@inheritDoc} */
+ public InputStream openInputStream(VirtualFile mountPoint, VirtualFile target) throws IOException
+ {
+ return new FileInputStream(getFile(mountPoint, target));
+ }
+
+ /** {@inheritDoc} */
+ public void close() throws IOException
+ {
+ temporaryFileSystem.close();
+ }
+
+ /** {@inheritDoc} */
+ public CodeSigner[] getCodeSigners(VirtualFile mountPoint, VirtualFile target)
+ {
+ return null;
+ }
+
+ /**
+ * Get the synchronization info for a target
+ *
+ * @param mountPoint the mount for this {@link FileSystem}
+ * @param target the target {@link VirtualFile} to get info for
+ * @return the synchronization info
+ */
+ private SynchInfo getSynchInfo(VirtualFile mountPoint, VirtualFile target)
+ {
+ return getSynchInfo(mountPoint, target, null);
+ }
+
+ /**
+ * Get the synchronization info for the child of a target
+ *
+ * @param mountPoint the mount for this {@link FileSystem}
+ * @param target the target {@link VirtualFile} to get info for
+ * @param targetChild the name of a child of the target
+ * @return the synchronization info
+ */
+ private SynchInfo getSynchInfo(VirtualFile mountPoint, VirtualFile target, String targetChild)
+ {
+ String path = getRelativePath(mountPoint, target);
+ if (targetChild != null) {
+ path = path.equals("") ? targetChild : path + "/" + targetChild;
+ }
+ return getSynchInfo(path);
+ }
+
+ /**
+ * Get the synchronization info for a raw file path key
+ *
+ * @param path the file path
+ * @return the synchronization info
+ */
+ private SynchInfo getSynchInfo(String path)
+ {
+ synchInfoMap.putIfAbsent(path, new SynchInfo());
+ return synchInfoMap.get(path);
+ }
+
+ /**
+ * Get the relative file path between the mount point and the target
+ *
+ * @param mountPoint the mount point for the {@link FileSystem}
+ * @param target the target {@link VirtualFile}
+ * @return the relative path between
+ */
+ private String getRelativePath(VirtualFile mountPoint, VirtualFile target)
+ {
+ if (mountPoint.equals(target)) {
+ return "";
+ }
+ return target.getPathNameRelativeTo(mountPoint);
+ }
+
+ /**
+ * Return the original target {@link VirtualFile} that should be used to back this temporary target.
+ *
+ * @param mountPoint the mount point for the {@link FileSystem}
+ * @param target the target {@link VirtualFile}
+ * @return the {@link VirtualFile} from the original {@link FileSystem}
+ */
+ private VirtualFile getOriginalTarget(VirtualFile mountPoint, VirtualFile target)
+ {
+ VirtualFile originalChild = null;
+ if (target.equals(mountPoint)) {
+ originalChild = originalRoot;
+ } else {
+ originalChild = originalRoot.getChild(getRelativePath(mountPoint, target));
+ }
+ return originalChild;
+ }
+
+ /**
+ * An enumeration of synchronizations states.
+ */
+ private enum SynchState {
+ UNKNOWN, COPIED, DELETED_LOCAL, ADDED_LOCAL
+ };
+
+ /**
+ * Holder for synchronization states
+ */
+ private class SynchInfo
+ {
+ private SynchState state = SynchState.UNKNOWN;
+
+ private boolean isInState(SynchState synchState)
+ {
+ return synchState.equals(state);
+ }
+
+ public void setState(SynchState state)
+ {
+ this.state = state;
+ }
+ }
+
+}
Modified: projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/util/Automounter.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/util/Automounter.java 2009-12-29 17:12:56 UTC (rev 98947)
+++ projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/util/Automounter.java 2009-12-29 17:36:55 UTC (rev 98948)
@@ -33,6 +33,7 @@
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.Executors;
+import org.jboss.util.id.GUID;
import org.jboss.vfs.TempFileProvider;
import org.jboss.vfs.VFS;
import org.jboss.vfs.VFSUtils;
@@ -51,6 +52,9 @@
/* Root entry in the tree. */
private static final RegistryEntry rootEntry = new RegistryEntry();
+ /* VirutalFile used as a base mount for 'hidden' original copies of mounted files */
+ private static final VirtualFile originalsRoot = VFS.getChild("/vfs/backups");
+
/* Possible mount types */
private static enum MountType {
ZIP, EXPANDED
@@ -87,7 +91,7 @@
RegistryEntry ownerEntry = getEntry(owner);
targetEntry.mount(ownerEntry, target, MountType.ZIP);
}
-
+
/**
* Mount provided {@link VirtualFile} (if not mounted) as an expanded Zip mount and add an owner entry.
* Also creates a back-reference to from the owner to the target. (Self owned mount)
@@ -137,8 +141,46 @@
{
return getEntry(target).isMounted();
}
-
+
/**
+ * Create a backup of the provided root. Only one backup is allowed for a location.
+ *
+ * @param original the original VirtualFile to backup
+ * @return a reference to the backup location
+ * @throws IOException if any problems occur during the backup process
+ */
+ public static VirtualFile backup(VirtualFile original) throws IOException
+ {
+ RegistryEntry entry = getEntry(original);
+ entry.backup(original);
+ return entry.backup.file;
+ }
+
+ /**
+ * Get the backup for the provided target
+ *
+ * @param target the location to get the backup for
+ * @return the backup
+ */
+ public static VirtualFile getBackup(VirtualFile target)
+ {
+ Backup backup = getEntry(target).backup;
+ return backup != null ? backup.file : null;
+ }
+
+ /**
+ * Check to see if a backup exists for the provided location.
+ *
+ * @param target the location to check for a backup.
+ * @return true if the backup exists.
+ */
+ public static boolean hasBackup(VirtualFile target)
+ {
+ return getEntry(target).backup != null;
+ }
+
+
+ /**
* Get the entry from the tree creating the entry if not present.
*
* @param virtualFile
@@ -157,7 +199,7 @@
{
return TempFileProvider.create(name, Executors.newSingleThreadScheduledExecutor());
}
-
+
static class RegistryEntry
{
private final ConcurrentMap<String, RegistryEntry> children = new ConcurrentHashMap<String, RegistryEntry>();
@@ -167,6 +209,8 @@
private final Set<RegistryEntry> outboundReferences = new HashSet<RegistryEntry>();
private Closeable handle;
+
+ private Backup backup;
Collection<RegistryEntry> getChildren()
{
@@ -175,12 +219,16 @@
void mount(RegistryEntry owner, VirtualFile target, MountType mountType) throws IOException
{
- if (!isMounted() && target.isFile())
+ if (!isMounted())
{
- if (MountType.ZIP.equals(mountType))
- handle = VFS.mountZip(target, target, getTempFileProvider(target.getName()));
- else
- handle = VFS.mountZipExpanded(target, target, getTempFileProvider(target.getName()));
+ if(target.isFile())
+ {
+ backup(target);
+ if (MountType.ZIP.equals(mountType))
+ handle = VFS.mountZip(target, target, getTempFileProvider(target.getName()));
+ else
+ handle = VFS.mountZipExpanded(target, target, getTempFileProvider(target.getName()));
+ }
}
if (owner.equals(this) == false)
{
@@ -202,6 +250,10 @@
{
VFSUtils.safeClose(handle);
handle = null;
+ if(backup != null) {
+ VFSUtils.safeClose(backup.handle);
+ backup = null;
+ }
Collection<RegistryEntry> entries = getEntriesRecursive();
for (RegistryEntry entry : entries)
@@ -250,8 +302,23 @@
collectEntries(childEntry, entries);
entries.add(childEntry);
}
+ }
+
+ void backup(VirtualFile target) throws IOException
+ {
+ VirtualFile backupFile = originalsRoot.getChild(GUID.asString() + target.getName());
+ backup = new Backup(backupFile, VFS.mountReal(target.getPhysicalFile(), backupFile));
+ }
+ }
+
+ static class Backup {
+ private final VirtualFile file;
+ private final Closeable handle;
+ public Backup(VirtualFile backupFile, Closeable handle)
+ {
+ this.file = backupFile;
+ this.handle = handle;
}
-
}
}
Modified: projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/vfs/AbstractVFSTest.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/vfs/AbstractVFSTest.java 2009-12-29 17:12:56 UTC (rev 98947)
+++ projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/vfs/AbstractVFSTest.java 2009-12-29 17:36:55 UTC (rev 98948)
@@ -21,8 +21,12 @@
*/
package org.jboss.test.vfs;
+import static org.junit.Assert.assertArrayEquals;
+
+import java.io.ByteArrayOutputStream;
import java.io.Closeable;
import java.io.IOException;
+import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
@@ -32,7 +36,9 @@
import org.jboss.test.BaseTestCase;
import org.jboss.vfs.TempFileProvider;
import org.jboss.vfs.VFS;
+import org.jboss.vfs.VFSUtils;
import org.jboss.vfs.VirtualFile;
+import org.junit.internal.ArrayComparisonFailure;
/**
* AbstractVFSTest.
@@ -61,13 +67,19 @@
provider.close();
}
- // TODO move to AbstractTestCase
public URL getResource(String name)
{
URL url = super.getResource(name);
assertNotNull("Resource not found: " + name, url);
return url;
}
+
+ public VirtualFile getVirtualFile(String name)
+ {
+ VirtualFile virtualFile = VFS.getChild(getResource(name).getPath());
+ assertTrue("VirtualFile does not exist: " + name, virtualFile.exists());
+ return virtualFile;
+ }
public List<Closeable> recursiveMount(VirtualFile file) throws IOException
{
@@ -102,4 +114,15 @@
getLog().debug("Got expected " + expected.getName() + "(" + throwable + ")");
}
}
+
+ protected void assertContentEqual(VirtualFile expected, VirtualFile actual) throws ArrayComparisonFailure, IOException {
+ assertArrayEquals("Expected content must mach actual conent", getContent(expected), getContent(actual));
+ }
+
+ protected byte[] getContent(VirtualFile virtualFile) throws IOException {
+ InputStream is = virtualFile.openStream();
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ VFSUtils.copyStreamAndClose(is, bos);
+ return bos.toByteArray();
+ }
}
Modified: projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/vfs/AssemblyFileSystemTest.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/vfs/AssemblyFileSystemTest.java 2009-12-29 17:12:56 UTC (rev 98947)
+++ projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/vfs/AssemblyFileSystemTest.java 2009-12-29 17:36:55 UTC (rev 98948)
@@ -1,7 +1,5 @@
package org.jboss.test.vfs;
-import static org.junit.Assert.*;
-
import java.io.Closeable;
import java.io.File;
import java.net.URL;
@@ -32,8 +30,7 @@
Closeable warAssemblyHandle = VFS.mountAssembly(warAssembly, warAssemblyLocation);
try {
- URL rootURL = getResource("/vfs/test");
- VirtualFile testDir = VFS.getChild(rootURL.getPath());
+ VirtualFile testDir = getVirtualFile("/vfs/test");
earAssembly.add("assembly.war", warAssemblyLocation);
@@ -126,8 +123,7 @@
assertFalse(assemblyLocation.getChild("lib").exists());
- URL jarURL = getResource("/vfs/test/jar1.jar");
- VirtualFile jarFile = VFS.getChild(jarURL);
+ VirtualFile jarFile = getVirtualFile("/vfs/test/jar1.jar");
assembly.add("lib/jar.jar", jarFile);
assertTrue(assemblyLocation.getChild("lib").exists());
@@ -154,8 +150,7 @@
try {
assertTrue(assemblyLocation.isDirectory());
- URL jarURL = getResource("/vfs/test/jar1.jar");
- VirtualFile jarFile = VFS.getChild(jarURL);
+ VirtualFile jarFile = getVirtualFile("/vfs/test/jar1.jar");
assembly.add("lib/jar.jar", jarFile);
assertTrue(assemblyLocation.getChild("lib").isDirectory());
Deleted: projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/vfs/AutomounterTest.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/vfs/AutomounterTest.java 2009-12-29 17:12:56 UTC (rev 98947)
+++ projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/vfs/AutomounterTest.java 2009-12-29 17:36:55 UTC (rev 98948)
@@ -1,133 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2009, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.test.vfs;
-
-import java.net.URL;
-
-import org.jboss.vfs.util.Automounter;
-import org.jboss.test.BaseTestCase;
-import org.jboss.vfs.VFS;
-import org.jboss.vfs.VirtualFile;
-
-/**
- * Test for {@link Automounter}
- *
- * @author <a href="jbailey at redhat.com">John Bailey</a>
- */
-public class AutomounterTest extends BaseTestCase
-{
-
- public AutomounterTest(String name)
- {
- super(name);
- }
-
- public void testMountAndCleanup() throws Exception
- {
- VirtualFile virtualFile = getVirtualFile("/vfs/test/simple.ear");
- Automounter.mount(virtualFile, virtualFile);
- assertTrue(Automounter.isMounted(virtualFile));
- Automounter.cleanup(virtualFile);
- assertFalse(Automounter.isMounted(virtualFile));
- }
-
- public void testCleanupWithOwner() throws Exception
- {
- VirtualFile earVirtualFile = getVirtualFile("/vfs/test/simple.ear");
- Automounter.mount(earVirtualFile);
-
- VirtualFile jarVirtualFile = earVirtualFile.getChild("archive.jar");
- Automounter.mount(earVirtualFile, jarVirtualFile);
-
- VirtualFile warVirtualFile = earVirtualFile.getChild("simple.war");
- Automounter.mount(earVirtualFile, warVirtualFile);
-
- assertTrue(Automounter.isMounted(earVirtualFile));
- assertTrue(Automounter.isMounted(warVirtualFile));
- assertTrue(Automounter.isMounted(jarVirtualFile));
-
- Automounter.cleanup(earVirtualFile);
-
- assertFalse(Automounter.isMounted(earVirtualFile));
- assertFalse(Automounter.isMounted(warVirtualFile));
- assertFalse(Automounter.isMounted(jarVirtualFile));
- }
-
- public void testCleanupRecursive() throws Exception
- {
- VirtualFile earVirtualFile = getVirtualFile("/vfs/test/simple.ear");
- Automounter.mount(earVirtualFile);
-
- VirtualFile jarVirtualFile = earVirtualFile.getChild("archive.jar");
- Automounter.mount(jarVirtualFile);
-
- VirtualFile warVirtualFile = earVirtualFile.getChild("simple.war");
- Automounter.mount(warVirtualFile);
-
- assertTrue(Automounter.isMounted(earVirtualFile));
- assertTrue(Automounter.isMounted(warVirtualFile));
- assertTrue(Automounter.isMounted(jarVirtualFile));
-
- Automounter.cleanup(earVirtualFile);
-
- assertFalse(Automounter.isMounted(earVirtualFile));
- assertFalse(Automounter.isMounted(warVirtualFile));
- assertFalse(Automounter.isMounted(jarVirtualFile));
- }
-
- public void testCleanupRefereces() throws Exception
- {
- VirtualFile earVirtualFile = getVirtualFile("/vfs/test/simple.ear");
- Automounter.mount(earVirtualFile);
-
- VirtualFile jarVirtualFile = getVirtualFile("/vfs/test/jar1.jar");
- Automounter.mount(earVirtualFile, jarVirtualFile);
-
- VirtualFile warVirtualFile = getVirtualFile("/vfs/test/filesonly.war");
- Automounter.mount(earVirtualFile, warVirtualFile);
-
- assertTrue(Automounter.isMounted(earVirtualFile));
- assertTrue(Automounter.isMounted(warVirtualFile));
- assertTrue(Automounter.isMounted(jarVirtualFile));
-
- VirtualFile otherEarVirtualFile = getVirtualFile("/vfs/test/spring-ear.ear");
- Automounter.mount(otherEarVirtualFile, jarVirtualFile);
-
- Automounter.cleanup(earVirtualFile);
-
- assertFalse(Automounter.isMounted(earVirtualFile));
- assertFalse(Automounter.isMounted(warVirtualFile));
- assertTrue("Should not have unmounted the reference from two locations", Automounter.isMounted(jarVirtualFile));
-
- Automounter.cleanup(otherEarVirtualFile);
- assertFalse(Automounter.isMounted(jarVirtualFile));
-
- }
-
- protected VirtualFile getVirtualFile(String path) throws Exception
- {
- URL url = getResource(path);
- VirtualFile rootFile = VFS.getChild(url);
- return rootFile;
- }
-
-}
Copied: projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/vfs/AutomounterTestCase.java (from rev 97993, projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/vfs/AutomounterTest.java)
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/vfs/AutomounterTestCase.java (rev 0)
+++ projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/vfs/AutomounterTestCase.java 2009-12-29 17:36:55 UTC (rev 98948)
@@ -0,0 +1,123 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.vfs;
+
+import org.jboss.vfs.VirtualFile;
+import org.jboss.vfs.util.Automounter;
+
+/**
+ * Test for {@link Automounter}
+ *
+ * @author <a href="jbailey at redhat.com">John Bailey</a>
+ */
+public class AutomounterTestCase extends AbstractVFSTest
+{
+
+ public AutomounterTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testMountAndCleanup() throws Exception
+ {
+ VirtualFile virtualFile = getVirtualFile("/vfs/test/simple.ear");
+ Automounter.mount(virtualFile, virtualFile);
+ assertTrue(Automounter.isMounted(virtualFile));
+ Automounter.cleanup(virtualFile);
+ assertFalse(Automounter.isMounted(virtualFile));
+ }
+
+ public void testCleanupWithOwner() throws Exception
+ {
+ VirtualFile earVirtualFile = getVirtualFile("/vfs/test/simple.ear");
+ Automounter.mount(earVirtualFile);
+
+ VirtualFile jarVirtualFile = earVirtualFile.getChild("archive.jar");
+ Automounter.mount(earVirtualFile, jarVirtualFile);
+
+ VirtualFile warVirtualFile = earVirtualFile.getChild("simple.war");
+ Automounter.mount(earVirtualFile, warVirtualFile);
+
+ assertTrue(Automounter.isMounted(earVirtualFile));
+ assertTrue(Automounter.isMounted(warVirtualFile));
+ assertTrue(Automounter.isMounted(jarVirtualFile));
+
+ Automounter.cleanup(earVirtualFile);
+
+ assertFalse(Automounter.isMounted(earVirtualFile));
+ assertFalse(Automounter.isMounted(warVirtualFile));
+ assertFalse(Automounter.isMounted(jarVirtualFile));
+ }
+
+ public void testCleanupRecursive() throws Exception
+ {
+ VirtualFile earVirtualFile = getVirtualFile("/vfs/test/simple.ear");
+ Automounter.mount(earVirtualFile);
+
+ VirtualFile jarVirtualFile = earVirtualFile.getChild("archive.jar");
+ Automounter.mount(jarVirtualFile);
+
+ VirtualFile warVirtualFile = earVirtualFile.getChild("simple.war");
+ Automounter.mount(warVirtualFile);
+
+ assertTrue(Automounter.isMounted(earVirtualFile));
+ assertTrue(Automounter.isMounted(warVirtualFile));
+ assertTrue(Automounter.isMounted(jarVirtualFile));
+
+ Automounter.cleanup(earVirtualFile);
+
+ assertFalse(Automounter.isMounted(earVirtualFile));
+ assertFalse(Automounter.isMounted(warVirtualFile));
+ assertFalse(Automounter.isMounted(jarVirtualFile));
+ }
+
+ public void testCleanupRefereces() throws Exception
+ {
+ VirtualFile earVirtualFile = getVirtualFile("/vfs/test/simple.ear");
+ Automounter.mount(earVirtualFile);
+
+ VirtualFile jarVirtualFile = getVirtualFile("/vfs/test/jar1.jar");
+ Automounter.mount(earVirtualFile, jarVirtualFile);
+
+ VirtualFile warVirtualFile = getVirtualFile("/vfs/test/filesonly.war");
+ Automounter.mount(earVirtualFile, warVirtualFile);
+
+ assertTrue(Automounter.isMounted(earVirtualFile));
+ assertTrue(Automounter.isMounted(warVirtualFile));
+ assertTrue(Automounter.isMounted(jarVirtualFile));
+
+ VirtualFile otherEarVirtualFile = getVirtualFile("/vfs/test/spring-ear.ear");
+ Automounter.mount(otherEarVirtualFile, jarVirtualFile);
+
+ Automounter.cleanup(earVirtualFile);
+
+ assertFalse(Automounter.isMounted(earVirtualFile));
+ assertFalse(Automounter.isMounted(warVirtualFile));
+ assertTrue("Should not have unmounted the reference from two locations", Automounter.isMounted(jarVirtualFile));
+
+ Automounter.cleanup(otherEarVirtualFile);
+ assertFalse(Automounter.isMounted(jarVirtualFile));
+ }
+
+
+
+}
Modified: projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/vfs/FileVFSUnitTestCase.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/vfs/FileVFSUnitTestCase.java 2009-12-29 17:12:56 UTC (rev 98947)
+++ projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/vfs/FileVFSUnitTestCase.java 2009-12-29 17:36:55 UTC (rev 98948)
@@ -101,8 +101,7 @@
*/
public void testInnerJarFile() throws Exception
{
- URL rootURL = getResource("/vfs/test");
- VirtualFile testdir = VFS.getChild(rootURL.getPath());
+ VirtualFile testdir = getVirtualFile("/vfs/test");
VirtualFile outerjar = testdir.getChild("outer.jar");
List<Closeable> mounts = recursiveMount(outerjar);
@@ -144,8 +143,7 @@
*/
public void testFindResource() throws Exception
{
- URL rootURL = getResource("/vfs/test");
- VirtualFile testdir = VFS.getChild(rootURL.getPath());
+ VirtualFile testdir = getVirtualFile("/vfs/test");
VirtualFile jar = testdir.getChild("outer.jar");
List<Closeable> mounts = recursiveMount(jar);
try
@@ -174,8 +172,7 @@
*/
public void testFindResourceUsingURLStream() throws Exception
{
- URL rootURL = getResource("/vfs/test");
- VirtualFile testdir = VFS.getChild(rootURL.getPath());
+ VirtualFile testdir = getVirtualFile("/vfs/test");
VirtualFile jar = testdir.getChild("outer.jar");
List<Closeable> mounts = recursiveMount(jar);
try
@@ -221,8 +218,7 @@
*/
public void testFindResourceInFilesOnlyJar() throws Exception
{
- URL rootURL = getResource("/vfs/test");
- VirtualFile testdir = VFS.getChild(rootURL.getPath());
+ VirtualFile testdir = getVirtualFile("/vfs/test");
VirtualFile jar = testdir.getChild("jar1-filesonly.jar");
List<Closeable> mounts = recursiveMount(jar);
try
@@ -266,8 +262,7 @@
*/
public void testFindResourceInFilesOnlyWar() throws Exception
{
- URL rootURL = getResource("/vfs/test");
- VirtualFile testdir = VFS.getChild(rootURL.getPath());
+ VirtualFile testdir = getVirtualFile("/vfs/test");
VirtualFile war2 = testdir.getChild("WarDeployApp_web.war");
List<Closeable> mounts = recursiveMount(war2);
try
@@ -337,8 +332,7 @@
*/
public void testFindClassesInFilesOnlyWar() throws Exception
{
- URL rootURL = getResource("/vfs/test");
- VirtualFile testdir = VFS.getChild(rootURL.getPath());
+ VirtualFile testdir = getVirtualFile("/vfs/test");
VirtualFile war = testdir.getChild("filesonly.war");
List<Closeable> mounts = recursiveMount(war);
@@ -369,8 +363,7 @@
public void testFindResourceUnpackedJar() throws Exception
{
- URL rootURL = getResource("/vfs/test");
- VirtualFile testdir = VFS.getChild(rootURL.getPath());
+ VirtualFile testdir = getVirtualFile("/vfs/test");
VirtualFile jar = testdir.getChild("unpacked-outer.jar");
assertTrue("unpacked-outer.jar != null", jar != null);
@@ -443,8 +436,7 @@
public void testResolveClassFileInClassPath() throws Exception
{
log.info("+++ testResolveFile, cwd=" + (new File(".").getCanonicalPath()));
- URL rootURL = getResource("/vfs/test");
- VirtualFile testdir = VFS.getChild(rootURL.getPath());
+ VirtualFile testdir = getVirtualFile("/vfs/test");
// Find ClassInJar1.class
VirtualFile vf = testdir.getChild("jar1.jar");
@@ -505,8 +497,7 @@
public void testFileNotFoundInUnpackedJar() throws Exception
{
- URL rootURL = getResource("/vfs/test");
- VirtualFile testdir = VFS.getChild(rootURL.getPath());
+ VirtualFile testdir = getVirtualFile("/vfs/test");
// Find the outer.jar
VirtualFile outerJar = testdir.getChild("unpacked-outer.jar");
@@ -530,8 +521,7 @@
*/
public void testInnerJar() throws Exception
{
- URL rootURL = getResource("/vfs/test");
- VirtualFile testdir = VFS.getChild(rootURL.getPath());
+ VirtualFile testdir = getVirtualFile("/vfs/test");
VirtualFile outer = testdir.getChild("outer.jar");
List<Closeable> mounts = recursiveMount(outer);
try
@@ -563,8 +553,7 @@
public void testInnerJarUsingURLStream() throws Exception
{
- URL rootURL = getResource("/vfs/test");
- VirtualFile testdir = VFS.getChild(rootURL.getPath());
+ VirtualFile testdir = getVirtualFile("/vfs/test");
VirtualFile outer = testdir.getChild("outer.jar");
List<Closeable> mounts = recursiveMount(outer);
try
@@ -600,8 +589,7 @@
*/
public void testClassScan() throws Exception
{
- URL rootURL = getResource("/vfs/test/outer.jar");
- VirtualFile outer = VFS.getChild(rootURL.getPath());
+ VirtualFile outer = getVirtualFile("/vfs/test/outer.jar");
List<Closeable> mounts = recursiveMount(outer);
try
{
@@ -738,8 +726,7 @@
*/
public void testFilesOnlyJar() throws Exception
{
- URL rootURL = getResource("/vfs/test");
- VirtualFile testdir = VFS.getChild(rootURL.getPath());
+ VirtualFile testdir = getVirtualFile("/vfs/test");
VirtualFile jar = testdir.getChild("jar1-filesonly.jar");
List<Closeable> mounts = recursiveMount(jar);
@@ -909,8 +896,7 @@
public void testVFNestedJarSerialization() throws Exception
{
// this expects to be run with a working dir of the container root
- URL rootURL = getResource("/vfs/test");
- VirtualFile testdir = VFS.getChild(rootURL.getPath());
+ VirtualFile testdir = getVirtualFile("/vfs/test");
VirtualFile outer = testdir.getChild("outer.jar");
List<Closeable> mounts = recursiveMount(outer);
try
@@ -965,8 +951,7 @@
*/
public void testDirURLs() throws Exception
{
- URL rootURL = getResource("/vfs/test");
- VirtualFile testdir = VFS.getChild(rootURL.getPath());
+ VirtualFile testdir = getVirtualFile("/vfs/test");
VirtualFile outerJar = testdir.getChild("unpacked-outer.jar");
URL outerURL = outerJar.toURL();
@@ -1002,8 +987,7 @@
*/
public void testDirURIs() throws Exception
{
- URL rootURL = getResource("/vfs/test");
- VirtualFile testdir = VFS.getChild(rootURL.getPath());
+ VirtualFile testdir = getVirtualFile("/vfs/test");
VirtualFile outerJar = testdir.getChild("unpacked-outer.jar");
URI outerURI = outerJar.toURI();
@@ -1037,8 +1021,7 @@
*/
public void testCopyJar() throws Exception
{
- URL rootURL = getResource("/vfs/test");
- VirtualFile testdir = VFS.getChild(rootURL.getPath());
+ VirtualFile testdir = getVirtualFile("/vfs/test");
VirtualFile jar = testdir.getChild("outer.jar");
assertTrue("outer.jar != null", jar != null);
File tmpJar = File.createTempFile("testCopyJar", ".jar");
@@ -1080,8 +1063,7 @@
*/
public void testCopyInnerJar() throws Exception
{
- URL rootURL = getResource("/vfs/test");
- VirtualFile testdir = VFS.getChild(rootURL.getPath());
+ VirtualFile testdir = getVirtualFile("/vfs/test");
VirtualFile outerjar = testdir.getChild("outer.jar");
List<Closeable> mounts = recursiveMount(outerjar);
try
@@ -1124,8 +1106,7 @@
*/
public void testManifestClasspath() throws Exception
{
- URL rootURL = getResource("/vfs/test");
- VirtualFile testdir = VFS.getChild(rootURL.getPath());
+ VirtualFile testdir = getVirtualFile("/vfs/test");
VirtualFile outerjar = testdir.getChild("outermf.jar");
List<Closeable> mounts = recursiveMount(outerjar);
try
@@ -1154,8 +1135,7 @@
*/
public void testInnerManifestClasspath() throws Exception
{
- URL rootURL = getResource("/vfs/test");
- VirtualFile testdir = VFS.getChild(rootURL.getPath());
+ VirtualFile testdir = getVirtualFile("/vfs/test");
VirtualFile outerjar = testdir.getChild("withalong/rootprefix/outermf.jar");
assertNotNull(outerjar);
List<Closeable> mounts = recursiveMount(outerjar);
@@ -1328,8 +1308,7 @@
*/
public void testURLClassLoaderFindResourceFailure() throws Exception
{
- URL rootURL = getResource("/vfs/test");
- VirtualFile testdir = VFS.getChild(rootURL.getPath());
+ VirtualFile testdir = getVirtualFile("/vfs/test");
URL[] cp = { testdir.toURL() };
URLClassLoader ucl = new URLClassLoader(cp);
// Search for a non-existent resource
Modified: projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/vfs/JARSerializationUnitTestCase.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/vfs/JARSerializationUnitTestCase.java 2009-12-29 17:12:56 UTC (rev 98947)
+++ projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/vfs/JARSerializationUnitTestCase.java 2009-12-29 17:36:55 UTC (rev 98948)
@@ -63,8 +63,7 @@
*/
public void testInnerJarFile() throws Exception
{
- URL rootURL = getResource("/vfs/test");
- VirtualFile outerjar = VFS.getChild(rootURL).getChild("outer.jar");
+ VirtualFile outerjar = getVirtualFile("/vfs/test/outer.jar");
List<Closeable> mounts = recursiveMount(outerjar);
try
{
@@ -100,8 +99,7 @@
public void testInnerJarFileSerialization() throws Exception
{
- URL rootURL = getResource("/vfs/test");
- VirtualFile outerjar = VFS.getChild(rootURL).getChild("outer.jar");
+ VirtualFile outerjar = getVirtualFile("/vfs/test/outer.jar");
List<Closeable> mounts = recursiveMount(outerjar);
try
{
@@ -139,8 +137,7 @@
public void testInnerJarFilesOnlyFileSerialization() throws Exception
{
- URL rootURL = getResource("/vfs/test");
- VirtualFile outerjar =VFS.getChild(rootURL).getChild("outer.jar");
+ VirtualFile outerjar = getVirtualFile("/vfs/test/outer.jar");
List<Closeable> mounts = recursiveMount(outerjar);
try
{
@@ -235,8 +232,7 @@
public void test2ndLevelRead() throws Exception
{
- URL rootURL = getResource("/vfs/test/level1.zip");
- VirtualFile root = VFS.getChild(rootURL);
+ VirtualFile root = getVirtualFile("/vfs/test/level1.zip");
List<Closeable> mounts = recursiveMount(root);
try
{
@@ -253,8 +249,7 @@
public void testEarsInnerJarChild() throws Exception
{
- URL rootURL = getResource("/vfs/test/interop_W2JREMarshallTest_appclient_vehicle.ear");
- VirtualFile root = VFS.getChild(rootURL);
+ VirtualFile root = getVirtualFile("/vfs/test/interop_W2JREMarshallTest_appclient_vehicle.ear");
List<Closeable> mounts = recursiveMount(root);
try
{
@@ -278,8 +273,7 @@
public void testVirtualFileAdaptor() throws Exception
{
- URL rootURL = getResource("/vfs/test/interop_W2JREMarshallTest_appclient_vehicle.ear");
- VirtualFile root = VFS.getChild(rootURL);
+ VirtualFile root = getVirtualFile("/vfs/test/interop_W2JREMarshallTest_appclient_vehicle.ear");
VirtualFile file = root.getChild("interop_W2JREMarshallTest_appclient_vehicle_client.jar");
VirtualFile same = file.getChild("");
// serialize
@@ -288,8 +282,7 @@
public void testDeepVFAMechanism() throws Exception
{
- URL rootURL = getResource("/vfs/test");
- VirtualFile root = VFS.getChild(rootURL);
+ VirtualFile root = getVirtualFile("/vfs/test");
VirtualFile one = root.getChild("level1.zip");
testVirtualFileAdaptor(one, "test1.txt");
VirtualFile textOne = one.getChild("test1.txt");
Added: projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/vfs/OneWaySynchronizedCopyFileSystemTestCase.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/vfs/OneWaySynchronizedCopyFileSystemTestCase.java (rev 0)
+++ projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/vfs/OneWaySynchronizedCopyFileSystemTestCase.java 2009-12-29 17:36:55 UTC (rev 98948)
@@ -0,0 +1,350 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.vfs;
+
+import java.io.Closeable;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.concurrent.Executors;
+
+import org.apache.tools.ant.filters.StringInputStream;
+import org.jboss.vfs.TempDir;
+import org.jboss.vfs.TempFileProvider;
+import org.jboss.vfs.VFS;
+import org.jboss.vfs.VFSUtils;
+import org.jboss.vfs.VirtualFile;
+import org.jboss.vfs.spi.OneWaySynchronizedCopyFileSystem;
+import org.junit.Test;
+import org.junit.internal.ArrayComparisonFailure;
+
+/**
+ * TestCase to verify the functionality of a {@link OneWaySynchronizedCopyFileSystem}.
+ *
+ * @author <a href="jbailey at redhat.com">John Bailey</a>
+ */
+public class OneWaySynchronizedCopyFileSystemTestCase extends AbstractVFSTest
+{
+
+ private TempFileProvider tempFileProvider;
+
+ public OneWaySynchronizedCopyFileSystemTestCase(String name)
+ {
+ super(name);
+ }
+
+ /**
+ * Verify files are correctly copied from the original root
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testExistingFiles() throws Exception
+ {
+ List<Closeable> mounts = new LinkedList<Closeable>();
+ try {
+ VirtualFile existing = getVirtualFile("/vfs/test/jar1");
+
+ TempDir dir = getTempFileProvider().createTempDir("new-jar1");
+ File dirRoot = dir.getRoot();
+
+ OneWaySynchronizedCopyFileSystem fs = new OneWaySynchronizedCopyFileSystem(existing, dirRoot);
+
+ VirtualFile newVirtualFile = VFS.getChild("/vfs/new-jar");
+ mounts.add(VFS.mount(newVirtualFile, fs));
+
+ assertFalse(new File(dirRoot, "META-INF").exists());
+ assertTrue(newVirtualFile.getChild("META-INF").exists());
+ assertTrue(new File(dirRoot, "META-INF").exists());
+ assertTrue(newVirtualFile.getChild("META-INF").isDirectory());
+
+ assertFalse(newVirtualFile.getChild("missing.txt").exists());
+
+ File manifest = newVirtualFile.getChild("META-INF/MANIFEST.MF").getPhysicalFile();
+ assertTrue(manifest.exists());
+
+
+ assertCoppied(existing.getChild("META-INF/MANIFEST.MF"), newVirtualFile.getChild("META-INF/MANIFEST.MF"));
+
+ List<VirtualFile> children = newVirtualFile.getChildren();
+ assertEquals(2, children.size());
+ assertTrue(children.contains(newVirtualFile.getChild("org")));
+ assertTrue(children.contains(newVirtualFile.getChild("META-INF")));
+
+ assertFalse(new File(dirRoot, "org").exists());
+ assertTrue(newVirtualFile.getChild("org").exists());
+ assertTrue(new File(dirRoot, "org").exists());
+ } finally {
+ VFSUtils.safeClose(mounts);
+ }
+ }
+
+ /**
+ * Verify that copies that are added to the original are copied to the temporary location
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testAddFilesToOriginal() throws Exception
+ {
+ List<Closeable> mounts = new LinkedList<Closeable>();
+ try {
+ TempDir dir = getTempFileProvider().createTempDir("existing-jar1");
+ File existingDir = dir.getRoot();
+ VirtualFile existing = getVirtualFile("/vfs/test/jar1");
+ mounts.add(VFS.mountReal(existingDir, existing));
+
+ dir = getTempFileProvider().createTempDir("new-jar1");
+ File dirRoot = dir.getRoot();
+ OneWaySynchronizedCopyFileSystem fs = new OneWaySynchronizedCopyFileSystem(existing, dirRoot);
+
+ VirtualFile newVirtualFile = VFS.getChild("/vfs/new-jar");
+ mounts.add(VFS.mount(newVirtualFile, fs));
+
+ assertEmpty(newVirtualFile.getChildren());
+
+ File addedDir = new File(existingDir, "META-INF");
+ addedDir.mkdir();
+
+ assertTrue(newVirtualFile.getChild("META-INF").exists());
+ assertTrue(new File(dirRoot, "META-INF").exists());
+ assertTrue(newVirtualFile.getChild("META-INF").isDirectory());
+
+ assertFalse(newVirtualFile.getChild("test.txt").exists());
+
+ File addedFile = new File(existingDir, "test.txt");
+ VFSUtils.copyStreamAndClose(new StringInputStream("Some text"), new FileOutputStream(addedFile));
+ assertTrue(addedFile.exists());
+ assertTrue(existing.getChild("test.txt").exists());
+
+ assertFalse(new File(dirRoot, "test.txt").exists());
+
+ List<VirtualFile> children = newVirtualFile.getChildren();
+ assertEquals(2, children.size());
+ assertTrue(children.contains(newVirtualFile.getChild("test.txt")));
+ assertTrue(children.contains(newVirtualFile.getChild("META-INF")));
+
+ assertFalse(new File(dirRoot, "test.txt").exists());
+
+ assertTrue(newVirtualFile.getChild("test.txt").exists());
+ assertTrue(new File(dirRoot, "test.txt").exists());
+
+ assertCoppied(existing.getChild("test.txt"), newVirtualFile.getChild("test.txt"));
+
+ } finally {
+ VFSUtils.safeClose(mounts);
+ }
+ }
+
+ /**
+ * Verify that files added to the temporary copy are not delete because they are missing in the original
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testAddFilesToCopy() throws Exception
+ {
+ List<Closeable> mounts = new LinkedList<Closeable>();
+ try {
+ TempDir dir = getTempFileProvider().createTempDir("existing-jar1");
+ File existingDir = dir.getRoot();
+ VirtualFile existing = getVirtualFile("/vfs/test/jar1");
+ mounts.add(VFS.mountReal(existingDir, existing));
+
+ dir = getTempFileProvider().createTempDir("new-jar1");
+ File dirRoot = dir.getRoot();
+ OneWaySynchronizedCopyFileSystem fs = new OneWaySynchronizedCopyFileSystem(existing, dirRoot);
+
+ VirtualFile newVirtualFile = VFS.getChild("/vfs/new-jar");
+ mounts.add(VFS.mount(newVirtualFile, fs));
+
+ assertEmpty(newVirtualFile.getChildren());
+
+ File addedDir = new File(dirRoot, "META-INF");
+ addedDir.mkdir();
+ assertTrue(addedDir.exists());
+
+ assertTrue(newVirtualFile.getChild("META-INF").exists());
+
+ File addedFile = new File(dirRoot, "test.txt");
+ VFSUtils.copyStreamAndClose(new StringInputStream("Some text"), new FileOutputStream(addedFile));
+ assertTrue(addedFile.exists());
+ assertFalse(existing.getChild("test.txt").exists());
+
+ assertTrue(newVirtualFile.getChild("test.txt").exists());
+
+ } finally {
+ VFSUtils.safeClose(mounts);
+ }
+ }
+
+ /**
+ * Verify that changes made to the original are correctly made to the copy
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testUpdateFilesFromOriginal() throws Exception
+ {
+ List<Closeable> mounts = new LinkedList<Closeable>();
+ try {
+ TempDir dir = getTempFileProvider().createTempDir("existing-jar1");
+ File existingDir = dir.getRoot();
+ VirtualFile existing = getVirtualFile("/vfs/test/jar1");
+ mounts.add(VFS.mountReal(existingDir, existing));
+
+ dir = getTempFileProvider().createTempDir("new-jar1");
+ File dirRoot = dir.getRoot();
+ OneWaySynchronizedCopyFileSystem fs = new OneWaySynchronizedCopyFileSystem(existing, dirRoot);
+
+ VirtualFile newVirtualFile = VFS.getChild("/vfs/new-jar");
+ mounts.add(VFS.mount(newVirtualFile, fs));
+
+
+ File addedFile = new File(existingDir, "test.txt");
+ VFSUtils.copyStreamAndClose(new StringInputStream("Some text"), new FileOutputStream(addedFile));
+ assertTrue(addedFile.exists());
+ assertTrue(newVirtualFile.getChild("test.txt").exists());
+ assertTrue(new File(dirRoot, "test.txt").exists());
+ assertCoppied(existing.getChild("test.txt"), newVirtualFile.getChild("test.txt"));
+
+ Thread.sleep(1000);
+
+ VFSUtils.copyStreamAndClose(new StringInputStream("Some other text"), new FileOutputStream(addedFile));
+
+ assertCoppied(existing.getChild("test.txt"), newVirtualFile.getChild("test.txt"));
+ } finally {
+ VFSUtils.safeClose(mounts);
+ }
+ }
+
+ /**
+ * Verify that files deleted from the original are deleted from the copy
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testDeleteFilesFromOriginal() throws Exception
+ {
+ List<Closeable> mounts = new LinkedList<Closeable>();
+ try {
+ TempDir dir = getTempFileProvider().createTempDir("existing-jar1");
+ File existingDir = dir.getRoot();
+ VirtualFile existing = getVirtualFile("/vfs/test/jar1");
+ mounts.add(VFS.mountReal(existingDir, existing));
+
+ dir = getTempFileProvider().createTempDir("new-jar1");
+ File dirRoot = dir.getRoot();
+ OneWaySynchronizedCopyFileSystem fs = new OneWaySynchronizedCopyFileSystem(existing, dirRoot);
+
+ VirtualFile newVirtualFile = VFS.getChild("/vfs/new-jar");
+ mounts.add(VFS.mount(newVirtualFile, fs));
+
+ File addedFile = new File(existingDir, "test.txt");
+ VFSUtils.copyStreamAndClose(new StringInputStream("Some text"), new FileOutputStream(addedFile));
+ assertTrue(addedFile.exists());
+ assertTrue(existing.getChild("test.txt").exists());
+
+ assertTrue(newVirtualFile.getChild("test.txt").exists());
+ assertTrue(new File(dirRoot, "test.txt").exists());
+
+ addedFile.delete();
+ assertFalse(addedFile.exists());
+ assertFalse(existing.getChild("test.txt").exists());
+
+ // Still in local temp.
+ assertTrue(new File(dirRoot, "test.txt").exists());
+
+ List<VirtualFile> children = newVirtualFile.getChildren();
+ assertEquals(0, children.size());
+
+ assertFalse(newVirtualFile.getChild("test.txt").exists());
+ assertFalse(new File(dirRoot, "test.txt").exists());
+
+ } finally {
+ VFSUtils.safeClose(mounts);
+ }
+ }
+
+ /**
+ * Verify that files deleted from the copy are not re-copied from the original
+ * @throws Exception
+ */
+ @Test
+ public void testDeleteFilesFromCopy() throws Exception
+ {
+ List<Closeable> mounts = new LinkedList<Closeable>();
+ try {
+ TempDir dir = getTempFileProvider().createTempDir("existing-jar1");
+ File existingDir = dir.getRoot();
+ VirtualFile existing = getVirtualFile("/vfs/test/jar1");
+ mounts.add(VFS.mountReal(existingDir, existing));
+
+ dir = getTempFileProvider().createTempDir("new-jar1");
+ File dirRoot = dir.getRoot();
+ OneWaySynchronizedCopyFileSystem fs = new OneWaySynchronizedCopyFileSystem(existing, dirRoot);
+
+ VirtualFile newVirtualFile = VFS.getChild("/vfs/new-jar");
+ mounts.add(VFS.mount(newVirtualFile, fs));
+
+ File addedFile = new File(existingDir, "test.txt");
+ VFSUtils.copyStreamAndClose(new StringInputStream("Some text"), new FileOutputStream(addedFile));
+ assertTrue(addedFile.exists());
+ assertTrue(existing.getChild("test.txt").exists());
+
+ assertTrue(newVirtualFile.getChild("test.txt").exists());
+ assertTrue(new File(dirRoot, "test.txt").exists());
+
+ newVirtualFile.getChild("test.txt").delete();
+ assertFalse(newVirtualFile.getChild("test.txt").exists());
+ assertTrue(existing.getChild("test.txt").exists());
+
+ addedFile = new File(existingDir, "test2.txt");
+ VFSUtils.copyStreamAndClose(new StringInputStream("Some text"), new FileOutputStream(addedFile));
+ assertTrue(addedFile.exists());
+ assertTrue(existing.getChild("test2.txt").exists());
+
+ assertTrue(newVirtualFile.getChild("test2.txt").exists());
+
+ File copiedFIle = new File(dirRoot, "test2.txt");
+ copiedFIle.delete();
+
+ assertFalse(newVirtualFile.getChild("test2.txt").exists());
+ } finally {
+ VFSUtils.safeClose(mounts);
+ }
+ }
+
+ private void assertCoppied(VirtualFile expected, VirtualFile actual) throws ArrayComparisonFailure, IOException
+ {
+ assertContentEqual(expected, actual);
+ assertEquals(expected.getLastModified(), actual.getLastModified());
+ }
+
+ private TempFileProvider getTempFileProvider() throws IOException {
+ if(tempFileProvider == null)
+ tempFileProvider = TempFileProvider.create("Test", Executors.newSingleThreadScheduledExecutor());
+ return tempFileProvider;
+ }
+}
Modified: projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/vfs/URLConnectionUnitTestCase.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/vfs/URLConnectionUnitTestCase.java 2009-12-29 17:12:56 UTC (rev 98947)
+++ projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/vfs/URLConnectionUnitTestCase.java 2009-12-29 17:36:55 UTC (rev 98948)
@@ -57,8 +57,7 @@
protected VirtualFile getFile() throws Exception
{
- URL url = getResource("/vfs/test/");
- VirtualFile root = VFS.getChild(url);
+ VirtualFile root = getVirtualFile("/vfs/test/");
VirtualFile file = root.getChild(getFileName());
assertNotNull(file);
return file;
Added: projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/vfs/VFSUtilsTestCase.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/vfs/VFSUtilsTestCase.java (rev 0)
+++ projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/vfs/VFSUtilsTestCase.java 2009-12-29 17:36:55 UTC (rev 98948)
@@ -0,0 +1,79 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.vfs;
+
+import static org.junit.Assert.*;
+
+import java.io.ByteArrayOutputStream;
+import java.io.Closeable;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.concurrent.Executors;
+
+import org.jboss.vfs.TempFileProvider;
+import org.jboss.vfs.VFS;
+import org.jboss.vfs.VFSUtils;
+import org.jboss.vfs.VirtualFile;
+import org.junit.Test;
+import org.junit.internal.ArrayComparisonFailure;
+
+/**
+ * Test to ensure the functionality of {@link VFSUtils} methods
+ *
+ * @author <a href="baileyje at gmail.com">John Bailey</a>
+ */
+public class VFSUtilsTestCase extends AbstractVFSTest
+{
+ public VFSUtilsTestCase(String name)
+ {
+ super(name);
+ }
+
+ @Test
+ public void testCopyChildrenRecursive() throws Exception
+ {
+ VirtualFile original = getVirtualFile("/vfs/test/jar1");
+ VirtualFile target = VFS.getChild("/target-jar1");
+ Closeable handle = null;
+ try {
+ handle = VFS.mountTemp(target, TempFileProvider.create("test", Executors.newSingleThreadScheduledExecutor()));
+ VFSUtils.copyChildrenRecursive(original, target);
+ assertChildren(original, target);
+
+ } finally {
+ VFSUtils.safeClose(handle);
+ }
+ }
+
+ private void assertChildren(VirtualFile original, VirtualFile target) throws ArrayComparisonFailure, IOException {
+ assertEquals("Original and target must have the same numer of children", original.getChildren().size(), target.getChildren().size());
+ for(VirtualFile child : original.getChildren()) {
+ VirtualFile targetChild = target.getChild(child.getName());
+ assertTrue("Target should contain same children as original", targetChild.exists());
+ if(child.isDirectory())
+ assertChildren(child, targetChild);
+ else {
+ assertContentEqual(child, targetChild);
+ }
+ }
+ }
+}
Deleted: projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/vfs/VirtualJarInputStreamTest.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/vfs/VirtualJarInputStreamTest.java 2009-12-29 17:12:56 UTC (rev 98947)
+++ projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/vfs/VirtualJarInputStreamTest.java 2009-12-29 17:36:55 UTC (rev 98948)
@@ -1,281 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2009, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.test.vfs;
-
-import java.io.ByteArrayOutputStream;
-import java.io.Closeable;
-import java.io.File;
-import java.io.IOException;
-import java.net.URL;
-import java.util.Arrays;
-import java.util.Enumeration;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.concurrent.ScheduledThreadPoolExecutor;
-import java.util.jar.Attributes;
-import java.util.jar.JarEntry;
-import java.util.jar.JarFile;
-import java.util.jar.JarInputStream;
-import java.util.jar.Manifest;
-
-import org.jboss.vfs.TempFileProvider;
-import org.jboss.vfs.VFS;
-import org.jboss.vfs.VFSUtils;
-import org.jboss.vfs.VirtualFile;
-import org.jboss.vfs.VirtualJarInputStream;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- * Test to ensure the functionality of {@link VirtualJarInputStream}
- *
- * @author <a href="baileyje at gmail.com">John Bailey</a>
- */
-public class VirtualJarInputStreamTest extends AbstractVFSTest {
-
- private TempFileProvider provider;
-
- public VirtualJarInputStreamTest(String name) {
- super(name);
- }
-
- @Before
- public void setUp() throws Exception {
- super.setUp();
- provider = TempFileProvider.create("test", new ScheduledThreadPoolExecutor(2));
- }
-
- @Test
- public void testIteration() throws Exception {
- URL rootURL = getResource("/vfs/test/");
- VirtualFile testdir = VFS.getChild(rootURL.getPath());
-
- VirtualFile jar = testdir.getChild("jar1.jar");
- Closeable mount = VFS.mountZip(jar, jar, provider);
- try {
- JarInputStream jarInput = (JarInputStream) jar.openStream();
- JarEntry next = null;
-
- List<String> entryNames = new LinkedList<String>();
- while ((next = jarInput.getNextJarEntry()) != null) {
- entryNames.add(next.getName());
- }
- JarFile jarFile = new JarFile(new File(new URL(rootURL, "jar1.jar").toURI()));
- Enumeration<JarEntry> entries = jarFile.entries();
- while(entries.hasMoreElements()) {
- String entryName = entries.nextElement().getName();
- assertTrue("JarEntry for " + entryName + " should be found in VirtualJarInputStream", entryNames.contains(entryName));
- }
- }
- finally {
- mount.close();
- }
- }
-
- @Test
- public void testIterationNonJar() throws Exception {
- URL rootURL = getResource("/vfs/test");
- VirtualFile testdir = VFS.getChild(rootURL.getPath());
-
- VirtualFile jar = testdir.getChild("jar1");
- Closeable mount = VFS.mountReal(jar.getPhysicalFile(), jar);
- try {
- JarInputStream jarInput = (JarInputStream) jar.openStream();
- JarEntry next = null;
-
- List<String> entryNames = new LinkedList<String>();
- while ((next = jarInput.getNextJarEntry()) != null) {
- entryNames.add(next.getName());
- }
- assertTrue(entryNames.contains("META-INF/MANIFEST.MF"));
- assertTrue(entryNames.contains("org/jboss/test/vfs/support/jar1/ClassInJar1$InnerClass.class"));
- assertTrue(entryNames.contains("org/jboss/test/vfs/support/jar1/ClassInJar1.class"));
- }
- finally {
- mount.close();
- }
- }
-
- @Test
- public void testRead() throws Exception {
- URL rootURL = getResource("/vfs/test");
- VirtualFile testdir = VFS.getChild(rootURL.getPath());
-
- VirtualFile jar = testdir.getChild("jar1.jar");
- Closeable mount = VFS.mountZip(jar, jar, provider);
- try {
- JarInputStream jarInput = (JarInputStream) jar.openStream();
- JarEntry next = jarInput.getNextJarEntry();
- assertEquals("META-INF/MANIFEST.MF", next.getName());
-
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- VFSUtils.copyStreamAndClose(jarInput, baos);
- byte[] actualBytes = baos.toByteArray();
-
- baos.reset();
-
- VFSUtils.copyStreamAndClose(jar.getChild("META-INF/MANIFEST.MF").openStream(), baos);
- byte[] expectedBytes = baos.toByteArray();
-
- assertTrue(Arrays.equals(expectedBytes, actualBytes));
- }
- finally {
- mount.close();
- }
- }
-
- @Test
- public void testReadNonJar() throws Exception {
- URL rootURL = getResource("/vfs/test");
- VirtualFile testdir = VFS.getChild(rootURL.getPath());
-
- VirtualFile jar = testdir.getChild("jar1");
- Closeable mount = VFS.mountReal(jar.getPhysicalFile(), jar);
- try {
- JarInputStream jarInput = (JarInputStream) jar.openStream();
- JarEntry next = jarInput.getNextJarEntry();
- assertEquals("META-INF/MANIFEST.MF", next.getName());
-
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- VFSUtils.copyStreamAndClose(jarInput, baos);
- byte[] actualBytes = baos.toByteArray();
-
- baos.reset();
-
- VFSUtils.copyStreamAndClose(jar.getChild("META-INF/MANIFEST.MF").openStream(), baos);
- byte[] expectedBytes = baos.toByteArray();
-
- assertTrue(Arrays.equals(expectedBytes, actualBytes));
- }
- finally {
- mount.close();
- }
- }
-
- @Test
- public void testReadClosed() throws Exception {
- URL rootURL = getResource("/vfs/test");
- VirtualFile testdir = VFS.getChild(rootURL.getPath());
-
- VirtualFile jar = testdir.getChild("jar1.jar");
- Closeable mount = VFS.mountZip(jar, jar, provider);
- try {
- JarInputStream jarInput = (JarInputStream) jar.openStream();
- JarEntry next = jarInput.getNextJarEntry();
- assertEquals("META-INF/MANIFEST.MF", next.getName());
-
- jarInput.close();
- try {
- jarInput.read();
- fail("Should have thrown IOException");
- }
- catch (IOException expected) {
- }
- }
- finally {
- mount.close();
- }
- }
-
- @Test
- public void testGetManifest() throws Exception {
- URL rootURL = getResource("/vfs/test");
- VirtualFile testdir = VFS.getChild(rootURL.getPath());
-
- VirtualFile jar = testdir.getChild("jar1.jar");
- Closeable mount = VFS.mountZip(jar, jar, provider);
- try {
- JarInputStream jarInput = (JarInputStream) jar.openStream();
- Manifest actual = jarInput.getManifest();
- Manifest expected = VFSUtils.getManifest(jar);
- assertEquals(expected, actual);
- }
- finally {
- mount.close();
- }
- }
-
- @Test
- public void testGetManifestNonJar() throws Exception {
- URL rootURL = getResource("/vfs/test");
- VirtualFile testdir = VFS.getChild(rootURL.getPath());
-
- VirtualFile jar = testdir.getChild("jar1");
- Closeable mount = VFS.mountReal(jar.getPhysicalFile(), jar);
- try {
- JarInputStream jarInput = (JarInputStream) jar.openStream();
- Manifest actual = jarInput.getManifest();
- Manifest expected = VFSUtils.getManifest(jar);
- assertEquals(expected, actual);
- }
- finally {
- mount.close();
- }
- }
-
- @Test
- public void testGetAttributes() throws Exception {
- URL rootURL = getResource("/vfs/test");
- VirtualFile testdir = VFS.getChild(rootURL.getPath());
-
- VirtualFile jar = testdir.getChild("jar1.jar");
- Closeable mount = VFS.mountZip(jar, jar, provider);
- try {
- JarInputStream jarInput = (JarInputStream) jar.openStream();
- Manifest manifest = jarInput.getManifest();
-
- JarEntry next = null;
- while ((next = jarInput.getNextJarEntry()) != null) {
- Attributes expected = manifest.getAttributes(next.getName());
- Attributes actual = next.getAttributes();
- assertEquals(expected, actual);
- }
- }
- finally {
- mount.close();
- }
- }
-
- @Test
- public void testGetAttributesNonJar() throws Exception {
- URL rootURL = getResource("/vfs/test");
- VirtualFile testdir = VFS.getChild(rootURL.getPath());
-
- VirtualFile jar = testdir.getChild("jar1");
- Closeable mount = VFS.mountReal(jar.getPhysicalFile(), jar);
- try {
- JarInputStream jarInput = (JarInputStream) jar.openStream();
- Manifest manifest = jarInput.getManifest();
-
- JarEntry next = null;
- while ((next = jarInput.getNextJarEntry()) != null) {
- Attributes expected = manifest.getAttributes(next.getName());
- Attributes actual = next.getAttributes();
- assertEquals(expected, actual);
- }
- }
- finally {
- mount.close();
- }
- }
-
-}
Copied: projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/vfs/VirtualJarInputStreamTestCase.java (from rev 97992, projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/vfs/VirtualJarInputStreamTest.java)
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/vfs/VirtualJarInputStreamTestCase.java (rev 0)
+++ projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/vfs/VirtualJarInputStreamTestCase.java 2009-12-29 17:36:55 UTC (rev 98948)
@@ -0,0 +1,256 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.vfs;
+
+import java.io.ByteArrayOutputStream;
+import java.io.Closeable;
+import java.io.File;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Enumeration;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.concurrent.ScheduledThreadPoolExecutor;
+import java.util.jar.Attributes;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+import java.util.jar.JarInputStream;
+import java.util.jar.Manifest;
+
+import org.jboss.vfs.TempFileProvider;
+import org.jboss.vfs.VFS;
+import org.jboss.vfs.VFSUtils;
+import org.jboss.vfs.VirtualFile;
+import org.jboss.vfs.VirtualJarInputStream;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Test to ensure the functionality of {@link VirtualJarInputStream}
+ *
+ * @author <a href="baileyje at gmail.com">John Bailey</a>
+ */
+public class VirtualJarInputStreamTestCase extends AbstractVFSTest {
+
+ private TempFileProvider provider;
+
+ private VirtualFile testdir;
+
+ public VirtualJarInputStreamTestCase(String name) {
+ super(name);
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ super.setUp();
+ provider = TempFileProvider.create("test", new ScheduledThreadPoolExecutor(2));
+ testdir = getVirtualFile("/vfs/test");
+ }
+
+ @Test
+ public void testIteration() throws Exception {
+ VirtualFile jar = testdir.getChild("jar1.jar");
+ Closeable mount = VFS.mountZip(jar, jar, provider);
+ try {
+ JarInputStream jarInput = (JarInputStream) jar.openStream();
+ JarEntry next = null;
+
+ List<String> entryNames = new LinkedList<String>();
+ while ((next = jarInput.getNextJarEntry()) != null) {
+ entryNames.add(next.getName());
+ }
+ JarFile jarFile = new JarFile(new File(getResource("/vfs/test/jar1.jar").toURI()));
+ Enumeration<JarEntry> entries = jarFile.entries();
+ while(entries.hasMoreElements()) {
+ String entryName = entries.nextElement().getName();
+ assertTrue("JarEntry for " + entryName + " should be found in VirtualJarInputStream", entryNames.contains(entryName));
+ }
+ }
+ finally {
+ mount.close();
+ }
+ }
+
+ @Test
+ public void testIterationNonJar() throws Exception {
+ VirtualFile jar = testdir.getChild("jar1");
+ Closeable mount = VFS.mountReal(jar.getPhysicalFile(), jar);
+ try {
+ JarInputStream jarInput = (JarInputStream) jar.openStream();
+ JarEntry next = null;
+
+ List<String> entryNames = new LinkedList<String>();
+ while ((next = jarInput.getNextJarEntry()) != null) {
+ entryNames.add(next.getName());
+ }
+ assertTrue(entryNames.contains("META-INF/MANIFEST.MF"));
+ assertTrue(entryNames.contains("org/jboss/test/vfs/support/jar1/ClassInJar1$InnerClass.class"));
+ assertTrue(entryNames.contains("org/jboss/test/vfs/support/jar1/ClassInJar1.class"));
+ }
+ finally {
+ mount.close();
+ }
+ }
+
+ @Test
+ public void testRead() throws Exception {
+ VirtualFile jar = testdir.getChild("jar1.jar");
+ Closeable mount = VFS.mountZip(jar, jar, provider);
+ try {
+ JarInputStream jarInput = (JarInputStream) jar.openStream();
+ JarEntry next = jarInput.getNextJarEntry();
+ assertEquals("META-INF/MANIFEST.MF", next.getName());
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ VFSUtils.copyStreamAndClose(jarInput, baos);
+ byte[] actualBytes = baos.toByteArray();
+
+ baos.reset();
+
+ VFSUtils.copyStreamAndClose(jar.getChild("META-INF/MANIFEST.MF").openStream(), baos);
+ byte[] expectedBytes = baos.toByteArray();
+
+ assertTrue(Arrays.equals(expectedBytes, actualBytes));
+ }
+ finally {
+ mount.close();
+ }
+ }
+
+ @Test
+ public void testReadNonJar() throws Exception {
+ VirtualFile jar = testdir.getChild("jar1");
+ Closeable mount = VFS.mountReal(jar.getPhysicalFile(), jar);
+ try {
+ JarInputStream jarInput = (JarInputStream) jar.openStream();
+ JarEntry next = jarInput.getNextJarEntry();
+ assertEquals("META-INF/MANIFEST.MF", next.getName());
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ VFSUtils.copyStreamAndClose(jarInput, baos);
+ byte[] actualBytes = baos.toByteArray();
+
+ baos.reset();
+
+ VFSUtils.copyStreamAndClose(jar.getChild("META-INF/MANIFEST.MF").openStream(), baos);
+ byte[] expectedBytes = baos.toByteArray();
+
+ assertTrue(Arrays.equals(expectedBytes, actualBytes));
+ }
+ finally {
+ mount.close();
+ }
+ }
+
+ @Test
+ public void testReadClosed() throws Exception {
+ VirtualFile jar = testdir.getChild("jar1.jar");
+ Closeable mount = VFS.mountZip(jar, jar, provider);
+ try {
+ JarInputStream jarInput = (JarInputStream) jar.openStream();
+ JarEntry next = jarInput.getNextJarEntry();
+ assertEquals("META-INF/MANIFEST.MF", next.getName());
+
+ jarInput.close();
+ try {
+ jarInput.read();
+ fail("Should have thrown IOException");
+ }
+ catch (IOException expected) {
+ }
+ }
+ finally {
+ mount.close();
+ }
+ }
+
+ @Test
+ public void testGetManifest() throws Exception {
+ VirtualFile jar = testdir.getChild("jar1.jar");
+ Closeable mount = VFS.mountZip(jar, jar, provider);
+ try {
+ JarInputStream jarInput = (JarInputStream) jar.openStream();
+ Manifest actual = jarInput.getManifest();
+ Manifest expected = VFSUtils.getManifest(jar);
+ assertEquals(expected, actual);
+ }
+ finally {
+ mount.close();
+ }
+ }
+
+ @Test
+ public void testGetManifestNonJar() throws Exception {
+ VirtualFile jar = testdir.getChild("jar1");
+ Closeable mount = VFS.mountReal(jar.getPhysicalFile(), jar);
+ try {
+ JarInputStream jarInput = (JarInputStream) jar.openStream();
+ Manifest actual = jarInput.getManifest();
+ Manifest expected = VFSUtils.getManifest(jar);
+ assertEquals(expected, actual);
+ }
+ finally {
+ mount.close();
+ }
+ }
+
+ @Test
+ public void testGetAttributes() throws Exception {
+ VirtualFile jar = testdir.getChild("jar1.jar");
+ Closeable mount = VFS.mountZip(jar, jar, provider);
+ try {
+ JarInputStream jarInput = (JarInputStream) jar.openStream();
+ Manifest manifest = jarInput.getManifest();
+
+ JarEntry next = null;
+ while ((next = jarInput.getNextJarEntry()) != null) {
+ Attributes expected = manifest.getAttributes(next.getName());
+ Attributes actual = next.getAttributes();
+ assertEquals(expected, actual);
+ }
+ }
+ finally {
+ mount.close();
+ }
+ }
+
+ @Test
+ public void testGetAttributesNonJar() throws Exception {
+ VirtualFile jar = testdir.getChild("jar1");
+ Closeable mount = VFS.mountReal(jar.getPhysicalFile(), jar);
+ try {
+ JarInputStream jarInput = (JarInputStream) jar.openStream();
+ Manifest manifest = jarInput.getManifest();
+
+ JarEntry next = null;
+ while ((next = jarInput.getNextJarEntry()) != null) {
+ Attributes expected = manifest.getAttributes(next.getName());
+ Attributes actual = next.getAttributes();
+ assertEquals(expected, actual);
+ }
+ }
+ finally {
+ mount.close();
+ }
+ }
+
+}
More information about the jboss-cvs-commits
mailing list