Search in sources :

Example 6 with NodeType

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

the class MandatoryItemTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    NodeType nt = superuser.getWorkspace().getNodeTypeManager().getNodeType(testNodeType);
    NodeDefinition[] ndefs = nt.getChildNodeDefinitions();
    for (int i = 0; i < ndefs.length; i++) {
        if (ndefs[i].isMandatory() && !ndefs[i].isProtected() && !ndefs[i].isAutoCreated()) {
            childNodeDef = ndefs[i];
            break;
        }
    }
    PropertyDefinition[] pdefs = nt.getPropertyDefinitions();
    for (int i = 0; i < pdefs.length; i++) {
        if (pdefs[i].isMandatory() && !pdefs[i].isProtected() && !pdefs[i].isAutoCreated()) {
            childPropDef = pdefs[i];
            break;
        }
    }
    if (childPropDef == null && childNodeDef == null) {
        cleanUp();
        throw new NotExecutableException();
    }
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) NodeType(javax.jcr.nodetype.NodeType) NodeDefinition(javax.jcr.nodetype.NodeDefinition) PropertyDefinition(javax.jcr.nodetype.PropertyDefinition)

Example 7 with NodeType

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

the class NodeAddMixinTest method testAddSuccessfully.

/**
     * Tests if <code>Node.addMixin(String mixinName)</code> adds the requested
     * mixin and stores it in property <code>jcr:mixinTypes</code>
     */
public void testAddSuccessfully() throws NotExecutableException, RepositoryException {
    Session session = testRootNode.getSession();
    Node node = testRootNode.addNode(nodeName1, testNodeType);
    String mixinName = NodeMixinUtil.getAddableMixinName(session, node);
    if (mixinName == null) {
        throw new NotExecutableException("No testable mixin node type found");
    }
    node.addMixin(mixinName);
    // test if mixin is written to property jcr:mixinTypes immediately
    Value[] mixinValues = node.getProperty(jcrMixinTypes).getValues();
    boolean found = false;
    for (int i = 0; i < mixinValues.length; i++) {
        found |= mixinName.equals(mixinValues[i].getString());
    }
    if (!found) {
        fail("Mixin type must be added to property " + jcrMixinTypes + " immediately.");
    }
    // it is implementation-specific if a added mixin is available
    // before or after save therefore save before further tests
    testRootNode.getSession().save();
    // test if added mixin is available by node.getMixinNodeTypes()
    NodeType[] mixins = node.getMixinNodeTypes();
    found = false;
    for (int i = 0; i < mixins.length; i++) {
        found |= mixinName.equals(mixins[i].getName());
    }
    if (!found) {
        fail("Mixin '" + mixinName + "' type not added.");
    }
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) Node(javax.jcr.Node) NodeType(javax.jcr.nodetype.NodeType) Value(javax.jcr.Value) Session(javax.jcr.Session)

Example 8 with NodeType

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

the class CanSetPropertyTest method testReturnFalseBecauseIsMultiple.

/**
     * Tests if NodeType.canSetProperty(String propertyName, Value value)
     * returns false if the property is multiple
     */
public void testReturnFalseBecauseIsMultiple() throws NotExecutableException, RepositoryException {
    PropertyDefinition propDef = NodeTypeUtil.locatePropertyDef(session, NodeTypeUtil.ANY_PROPERTY_TYPE, true, false, false, false);
    if (propDef == null) {
        throw new NotExecutableException("No multiple, not protected property def found.");
    }
    NodeType nodeType = propDef.getDeclaringNodeType();
    Value value = NodeTypeUtil.getValueOfType(superuser, propDef.getRequiredType());
    assertFalse("canSetProperty(String propertyName, Value value) must " + "return false if the property is multiple.", nodeType.canSetProperty(propDef.getName(), value));
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) NodeType(javax.jcr.nodetype.NodeType) Value(javax.jcr.Value) PropertyDefinition(javax.jcr.nodetype.PropertyDefinition)

Example 9 with NodeType

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

the class NodeDefTest method testGetDefaultPrimaryTypes.

/**
     * Tests if the default primary type is of the same or a sub node type as the
     * the required primary types. Test runs for all existing node types. Also
     * tests the string based access ({@link NodeDefinition#getDefaultPrimaryTypeName()}.
     * 
     * @since JCR 2.0
     */
public void testGetDefaultPrimaryTypes() throws RepositoryException {
    // loop all node types
    for (NodeTypeIterator types = manager.getAllNodeTypes(); types.hasNext(); ) {
        NodeType type = types.nextNodeType();
        NodeDefinition[] defs = type.getChildNodeDefinitions();
        for (int i = 0; i < defs.length; i++) {
            NodeDefinition def = defs[i];
            NodeType defaultType = def.getDefaultPrimaryType();
            String defaultTypeName = def.getDefaultPrimaryTypeName();
            if (defaultType != null) {
                NodeType[] requiredTypes = def.getRequiredPrimaryTypes();
                for (int j = 0; j < requiredTypes.length; j++) {
                    NodeType requiredType = requiredTypes[j];
                    boolean isSubType = compareWithRequiredType(requiredType, defaultType);
                    assertTrue("The NodeType returned by " + "getDefaultPrimaryType or one of its " + "supertypes must match all NodeTypes " + "returned by getRequiredPrimaryTypes()", isSubType);
                }
                assertEquals("type names obtained from getDefaultPrimaryType and getDefaultPrimaryTypeName should match", defaultType.getName(), defaultTypeName);
                NodeType tmpType = manager.getNodeType(defaultTypeName);
                assertEquals(tmpType.getName(), defaultTypeName);
            } else {
                assertNull("getDefaultPrimaryTypeName should return null when getDefaultPrimaryType does", defaultTypeName);
            }
        }
    }
}
Also used : NodeType(javax.jcr.nodetype.NodeType) NodeDefinition(javax.jcr.nodetype.NodeDefinition) NodeTypeIterator(javax.jcr.nodetype.NodeTypeIterator)

Example 10 with NodeType

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

the class NodeDefTest method testGetRequiredPrimaryTypeNames.

/**
     * Tests that the information from getRequiredPrimaryTypeNames()
     * matches getRequiredPrimaryTypes().
     * 
     * @since JCR 2.0
     */
public void testGetRequiredPrimaryTypeNames() throws RepositoryException {
    // loop all node types
    for (NodeTypeIterator types = manager.getAllNodeTypes(); types.hasNext(); ) {
        NodeType type = types.nextNodeType();
        NodeDefinition[] defs = type.getChildNodeDefinitions();
        for (int i = 0; i < defs.length; i++) {
            NodeType[] requiredPrimaryTypes = defs[i].getRequiredPrimaryTypes();
            Set<String> rptnames = new HashSet<String>();
            for (int j = 0; j < requiredPrimaryTypes.length; j++) {
                rptnames.add(requiredPrimaryTypes[j].getName());
            }
            Set<String> rptnames2 = new HashSet<String>(Arrays.asList(defs[i].getRequiredPrimaryTypeNames()));
            assertEquals("names returned from getRequiredPrimaryTypeNames should match types returned from getRequiredPrimaryTypes", rptnames, rptnames2);
        }
    }
}
Also used : NodeType(javax.jcr.nodetype.NodeType) NodeDefinition(javax.jcr.nodetype.NodeDefinition) NodeTypeIterator(javax.jcr.nodetype.NodeTypeIterator) HashSet(java.util.HashSet)

Aggregations

NodeType (javax.jcr.nodetype.NodeType)258 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)84 PropertyDefinition (javax.jcr.nodetype.PropertyDefinition)79 Value (javax.jcr.Value)57 NodeTypeIterator (javax.jcr.nodetype.NodeTypeIterator)53 Node (javax.jcr.Node)52 NodeDefinition (javax.jcr.nodetype.NodeDefinition)44 NodeTypeManager (javax.jcr.nodetype.NodeTypeManager)41 RepositoryException (javax.jcr.RepositoryException)33 ArrayList (java.util.ArrayList)29 Test (org.junit.Test)27 Session (javax.jcr.Session)20 NodeTypeIteratorAdapter (org.apache.jackrabbit.commons.iterator.NodeTypeIteratorAdapter)16 Name (org.apache.jackrabbit.spi.Name)15 HashSet (java.util.HashSet)14 NoSuchNodeTypeException (javax.jcr.nodetype.NoSuchNodeTypeException)13 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)11 QNodeTypeDefinition (org.apache.jackrabbit.spi.QNodeTypeDefinition)6 InputStreamReader (java.io.InputStreamReader)5 NodeIterator (javax.jcr.NodeIterator)5