Return-Path: Delivered-To: apmail-jackrabbit-commits-archive@www.apache.org Received: (qmail 30687 invoked from network); 5 Feb 2009 13:25:51 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 5 Feb 2009 13:25:51 -0000 Received: (qmail 21019 invoked by uid 500); 5 Feb 2009 13:25:51 -0000 Delivered-To: apmail-jackrabbit-commits-archive@jackrabbit.apache.org Received: (qmail 20924 invoked by uid 500); 5 Feb 2009 13:25:50 -0000 Mailing-List: contact commits-help@jackrabbit.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@jackrabbit.apache.org Delivered-To: mailing list commits@jackrabbit.apache.org Received: (qmail 20915 invoked by uid 99); 5 Feb 2009 13:25:50 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 05 Feb 2009 05:25:50 -0800 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 05 Feb 2009 13:25:41 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 97DB3238896B; Thu, 5 Feb 2009 13:25:21 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@jackrabbit.apache.org From: angela@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090205132521.97DB3238896B@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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; + +/** + * NodeTypesInContentTest... + */ +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 JCR-1964 + * + * @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 Test suite that executes all tests inside this + * package. + * + * @return a Test 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. */ --> - + requiredType="String" autoCreated="true" mandatory="false" + onParentVersion="IGNORE" protected="false" multiple="false"> + + "defvalue" + + + @@ -144,7 +149,7 @@ requiredType="Reference" autoCreated="false" mandatory="false" onParentVersion="IGNORE" protected="false" multiple="false"> - test:testType + nt:base - test:baseType - test:testType + nt:base + nt:unstructured