use of javax.jcr.nodetype.NodeDefinitionTemplate in project jackrabbit by apache.
the class NodeTypeCreationTest method testNewNodeTypeTemplate.
public void testNewNodeTypeTemplate() throws Exception {
String expandedName = "{" + NS_MIX_URI + "}" + "littlemixin";
String jcrName = superuser.getNamespacePrefix(NS_MIX_URI) + ":littlemixin";
NodeTypeTemplate ntt = ntm.createNodeTypeTemplate();
ntt.setName(expandedName);
assertEquals(jcrName, ntt.getName());
ntt.setName(jcrName);
assertEquals(jcrName, ntt.getName());
ntt.setAbstract(false);
assertFalse(ntt.isAbstract());
try {
ntt.setDeclaredSuperTypeNames(null);
fail("null isn't a valid array of jcr name");
} catch (ConstraintViolationException e) {
// success
}
assertNotNull(ntt.getDeclaredSupertypeNames());
assertEquals(0, ntt.getDeclaredSupertypeNames().length);
ntt.setDeclaredSuperTypeNames(new String[] { mixReferenceable });
assertNotNull(ntt.getDeclaredSupertypeNames());
assertEquals(1, ntt.getDeclaredSupertypeNames().length);
assertEquals(mixReferenceable, ntt.getDeclaredSupertypeNames()[0]);
ntt.setMixin(true);
assertTrue(ntt.isMixin());
ntt.setOrderableChildNodes(true);
assertTrue(ntt.hasOrderableChildNodes());
ntt.setQueryable(false);
assertFalse(ntt.isQueryable());
ntt.setPrimaryItemName(null);
assertNull(ntt.getPrimaryItemName());
ntt.setPrimaryItemName(jcrPrimaryType);
assertEquals(jcrPrimaryType, ntt.getPrimaryItemName());
PropertyDefinitionTemplate pdTemplate = createBooleanPropTemplate();
List pdefs = ntt.getPropertyDefinitionTemplates();
pdefs.add(pdTemplate);
assertNotNull(ntt.getDeclaredPropertyDefinitions());
assertEquals(1, ntt.getDeclaredPropertyDefinitions().length);
assertEquals(pdTemplate, ntt.getDeclaredPropertyDefinitions()[0]);
pdefs = ntt.getPropertyDefinitionTemplates();
assertEquals(1, pdefs.size());
assertEquals(pdTemplate, pdefs.get(0));
NodeDefinitionTemplate ndTemplate = ntm.createNodeDefinitionTemplate();
List ndefs = ntt.getNodeDefinitionTemplates();
ndefs.add(ndTemplate);
assertNotNull(ntt.getDeclaredChildNodeDefinitions());
assertEquals(1, ntt.getDeclaredChildNodeDefinitions().length);
assertEquals(ndTemplate, ntt.getDeclaredChildNodeDefinitions()[0]);
ndefs = ntt.getNodeDefinitionTemplates();
assertEquals(1, ndefs.size());
assertEquals(ndTemplate, ndefs.get(0));
}
use of javax.jcr.nodetype.NodeDefinitionTemplate in project jackrabbit by apache.
the class NodeTypeCreationTest method testResidualNames.
public void testResidualNames() throws Exception {
String residualName = "*";
NodeDefinitionTemplate ndt = ntm.createNodeDefinitionTemplate();
ndt.setName(residualName);
assertEquals(residualName, ndt.getName());
PropertyDefinitionTemplate pdt = ntm.createPropertyDefinitionTemplate();
pdt.setName(residualName);
assertEquals(residualName, pdt.getName());
}
use of javax.jcr.nodetype.NodeDefinitionTemplate in project jackrabbit by apache.
the class NodeTypeCreationTest method testNodeDefinitionTemplate.
public void testNodeDefinitionTemplate() throws Exception {
NodeDefinitionTemplate ndt = ntm.createNodeDefinitionTemplate();
try {
ndt.setName(null);
fail("null isn't a valid JCR name");
} catch (ConstraintViolationException e) {
// success
}
String expandedName = "{" + NS_JCR_URI + "}" + "content";
String jcrName = superuser.getNamespacePrefix(NS_JCR_URI) + ":content";
ndt.setName(expandedName);
assertEquals(jcrName, ndt.getName());
ndt.setName(jcrName);
assertEquals(jcrName, ndt.getName());
ndt.setSameNameSiblings(true);
assertTrue(ndt.allowsSameNameSiblings());
ndt.setAutoCreated(true);
assertTrue(ndt.isAutoCreated());
ndt.setMandatory(true);
assertTrue(ndt.isMandatory());
ndt.setProtected(true);
assertTrue(ndt.isProtected());
ndt.setOnParentVersion(OnParentVersionAction.VERSION);
assertEquals(OnParentVersionAction.VERSION, ndt.getOnParentVersion());
expandedName = "{" + NS_NT_URI + "}" + "folder";
jcrName = superuser.getNamespacePrefix(NS_NT_URI) + ":folder";
ndt.setDefaultPrimaryTypeName(expandedName);
assertEquals(jcrName, ndt.getDefaultPrimaryTypeName());
ndt.setDefaultPrimaryTypeName(null);
assertEquals("setting null must clear the name.", null, ndt.getDefaultPrimaryTypeName());
ndt.setRequiredPrimaryTypeNames(new String[] { expandedName });
assertNotNull(ndt.getRequiredPrimaryTypeNames());
assertEquals(1, ndt.getRequiredPrimaryTypeNames().length);
assertEquals(jcrName, ndt.getRequiredPrimaryTypeNames()[0]);
try {
ndt.setRequiredPrimaryTypeNames(null);
fail("null isn't a valid array of jcr name");
} catch (ConstraintViolationException e) {
// success
}
}
use of javax.jcr.nodetype.NodeDefinitionTemplate in project jackrabbit by apache.
the class NodeTypeDefinitionFactory method create.
/**
* Create a new JCR node definition from the given <code>QNodeDefinition</code>.
*
* @param qNd A node definition.
* @return The corresponding JCR node definition.
* @throws RepositoryException if an error occurs.
*/
public NodeDefinition create(QNodeDefinition qNd) throws RepositoryException {
NodeDefinitionTemplate nt = ntMgr.createNodeDefinitionTemplate();
nt.setName(getJCRName(qNd.getName()));
nt.setAutoCreated(qNd.isAutoCreated());
nt.setMandatory(qNd.isMandatory());
nt.setOnParentVersion(qNd.getOnParentVersion());
nt.setProtected(qNd.isProtected());
nt.setSameNameSiblings(qNd.allowsSameNameSiblings());
nt.setDefaultPrimaryTypeName(getJCRName(qNd.getDefaultPrimaryType()));
nt.setRequiredPrimaryTypeNames(getJCRNames(qNd.getRequiredPrimaryTypes()));
return nt;
}
use of javax.jcr.nodetype.NodeDefinitionTemplate in project jackrabbit-oak by apache.
the class CugValidatorTest method testNodeTypeWithCugNames.
@Test
public void testNodeTypeWithCugNames() throws Exception {
ReadWriteNodeTypeManager ntMgr = new ReadWriteNodeTypeManager() {
@Nonnull
@Override
protected Root getWriteRoot() {
return root;
}
@CheckForNull
@Override
protected Tree getTypes() {
return root.getTree(NODE_TYPES_PATH);
}
};
NodeTypeTemplate ntTemplate = ntMgr.createNodeTypeTemplate();
ntTemplate.setName("testNT");
NodeDefinitionTemplate ndt = ntMgr.createNodeDefinitionTemplate();
ndt.setName(REP_CUG_POLICY);
ndt.setRequiredPrimaryTypeNames(new String[] { JcrConstants.NT_BASE });
ntTemplate.getNodeDefinitionTemplates().add(ndt);
ntMgr.registerNodeType(ntTemplate, true);
}
Aggregations