[jboss-cvs] JBossAS SVN: r74866 - in projects/vfs/trunk/src/test/java/org/jboss/test/virtual: test and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Jun 19 19:48:31 EDT 2008
Author: alesj
Date: 2008-06-19 19:48:30 -0400 (Thu, 19 Jun 2008)
New Revision: 74866
Added:
projects/vfs/trunk/src/test/java/org/jboss/test/virtual/support/VirtualFileAdaptor.java
Modified:
projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/JARSerializationUnitTestCase.java
Log:
VFA test.
Added: projects/vfs/trunk/src/test/java/org/jboss/test/virtual/support/VirtualFileAdaptor.java
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/virtual/support/VirtualFileAdaptor.java (rev 0)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/virtual/support/VirtualFileAdaptor.java 2008-06-19 23:48:30 UTC (rev 74866)
@@ -0,0 +1,131 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.virtual.support;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.ObjectStreamField;
+import java.io.Serializable;
+import java.net.URISyntaxException;
+import java.net.URL;
+
+import org.jboss.virtual.VFS;
+import org.jboss.virtual.VirtualFile;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class VirtualFileAdaptor implements Serializable
+{
+ private static final long serialVersionUID = -4509594124653184347L;
+
+ private static final ObjectStreamField[] serialPersistentFields =
+ {
+ new ObjectStreamField("rootUrl", URL.class),
+ new ObjectStreamField("path", String.class),
+ };
+
+ /** Minimal info to get full vfs file structure */
+ private URL rootUrl;
+ private String path;
+ /** The virtual file */
+ private transient VirtualFile file;
+
+ public VirtualFileAdaptor(VirtualFile file)
+ {
+ this.file = file;
+ }
+
+ public VirtualFileAdaptor(URL rootUrl, String path)
+ {
+ if (rootUrl == null)
+ throw new IllegalArgumentException("Null root url");
+ if (path == null)
+ throw new IllegalArgumentException("Null path");
+
+ this.rootUrl = rootUrl;
+ this.path = path;
+ }
+
+ /**
+ * Get the virtual file.
+ * Create file from root url and path if it doesn't exist yet.
+ *
+ * @return virtual file root
+ * @throws IOException for any error
+ */
+ @SuppressWarnings("deprecation")
+ protected VirtualFile getFile() throws IOException
+ {
+ if (file == null)
+ {
+ VirtualFile root = VFS.getRoot(rootUrl);
+ file = root.findChild(path);
+ }
+ return file;
+ }
+
+ @SuppressWarnings("deprecation")
+ public VirtualFileAdaptor findChild(String child) throws IOException
+ {
+ VirtualFile vf = getFile().findChild(child);
+ return new VirtualFileAdaptor(vf);
+ }
+
+ public URL toURL()
+ {
+ try
+ {
+ return getFile().toURL();
+ }
+ catch (Exception e)
+ {
+ return null;
+ }
+ }
+
+ private void writeObject(ObjectOutputStream out) throws IOException, URISyntaxException
+ {
+ URL url = rootUrl;
+ if (url == null)
+ {
+ VFS vfs = getFile().getVFS();
+ url = vfs.getRoot().toURL();
+ }
+ String pathName = path;
+ if (pathName == null)
+ pathName = getFile().getPathName();
+
+ ObjectOutputStream.PutField fields = out.putFields();
+ fields.put("rootUrl", url);
+ fields.put("path", pathName);
+ out.writeFields();
+ }
+
+ private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException
+ {
+ ObjectInputStream.GetField fields = in.readFields();
+ rootUrl = (URL) fields.get("rootUrl", null);
+ path = (String) fields.get("path", null);
+ }
+}
\ No newline at end of file
Modified: projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/JARSerializationUnitTestCase.java
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/JARSerializationUnitTestCase.java 2008-06-19 23:46:17 UTC (rev 74865)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/JARSerializationUnitTestCase.java 2008-06-19 23:48:30 UTC (rev 74866)
@@ -32,6 +32,7 @@
import junit.framework.Test;
import org.jboss.virtual.VFS;
import org.jboss.virtual.VirtualFile;
+import org.jboss.test.virtual.support.VirtualFileAdaptor;
/**
* Tests of no copy nested jars
@@ -238,6 +239,18 @@
assertTrue(text.length() > 0);
}
+ public void testVirtualFileAdaptor() throws Exception
+ {
+ URL rootURL = getResource("/vfs/test/interop_W2JREMarshallTest_appclient_vehicle.ear");
+ VFS vfs = VFS.getVFS(rootURL);
+ VirtualFile file = vfs.findChild("interop_W2JREMarshallTest_appclient_vehicle_client.jar");
+ VirtualFileAdaptor adaptor = new VirtualFileAdaptor(file);
+ // serialize
+ adaptor = serializeDeserialize(adaptor, VirtualFileAdaptor.class);
+ VirtualFileAdaptor child = adaptor.findChild("MarshallTest.xml");
+ assertNotNull(child);
+ }
+
protected String getText(VirtualFile file) throws Exception
{
InputStream in = file.openStream();
More information about the jboss-cvs-commits
mailing list