jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r741100 - in /jackrabbit/trunk/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/nodetype/virtual/ test/java/org/apache/jackrabbit/core/nodetype/ test/java/org/apache/jackrabbit/core/nodetype/xml/ test/resources/org/apache/jackrabbi...
Date Thu, 05 Feb 2009 13:25:20 GMT
Author: angela
Date: Thu Feb  5 13:25:20 2009
New Revision: 741100

URL: http://svn.apache.org/viewvc?rev=741100&view=rev
Log:
JCR-1964: VirtualNodeTypeStateProvider creates PropertyState with type != value(s).getType
JCR-1969: Invalid node type definitions with test_nodetypes.xml

Added:
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/nodetype/NodeTypesInContentTest.java
  (with props)
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/nodetype/TestAll.java
  (with props)
Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/virtual/VirtualNodeTypeStateProvider.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/nodetype/xml/TestAll.java
    jackrabbit/trunk/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/nodetype/xml/test_nodetypes.xml

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/virtual/VirtualNodeTypeStateProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/virtual/VirtualNodeTypeStateProvider.java?rev=741100&r1=741099&r2=741100&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/virtual/VirtualNodeTypeStateProvider.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/virtual/VirtualNodeTypeStateProvider.java
Thu Feb  5 13:25:20 2009
@@ -219,7 +219,16 @@
         pState.setPropertyValue(
                 NameConstants.JCR_REQUIREDTYPE,
                 InternalValue.create(PropertyType.nameFromValue(propDef.getRequiredType()).toUpperCase()));
-        pState.setPropertyValues(NameConstants.JCR_DEFAULTVALUES, PropertyType.STRING, propDef.getDefaultValues());
+        InternalValue[] defVals = propDef.getDefaultValues();
+        // retrieve the property type from the first default value present with
+        // the property definition. in case no default values are defined,
+        // fallback to PropertyType.STRING in order to avoid creating a property
+        // with type UNDEFINED which is illegal.
+        int defValsType = PropertyType.STRING;
+        if (defVals != null && defVals.length > 0) {
+            defValsType = defVals[0].getType();
+        }
+        pState.setPropertyValues(NameConstants.JCR_DEFAULTVALUES, defValsType, defVals);
         ValueConstraint[] vc = propDef.getValueConstraints();
         InternalValue[] vals = new InternalValue[vc.length];
         for (int i = 0; i < vc.length; i++) {

Added: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/nodetype/NodeTypesInContentTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/nodetype/NodeTypesInContentTest.java?rev=741100&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/nodetype/NodeTypesInContentTest.java
(added)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/nodetype/NodeTypesInContentTest.java
Thu Feb  5 13:25:20 2009
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.core.nodetype;
+
+import org.apache.jackrabbit.test.AbstractJCRTest;
+import org.apache.jackrabbit.core.SessionImpl;
+import org.apache.jackrabbit.core.nodetype.xml.NodeTypeReader;
+import org.apache.jackrabbit.JcrConstants;
+
+import javax.jcr.ItemVisitor;
+import javax.jcr.Property;
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+import javax.jcr.Node;
+import javax.jcr.util.TraversingItemVisitor;
+import java.io.InputStream;
+import java.util.Arrays;
+
+/**
+ * <code>NodeTypesInContentTest</code>...
+ */
+public class NodeTypesInContentTest extends AbstractJCRTest {
+
+    /**
+     * custom node type defs defining non-string default values
+     */
+    private static final String TEST_NODETYPES = "org/apache/jackrabbit/core/nodetype/xml/test_nodetypes.xml";
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        
+        InputStream xml = getClass().getClassLoader().getResourceAsStream(TEST_NODETYPES);
+        NodeTypeDef[] ntDefs = NodeTypeReader.read(xml);
+        NodeTypeRegistry ntReg = ((SessionImpl) superuser).getNodeTypeManager().getNodeTypeRegistry();
+        if (!ntReg.isRegistered(ntDefs[0].getName())) {
+            ntReg.registerNodeTypes(Arrays.asList(ntDefs));
+        }
+    }
+
+    /**
+     * Test for <a href="https://issues.apache.org/jira/browse/JCR-1964">JCR-1964</a>
+     * 
+     * @throws javax.jcr.RepositoryException If an exception occurs.
+     */
+    public void testDefaultValues() throws RepositoryException {
+        ItemVisitor visitor = new TraversingItemVisitor.Default() {
+
+            public void visit(Property property) throws RepositoryException {
+                if (JcrConstants.JCR_DEFAULTVALUES.equals(property.getName())) {
+                    int type = property.getType();
+                    Value[] vs = property.getValues();
+                    for (int i = 0; i < vs.length; i++) {
+                        assertEquals("Property type must match the value(s) type", type,
vs[i].getType());
+                    }
+                }
+            }
+        };
+
+        Node start = (Node) superuser.getItem("/jcr:system/jcr:nodeTypes");
+        visitor.visit(start);
+    }
+}
\ No newline at end of file

Propchange: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/nodetype/NodeTypesInContentTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/nodetype/NodeTypesInContentTest.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url

Added: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/nodetype/TestAll.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/nodetype/TestAll.java?rev=741100&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/nodetype/TestAll.java
(added)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/nodetype/TestAll.java
Thu Feb  5 13:25:20 2009
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.core.nodetype;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * Test suite that includes all testcases for package org.apache.jackrabbit.core.nodetype.
+ */
+public class TestAll extends TestCase {
+
+    /**
+     * Returns a <code>Test</code> suite that executes all tests inside this
+     * package.
+     * 
+     * @return a <code>Test</code> suite that executes all tests inside this
+     * package.
+     */
+    public static Test suite() {
+        TestSuite suite = new TestSuite("org.apache.jackrabbit.core.nodetype tests");
+
+        suite.addTestSuite(NodeTypesInContentTest.class);
+
+        return suite;
+    }
+}

Propchange: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/nodetype/TestAll.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/nodetype/TestAll.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/nodetype/xml/TestAll.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/nodetype/xml/TestAll.java?rev=741100&r1=741099&r2=741100&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/nodetype/xml/TestAll.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/nodetype/xml/TestAll.java
Thu Feb  5 13:25:20 2009
@@ -51,7 +51,7 @@
 public class TestAll extends TestCase {
 
     /** The dummy test namespace. */
-    private static final String TEST_NAMESPACE = "test-namespace";
+    private static final String TEST_NAMESPACE = "http://www.apache.org/jackrabbit/test";
 
     /** Name of the include test node type definition file. */
     private static final String TEST_NODETYPES =
@@ -486,7 +486,7 @@
         assertEquals("referenceProperty valueConstraints",
                 1, def.getValueConstraints().length);
         assertEquals("referenceProperty valueConstraints[0]",
-                "test:testType",
+                "nt:base",
                 (def.getValueConstraints())[0].getDefinition());
         assertEquals("referenceProperty defaultValues",
                 0, def.getDefaultValues().length);
@@ -544,7 +544,7 @@
     public void testDefaultTypeNode() {
         NodeDef def = getChildNode("childNodeType", "defaultTypeNode");
         assertEquals("defaultTypeNode defaultPrimaryType",
-                FACTORY.create(TEST_NAMESPACE, "testType"),
+                FACTORY.create(Name.NS_NT_URI, "base"),
                 def.getDefaultPrimaryType());
     }
 
@@ -556,9 +556,9 @@
         Name[] types = def.getRequiredPrimaryTypes();
         Arrays.sort(types);
         assertEquals("requiredTypeNode requiredPrimaryTypes[0]",
-                FACTORY.create(TEST_NAMESPACE, "baseType"), types[0]);
+                FACTORY.create(Name.NS_NT_URI, "base"), types[0]);
         assertEquals("requiredTypeNode requiredPrimaryTypes[1]",
-                FACTORY.create(TEST_NAMESPACE, "testType"), types[1]);
+                FACTORY.create(Name.NS_NT_URI, "unstructured"), types[1]);
     }
 
     /**

Modified: jackrabbit/trunk/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/nodetype/xml/test_nodetypes.xml
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/nodetype/xml/test_nodetypes.xml?rev=741100&r1=741099&r2=741100&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/nodetype/xml/test_nodetypes.xml
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/nodetype/xml/test_nodetypes.xml
Thu Feb  5 13:25:20 2009
@@ -17,7 +17,7 @@
  * limitations under the License.
  */
  -->
-<nodeTypes xmlns:test="test-namespace"
+<nodeTypes xmlns:test="http://www.apache.org/jackrabbit/test"
            xmlns:nt="http://www.jcp.org/jcr/nt/1.0">
 
   <nodeType name="test:emptyNodeType"
@@ -39,8 +39,13 @@
                  requiredType="undefined" autoCreated="false" mandatory="false"
                  onParentVersion="IGNORE" protected="false" multiple="false"/>
     <propertyDefinition name="test:autoCreatedItem"
-                 requiredType="undefined" autoCreated="true" mandatory="false"
-                 onParentVersion="IGNORE" protected="false" multiple="false"/>
+                 requiredType="String" autoCreated="true" mandatory="false"
+                 onParentVersion="IGNORE" protected="false" multiple="false">
+      <defaultValues>
+        <defaultValue>"defvalue"</defaultValue>
+      </defaultValues>
+    </propertyDefinition>
+
     <propertyDefinition name="test:mandatoryItem"
                  requiredType="undefined" autoCreated="false" mandatory="true"
                  onParentVersion="IGNORE" protected="false" multiple="false"/>
@@ -144,7 +149,7 @@
                  requiredType="Reference" autoCreated="false" mandatory="false"
                  onParentVersion="IGNORE" protected="false" multiple="false">
       <valueConstraints>
-        <valueConstraint>test:testType</valueConstraint>
+        <valueConstraint>nt:base</valueConstraint>
       </valueConstraints>
     </propertyDefinition>
     <propertyDefinition name="test:stringProperty"
@@ -174,7 +179,7 @@
                   autoCreated="false" mandatory="false"
                   onParentVersion="IGNORE" protected="false"/>
     <childNodeDefinition name="test:defaultTypeNode"
-                  defaultPrimaryType="test:testType" sameNameSiblings="false"
+                  defaultPrimaryType="nt:base" sameNameSiblings="false"
                   autoCreated="false" mandatory="false"
                   onParentVersion="IGNORE" protected="false"/>
     <childNodeDefinition name="test:requiredTypeNode"
@@ -182,8 +187,8 @@
                   autoCreated="false" mandatory="false"
                   onParentVersion="IGNORE" protected="false">
       <requiredPrimaryTypes>
-        <requiredPrimaryType>test:baseType</requiredPrimaryType>
-        <requiredPrimaryType>test:testType</requiredPrimaryType>
+        <requiredPrimaryType>nt:base</requiredPrimaryType>
+        <requiredPrimaryType>nt:unstructured</requiredPrimaryType>
       </requiredPrimaryTypes>
     </childNodeDefinition>
   </nodeType>



Mime
View raw message