You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by re...@apache.org on 2022/01/14 15:42:48 UTC

[jackrabbit-filevault] branch master updated: JCRVLT-594: basic tests for UUID clashes in import package (#201)

This is an automated email from the ASF dual-hosted git repository.

reschke pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jackrabbit-filevault.git


The following commit(s) were added to refs/heads/master by this push:
     new 93808b2  JCRVLT-594: basic tests for UUID clashes in import package (#201)
93808b2 is described below

commit 93808b2fbbd72778cef89f572b8b88dc9aa2a3d5
Author: Julian Reschke <re...@apache.org>
AuthorDate: Fri Jan 14 16:42:45 2022 +0100

    JCRVLT-594: basic tests for UUID clashes in import package (#201)
    
    * JCRVLT-584: basic tests for UUID clashes in import package
    
    * JCRVLT-584: remove unneeded cleanup
    
    * JCRVLT-584: special-case one test expectation for Jackrabbit
    
    * JCRVLT-584: special-case one test expectation for Jackrabbit - leverage system property
---
 .../ReferenceableIdentifiersImportIT.java          | 86 ++++++++++++++++++++
 .../META-INF/vault/config.xml                      | 93 ++++++++++++++++++++++
 .../META-INF/vault/definition/.content.xml         | 25 ++++++
 .../META-INF/vault/filter.xml                      |  4 +
 .../META-INF/vault/nodetypes.cnd                   | 17 ++++
 .../META-INF/vault/properties.xml                  | 18 +++++
 .../referenceable-dup.zip/jcr_root/.content.xml    |  6 ++
 .../jcr_root/tmp/.content.xml                      |  4 +
 .../jcr_root/tmp/duplicate.xml                     | 12 +++
 .../jcr_root/tmp/referenceable.xml                 | 12 +++
 10 files changed, 277 insertions(+)

diff --git a/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/ReferenceableIdentifiersImportIT.java b/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/ReferenceableIdentifiersImportIT.java
index c541a69..35cecff 100644
--- a/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/ReferenceableIdentifiersImportIT.java
+++ b/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/ReferenceableIdentifiersImportIT.java
@@ -21,10 +21,12 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotEquals;
 import static org.junit.Assert.assertThrows;
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
 import java.io.IOException;
 
 import javax.jcr.Node;
+import javax.jcr.PathNotFoundException;
 import javax.jcr.PropertyIterator;
 import javax.jcr.ReferentialIntegrityException;
 import javax.jcr.RepositoryException;
@@ -287,4 +289,88 @@ public class ReferenceableIdentifiersImportIT extends IntegrationTestBase {
         // try to remove referenceable node -> fails with RIE
         Assert.assertThrows(ReferentialIntegrityException.class, () -> { referenceableNode.remove();  admin.save();});
     }
+
+    // tests that import the variant referenceable-dup, which contains a
+    // duplicate node "duplicate" with the same jcr:uuid as "referenceable"
+
+    @Test
+    public void testImportDupPolicyFail() throws RepositoryException, IOException, PackageException {
+        testImportDup(IdConflictPolicy.FAIL);
+        Node referenceableNode = getNodeOrNull("/tmp/referenceable");
+        Node duplicateNode = getNodeOrNull("/tmp/duplicate");
+        if (duplicateNode == null && referenceableNode != null) {
+            assertTrue(referenceableNode.isNodeType(JcrConstants.MIX_REFERENCEABLE));
+            assertEquals(referenceableNode.getIdentifier(), UUID_REFERENCEABLE);
+        } else if (duplicateNode != null && referenceableNode == null) {
+            assertTrue(duplicateNode.isNodeType(JcrConstants.MIX_REFERENCEABLE));
+            assertEquals(duplicateNode.getIdentifier(), UUID_REFERENCEABLE);
+        } else {
+            fail("both nodes imported");
+        }
+    }
+
+    @Test
+    public void testImportDupPolicyCreateNewId() throws RepositoryException, IOException, PackageException {
+        testImportDup(IdConflictPolicy.CREATE_NEW_ID);
+        Node referenceableNode = getNodeOrNull("/tmp/referenceable");
+        Node duplicateNode = getNodeOrNull("/tmp/duplicate");
+        if (duplicateNode == null) {
+            fail("'duplicate' not imported");
+        } else if (referenceableNode == null) {
+            fail("'referencable' not imported");
+        } else {
+            assertTrue(referenceableNode.isNodeType(JcrConstants.MIX_REFERENCEABLE));
+            String refref = referenceableNode.getIdentifier();
+            assertTrue(duplicateNode.isNodeType(JcrConstants.MIX_REFERENCEABLE));
+            String dupref = duplicateNode.getIdentifier();
+            assertNotEquals("identifiers should be different", refref, dupref);
+
+            // For this test, Jackrabbit and Oak behave differently; for now, we
+            // just observe the behavior (and the test ensures, that it doesn't
+            // change without us noticing)
+            if (isOak()) {
+                assertTrue("identifiers should be new", !UUID_REFERENCEABLE.equals(refref) && !UUID_REFERENCEABLE.equals(dupref));
+            } else {
+                int newUUIDs = 0;
+                if (!UUID_REFERENCEABLE.equals(refref)) {
+                    newUUIDs += 1;
+                }
+                if (!UUID_REFERENCEABLE.equals(dupref)) {
+                    newUUIDs += 1;
+                }
+                assertEquals("for Jackrabbit classic, exactly one changed UUID was expected", 1, newUUIDs);
+            }
+        }
+    }
+
+    @Test
+    public void testImportDupPolicyForceRemove() throws RepositoryException, IOException, PackageException {
+        testImportDup(IdConflictPolicy.FORCE_REMOVE_CONFLICTING_ID);
+        Node referenceableNode = getNodeOrNull("/tmp/referenceable");
+        Node duplicateNode = getNodeOrNull("/tmp/duplicate");
+        if (duplicateNode == null && referenceableNode != null) {
+            assertTrue(referenceableNode.isNodeType(JcrConstants.MIX_REFERENCEABLE));
+            assertEquals(referenceableNode.getIdentifier(), UUID_REFERENCEABLE);
+        } else if (duplicateNode != null && referenceableNode == null) {
+            assertTrue(duplicateNode.isNodeType(JcrConstants.MIX_REFERENCEABLE));
+            assertEquals(duplicateNode.getIdentifier(), UUID_REFERENCEABLE);
+        } else {
+            fail("both nodes imported");
+        }
+    }
+
+    private Node getNodeOrNull(String path) throws RepositoryException {
+        try {
+            return admin.getNode(path);
+        } catch (PathNotFoundException ex) {
+            return null;
+        }
+    }
+
+    private void testImportDup(IdConflictPolicy policy) throws IOException, PackageException, RepositoryException {
+        ImportOptions options = getDefaultOptions();
+        options.setStrict(true);
+        options.setIdConflictPolicy(policy);
+        extractVaultPackage("/test-packages/referenceable-dup.zip", options);
+    }
 }
\ No newline at end of file
diff --git a/vault-core/src/test/resources/test-packages/referenceable-dup.zip/META-INF/vault/config.xml b/vault-core/src/test/resources/test-packages/referenceable-dup.zip/META-INF/vault/config.xml
new file mode 100644
index 0000000..b525f1c
--- /dev/null
+++ b/vault-core/src/test/resources/test-packages/referenceable-dup.zip/META-INF/vault/config.xml
@@ -0,0 +1,93 @@
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+  -->
+<vaultfs version="1.1">
+    <!--
+        Defines the content aggregation. The order of the defined aggregates
+        is important for finding the correct aggregator.
+    -->
+    <aggregates>
+        <!--
+            Defines an aggregate that handles nt:file and nt:resource nodes.
+        -->
+        <aggregate type="file" title="File Aggregate"/>
+
+        <!--
+            Defines an aggregate that handles file/folder like nodes. It matches
+            all nt:hierarchyNode nodes that have or define a jcr:content
+            child node and excludes child nodes that are nt:hierarchyNodes.
+        -->
+        <aggregate type="filefolder" title="File/Folder Aggregate"/>
+
+        <!--
+            Defines an aggregate that handles nt:nodeType nodes and serializes
+            them into .cnd notation.
+        -->
+        <aggregate type="nodetype" title="Node Type Aggregate" />
+
+        <!--
+            Defines an aggregate that defines full coverage for certain node
+            types that cannot be covered by the default aggregator.
+        -->
+        <aggregate type="full" title="Full Coverage Aggregate">
+            <matches>
+                <include nodeType="rep:AccessControl" respectSupertype="true" />
+                <include nodeType="rep:Policy" respectSupertype="true" />
+                <include nodeType="cq:Widget" respectSupertype="true" />
+                <include nodeType="cq:EditConfig" respectSupertype="true" />
+                <include nodeType="cq:WorkflowModel" respectSupertype="true" />
+                <include nodeType="vlt:FullCoverage" respectSupertype="true" />
+                <include nodeType="mix:language" respectSupertype="true" />
+                <include nodeType="sling:OsgiConfig" respectSupertype="true" />
+            </matches>
+        </aggregate>
+
+        <!--
+            Defines an aggregate that handles nt:folder like nodes.
+        -->
+        <aggregate type="generic" title="Folder Aggregate">
+            <matches>
+                <include nodeType="nt:folder" respectSupertype="true" />
+            </matches>
+            <contains>
+                <exclude isNode="true" />
+            </contains>
+        </aggregate>
+
+        <!--
+            Defines the default aggregate
+        -->
+        <aggregate type="generic" title="Default Aggregator" isDefault="true">
+            <matches>
+                <!-- all -->
+            </matches>
+            <contains>
+                <exclude nodeType="nt:hierarchyNode" respectSupertype="true" />
+            </contains>
+        </aggregate>
+
+    </aggregates>
+
+    <!--
+      defines the input handlers
+    -->
+    <handlers>
+        <handler type="folder"/>
+        <handler type="file"/>
+        <handler type="nodetype"/>
+        <handler type="generic"/>
+    </handlers>
+</vaultfs>
diff --git a/vault-core/src/test/resources/test-packages/referenceable-dup.zip/META-INF/vault/definition/.content.xml b/vault-core/src/test/resources/test-packages/referenceable-dup.zip/META-INF/vault/definition/.content.xml
new file mode 100644
index 0000000..c57b6a8
--- /dev/null
+++ b/vault-core/src/test/resources/test-packages/referenceable-dup.zip/META-INF/vault/definition/.content.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<jcr:root xmlns:vlt="http://www.day.com/jcr/vault/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
+    jcr:created="{Date}2015-12-16T16:59:10.779+01:00"
+    jcr:createdBy="admin"
+    jcr:description=""
+    jcr:lastModified="{Date}2015-12-16T16:59:10.779+01:00"
+    jcr:lastModifiedBy="admin"
+    jcr:primaryType="vlt:PackageDefinition"
+    buildCount="5"
+    builtWith="Adobe Experience Manager-6.1.0.20150507"
+    group="my_packages"
+    lastUnwrapped="{Date}2015-12-16T16:59:10.779+01:00"
+    lastUnwrappedBy="admin"
+    lastWrapped="{Date}2015-12-16T16:59:10.779+01:00"
+    lastWrappedBy="admin"
+    name="test_referenceable"
+    version="">
+    <filter jcr:primaryType="nt:unstructured">
+        <f0
+            jcr:primaryType="nt:unstructured"
+            mode="replace"
+            root="/tmp/referenceable"
+            rules="[]"/>
+    </filter>
+</jcr:root>
diff --git a/vault-core/src/test/resources/test-packages/referenceable-dup.zip/META-INF/vault/filter.xml b/vault-core/src/test/resources/test-packages/referenceable-dup.zip/META-INF/vault/filter.xml
new file mode 100644
index 0000000..1f2812b
--- /dev/null
+++ b/vault-core/src/test/resources/test-packages/referenceable-dup.zip/META-INF/vault/filter.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<workspaceFilter version="1.0">
+    <filter root="/tmp"/>
+</workspaceFilter>
diff --git a/vault-core/src/test/resources/test-packages/referenceable-dup.zip/META-INF/vault/nodetypes.cnd b/vault-core/src/test/resources/test-packages/referenceable-dup.zip/META-INF/vault/nodetypes.cnd
new file mode 100644
index 0000000..c348e28
--- /dev/null
+++ b/vault-core/src/test/resources/test-packages/referenceable-dup.zip/META-INF/vault/nodetypes.cnd
@@ -0,0 +1,17 @@
+<'vlt'='http://www.day.com/jcr/vault/1.0'>
+<'sling'='http://sling.apache.org/jcr/sling/1.0'>
+<'nt'='http://www.jcp.org/jcr/nt/1.0'>
+<'rep'='internal'>
+
+[vlt:FullCoverage]
+  mixin
+
+[sling:Folder] > nt:folder
+  - * (undefined) multiple
+  - * (undefined)
+  + * (nt:base) = sling:Folder version
+
+[rep:RepoAccessControllable]
+  mixin
+  + rep:repoPolicy (rep:Policy) protected ignore
+
diff --git a/vault-core/src/test/resources/test-packages/referenceable-dup.zip/META-INF/vault/properties.xml b/vault-core/src/test/resources/test-packages/referenceable-dup.zip/META-INF/vault/properties.xml
new file mode 100644
index 0000000..2494f50
--- /dev/null
+++ b/vault-core/src/test/resources/test-packages/referenceable-dup.zip/META-INF/vault/properties.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8" standalone="no"?>
+<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
+<properties>
+<comment>FileVault Package Properties</comment>
+<entry key="createdBy">admin</entry>
+<entry key="name">test_referenceable</entry>
+<entry key="lastModified">2015-12-16T16:59:10.779+01:00</entry>
+<entry key="lastModifiedBy">admin</entry>
+<entry key="created">2015-12-16T16:59:10.795+01:00</entry>
+<entry key="buildCount">5</entry>
+<entry key="version"/>
+<entry key="dependencies"/>
+<entry key="packageFormatVersion">2</entry>
+<entry key="description"/>
+<entry key="lastWrapped">2015-12-16T16:59:10.779+01:00</entry>
+<entry key="group">my_packages</entry>
+<entry key="lastWrappedBy">admin</entry>
+</properties>
diff --git a/vault-core/src/test/resources/test-packages/referenceable-dup.zip/jcr_root/.content.xml b/vault-core/src/test/resources/test-packages/referenceable-dup.zip/jcr_root/.content.xml
new file mode 100644
index 0000000..8ea9f2a
--- /dev/null
+++ b/vault-core/src/test/resources/test-packages/referenceable-dup.zip/jcr_root/.content.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:rep="internal"
+    jcr:mixinTypes="[rep:AccessControllable,rep:RepoAccessControllable]"
+    jcr:primaryType="rep:root"
+    sling:resourceType="sling:redirect"
+    sling:target="/index.html"/>
diff --git a/vault-core/src/test/resources/test-packages/referenceable-dup.zip/jcr_root/tmp/.content.xml b/vault-core/src/test/resources/test-packages/referenceable-dup.zip/jcr_root/tmp/.content.xml
new file mode 100644
index 0000000..54084a8
--- /dev/null
+++ b/vault-core/src/test/resources/test-packages/referenceable-dup.zip/jcr_root/tmp/.content.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:rep="internal"
+    jcr:mixinTypes="[rep:AccessControllable]"
+    jcr:primaryType="sling:Folder"/>
diff --git a/vault-core/src/test/resources/test-packages/referenceable-dup.zip/jcr_root/tmp/duplicate.xml b/vault-core/src/test/resources/test-packages/referenceable-dup.zip/jcr_root/tmp/duplicate.xml
new file mode 100644
index 0000000..2d1995c
--- /dev/null
+++ b/vault-core/src/test/resources/test-packages/referenceable-dup.zip/jcr_root/tmp/duplicate.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:vlt="http://www.day.com/jcr/vault/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:mix="http://www.jcp.org/jcr/mix/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
+    jcr:mixinTypes="[mix:referenceable,vlt:FullCoverage]"
+    jcr:primaryType="sling:Folder"
+    jcr:uuid="352c89a4-304f-4b87-9bed-e09275597df1"
+    someproperty="somevalue">
+    <child
+        jcr:mixinTypes="[mix:referenceable]"
+        jcr:primaryType="nt:unstructured"
+        jcr:uuid="a201bd6b-25b9-4255-b7db-6fc4c3ddb32d"
+        someproperty="somevalue"/>
+</jcr:root>
diff --git a/vault-core/src/test/resources/test-packages/referenceable-dup.zip/jcr_root/tmp/referenceable.xml b/vault-core/src/test/resources/test-packages/referenceable-dup.zip/jcr_root/tmp/referenceable.xml
new file mode 100644
index 0000000..2d1995c
--- /dev/null
+++ b/vault-core/src/test/resources/test-packages/referenceable-dup.zip/jcr_root/tmp/referenceable.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:vlt="http://www.day.com/jcr/vault/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:mix="http://www.jcp.org/jcr/mix/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
+    jcr:mixinTypes="[mix:referenceable,vlt:FullCoverage]"
+    jcr:primaryType="sling:Folder"
+    jcr:uuid="352c89a4-304f-4b87-9bed-e09275597df1"
+    someproperty="somevalue">
+    <child
+        jcr:mixinTypes="[mix:referenceable]"
+        jcr:primaryType="nt:unstructured"
+        jcr:uuid="a201bd6b-25b9-4255-b7db-6fc4c3ddb32d"
+        someproperty="somevalue"/>
+</jcr:root>