jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tri...@apache.org
Subject svn commit: r1569571 - in /jackrabbit/commons/filevault/trunk: vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/ vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/ vault-core/src/test/resources/org/apache/jackrabbit/v...
Date Wed, 19 Feb 2014 00:17:29 GMT
Author: tripod
Date: Wed Feb 19 00:17:29 2014
New Revision: 1569571

URL: http://svn.apache.org/r1569571
Log:
JCRVLT-31 Packages defined by a stream are copied to a file first

- enable hook tests
- generate proper systemid for memory archive

Modified:
    jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/MemoryArchive.java
    jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestPackageInstall.java
    jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/integration/testpackages/external_hook.zip
    jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/integration/testpackages/test_hook.zip
    jackrabbit/commons/filevault/trunk/vault-hook-example/src/main/java/org/apache/jackrabbit/vault/packaging/hooks/ExampleHook.java

Modified: jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/MemoryArchive.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/MemoryArchive.java?rev=1569571&r1=1569570&r2=1569571&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/MemoryArchive.java
(original)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/MemoryArchive.java
Wed Feb 19 00:17:29 2014
@@ -59,7 +59,7 @@ public class MemoryArchive extends Abstr
 
     public MemoryArchive(boolean metaOnly) throws IOException {
         this.cacheMetaOnly = metaOnly;
-        root = new VirtualEntry("", 0, null);
+        root = new VirtualEntry(null, "", 0, null);
         inf = new DefaultMetaInf();
     }
 
@@ -156,6 +156,16 @@ public class MemoryArchive extends Abstr
         }
         return new VaultInputSource() {
 
+            @Override
+            public String getSystemId() {
+                String systemId = super.getSystemId();
+                if (systemId == null) {
+                    systemId = ve.getPath();
+                    setSystemId(systemId);
+                }
+                return systemId;
+            }
+
             public InputStream getByteStream() {
                 return ve.data == null ? null : new ByteArrayInputStream(ve.data);
             }
@@ -190,6 +200,8 @@ public class MemoryArchive extends Abstr
 
     private static class VirtualEntry implements Entry {
 
+        private final VirtualEntry parent;
+
         private final String name;
 
         private final long time;
@@ -198,7 +210,8 @@ public class MemoryArchive extends Abstr
 
         private Map<String, VirtualEntry> children;
 
-        private VirtualEntry(String name, long time, byte[] data) {
+        private VirtualEntry(VirtualEntry parent, String name, long time, byte[] data) {
+            this.parent = parent;
             this.name = name;
             this.time = time;
             this.data = data;
@@ -208,6 +221,14 @@ public class MemoryArchive extends Abstr
             return name;
         }
 
+        public String getPath() {
+            return getPath(new StringBuilder()).toString();
+        }
+
+        private StringBuilder getPath(StringBuilder sb) {
+            return parent == null ? sb : parent.getPath(sb).append('/').append(name);
+        }
+
         public boolean isDirectory() {
             return data == null;
         }
@@ -227,7 +248,7 @@ public class MemoryArchive extends Abstr
                     return ret;
                 }
             }
-            VirtualEntry ve = new VirtualEntry(name, time, data);
+            VirtualEntry ve = new VirtualEntry(this, name, time, data);
             if (children == null) {
                 children = new LinkedHashMap<String, VirtualEntry>();
             }

Modified: jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestPackageInstall.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestPackageInstall.java?rev=1569571&r1=1569570&r2=1569571&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestPackageInstall.java
(original)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestPackageInstall.java
Wed Feb 19 00:17:29 2014
@@ -23,12 +23,14 @@ import java.io.IOException;
 import javax.jcr.RepositoryException;
 
 import org.apache.commons.io.FileUtils;
+import org.apache.jackrabbit.vault.packaging.InstallContext;
 import org.apache.jackrabbit.vault.packaging.JcrPackage;
 import org.apache.jackrabbit.vault.packaging.PackageException;
 import org.apache.tika.io.IOUtils;
 import org.junit.Test;
 
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
 /**
@@ -127,13 +129,34 @@ public class TestPackageInstall extends 
      */
     @Test
     public void testHook() throws RepositoryException, IOException, PackageException {
-        // Disabled for now, since the bundled package contains a hook that still contain
classes
-        // compiled the com.day.jcr.vault.*
+        if (admin.nodeExists("/testroot")) {
+            admin.getNode("/testroot").remove();
+        }
+        admin.getRootNode().addNode("testroot", "nt:unstructured").addNode("testnode", "nt:unstructured");
+        admin.save();
+        JcrPackage pack = packMgr.upload(getStream("testpackages/test_hook.zip"), false);
+        assertNotNull(pack);
+        pack.install(getDefaultOptions());
+        assertTrue(admin.propertyExists("/testroot/hook-example"));
+    }
 
-//        JcrPackage pack = packMgr.upload(getStream("testpackages/test_hook.zip"), false);
-//        assertNotNull(pack);
-//        pack.install(getDefaultOptions());
-//        assertProperty("/testroot/TestHook", InstallContext.Phase.INSTALLED.toString());
+    /**
+     * Installs a package with an install hook
+     */
+    @Test
+    public void testHookFail() throws RepositoryException, IOException, PackageException
{
+        if (admin.nodeExists("/testroot")) {
+            admin.getNode("/testroot").remove();
+        }
+        admin.save();
+        JcrPackage pack = packMgr.upload(getStream("testpackages/test_hook.zip"), false);
+        assertNotNull(pack);
+        try {
+            pack.install(getDefaultOptions());
+            fail("installing failing hook should fail");
+        } catch (PackageException e) {
+            // ok
+        }
     }
 
     /**
@@ -157,22 +180,18 @@ public class TestPackageInstall extends 
      */
     @Test
     public void testExternalHook() throws RepositoryException, IOException, PackageException
{
-        // Disabled for now, since the bundled package contains a hook that still contain
classes
-        // compiled the com.day.jcr.vault.*
+        if (!admin.nodeExists("/testroot")) {
+            admin.getRootNode().addNode("testroot", "nt:unstructured");
+            admin.save();
+        }
+
+        JcrPackage pack = packMgr.upload(getStream("testpackages/external_hook.zip"), false);
+        assertNotNull(pack);
 
+        pack.install(getDefaultOptions());
 
-//        if (!admin.nodeExists("/testroot")) {
-//            admin.getRootNode().addNode("testroot", "nt:unstructured");
-//            admin.save();
-//        }
-//
-//        JcrPackage pack = packMgr.upload(getStream("testpackages/external_hook.zip"), false);
-//        assertNotNull(pack);
-//
-//        pack.install(getDefaultOptions());
-//
-//        assertProperty("/testroot/TestHook1", InstallContext.Phase.END.toString());
-//        assertProperty("/testroot/TestHook2", InstallContext.Phase.END.toString());
+        assertProperty("/testroot/TestHook1", InstallContext.Phase.END.toString());
+        assertProperty("/testroot/TestHook2", InstallContext.Phase.END.toString());
     }
 
     /**

Modified: jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/integration/testpackages/external_hook.zip
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/integration/testpackages/external_hook.zip?rev=1569571&r1=1569570&r2=1569571&view=diff
==============================================================================
Binary files - no diff available.

Modified: jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/integration/testpackages/test_hook.zip
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/integration/testpackages/test_hook.zip?rev=1569571&r1=1569570&r2=1569571&view=diff
==============================================================================
Binary files - no diff available.

Modified: jackrabbit/commons/filevault/trunk/vault-hook-example/src/main/java/org/apache/jackrabbit/vault/packaging/hooks/ExampleHook.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-hook-example/src/main/java/org/apache/jackrabbit/vault/packaging/hooks/ExampleHook.java?rev=1569571&r1=1569570&r2=1569571&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-hook-example/src/main/java/org/apache/jackrabbit/vault/packaging/hooks/ExampleHook.java
(original)
+++ jackrabbit/commons/filevault/trunk/vault-hook-example/src/main/java/org/apache/jackrabbit/vault/packaging/hooks/ExampleHook.java
Wed Feb 19 00:17:29 2014
@@ -60,10 +60,10 @@ public class ExampleHook implements Inst
                     doInstallFailed(ctx);
                     break;
                 case PREPARE:
-                    doPreprare(ctx);
+                    doPrepare(ctx);
                     break;
                 case PREPARE_FAILED:
-                    doPreprareFailed(ctx);
+                    doPrepareFailed(ctx);
                     break;
             }
         } catch (RepositoryException e) {
@@ -71,7 +71,7 @@ public class ExampleHook implements Inst
         }
     }
 
-    private void doPreprare(InstallContext ctx) throws PackageException, RepositoryException
{
+    private void doPrepare(InstallContext ctx) throws PackageException, RepositoryException
{
         // read the properties from the package
         Properties props = ctx.getPackage().getMetaInf().getProperties();
         String copyFrom = props.getProperty(PROP_COPY_FROM, "");
@@ -92,7 +92,7 @@ public class ExampleHook implements Inst
 
     }
 
-    private void doPreprareFailed(InstallContext ctx) {
+    private void doPrepareFailed(InstallContext ctx) {
         // this is invoked when any of the hooks (including our self) threw a
         // package exception during prepare
     }



Mime
View raw message