You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by kw...@apache.org on 2022/04/05 10:00:36 UTC

[jackrabbit-filevault] branch master updated: add more ITs for DocViewSaxFormatter (order nodes and sorted mixins)

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

kwin 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 edb5eaf7 add more ITs for DocViewSaxFormatter (order nodes and sorted mixins)
edb5eaf7 is described below

commit edb5eaf770c7b3f9c67677724417540bcc5e381d
Author: Konrad Windszus <kw...@apache.org>
AuthorDate: Tue Apr 5 12:00:32 2022 +0200

    add more ITs for DocViewSaxFormatter (order nodes and sorted mixins)
---
 .../vault/fs/impl/io/DocViewSaxFormatterIT.java    | 127 ++++++++++++---------
 1 file changed, 75 insertions(+), 52 deletions(-)

diff --git a/vault-core/src/test/java/org/apache/jackrabbit/vault/fs/impl/io/DocViewSaxFormatterIT.java b/vault-core/src/test/java/org/apache/jackrabbit/vault/fs/impl/io/DocViewSaxFormatterIT.java
index 09da9d64..39b195d3 100644
--- a/vault-core/src/test/java/org/apache/jackrabbit/vault/fs/impl/io/DocViewSaxFormatterIT.java
+++ b/vault-core/src/test/java/org/apache/jackrabbit/vault/fs/impl/io/DocViewSaxFormatterIT.java
@@ -24,14 +24,20 @@ import java.util.HashMap;
 import java.util.Map;
 
 import javax.jcr.GuestCredentials;
+import javax.jcr.ItemExistsException;
 import javax.jcr.Node;
+import javax.jcr.PathNotFoundException;
 import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 import javax.jcr.Value;
+import javax.jcr.lock.LockException;
+import javax.jcr.nodetype.ConstraintViolationException;
+import javax.jcr.nodetype.NoSuchNodeTypeException;
 import javax.jcr.nodetype.NodeType;
 import javax.jcr.security.AccessControlManager;
 import javax.jcr.security.Privilege;
+import javax.jcr.version.VersionException;
 
 import org.apache.jackrabbit.api.security.JackrabbitAccessControlList;
 import org.apache.jackrabbit.commons.JcrUtils;
@@ -44,6 +50,7 @@ import org.apache.jackrabbit.vault.fs.api.RepositoryAddress;
 import org.apache.jackrabbit.vault.fs.api.VaultFileSystem;
 import org.apache.jackrabbit.vault.fs.config.DefaultWorkspaceFilter;
 import org.apache.jackrabbit.vault.packaging.integration.IntegrationTestBase;
+import org.apache.jackrabbit.vault.util.JcrConstants;
 import org.junit.Assume;
 import org.junit.Test;
 
@@ -51,6 +58,23 @@ import static org.junit.Assert.assertEquals;
 
 public class DocViewSaxFormatterIT extends IntegrationTestBase {
 
+    static String getSerializedAggregate(Session session, String rootNodePath) throws URISyntaxException, RepositoryException, IOException {
+        return getSerializedAggregate(session, rootNodePath, rootNodePath.substring(1));
+    }
+
+    static String getSerializedAggregate(Session session, String filterRootNodePath, String relAggregatePath) throws URISyntaxException, RepositoryException, IOException {
+        DefaultWorkspaceFilter filter = new DefaultWorkspaceFilter();
+        filter.add(new PathFilterSet(filterRootNodePath));
+        RepositoryAddress addr = new RepositoryAddress("/" + session.getWorkspace().getName() + "/");
+        VaultFileSystem jcrfs = Mounter.mount(null, filter, addr, null, session);
+        Aggregate a = jcrfs.getAggregateManager().getRoot().getAggregate(relAggregatePath); //strip leading "/"
+        DocViewSerializer s = new DocViewSerializer(a);
+
+        try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
+            s.writeContent(out);
+            return out.toString("utf-8");
+        }
+    }
 
     /**
      * Tests if an 'empty' node serialization includes the jcr namespace. see JCRVLT-266
@@ -78,20 +102,11 @@ public class DocViewSaxFormatterIT extends IntegrationTestBase {
         admin.save();
 
         Session guest = repository.login(new GuestCredentials());
-
-        DefaultWorkspaceFilter filter = new DefaultWorkspaceFilter();
-        filter.add(new PathFilterSet("/testroot"));
-        RepositoryAddress addr = new RepositoryAddress("/" + admin.getWorkspace().getName() + "/");
-        VaultFileSystem jcrfs = Mounter.mount(null, filter, addr, null, guest);
-        Aggregate a = jcrfs.getAggregateManager().getRoot().getAggregate("testroot");
-        DocViewSerializer s = new DocViewSerializer(a);
-
-        ByteArrayOutputStream out = new ByteArrayOutputStream();
-        s.writeContent(out);
+        String serialization = getSerializedAggregate(guest, "/testroot");
 
         assertEquals("valid xml",
                 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
-                "<jcr:root xmlns:jcr=\"http://www.jcp.org/jcr/1.0\"/>\n", out.toString("utf-8"));
+                "<jcr:root xmlns:jcr=\"http://www.jcp.org/jcr/1.0\"/>\n", serialization);
     }
 
     /**
@@ -102,20 +117,12 @@ public class DocViewSaxFormatterIT extends IntegrationTestBase {
         JcrUtils.getOrCreateByPath("/testroot", NodeType.NT_UNSTRUCTURED, admin);
         admin.save();
 
-        DefaultWorkspaceFilter filter = new DefaultWorkspaceFilter();
-        filter.add(new PathFilterSet("/testroot"));
-        RepositoryAddress addr = new RepositoryAddress("/" + admin.getWorkspace().getName() + "/");
-        VaultFileSystem jcrfs = Mounter.mount(null, filter, addr, null, admin);
-        Aggregate a = jcrfs.getAggregateManager().getRoot().getAggregate("testroot");
-        DocViewSerializer s = new DocViewSerializer(a);
-
-        ByteArrayOutputStream out = new ByteArrayOutputStream();
-        s.writeContent(out);
+        String serialization = getSerializedAggregate(admin, "/testroot");
 
         assertEquals("valid xml",
                 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
                 "<jcr:root xmlns:jcr=\"http://www.jcp.org/jcr/1.0\" xmlns:nt=\"http://www.jcp.org/jcr/nt/1.0\"\n" +
-                "    jcr:primaryType=\"nt:unstructured\"/>\n", out.toString("utf-8"));
+                "    jcr:primaryType=\"nt:unstructured\"/>\n", serialization);
     }
 
     /**
@@ -128,42 +135,26 @@ public class DocViewSaxFormatterIT extends IntegrationTestBase {
         node.setProperty("TestProperty", "MixedCase");
         admin.save();
 
-        DefaultWorkspaceFilter filter = new DefaultWorkspaceFilter();
-        filter.add(new PathFilterSet("/testroot"));
-        RepositoryAddress addr = new RepositoryAddress("/" + admin.getWorkspace().getName() + "/");
-        VaultFileSystem jcrfs = Mounter.mount(null, filter, addr, null, admin);
-        Aggregate a = jcrfs.getAggregateManager().getRoot().getAggregate("testroot");
-        DocViewSerializer s = new DocViewSerializer(a);
-
-        ByteArrayOutputStream out = new ByteArrayOutputStream();
-        s.writeContent(out);
+        String serialization = getSerializedAggregate(admin, "/testroot");
 
         assertEquals("valid xml",
                 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
                 "<jcr:root xmlns:jcr=\"http://www.jcp.org/jcr/1.0\" xmlns:nt=\"http://www.jcp.org/jcr/nt/1.0\"\n" +
                 "    jcr:primaryType=\"nt:unstructured\"\n" +
                 "    TestProperty=\"MixedCase\"\n" +
-                "    testproperty=\"lowercase\"/>\n", out.toString("utf-8"));
+                "    testproperty=\"lowercase\"/>\n", serialization);
     }
 
     @Test
     public void testSnsNodeNames() throws RepositoryException, URISyntaxException, IOException {
-        Assume.assumeFalse(isOak()); // same-name siblings are only supported by Jackrabbit2
+        Assume.assumeFalse(isOak()); // same-name siblings are only supported in Jackrabbit2
         Node node = JcrUtils.getOrCreateByPath("/testroot", NodeType.NT_UNSTRUCTURED, admin);
         node.addNode("childnode",  NodeType.NT_UNSTRUCTURED);
         node.addNode("childnode",  NodeType.NT_UNSTRUCTURED);
         node.addNode("childnode",  NodeType.NT_UNSTRUCTURED);
         admin.save();
 
-        DefaultWorkspaceFilter filter = new DefaultWorkspaceFilter();
-        filter.add(new PathFilterSet("/testroot"));
-        RepositoryAddress addr = new RepositoryAddress("/" + admin.getWorkspace().getName() + "/");
-        VaultFileSystem jcrfs = Mounter.mount(null, filter, addr, null, admin);
-        Aggregate a = jcrfs.getAggregateManager().getRoot().getAggregate("testroot");
-        DocViewSerializer s = new DocViewSerializer(a);
-
-        ByteArrayOutputStream out = new ByteArrayOutputStream();
-        s.writeContent(out);
+        String serialization = getSerializedAggregate(admin, "/testroot");
 
         assertEquals("valid xml",
                 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
@@ -172,7 +163,7 @@ public class DocViewSaxFormatterIT extends IntegrationTestBase {
                 "    <childnode jcr:primaryType=\"nt:unstructured\"/>\n" +
                 "    <childnode_x005b_2_x005d_ jcr:primaryType=\"nt:unstructured\"/>\n" +
                 "    <childnode_x005b_3_x005d_ jcr:primaryType=\"nt:unstructured\"/>\n" +
-                "</jcr:root>\n", out.toString("utf-8"));
+                "</jcr:root>\n", serialization);
     }
 
     @Test
@@ -183,15 +174,7 @@ public class DocViewSaxFormatterIT extends IntegrationTestBase {
         childNode.setProperty("_test&test", "test");
         admin.save();
 
-        DefaultWorkspaceFilter filter = new DefaultWorkspaceFilter();
-        filter.add(new PathFilterSet("/testroot"));
-        RepositoryAddress addr = new RepositoryAddress("/" + admin.getWorkspace().getName() + "/");
-        VaultFileSystem jcrfs = Mounter.mount(null, filter, addr, null, admin);
-        Aggregate a = jcrfs.getAggregateManager().getRoot().getAggregate("testroot");
-        DocViewSerializer s = new DocViewSerializer(a);
-
-        ByteArrayOutputStream out = new ByteArrayOutputStream();
-        s.writeContent(out);
+        String serialization = getSerializedAggregate(admin, "/testroot");
 
         assertEquals("valid xml",
                 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
@@ -201,6 +184,46 @@ public class DocViewSaxFormatterIT extends IntegrationTestBase {
                 "    <test_x0025_test\n" +
                 "        jcr:primaryType=\"nt:unstructured\"\n" +
                 "        _test_x0026_test=\"test\"/>\n" +
-                "</jcr:root>\n", out.toString("utf-8"));
+                "</jcr:root>\n", serialization);
+    }
+
+    @Test
+    public void testEmptyOrderNodes() throws ItemExistsException, PathNotFoundException, NoSuchNodeTypeException, LockException, VersionException, ConstraintViolationException, RepositoryException, URISyntaxException, IOException {
+        // orderable child nodes
+        Node node = JcrUtils.getOrCreateByPath("/testroot", NodeType.NT_UNSTRUCTURED, admin);
+        node.addNode("child1", NodeType.NT_UNSTRUCTURED);
+        node.addNode("child2", NodeType.NT_UNSTRUCTURED);
+        node.addNode("child3", NodeType.NT_UNSTRUCTURED);
+        admin.save();
+
+        String serialization = getSerializedAggregate(admin, "/testroot/child2", "testroot");
+
+        assertEquals("valid xml",
+                "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
+                "<jcr:root xmlns:jcr=\"http://www.jcp.org/jcr/1.0\" xmlns:nt=\"http://www.jcp.org/jcr/nt/1.0\"\n" +
+                "    jcr:primaryType=\"nt:unstructured\">\n" +
+                "    <child1/>\n" +
+                "    <child2 jcr:primaryType=\"nt:unstructured\"/>\n" +
+                "    <child3/>\n" +
+                "</jcr:root>\n", serialization);
+    }
+
+    @Test
+    public void testSortedMixinValues() throws RepositoryException, URISyntaxException, IOException {
+        Node node = JcrUtils.getOrCreateByPath("/testroot", NodeType.NT_UNSTRUCTURED, admin);
+        node.addMixin(JcrConstants.MIX_LOCKABLE);
+        node.addMixin(JcrConstants.MIX_TITLE);
+        node.addMixin(JcrConstants.MIX_CREATED);
+        node.setProperty("customMv", new String[] { "value2", "value3", "value1" });
+        admin.save();
+
+        String serialization = getSerializedAggregate(admin, "/testroot");
+
+        assertEquals("valid xml",
+                "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
+                "<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\"\n" +
+                "    jcr:mixinTypes=\"[mix:created,mix:lockable,mix:title]\"\n" + // sort mixins alphabetically
+                "    jcr:primaryType=\"nt:unstructured\"\n" +
+                "    customMv=\"[value2,value3,value1]\"/>\n", serialization); // don't sort other mv-properties
     }
 }