jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r155900 [2/2] - in incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit: init/ test/ test/api/ test/api/nodetype/ test/api/query/ test/api/version/
Date Wed, 02 Mar 2005 09:07:11 GMT
Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/nodetype/NodeTypeTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/nodetype/NodeTypeTest.java?view=auto&rev=155900
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/nodetype/NodeTypeTest.java
(added)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/nodetype/NodeTypeTest.java
Wed Mar  2 01:06:54 2005
@@ -0,0 +1,409 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.test.api.nodetype;
+
+import org.apache.jackrabbit.test.AbstractJCRTest;
+import org.apache.jackrabbit.test.NotExecutableException;
+
+import javax.jcr.Session;
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.jcr.ItemNotFoundException;
+import javax.jcr.NodeIterator;
+import javax.jcr.nodetype.NodeTypeManager;
+import javax.jcr.nodetype.NodeType;
+import javax.jcr.nodetype.NodeTypeIterator;
+import javax.jcr.nodetype.PropertyDef;
+import javax.jcr.nodetype.NodeDef;
+
+/**
+ * Tests if the node type hierarchy is correctly mapped to the methods
+ * defined in {@link NodeType}.
+ *
+ * @test
+ * @sources NodeTypeTest.java
+ * @executeClass org.apache.jackrabbit.test.api.NodeTypeTest
+ * @keywords level1
+ */
+public class NodeTypeTest extends AbstractJCRTest {
+
+    /**
+     * The session we use for the tests
+     */
+    private Session session;
+
+    /**
+     * The node type manager of the session
+     */
+    private NodeTypeManager manager;
+
+    /**
+     * The root node of the default workspace
+     */
+    private Node rootNode;
+
+    /**
+     * Sets up the fixture for the test cases.
+     */
+    protected void setUp() throws Exception {
+        isReadOnly = true;
+        super.setUp();
+
+        session = helper.getReadOnlySession();
+        manager = session.getWorkspace().getNodeTypeManager();
+        rootNode = session.getRootNode();
+    }
+
+    /**
+     * Releases the session aquired in {@link #setUp()}.
+     */
+    protected void tearDown() throws Exception {
+        if (session != null) {
+            session.logout();
+        }
+        super.tearDown();
+    }
+
+    /**
+     * Test if getNode() returns the name of a node type.
+     */
+    public void testGetName() throws RepositoryException {
+        NodeType type = manager.getNodeType(ntBase);
+        assertEquals("getName() must return the name of the node",
+                ntBase, type.getName());
+    }
+
+    /**
+     * Test if isMixin() returns false if applied on a primary node type and true
+     * on a mixin node type.
+     */
+    public void testIsMixin() throws RepositoryException {
+
+        NodeTypeIterator primaryTypes = manager.getPrimaryNodeTypes();
+        assertFalse("testIsMixin() must return false if applied on a " +
+                "primary node type",
+                primaryTypes.nextNodeType().isMixin());
+
+        // if a mixin node type exist, test if isMixin() returns true
+        NodeTypeIterator mixinTypes = manager.getMixinNodeTypes();
+        if (getSize(mixinTypes) > 0) {
+            // need to re-aquire iterator {@link #getSize} may consume iterator
+            mixinTypes = manager.getMixinNodeTypes();
+            assertTrue("testIsMixin() must return true if applied on a " +
+                    "mixin node type",
+                    mixinTypes.nextNodeType().isMixin());
+        }
+        // else skip the test for mixin node types
+    }
+
+    /**
+     * Test if node.getPrimaryItemName() returns the same name as
+     * node.getPrimaryItem().getName()
+     */
+    public void testGetPrimaryItemName()
+            throws NotExecutableException, RepositoryException {
+
+        Node node = locateNodeWithPrimaryItem(rootNode);
+
+        if (node == null) {
+            throw new NotExecutableException("Workspace does not contain a node with primary
item defined");
+        }
+
+        String name = node.getPrimaryItem().getName();
+        NodeType type = node.getPrimaryNodeType();
+
+        assertEquals("node.getPrimaryNodeType().getPrimaryItemName() " +
+                "must return the same name as " +
+                "node.getPrimaryItem().getName()",
+                name, type.getPrimaryItemName());
+    }
+
+    /**
+     * Test if node.getPrimaryItemName() returns null if no primary item is
+     * defined
+     */
+    public void testGetPrimaryItemNameNotExisting()
+            throws NotExecutableException, RepositoryException {
+
+        Node node = locateNodeWithoutPrimaryItem(rootNode);
+
+        if (node == null) {
+            throw new NotExecutableException("Workspace does not contain a node without primary
item defined");
+        }
+
+        NodeType type = node.getPrimaryNodeType();
+
+        assertNull("getPrimaryItemName() must return null if NodeType " +
+                "does not define a primary item",
+                type.getPrimaryItemName());
+    }
+
+
+    /**
+     * Test if getSupertypes() of a primary node that is not "nt:base" returns at
+     * least "nt:base". NotExecutableException is thrown if no primary node type
+     * apart from "nt:base".
+     */
+    public void testGetSupertypes()
+            throws NotExecutableException, RepositoryException {
+
+        // find a primary node type but not "nt:base"
+        NodeTypeIterator types = manager.getPrimaryNodeTypes();
+        NodeType type = null;
+        while (types.hasNext()) {
+            type = types.nextNodeType();
+            if (!type.getName().equals(ntBase)) {
+                break;
+            }
+        }
+
+        // note: type is never null, since at least "nt:base" must exist
+        if (type.getName().equals("nt:base")) {
+            throw new NotExecutableException("Workspace does not have sufficient primary
node types to run " +
+                    "this test. At least nt:base plus anther type are required.");
+        }
+
+        NodeType supertypes[] = type.getSupertypes();
+        boolean hasNTBase = false;
+        for (int i = 0; i < supertypes.length; i++) {
+            if (supertypes[i].getName().equals(ntBase)) {
+                hasNTBase = true;
+                break;
+            }
+        }
+        assertTrue("getSupertypes() of a primary node type that is not " +
+                "\"nt:base\" must at least return \"nt:base\"",
+                hasNTBase);
+    }
+
+    /**
+     * Test if all node types returned by getDeclatedSupertypes() are also
+     * returned by getSupertypes(). All existing node types are tested.
+     */
+    public void testGetDeclaredSupertypes()
+            throws RepositoryException {
+
+        NodeTypeIterator types = manager.getAllNodeTypes();
+        while (types.hasNext()) {
+            NodeType type = types.nextNodeType();
+
+            NodeType declaredSupertypes[] = type.getDeclaredSupertypes();
+            NodeType supertypes[] = type.getSupertypes();
+
+            try {
+                for (int i = 0; i < declaredSupertypes.length; i++) {
+                    boolean exists = false;
+                    for (int j = 0; j < supertypes.length; j++) {
+                        if (supertypes[j].getName().equals(declaredSupertypes[i].getName()))
{
+                            exists = true;
+                            break;
+                        }
+                    }
+                    assertTrue("All node types returned by " +
+                            "getDeclaredSupertypes() must also be " +
+                            "returned by getSupertypes()",
+                            exists);
+                }
+            } catch (ArrayIndexOutOfBoundsException e) {
+                fail("The array returned by " +
+                        "getDeclaredSupertypes() must not exceed " +
+                        "the one returned by getSupertypes()");
+            }
+        }
+    }
+
+    /**
+     * Test if isNodeType(String nodeTypeName) returns true if nodeTypeName is
+     * the name of the node itself. Also, primary node types must return true if
+     * nodeTypeName is "nt:base", and mixin node types must return false in that
+     * case.
+     */
+    public void testIsNodeType()
+            throws RepositoryException {
+
+        // find a primary node type but not "nt:base"
+        NodeTypeIterator types = manager.getPrimaryNodeTypes();
+        while (types.hasNext()) {
+            NodeType type = types.nextNodeType();
+            assertTrue("isNodeType(String nodeTypeName) must return true if " +
+                    "NodeType is nodeTypeName",
+                    type.isNodeType(type.getName()));
+            if (type.isMixin()) {
+                assertFalse("isNodeType(String nodeTypeName) must return " +
+                        "false if NodeType is not a subtype of " +
+                        "nodeTypeName",
+                        type.isNodeType(ntBase));
+            } else {
+                assertTrue("isNodeType(String nodeTypeName) must return true if " +
+                        "NodeType is a subtype of nodeTypeName",
+                        type.isNodeType(ntBase));
+            }
+        }
+    }
+
+    /**
+     * Test if all property defs returned by getDeclatedPropertyDefs() are also
+     * returned by getPropertyDefs(). All existing node types are tested.
+     */
+    public void testGetDeclaredPropertyDefs()
+            throws RepositoryException {
+
+        NodeTypeIterator types = manager.getAllNodeTypes();
+        while (types.hasNext()) {
+            NodeType type = types.nextNodeType();
+
+            PropertyDef declaredDefs[] = type.getDeclaredPropertyDefs();
+            PropertyDef defs[] = type.getPropertyDefs();
+
+            try {
+                for (int i = 0; i < declaredDefs.length; i++) {
+                    boolean exists = false;
+                    for (int j = 0; j < defs.length; j++) {
+                        if (defs[j].getName().equals(declaredDefs[i].getName())) {
+                            exists = true;
+                            break;
+                        }
+                    }
+                    assertTrue("All property defs returned by " +
+                            "getDeclaredPropertyDefs() must also be " +
+                            "returned by getPropertyDefs()",
+                            exists);
+                }
+            } catch (ArrayIndexOutOfBoundsException e) {
+                fail("The array returned by " +
+                        "getDeclaredPropertyDefs() must not exceed " +
+                        "the one returned by getPropertyDefs()");
+            }
+        }
+    }
+
+    /**
+     * Test if getPropertyDefs() of a primary node returns also "jcr:primaryType"
+     * which is inherited from "nt:base".
+     */
+    public void testGetPropertyDefs()
+            throws NotExecutableException, RepositoryException {
+
+        // find a primary node type but not "nt:base"
+        NodeTypeIterator types = manager.getPrimaryNodeTypes();
+        while (types.hasNext()) {
+            NodeType type = types.nextNodeType();
+            PropertyDef defs[] = type.getPropertyDefs();
+            boolean hasJCRPrimaryType = false;
+            for (int i = 0; i < defs.length; i++) {
+                if (defs[i].getName().equals(jcrPrimaryType)) {
+                    hasJCRPrimaryType = true;
+                    break;
+                }
+            }
+            assertTrue("getPropertyDefs() of a primary node type " +
+                    "must return also \"jcr:primaryType\".",
+                    hasJCRPrimaryType);
+        }
+    }
+
+    /**
+     * Test if all node defs returned by getDeclaredChildNodeDefs() are also
+     * returned by getChildNodeDefs(). All existing node types are tested.
+     */
+    public void testGetDeclaredChildNodeDefs()
+            throws RepositoryException {
+
+        NodeTypeIterator types = manager.getAllNodeTypes();
+        while (types.hasNext()) {
+            NodeType type = types.nextNodeType();
+
+            NodeDef declaredDefs[] = type.getDeclaredChildNodeDefs();
+            NodeDef defs[] = type.getChildNodeDefs();
+
+            try {
+                for (int i = 0; i < declaredDefs.length; i++) {
+                    boolean exists = false;
+                    for (int j = 0; j < defs.length; j++) {
+                        if (defs[j].getName().equals(declaredDefs[i].getName())) {
+                            exists = true;
+                            break;
+                        }
+                    }
+                    assertTrue("All node defs returned by " +
+                            "getDeclaredChildNodeDefs() must also be " +
+                            "returned by getChildNodeDefs().",
+                            exists);
+                }
+            } catch (ArrayIndexOutOfBoundsException e) {
+                fail("The array returned by " +
+                        "getDeclaredChildNodeDefs() must not exceed " +
+                        "the one returned by getChildNodeDefs()");
+            }
+        }
+    }
+
+    //-----------------------< internal >---------------------------------------
+
+    /**
+     * Returns the first descendant of <code>node</code> which defines primary
+     * item
+     *
+     * @param node <code>Node</code> to start traversal.
+     * @return first node with primary item
+     */
+    private Node locateNodeWithPrimaryItem(Node node)
+            throws RepositoryException {
+
+        try {
+            node.getPrimaryItem();
+            return node;
+        } catch (ItemNotFoundException e) {
+
+        }
+
+        NodeIterator nodes = node.getNodes();
+        while (nodes.hasNext()) {
+            Node returnedNode = locateNodeWithPrimaryItem(nodes.nextNode());
+            if (returnedNode != null) {
+                return returnedNode;
+            }
+        }
+        return null;
+    }
+
+    /**
+     * Returns the first descendant of <code>node</code> without a primary item
+     *
+     * @param node
+     * @return first node without primary item
+     */
+    private Node locateNodeWithoutPrimaryItem(Node node)
+            throws RepositoryException {
+
+        try {
+            node.getPrimaryItem();
+        } catch (ItemNotFoundException e) {
+            return node;
+        }
+
+        NodeIterator nodes = node.getNodes();
+        while (nodes.hasNext()) {
+            Node returnedNode = this.locateNodeWithoutPrimaryItem(nodes.nextNode());
+            if (returnedNode != null) {
+                return returnedNode;
+            }
+        }
+        return null;
+    }
+
+}
\ No newline at end of file

Propchange: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/nodetype/NodeTypeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/nodetype/PropertyDefTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/nodetype/PropertyDefTest.java?view=auto&rev=155900
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/nodetype/PropertyDefTest.java
(added)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/nodetype/PropertyDefTest.java
Wed Mar  2 01:06:54 2005
@@ -0,0 +1,400 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.test.api.nodetype;
+
+import org.apache.jackrabbit.test.AbstractJCRTest;
+import org.apache.jackrabbit.test.NotExecutableException;
+import org.apache.jackrabbit.test.api.PropertyUtil;
+
+import javax.jcr.Session;
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.jcr.PropertyType;
+import javax.jcr.Value;
+import javax.jcr.NodeIterator;
+import javax.jcr.Property;
+import javax.jcr.PathNotFoundException;
+import javax.jcr.nodetype.NodeTypeManager;
+import javax.jcr.nodetype.NodeTypeIterator;
+import javax.jcr.nodetype.NodeType;
+import javax.jcr.nodetype.PropertyDef;
+import java.util.regex.Pattern;
+import java.util.regex.Matcher;
+
+/**
+ * Tests if property definitions are properly defined.
+ *
+ * @test
+ * @sources PropertyDefTest.java
+ * @executeClass org.apache.jackrabbit.test.api.PropertyDefTest
+ * @keywords level1
+ */
+public class PropertyDefTest extends AbstractJCRTest {
+
+    // format: '(<min>, <max>)',  '[<min>, <max>]', '(, <max>)'
etc.
+    private static final Pattern CONSTRAINTSPATTERN_BINARY =
+            Pattern.compile("([\\(\\[]) *\\d* *, *\\d* *([\\)\\]])");
+
+    // format: '(<min>, <max>)',  '[<min>, <max>]', '(, <max>)'
etc.
+    private static final Pattern CONSTRAINTSPATTERN_LONG =
+            Pattern.compile("([\\(\\[]) *(\\-?\\d*)? *, *(\\-?\\d*)? *([\\)\\]])");
+
+    // format: '(<min>, <max>)',  '[<min>, <max>]', '(, <max>)'
etc.
+    private static final Pattern CONSTRAINTSPATTERN_DOUBLE =
+            Pattern.compile("([\\(\\[]) *(\\-?\\d+\\.?\\d*)? *, *(\\-?\\d+\\.?\\d*)? *([\\)\\]])");
+
+    // format: '(<min>, <max>)',  '[<min>, <max>]', '(, <max>)'
etc.
+    private static final Pattern CONSTRAINTSPATTERN_DATE =
+            Pattern.compile("([\\(\\[]) *(" + PropertyUtil.PATTERNSTRING_DATE + ")? *, *"
+
+            "(" + PropertyUtil.PATTERNSTRING_DATE + ")? *([\\)\\]])");
+
+    private static final Pattern CONSTRAINTSPATTERN_PATH =
+            Pattern.compile(PropertyUtil.PATTERNSTRING_PATH_WITHOUT_LAST_SLASH +
+            "(/|/\\*)?");
+
+    /**
+     * The session we use for the tests
+     */
+    private Session session;
+
+    /**
+     * The node type manager of the session
+     */
+    private NodeTypeManager manager;
+
+    /**
+     * The root node of the default workspace
+     */
+    private Node rootNode;
+
+    /**
+     * If <code>true</code> indicates that the test found a mandatory property
+     */
+    private boolean foundMandatoryProperty = false;
+
+    /**
+     * Sets up the fixture for the test cases.
+     */
+    protected void setUp() throws Exception {
+        isReadOnly = true;
+        super.setUp();
+
+        session = helper.getReadOnlySession();
+        manager = session.getWorkspace().getNodeTypeManager();
+        rootNode = session.getRootNode();
+    }
+
+    /**
+     * Releases the session aquired in {@link #setUp()}.
+     */
+    protected void tearDown() throws Exception {
+        if (session != null) {
+            session.logout();
+        }
+        super.tearDown();
+    }
+
+    /**
+     * 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();
+            PropertyDef defsOfCurrentType[] =
+                    currentType.getPropertyDefs();
+
+            // loop all property defs of each node type
+            for (int i = 0; i < defsOfCurrentType.length; i++) {
+                PropertyDef def = defsOfCurrentType[i];
+                NodeType type = def.getDeclaringNodeType();
+
+                // check if def is part of the property defs of the
+                // declaring node type
+                PropertyDef defs[] = type.getPropertyDefs();
+                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);
+            }
+        }
+    }
+
+    /**
+     * 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();
+            PropertyDef defs[] = type.getPropertyDefs();
+            for (int i = 0; i < defs.length; i++) {
+                if (defs[i].isAutoCreate()) {
+                    assertFalse("An auto create property must not be a " +
+                            "residual set definition.",
+                            defs[i].getName().equals("*"));
+                }
+            }
+        }
+    }
+
+    /**
+     * This test checks if item definitions with mandatory constraints are
+     * respected.
+     * <p/>
+     * If the default workspace does not contain a node with a node type
+     * definition that specifies a mandatory property a {@link
+     * org.apache.jackrabbit.test.NotExecutableException} is thrown.
+     */
+    public void testIsMandatory() throws RepositoryException, NotExecutableException {
+        traverse(rootNode);
+        if (!foundMandatoryProperty) {
+            throw new NotExecutableException("Workspace does not contain any node with a
mandatory property definition");
+        }
+    }
+
+    /**
+     * 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();
+            PropertyDef defs[] = type.getPropertyDefs();
+            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:
+                        // success
+                        break;
+                    default:
+                        fail("getRequiredType() returns an " +
+                                "invalid PropertyType.");
+                }
+            }
+        }
+    }
+
+    /**
+     * Tests if value constraints match the pattern specified by the required
+     * property type. </p> The test runs for all value constraints of all
+     * properties of all available node types.
+     */
+    public void testGetValueConstraints() throws RepositoryException {
+
+        NodeTypeIterator types = manager.getAllNodeTypes();
+        // loop all node types
+        while (types.hasNext()) {
+            NodeType type = types.nextNodeType();
+            PropertyDef defs[] = type.getPropertyDefs();
+            for (int i = 0; i < defs.length; i++) {
+                PropertyDef def = defs[i];
+
+                String constraints[] = def.getValueConstraints();
+                if (constraints != null) {
+
+                    for (int j = 0; j < constraints.length; j++) {
+                        Matcher matcher;
+
+                        switch (defs[i].getRequiredType()) {
+                            case PropertyType.STRING:
+                            case PropertyType.UNDEFINED:
+                                // any value matches
+                                break;
+
+                            case PropertyType.BINARY:
+                                matcher =
+                                        CONSTRAINTSPATTERN_BINARY.matcher(constraints[j]);
+                                assertTrue("Value constraint does not match " +
+                                        "the pattern of PropertyType.BINARY ",
+                                        matcher.matches());
+                                break;
+
+                            case PropertyType.DATE:
+                                matcher =
+                                        CONSTRAINTSPATTERN_DATE.matcher(constraints[j]);
+                                assertTrue("Value constraint does not match " +
+                                        "the pattern of PropertyType.DATE ",
+                                        matcher.matches());
+                                break;
+
+                            case PropertyType.LONG:
+                                matcher =
+                                        CONSTRAINTSPATTERN_LONG.matcher(constraints[j]);
+                                assertTrue("Value constraint does not match " +
+                                        "the pattern of PropertyType.LONG",
+                                        matcher.matches());
+                                break;
+
+                            case PropertyType.DOUBLE:
+                                matcher =
+                                        CONSTRAINTSPATTERN_DOUBLE.matcher(constraints[j]);
+                                assertTrue("Value constraint does not match " +
+                                        "the pattern of PropertyType.DOUBLE",
+                                        matcher.matches());
+                                break;
+
+                            case PropertyType.NAME:
+                                matcher =
+                                        PropertyUtil.PATTERN_NAME.matcher(constraints[j]);
+                                assertTrue("Value constraint does not match " +
+                                        "the pattern of PropertyType.NAME",
+                                        matcher.matches());
+                                break;
+
+                            case PropertyType.PATH:
+                                matcher = CONSTRAINTSPATTERN_PATH.matcher(constraints[j]);
+                                assertTrue("Value constraint does not match " +
+                                        "the pattern of PropertyType.PATH",
+                                        matcher.matches());
+                                break;
+
+                            case PropertyType.REFERENCE:
+                                matcher =
+                                        PropertyUtil.PATTERN_NAME.matcher(constraints[j]);
+                                assertTrue("Value constraint does not match " +
+                                        "the pattern of PropertyType.REFERENCE",
+                                        matcher.matches());
+                                break;
+
+                            case PropertyType.BOOLEAN:
+                                assertTrue("Value constraint does not match " +
+                                        "the pattern of PropertyType.BOOLEAN",
+                                        constraints[j].equals("true") ||
+                                        constraints[j].equals("false"));
+                                break;
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+    /**
+     * 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();
+            PropertyDef defs[] = type.getPropertyDefs();
+            for (int i = 0; i < defs.length; i++) {
+                PropertyDef def = defs[i];
+
+                Value values[] = def.getDefaultValues();
+                if (values != null) {
+
+                    for (int j = 0; j < values.length; j++) {
+
+                        if (!def.isMultiple()) {
+                            assertEquals("Single-valued properties must not " +
+                                    "have more than one default value.",
+                                    1, values.length);
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+    /**
+     * Traverses the node hierarchy and applies
+     * {@link #checkMandatoryConstraint(javax.jcr.Node, javax.jcr.nodetype.NodeType)}
+     * to all descendant nodes of <code>parentNode</code>.
+     */
+    private void traverse(Node parentNode)
+            throws RepositoryException {
+
+        NodeIterator nodes = parentNode.getNodes();
+        while (nodes.hasNext()) {
+            Node node = nodes.nextNode();
+
+            NodeType primeType = node.getPrimaryNodeType();
+            checkMandatoryConstraint(node, primeType);
+
+            NodeType mixins[] = node.getMixinNodeTypes();
+            for (int i = 0; i < mixins.length; i++) {
+                checkMandatoryConstraint(node, mixins[i]);
+            }
+
+            traverse(node);
+        }
+    }
+
+    /**
+     * Checks if mandatory property definitions are respected.
+     */
+    private void checkMandatoryConstraint(Node node, NodeType type)
+            throws RepositoryException {
+
+        // test if node contains all mandatory properties of current type
+        PropertyDef propDefs[] = type.getPropertyDefs();
+        for (int i = 0; i < propDefs.length; i++) {
+            PropertyDef propDef = propDefs[i];
+
+            if (propDef.isMandatory()) {
+                foundMandatoryProperty = true;
+                String name = propDef.getName();
+
+                try {
+                    Property p = node.getProperty(name);
+                    if (propDef.isMultiple()) {
+                        // empty array fails
+                        assertFalse("A mandatory and multiple property " +
+                                "must not be empty.",
+                                p.getValues().length == 0);
+                    } else {
+                        // empty value fails
+                        assertNotNull("A mandatory property must have a value",
+                                p.getValue());
+                    }
+                } catch (PathNotFoundException e) {
+                    fail("Mandatory property " + name + " does not exist.");
+                }
+            }
+        }
+    }
+}
\ No newline at end of file

Propchange: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/nodetype/PropertyDefTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/nodetype/TestAll.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/nodetype/TestAll.java?view=diff&r1=155899&r2=155900
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/nodetype/TestAll.java
(original)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/nodetype/TestAll.java
Wed Mar  2 01:06:54 2005
@@ -37,6 +37,10 @@
         TestSuite suite = new TestSuite("javax.jcr.nodetype tests");
 
         // ADD TEST CLASSES HERE:
+        suite.addTestSuite(NodeDefTest.class);
+        suite.addTestSuite(NodeTypeManagerTest.class);
+        suite.addTestSuite(NodeTypeTest.class);
+        suite.addTestSuite(PropertyDefTest.class);
 
         return suite;
     }

Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/AbstractQueryTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/AbstractQueryTest.java?view=diff&r1=155899&r2=155900
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/AbstractQueryTest.java
(original)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/AbstractQueryTest.java
Wed Mar  2 01:06:54 2005
@@ -197,9 +197,11 @@
                                        boolean descending)
             throws RepositoryException, NotExecutableException {
         RowIterator rows = queryResult.getRows();
-        if (rows.getSize() < 2) {
+        if (getSize(rows) < 2) {
             throw new NotExecutableException("Can not test ordering on less than 2 results");
         }
+        // need to re-aquire rows, {@link #getSize} may consume elements.
+        rows = queryResult.getRows();
         int changeCnt = 0;
         String last = "";
         while (rows.hasNext()) {

Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/SQLQueryLevel2Test.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/SQLQueryLevel2Test.java?view=diff&r1=155899&r2=155900
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/SQLQueryLevel2Test.java
(original)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/SQLQueryLevel2Test.java
Wed Mar  2 01:06:54 2005
@@ -123,9 +123,11 @@
         setUpFullTextTest();
         QueryResult result = execute(getFullTextStatement());
         RowIterator rows = result.getRows();
-        if (rows.getSize() < 1) {
+        if (getSize(rows) < 1) {
             fail("Query result did not return any nodes");
         }
+        // re-aquire rows
+        rows = result.getRows();
 
         // test mere existence
         rows.nextRow().getValue(jcrPath);

Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/XPathQueryLevel2Test.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/XPathQueryLevel2Test.java?view=diff&r1=155899&r2=155900
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/XPathQueryLevel2Test.java
(original)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/XPathQueryLevel2Test.java
Wed Mar  2 01:06:54 2005
@@ -122,9 +122,12 @@
         setUpFullTextTest();
         QueryResult result = execute(getFullTextStatement());
         RowIterator rows = result.getRows();
-        if (rows.getSize() < 1) {
+        if (getSize(rows) < 1) {
             fail("Query result did not return any nodes");
         }
+        // re-aquire rows
+        rows = result.getRows();
+
         // test mere existence
         rows.nextRow().getValue(jcrPath);
     }

Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/version/AbstractVersionTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/version/AbstractVersionTest.java?view=diff&r1=155899&r2=155900
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/version/AbstractVersionTest.java
(original)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/version/AbstractVersionTest.java
Wed Mar  2 01:06:54 2005
@@ -24,7 +24,6 @@
 import javax.jcr.Node;
 import javax.jcr.RepositoryException;
 import javax.jcr.version.VersionHistory;
-import javax.jcr.version.VersionIterator;
 
 /**
  * <code>AbstractVersionTest</code> is the abstract base class for all
@@ -115,16 +114,7 @@
      * @throws RepositoryException
      */
     protected long getNumberOfVersions(VersionHistory vHistory) throws RepositoryException
{
-        VersionIterator vIter = vHistory.getAllVersions();
-        long numOfVersions = vIter.getSize();
-        if (numOfVersions == -1) {
-            numOfVersions = 0;
-            while (vIter.hasNext()) {
-                vIter.nextVersion();
-                numOfVersions++;
-            }
-        }
-        return numOfVersions;
+        return getSize(vHistory.getAllVersions());
     }
 
     /**



Mime
View raw message