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 2023/02/14 16:01:11 UTC

[jackrabbit-filevault] branch master updated: JCRVLT-684: test coverage and fix for bug in mixin restoration (#273)

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 44ba2407 JCRVLT-684: test coverage and fix for bug in mixin restoration (#273)
44ba2407 is described below

commit 44ba240756901c4abde51fbb938c2011525507a5
Author: Julian Reschke <ju...@gmx.de>
AuthorDate: Tue Feb 14 17:01:04 2023 +0100

    JCRVLT-684: test coverage and fix for bug in mixin restoration (#273)
    
    * JCRVLT-684: test coverage and fix for bug in mixin restoration
    
    * fix mixin type decl
    
    * restrict test to Oak
    
    * JCRVLT-684: remove unneeded files
    
    * JCRVLT-684: restructure test packages
    
    * JCRVLT-684: mimimal metadata fix
    
    * improve documentation
---
 .../jackrabbit/vault/fs/impl/io/NodeStash.java     |  2 +-
 .../packaging/integration/NodeStashingIT.java      | 74 ++++++++++++++++++++++
 .../stashing/create.zip/META-INF/vault/filter.xml  |  3 +
 .../create.zip/META-INF/vault/nodetypes.cnd        |  7 ++
 .../create.zip/META-INF/vault/properties.xml       | 18 ++++++
 .../stashing/create.zip/jcr_root/.content.xml      |  4 ++
 .../stashing/create.zip/jcr_root/tmp/.content.xml  | 13 ++++
 .../stashing/update.zip/META-INF/vault/filter.xml  |  3 +
 .../update.zip/META-INF/vault/nodetypes.cnd        |  7 ++
 .../update.zip/META-INF/vault/properties.xml       | 18 ++++++
 .../stashing/update.zip/jcr_root/.content.xml      |  4 ++
 .../stashing/update.zip/jcr_root/tmp/.content.xml  | 12 ++++
 12 files changed, 164 insertions(+), 1 deletion(-)

diff --git a/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/NodeStash.java b/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/NodeStash.java
index 2028c9b0..f0b265fd 100644
--- a/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/NodeStash.java
+++ b/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/NodeStash.java
@@ -212,7 +212,7 @@ public class NodeStash {
         Property mixinProperty = tmpNode.hasProperty(JcrConstants.JCR_MIXINTYPES + PROTECTED_PROPERTIES_SUFFIX) ? tmpNode.getProperty(JcrConstants.JCR_MIXINTYPES + PROTECTED_PROPERTIES_SUFFIX) : null;
         if (mixinProperty != null) {
             for (Value value : mixinProperty.getValues()) {
-                tmpNode.addMixin(value.getString());
+                destNode.addMixin(value.getString());
             }
         }
         PropertyIterator propIterator = tmpNode.getProperties();
diff --git a/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/NodeStashingIT.java b/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/NodeStashingIT.java
new file mode 100644
index 00000000..b5ce2dd5
--- /dev/null
+++ b/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/NodeStashingIT.java
@@ -0,0 +1,74 @@
+/*
+ * 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.
+ */
+
+package org.apache.jackrabbit.vault.packaging.integration;
+
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assume.assumeTrue;
+
+import java.io.IOException;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+
+import org.apache.jackrabbit.vault.fs.api.ImportMode;
+import org.apache.jackrabbit.vault.fs.io.ImportOptions;
+import org.apache.jackrabbit.vault.packaging.PackageException;
+import org.junit.Test;
+
+public class NodeStashingIT extends IntegrationTestBase {
+
+    private static final String TESTNS = "https://issues.apache.org/jira/browse/JCRVLT-684";
+
+    @Test
+    public void testStashMixinMandatoryChildNode() throws RepositoryException, IOException, PackageException {
+
+        assumeTrue(isOak()); // see JCRVLT-687
+
+        ImportOptions options = getDefaultOptions();
+        options.setImportMode(ImportMode.MERGE_PROPERTIES);
+
+        // import test structure from package
+        extractVaultPackage("/test-packages/stashing/create.zip", options);
+
+        assertNodeExists("/tmp/stash");
+        assertNodeExists("/tmp/stash/{" + TESTNS + "}mandatoryChildNode");
+
+        Node node1 = admin.getNode("/tmp/stash");
+        String id1 = node1.getIdentifier();
+        assertTrue(node1.isNodeType("{" + TESTNS + "}noChildNodes"));
+        assertTrue(node1.isNodeType("{" + TESTNS + "}hasMandatoryChildNode"));
+
+        // update same path but without mixin allowing child nodes and different
+        // UUID so that node stashing kicks in
+        extractVaultPackage("/test-packages/stashing/update.zip", options);
+
+        // child node should be retained
+        assertNodeExists("/tmp/stash");
+        assertNodeExists("/tmp/stash/{" + TESTNS + "}mandatoryChildNode");
+
+        Node node2 = admin.getNode("/tmp/stash");
+        String id2 = node2.getIdentifier();
+
+        // make sure it's really the new node
+        assertNotEquals("imported node should have different identifier", id1, id2);
+
+        // make sure mixin type was restored
+        assertTrue(node2.isNodeType("{" + TESTNS + "}hasMandatoryChildNode"));
+    }
+}
\ No newline at end of file
diff --git a/vault-core/src/test/resources/test-packages/stashing/create.zip/META-INF/vault/filter.xml b/vault-core/src/test/resources/test-packages/stashing/create.zip/META-INF/vault/filter.xml
new file mode 100644
index 00000000..922561df
--- /dev/null
+++ b/vault-core/src/test/resources/test-packages/stashing/create.zip/META-INF/vault/filter.xml
@@ -0,0 +1,3 @@
+<workspaceFilter version="1.0">
+    <filter root="/tmp/stash"/>
+</workspaceFilter>
diff --git a/vault-core/src/test/resources/test-packages/stashing/create.zip/META-INF/vault/nodetypes.cnd b/vault-core/src/test/resources/test-packages/stashing/create.zip/META-INF/vault/nodetypes.cnd
new file mode 100644
index 00000000..fef66ef3
--- /dev/null
+++ b/vault-core/src/test/resources/test-packages/stashing/create.zip/META-INF/vault/nodetypes.cnd
@@ -0,0 +1,7 @@
+<'teststash'='https://issues.apache.org/jira/browse/JCRVLT-684'>
+
+[teststash:noChildNodes]
+
+[teststash:hasMandatoryChildNode]
+  mixin
+  + teststash:mandatoryChildNode mandatory
diff --git a/vault-core/src/test/resources/test-packages/stashing/create.zip/META-INF/vault/properties.xml b/vault-core/src/test/resources/test-packages/stashing/create.zip/META-INF/vault/properties.xml
new file mode 100644
index 00000000..a3215d04
--- /dev/null
+++ b/vault-core/src/test/resources/test-packages/stashing/create.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_stashing_create</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/stashing/create.zip/jcr_root/.content.xml b/vault-core/src/test/resources/test-packages/stashing/create.zip/jcr_root/.content.xml
new file mode 100644
index 00000000..4f8ba9aa
--- /dev/null
+++ b/vault-core/src/test/resources/test-packages/stashing/create.zip/jcr_root/.content.xml
@@ -0,0 +1,4 @@
+<jcr:root
+  xmlns:jcr="http://www.jcp.org/jcr/1.0"
+  xmlns:rep="internal"
+  jcr:primaryType="rep:root"/>
diff --git a/vault-core/src/test/resources/test-packages/stashing/create.zip/jcr_root/tmp/.content.xml b/vault-core/src/test/resources/test-packages/stashing/create.zip/jcr_root/tmp/.content.xml
new file mode 100644
index 00000000..e4a57936
--- /dev/null
+++ b/vault-core/src/test/resources/test-packages/stashing/create.zip/jcr_root/tmp/.content.xml
@@ -0,0 +1,13 @@
+<jcr:root
+  xmlns:jcr="http://www.jcp.org/jcr/1.0"
+  xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
+  xmlns:mix="http://www.jcp.org/jcr/mix/1.0"
+  xmlns:teststash="https://issues.apache.org/jira/browse/JCRVLT-684"
+  jcr:primaryType="nt:unstructured">
+  <stash
+    jcr:primaryType="teststash:noChildNodes"
+    jcr:mixinTypes="[mix:referenceable,teststash:hasMandatoryChildNode]"
+    jcr:uuid="c842f252-ab9c-11ed-9e53-00155d01040e">
+    <teststash:mandatoryChildNode jcr:primaryType="nt:unstructured"/>
+  </stash>
+</jcr:root>
diff --git a/vault-core/src/test/resources/test-packages/stashing/update.zip/META-INF/vault/filter.xml b/vault-core/src/test/resources/test-packages/stashing/update.zip/META-INF/vault/filter.xml
new file mode 100644
index 00000000..922561df
--- /dev/null
+++ b/vault-core/src/test/resources/test-packages/stashing/update.zip/META-INF/vault/filter.xml
@@ -0,0 +1,3 @@
+<workspaceFilter version="1.0">
+    <filter root="/tmp/stash"/>
+</workspaceFilter>
diff --git a/vault-core/src/test/resources/test-packages/stashing/update.zip/META-INF/vault/nodetypes.cnd b/vault-core/src/test/resources/test-packages/stashing/update.zip/META-INF/vault/nodetypes.cnd
new file mode 100644
index 00000000..fef66ef3
--- /dev/null
+++ b/vault-core/src/test/resources/test-packages/stashing/update.zip/META-INF/vault/nodetypes.cnd
@@ -0,0 +1,7 @@
+<'teststash'='https://issues.apache.org/jira/browse/JCRVLT-684'>
+
+[teststash:noChildNodes]
+
+[teststash:hasMandatoryChildNode]
+  mixin
+  + teststash:mandatoryChildNode mandatory
diff --git a/vault-core/src/test/resources/test-packages/stashing/update.zip/META-INF/vault/properties.xml b/vault-core/src/test/resources/test-packages/stashing/update.zip/META-INF/vault/properties.xml
new file mode 100644
index 00000000..8373968d
--- /dev/null
+++ b/vault-core/src/test/resources/test-packages/stashing/update.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_stashing_update</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/stashing/update.zip/jcr_root/.content.xml b/vault-core/src/test/resources/test-packages/stashing/update.zip/jcr_root/.content.xml
new file mode 100644
index 00000000..4f8ba9aa
--- /dev/null
+++ b/vault-core/src/test/resources/test-packages/stashing/update.zip/jcr_root/.content.xml
@@ -0,0 +1,4 @@
+<jcr:root
+  xmlns:jcr="http://www.jcp.org/jcr/1.0"
+  xmlns:rep="internal"
+  jcr:primaryType="rep:root"/>
diff --git a/vault-core/src/test/resources/test-packages/stashing/update.zip/jcr_root/tmp/.content.xml b/vault-core/src/test/resources/test-packages/stashing/update.zip/jcr_root/tmp/.content.xml
new file mode 100644
index 00000000..43b205e9
--- /dev/null
+++ b/vault-core/src/test/resources/test-packages/stashing/update.zip/jcr_root/tmp/.content.xml
@@ -0,0 +1,12 @@
+<jcr:root
+  xmlns:jcr="http://www.jcp.org/jcr/1.0"
+  xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
+  xmlns:mix="http://www.jcp.org/jcr/mix/1.0"
+  xmlns:teststash="https://issues.apache.org/jira/browse/JCRVLT-684"
+  jcr:primaryType="nt:unstructured">
+  <stash
+    jcr:primaryType="teststash:noChildNodes"
+    jcr:mixinTypes="[mix:referenceable]"
+    jcr:uuid="c842f252-ab9c-11ed-9e53-00155d01040f">
+  </stash>
+</jcr:root>