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);
}
use of javax.jcr.nodetype.NodeDefinitionTemplate in project jackrabbit-oak by apache.
the class CompatibilityIssuesTest method addNodeTest.
@Test
public void addNodeTest() throws RepositoryException {
Session session = getAdminSession();
// node type with default child-node type of to nt:base
String ntName = "test";
NodeTypeManager ntm = session.getWorkspace().getNodeTypeManager();
NodeTypeTemplate ntt = ntm.createNodeTypeTemplate();
ntt.setName(ntName);
NodeDefinitionTemplate child = ntm.createNodeDefinitionTemplate();
child.setName("*");
child.setDefaultPrimaryTypeName("nt:base");
child.setRequiredPrimaryTypeNames(new String[] { "nt:base" });
List<NodeDefinition> children = ntt.getNodeDefinitionTemplates();
children.add(child);
ntm.registerNodeType(ntt, true);
// try to create a node with the default nt:base
Node node = session.getRootNode().addNode("defaultNtBase", ntName);
// See OAK-1013
node.addNode("nothrow");
try {
node.addNode("throw", "nt:hierarchyNode");
fail("Abstract primary type should cause ConstraintViolationException");
} catch (ConstraintViolationException expected) {
}
session.save();
}
use of javax.jcr.nodetype.NodeDefinitionTemplate in project jackrabbit-oak by apache.
the class ObservationTest method deepNodeTypeMixinHierarchy.
@Test
public void deepNodeTypeMixinHierarchy() throws Exception {
NodeTypeManager ntm = getAdminSession().getWorkspace().getNodeTypeManager();
NodeTypeTemplate parentMixin = ntm.createNodeTypeTemplate();
parentMixin.setName("parentmixin");
parentMixin.setMixin(true);
ntm.registerNodeType(parentMixin, false);
NodeTypeTemplate childMixin = ntm.createNodeTypeTemplate();
childMixin.setName("childmixin");
childMixin.setMixin(true);
childMixin.setDeclaredSuperTypeNames(new String[] { "parentmixin" });
ntm.registerNodeType(childMixin, false);
NodeTypeTemplate mytype = ntm.createNodeTypeTemplate();
mytype.setName("mytype");
mytype.setMixin(false);
mytype.setDeclaredSuperTypeNames(new String[] { "childmixin" });
NodeDefinitionTemplate child = ntm.createNodeDefinitionTemplate();
child.setName("*");
child.setDefaultPrimaryTypeName("nt:base");
child.setRequiredPrimaryTypeNames(new String[] { "nt:base" });
List<NodeDefinition> children = mytype.getNodeDefinitionTemplates();
children.add(child);
ntm.registerNodeType(mytype, false);
getAdminSession().save();
// create a fresh session here to catch the above new node type definitions
observingSession = createAdminSession();
observationManager = observingSession.getWorkspace().getObservationManager();
JackrabbitObservationManager oManager = (JackrabbitObservationManager) observationManager;
ExpectationListener listener = new ExpectationListener();
JackrabbitEventFilter filter = new JackrabbitEventFilter().setAbsPath("/").setIsDeep(true).setNodeTypes(new String[] { "parentmixin" }).setEventTypes(ALL_EVENTS);
oManager.addEventListener(listener, filter);
Node n = getNode(TEST_PATH).addNode("n", "mytype");
listener.expect(n.getPath() + "/jcr:primaryType", PROPERTY_ADDED);
Node m = n.addNode("m", "nt:unstructured");
listener.expect(m.getPath(), NODE_ADDED);
getAdminSession().save();
Thread.sleep(1000);
List<Expectation> missing = listener.getMissing(TIME_OUT, TimeUnit.SECONDS);
assertTrue("Missing events: " + missing, missing.isEmpty());
List<Event> unexpected = listener.getUnexpected();
assertTrue("Unexpected events: " + unexpected, unexpected.isEmpty());
}
Aggregations