You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ss...@apache.org on 2025/02/24 12:48:07 UTC

(sling-org-apache-sling-jcr-repoinit) branch feature/SLING-12668-forcedMultiValue created (now c5fdacd)

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

sseifert pushed a change to branch feature/SLING-12668-forcedMultiValue
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-repoinit.git


      at c5fdacd  SLING-12668 unit test to reproduce problem

This branch includes the following new commits:

     new c5fdacd  SLING-12668 unit test to reproduce problem

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(sling-org-apache-sling-jcr-repoinit) 01/01: SLING-12668 unit test to reproduce problem

Posted by ss...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

sseifert pushed a commit to branch feature/SLING-12668-forcedMultiValue
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-repoinit.git

commit c5fdacdec9405f7e508fc42bee4633be2c47e234
Author: Stefan Seifert <st...@users.noreply.github.com>
AuthorDate: Mon Feb 24 13:47:42 2025 +0100

    SLING-12668 unit test to reproduce problem
---
 .../sling/jcr/repoinit/it/RepoInitTextIT.java      | 53 ++++++++++++++++++++++
 src/test/resources/repoinit.txt                    |  9 ++++
 2 files changed, 62 insertions(+)

diff --git a/src/test/java/org/apache/sling/jcr/repoinit/it/RepoInitTextIT.java b/src/test/java/org/apache/sling/jcr/repoinit/it/RepoInitTextIT.java
index baac1c9..c4c400d 100644
--- a/src/test/java/org/apache/sling/jcr/repoinit/it/RepoInitTextIT.java
+++ b/src/test/java/org/apache/sling/jcr/repoinit/it/RepoInitTextIT.java
@@ -19,13 +19,17 @@
 package org.apache.sling.jcr.repoinit.it;
 
 import javax.inject.Inject;
+import javax.jcr.Node;
+import javax.jcr.Property;
 import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
 import javax.jcr.Value;
 import javax.jcr.ValueFactory;
 
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.util.UUID;
+import java.util.stream.Stream;
 
 import org.apache.jackrabbit.api.JackrabbitSession;
 import org.apache.jackrabbit.api.security.user.Authorizable;
@@ -40,6 +44,7 @@ import org.ops4j.pax.exam.junit.PaxExam;
 import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
 import org.ops4j.pax.exam.spi.reactors.PerClass;
 
+import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
@@ -407,4 +412,52 @@ public class RepoInitTextIT extends RepoInitTestSupport {
             }
         };
     }
+
+    @Test
+    public void forcedMultiValue() throws Exception {
+        new Retry() {
+            @Override
+            public Void call() throws Exception {
+                Node node = session.getNode("/forcedMultiValue");
+                assertMultiProperty(node, "multiValue", new String[] {"item1", "item2"});
+                assertMultiProperty(node, "singleMultiValue", new String[] {"single"});
+                assertMultiProperty(node, "emptyMultiValue", new String[0]);
+                assertLongMultiProperty(node, "longMultiValue", new Long[] {1243L, 5678L});
+                assertLongMultiProperty(node, "singleLongMultiValue", new Long[] {1243L});
+                assertLongMultiProperty(node, "emptyMultiValue", new Long[0]);
+                return null;
+            }
+        };
+    }
+
+    private static void assertMultiProperty(Node node, String propertyName, Object[] expectedValues) throws Exception {
+        Property prop = node.getProperty(propertyName);
+        assertTrue("Property " + propertyName + " is not multiple", prop.isMultiple());
+        Object[] actualValues = Stream.of(prop.getValues())
+                .map(value -> {
+                    try {
+                        return value.getString();
+                    } catch (IllegalStateException | RepositoryException e) {
+                        return null;
+                    }
+                })
+                .toArray();
+        assertArrayEquals("Unexpected values for property " + propertyName, expectedValues, actualValues);
+    }
+
+    private static void assertLongMultiProperty(Node node, String propertyName, Object[] expectedValues)
+            throws Exception {
+        Property prop = node.getProperty(propertyName);
+        assertTrue("Property " + propertyName + " is not multiple", prop.isMultiple());
+        Object[] actualValues = Stream.of(prop.getValues())
+                .map(value -> {
+                    try {
+                        return value.getLong();
+                    } catch (IllegalStateException | RepositoryException e) {
+                        return null;
+                    }
+                })
+                .toArray();
+        assertArrayEquals("Unexpected values for property " + propertyName, expectedValues, actualValues);
+    }
 }
diff --git a/src/test/resources/repoinit.txt b/src/test/resources/repoinit.txt
index 2dbbe24..a3fa817 100644
--- a/src/test/resources/repoinit.txt
+++ b/src/test/resources/repoinit.txt
@@ -112,3 +112,12 @@ set properties on authorizable(bob)/nested,authorizable(grpB)/nested
   set quotedMix to "quoted", non-quoted, "the last \" one"
   set nested/someInteger{Long} to 42
 end
+
+ensure nodes (nt:unstructured) /forcedMultiValue with properties
+  set multiValue{String[]} to "item1","item2"
+  set singleMultiValue{String[]} to "single"
+  set emptyMultiValue{String[]} to
+  set longMultiValue{Long[]} to 1243,5678
+  set singleLongMultiValue{Long[]} to 1243
+  set emptyLongMultiValue{Long[]} to
+end