jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tri...@apache.org
Subject svn commit: r1727172 - in /jackrabbit/commons/filevault/trunk: parent/ vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/ vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/integration/testpackages/
Date Wed, 27 Jan 2016 20:04:06 GMT
Author: tripod
Date: Wed Jan 27 20:04:06 2016
New Revision: 1727172

URL: http://svn.apache.org/viewvc?rev=1727172&view=rev
Log:
JCRVLT-108 Import of binaries fail because they cannot be converted to strings

- adding more test cases

Modified:
    jackrabbit/commons/filevault/trunk/parent/pom.xml
    jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/IntegrationTestBase.java
    jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestBinarylessExport.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/tmp_binary.zip

Modified: jackrabbit/commons/filevault/trunk/parent/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/parent/pom.xml?rev=1727172&r1=1727171&r2=1727172&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/parent/pom.xml (original)
+++ jackrabbit/commons/filevault/trunk/parent/pom.xml Wed Jan 27 20:04:06 2016
@@ -41,7 +41,7 @@
 
     <properties>
         <jackrabbit.version>2.11.3</jackrabbit.version>
-        <oak.version>1.3.9</oak.version>
+        <oak.version>1.3.14</oak.version>
     </properties>
 
     <!-- ====================================================================== -->
@@ -321,7 +321,7 @@
             <dependency>
                 <groupId>commons-io</groupId>
                 <artifactId>commons-io</artifactId>
-                <version>1.4</version>
+                <version>2.4</version>
             </dependency>
             <dependency>
                 <groupId>commons-collections</groupId>

Modified: jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/IntegrationTestBase.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/IntegrationTestBase.java?rev=1727172&r1=1727171&r2=1727172&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/IntegrationTestBase.java
(original)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/IntegrationTestBase.java
Wed Jan 27 20:04:06 2016
@@ -48,11 +48,16 @@ import org.apache.jackrabbit.api.securit
 import org.apache.jackrabbit.commons.jackrabbit.authorization.AccessControlUtils;
 import org.apache.jackrabbit.core.RepositoryImpl;
 import org.apache.jackrabbit.core.config.RepositoryConfig;
+import org.apache.jackrabbit.core.data.FileDataStore;
 import org.apache.jackrabbit.core.security.principal.EveryonePrincipal;
 import org.apache.jackrabbit.core.security.principal.PrincipalImpl;
 import org.apache.jackrabbit.oak.jcr.Jcr;
+import org.apache.jackrabbit.oak.plugins.blob.datastore.DataStoreBlobStore;
+import org.apache.jackrabbit.oak.plugins.segment.SegmentNodeStore;
+import org.apache.jackrabbit.oak.plugins.segment.file.FileStore;
 import org.apache.jackrabbit.oak.security.SecurityProviderImpl;
 import org.apache.jackrabbit.oak.security.user.RandomAuthorizableNodeName;
+import org.apache.jackrabbit.oak.spi.blob.BlobStore;
 import org.apache.jackrabbit.oak.spi.security.ConfigurationParameters;
 import org.apache.jackrabbit.oak.spi.security.authorization.AuthorizationConfiguration;
 import org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeConstants;
@@ -70,6 +75,8 @@ import org.junit.After;
 import org.junit.AfterClass;
 import org.junit.Before;
 import org.junit.BeforeClass;
+import org.junit.Rule;
+import org.junit.rules.TemporaryFolder;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -91,6 +98,14 @@ public class IntegrationTestBase  {
     private static final Logger log = LoggerFactory.getLogger(IntegrationTestBase.class);
 
     private static final String REPO_HOME = "target/repository";
+    private static final File DIR_REPO_HOME = new File(REPO_HOME);
+    private static final File DIR_DATA_STORE = new File(REPO_HOME + "/datastore");
+    private static final File DIR_BLOB_STORE = new File(REPO_HOME + "/blobstore");
+
+    @Rule
+    public static TemporaryFolder tempFolder = new TemporaryFolder();
+
+    private static FileStore fileStore = null;
 
     protected static Repository repository;
 
@@ -99,7 +114,7 @@ public class IntegrationTestBase  {
     protected JcrPackageManager packMgr;
 
     @BeforeClass
-    public static void initRepository() throws RepositoryException {
+    public static void initRepository() throws RepositoryException, IOException {
         if (isOak()) {
             Properties userProps = new Properties();
             AuthorizableNodeName nameGenerator = new RandomAuthorizableNodeName();
@@ -115,7 +130,21 @@ public class IntegrationTestBase  {
             Properties securityProps = new Properties();
             securityProps.put(UserConfiguration.NAME, ConfigurationParameters.of(userProps));
             securityProps.put(AuthorizationConfiguration.NAME, ConfigurationParameters.of(authzProps));
-            repository = new Jcr()
+
+            Jcr jcr;
+            if (useFileStore()) {
+                BlobStore blobStore = createBlobStore();
+                DIR_DATA_STORE.mkdirs();
+                fileStore = FileStore.newFileStore(DIR_DATA_STORE)
+                        .withBlobStore(blobStore)
+                        .create();
+                SegmentNodeStore nodeStore = SegmentNodeStore.newSegmentNodeStore(fileStore).create();
+                jcr = new Jcr(nodeStore);
+            } else {
+                jcr = new Jcr();
+            }
+
+            repository = jcr
                     .with(new SecurityProviderImpl(ConfigurationParameters.of(securityProps)))
                     .createRepository();
 
@@ -134,12 +163,33 @@ public class IntegrationTestBase  {
                 repository.getDescriptor(Repository.REP_VERSION_DESC));
     }
 
+    public static boolean useFileStore() {
+        return true;
+    }
+
+    private static BlobStore createBlobStore() throws IOException {
+        DIR_BLOB_STORE.mkdirs();
+        FileDataStore fds = new FileDataStore();
+        fds.setMinRecordLength(4092);
+        fds.init(DIR_BLOB_STORE.getAbsolutePath());
+        return new DataStoreBlobStore(fds);
+    }
+
     @AfterClass
-    public static void shutdownRepository() {
+    public static void shutdownRepository() throws IOException {
         if (repository instanceof RepositoryImpl) {
             ((RepositoryImpl) repository).shutdown();
+        } else if (repository instanceof org.apache.jackrabbit.oak.jcr.repository.RepositoryImpl)
{
+            ((org.apache.jackrabbit.oak.jcr.repository.RepositoryImpl) repository).shutdown();
         }
         repository = null;
+
+        if (fileStore != null) {
+            fileStore.close();
+            fileStore = null;
+        }
+
+        FileUtils.deleteDirectory(DIR_REPO_HOME);
     }
 
     @Before
@@ -415,4 +465,35 @@ public class IntegrationTestBase  {
         admin.getAccessControlManager().setPolicy(path, acl);
         admin.save();
     }
+
+    public static class TrackingListener implements ProgressTrackerListener {
+
+        private final ProgressTrackerListener delegate;
+
+        private final Map<String, String> actions = new HashMap<String, String>();
+
+        public TrackingListener(ProgressTrackerListener delegate) {
+            this.delegate = delegate;
+        }
+
+        public Map<String, String> getActions() {
+            return actions;
+        }
+
+        @Override
+        public void onMessage(Mode mode, String action, String path) {
+            if (delegate != null) {
+                delegate.onMessage(mode, action, path);
+            }
+            actions.put(path, action);
+        }
+
+        @Override
+        public void onError(Mode mode, String path, Exception e) {
+            if (delegate != null) {
+                delegate.onError(mode, path, e);
+            }
+            actions.put(path, "E");
+        }
+    }
 }
\ No newline at end of file

Modified: jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestBinarylessExport.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestBinarylessExport.java?rev=1727172&r1=1727171&r2=1727172&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestBinarylessExport.java
(original)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestBinarylessExport.java
Wed Jan 27 20:04:06 2016
@@ -17,17 +17,22 @@
 
 package org.apache.jackrabbit.vault.packaging.integration;
 
+import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.IOUtils;
 import org.apache.jackrabbit.api.ReferenceBinary;
 import org.apache.jackrabbit.commons.JcrUtils;
 import org.apache.jackrabbit.vault.fs.api.PathFilterSet;
 import org.apache.jackrabbit.vault.fs.config.DefaultMetaInf;
 import org.apache.jackrabbit.vault.fs.config.DefaultWorkspaceFilter;
+import org.apache.jackrabbit.vault.fs.io.ImportOptions;
 import org.apache.jackrabbit.vault.packaging.ExportOptions;
+import org.apache.jackrabbit.vault.packaging.JcrPackage;
 import org.apache.jackrabbit.vault.packaging.PackageException;
 import org.apache.jackrabbit.vault.packaging.PackageProperties;
 import org.apache.jackrabbit.vault.packaging.VaultPackage;
 import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
 import org.junit.Test;
 
 import javax.jcr.Binary;
@@ -69,7 +74,6 @@ public class TestBinarylessExport extend
         BIG_TEXT = buffer.toString();
     }
 
-
     @Before
     public void setup() throws RepositoryException, PackageException, IOException {
         Node binaryNode = JcrUtils.getOrCreateByPath(BINARY_NODE_PATH, "nt:unstructured",
admin);
@@ -81,14 +85,18 @@ public class TestBinarylessExport extend
 
         Binary smallBin = admin.getValueFactory().createBinary(IOUtils.toInputStream(SMALL_TEXT,
"UTF-8"));
         Property smallProperty = binaryNode.setProperty(SMALL_BINARY_PROPERTY, smallBin);
-        assertFalse(smallProperty.getBinary() instanceof ReferenceBinary);
-
+        if (isOak()) {
+            assertTrue(smallProperty.getBinary() instanceof ReferenceBinary);
+        } else {
+            assertFalse(smallProperty.getBinary() instanceof ReferenceBinary);
+        }
 
         JcrUtils.putFile(binaryNode.getParent(), "file", "text/plain", IOUtils.toInputStream(BIG_TEXT,
"UTF-8"));
         admin.save();
     }
 
 
+
     @Test
     public void exportBinary() throws RepositoryException, IOException, PackageException
{
 
@@ -116,7 +124,7 @@ public class TestBinarylessExport extend
         assertNotNull(pkg.getArchive().getEntry("jcr_root"+ BINARY_NODE_PATH + "/" + SMALL_BINARY_PROPERTY
+ ".binary"));
 
 
-        admin.getNode(nodePath).remove();
+        clean(nodePath);
 
         pkg.extract(admin, getDefaultOptions());
 
@@ -155,7 +163,7 @@ public class TestBinarylessExport extend
 
         assertTrue(pkg.getArchive().getEntry("jcr_root" + FILE_NODE_PATH).isDirectory());
 
-        admin.getNode(nodePath).remove();
+        clean(nodePath);
 
         pkg.extract(admin, getDefaultOptions());
 
@@ -171,4 +179,53 @@ public class TestBinarylessExport extend
         pkg.close();
         tmpFile.delete();
     }
+
+    /**
+     * Tests if the same package installed twice does not report and update. See JCRVLT-108
+     */
+    @Test
+    @Ignore("JCRVLT-108")
+    public void importTwice() throws RepositoryException, IOException, PackageException {
+        String nodePath = BINARY_NODE_PATH;
+
+        ExportOptions opts = new ExportOptions();
+        DefaultMetaInf inf = new DefaultMetaInf();
+        DefaultWorkspaceFilter filter = new DefaultWorkspaceFilter();
+        filter.add(new PathFilterSet(nodePath));
+
+        inf.setFilter(filter);
+        Properties props = new Properties();
+        props.setProperty(VaultPackage.NAME_GROUP, "jackrabbit/test");
+        props.setProperty(VaultPackage.NAME_NAME, "test-package");
+        props.setProperty(PackageProperties.NAME_USE_BINARY_REFERENCES, "true");
+        inf.setProperties(props);
+
+        opts.setMetaInf(inf);
+
+        File tmpFile = File.createTempFile("vaulttest", "zip");
+        VaultPackage pkg = packMgr.assemble(admin, opts, tmpFile);
+        pkg.close();
+
+        clean(nodePath);
+
+        // import again
+        JcrPackage pack = packMgr.upload(FileUtils.openInputStream(tmpFile), false);
+        assertNotNull(pack);
+
+        ImportOptions io = getDefaultOptions();
+        TrackingListener listener = new TrackingListener(opts.getListener());
+        io.setListener(listener);
+        pack.install(io);
+        assertEquals("A", listener.getActions().get(BINARY_NODE_PATH));
+
+        // and again
+        io = getDefaultOptions();
+        listener = new TrackingListener(opts.getListener());
+        io.setListener(listener);
+
+        pack.install(io);
+        assertEquals("U", listener.getActions().get(BINARY_NODE_PATH));
+
+        tmpFile.delete();
+    }
 }
\ No newline at end of file

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=1727172&r1=1727171&r2=1727172&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 Jan 27 20:04:06 2016
@@ -28,12 +28,14 @@ import javax.jcr.RepositoryException;
 
 import org.apache.commons.io.FileUtils;
 import org.apache.derby.impl.load.Import;
+import org.apache.jackrabbit.vault.fs.api.ProgressTrackerListener;
 import org.apache.jackrabbit.vault.fs.io.ImportOptions;
 import org.apache.jackrabbit.vault.packaging.InstallContext;
 import org.apache.jackrabbit.vault.packaging.JcrPackage;
 import org.apache.jackrabbit.vault.packaging.PackageException;
 import org.apache.jackrabbit.vault.packaging.PackageId;
 import org.apache.tika.io.IOUtils;
+import org.junit.Ignore;
 import org.junit.Test;
 
 import static org.junit.Assert.assertEquals;
@@ -377,9 +379,11 @@ public class TestPackageInstall extends
     }
 
     /**
-     * Installs a package that and checks if snapshot is created
+     * Installs a binary properties twice to check if it doesn't report an update. JCRVLT-108.
+     * this only works for small binaries, though.
      */
     @Test
+    @Ignore("JCRVLT-108")
     public void testBinaryProperties() throws RepositoryException, IOException, PackageException
{
         JcrPackage pack = packMgr.upload(getStream("testpackages/tmp_binary.zip"), false);
         assertNotNull(pack);
@@ -387,7 +391,23 @@ public class TestPackageInstall extends
 
         Property p = admin.getProperty("/tmp/binary/test/jcr:data");
         assertEquals(PropertyType.BINARY, p.getType());
-        assertEquals("this is binary data.\n", p.getString());
+
+        StringBuilder buffer = new StringBuilder(8192);
+        while (buffer.length() < 8192) {
+            buffer.append("0123456789abcdef");
+        }
+        String result = IOUtils.toString(p.getBinary().getStream());
+
+        assertEquals(buffer.toString(), result);
+
+        // install again to check if binary data is not updated
+        ImportOptions opts = getDefaultOptions();
+        TrackingListener listener = new TrackingListener(opts.getListener());
+        opts.setListener(listener);
+
+        pack.install(opts);
+
+        assertEquals("-", listener.getActions().get("/tmp/binary/test"));
     }
 
     // todo: upload with version

Modified: jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/integration/testpackages/tmp_binary.zip
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/integration/testpackages/tmp_binary.zip?rev=1727172&r1=1727171&r2=1727172&view=diff
==============================================================================
Binary files jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/integration/testpackages/tmp_binary.zip
(original) and jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/integration/testpackages/tmp_binary.zip
Wed Jan 27 20:04:06 2016 differ



Mime
View raw message