jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tri...@apache.org
Subject svn commit: r1766472 - in /jackrabbit/commons/filevault/trunk: parent/ vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/ vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/ vault-core/src/test/resources/org/apache...
Date Tue, 25 Oct 2016 04:49:57 GMT
Author: tripod
Date: Tue Oct 25 04:49:57 2016
New Revision: 1766472

URL: http://svn.apache.org/viewvc?rev=1766472&view=rev
Log:
JCRVLT-137 Importing packages with users that contain a rep:cache node fails

Added:
    jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/integration/testpackages/test_user_with_rep_cache.zip
Modified:
    jackrabbit/commons/filevault/trunk/parent/pom.xml
    jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/DocViewAdapter.java
    jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/DocViewSAXImporter.java
    jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/JcrSysViewTransformer.java
    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/TestGroupMergePackage.java
    jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestUserContentPackage.java

Modified: jackrabbit/commons/filevault/trunk/parent/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/parent/pom.xml?rev=1766472&r1=1766471&r2=1766472&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/parent/pom.xml (original)
+++ jackrabbit/commons/filevault/trunk/parent/pom.xml Tue Oct 25 04:49:57 2016
@@ -346,7 +346,7 @@
             <dependency>
                 <groupId>junit</groupId>
                 <artifactId>junit</artifactId>
-                <version>4.8.2</version>
+                <version>4.12</version>
                 <scope>test</scope>
             </dependency>
         </dependencies>

Modified: jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/DocViewAdapter.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/DocViewAdapter.java?rev=1766472&r1=1766471&r2=1766472&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/DocViewAdapter.java
(original)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/DocViewAdapter.java
Tue Oct 25 04:49:57 2016
@@ -33,19 +33,19 @@ public interface DocViewAdapter {
      * @param node the node
      * @throws SAXException if an error occurrs
      */
-    public void startNode(DocViewNode node) throws SAXException;
+    void startNode(DocViewNode node) throws SAXException;
 
     /**
      * Ends node is invoked when the importer ascends from an element.
      * @throws SAXException if an error occurrs.
      */
-    public void endNode() throws SAXException;
+    void endNode() throws SAXException;
 
     /**
      * Is called by the importer if the adapter is no longer used and must finalize the import.
      * @throws SAXException if an error occurrs.
      * @return The paths that were created.
      */
-    public List<String> close() throws SAXException;
+    List<String> close() throws SAXException;
 
 }
\ No newline at end of file

Modified: jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/DocViewSAXImporter.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/DocViewSAXImporter.java?rev=1766472&r1=1766471&r2=1766472&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/DocViewSAXImporter.java
(original)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/DocViewSAXImporter.java
Tue Oct 25 04:49:57 2016
@@ -658,8 +658,8 @@ public class DocViewSAXImporter extends
      * Handle an authorizable node
      * @param node the parent node
      * @param ni doc view node of the authorizable
-     * @throws RepositoryException
-     * @throws SAXException
+     * @throws RepositoryException if an error accessing the repository occurrs.
+     * @throws SAXException if an XML parsing error occurrs.
      */
     private void handleAuthorizable(Node node, DocViewNode ni) throws RepositoryException,
SAXException {
         String id = userManagement.getAuthorizableId(ni);

Modified: jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/JcrSysViewTransformer.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/JcrSysViewTransformer.java?rev=1766472&r1=1766471&r2=1766472&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/JcrSysViewTransformer.java
(original)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/JcrSysViewTransformer.java
Tue Oct 25 04:49:57 2016
@@ -17,7 +17,10 @@
 package org.apache.jackrabbit.vault.fs.impl.io;
 
 import java.util.ArrayList;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
+import java.util.Stack;
 
 import javax.jcr.ImportUUIDBehavior;
 import javax.jcr.Node;
@@ -64,6 +67,10 @@ public class JcrSysViewTransformer imple
 
     private final String existingPath;
 
+    private final Set<String> excludedNodeNames = new HashSet<String>();
+
+    private long ignoreLevel = 0;
+
     public JcrSysViewTransformer(Node node) throws SAXException, RepositoryException {
         this(node, null);
     }
@@ -90,6 +97,7 @@ public class JcrSysViewTransformer imple
             recovery = new ChildNodeStash(session).excludeName("rep:cache");
             recovery.stashChildren(existingPath);
         }
+        excludeNode("rep:cache");
     }
 
     public List<String> close() throws SAXException {
@@ -130,6 +138,17 @@ public class JcrSysViewTransformer imple
     }
 
     public void startNode(DocViewNode ni) throws SAXException {
+        if (ignoreLevel > 0) {
+            DocViewSAXImporter.log.debug("ignoring child node of excluded node: {}", ni.name);
+            ignoreLevel++;
+            return;
+        }
+        if (excludedNodeNames.contains(ni.name)) {
+            DocViewSAXImporter.log.debug("Ignoring excluded node {}", ni.name);
+            ignoreLevel = 1;
+            return;
+        }
+
         DocViewSAXImporter.log.debug("Transforming element to sysview {}", ni.name);
 
         AttributesImpl attrs = new AttributesImpl();
@@ -163,6 +182,15 @@ public class JcrSysViewTransformer imple
     }
 
     public void endNode() throws SAXException {
+        if (ignoreLevel > 0) {
+            ignoreLevel--;
+            return;
+        }
         handler.endElement(Name.NS_SV_URI, "node", "sv:node");
     }
+
+    public JcrSysViewTransformer excludeNode(String name) {
+        excludedNodeNames.add(name);
+        return this;
+    }
 }
\ No newline at end of file

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=1766472&r1=1766471&r2=1766472&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
Tue Oct 25 04:49:57 2016
@@ -25,6 +25,7 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.Iterator;
 import java.util.Map;
 import java.util.Properties;
 import java.util.Set;
@@ -43,8 +44,11 @@ import javax.jcr.security.Privilege;
 
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.IOUtils;
+import org.apache.jackrabbit.api.JackrabbitSession;
 import org.apache.jackrabbit.api.security.JackrabbitAccessControlEntry;
 import org.apache.jackrabbit.api.security.JackrabbitAccessControlList;
+import org.apache.jackrabbit.api.security.user.Authorizable;
+import org.apache.jackrabbit.api.security.user.UserManager;
 import org.apache.jackrabbit.commons.jackrabbit.authorization.AccessControlUtils;
 import org.apache.jackrabbit.core.RepositoryImpl;
 import org.apache.jackrabbit.core.config.RepositoryConfig;
@@ -76,6 +80,7 @@ import org.junit.After;
 import org.junit.AfterClass;
 import org.junit.Before;
 import org.junit.BeforeClass;
+import org.junit.ClassRule;
 import org.junit.Rule;
 import org.junit.rules.TemporaryFolder;
 import org.slf4j.Logger;
@@ -103,7 +108,7 @@ public class IntegrationTestBase  {
     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
+    @ClassRule
     public static TemporaryFolder tempFolder = new TemporaryFolder();
 
     private static FileStore fileStore = null;
@@ -114,6 +119,8 @@ public class IntegrationTestBase  {
 
     protected JcrPackageManager packMgr;
 
+    protected Set<String> preTestAuthorizables;
+
     @BeforeClass
     public static void initRepository() throws RepositoryException, IOException, InvalidFileStoreVersionException
{
         if (isOak()) {
@@ -204,6 +211,27 @@ public class IntegrationTestBase  {
         clean("/testroot");
 
         packMgr = new JcrPackageManagerImpl(admin);
+
+        preTestAuthorizables = getAllAuthorizableIds();
+    }
+
+    @After
+    public void tearDown() throws Exception {
+        // remove test authorizables
+        admin.refresh(false);
+        UserManager mgr = ((JackrabbitSession) admin).getUserManager();
+        for (String id: getAllAuthorizableIds()) {
+            if (!preTestAuthorizables.remove(id)) {
+                removeAuthorizable(mgr, id);
+            }
+        }
+        admin.save();
+
+        packMgr = null;
+        if (admin != null) {
+            admin.logout();
+            admin = null;
+        }
     }
 
     public static boolean isOak() {
@@ -218,12 +246,20 @@ public class IntegrationTestBase  {
             // ignore
         }
     }
-    @After
-    public void tearDown() throws Exception {
-        packMgr = null;
-        if (admin != null) {
-            admin.logout();
-            admin = null;
+    public final Set<String> getAllAuthorizableIds() throws RepositoryException {
+        Set<String> ret = new HashSet<String>();
+        UserManager mgr = ((JackrabbitSession) admin).getUserManager();
+        Iterator<Authorizable> auths = mgr.findAuthorizables("rep:principalName", null);
+        while (auths.hasNext()) {
+            ret.add(auths.next().getID());
+        }
+        return ret;
+    }
+
+    public final void removeAuthorizable(UserManager mgr, String name) throws RepositoryException
{
+        Authorizable a = mgr.getAuthorizable(name);
+        if (a != null) {
+            a.remove();
         }
     }
 

Modified: jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestGroupMergePackage.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestGroupMergePackage.java?rev=1766472&r1=1766471&r2=1766472&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestGroupMergePackage.java
(original)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestGroupMergePackage.java
Tue Oct 25 04:49:57 2016
@@ -22,7 +22,6 @@ import java.io.IOException;
 import javax.jcr.RepositoryException;
 
 import org.apache.jackrabbit.api.JackrabbitSession;
-import org.apache.jackrabbit.api.security.user.Authorizable;
 import org.apache.jackrabbit.api.security.user.Group;
 import org.apache.jackrabbit.api.security.user.User;
 import org.apache.jackrabbit.api.security.user.UserManager;
@@ -56,13 +55,6 @@ public class TestGroupMergePackage exten
         super.tearDown();
     }
 
-    private void removeAuthorizable(UserManager mgr, String name) throws RepositoryException
{
-        Authorizable a = mgr.getAuthorizable(name);
-        if (a != null) {
-            a.remove();
-        }
-    }
-
     /**
      * Installs a package that contains a "test-group" and a "test-user-a" as member of the
group.
      */

Modified: jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestUserContentPackage.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestUserContentPackage.java?rev=1766472&r1=1766471&r2=1766472&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestUserContentPackage.java
(original)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestUserContentPackage.java
Tue Oct 25 04:49:57 2016
@@ -19,10 +19,7 @@ package org.apache.jackrabbit.vault.pack
 
 import java.io.File;
 import java.io.IOException;
-import java.util.HashSet;
-import java.util.Iterator;
 import java.util.Properties;
-import java.util.Set;
 
 import javax.jcr.Node;
 import javax.jcr.Property;
@@ -48,7 +45,6 @@ import org.apache.jackrabbit.vault.packa
 import org.apache.jackrabbit.vault.packaging.VaultPackage;
 import org.apache.jackrabbit.vault.util.Text;
 import org.junit.Assume;
-import org.junit.Ignore;
 import org.junit.Test;
 
 import static org.junit.Assert.assertEquals;
@@ -73,45 +69,6 @@ public class TestUserContentPackage exte
     private static final String NAME_PROFILE_PICTURE_NODE = "profile/picture.txt";
     private static final String NAME_PROFILE_PRIVATE_NODE = "profile_private";
 
-    private Set<String> preTestAuhorizables;
-
-    @Override
-    public void setUp() throws Exception {
-        super.setUp();
-        preTestAuhorizables = getAllAuthorizableIds();
-    }
-
-    private Set<String> getAllAuthorizableIds() throws RepositoryException {
-        Set<String> ret = new HashSet<String>();
-        UserManager mgr = ((JackrabbitSession) admin).getUserManager();
-        Iterator<Authorizable> auths = mgr.findAuthorizables("rep:principalName", null);
-        while (auths.hasNext()) {
-            ret.add(auths.next().getID());
-        }
-        return ret;
-    }
-
-    @Override
-    public void tearDown() throws Exception {
-        // remove test authorizables
-        admin.refresh(false);
-        UserManager mgr = ((JackrabbitSession) admin).getUserManager();
-        for (String id: getAllAuthorizableIds()) {
-            if (!preTestAuhorizables.remove(id)) {
-                removeAuthorizable(mgr, id);
-            }
-        }
-        admin.save();
-        super.tearDown();
-    }
-
-    private void removeAuthorizable(UserManager mgr, String name) throws RepositoryException
{
-        Authorizable a = mgr.getAuthorizable(name);
-        if (a != null) {
-            a.remove();
-        }
-    }
-
     @Test
     public void installUserA() throws RepositoryException, IOException, PackageException
{
         installUserA(null, false, true);
@@ -391,6 +348,52 @@ public class TestUserContentPackage exte
         install_moved_user_with_rep_cache(ImportMode.MERGE);
     }
 
+    /**
+     * Tests if installing a package using {@link ImportMode#UPDATE} with a package that
contains a rep:cache node
+     * and another childnode works (JCRVLT-137).
+     */
+    @Test
+    public void install_user_with_rep_cache_update() throws RepositoryException, IOException,
PackageException {
+        Assume.assumeTrue(isOak());
+        install_user_with_rep_cache(ImportMode.UPDATE);
+    }
+
+    /**
+     * Tests if installing a package using {@link ImportMode#REPLACE} with a package that
contains a rep:cache node
+     * and another childnode works (JCRVLT-137).
+     */
+    @Test
+    public void install_user_with_rep_cache_replace() throws RepositoryException, IOException,
PackageException {
+        Assume.assumeTrue(isOak());
+        install_user_with_rep_cache(ImportMode.REPLACE);
+    }
+
+    /**
+     * Tests if installing a package using {@link ImportMode#MERGE} with a package that contains
a rep:cache node
+     * and another childnode works (JCRVLT-137).
+     */
+    @Test
+    public void install_user_with_rep_cache_merge() throws RepositoryException, IOException,
PackageException {
+        Assume.assumeTrue(isOak());
+        install_user_with_rep_cache(ImportMode.MERGE);
+    }
+
+    private void install_user_with_rep_cache(ImportMode mode) throws RepositoryException,
IOException, PackageException {
+        UserManager mgr = ((JackrabbitSession) admin).getUserManager();
+        assertNull("test-user-a must not exist", mgr.getAuthorizable(ID_TEST_USER_A));
+
+        // install user package
+        JcrPackage pack = packMgr.upload(getStream("testpackages/test_user_with_rep_cache.zip"),
false);
+        assertNotNull(pack);
+        ImportOptions opts = getDefaultOptions();
+        opts.setImportMode(mode);
+        pack.install(opts);
+
+        // check if user exists
+        User userA = (User) mgr.getAuthorizable(ID_TEST_USER_A);
+        assertNotNull("test-user-a must exist", userA);
+    }
+
     private void install_moved_user_with_rep_cache(ImportMode mode) throws RepositoryException,
IOException, PackageException {
         UserManager mgr = ((JackrabbitSession) admin).getUserManager();
         User u = mgr.createUser(ID_TEST_USER_A, ID_TEST_PASSWORD);

Added: jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/integration/testpackages/test_user_with_rep_cache.zip
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/integration/testpackages/test_user_with_rep_cache.zip?rev=1766472&view=auto
==============================================================================
Binary files jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/integration/testpackages/test_user_with_rep_cache.zip
(added) and jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/integration/testpackages/test_user_with_rep_cache.zip
Tue Oct 25 04:49:57 2016 differ



Mime
View raw message