Search in sources :

Example 26 with NodeTypeManager

use of javax.jcr.nodetype.NodeTypeManager in project jackrabbit by apache.

the class AbstractWorkspaceReferenceableTest method setUp.

protected void setUp() throws Exception {
    super.setUp();
    // we assume referencing is supported by repository
    NodeTypeManager ntMgr = superuser.getWorkspace().getNodeTypeManager();
    // assert that this repository supports references
    try {
        NodeType referenceableNt = ntMgr.getNodeType(mixReferenceable);
        if (referenceableNt == null) {
            throw new NotExecutableException("Repository does not support Referencing: mixin nodetype '" + mixReferenceable + "' is missing.");
        }
    } catch (NoSuchNodeTypeException e) {
        throw new NotExecutableException("Repository does not support Referencing: mixin nodetype '" + mixReferenceable + "' is missing.");
    }
}
Also used : NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) NodeType(javax.jcr.nodetype.NodeType) NoSuchNodeTypeException(javax.jcr.nodetype.NoSuchNodeTypeException)

Example 27 with NodeTypeManager

use of javax.jcr.nodetype.NodeTypeManager in project jackrabbit by apache.

the class AbstractWorkspaceVersionableTest method setUp.

protected void setUp() throws Exception {
    super.setUp();
    // we assume versioning is supported by repository
    NodeTypeManager ntMgr = superuser.getWorkspace().getNodeTypeManager();
    // assert that this repository supports versioning
    try {
        NodeType versionableNt = ntMgr.getNodeType(mixVersionable);
        if (versionableNt == null) {
            throw new NotExecutableException("Repository does not support versioning: mixin nodetype '" + mixVersionable + "' is missing.");
        }
    } catch (NoSuchNodeTypeException e) {
        throw new NotExecutableException("Repository does not support versioning: mixin nodetype '" + mixVersionable + "' is missing.");
    }
}
Also used : NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) NodeType(javax.jcr.nodetype.NodeType) NoSuchNodeTypeException(javax.jcr.nodetype.NoSuchNodeTypeException)

Example 28 with NodeTypeManager

use of javax.jcr.nodetype.NodeTypeManager in project jackrabbit by apache.

the class MixinTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    NodeTypeManager manager = superuser.getWorkspace().getNodeTypeManager();
    if (!manager.hasNodeType("test:mimeType")) {
        String cnd = "<test='http://www.apache.org/jackrabbit/test'>\n" + "[test:mimeType] > mix:mimeType mixin";
        Reader cndReader = new InputStreamReader(new ByteArrayInputStream(cnd.getBytes()));
        CndImporter.registerNodeTypes(cndReader, superuser);
    }
}
Also used : NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) InputStreamReader(java.io.InputStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader)

Example 29 with NodeTypeManager

use of javax.jcr.nodetype.NodeTypeManager in project jackrabbit by apache.

the class NodeSetPrimaryTypeTest method testSetAbstractAsPrimaryType.

/**
 * Tests if <code>Node.setPrimaryType(String)</code> throws a
 * <code>ConstraintViolationException</code> if the
 * name of a mixin type is passed
 */
public void testSetAbstractAsPrimaryType() throws RepositoryException {
    Session session = testRootNode.getSession();
    NodeTypeManager manager = session.getWorkspace().getNodeTypeManager();
    NodeTypeIterator nts = manager.getPrimaryNodeTypes();
    while (nts.hasNext()) {
        NodeType nt = nts.nextNodeType();
        if (nt.isAbstract()) {
            try {
                Node node = testRootNode.addNode(nodeName1, testNodeType);
                node.setPrimaryType(nt.getName());
                fail("Node.setPrimaryType(String) must throw ConstraintViolationException if the specified node type name refers to an abstract node type.");
            } catch (ConstraintViolationException e) {
            // success
            } finally {
                // reset the changes.
                session.refresh(false);
            }
        }
    }
}
Also used : NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) NodeType(javax.jcr.nodetype.NodeType) Node(javax.jcr.Node) NodeTypeIterator(javax.jcr.nodetype.NodeTypeIterator) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) Session(javax.jcr.Session)

Example 30 with NodeTypeManager

use of javax.jcr.nodetype.NodeTypeManager in project jackrabbit by apache.

the class NodeSetPrimaryTypeTest method testAddNonExisting.

/**
 * Tests if <code>Node.setPrimaryType(String)</code> throws a
 * <code>NoSuchNodeTypeException</code> if the
 * name of an existing node type is passed.
 */
public void testAddNonExisting() throws RepositoryException {
    Session session = testRootNode.getSession();
    NodeTypeManager manager = session.getWorkspace().getNodeTypeManager();
    String nonExistingMixinName = "abc";
    while (manager.hasNodeType(nonExistingMixinName)) {
        nonExistingMixinName += "_";
    }
    Node node = testRootNode.addNode(nodeName1, testNodeType);
    try {
        node.setPrimaryType(nonExistingMixinName);
        // ev. only detected upon save
        superuser.save();
        fail("Node.setPrimaryType(String) must throw a NoSuchNodeTypeException if no nodetype exists with the given name.");
    } catch (NoSuchNodeTypeException e) {
    // success
    }
}
Also used : NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) Node(javax.jcr.Node) Session(javax.jcr.Session) NoSuchNodeTypeException(javax.jcr.nodetype.NoSuchNodeTypeException)

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