use of javax.jcr.nodetype.NodeDefinitionTemplate in project jackrabbit by apache.
the class AddMixinTest method testAddItemsDefinedByMixin.
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();
}
use of javax.jcr.nodetype.NodeDefinitionTemplate in project jackrabbit by apache.
the class AddMixinTest method testAddItemsDefinedByMixin3.
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();
}
use of javax.jcr.nodetype.NodeDefinitionTemplate in project jackrabbit by apache.
the class AddMixinTest method testAddItemsDefinedByMixin2.
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();
// 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
}
}
use of javax.jcr.nodetype.NodeDefinitionTemplate in project jackrabbit by apache.
the class NodeTypeCreationTest method testInvalidJCRNames.
public void testInvalidJCRNames() throws Exception {
String invalidName = ":ab[2]";
// invalid name(s) passed to NT-template methods
NodeTypeTemplate ntt = ntm.createNodeTypeTemplate();
try {
ntt.setName(invalidName);
fail("ConstraintViolationException expected. Nt-name is invalid");
} catch (ConstraintViolationException e) {
// success
}
try {
ntt.setDeclaredSuperTypeNames(new String[] { "{" + NS_MIX_URI + "}" + "littlemixin", invalidName });
fail("ConstraintViolationException expected. One of the super type names is invalid");
} catch (ConstraintViolationException e) {
// success
}
try {
ntt.setPrimaryItemName(invalidName);
fail("ConstraintViolationException expected. Primary item name is invalid");
} catch (ConstraintViolationException e) {
// success
}
// invalid name(s) passed to NodeDefinitionTemplate
NodeDefinitionTemplate ndt = ntm.createNodeDefinitionTemplate();
try {
ndt.setName(invalidName);
fail("ConstraintViolationException expected. Name is invalid");
} catch (ConstraintViolationException e) {
// success
}
try {
ndt.setRequiredPrimaryTypeNames(new String[] { "{" + NS_MIX_URI + "}" + "littlemixin", invalidName });
fail("ConstraintViolationException expected. One of the required primary type names is invalid");
} catch (ConstraintViolationException e) {
// success
}
try {
ndt.setDefaultPrimaryTypeName(invalidName);
fail("ConstraintViolationException expected. Default primary type name is invalid");
} catch (ConstraintViolationException e) {
// success
}
// invalid name(s) passed to PropertyDefinitionTemplate
PropertyDefinitionTemplate pdt = ntm.createPropertyDefinitionTemplate();
try {
pdt.setName(invalidName);
fail("ConstraintViolationException expected. Name is invalid");
} catch (ConstraintViolationException e) {
// success
}
}
use of javax.jcr.nodetype.NodeDefinitionTemplate in project jackrabbit by apache.
the class NodeTypeCreationTest method testEmptyNodeDefinitionTemplate.
public void testEmptyNodeDefinitionTemplate() throws Exception {
NodeDefinitionTemplate ndt = ntm.createNodeDefinitionTemplate();
assertNull(ndt.getName());
assertFalse(ndt.isAutoCreated());
assertFalse(ndt.isMandatory());
assertFalse(ndt.isProtected());
assertEquals(OnParentVersionAction.COPY, ndt.getOnParentVersion());
assertNull(ndt.getDeclaringNodeType());
assertNull(ndt.getRequiredPrimaryTypes());
assertNull(ndt.getRequiredPrimaryTypeNames());
assertNull(ndt.getDefaultPrimaryType());
assertNull(ndt.getDefaultPrimaryTypeName());
assertFalse(ndt.allowsSameNameSiblings());
}
Aggregations