You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by kw...@apache.org on 2021/11/11 14:32:16 UTC
[jackrabbit-oak] 01/01: OAK-9621: add failing tests for mandatory
child nodes
This is an automated email from the ASF dual-hosted git repository.
kwin pushed a commit to branch bugfix/OAK-9621
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git
commit 656b12aa2be62ea29cbf557e01a33a88edd79b1a
Author: Konrad Windszus <kw...@apache.org>
AuthorDate: Thu Nov 11 15:28:02 2021 +0100
OAK-9621: add failing tests for mandatory child nodes
---
.../jackrabbit/oak/jcr/nodetype/NodeTypeTest.java | 40 ++++++++++++++++++++++
1 file changed, 40 insertions(+)
diff --git a/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/nodetype/NodeTypeTest.java b/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/nodetype/NodeTypeTest.java
index b7c2e7f..f191c99 100644
--- a/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/nodetype/NodeTypeTest.java
+++ b/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/nodetype/NodeTypeTest.java
@@ -23,6 +23,7 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
+import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;
@@ -30,6 +31,7 @@ import java.util.UUID;
import javax.jcr.Node;
import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.ValueFactory;
import javax.jcr.nodetype.ConstraintViolationException;
@@ -41,6 +43,7 @@ import javax.jcr.nodetype.PropertyDefinitionTemplate;
import org.apache.jackrabbit.JcrConstants;
import org.apache.jackrabbit.commons.cnd.CndImporter;
+import org.apache.jackrabbit.commons.cnd.ParseException;
import org.apache.jackrabbit.oak.commons.junit.LogCustomizer;
import org.apache.jackrabbit.oak.fixture.NodeStoreFixture;
import org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest;
@@ -379,6 +382,43 @@ public class NodeTypeTest extends AbstractRepositoryTest {
}
@Test
+ public void mandatoryChildNode() throws RepositoryException, ParseException, IOException {
+ Session session = getAdminSession();
+ Node root = session.getRootNode();
+
+ String cnd = "<'test'='http://www.apache.org/jackrabbit/test'>\n" +
+ "[test:MyType] > nt:unstructured\n" +
+ " + * (nt:folder) mandatory";
+
+ CndImporter.registerNodeTypes(new StringReader(cnd), session);
+
+ // add with missing mandatory child node
+ Node n = root.addNode("test", "test:MyType");
+
+ try {
+ session.save();
+ fail("Must fail with ConstraintViolationException due to missing mandatory child node");
+ } catch (ConstraintViolationException e) {
+ // expected
+ session.refresh(false);
+ }
+
+ // set up correct structure
+ n = root.addNode("test", "test:MyType");
+ Node mandatoryChildNode = n.addNode("child", "nt:folder");
+ session.save();
+
+ // remove mandatory child node
+ try {
+ mandatoryChildNode.remove();
+ fail("Must fail with ConstraintViolationException because this is a mandatory child node of the parent node's node type");
+ } catch (ConstraintViolationException e) {
+ // expected
+ session.refresh(false);
+ }
+ }
+
+ @Test
public void addReferenceableToExistingType() throws Exception {
Session session = getAdminSession();
Node root = session.getRootNode();