Search in sources :

Example 16 with NodeTypeIterator

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

the class PropertyDefTest method testIsAutoCreate.

/**
     * Tests if auto create properties are not a residual set definition
     * (getName() does not return "*")
     */
public void testIsAutoCreate() throws RepositoryException {
    NodeTypeIterator types = manager.getAllNodeTypes();
    // loop all node types
    while (types.hasNext()) {
        NodeType type = types.nextNodeType();
        PropertyDefinition[] defs = type.getPropertyDefinitions();
        for (int i = 0; i < defs.length; i++) {
            if (defs[i].isAutoCreated()) {
                assertFalse("An auto create property must not be a " + "residual set definition.", defs[i].getName().equals("*"));
            }
        }
    }
}
Also used : NodeType(javax.jcr.nodetype.NodeType) NodeTypeIterator(javax.jcr.nodetype.NodeTypeIterator) PropertyDefinition(javax.jcr.nodetype.PropertyDefinition)

Example 17 with NodeTypeIterator

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

the class PropertyDefTest method testGetDeclaringNodeType.

/**
     * Test getDeclaringNodeType() returns the node type which is defining the
     * requested property def. Test runs for all existing node types.
     */
public void testGetDeclaringNodeType() throws RepositoryException {
    NodeTypeIterator types = manager.getAllNodeTypes();
    // loop all node types
    while (types.hasNext()) {
        NodeType currentType = types.nextNodeType();
        PropertyDefinition[] defsOfCurrentType = currentType.getPropertyDefinitions();
        // loop all property defs of each node type
        for (int i = 0; i < defsOfCurrentType.length; i++) {
            PropertyDefinition def = defsOfCurrentType[i];
            NodeType type = def.getDeclaringNodeType();
            // check if def is part of the property defs of the
            // declaring node type
            PropertyDefinition[] defs = type.getPropertyDefinitions();
            boolean hasType = false;
            for (int j = 0; j < defs.length; j++) {
                if (defs[j].getName().equals(def.getName())) {
                    hasType = true;
                    break;
                }
            }
            assertTrue("getDeclaringNodeType() must return the node " + "which defines the corresponding property def.", hasType);
        }
    }
}
Also used : NodeType(javax.jcr.nodetype.NodeType) NodeTypeIterator(javax.jcr.nodetype.NodeTypeIterator) PropertyDefinition(javax.jcr.nodetype.PropertyDefinition)

Example 18 with NodeTypeIterator

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

the class PropertyDefTest method testIsRequiredType.

/**
     * Tests if isRequiredType() returns a valid PropertyType.
     * <p>
     * The test runs for all available node types.
     */
public void testIsRequiredType() throws RepositoryException {
    NodeTypeIterator types = manager.getAllNodeTypes();
    // loop all node types
    while (types.hasNext()) {
        NodeType type = types.nextNodeType();
        PropertyDefinition[] defs = type.getPropertyDefinitions();
        for (int i = 0; i < defs.length; i++) {
            switch(defs[i].getRequiredType()) {
                case PropertyType.STRING:
                case PropertyType.BINARY:
                case PropertyType.DATE:
                case PropertyType.LONG:
                case PropertyType.DOUBLE:
                case PropertyType.NAME:
                case PropertyType.PATH:
                case PropertyType.REFERENCE:
                case PropertyType.BOOLEAN:
                case PropertyType.UNDEFINED:
                case PropertyType.WEAKREFERENCE:
                case PropertyType.DECIMAL:
                case PropertyType.URI:
                    // success
                    break;
                default:
                    fail("getRequiredType() returns an " + "invalid PropertyType.");
            }
        }
    }
}
Also used : NodeType(javax.jcr.nodetype.NodeType) NodeTypeIterator(javax.jcr.nodetype.NodeTypeIterator) PropertyDefinition(javax.jcr.nodetype.PropertyDefinition)

Example 19 with NodeTypeIterator

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

the class PropertyDefTest method testGetDefaultValues.

/**
     * Tests if single-valued properties do have not more than one default
     * value.
     * <p>
     * The test runs for all default values of all properties of all available
     * node types.
     */
public void testGetDefaultValues() throws RepositoryException {
    NodeTypeIterator types = manager.getAllNodeTypes();
    // loop all node types
    while (types.hasNext()) {
        NodeType type = types.nextNodeType();
        PropertyDefinition[] defs = type.getPropertyDefinitions();
        for (int i = 0; i < defs.length; i++) {
            PropertyDefinition def = defs[i];
            Value[] values = def.getDefaultValues();
            if (values != null) {
                for (int j = 0; j < values.length; j++) {
                    if (!def.isMultiple()) {
                        assertEquals("Single-valued property " + type.getName() + "/" + def.getName() + " must not have more than one default value.", 1, values.length);
                    }
                }
            }
        }
    }
}
Also used : NodeType(javax.jcr.nodetype.NodeType) Value(javax.jcr.Value) NodeTypeIterator(javax.jcr.nodetype.NodeTypeIterator) PropertyDefinition(javax.jcr.nodetype.PropertyDefinition)

Example 20 with NodeTypeIterator

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

the class NodeTypeTest method testIsNodeTypeQName.

/**
     * Like {@link #testIsNodeType()}, but using qualified names
     */
public void testIsNodeTypeQName() throws RepositoryException {
    // find a primary node type but not "nt:base"
    NodeTypeIterator types = manager.getPrimaryNodeTypes();
    while (types.hasNext()) {
        NodeType type = types.nextNodeType();
        String typename = type.getName();
        String ns = session.getNamespaceURI(AbstractJCRTest.getPrefix(typename));
        if (ns.length() != 0 && !ns.contains(":")) {
            log.warn("Node type '" + typename + "' has invalid namespace '" + ns + "', thus skipping testIsNodeTypeQName() for this type");
        } else {
            String qn = AbstractJCRTest.getQualifiedName(session, typename);
            assertTrue("isNodeType(String nodeTypeName) must return true if " + "NodeType is nodeTypeName", type.isNodeType(qn));
        }
        if (type.isMixin()) {
            assertFalse("isNodeType(String nodeTypeName) must return " + "false if NodeType is not a subtype of " + "nodeTypeName", type.isNodeType(NodeType.NT_BASE));
        } else {
            assertTrue("isNodeType(String nodeTypeName) must return true if " + "NodeType is a subtype of nodeTypeName", type.isNodeType(NodeType.NT_BASE));
        }
    }
}
Also used : NodeType(javax.jcr.nodetype.NodeType) NodeTypeIterator(javax.jcr.nodetype.NodeTypeIterator)

Aggregations

NodeTypeIterator (javax.jcr.nodetype.NodeTypeIterator)65 NodeType (javax.jcr.nodetype.NodeType)53 NodeTypeManager (javax.jcr.nodetype.NodeTypeManager)28 PropertyDefinition (javax.jcr.nodetype.PropertyDefinition)15 NodeDefinition (javax.jcr.nodetype.NodeDefinition)13 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)11 Node (javax.jcr.Node)9 RepositoryException (javax.jcr.RepositoryException)9 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)8 ArrayList (java.util.ArrayList)6 Session (javax.jcr.Session)6 HashSet (java.util.HashSet)4 Value (javax.jcr.Value)3 QueryObjectModel (javax.jcr.query.qom.QueryObjectModel)3 NodeTypeIteratorAdapter (org.apache.jackrabbit.commons.iterator.NodeTypeIteratorAdapter)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IOException (java.io.IOException)2 PrintWriter (java.io.PrintWriter)2 StringWriter (java.io.StringWriter)2 Property (javax.jcr.Property)2