[jboss-cvs] JBossAS SVN: r94267 - in projects/vfs/branches/Branch_2_1/src: test/java/org/jboss/test/virtual/support and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Oct 2 08:43:25 EDT 2009
Author: alesj
Date: 2009-10-02 08:43:25 -0400 (Fri, 02 Oct 2009)
New Revision: 94267
Added:
projects/vfs/branches/Branch_2_1/src/main/java/org/jboss/virtual/plugins/copy/DeleteOnExitTempStore.java
projects/vfs/branches/Branch_2_1/src/main/java/org/jboss/virtual/plugins/copy/MkdirTempStore.java
projects/vfs/branches/Branch_2_1/src/main/java/org/jboss/virtual/plugins/copy/TrackingTempStore.java
projects/vfs/branches/Branch_2_1/src/test/java/org/jboss/test/virtual/support/MockTempStore.java
projects/vfs/branches/Branch_2_1/src/test/java/org/jboss/test/virtual/test/TempStoreTestCase.java
Modified:
projects/vfs/branches/Branch_2_1/src/test/java/org/jboss/test/virtual/test/VFSAllTestSuite.java
Log:
[JBVFS-125]; test temp store.
Added: projects/vfs/branches/Branch_2_1/src/main/java/org/jboss/virtual/plugins/copy/DeleteOnExitTempStore.java
===================================================================
--- projects/vfs/branches/Branch_2_1/src/main/java/org/jboss/virtual/plugins/copy/DeleteOnExitTempStore.java (rev 0)
+++ projects/vfs/branches/Branch_2_1/src/main/java/org/jboss/virtual/plugins/copy/DeleteOnExitTempStore.java 2009-10-02 12:43:25 UTC (rev 94267)
@@ -0,0 +1,63 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.copy;
+
+import java.io.File;
+
+import org.jboss.virtual.spi.TempStore;
+import org.jboss.virtual.VirtualFile;
+
+/**
+ * Delete on exit temp store wrapper.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class DeleteOnExitTempStore implements TempStore
+{
+ private TempStore delegate;
+
+ public DeleteOnExitTempStore(TempStore delegate)
+ {
+ if (delegate == null)
+ throw new IllegalArgumentException("Null delegate");
+ this.delegate = delegate;
+ }
+
+ public File createTempFolder(VirtualFile file)
+ {
+ File dir = delegate.createTempFolder(file);
+ dir.deleteOnExit();
+ return dir;
+ }
+
+ public File createTempFolder(String outerName, String innerName)
+ {
+ File dir = delegate.createTempFolder(outerName, innerName);
+ dir.deleteOnExit();
+ return dir;
+ }
+
+ public void clear()
+ {
+ // do nothing
+ }
+}
Added: projects/vfs/branches/Branch_2_1/src/main/java/org/jboss/virtual/plugins/copy/MkdirTempStore.java
===================================================================
--- projects/vfs/branches/Branch_2_1/src/main/java/org/jboss/virtual/plugins/copy/MkdirTempStore.java (rev 0)
+++ projects/vfs/branches/Branch_2_1/src/main/java/org/jboss/virtual/plugins/copy/MkdirTempStore.java 2009-10-02 12:43:25 UTC (rev 94267)
@@ -0,0 +1,74 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.copy;
+
+import java.io.File;
+
+import org.jboss.virtual.spi.TempStore;
+import org.jboss.virtual.VirtualFile;
+
+/**
+ * Mkdir temp store wrapper.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class MkdirTempStore implements TempStore
+{
+ private TempStore delegate;
+
+ public MkdirTempStore(TempStore delegate)
+ {
+ if (delegate == null)
+ throw new IllegalArgumentException("Null delegate");
+ this.delegate = delegate;
+ }
+
+ /**
+ * Assert directory creation.
+ *
+ * @param dir the current directory
+ */
+ protected void assertMkdir(File dir)
+ {
+ if (dir.mkdir() == false)
+ throw new IllegalArgumentException("Cannot create directory: " + dir);
+ }
+
+ public File createTempFolder(VirtualFile file)
+ {
+ File dir = delegate.createTempFolder(file);
+ assertMkdir(dir);
+ return dir;
+ }
+
+ public File createTempFolder(String outerName, String innerName)
+ {
+ File dir = delegate.createTempFolder(outerName, innerName);
+ assertMkdir(dir);
+ return dir;
+ }
+
+ public void clear()
+ {
+ delegate.clear();
+ }
+}
\ No newline at end of file
Added: projects/vfs/branches/Branch_2_1/src/main/java/org/jboss/virtual/plugins/copy/TrackingTempStore.java
===================================================================
--- projects/vfs/branches/Branch_2_1/src/main/java/org/jboss/virtual/plugins/copy/TrackingTempStore.java (rev 0)
+++ projects/vfs/branches/Branch_2_1/src/main/java/org/jboss/virtual/plugins/copy/TrackingTempStore.java 2009-10-02 12:43:25 UTC (rev 94267)
@@ -0,0 +1,83 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.copy;
+
+import java.io.File;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.jboss.util.collection.ConcurrentSet;
+import org.jboss.util.file.Files;
+import org.jboss.virtual.VirtualFile;
+import org.jboss.virtual.spi.TempStore;
+
+/**
+ * Track files temp store.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class TrackingTempStore implements TempStore
+{
+ private TempStore delegate;
+ private Set<File> files;
+
+ public TrackingTempStore(TempStore delegate)
+ {
+ if (delegate == null)
+ throw new IllegalArgumentException("Null delegate");
+ this.delegate = delegate;
+ this.files = new ConcurrentSet<File>();
+ }
+
+ /**
+ * Get files.
+ *
+ * @return the files
+ */
+ public Set<File> getFiles()
+ {
+ return Collections.unmodifiableSet(files);
+ }
+
+ public File createTempFolder(VirtualFile file)
+ {
+ File dir = delegate.createTempFolder(file);
+ files.add(dir);
+ return dir;
+ }
+
+ public File createTempFolder(String outerName, String innerName)
+ {
+ File dir = delegate.createTempFolder(outerName, innerName);
+ files.add(dir);
+ return dir;
+ }
+
+ public void clear()
+ {
+ Set<File> copy = new HashSet<File>(files);
+ files.clear();
+ for (File dir : copy)
+ Files.delete(dir);
+ }
+}
\ No newline at end of file
Added: projects/vfs/branches/Branch_2_1/src/test/java/org/jboss/test/virtual/support/MockTempStore.java
===================================================================
--- projects/vfs/branches/Branch_2_1/src/test/java/org/jboss/test/virtual/support/MockTempStore.java (rev 0)
+++ projects/vfs/branches/Branch_2_1/src/test/java/org/jboss/test/virtual/support/MockTempStore.java 2009-10-02 12:43:25 UTC (rev 94267)
@@ -0,0 +1,57 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.File;
+
+import org.jboss.virtual.VirtualFile;
+import org.jboss.virtual.plugins.copy.AbstractCopyMechanism;
+import org.jboss.virtual.spi.TempStore;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class MockTempStore implements TempStore
+{
+ private File tempRoot = AbstractCopyMechanism.getTempDirectory();
+ private long seed;
+
+ public MockTempStore(long seed)
+ {
+ this.seed = seed;
+ }
+
+ public File createTempFolder(VirtualFile file)
+ {
+ String name = file.getName();
+ return new File(tempRoot, name + '_' + seed);
+ }
+
+ public File createTempFolder(String outerName, String innerName)
+ {
+ return new File(tempRoot, innerName + '_' + seed);
+ }
+
+ public void clear()
+ {
+ }
+}
Copied: projects/vfs/branches/Branch_2_1/src/test/java/org/jboss/test/virtual/test/TempStoreTestCase.java (from rev 93905, projects/vfs/branches/Branch_2_1/src/test/java/org/jboss/test/virtual/test/CopyTest.java)
===================================================================
--- projects/vfs/branches/Branch_2_1/src/test/java/org/jboss/test/virtual/test/TempStoreTestCase.java (rev 0)
+++ projects/vfs/branches/Branch_2_1/src/test/java/org/jboss/test/virtual/test/TempStoreTestCase.java 2009-10-02 12:43:25 UTC (rev 94267)
@@ -0,0 +1,104 @@
+/*
+* 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.File;
+import java.net.URL;
+
+import junit.framework.Test;
+import org.jboss.test.virtual.support.MockTempStore;
+import org.jboss.virtual.VFS;
+import org.jboss.virtual.VirtualFile;
+import org.jboss.virtual.VFSUtils;
+import org.jboss.virtual.plugins.copy.AbstractCopyMechanism;
+import org.jboss.virtual.plugins.copy.DeleteOnExitTempStore;
+import org.jboss.virtual.plugins.copy.MkdirTempStore;
+import org.jboss.virtual.plugins.copy.TrackingTempStore;
+import org.jboss.virtual.spi.TempStore;
+
+/**
+ * Test TempStore usage.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class TempStoreTestCase extends AbstractVFSTest
+{
+ public TempStoreTestCase(String s)
+ {
+ super(s);
+ }
+
+ public static Test suite()
+ {
+ return suite(TempStoreTestCase.class);
+ }
+
+ public void testCopyMechanism() throws Throwable
+ {
+ long seed = System.nanoTime();
+ URL url = getResource("/vfs/test");
+ VFS vfs = VFS.getVFS(url);
+ TempStore store = new MkdirTempStore(new DeleteOnExitTempStore(new MockTempStore(seed)));
+ vfs.setTempStore(store);
+ VirtualFile file = vfs.getChild("jar1.jar");
+ VirtualFile temp = VFSUtils.explode(file);
+ try
+ {
+ File tempRoot = AbstractCopyMechanism.getTempDirectory();
+ File test = new File(tempRoot, "jar1.jar" + '_' + seed);
+ assertTrue(test.exists()); // should be created by MockTS
+ }
+ finally
+ {
+ temp.cleanup();
+ }
+ }
+
+ public void testNestedZip() throws Throwable
+ {
+ long seed = System.nanoTime();
+ URL url = getResource("/vfs/test/nested");
+ VFS vfs = VFS.getVFS(url);
+ VFSUtils.enableCopy(vfs);
+ TempStore store = new MkdirTempStore(new TrackingTempStore(new MockTempStore(seed)));
+ try
+ {
+ vfs.setTempStore(store);
+ VirtualFile file = vfs.getChild("nested.jar");
+ assertNotNull(file.getChild("complex.jar/subfolder/subchild"));
+ try
+ {
+ File tempRoot = AbstractCopyMechanism.getTempDirectory();
+ File test = new File(tempRoot, "complex.jar" + '_' + seed);
+ assertTrue(test.exists()); // should be created by MockTS
+ }
+ finally
+ {
+ file.cleanup();
+ }
+ }
+ finally
+ {
+ store.clear();
+ }
+ }
+}
\ No newline at end of file
Modified: projects/vfs/branches/Branch_2_1/src/test/java/org/jboss/test/virtual/test/VFSAllTestSuite.java
===================================================================
--- projects/vfs/branches/Branch_2_1/src/test/java/org/jboss/test/virtual/test/VFSAllTestSuite.java 2009-10-02 12:02:03 UTC (rev 94266)
+++ projects/vfs/branches/Branch_2_1/src/test/java/org/jboss/test/virtual/test/VFSAllTestSuite.java 2009-10-02 12:43:25 UTC (rev 94267)
@@ -100,6 +100,8 @@
suite.addTest(CombinedVFSCacheTestCase.suite());
// exception handler
suite.addTest(ExceptionHandlerTestCase.suite());
+ // temp store
+ suite.addTest(TempStoreTestCase.suite());
// operations
suite.addTest(TempCleanupUnitTestCase.suite());
suite.addTest(ExplodeCleanupUnitTestCase.suite());
More information about the jboss-cvs-commits
mailing list