Search in sources :

Example 36 with NodeTypeManager

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 + "'");
    }
}
Also used : NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) NodeDefinition(javax.jcr.nodetype.NodeDefinition) NoSuchNodeTypeException(javax.jcr.nodetype.NoSuchNodeTypeException)

Example 37 with NodeTypeManager

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.");
    }
}
Also used : NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) NodeTypeIterator(javax.jcr.nodetype.NodeTypeIterator) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException)

Example 38 with NodeTypeManager

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);
            }
        }
    }
}
Also used : NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) NodeType(javax.jcr.nodetype.NodeType) NodeTypeIterator(javax.jcr.nodetype.NodeTypeIterator) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException)

Example 39 with NodeTypeManager

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();
}
Also used : NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) InputStreamReader(java.io.InputStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) Node(javax.jcr.Node) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader)

Example 40 with NodeTypeManager

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();
}
Also used : NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) InputStreamReader(java.io.InputStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) Node(javax.jcr.Node) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader)

Aggregations

NodeTypeManager (javax.jcr.nodetype.NodeTypeManager)103 NodeType (javax.jcr.nodetype.NodeType)47 Node (javax.jcr.Node)38 Session (javax.jcr.Session)35 NodeTypeTemplate (javax.jcr.nodetype.NodeTypeTemplate)31 NodeTypeIterator (javax.jcr.nodetype.NodeTypeIterator)29 Test (org.junit.Test)25 RepositoryException (javax.jcr.RepositoryException)18 ByteArrayInputStream (java.io.ByteArrayInputStream)15 PropertyDefinition (javax.jcr.nodetype.PropertyDefinition)15 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)14 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)11 ArrayList (java.util.ArrayList)10 Workspace (javax.jcr.Workspace)10 InputStream (java.io.InputStream)9 NodeDefinition (javax.jcr.nodetype.NodeDefinition)9 PropertyDefinitionTemplate (javax.jcr.nodetype.PropertyDefinitionTemplate)9 InputStreamReader (java.io.InputStreamReader)8 NamespaceRegistry (javax.jcr.NamespaceRegistry)8 Value (javax.jcr.Value)8