jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r1135950 - /jackrabbit/trunk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/nodetype/AddMixinTest.java
Date Wed, 15 Jun 2011 08:09:50 GMT
Author: angela
Date: Wed Jun 15 08:09:50 2011
New Revision: 1135950

URL: http://svn.apache.org/viewvc?rev=1135950&view=rev
Log:
tests

Modified:
    jackrabbit/trunk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/nodetype/AddMixinTest.java

Modified: jackrabbit/trunk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/nodetype/AddMixinTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/nodetype/AddMixinTest.java?rev=1135950&r1=1135949&r2=1135950&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/nodetype/AddMixinTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/nodetype/AddMixinTest.java
Wed Jun 15 08:09:50 2011
@@ -21,8 +21,11 @@ import java.util.List;
 
 import javax.jcr.Node;
 import javax.jcr.RepositoryException;
+import javax.jcr.nodetype.ConstraintViolationException;
+import javax.jcr.nodetype.NodeDefinitionTemplate;
 import javax.jcr.nodetype.NodeType;
 import javax.jcr.nodetype.NodeTypeManager;
+import javax.jcr.nodetype.NodeTypeTemplate;
 
 import org.apache.jackrabbit.test.AbstractJCRTest;
 import org.apache.jackrabbit.test.NotExecutableException;
@@ -168,4 +171,84 @@ public class AddMixinTest extends Abstra
         List<NodeType> mixins = Arrays.asList(node.getMixinNodeTypes());
         assertTrue("Adding 2 mixins at once -> both must be present.", mixins.contains(ntMgr.getNodeType(mixReferenceable))
&& mixins.contains(ntMgr.getNodeType(mixLockable)));
     }
+
+    public void testAddItemsDefinedByMixin() throws NotExecutableException, RepositoryException
{
+        // register mixin
+        NodeTypeManager ntm = superuser.getWorkspace().getNodeTypeManager();
+        NodeTypeTemplate ntd = ntm.createNodeTypeTemplate();
+        ntd.setName("testMixin");
+        ntd.setMixin(true);
+        NodeDefinitionTemplate nodeDef = ntm.createNodeDefinitionTemplate();
+        nodeDef.setName("child");
+        nodeDef.setRequiredPrimaryTypeNames(new String[] {"nt:folder"});
+        ntd.getNodeDefinitionTemplates().add(nodeDef);
+        ntm.registerNodeType(ntd, true);
+
+        // create node and add mixin
+        Node node = testRootNode.addNode(nodeName1, "nt:resource");
+        node.setProperty("jcr:data", "abc");
+        node.addMixin("testMixin");
+        superuser.save();
+
+        // create a child node defined by the mixin
+        node.addNode("child", "nt:folder");
+        node.save();
+    }
+
+
+    public void testAddItemsDefinedByMixin2() throws NotExecutableException, RepositoryException
{
+        // register mixin
+        NodeTypeManager ntm = superuser.getWorkspace().getNodeTypeManager();
+        NodeTypeTemplate ntd = ntm.createNodeTypeTemplate();
+        ntd.setName("testMixin");
+        ntd.setMixin(true);
+        NodeDefinitionTemplate nodeDef = ntm.createNodeDefinitionTemplate();
+        nodeDef.setName("child");
+        nodeDef.setRequiredPrimaryTypeNames(new String[] {"nt:folder"});
+        ntd.getNodeDefinitionTemplates().add(nodeDef);
+        ntm.registerNodeType(ntd, true);
+
+        // create node and add mixin
+        Node node = testRootNode.addNode(nodeName1, "nt:resource");
+        node.setProperty("jcr:data", "abc");
+        node.addMixin("testMixin");
+        superuser.save();
+
+        // create a child node defined by the mixin without specifying the
+        // node type
+        try {
+            node.addNode("child");
+            fail();
+        } catch (ConstraintViolationException e) {
+            // success as ChildNode Definition doesn't specify a default primary
+            // type -> see comment in ItemDefinitionProvider#getQNodeDefinition
+        }
+    }
+
+    public void testAddItemsDefinedByMixin3() throws NotExecutableException, RepositoryException
{
+        // register mixin
+        NodeTypeManager ntm = superuser.getWorkspace().getNodeTypeManager();
+        NodeTypeTemplate ntd = ntm.createNodeTypeTemplate();
+        ntd.setName("testMixin");
+        ntd.setMixin(true);
+        NodeDefinitionTemplate nodeDef = ntm.createNodeDefinitionTemplate();
+        nodeDef.setName("child");
+        nodeDef.setRequiredPrimaryTypeNames(new String[] {"nt:folder"});
+        nodeDef.setDefaultPrimaryTypeName("nt:folder");
+        ntd.getNodeDefinitionTemplates().add(nodeDef);
+        ntm.registerNodeType(ntd, true);
+
+        // create node and add mixin
+        Node node = testRootNode.addNode(nodeName1, "nt:resource");
+        node.setProperty("jcr:data", "abc");
+        node.addMixin("testMixin");
+        superuser.save();
+
+        // create a child node defined by the mixin without specifying the
+        // node type -> must succeed since default primary type is specified
+        // in the child node def
+        Node c = node.addNode("child");
+        assertEquals("nt:folder", c.getPrimaryNodeType().getName());
+        superuser.save();
+    }
 }
\ No newline at end of file



Mime
View raw message