use of javax.jcr.nodetype.NodeTypeManager in project jackrabbit by apache.
the class AbstractWorkspaceSameNameSibsTest method setUp.
protected void setUp() throws Exception {
super.setUp();
// we assume sameNameSibs is supported by repository
NodeTypeManager ntMgr = superuser.getWorkspace().getNodeTypeManager();
// make sure 'sameNameSibsTrue' nodetype is properly defined
try {
sameNameSibsTrueNodeType = ntMgr.getNodeType(getProperty(PROP_SAME_NAME_SIBS_TRUE_NODE_TYPE));
NodeDefinition[] childNodeDefs = sameNameSibsTrueNodeType.getDeclaredChildNodeDefinitions();
boolean isSameNameSibs = false;
for (int i = 0; i < childNodeDefs.length; i++) {
if (childNodeDefs[i].allowsSameNameSiblings()) {
isSameNameSibs = true;
break;
}
}
if (!isSameNameSibs) {
throw new NotExecutableException("Property 'sameNameSibsTrueNodeType' does not define a nodetype where sameNameSibs are allowed: '" + sameNameSibsTrueNodeType.getName() + "'");
}
} catch (NoSuchNodeTypeException e) {
fail("Property 'sameNameSibsTrueNodeType' does not define an existing nodetype: '" + sameNameSibsTrueNodeType + "'");
}
// make sure 'sameNameSibsFalse' nodetype is properly defined
try {
sameNameSibsFalseNodeType = ntMgr.getNodeType(getProperty(PROP_SAME_NAME_SIBS_FALSE_NODE_TYPE));
NodeDefinition[] childNodeDefs = sameNameSibsFalseNodeType.getDeclaredChildNodeDefinitions();
boolean isSameNameSibs = true;
for (int i = 0; i < childNodeDefs.length; i++) {
if (!childNodeDefs[i].allowsSameNameSiblings()) {
isSameNameSibs = false;
break;
}
}
if (isSameNameSibs) {
fail("Property 'sameNameSibsFalseNodeType' does define a nodetype where sameNameSibs are not allowed: '" + sameNameSibsFalseNodeType.getName() + "'");
}
} catch (NoSuchNodeTypeException e) {
fail("Property 'sameNameSibsFalseNodeType' does not define an existing nodetype: '" + sameNameSibsFalseNodeType + "'");
}
}
use of javax.jcr.nodetype.NodeTypeManager in project jackrabbit by apache.
the class AddNodeTest method testMixinNodeType.
/**
* Tests if addNode() throws a ConstraintViolationException in case
* of an mixin node type.
*/
public void testMixinNodeType() throws RepositoryException, NotExecutableException {
NodeTypeManager ntMgr = superuser.getWorkspace().getNodeTypeManager();
NodeTypeIterator nts = ntMgr.getMixinNodeTypes();
if (nts.hasNext()) {
try {
testRootNode.addNode(nodeName1, nts.nextNodeType().getName());
superuser.save();
fail("Expected ConstraintViolationException.");
} catch (ConstraintViolationException e) {
// correct.
}
} else {
throw new NotExecutableException("no mixins.");
}
}
use of javax.jcr.nodetype.NodeTypeManager in project jackrabbit by apache.
the class AddNodeTest method testAbstractNodeType.
/**
* Tests if addNode() throws a ConstraintViolationException in case
* of an abstract node type.
*/
public void testAbstractNodeType() throws RepositoryException {
NodeTypeManager ntMgr = superuser.getWorkspace().getNodeTypeManager();
NodeTypeIterator nts = ntMgr.getPrimaryNodeTypes();
while (nts.hasNext()) {
NodeType nt = nts.nextNodeType();
if (nt.isAbstract()) {
try {
testRootNode.addNode(nodeName1, nt.getName());
superuser.save();
fail("Expected ConstraintViolationException.");
} catch (ConstraintViolationException e) {
// correct.
} finally {
superuser.refresh(false);
}
}
}
}
use of javax.jcr.nodetype.NodeTypeManager in project jackrabbit by apache.
the class SQL2OuterJoinTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
NodeTypeManager manager = superuser.getWorkspace().getNodeTypeManager();
if (!manager.hasNodeType("test:SamplePage")) {
StringBuilder defs = new StringBuilder();
defs.append("[test:SamplePage]\n");
defs.append(" - n1prop1\n");
defs.append(" + * (nt:base) = nt:unstructured \n");
defs.append("[test:SampleContent]\n");
defs.append(" - n2prop1");
Reader cndReader = new InputStreamReader(new ByteArrayInputStream(defs.toString().getBytes()));
CndImporter.registerNodeTypes(cndReader, superuser);
}
Node n1 = testRootNode.addNode("node1", "test:SamplePage");
n1.setProperty("n1prop1", "page1");
n2 = n1.addNode("node2", "test:SampleContent");
n2.setProperty("n2prop1", "content1");
testRootNode.getSession().save();
}
use of javax.jcr.nodetype.NodeTypeManager in project jackrabbit by apache.
the class SQL2QueryResultTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
NodeTypeManager manager = superuser.getWorkspace().getNodeTypeManager();
if (!manager.hasNodeType("test:RTypeTest")) {
StringBuilder defs = new StringBuilder();
defs.append("[test:RTypeTest]\n");
defs.append(" - prop1\n");
defs.append(" - prop2\n");
Reader cndReader = new InputStreamReader(new ByteArrayInputStream(defs.toString().getBytes()));
CndImporter.registerNodeTypes(cndReader, superuser);
}
Node n1 = testRootNode.addNode("node1", "test:RTypeTest");
n1.setProperty("prop1", "p1");
n1.setProperty("prop2", "p2");
testRootNode.getSession().save();
}
Aggregations