Index: dna-cnd/src/main/java/org/jboss/dna/cnd/CndImporter.java =================================================================== --- dna-cnd/src/main/java/org/jboss/dna/cnd/CndImporter.java (revision 870) +++ dna-cnd/src/main/java/org/jboss/dna/cnd/CndImporter.java (working copy) @@ -577,6 +577,7 @@ factory.create(JcrLexicon.HAS_ORDERABLE_CHILD_NODES, hasOrderableChildNodes), factory.create(JcrLexicon.IS_MIXIN, isMixin), factory.create(JcrLexicon.IS_QUERYABLE, isQueryable), + factory.create(JcrLexicon.NODE_TYPE_NAME, name), factory.create(JcrLexicon.PRIMARY_ITEM_NAME, primaryItemName)); return path; @@ -599,7 +600,7 @@ // Create the node for the node type ... if (name == null) return null; - Path path = pathFactory().create(parentPath, name); + Path path = pathFactory().create(parentPath, JcrLexicon.PROPERTY_DEFINITION); PropertyFactory factory = context.getPropertyFactory(); destination.create(path, @@ -608,6 +609,7 @@ factory.create(JcrLexicon.DEFAULT_VALUES, (Object[])defaultValues), factory.create(JcrLexicon.MULTIPLE, multiple), factory.create(JcrLexicon.MANDATORY, mandatory), + factory.create(JcrLexicon.NAME, name), factory.create(JcrLexicon.AUTO_CREATED, autoCreated), factory.create(JcrLexicon.PROTECTED, isProtected), factory.create(JcrLexicon.ON_PARENT_VERSION, onParentVersion), @@ -632,7 +634,7 @@ // Create the node for the node type ... if (name == null) return null; - Path path = pathFactory().create(parentPath, name); + Path path = pathFactory().create(parentPath, JcrLexicon.CHILD_NODE_DEFINITION); PropertyFactory factory = context.getPropertyFactory(); destination.create(path, @@ -640,6 +642,7 @@ factory.create(JcrLexicon.REQUIRED_PRIMARY_TYPES, (Object[])requiredPrimaryTypes), factory.create(JcrLexicon.DEFAULT_PRIMARY_TYPE, defaultPrimaryType), factory.create(JcrLexicon.MANDATORY, mandatory), + factory.create(JcrLexicon.NAME, name), factory.create(JcrLexicon.AUTO_CREATED, autoCreated), factory.create(JcrLexicon.PROTECTED, isProtected), factory.create(JcrLexicon.ON_PARENT_VERSION, onParentVersion), Index: dna-graph/src/main/java/org/jboss/dna/graph/JcrLexicon.java =================================================================== --- dna-graph/src/main/java/org/jboss/dna/graph/JcrLexicon.java (revision 870) +++ dna-graph/src/main/java/org/jboss/dna/graph/JcrLexicon.java (working copy) @@ -60,6 +60,7 @@ public static final Name IS_QUERYABLE = new BasicName(Namespace.URI, "isQueryable"); public static final Name MANDATORY = new BasicName(Namespace.URI, "mandatory"); public static final Name MULTIPLE = new BasicName(Namespace.URI, "multiple"); + public static final Name NODE_TYPE_NAME = new BasicName(Namespace.URI, "nodeTypeName"); public static final Name ON_PARENT_VERSION = new BasicName(Namespace.URI, "onParentVersion"); public static final Name PRIMARY_ITEM_NAME = new BasicName(Namespace.URI, "primaryItemName"); public static final Name PROPERTY_DEFINITION = new BasicName(Namespace.URI, "propertyDefinition"); Index: dna-jcr/src/main/java/org/jboss/dna/jcr/CndNodeTypeSource.java =================================================================== --- dna-jcr/src/main/java/org/jboss/dna/jcr/CndNodeTypeSource.java (revision 0) +++ dna-jcr/src/main/java/org/jboss/dna/jcr/CndNodeTypeSource.java (revision 0) @@ -0,0 +1,84 @@ +/* + * JBoss DNA (http://www.jboss.org/dna) + * See the COPYRIGHT.txt file distributed with this work for information + * regarding copyright ownership. Some portions may be licensed + * to Red Hat, Inc. under one or more contributor license agreements. + * See the AUTHORS.txt file in the distribution for a full listing of + * individual contributors. + * + * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA + * is licensed to you under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * JBoss DNA is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.jboss.dna.jcr; + +import java.io.IOException; +import java.io.InputStream; +import org.jboss.dna.cnd.CndImporter; +import org.jboss.dna.common.collection.Problems; +import org.jboss.dna.common.collection.SimpleProblems; +import org.jboss.dna.graph.ExecutionContext; +import org.jboss.dna.graph.Graph; +import org.jboss.dna.graph.connector.inmemory.InMemoryRepositorySource; +import org.jboss.dna.graph.io.Destination; +import org.jboss.dna.graph.io.GraphBatchDestination; +import org.jboss.dna.graph.property.PathFactory; + +public class CndNodeTypeSource implements GraphNodeTypeSource { + + private final ExecutionContext context; + private final Graph graph; + private final Problems problems; + + public CndNodeTypeSource(ExecutionContext context, String resourceName) throws IOException { + this(context, new String[] { resourceName }); + } + + public CndNodeTypeSource(ExecutionContext context, String resourceNames[]) throws IOException { + + this.context = context; + this.problems = new SimpleProblems(); + + PathFactory pathFactory = context.getValueFactories().getPathFactory(); + InMemoryRepositorySource source = new InMemoryRepositorySource(); + source.setName("CND Import Source"); + this.graph = Graph.create(source, context); + Graph.Batch batch = graph.batch(); + Destination destination = new GraphBatchDestination(batch); + CndImporter importer = new CndImporter(destination, pathFactory.createRootPath()); + for (int i = 0; i < resourceNames.length; i++) { + InputStream is = getClass().getResourceAsStream(resourceNames[i]); + importer.importFrom(is, problems, resourceNames[i]); + } + + destination.submit(); + } + + public boolean isValid() { + return !problems.hasErrors(); + } + + public Problems getProblems() { + return problems; + } + + public final Graph getNodeTypes() { + return graph; + } + + public ExecutionContext getExecutionContext() { + return context; + } + +} Property changes on: dna-jcr\src\main\java\org\jboss\dna\jcr\CndNodeTypeSource.java ___________________________________________________________________ Added: svn:keywords + Id Revision Added: svn:eol-style + LF Index: dna-jcr/src/main/java/org/jboss/dna/jcr/DnaBuiltinNodeTypeSource.java =================================================================== --- dna-jcr/src/main/java/org/jboss/dna/jcr/DnaBuiltinNodeTypeSource.java (revision 870) +++ dna-jcr/src/main/java/org/jboss/dna/jcr/DnaBuiltinNodeTypeSource.java (working copy) @@ -31,6 +31,7 @@ import net.jcip.annotations.Immutable; import org.jboss.dna.graph.ExecutionContext; import org.jboss.dna.graph.JcrMixLexicon; +import org.jboss.dna.graph.property.Name; /** * {@link JcrNodeTypeSource} that provides built-in node types provided by DNA. @@ -109,7 +110,7 @@ true, false, DnaLexicon.NAMESPACE, - new JcrNodeType[] {namespace})}), + new Name[] {DnaLexicon.NAMESPACE})}), NO_PROPERTIES, NOT_MIXIN, UNORDERABLE_CHILD_NODES); JcrNodeType dnaNodeTypes = new JcrNodeType( @@ -128,7 +129,7 @@ true, true, JcrNtLexicon.NODE_TYPE, - new JcrNodeType[] {nodeType})}), + new Name[] {JcrNtLexicon.NODE_TYPE})}), NO_PROPERTIES, NOT_MIXIN, UNORDERABLE_CHILD_NODES); JcrNodeType system = new JcrNodeType(context, NO_NODE_TYPE_MANAGER, DnaLexicon.SYSTEM, @@ -137,20 +138,20 @@ new JcrNodeDefinition(context, null, DnaLexicon.NAMESPACES, OnParentVersionBehavior.VERSION.getJcrValue(), true, true, true, false, DnaLexicon.NAMESPACES, - new JcrNodeType[] {namespaces}), + new Name[] {DnaLexicon.NAMESPACES}), new JcrNodeDefinition(context, null, JcrLexicon.NODE_TYPES, OnParentVersionBehavior.VERSION.getJcrValue(), true, true, true, false, DnaLexicon.NODE_TYPES, - new JcrNodeType[] {dnaNodeTypes})}), NO_PROPERTIES, + new Name[] {DnaLexicon.NODE_TYPES})}), NO_PROPERTIES, NOT_MIXIN, UNORDERABLE_CHILD_NODES); JcrNodeType root = new JcrNodeType(context, NO_NODE_TYPE_MANAGER, DnaLexicon.ROOT, Arrays.asList(new JcrNodeType[] {base, referenceable}), NO_PRIMARY_ITEM_NAME, Arrays.asList(new JcrNodeDefinition[] { new JcrNodeDefinition(context, null, JcrLexicon.SYSTEM, OnParentVersionBehavior.IGNORE.getJcrValue(), true, true, - true, false, DnaLexicon.SYSTEM, new JcrNodeType[] {system}), + true, false, DnaLexicon.SYSTEM, new Name[] {DnaLexicon.SYSTEM}), new JcrNodeDefinition(context, null, ALL_NODES, OnParentVersionBehavior.VERSION.getJcrValue(), false, false, false, - true, JcrNtLexicon.UNSTRUCTURED, new JcrNodeType[] {base}), + true, JcrNtLexicon.UNSTRUCTURED, new Name[] {JcrNtLexicon.BASE}), }), Arrays.asList(new JcrPropertyDefinition[] { new JcrPropertyDefinition(context, null, ALL_NODES, OnParentVersionBehavior.COPY.getJcrValue(), false, false, false, Index: dna-jcr/src/main/java/org/jboss/dna/jcr/GraphNodeTypeSource.java =================================================================== --- dna-jcr/src/main/java/org/jboss/dna/jcr/GraphNodeTypeSource.java (revision 0) +++ dna-jcr/src/main/java/org/jboss/dna/jcr/GraphNodeTypeSource.java (revision 0) @@ -0,0 +1,35 @@ +/* + * JBoss DNA (http://www.jboss.org/dna) + * See the COPYRIGHT.txt file distributed with this work for information + * regarding copyright ownership. Some portions may be licensed + * to Red Hat, Inc. under one or more contributor license agreements. + * See the AUTHORS.txt file in the distribution for a full listing of + * individual contributors. + * + * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA + * is licensed to you under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * JBoss DNA is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.jboss.dna.jcr; + +import org.jboss.dna.graph.ExecutionContext; +import org.jboss.dna.graph.Graph; + +/** + * + */ +public interface GraphNodeTypeSource { + Graph getNodeTypes(); + ExecutionContext getExecutionContext(); +} Property changes on: dna-jcr\src\main\java\org\jboss\dna\jcr\GraphNodeTypeSource.java ___________________________________________________________________ Added: svn:keywords + Id Revision Added: svn:eol-style + LF Index: dna-jcr/src/main/java/org/jboss/dna/jcr/JcrBuiltinNodeTypeSource.java =================================================================== --- dna-jcr/src/main/java/org/jboss/dna/jcr/JcrBuiltinNodeTypeSource.java (revision 870) +++ dna-jcr/src/main/java/org/jboss/dna/jcr/JcrBuiltinNodeTypeSource.java (working copy) @@ -31,6 +31,7 @@ import javax.jcr.Value; import net.jcip.annotations.Immutable; import org.jboss.dna.graph.ExecutionContext; +import org.jboss.dna.graph.property.Name; /** * {@link JcrNodeTypeSource} that provides built-in node types per the 1.0 specification. @@ -221,7 +222,7 @@ OnParentVersionBehavior.COPY.getJcrValue(), false, true, false, false, null, - new JcrNodeType[] {base})}), + new Name[] {JcrNtLexicon.BASE})}), NO_PROPERTIES, NOT_MIXIN, UNORDERABLE_CHILD_NODES); JcrNodeType folder = new JcrNodeType( @@ -240,7 +241,7 @@ false, false, null, - new JcrNodeType[] {hierarchyNode})}), + new Name[] {JcrNtLexicon.HIERARCHY_NODE})}), NO_PROPERTIES, NOT_MIXIN, UNORDERABLE_CHILD_NODES); JcrNodeType frozenNode = new JcrNodeType( @@ -259,7 +260,7 @@ true, true, null, - new JcrNodeType[] {base})}), + new Name[] {JcrNtLexicon.BASE})}), Arrays.asList(new JcrPropertyDefinition[] { new JcrPropertyDefinition(context, null, JcrLexicon.FROZEN_MIXIN_TYPES, OnParentVersionBehavior.ABORT.getJcrValue(), @@ -418,12 +419,12 @@ OnParentVersionBehavior.VERSION.getJcrValue(), false, false, NT_NODE_TYPES_PROTECTED, true, JcrNtLexicon.CHILD_NODE_DEFINITION, - new JcrNodeType[] {childNodeDefinition}), + new Name[] {JcrNtLexicon.CHILD_NODE_DEFINITION}), new JcrNodeDefinition(context, null, JcrLexicon.PROPERTY_DEFINITION, OnParentVersionBehavior.VERSION.getJcrValue(), false, false, NT_NODE_TYPES_PROTECTED, true, JcrNtLexicon.PROPERTY_DEFINITION, - new JcrNodeType[] {propertyDefinition})}), + new Name[] {JcrNtLexicon.PROPERTY_DEFINITION})}), Arrays.asList(new JcrPropertyDefinition[] { new JcrPropertyDefinition(context, null, JcrLexicon.HAS_ORDERABLE_CHILD_NODES, OnParentVersionBehavior.COPY.getJcrValue(), false, @@ -505,7 +506,7 @@ false, true, JcrNtLexicon.UNSTRUCTURED, - new JcrNodeType[] {base}),}), + new Name[] {JcrNtLexicon.BASE}),}), Arrays.asList(new JcrPropertyDefinition[] { new JcrPropertyDefinition(context, null, ALL_NODES, OnParentVersionBehavior.COPY.getJcrValue(), Index: dna-jcr/src/main/java/org/jboss/dna/jcr/JcrLexicon.java =================================================================== --- dna-jcr/src/main/java/org/jboss/dna/jcr/JcrLexicon.java (revision 870) +++ dna-jcr/src/main/java/org/jboss/dna/jcr/JcrLexicon.java (working copy) @@ -47,7 +47,6 @@ public static final Name LOCK_OWNER = new BasicName(Namespace.URI, "lockOwner"); public static final Name MERGE_FAILED = new BasicName(Namespace.URI, "mergeFailed"); public static final Name NODE_TYPES = new BasicName(Namespace.URI, "nodeTypes"); - public static final Name NODE_TYPE_NAME = new BasicName(Namespace.URI, "nodeTypeName"); public static final Name PREDECESSORS = new BasicName(Namespace.URI, "predecessors"); public static final Name ROOT = new BasicName(Namespace.URI, "root"); public static final Name ROOT_VERSION = new BasicName(Namespace.URI, "rootVersion"); Index: dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNodeDefinition.java =================================================================== --- dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNodeDefinition.java (revision 870) +++ dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNodeDefinition.java (working copy) @@ -49,7 +49,7 @@ private final Name defaultPrimaryTypeName; /** @see NodeDefinition#getRequiredPrimaryTypes() */ - private final Map requiredPrimaryTypesByName; + private Map requiredPrimaryTypesByName; private JcrNodeType[] requiredPrimaryTypes; @@ -70,9 +70,9 @@ boolean protectedItem, boolean allowsSameNameSiblings, Name defaultPrimaryTypeName, - JcrNodeType[] requiredPrimaryTypes ) { + Name[] requiredPrimaryTypeNames ) { this(context, null, declaringNodeType, name, onParentVersion, autoCreated, mandatory, protectedItem, - allowsSameNameSiblings, defaultPrimaryTypeName, requiredPrimaryTypes); + allowsSameNameSiblings, defaultPrimaryTypeName, requiredPrimaryTypeNames); } JcrNodeDefinition( ExecutionContext context, @@ -85,24 +85,29 @@ boolean protectedItem, boolean allowsSameNameSiblings, Name defaultPrimaryTypeName, - JcrNodeType[] requiredPrimaryTypes ) { + Name[] requiredPrimaryTypeNames ) { super(context, declaringNodeType, name, onParentVersion, autoCreated, mandatory, protectedItem); this.nodeTypeManager = nodeTypeManager; this.allowsSameNameSiblings = allowsSameNameSiblings; this.defaultPrimaryTypeName = defaultPrimaryTypeName; - this.requiredPrimaryTypes = new JcrNodeType[requiredPrimaryTypes.length]; - this.requiredPrimaryTypeNames = new Name[requiredPrimaryTypes.length]; - for (int i = 0; i != requiredPrimaryTypes.length; ++i) { - this.requiredPrimaryTypes[i] = requiredPrimaryTypes[i]; - this.requiredPrimaryTypeNames[i] = requiredPrimaryTypes[i].getInternalName(); + this.requiredPrimaryTypes = new JcrNodeType[requiredPrimaryTypeNames.length]; + this.requiredPrimaryTypeNames = requiredPrimaryTypeNames; + } + + private void ensureRequiredPrimaryTypesLoaded() { + if (requiredPrimaryTypesByName != null) return; + this.requiredPrimaryTypes = new JcrNodeType[requiredPrimaryTypeNames.length]; + for (int i = 0; i != requiredPrimaryTypeNames.length; ++i) { + this.requiredPrimaryTypes[i] = nodeTypeManager.getNodeType(requiredPrimaryTypeNames[i]); } Map requiredPrimaryTypesByName = new HashMap(); for (JcrNodeType requiredPrimaryType : requiredPrimaryTypes) { requiredPrimaryTypesByName.put(requiredPrimaryType.getInternalName(), requiredPrimaryType); } this.requiredPrimaryTypesByName = Collections.unmodifiableMap(requiredPrimaryTypesByName); + } - + /** * Get the durable identifier for this node definition. * @@ -145,6 +150,7 @@ * @see javax.jcr.nodetype.NodeDefinition#getRequiredPrimaryTypes() */ public NodeType[] getRequiredPrimaryTypes() { + ensureRequiredPrimaryTypesLoaded(); // Make a copy so that the caller can't modify our content ... NodeType[] result = new NodeType[requiredPrimaryTypes.length]; for (int i = 0; i != requiredPrimaryTypes.length; ++i) { @@ -159,6 +165,7 @@ * @return the required primary type names */ Set getRequiredPrimaryTypeNames() { + ensureRequiredPrimaryTypesLoaded(); return requiredPrimaryTypesByName.keySet(); } @@ -179,6 +186,7 @@ } return false; } + ensureRequiredPrimaryTypesLoaded(); // The supplied primary type must be or extend all of the required primary types ... for (Name requiredPrimaryTypeName : requiredPrimaryTypesByName.keySet()) { if (!childPrimaryType.isNodeType(requiredPrimaryTypeName)) return false; @@ -195,24 +203,21 @@ * declaringNodeType. */ JcrNodeDefinition with( JcrNodeType declaringNodeType ) { - JcrNodeType[] required = requiredPrimaryTypesByName.values().toArray(new JcrNodeType[requiredPrimaryTypesByName.size()]); return new JcrNodeDefinition(this.context, declaringNodeType.nodeTypeManager(), declaringNodeType, name, getOnParentVersion(), isAutoCreated(), isMandatory(), isProtected(), - allowsSameNameSiblings(), defaultPrimaryTypeName, required); + allowsSameNameSiblings(), defaultPrimaryTypeName, requiredPrimaryTypeNames); } JcrNodeDefinition with( ExecutionContext context ) { - JcrNodeType[] required = requiredPrimaryTypesByName.values().toArray(new JcrNodeType[requiredPrimaryTypesByName.size()]); return new JcrNodeDefinition(context, this.nodeTypeManager, this.declaringNodeType, name, getOnParentVersion(), isAutoCreated(), isMandatory(), isProtected(), allowsSameNameSiblings(), - defaultPrimaryTypeName, required); + defaultPrimaryTypeName, requiredPrimaryTypeNames); } JcrNodeDefinition with( RepositoryNodeTypeManager nodeTypeManager ) { - JcrNodeType[] required = requiredPrimaryTypesByName.values().toArray(new JcrNodeType[requiredPrimaryTypesByName.size()]); return new JcrNodeDefinition(this.context, nodeTypeManager, this.declaringNodeType, name, getOnParentVersion(), isAutoCreated(), isMandatory(), isProtected(), allowsSameNameSiblings(), - defaultPrimaryTypeName, required); + defaultPrimaryTypeName, requiredPrimaryTypeNames); } Index: dna-jcr/src/main/java/org/jboss/dna/jcr/RepositoryNodeTypeManager.java =================================================================== --- dna-jcr/src/main/java/org/jboss/dna/jcr/RepositoryNodeTypeManager.java (revision 870) +++ dna-jcr/src/main/java/org/jboss/dna/jcr/RepositoryNodeTypeManager.java (working copy) @@ -44,27 +44,54 @@ import org.jboss.dna.common.text.XmlNameEncoder; import org.jboss.dna.graph.ExecutionContext; import org.jboss.dna.graph.Graph; +import org.jboss.dna.graph.Location; +import org.jboss.dna.graph.Node; +import org.jboss.dna.graph.Subgraph; import org.jboss.dna.graph.property.Name; +import org.jboss.dna.graph.property.NameFactory; +import org.jboss.dna.graph.property.NamespaceRegistry; import org.jboss.dna.graph.property.Path; import org.jboss.dna.graph.property.PathFactory; import org.jboss.dna.graph.property.PathNotFoundException; import org.jboss.dna.graph.property.Property; import org.jboss.dna.graph.property.PropertyFactory; -import org.jboss.dna.jcr.JcrNodeTypeSource; +import org.jboss.dna.graph.property.ValueFactories; +import org.jboss.dna.graph.property.ValueFactory; /** * The {@link RepositoryNodeTypeManager} is the maintainer of node type information for the entire repository at run-time. The - * repository manager maintains a list of all node types and the ability to retrieve node types by {@link Name}.

The JCR 1.0 - * and 2.0 specifications both require that node type information be shared across all sessions within a repository and that the - * {@link javax.jcr.nodetype.NodeTypeManager} perform operations based on the string versions of {@link Name}s based on the - * permanent (workspace-scoped) and transient (session-scoped) namespace mappings. DNA achieves this by maintaining a single - * master repository of all node type information (the {@link RepositoryNodeTypeManager}) and per-session wrappers ( + * repository manager maintains a list of all node types and the ability to retrieve node types by {@link Name}. + *

+ * The JCR 1.0 and 2.0 specifications both require that node type information be shared across all sessions within a repository + * and that the {@link javax.jcr.nodetype.NodeTypeManager} perform operations based on the string versions of {@link Name}s based + * on the permanent (workspace-scoped) and transient (session-scoped) namespace mappings. DNA achieves this by maintaining a + * single master repository of all node type information (the {@link RepositoryNodeTypeManager}) and per-session wrappers ( * {@link JcrNodeTypeManager}) for this master repository that perform {@link String} to {@link Name} translation based on the * {@link javax.jcr.Session}'s transient mappings and then delegating node type lookups to the repository manager. + *

*/ @Immutable class RepositoryNodeTypeManager { + private static final Map PROPERTY_TYPE_VALUES_FROM_NAME; + + static { + Map temp = new HashMap(); + + temp.put(PropertyType.TYPENAME_BINARY.toUpperCase(), PropertyType.BINARY); + temp.put(PropertyType.TYPENAME_BOOLEAN.toUpperCase(), PropertyType.BOOLEAN); + temp.put(PropertyType.TYPENAME_DATE.toUpperCase(), PropertyType.DATE); + temp.put(PropertyType.TYPENAME_DOUBLE.toUpperCase(), PropertyType.DOUBLE); + temp.put(PropertyType.TYPENAME_LONG.toUpperCase(), PropertyType.LONG); + temp.put(PropertyType.TYPENAME_NAME.toUpperCase(), PropertyType.NAME); + temp.put(PropertyType.TYPENAME_PATH.toUpperCase(), PropertyType.PATH); + temp.put(PropertyType.TYPENAME_STRING.toUpperCase(), PropertyType.STRING); + temp.put(PropertyType.TYPENAME_REFERENCE.toUpperCase(), PropertyType.REFERENCE); + temp.put(PropertyType.TYPENAME_UNDEFINED.toUpperCase(), PropertyType.UNDEFINED); + + PROPERTY_TYPE_VALUES_FROM_NAME = Collections.unmodifiableMap(temp); + } + private static final TextEncoder NAME_ENCODER = new XmlNameEncoder(); private final ExecutionContext context; @@ -1005,25 +1032,32 @@ * @throws RepositoryException if any of the node types in the the {@link JcrNodeTypeSource} are invalid * @throws RepositoryException if another error occurs */ - List registerNodeTypes( JcrNodeTypeSource nodeTypeSource ) throws RepositoryException { + List registerNodeTypes( GraphNodeTypeSource nodeTypeSource ) throws RepositoryException { assert nodeTypeSource != null; - Collection nodeTypeBatch = nodeTypeSource.getNodeTypes(); - List typesPendingRegistration = new ArrayList(nodeTypeBatch.size()); + Graph nodeTypeBatch = nodeTypeSource.getNodeTypes(); + NamespaceRegistry namespaces = this.context.getNamespaceRegistry(); - for (JcrNodeType nodeType : nodeTypeBatch) { - if (nodeType.getInternalName() == null || nodeType.getName().length() == 0) { + List nodeTypeLocations = nodeTypeBatch.getChildren().of("/"); + List typesPendingRegistration = new ArrayList(nodeTypeLocations.size()); + + for (Location location : nodeTypeLocations) { + Node nodeTypeNode = nodeTypeBatch.getNodeAt(location); + assert location.getPath() != null; + + Name internalName = location.getPath().getLastSegment().getName(); + if (internalName == null || internalName.getLocalName().length() == 0) { throw new RepositoryException(JcrI18n.invalidNodeTypeName.text()); } - Name name = nodeType.getInternalName(); - - if (nodeTypes.containsKey(name)) { - throw new RepositoryException(JcrI18n.nodeTypeAlreadyExists.text(nodeType.getName())); + if (nodeTypes.containsKey(internalName)) { + throw new RepositoryException(JcrI18n.nodeTypeAlreadyExists.text(internalName.getString(namespaces))); } - List supertypes = supertypesFor(nodeType, typesPendingRegistration); + List supertypes = supertypesFor(nodeTypeNode, typesPendingRegistration); + // No need to re-parse the supertypes + JcrNodeType nodeType = nodeTypeFrom(nodeTypeBatch.getSubgraphOfDepth(2).at(location), supertypes); validate(nodeType, supertypes, typesPendingRegistration); @@ -1052,7 +1086,7 @@ nodeDefs.add(nodeDef.with(this.context).with(this)); } - JcrNodeType newNodeType = new JcrNodeType(this.context, this, name, supertypes, + JcrNodeType newNodeType = new JcrNodeType(this.context, this, nodeType.getInternalName(), supertypes, nodeType.getInternalPrimaryItemName(), nodeDefs, propertyDefs, nodeType.isMixin(), nodeType.hasOrderableChildNodes()); @@ -1082,6 +1116,125 @@ return typesPendingRegistration; } + private JcrNodeType nodeTypeFrom(Subgraph nodeTypeGraph, List supertypes) { + Node nodeTypeNode = nodeTypeGraph.getRoot(); + List children = nodeTypeNode.getChildren(); + + List properties = new ArrayList(children.size()); + List childNodes = new ArrayList(children.size()); + + for (Location childLocation : children) { + if (JcrLexicon.PROPERTY_DEFINITION.equals(childLocation.getPath().getLastSegment().getName())) { + properties.add(this.propertyDefinitionFrom(nodeTypeGraph, childLocation)); + } + else if (JcrLexicon.CHILD_NODE_DEFINITION.equals(childLocation.getPath().getLastSegment().getName())) { + childNodes.add(this.childNodeDefinitionFrom(nodeTypeGraph, childLocation)); + } + else { + throw new IllegalStateException("Unexpected child of node type at: " + childLocation); + } + } + + Map nodeProperties = nodeTypeNode.getPropertiesByName(); + + ValueFactories valueFactories = context.getValueFactories(); + NameFactory nameFactory = valueFactories.getNameFactory(); + ValueFactory booleanFactory = valueFactories.getBooleanFactory(); + + Name name = nameFactory.create(getFirstPropertyValue(nodeProperties.get(JcrLexicon.NODE_TYPE_NAME))); + Name primaryItemName = nameFactory.create(getFirstPropertyValue(nodeProperties.get(JcrLexicon.PRIMARY_ITEM_NAME))); + boolean mixin = booleanFactory.create(getFirstPropertyValue(nodeProperties.get(JcrLexicon.IS_MIXIN))); + boolean orderableChildNodes = booleanFactory.create(getFirstPropertyValue(nodeProperties.get(JcrLexicon.HAS_ORDERABLE_CHILD_NODES))); + + return new JcrNodeType(this.context, this, name, supertypes, primaryItemName, childNodes, properties, mixin, orderableChildNodes); + } + + private JcrPropertyDefinition propertyDefinitionFrom(Subgraph nodeTypeGraph, Location propertyLocation) { + Node propertyDefinitionNode = nodeTypeGraph.getNode(propertyLocation); + Map properties = propertyDefinitionNode.getPropertiesByName(); + + ValueFactories valueFactories = context.getValueFactories(); + NameFactory nameFactory = valueFactories.getNameFactory(); + ValueFactory booleanFactory = valueFactories.getBooleanFactory(); + + Name propertyName = nameFactory.create(getFirstPropertyValue(properties.get(JcrLexicon.NAME))); + int onParentVersionBehavior = OnParentVersionAction.valueFromName((String) getFirstPropertyValue(properties.get(JcrLexicon.ON_PARENT_VERSION))); + int requiredType = PROPERTY_TYPE_VALUES_FROM_NAME.get(getFirstPropertyValue(properties.get(JcrLexicon.REQUIRED_TYPE))); + + boolean mandatory = booleanFactory.create(getFirstPropertyValue(properties.get(JcrLexicon.MANDATORY))); + boolean multiple = booleanFactory.create(getFirstPropertyValue(properties.get(JcrLexicon.MULTIPLE))); + boolean autoCreated = booleanFactory.create(getFirstPropertyValue(properties.get(JcrLexicon.AUTO_CREATED))); + boolean isProtected = booleanFactory.create(getFirstPropertyValue(properties.get(JcrLexicon.PROTECTED))); + + Value[] defaultValues; + Property defaultValuesProperty = properties.get(JcrLexicon.DEFAULT_VALUES); + if (defaultValuesProperty != null) { + List values = new ArrayList(); + + for (Object value : defaultValuesProperty) { + values.add(new JcrValue(this.context.getValueFactories(), (SessionCache) null, requiredType, value)); + } + defaultValues = values.toArray(new Value[values.size()]); + } + else { + defaultValues = new Value[0]; + } + + String[] valueConstraints; + Property constraintsProperty = properties.get(JcrLexicon.VALUE_CONSTRAINTS); + if (constraintsProperty != null) { + List constraints = new ArrayList(); + + for (Object value : constraintsProperty) { + constraints.add((String) value); + } + valueConstraints = constraints.toArray(new String[constraints.size()]); + } + else { + valueConstraints = new String[0]; + } + + return new JcrPropertyDefinition(this.context, null, propertyName, onParentVersionBehavior, autoCreated, mandatory, isProtected, defaultValues, requiredType, valueConstraints, multiple); + } + + private JcrNodeDefinition childNodeDefinitionFrom(Subgraph nodeTypeGraph, Location childNodeLocation) { + Node childNodeDefinitionNode = nodeTypeGraph.getNode(childNodeLocation); + Map properties = childNodeDefinitionNode.getPropertiesByName(); + + ValueFactories valueFactories = context.getValueFactories(); + NameFactory nameFactory = valueFactories.getNameFactory(); + ValueFactory booleanFactory = valueFactories.getBooleanFactory(); + + Name childNodeName = nameFactory.create(getFirstPropertyValue(properties.get(JcrLexicon.NAME))); + Name defaultPrimaryTypeName = nameFactory.create(getFirstPropertyValue(properties.get(JcrLexicon.DEFAULT_PRIMARY_TYPE))); + int onParentVersion = OnParentVersionAction.valueFromName((String) getFirstPropertyValue(properties.get(JcrLexicon.ON_PARENT_VERSION))); + + boolean mandatory = booleanFactory.create(getFirstPropertyValue(properties.get(JcrLexicon.MANDATORY))); + boolean allowsSns = booleanFactory.create(getFirstPropertyValue(properties.get(JcrLexicon.SAME_NAME_SIBLINGS))); + boolean autoCreated = booleanFactory.create(getFirstPropertyValue(properties.get(JcrLexicon.AUTO_CREATED))); + boolean isProtected = booleanFactory.create(getFirstPropertyValue(properties.get(JcrLexicon.PROTECTED))); + + Name[] requiredTypes; + Property requiredTypeNamesProperty = properties.get(JcrLexicon.REQUIRED_PRIMARY_TYPES); + if (requiredTypeNamesProperty != null) { + List names = new ArrayList(requiredTypeNamesProperty.size()); + for (Object value : requiredTypeNamesProperty) { + names.add(nameFactory.create(value)); + } + + requiredTypes = names.toArray(new Name[names.size()]); + } + else { + requiredTypes = new Name[0]; + } + + return new JcrNodeDefinition(this.context, null, childNodeName, onParentVersion, autoCreated, mandatory, isProtected, allowsSns, defaultPrimaryTypeName, requiredTypes); + } + + private Object getFirstPropertyValue(Property property) { + return property != null ? property.getFirstValue() : null; + } + /** * Finds the named type in the given list of types pending registration if it exists, else returns the type definition from * the repository @@ -1113,24 +1266,26 @@ * @throws RepositoryException if any of the names in the array of supertype names does not correspond to an * already-registered node type or a node type that is pending registration */ - private List supertypesFor( JcrNodeType nodeType, + private List supertypesFor( Node nodeType, List pendingTypes ) throws RepositoryException { assert nodeType != null; + Property supertypesProperty = nodeType.getProperty(JcrLexicon.SUPERTYPES); + // If no supertypes are provided, assume nt:base as a supertype - if (nodeType.getDeclaredSupertypes() == null || nodeType.getDeclaredSupertypes().length == 0) { + if (supertypesProperty == null || supertypesProperty.size() == 0) { return Collections.singletonList(nodeTypes.get(JcrNtLexicon.BASE)); } - JcrNodeType[] supertypesArray = nodeType.getDeclaredSupertypes(); + Object[] supertypesArray = supertypesProperty.getValuesAsArray(); List supertypes = new ArrayList(supertypesArray.length); for (int i = 0; i < supertypesArray.length; i++) { - supertypes.add(findTypeInMapOrList(supertypesArray[i].getInternalName(), pendingTypes)); + supertypes.add(findTypeInMapOrList((Name)supertypesArray[i], pendingTypes)); if (supertypes.get(i) == null) { - throw new RepositoryException(JcrI18n.invalidSupertypeName.text(supertypesArray[i].getInternalName(), - nodeType.getName())); + Name nodeTypeName = nodeType.getLocation().getPath().getLastSegment().getName(); + throw new RepositoryException(JcrI18n.invalidSupertypeName.text(supertypesArray[i], nodeTypeName)); } } @@ -1208,8 +1363,8 @@ /** * Validates that the given node type definition is valid under the DNA and JCR type rules within the given context. *

- * See {@link #registerNodeTypes(JcrNodeTypeSource)} for the list of criteria that determine whether a node type definition is - * valid. + * See {@link #registerNodeTypes(GraphNodeTypeSource)} for the list of criteria that determine whether a node type definition + * is valid. *

* * @param nodeType the node type to attempt to validate @@ -1220,25 +1375,27 @@ private void validate( JcrNodeType nodeType, List supertypes, List pendingTypes ) throws RepositoryException { - validate(supertypes, nodeType.getName()); + Name nodeTypeName = nodeType.getInternalName(); + validate(supertypes, nodeTypeName.getString()); List supertypeNames = new ArrayList(supertypes.size()); for (JcrNodeType supertype : supertypes) supertypeNames.add(supertype.getInternalName()); boolean found = false; - String primaryItemName = nodeType.getPrimaryItemName(); + Name primaryItemName = nodeType.getInternalPrimaryItemName(); + for (JcrNodeDefinition node : nodeType.getDeclaredChildNodeDefinitions()) { validate(node, supertypeNames, pendingTypes); - if (primaryItemName != null && primaryItemName.equals(node.getName())) { + if (primaryItemName != null && primaryItemName.equals(node.getInternalName())) { found = true; } } for (JcrPropertyDefinition prop : nodeType.getDeclaredPropertyDefinitions()) { validate(prop, supertypeNames, pendingTypes); - if (primaryItemName != null && primaryItemName.equals(prop.getName())) { + if (primaryItemName != null && primaryItemName.equals(prop.getInternalName())) { if (found) { throw new RepositoryException(JcrI18n.ambiguousPrimaryItemName.text(primaryItemName)); } Index: dna-jcr/src/test/java/org/jboss/dna/jcr/CndNodeTypeRegistrationTest.java =================================================================== --- dna-jcr/src/test/java/org/jboss/dna/jcr/CndNodeTypeRegistrationTest.java (revision 0) +++ dna-jcr/src/test/java/org/jboss/dna/jcr/CndNodeTypeRegistrationTest.java (revision 0) @@ -0,0 +1,109 @@ +/* + * JBoss DNA (http://www.jboss.org/dna) + * See the COPYRIGHT.txt file distributed with this work for information + * regarding copyright ownership. Some portions may be licensed + * to Red Hat, Inc. under one or more contributor license agreements. + * See the AUTHORS.txt file in the distribution for a full listing of + * individual contributors. + * + * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA + * is licensed to you under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * JBoss DNA is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.jboss.dna.jcr; + +import static org.hamcrest.core.Is.is; +import static org.hamcrest.core.IsNull.notNullValue; +import static org.junit.Assert.assertThat; +import javax.jcr.PropertyType; +import javax.jcr.RepositoryException; +import javax.jcr.nodetype.NodeType; +import org.jboss.dna.graph.ExecutionContext; +import org.jboss.dna.graph.property.Name; +import org.junit.Before; +import org.junit.Test; +import org.mockito.MockitoAnnotations; + +/** + * Test of CND-based type definitions. These test cases focus on ensuring that an import of a type from a CND file registers the + * expected type rather than attempting to validate all of the type registration functionality already tested in + * {@link TypeRegistrationTest}. + */ +public class CndNodeTypeRegistrationTest { + + /** Location of CND files for this test */ + private static final String CND_LOCATION = "/cndNodeTypeRegistration/"; + + private ExecutionContext context; + private RepositoryNodeTypeManager repoTypeManager; + private GraphNodeTypeSource nodeTypes; + + @Before + public void beforeEach() throws Exception { + MockitoAnnotations.initMocks(this); + context = new ExecutionContext(); + context.getNamespaceRegistry().register(TestLexicon.Namespace.PREFIX, TestLexicon.Namespace.URI); + + JcrNodeTypeSource source = null; + source = new JcrBuiltinNodeTypeSource(context, source); + source = new DnaBuiltinNodeTypeSource(this.context, source); + repoTypeManager = new RepositoryNodeTypeManager(context, source); + + } + + @Test( expected = AssertionError.class ) + public void shouldNotAllowNullTypeSource() throws Exception { + repoTypeManager.registerNodeTypes(null); + } + + @Test( expected = RepositoryException.class ) + public void shouldNotAllowRedefinitionOfExistingType() throws Exception { + nodeTypes = new CndNodeTypeSource(context, CND_LOCATION + "existingType.cnd"); + + repoTypeManager.registerNodeTypes(nodeTypes); + } + + @Test + public void shouldRegisterValidTypes() throws Exception { + nodeTypes = new CndNodeTypeSource(context, CND_LOCATION + "validType.cnd"); + + repoTypeManager.registerNodeTypes(nodeTypes); + Name testNodeName = context.getValueFactories().getNameFactory().create(TestLexicon.Namespace.URI, "testType"); + + NodeType nodeType = repoTypeManager.getNodeType(testNodeName); + assertThat(nodeType, is(notNullValue())); + assertThat(nodeType.isMixin(), is(true)); + assertThat(nodeType.hasOrderableChildNodes(), is(true)); + assertThat(nodeType.getDeclaredSupertypes().length, is(2)); + assertThat(nodeType.getDeclaredChildNodeDefinitions().length, is(1)); + JcrNodeDefinition childNode = (JcrNodeDefinition) nodeType.getDeclaredChildNodeDefinitions()[0]; + assertThat(childNode.getName(), is("dnatest:namespace")); + assertThat(childNode.getDefaultPrimaryType().getName(), is("dna:namespace")); + assertThat(childNode.getRequiredPrimaryTypes().length, is(1)); + assertThat(childNode.getRequiredPrimaryTypes()[0].getName(), is("dna:namespace")); + assertThat(childNode.allowsSameNameSiblings(), is(false)); + assertThat(childNode.isMandatory(), is(false)); + + assertThat(nodeType.getDeclaredPropertyDefinitions().length, is(1)); + JcrPropertyDefinition property = (JcrPropertyDefinition) nodeType.getDeclaredPropertyDefinitions()[0]; + assertThat(property.getName(), is("*")); + assertThat(property.getRequiredType(), is(PropertyType.STRING)); + assertThat(property.getValueConstraints().length, is(3)); + assertThat(property.getValueConstraints()[0], is("foo")); + assertThat(property.getValueConstraints()[1], is("bar")); + assertThat(property.getValueConstraints()[2], is("baz")); + assertThat(property.getDefaultValues().length, is(1)); + assertThat(property.getDefaultValues()[0].getString(), is("foo")); + } +} Property changes on: dna-jcr\src\test\java\org\jboss\dna\jcr\CndNodeTypeRegistrationTest.java ___________________________________________________________________ Added: svn:keywords + Id Revision Added: svn:eol-style + LF Index: dna-jcr/src/test/java/org/jboss/dna/jcr/InMemoryRepositoryStub.java =================================================================== --- dna-jcr/src/test/java/org/jboss/dna/jcr/InMemoryRepositoryStub.java (revision 870) +++ dna-jcr/src/test/java/org/jboss/dna/jcr/InMemoryRepositoryStub.java (working copy) @@ -27,20 +27,14 @@ import java.net.URI; import java.security.AccessControlContext; import java.security.AccessController; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; import java.util.Collections; -import java.util.List; import java.util.Map; import java.util.Properties; import javax.jcr.Credentials; -import javax.jcr.PropertyType; import org.apache.jackrabbit.test.RepositoryStub; +import org.jboss.dna.common.collection.Problem; import org.jboss.dna.graph.ExecutionContext; import org.jboss.dna.graph.Graph; -import org.jboss.dna.graph.JcrMixLexicon; -import org.jboss.dna.graph.JcrNtLexicon; import org.jboss.dna.graph.Location; import org.jboss.dna.graph.connector.RepositoryConnection; import org.jboss.dna.graph.connector.RepositoryConnectionFactory; @@ -114,7 +108,16 @@ // Set up some sample nodes in the graph to match the expected test configuration try { - nodeTypes.registerNodeTypes(new TckTestNodeTypeSource(executionContext, nodeTypes)); + CndNodeTypeSource nodeTypeSource = new CndNodeTypeSource(executionContext, "/tck_test_types.cnd"); + + for (Problem problem: nodeTypeSource.getProblems()) { + System.err.println(problem); + } + if (!nodeTypeSource.isValid()) { + throw new IllegalStateException("Problems loading TCK test node types"); + } + + nodeTypes.registerNodeTypes(nodeTypeSource); executionContext.getNamespaceRegistry().register(TestLexicon.Namespace.PREFIX, TestLexicon.Namespace.URI); @@ -171,158 +174,4 @@ public JcrRepository getRepository() { return repository; } - - class TckTestNodeTypeSource extends AbstractJcrNodeTypeSource { - /** The list of node types. */ - private final List nodeTypes; - - TckTestNodeTypeSource( ExecutionContext context, - RepositoryNodeTypeManager nodeTypeManager ) { - super(null); - - nodeTypes = new ArrayList(); - - JcrNodeType base = nodeTypeManager.getNodeType(JcrNtLexicon.BASE); - - if (base == null) { - String baseTypeName = JcrNtLexicon.BASE.getString(context.getNamespaceRegistry()); - String namespaceTypeName = TestLexicon.NO_SAME_NAME_SIBS.getString(context.getNamespaceRegistry()); - throw new IllegalStateException(JcrI18n.supertypeNotFound.text(baseTypeName, namespaceTypeName)); - } - - JcrNodeType referenceable = nodeTypeManager.getNodeType(JcrMixLexicon.REFERENCEABLE); - - if (referenceable == null) { - String baseTypeName = JcrMixLexicon.REFERENCEABLE.getString(context.getNamespaceRegistry()); - String namespaceTypeName = TestLexicon.REFERENCEABLE_UNSTRUCTURED.getString(context.getNamespaceRegistry()); - throw new IllegalStateException(JcrI18n.supertypeNotFound.text(baseTypeName, namespaceTypeName)); - } - - JcrNodeType unstructured = nodeTypeManager.getNodeType(JcrNtLexicon.UNSTRUCTURED); - - if (unstructured == null) { - String baseTypeName = JcrNtLexicon.UNSTRUCTURED.getString(context.getNamespaceRegistry()); - String namespaceTypeName = TestLexicon.REFERENCEABLE_UNSTRUCTURED.getString(context.getNamespaceRegistry()); - throw new IllegalStateException(JcrI18n.supertypeNotFound.text(baseTypeName, namespaceTypeName)); - } - - // Stubbing in child node and property definitions for now - JcrNodeType noSameNameSibs = new JcrNodeType( - context, - NO_NODE_TYPE_MANAGER, - TestLexicon.NO_SAME_NAME_SIBS, - Arrays.asList(new JcrNodeType[] {base}), - NO_PRIMARY_ITEM_NAME, - Arrays.asList(new JcrNodeDefinition[] {new JcrNodeDefinition( - context, - null, - ALL_NODES, - OnParentVersionBehavior.VERSION.getJcrValue(), - false, - false, - false, - false, - JcrNtLexicon.UNSTRUCTURED, - new JcrNodeType[] {base}),}), - NO_PROPERTIES, NOT_MIXIN, UNORDERABLE_CHILD_NODES); - - JcrNodeType referenceableUnstructured = new JcrNodeType( - context, - NO_NODE_TYPE_MANAGER, - TestLexicon.REFERENCEABLE_UNSTRUCTURED, - Arrays.asList(new JcrNodeType[] {unstructured, referenceable}), - NO_PRIMARY_ITEM_NAME, NO_CHILD_NODES, NO_PROPERTIES, - NOT_MIXIN, ORDERABLE_CHILD_NODES); - - JcrNodeType nodeWithMandatoryProperty = new JcrNodeType( - context, - NO_NODE_TYPE_MANAGER, - TestLexicon.NODE_WITH_MANDATORY_PROPERTY, - Arrays.asList(new JcrNodeType[] {unstructured, referenceable}), - NO_PRIMARY_ITEM_NAME, - NO_CHILD_NODES, - Arrays.asList(new JcrPropertyDefinition[] {new JcrPropertyDefinition( - context, - null, - TestLexicon.MANDATORY_STRING, - OnParentVersionBehavior.COPY.getJcrValue(), - false, - true, - false, - NO_DEFAULT_VALUES, - PropertyType.UNDEFINED, - NO_CONSTRAINTS, - false)}), - NOT_MIXIN, ORDERABLE_CHILD_NODES); - JcrNodeType nodeWithMandatoryChild = new JcrNodeType( - context, - NO_NODE_TYPE_MANAGER, - TestLexicon.NODE_WITH_MANDATORY_CHILD, - Arrays.asList(new JcrNodeType[] {unstructured, referenceable}), - NO_PRIMARY_ITEM_NAME, - Arrays.asList(new JcrNodeDefinition[] {new JcrNodeDefinition( - context, - null, - TestLexicon.MANDATORY_CHILD, - OnParentVersionBehavior.VERSION.getJcrValue(), - false, - true, - false, - false, - JcrNtLexicon.UNSTRUCTURED, - new JcrNodeType[] {base}),}), - NO_PROPERTIES, NOT_MIXIN, ORDERABLE_CHILD_NODES); - - JcrNodeType unorderableUnstructured = new JcrNodeType( - context, - NO_NODE_TYPE_MANAGER, - TestLexicon.UNORDERABLE_UNSTRUCTURED, - Arrays.asList(new JcrNodeType[] {base}), - NO_PRIMARY_ITEM_NAME, - Arrays.asList(new JcrNodeDefinition[] {new JcrNodeDefinition( - context, - null, - ALL_NODES, - OnParentVersionBehavior.VERSION.getJcrValue(), - false, - false, - false, - true, - TestLexicon.UNORDERABLE_UNSTRUCTURED, - new JcrNodeType[] {base}),}), - Arrays.asList(new JcrPropertyDefinition[] { - new JcrPropertyDefinition( - context, - null, - ALL_NODES, - OnParentVersionBehavior.COPY.getJcrValue(), - false, false, false, - NO_DEFAULT_VALUES, - PropertyType.UNDEFINED, - NO_CONSTRAINTS, false), - new JcrPropertyDefinition( - context, - null, - ALL_NODES, - OnParentVersionBehavior.COPY.getJcrValue(), - false, false, false, - NO_DEFAULT_VALUES, - PropertyType.UNDEFINED, - NO_CONSTRAINTS, true),}), - NOT_MIXIN, UNORDERABLE_CHILD_NODES); - - nodeTypes.addAll(Arrays.asList(new JcrNodeType[] {referenceableUnstructured, noSameNameSibs, - nodeWithMandatoryProperty, nodeWithMandatoryChild, unorderableUnstructured,})); - } - - /** - * {@inheritDoc} - * - * @see org.jboss.dna.jcr.JcrNodeTypeSource#getNodeTypes() - */ - @Override - public Collection getDeclaredNodeTypes() { - return nodeTypes; - } - } } Index: dna-jcr/src/test/java/org/jboss/dna/jcr/TypeRegistrationTest.java =================================================================== --- dna-jcr/src/test/java/org/jboss/dna/jcr/TypeRegistrationTest.java (revision 870) +++ dna-jcr/src/test/java/org/jboss/dna/jcr/TypeRegistrationTest.java (working copy) @@ -98,1218 +98,1218 @@ } }; } - - @Test( expected = AssertionError.class ) - public void shouldNotAllowNullDefinition() throws Exception { - repoTypeManager.registerNodeTypes(null); - } - - @Test( expected = AssertionError.class ) - public void shouldNotAllowTemplateWithNullContext() throws Exception { - repoTypeManager.registerNodeTypes(sourceFor(new JcrNodeType(null, AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, - nameFor(TEST_TYPE_NAME), Arrays.asList(new JcrNodeType[] {}), - AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, - AbstractJcrNodeTypeSource.NO_CHILD_NODES, - AbstractJcrNodeTypeSource.NO_PROPERTIES, - AbstractJcrNodeTypeSource.NOT_MIXIN, - AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES))); - } - - @Test( expected = RepositoryException.class ) - public void shouldNotAllowNodeTypeWithNoName() throws Exception { - ntTemplate = new JcrNodeType(context, AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, null, - Arrays.asList(new JcrNodeType[] {}), AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, - AbstractJcrNodeTypeSource.NO_CHILD_NODES, AbstractJcrNodeTypeSource.NO_PROPERTIES, - AbstractJcrNodeTypeSource.NOT_MIXIN, AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); - repoTypeManager.registerNodeTypes(sourceFor(ntTemplate)); - } - - @Test - public void shouldAllowNewDefinitionWithNoChildNodesOrProperties() throws Exception { - Name testTypeName = nameFactory.create(TEST_TYPE_NAME); - ntTemplate = new JcrNodeType(context, AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, testTypeName, - Arrays.asList(new JcrNodeType[] {}), AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, - AbstractJcrNodeTypeSource.NO_CHILD_NODES, AbstractJcrNodeTypeSource.NO_PROPERTIES, - AbstractJcrNodeTypeSource.NOT_MIXIN, AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); - - List testNodeTypes = repoTypeManager.registerNodeTypes(sourceFor(ntTemplate)); - JcrNodeType testNodeType = testNodeTypes.get(0); - - assertThat(testNodeType.getName(), is(TEST_TYPE_NAME)); - JcrNodeType nodeTypeFromRepo = repoTypeManager.getNodeType(testTypeName); - assertThat(nodeTypeFromRepo, is(notNullValue())); - assertThat(nodeTypeFromRepo.getName(), is(TEST_TYPE_NAME)); - } - - // @Test( expected = RepositoryException.class ) - // public void shouldNotAllowModificationIfAllowUpdatesIsFalse() throws Exception { - // ntTemplate.setName("nt:base"); - // repoTypeManager.registerNodeType(ntTemplate, false); - // } - - // @Test( expected = RepositoryException.class ) - // public void shouldNotAllowRedefinitionOfNewTypeIfAllowUpdatesIsFalse() throws Exception { - // Name testTypeName = nameFactory.create(TEST_TYPE_NAME); - // ntTemplate.setName(TEST_TYPE_NAME); - // ntTemplate.setDeclaredSupertypeNames(new String[] {"nt:base"}); - // - // JcrNodeType testNodeType = repoTypeManager.registerNodeType(ntTemplate, false); - // - // assertThat(testNodeType.getName(), is(TEST_TYPE_NAME)); - // JcrNodeType nodeTypeFromRepo = repoTypeManager.getNodeType(testTypeName); - // assertThat(nodeTypeFromRepo, is(notNullValue())); - // assertThat(nodeTypeFromRepo.getName(), is(TEST_TYPE_NAME)); - // - // testNodeType = repoTypeManager.registerNodeType(ntTemplate, false); - // } - - @Test - public void shouldAllowDefinitionWithExistingSupertypes() throws Exception { - Name testTypeName = nameFactory.create(TEST_TYPE_NAME); - - ntTemplate = new JcrNodeType(context, AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, testTypeName, - Arrays.asList(new JcrNodeType[] {base, referenceable}), - AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, AbstractJcrNodeTypeSource.NO_CHILD_NODES, - AbstractJcrNodeTypeSource.NO_PROPERTIES, AbstractJcrNodeTypeSource.NOT_MIXIN, - AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); - - List testNodeTypes = repoTypeManager.registerNodeTypes(sourceFor(ntTemplate)); - JcrNodeType testNodeType = testNodeTypes.get(0); - - assertThat(testNodeType.getName(), is(TEST_TYPE_NAME)); - JcrNodeType nodeTypeFromRepo = repoTypeManager.getNodeType(testTypeName); - assertThat(nodeTypeFromRepo, is(notNullValue())); - assertThat(nodeTypeFromRepo.getName(), is(TEST_TYPE_NAME)); - - } - - @Test - public void shouldAllowDefinitionWithSupertypesFromTypesRegisteredInSameCall() throws Exception { - ntTemplate = new JcrNodeType(context, AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, nameFor(TEST_TYPE_NAME), - Arrays.asList(new JcrNodeType[] {base, referenceable}), - AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, AbstractJcrNodeTypeSource.NO_CHILD_NODES, - AbstractJcrNodeTypeSource.NO_PROPERTIES, AbstractJcrNodeTypeSource.NOT_MIXIN, - AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); - - JcrNodeType ntTemplate2 = new JcrNodeType(context, AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, - nameFor(TEST_TYPE_NAME2), Arrays.asList(new JcrNodeType[] {ntTemplate}), - AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, - AbstractJcrNodeTypeSource.NO_CHILD_NODES, - AbstractJcrNodeTypeSource.NO_PROPERTIES, AbstractJcrNodeTypeSource.NOT_MIXIN, - AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); - - List templates = Arrays.asList(new JcrNodeType[] {ntTemplate, ntTemplate2}); - compareTemplatesToNodeTypes(templates, repoTypeManager.registerNodeTypes(sourceFor(ntTemplate, ntTemplate2))); - } - - @Test( expected = RepositoryException.class ) - public void shouldNotAllowDefinitionWithSupertypesFromTypesRegisteredInSameCallInWrongOrder() throws Exception { - // Try to register the supertype AFTER the class that registers it - ntTemplate = new JcrNodeType(context, AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, nameFor(TEST_TYPE_NAME), - Arrays.asList(new JcrNodeType[] {base, referenceable}), - AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, AbstractJcrNodeTypeSource.NO_CHILD_NODES, - AbstractJcrNodeTypeSource.NO_PROPERTIES, AbstractJcrNodeTypeSource.NOT_MIXIN, - AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); - - JcrNodeType ntTemplate2 = new JcrNodeType(context, AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, - nameFor(TEST_TYPE_NAME2), Arrays.asList(new JcrNodeType[] {ntTemplate}), - AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, - AbstractJcrNodeTypeSource.NO_CHILD_NODES, - AbstractJcrNodeTypeSource.NO_PROPERTIES, AbstractJcrNodeTypeSource.NOT_MIXIN, - AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); - - List templates = Arrays.asList(new JcrNodeType[] {ntTemplate2, ntTemplate}); - compareTemplatesToNodeTypes(templates, repoTypeManager.registerNodeTypes(sourceFor(ntTemplate2, ntTemplate))); - } - - @Test - public void shouldAllowDefinitionWithAProperty() throws Exception { - ntTemplate = new JcrNodeType( - context, - AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, - nameFor(TEST_TYPE_NAME), - Arrays.asList(new JcrNodeType[] {base, referenceable}), - AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, - AbstractJcrNodeTypeSource.NO_CHILD_NODES, - Arrays.asList(new JcrPropertyDefinition[] {new JcrPropertyDefinition( - context, - null, - null, - OnParentVersionBehavior.VERSION.getJcrValue(), - false, - false, - false, - AbstractJcrNodeTypeSource.NO_DEFAULT_VALUES, - PropertyType.LONG, - AbstractJcrNodeTypeSource.NO_CONSTRAINTS, - false)}), - AbstractJcrNodeTypeSource.NOT_MIXIN, AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); - - List templates = Arrays.asList(new JcrNodeType[] {ntTemplate}); - compareTemplatesToNodeTypes(templates, repoTypeManager.registerNodeTypes(sourceFor(ntTemplate))); - } - - @Test - public void shouldAllowDefinitionWithProperties() throws Exception { - - ntTemplate = new JcrNodeType(context, AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, nameFor(TEST_TYPE_NAME), - Arrays.asList(new JcrNodeType[] {base, referenceable}), - AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, AbstractJcrNodeTypeSource.NO_CHILD_NODES, - Arrays.asList(new JcrPropertyDefinition[] { - new JcrPropertyDefinition(context, null, null, - OnParentVersionBehavior.VERSION.getJcrValue(), false, false, - false, AbstractJcrNodeTypeSource.NO_DEFAULT_VALUES, - PropertyType.LONG, AbstractJcrNodeTypeSource.NO_CONSTRAINTS, - false), - new JcrPropertyDefinition(context, null, null, - OnParentVersionBehavior.VERSION.getJcrValue(), false, false, - false, AbstractJcrNodeTypeSource.NO_DEFAULT_VALUES, - PropertyType.STRING, AbstractJcrNodeTypeSource.NO_CONSTRAINTS, - true), - new JcrPropertyDefinition(context, null, nameFor(TEST_PROPERTY_NAME), - OnParentVersionBehavior.VERSION.getJcrValue(), false, false, - false, AbstractJcrNodeTypeSource.NO_DEFAULT_VALUES, - PropertyType.STRING, AbstractJcrNodeTypeSource.NO_CONSTRAINTS, - false)}), AbstractJcrNodeTypeSource.NOT_MIXIN, - AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); - - List templates = Arrays.asList(new JcrNodeType[] {ntTemplate}); - compareTemplatesToNodeTypes(templates, repoTypeManager.registerNodeTypes(sourceFor(ntTemplate))); - - } - - @Test( expected = RepositoryException.class ) - public void shouldNotAllowAutocreatedPropertyWithNoDefault() throws Exception { - ntTemplate = new JcrNodeType( - context, - AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, - nameFor(TEST_TYPE_NAME), - Arrays.asList(new JcrNodeType[] {base, referenceable}), - AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, - AbstractJcrNodeTypeSource.NO_CHILD_NODES, - Arrays.asList(new JcrPropertyDefinition[] {new JcrPropertyDefinition( - context, - null, - nameFor(TEST_PROPERTY_NAME), - OnParentVersionBehavior.VERSION.getJcrValue(), - true, - false, - false, - AbstractJcrNodeTypeSource.NO_DEFAULT_VALUES, - PropertyType.LONG, - AbstractJcrNodeTypeSource.NO_CONSTRAINTS, - false),}), - AbstractJcrNodeTypeSource.NOT_MIXIN, AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); - - List templates = Arrays.asList(new JcrNodeType[] {ntTemplate}); - compareTemplatesToNodeTypes(templates, repoTypeManager.registerNodeTypes(sourceFor(ntTemplate))); - - } - - @Test( expected = RepositoryException.class ) - public void shouldNotAllowAutocreatedResidualProperty() throws Exception { - ntTemplate = new JcrNodeType( - context, - AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, - nameFor(TEST_TYPE_NAME), - Arrays.asList(new JcrNodeType[] {base, referenceable}), - AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, - AbstractJcrNodeTypeSource.NO_CHILD_NODES, - Arrays.asList(new JcrPropertyDefinition[] {new JcrPropertyDefinition( - context, - null, - null, - OnParentVersionBehavior.VERSION.getJcrValue(), - true, - false, - false, - AbstractJcrNodeTypeSource.NO_DEFAULT_VALUES, - PropertyType.UNDEFINED, - AbstractJcrNodeTypeSource.NO_CONSTRAINTS, - false),}), - AbstractJcrNodeTypeSource.NOT_MIXIN, AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); - - List templates = Arrays.asList(new JcrNodeType[] {ntTemplate}); - compareTemplatesToNodeTypes(templates, repoTypeManager.registerNodeTypes(sourceFor(ntTemplate))); - - } - - // @Test - // public void shouldAllowAutocreatedNamedPropertyWithDefault() throws Exception { - // ntTemplate.setName(TEST_TYPE_NAME); - // ntTemplate.setDeclaredSupertypeNames(new String[] {"nt:base", "mix:referenceable"}); - // - // JcrPropertyDefinitionTemplate prop = new JcrPropertyDefinitionTemplate(this.context); - // prop.setName(TEST_PROPERTY_NAME); - // prop.setRequiredType(PropertyType.UNDEFINED); - // prop.setAutoCreated(true); - // prop.setDefaultValues(new String[] {""}); - // ntTemplate.getPropertyDefinitionTemplates().add(prop); - // - // List templates = Arrays.asList(new NodeTypeDefinition[] {ntTemplate}); - // compareTemplatesToNodeTypes(templates, repoTypeManager.registerNodeTypes(templates, false)); - // } - // - // @Test( expected = RepositoryException.class ) - // public void shouldNotAllowSingleValuedPropertyWithMultipleDefaults() throws Exception { - // ntTemplate.setName(TEST_TYPE_NAME); - // ntTemplate.setDeclaredSupertypeNames(new String[] {"nt:base", "mix:referenceable"}); - // - // JcrPropertyDefinitionTemplate prop = new JcrPropertyDefinitionTemplate(this.context); - // prop.setName(TEST_PROPERTY_NAME); - // prop.setRequiredType(PropertyType.UNDEFINED); - // prop.setAutoCreated(true); - // prop.setDefaultValues(new String[] {"", "too many values"}); - // ntTemplate.getPropertyDefinitionTemplates().add(prop); - // - // List templates = Arrays.asList(new NodeTypeDefinition[] {ntTemplate}); - // compareTemplatesToNodeTypes(templates, repoTypeManager.registerNodeTypes(templates, false)); - // } - - @Test( expected = RepositoryException.class ) - public void shouldNotAllowMandatoryResidualProperty() throws Exception { - ntTemplate = new JcrNodeType( - context, - AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, - nameFor(TEST_TYPE_NAME), - Arrays.asList(new JcrNodeType[] {base, referenceable}), - AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, - AbstractJcrNodeTypeSource.NO_CHILD_NODES, - Arrays.asList(new JcrPropertyDefinition[] {new JcrPropertyDefinition( - context, - null, - null, - OnParentVersionBehavior.VERSION.getJcrValue(), - false, - true, - false, - AbstractJcrNodeTypeSource.NO_DEFAULT_VALUES, - PropertyType.UNDEFINED, - AbstractJcrNodeTypeSource.NO_CONSTRAINTS, - false),}), - AbstractJcrNodeTypeSource.NOT_MIXIN, AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); - - List templates = Arrays.asList(new JcrNodeType[] {ntTemplate}); - compareTemplatesToNodeTypes(templates, repoTypeManager.registerNodeTypes(sourceFor(ntTemplate))); - - } - - @Test - public void shouldAllowTypeWithChildNode() throws Exception { - ntTemplate = new JcrNodeType( - context, - AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, - nameFor(TEST_TYPE_NAME), - Arrays.asList(new JcrNodeType[] {base, referenceable}), - AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, - Arrays.asList(new JcrNodeDefinition[] {new JcrNodeDefinition( - context, - null, - nameFor(TEST_CHILD_NODE_NAME), - OnParentVersionBehavior.VERSION.getJcrValue(), - false, false, false, true, - JcrNtLexicon.BASE, - new JcrNodeType[] {base})}), - AbstractJcrNodeTypeSource.NO_PROPERTIES, AbstractJcrNodeTypeSource.NOT_MIXIN, - AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); - - List templates = Arrays.asList(new JcrNodeType[] {ntTemplate}); - compareTemplatesToNodeTypes(templates, repoTypeManager.registerNodeTypes(sourceFor(ntTemplate))); - - } - - @Test - public void shouldAllowTypeWithMultipleChildNodes() throws Exception { - ntTemplate = new JcrNodeType( - context, - AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, - nameFor(TEST_TYPE_NAME), - Arrays.asList(new JcrNodeType[] {base, referenceable}), - AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, - Arrays.asList(new JcrNodeDefinition[] { - new JcrNodeDefinition(context, null, nameFor(TEST_CHILD_NODE_NAME), - OnParentVersionBehavior.VERSION.getJcrValue(), false, false, - false, true, JcrNtLexicon.BASE, new JcrNodeType[] {base}), - new JcrNodeDefinition(context, null, nameFor(TEST_CHILD_NODE_NAME), - OnParentVersionBehavior.VERSION.getJcrValue(), false, false, - false, false, JcrNtLexicon.BASE, new JcrNodeType[] {unstructured}), - new JcrNodeDefinition(context, null, nameFor(TEST_CHILD_NODE_NAME + "2"), - OnParentVersionBehavior.VERSION.getJcrValue(), false, false, - false, true, JcrNtLexicon.BASE, new JcrNodeType[] {base}), - - }), AbstractJcrNodeTypeSource.NO_PROPERTIES, AbstractJcrNodeTypeSource.NOT_MIXIN, - AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); - - List templates = Arrays.asList(new JcrNodeType[] {ntTemplate}); - compareTemplatesToNodeTypes(templates, repoTypeManager.registerNodeTypes(sourceFor(ntTemplate))); - } - - @Test( expected = RepositoryException.class ) - public void shouldNotAllowAutocreatedChildNodeWithNoDefaultPrimaryType() throws Exception { - ntTemplate = new JcrNodeType( - context, - AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, - nameFor(TEST_TYPE_NAME), - Arrays.asList(new JcrNodeType[] {base, referenceable}), - AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, - Arrays.asList(new JcrNodeDefinition[] {new JcrNodeDefinition( - context, - null, - nameFor(TEST_CHILD_NODE_NAME), - OnParentVersionBehavior.VERSION.getJcrValue(), - true, false, false, false, - null, new JcrNodeType[] {base}),}), - AbstractJcrNodeTypeSource.NO_PROPERTIES, AbstractJcrNodeTypeSource.NOT_MIXIN, - AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); - - List templates = Arrays.asList(new JcrNodeType[] {ntTemplate}); - compareTemplatesToNodeTypes(templates, repoTypeManager.registerNodeTypes(sourceFor(ntTemplate))); - } - - @Test( expected = RepositoryException.class ) - public void shouldNotAllowMandatoryResidualChildNode() throws Exception { - ntTemplate = new JcrNodeType( - context, - AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, - nameFor(TEST_TYPE_NAME), - Arrays.asList(new JcrNodeType[] {base, referenceable}), - AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, - Arrays.asList(new JcrNodeDefinition[] {new JcrNodeDefinition( - context, - null, - null, - OnParentVersionBehavior.VERSION.getJcrValue(), - false, true, false, false, - JcrNtLexicon.BASE, - new JcrNodeType[] {base}),}), - AbstractJcrNodeTypeSource.NO_PROPERTIES, AbstractJcrNodeTypeSource.NOT_MIXIN, - AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); - - List templates = Arrays.asList(new JcrNodeType[] {ntTemplate}); - compareTemplatesToNodeTypes(templates, repoTypeManager.registerNodeTypes(sourceFor(ntTemplate))); - } - - @Test( expected = RepositoryException.class ) - public void shouldNotAllowOverridingProtectedProperty() throws Exception { - ntTemplate = new JcrNodeType( - context, - AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, - nameFor(TEST_TYPE_NAME), - Arrays.asList(new JcrNodeType[] {base, referenceable}), - AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, - AbstractJcrNodeTypeSource.NO_CHILD_NODES, - Arrays.asList(new JcrPropertyDefinition[] {new JcrPropertyDefinition( - context, - null, - JcrLexicon.PRIMARY_TYPE, - OnParentVersionBehavior.VERSION.getJcrValue(), - false, - false, - false, - AbstractJcrNodeTypeSource.NO_DEFAULT_VALUES, - PropertyType.NAME, - AbstractJcrNodeTypeSource.NO_CONSTRAINTS, - false),}), - AbstractJcrNodeTypeSource.NOT_MIXIN, AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); - - List templates = Arrays.asList(new JcrNodeType[] {ntTemplate}); - compareTemplatesToNodeTypes(templates, repoTypeManager.registerNodeTypes(sourceFor(ntTemplate))); - - } - - @Test( expected = RepositoryException.class ) - public void shouldNotAllowOverridingProtectedChildNode() throws Exception { - ntTemplate = new JcrNodeType( - context, - AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, - nameFor(TEST_TYPE_NAME), - Arrays.asList(new JcrNodeType[] {root, referenceable}), - AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, - Arrays.asList(new JcrNodeDefinition[] {new JcrNodeDefinition( - context, - null, - JcrLexicon.SYSTEM, - OnParentVersionBehavior.VERSION.getJcrValue(), - false, false, false, false, - JcrNtLexicon.BASE, - new JcrNodeType[] {base}),}), - AbstractJcrNodeTypeSource.NO_PROPERTIES, AbstractJcrNodeTypeSource.NOT_MIXIN, - AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); - - List templates = Arrays.asList(new JcrNodeType[] {ntTemplate}); - compareTemplatesToNodeTypes(templates, repoTypeManager.registerNodeTypes(sourceFor(ntTemplate))); - } - - @Test( expected = RepositoryException.class ) - public void shouldNotAllowOverridingMandatoryChildNodeWithOptionalChildNode() throws Exception { - ntTemplate = new JcrNodeType( - context, - AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, - nameFor(TEST_TYPE_NAME), - Arrays.asList(new JcrNodeType[] {file}), - AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, - Arrays.asList(new JcrNodeDefinition[] {new JcrNodeDefinition( - context, - null, - JcrLexicon.CONTENT, - OnParentVersionBehavior.VERSION.getJcrValue(), - false, false, false, false, - JcrNtLexicon.BASE, - new JcrNodeType[] {base}),}), - AbstractJcrNodeTypeSource.NO_PROPERTIES, AbstractJcrNodeTypeSource.NOT_MIXIN, - AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); - - List templates = Arrays.asList(new JcrNodeType[] {ntTemplate}); - compareTemplatesToNodeTypes(templates, repoTypeManager.registerNodeTypes(sourceFor(ntTemplate))); - - } - - @Test - public void shouldAllowOverridingPropertyFromCommonAncestor() throws Exception { - /* - * testNode declares prop testProperty - * testNodeB extends testNode - * testNodeC extends testNode - * testNodeD extends testNodeB and testNodeC and overrides testProperty --> LEGAL - */ - - ntTemplate = new JcrNodeType( - context, - AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, - nameFor(TEST_TYPE_NAME), - Arrays.asList(new JcrNodeType[] {base, referenceable}), - AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, - AbstractJcrNodeTypeSource.NO_CHILD_NODES, - Arrays.asList(new JcrPropertyDefinition[] {new JcrPropertyDefinition( - context, - null, - nameFor(TEST_PROPERTY_NAME), - OnParentVersionBehavior.VERSION.getJcrValue(), - false, - false, - false, - AbstractJcrNodeTypeSource.NO_DEFAULT_VALUES, - PropertyType.UNDEFINED, - AbstractJcrNodeTypeSource.NO_CONSTRAINTS, - false),}), - AbstractJcrNodeTypeSource.NOT_MIXIN, AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); - - JcrNodeType nodeBTemplate = new JcrNodeType(context, AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, - nameFor(TEST_TYPE_NAME + "B"), Arrays.asList(new JcrNodeType[] {ntTemplate}), - AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, - AbstractJcrNodeTypeSource.NO_CHILD_NODES, - AbstractJcrNodeTypeSource.NO_PROPERTIES, AbstractJcrNodeTypeSource.NOT_MIXIN, - AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); - - JcrNodeType nodeCTemplate = new JcrNodeType(context, AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, - nameFor(TEST_TYPE_NAME + "C"), Arrays.asList(new JcrNodeType[] {ntTemplate}), - AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, - AbstractJcrNodeTypeSource.NO_CHILD_NODES, - AbstractJcrNodeTypeSource.NO_PROPERTIES, AbstractJcrNodeTypeSource.NOT_MIXIN, - AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); - - JcrNodeType nodeDTemplate = new JcrNodeType( - context, - AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, - nameFor(TEST_TYPE_NAME + "D"), - Arrays.asList(new JcrNodeType[] {nodeBTemplate, nodeCTemplate}), - AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, - AbstractJcrNodeTypeSource.NO_CHILD_NODES, - Arrays.asList(new JcrPropertyDefinition[] {new JcrPropertyDefinition( - context, - null, - nameFor(TEST_PROPERTY_NAME), - OnParentVersionBehavior.VERSION.getJcrValue(), - false, - false, - false, - AbstractJcrNodeTypeSource.NO_DEFAULT_VALUES, - PropertyType.STRING, - AbstractJcrNodeTypeSource.NO_CONSTRAINTS, - false),}), - AbstractJcrNodeTypeSource.NOT_MIXIN, - AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); - - List templates = Arrays.asList(new JcrNodeType[] {ntTemplate, nodeBTemplate, nodeCTemplate, nodeDTemplate}); - compareTemplatesToNodeTypes(templates, repoTypeManager.registerNodeTypes(sourceFor(ntTemplate, - nodeBTemplate, - nodeCTemplate, - nodeDTemplate))); - } - - @Test( expected = RepositoryException.class ) - public void shouldNotAllowOverridingPropertyFromDifferentAncestors() throws Exception { - /* - * testNode - * testNodeB extends testNode and declares prop testProperty - * testNodeC extends testNode and declares prop testProperty - * testNodeD extends testNodeB and testNodeC and overrides testProperty --> ILLEGAL - */ - - ntTemplate = new JcrNodeType(context, AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, nameFor(TEST_TYPE_NAME), - Arrays.asList(new JcrNodeType[] {base, referenceable}), - AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, AbstractJcrNodeTypeSource.NO_CHILD_NODES, - AbstractJcrNodeTypeSource.NO_PROPERTIES, AbstractJcrNodeTypeSource.NOT_MIXIN, - AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); - - JcrNodeType nodeBTemplate = new JcrNodeType( - context, - AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, - nameFor(TEST_TYPE_NAME + "B"), - Arrays.asList(new JcrNodeType[] {ntTemplate}), - AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, - AbstractJcrNodeTypeSource.NO_CHILD_NODES, - Arrays.asList(new JcrPropertyDefinition[] {new JcrPropertyDefinition( - context, - null, - nameFor(TEST_PROPERTY_NAME), - OnParentVersionBehavior.VERSION.getJcrValue(), - false, - false, - false, - AbstractJcrNodeTypeSource.NO_DEFAULT_VALUES, - PropertyType.UNDEFINED, - AbstractJcrNodeTypeSource.NO_CONSTRAINTS, - false),}), - AbstractJcrNodeTypeSource.NOT_MIXIN, - AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); - - JcrNodeType nodeCTemplate = new JcrNodeType( - context, - AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, - nameFor(TEST_TYPE_NAME + "C"), - Arrays.asList(new JcrNodeType[] {ntTemplate}), - AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, - AbstractJcrNodeTypeSource.NO_CHILD_NODES, - Arrays.asList(new JcrPropertyDefinition[] {new JcrPropertyDefinition( - context, - null, - nameFor(TEST_PROPERTY_NAME), - OnParentVersionBehavior.VERSION.getJcrValue(), - false, - false, - false, - AbstractJcrNodeTypeSource.NO_DEFAULT_VALUES, - PropertyType.UNDEFINED, - AbstractJcrNodeTypeSource.NO_CONSTRAINTS, - false),}), - AbstractJcrNodeTypeSource.NOT_MIXIN, - AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); - - JcrNodeType nodeDTemplate = new JcrNodeType( - context, - AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, - nameFor(TEST_TYPE_NAME + "D"), - Arrays.asList(new JcrNodeType[] {nodeBTemplate, nodeCTemplate}), - AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, - AbstractJcrNodeTypeSource.NO_CHILD_NODES, - Arrays.asList(new JcrPropertyDefinition[] {new JcrPropertyDefinition( - context, - null, - nameFor(TEST_PROPERTY_NAME), - OnParentVersionBehavior.VERSION.getJcrValue(), - false, - false, - false, - AbstractJcrNodeTypeSource.NO_DEFAULT_VALUES, - PropertyType.STRING, - AbstractJcrNodeTypeSource.NO_CONSTRAINTS, - false),}), - AbstractJcrNodeTypeSource.NOT_MIXIN, - AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); - - List templates = Arrays.asList(new JcrNodeType[] {ntTemplate, nodeBTemplate, nodeCTemplate, nodeDTemplate}); - compareTemplatesToNodeTypes(templates, repoTypeManager.registerNodeTypes(sourceFor(ntTemplate, - nodeBTemplate, - nodeCTemplate, - nodeDTemplate))); - } - - @Test - public void shouldAllowOverridingChildNodeFromCommonAncestor() throws Exception { - /* - * testNode declares node testChildNode - * testNodeB extends testNode - * testNodeC extends testNode - * testNodeD extends testNodeB and testNodeC and overrides testChildNode --> LEGAL - */ - ntTemplate = new JcrNodeType( - context, - AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, - nameFor(TEST_TYPE_NAME), - Arrays.asList(new JcrNodeType[] {base, referenceable}), - AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, - Arrays.asList(new JcrNodeDefinition[] {new JcrNodeDefinition( - context, - null, - null, - OnParentVersionBehavior.VERSION.getJcrValue(), - false, false, false, false, - JcrNtLexicon.BASE, - new JcrNodeType[] {base}),}), - AbstractJcrNodeTypeSource.NO_PROPERTIES, AbstractJcrNodeTypeSource.NOT_MIXIN, - AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); - - JcrNodeType nodeBTemplate = new JcrNodeType(context, AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, - nameFor(TEST_TYPE_NAME + "B"), Arrays.asList(new JcrNodeType[] {ntTemplate}), - AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, - AbstractJcrNodeTypeSource.NO_CHILD_NODES, - AbstractJcrNodeTypeSource.NO_PROPERTIES, AbstractJcrNodeTypeSource.NOT_MIXIN, - AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); - - JcrNodeType nodeCTemplate = new JcrNodeType(context, AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, - nameFor(TEST_TYPE_NAME + "C"), Arrays.asList(new JcrNodeType[] {ntTemplate}), - AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, - AbstractJcrNodeTypeSource.NO_CHILD_NODES, - AbstractJcrNodeTypeSource.NO_PROPERTIES, AbstractJcrNodeTypeSource.NOT_MIXIN, - AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); - - JcrNodeType nodeDTemplate = new JcrNodeType( - context, - AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, - nameFor(TEST_TYPE_NAME + "D"), - Arrays.asList(new JcrNodeType[] {nodeBTemplate, nodeCTemplate}), - AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, - Arrays.asList(new JcrNodeDefinition[] {new JcrNodeDefinition( - context, - null, - JcrLexicon.SYSTEM, - OnParentVersionBehavior.VERSION.getJcrValue(), - false, - false, - false, - false, - JcrNtLexicon.UNSTRUCTURED, - new JcrNodeType[] {unstructured}),}), - AbstractJcrNodeTypeSource.NO_PROPERTIES, AbstractJcrNodeTypeSource.NOT_MIXIN, - - AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); - - List templates = Arrays.asList(new JcrNodeType[] {ntTemplate, nodeBTemplate, nodeCTemplate, nodeDTemplate}); - compareTemplatesToNodeTypes(templates, repoTypeManager.registerNodeTypes(sourceFor(ntTemplate, - nodeBTemplate, - nodeCTemplate, - nodeDTemplate))); - } - - @Test( expected = RepositoryException.class ) - public void shouldNotAllowOverridingChildNodeFromDifferentAncestors() throws Exception { - /* - * testNode - * testNodeB extends testNode and declares node testChildNode - * testNodeC extends testNode and declares node testChildNode - * testNodeD extends testNodeB and testNodeC and overrides testChildNode --> ILLEGAL - */ - ntTemplate = new JcrNodeType(context, AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, nameFor(TEST_TYPE_NAME), - Arrays.asList(new JcrNodeType[] {base, referenceable}), - AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, AbstractJcrNodeTypeSource.NO_CHILD_NODES, - AbstractJcrNodeTypeSource.NO_PROPERTIES, AbstractJcrNodeTypeSource.NOT_MIXIN, - AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); - - JcrNodeType nodeBTemplate = new JcrNodeType( - context, - AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, - nameFor(TEST_TYPE_NAME + "B"), - Arrays.asList(new JcrNodeType[] {ntTemplate}), - AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, - Arrays.asList(new JcrNodeDefinition[] {new JcrNodeDefinition( - context, - null, - null, - OnParentVersionBehavior.VERSION.getJcrValue(), - false, - false, - false, - false, - JcrNtLexicon.BASE, - new JcrNodeType[] {base}),}), - - AbstractJcrNodeTypeSource.NO_PROPERTIES, AbstractJcrNodeTypeSource.NOT_MIXIN, - AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); - - JcrNodeType nodeCTemplate = new JcrNodeType( - context, - AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, - nameFor(TEST_TYPE_NAME + "C"), - Arrays.asList(new JcrNodeType[] {ntTemplate}), - AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, - Arrays.asList(new JcrNodeDefinition[] {new JcrNodeDefinition( - context, - null, - null, - OnParentVersionBehavior.VERSION.getJcrValue(), - false, - false, - false, - false, - JcrNtLexicon.BASE, - new JcrNodeType[] {base}),}), - - AbstractJcrNodeTypeSource.NO_PROPERTIES, AbstractJcrNodeTypeSource.NOT_MIXIN, - AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); - - JcrNodeType nodeDTemplate = new JcrNodeType( - context, - AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, - nameFor(TEST_TYPE_NAME + "D"), - Arrays.asList(new JcrNodeType[] {nodeBTemplate, nodeCTemplate}), - AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, - Arrays.asList(new JcrNodeDefinition[] {new JcrNodeDefinition( - context, - null, - JcrLexicon.SYSTEM, - OnParentVersionBehavior.VERSION.getJcrValue(), - false, - false, - false, - false, - JcrNtLexicon.UNSTRUCTURED, - new JcrNodeType[] {unstructured}),}), - AbstractJcrNodeTypeSource.NO_PROPERTIES, AbstractJcrNodeTypeSource.NOT_MIXIN, - - AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); - - List templates = Arrays.asList(new JcrNodeType[] {ntTemplate, nodeBTemplate, nodeCTemplate, nodeDTemplate}); - compareTemplatesToNodeTypes(templates, repoTypeManager.registerNodeTypes(sourceFor(ntTemplate, - nodeBTemplate, - nodeCTemplate, - nodeDTemplate))); - } - - @Test( expected = RepositoryException.class ) - public void shouldNotAllowExtendingChildNodeIfSnsChanges() throws Exception { - /* - * testNode declares node testChildNode with no SNS - * testNodeB extends testNode with node testChildNode with SNS -> ILLEGAL - */ - ntTemplate = new JcrNodeType( - context, - AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, - nameFor(TEST_TYPE_NAME), - Arrays.asList(new JcrNodeType[] {base, referenceable}), - AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, - Arrays.asList(new JcrNodeDefinition[] {new JcrNodeDefinition( - context, - null, - nameFor(TEST_CHILD_NODE_NAME), - OnParentVersionBehavior.VERSION.getJcrValue(), - false, false, false, false, - null, new JcrNodeType[] {root}),}), - AbstractJcrNodeTypeSource.NO_PROPERTIES, AbstractJcrNodeTypeSource.NOT_MIXIN, - AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); - - JcrNodeType nodeBTemplate = new JcrNodeType( - context, - AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, - nameFor(TEST_TYPE_NAME + "B"), - Arrays.asList(new JcrNodeType[] {ntTemplate}), - AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, - Arrays.asList(new JcrNodeDefinition[] {new JcrNodeDefinition( - context, - null, - nameFor(TEST_CHILD_NODE_NAME), - OnParentVersionBehavior.VERSION.getJcrValue(), - false, - false, - false, - true, - JcrNtLexicon.UNSTRUCTURED, - new JcrNodeType[] {unstructured}),}), - - AbstractJcrNodeTypeSource.NO_PROPERTIES, AbstractJcrNodeTypeSource.NOT_MIXIN, - AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); - - List templates = Arrays.asList(new JcrNodeType[] {ntTemplate, nodeBTemplate,}); - compareTemplatesToNodeTypes(templates, repoTypeManager.registerNodeTypes(sourceFor(ntTemplate, nodeBTemplate))); - - } - - @Test - public void shouldAllowExtendingPropertyIfMultipleChanges() throws Exception { - /* - * testNode declares SV property testProperty - * testNodeB extends testNode with MV property testProperty with incompatible type -> LEGAL - * testNodeC extends testNode, testNodeB -> LEGAL - */ - ntTemplate = new JcrNodeType( - context, - AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, - nameFor(TEST_TYPE_NAME), - Arrays.asList(new JcrNodeType[] {base, referenceable}), - AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, - AbstractJcrNodeTypeSource.NO_CHILD_NODES, - Arrays.asList(new JcrPropertyDefinition[] {new JcrPropertyDefinition( - context, - null, - nameFor(TEST_PROPERTY_NAME), - OnParentVersionBehavior.VERSION.getJcrValue(), - false, - false, - false, - AbstractJcrNodeTypeSource.NO_DEFAULT_VALUES, - PropertyType.LONG, - AbstractJcrNodeTypeSource.NO_CONSTRAINTS, - false),}), - AbstractJcrNodeTypeSource.NOT_MIXIN, AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); - - JcrNodeType nodeBTemplate = new JcrNodeType( - context, - AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, - nameFor(TEST_TYPE_NAME + "B"), - Arrays.asList(new JcrNodeType[] {ntTemplate}), - AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, - AbstractJcrNodeTypeSource.NO_CHILD_NODES, - Arrays.asList(new JcrPropertyDefinition[] {new JcrPropertyDefinition( - context, - null, - nameFor(TEST_PROPERTY_NAME), - OnParentVersionBehavior.VERSION.getJcrValue(), - false, - false, - false, - AbstractJcrNodeTypeSource.NO_DEFAULT_VALUES, - PropertyType.DATE, - AbstractJcrNodeTypeSource.NO_CONSTRAINTS, - true),}), - AbstractJcrNodeTypeSource.NOT_MIXIN, - AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); - - JcrNodeType nodeCTemplate = new JcrNodeType(context, AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, - nameFor(TEST_TYPE_NAME + "C"), Arrays.asList(new JcrNodeType[] {ntTemplate, - nodeBTemplate}), AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, - AbstractJcrNodeTypeSource.NO_CHILD_NODES, - AbstractJcrNodeTypeSource.NO_PROPERTIES, AbstractJcrNodeTypeSource.NOT_MIXIN, - AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); - - List templates = Arrays.asList(new JcrNodeType[] {ntTemplate, nodeBTemplate, nodeCTemplate,}); - compareTemplatesToNodeTypes(templates, repoTypeManager.registerNodeTypes(sourceFor(ntTemplate, - nodeBTemplate, - nodeCTemplate))); - } - - @Test - public void shouldAllowOverridingPropertyIfTypeNarrows() throws Exception { - /* - * testNode declares SV property testProperty of type UNDEFINED - * testNodeB extends testNode with SV property testProperty of type STRING -> LEGAL - */ - ntTemplate = new JcrNodeType( - context, - AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, - nameFor(TEST_TYPE_NAME), - Arrays.asList(new JcrNodeType[] {base, referenceable}), - AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, - AbstractJcrNodeTypeSource.NO_CHILD_NODES, - Arrays.asList(new JcrPropertyDefinition[] {new JcrPropertyDefinition( - context, - null, - nameFor(TEST_PROPERTY_NAME), - OnParentVersionBehavior.VERSION.getJcrValue(), - false, - false, - false, - AbstractJcrNodeTypeSource.NO_DEFAULT_VALUES, - PropertyType.STRING, - AbstractJcrNodeTypeSource.NO_CONSTRAINTS, - false),}), - AbstractJcrNodeTypeSource.NOT_MIXIN, AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); - - JcrNodeType nodeBTemplate = new JcrNodeType( - context, - AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, - nameFor(TEST_TYPE_NAME + "B"), - Arrays.asList(new JcrNodeType[] {ntTemplate}), - AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, - AbstractJcrNodeTypeSource.NO_CHILD_NODES, - Arrays.asList(new JcrPropertyDefinition[] {new JcrPropertyDefinition( - context, - null, - nameFor(TEST_PROPERTY_NAME), - OnParentVersionBehavior.VERSION.getJcrValue(), - false, - false, - false, - AbstractJcrNodeTypeSource.NO_DEFAULT_VALUES, - PropertyType.LONG, - AbstractJcrNodeTypeSource.NO_CONSTRAINTS, - false),}), - AbstractJcrNodeTypeSource.NOT_MIXIN, - AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); - - List templates = Arrays.asList(new JcrNodeType[] {ntTemplate, nodeBTemplate,}); - compareTemplatesToNodeTypes(templates, repoTypeManager.registerNodeTypes(sourceFor(ntTemplate, nodeBTemplate))); - } - - @Test( expected = RepositoryException.class ) - public void shouldNotAllowOverridingPropertyIfTypeDoesNotNarrow() throws Exception { - /* - * testNode declares SV property testProperty of type DATE - * testNodeB extends testNode with SV property testProperty of type NAME -> ILLEGAL - */ - ntTemplate = new JcrNodeType( - context, - AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, - nameFor(TEST_TYPE_NAME), - Arrays.asList(new JcrNodeType[] {base, referenceable}), - AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, - AbstractJcrNodeTypeSource.NO_CHILD_NODES, - Arrays.asList(new JcrPropertyDefinition[] {new JcrPropertyDefinition( - context, - null, - nameFor(TEST_PROPERTY_NAME), - OnParentVersionBehavior.VERSION.getJcrValue(), - false, - false, - false, - AbstractJcrNodeTypeSource.NO_DEFAULT_VALUES, - PropertyType.DATE, - AbstractJcrNodeTypeSource.NO_CONSTRAINTS, - false),}), - AbstractJcrNodeTypeSource.NOT_MIXIN, AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); - - JcrNodeType nodeBTemplate = new JcrNodeType( - context, - AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, - nameFor(TEST_TYPE_NAME + "B"), - Arrays.asList(new JcrNodeType[] {ntTemplate}), - AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, - AbstractJcrNodeTypeSource.NO_CHILD_NODES, - Arrays.asList(new JcrPropertyDefinition[] {new JcrPropertyDefinition( - context, - null, - nameFor(TEST_PROPERTY_NAME), - OnParentVersionBehavior.VERSION.getJcrValue(), - false, - false, - false, - AbstractJcrNodeTypeSource.NO_DEFAULT_VALUES, - PropertyType.NAME, - AbstractJcrNodeTypeSource.NO_CONSTRAINTS, - false),}), - AbstractJcrNodeTypeSource.NOT_MIXIN, - AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); - - List templates = Arrays.asList(new JcrNodeType[] {ntTemplate, nodeBTemplate,}); - compareTemplatesToNodeTypes(templates, repoTypeManager.registerNodeTypes(sourceFor(ntTemplate, nodeBTemplate))); - } - - @Test - public void shouldAllowOverridingChildNodeIfRequiredTypesNarrow() throws Exception { - /* - * testNode declares No-SNS childNode testChildNode requiring type nt:hierarchy - * testNodeB extends testNode with No-SNS childNode testChildNode requiring type nt:file -> LEGAL - */ - ntTemplate = new JcrNodeType( - context, - AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, - nameFor(TEST_TYPE_NAME), - Arrays.asList(new JcrNodeType[] {base, referenceable}), - AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, - Arrays.asList(new JcrNodeDefinition[] {new JcrNodeDefinition( - context, - null, - nameFor(TEST_CHILD_NODE_NAME), - OnParentVersionBehavior.VERSION.getJcrValue(), - false, - false, - false, - false, - null, - new JcrNodeType[] {hierarchyNode}),}), - AbstractJcrNodeTypeSource.NO_PROPERTIES, AbstractJcrNodeTypeSource.NOT_MIXIN, - AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); - - JcrNodeType nodeBTemplate = new JcrNodeType( - context, - AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, - nameFor(TEST_TYPE_NAME + "B"), - Arrays.asList(new JcrNodeType[] {ntTemplate}), - AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, - Arrays.asList(new JcrNodeDefinition[] {new JcrNodeDefinition( - context, - null, - nameFor(TEST_CHILD_NODE_NAME), - OnParentVersionBehavior.VERSION.getJcrValue(), - false, - false, - false, - true, - null, - new JcrNodeType[] {file}),}), - - AbstractJcrNodeTypeSource.NO_PROPERTIES, AbstractJcrNodeTypeSource.NOT_MIXIN, - AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); - - List templates = Arrays.asList(new JcrNodeType[] {ntTemplate, nodeBTemplate,}); - compareTemplatesToNodeTypes(templates, repoTypeManager.registerNodeTypes(sourceFor(ntTemplate, nodeBTemplate))); - - } - - @Test( expected = RepositoryException.class ) - public void shouldNotAllowOverridingChildNodeIfRequiredTypesDoNotNarrow() throws Exception { - /* - * testNode declares No-SNS childNode testChildNode requiring type nt:hierarchy - * testNodeB extends testNode with No-SNS childNode testChildNode requiring type nt:base -> ILLEGAL - */ - ntTemplate = new JcrNodeType( - context, - AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, - nameFor(TEST_TYPE_NAME), - Arrays.asList(new JcrNodeType[] {base, referenceable}), - AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, - Arrays.asList(new JcrNodeDefinition[] {new JcrNodeDefinition( - context, - null, - nameFor(TEST_CHILD_NODE_NAME), - OnParentVersionBehavior.VERSION.getJcrValue(), - false, - false, - false, - false, - null, - new JcrNodeType[] {hierarchyNode}),}), - AbstractJcrNodeTypeSource.NO_PROPERTIES, AbstractJcrNodeTypeSource.NOT_MIXIN, - AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); - - JcrNodeType nodeBTemplate = new JcrNodeType( - context, - AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, - nameFor(TEST_TYPE_NAME + "B"), - Arrays.asList(new JcrNodeType[] {ntTemplate}), - AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, - Arrays.asList(new JcrNodeDefinition[] {new JcrNodeDefinition( - context, - null, - nameFor(TEST_CHILD_NODE_NAME), - OnParentVersionBehavior.VERSION.getJcrValue(), - false, - false, - false, - true, - null, - new JcrNodeType[] {base}),}), - - AbstractJcrNodeTypeSource.NO_PROPERTIES, AbstractJcrNodeTypeSource.NOT_MIXIN, - AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); - - List templates = Arrays.asList(new JcrNodeType[] {ntTemplate, nodeBTemplate,}); - compareTemplatesToNodeTypes(templates, repoTypeManager.registerNodeTypes(sourceFor(ntTemplate, nodeBTemplate))); - - } - - private void compareTemplatesToNodeTypes( List templates, - List nodeTypes ) { - assertThat(templates.size(), is(nodeTypes.size())); - - for (int i = 0; i < nodeTypes.size(); i++) { - JcrNodeType jntt = templates.get(i); - compareTemplateToNodeType(jntt, null); - compareTemplateToNodeType(jntt, nodeTypes.get(i)); - } - } - - private void compareTemplateToNodeType( JcrNodeType template, - JcrNodeType nodeType ) { - Name nodeTypeName = nameFactory.create(template.getName()); - if (nodeType == null) { - nodeType = repoTypeManager.getNodeType(nodeTypeName); - assertThat(nodeType.nodeTypeManager(), is(notNullValue())); - } - - assertThat(nodeType, is(notNullValue())); - assertThat(nodeType.getName(), is(template.getName())); - - assertThat(nodeType.getDeclaredSupertypes().length, is(template.getDeclaredSupertypes().length)); - for (int i = 0; i < template.getDeclaredSupertypes().length; i++) { - assertThat(template.getDeclaredSupertypes()[i].getName(), is(nodeType.getDeclaredSupertypes()[i].getName())); - } - assertThat(template.isMixin(), is(nodeType.isMixin())); - assertThat(template.hasOrderableChildNodes(), is(nodeType.hasOrderableChildNodes())); - - PropertyDefinition[] propertyDefs = nodeType.getDeclaredPropertyDefinitions(); - List propertyTemplates = Arrays.asList(template.getDeclaredPropertyDefinitions()); - - assertThat(propertyDefs.length, is(propertyTemplates.size())); - for (JcrPropertyDefinition pt : propertyTemplates) { - JcrPropertyDefinition propertyTemplate = pt; - - PropertyDefinition matchingDefinition = null; - for (int i = 0; i < propertyDefs.length; i++) { - PropertyDefinition pd = propertyDefs[i]; - - String ptName = propertyTemplate.getName() == null ? JcrNodeType.RESIDUAL_ITEM_NAME : propertyTemplate.getName(); - if (pd.getName().equals(ptName) && pd.getRequiredType() == propertyTemplate.getRequiredType() - && pd.isMultiple() == propertyTemplate.isMultiple()) { - matchingDefinition = pd; - break; - } - } - - comparePropertyTemplateToPropertyDefinition(propertyTemplate, (JcrPropertyDefinition)matchingDefinition); - } - - NodeDefinition[] childNodeDefs = nodeType.getDeclaredChildNodeDefinitions(); - List childNodeTemplates = Arrays.asList(template.getDeclaredChildNodeDefinitions()); - - assertThat(childNodeDefs.length, is(childNodeTemplates.size())); - for (JcrNodeDefinition nt : childNodeTemplates) { - JcrNodeDefinition childNodeTemplate = nt; - - NodeDefinition matchingDefinition = null; - for (int i = 0; i < childNodeDefs.length; i++) { - JcrNodeDefinition nd = (JcrNodeDefinition)childNodeDefs[i]; - - String ntName = childNodeTemplate.getName() == null ? JcrNodeType.RESIDUAL_ITEM_NAME : childNodeTemplate.getName(); - if (nd.getName().equals(ntName) && nd.allowsSameNameSiblings() == childNodeTemplate.allowsSameNameSiblings()) { - - boolean matchesOnRequiredTypes = childNodeTemplate.getRequiredPrimaryTypeNames() - .equals(nd.getRequiredPrimaryTypeNames()); - - if (matchesOnRequiredTypes) { - matchingDefinition = nd; - break; - } - } - } - - compareNodeTemplateToNodeDefinition(childNodeTemplate, (JcrNodeDefinition)matchingDefinition); - } - - } - - private void comparePropertyTemplateToPropertyDefinition( JcrPropertyDefinition template, - JcrPropertyDefinition definition ) { - - assertThat(definition, is(notNullValue())); - assertThat(definition.getDeclaringNodeType(), is(notNullValue())); - // Had to match on name to even get to the definition - // assertThat(template.getName(), is(definition.getName())); - - assertThat(template.getValueConstraints(), is(definition.getValueConstraints())); - assertThat(template.getOnParentVersion(), is(definition.getOnParentVersion())); - assertThat(template.getRequiredType(), is(definition.getRequiredType())); - assertThat(template.isAutoCreated(), is(definition.isAutoCreated())); - assertThat(template.isMandatory(), is(definition.isMandatory())); - assertThat(template.isMultiple(), is(definition.isMultiple())); - assertThat(template.isProtected(), is(definition.isProtected())); - } - - private void compareNodeTemplateToNodeDefinition( JcrNodeDefinition template, - JcrNodeDefinition definition ) { - assertThat(definition, is(notNullValue())); - assertThat(definition.getDeclaringNodeType(), is(notNullValue())); - // Had to match on name to even get to the definition - // assertThat(template.getName(), is(definition.getName())); - - assertThat(template.getOnParentVersion(), is(definition.getOnParentVersion())); - assertThat(template.isAutoCreated(), is(definition.isAutoCreated())); - assertThat(template.isMandatory(), is(definition.isMandatory())); - assertThat(template.isProtected(), is(definition.isProtected())); - - assertThat(template.with(repoTypeManager).getDefaultPrimaryType(), is(definition.getDefaultPrimaryType())); - assertThat(template.allowsSameNameSiblings(), is(definition.allowsSameNameSiblings())); - - // assertThat(template.getRequiredPrimaryTypeNames(), is(definition.getRequiredPrimaryTypeNames())); - - } +// +// @Test( expected = AssertionError.class ) +// public void shouldNotAllowNullDefinition() throws Exception { +// repoTypeManager.registerNodeTypes(null); +// } +// +// @Test( expected = AssertionError.class ) +// public void shouldNotAllowTemplateWithNullContext() throws Exception { +// repoTypeManager.registerNodeTypes(sourceFor(new JcrNodeType(null, AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, +// nameFor(TEST_TYPE_NAME), Arrays.asList(new JcrNodeType[] {}), +// AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, +// AbstractJcrNodeTypeSource.NO_CHILD_NODES, +// AbstractJcrNodeTypeSource.NO_PROPERTIES, +// AbstractJcrNodeTypeSource.NOT_MIXIN, +// AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES))); +// } +// +// @Test( expected = RepositoryException.class ) +// public void shouldNotAllowNodeTypeWithNoName() throws Exception { +// ntTemplate = new JcrNodeType(context, AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, null, +// Arrays.asList(new JcrNodeType[] {}), AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, +// AbstractJcrNodeTypeSource.NO_CHILD_NODES, AbstractJcrNodeTypeSource.NO_PROPERTIES, +// AbstractJcrNodeTypeSource.NOT_MIXIN, AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); +// repoTypeManager.registerNodeTypes(sourceFor(ntTemplate)); +// } +// +// @Test +// public void shouldAllowNewDefinitionWithNoChildNodesOrProperties() throws Exception { +// Name testTypeName = nameFactory.create(TEST_TYPE_NAME); +// ntTemplate = new JcrNodeType(context, AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, testTypeName, +// Arrays.asList(new JcrNodeType[] {}), AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, +// AbstractJcrNodeTypeSource.NO_CHILD_NODES, AbstractJcrNodeTypeSource.NO_PROPERTIES, +// AbstractJcrNodeTypeSource.NOT_MIXIN, AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); +// +// List testNodeTypes = repoTypeManager.registerNodeTypes(sourceFor(ntTemplate)); +// JcrNodeType testNodeType = testNodeTypes.get(0); +// +// assertThat(testNodeType.getName(), is(TEST_TYPE_NAME)); +// JcrNodeType nodeTypeFromRepo = repoTypeManager.getNodeType(testTypeName); +// assertThat(nodeTypeFromRepo, is(notNullValue())); +// assertThat(nodeTypeFromRepo.getName(), is(TEST_TYPE_NAME)); +// } +// +// // @Test( expected = RepositoryException.class ) +// // public void shouldNotAllowModificationIfAllowUpdatesIsFalse() throws Exception { +// // ntTemplate.setName("nt:base"); +// // repoTypeManager.registerNodeType(ntTemplate, false); +// // } +// +// // @Test( expected = RepositoryException.class ) +// // public void shouldNotAllowRedefinitionOfNewTypeIfAllowUpdatesIsFalse() throws Exception { +// // Name testTypeName = nameFactory.create(TEST_TYPE_NAME); +// // ntTemplate.setName(TEST_TYPE_NAME); +// // ntTemplate.setDeclaredSupertypeNames(new String[] {"nt:base"}); +// // +// // JcrNodeType testNodeType = repoTypeManager.registerNodeType(ntTemplate, false); +// // +// // assertThat(testNodeType.getName(), is(TEST_TYPE_NAME)); +// // JcrNodeType nodeTypeFromRepo = repoTypeManager.getNodeType(testTypeName); +// // assertThat(nodeTypeFromRepo, is(notNullValue())); +// // assertThat(nodeTypeFromRepo.getName(), is(TEST_TYPE_NAME)); +// // +// // testNodeType = repoTypeManager.registerNodeType(ntTemplate, false); +// // } +// +// @Test +// public void shouldAllowDefinitionWithExistingSupertypes() throws Exception { +// Name testTypeName = nameFactory.create(TEST_TYPE_NAME); +// +// ntTemplate = new JcrNodeType(context, AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, testTypeName, +// Arrays.asList(new JcrNodeType[] {base, referenceable}), +// AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, AbstractJcrNodeTypeSource.NO_CHILD_NODES, +// AbstractJcrNodeTypeSource.NO_PROPERTIES, AbstractJcrNodeTypeSource.NOT_MIXIN, +// AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); +// +// List testNodeTypes = repoTypeManager.registerNodeTypes(sourceFor(ntTemplate)); +// JcrNodeType testNodeType = testNodeTypes.get(0); +// +// assertThat(testNodeType.getName(), is(TEST_TYPE_NAME)); +// JcrNodeType nodeTypeFromRepo = repoTypeManager.getNodeType(testTypeName); +// assertThat(nodeTypeFromRepo, is(notNullValue())); +// assertThat(nodeTypeFromRepo.getName(), is(TEST_TYPE_NAME)); +// +// } +// +// @Test +// public void shouldAllowDefinitionWithSupertypesFromTypesRegisteredInSameCall() throws Exception { +// ntTemplate = new JcrNodeType(context, AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, nameFor(TEST_TYPE_NAME), +// Arrays.asList(new JcrNodeType[] {base, referenceable}), +// AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, AbstractJcrNodeTypeSource.NO_CHILD_NODES, +// AbstractJcrNodeTypeSource.NO_PROPERTIES, AbstractJcrNodeTypeSource.NOT_MIXIN, +// AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); +// +// JcrNodeType ntTemplate2 = new JcrNodeType(context, AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, +// nameFor(TEST_TYPE_NAME2), Arrays.asList(new JcrNodeType[] {ntTemplate}), +// AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, +// AbstractJcrNodeTypeSource.NO_CHILD_NODES, +// AbstractJcrNodeTypeSource.NO_PROPERTIES, AbstractJcrNodeTypeSource.NOT_MIXIN, +// AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); +// +// List templates = Arrays.asList(new JcrNodeType[] {ntTemplate, ntTemplate2}); +// compareTemplatesToNodeTypes(templates, repoTypeManager.registerNodeTypes(sourceFor(ntTemplate, ntTemplate2))); +// } +// +// @Test( expected = RepositoryException.class ) +// public void shouldNotAllowDefinitionWithSupertypesFromTypesRegisteredInSameCallInWrongOrder() throws Exception { +// // Try to register the supertype AFTER the class that registers it +// ntTemplate = new JcrNodeType(context, AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, nameFor(TEST_TYPE_NAME), +// Arrays.asList(new JcrNodeType[] {base, referenceable}), +// AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, AbstractJcrNodeTypeSource.NO_CHILD_NODES, +// AbstractJcrNodeTypeSource.NO_PROPERTIES, AbstractJcrNodeTypeSource.NOT_MIXIN, +// AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); +// +// JcrNodeType ntTemplate2 = new JcrNodeType(context, AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, +// nameFor(TEST_TYPE_NAME2), Arrays.asList(new JcrNodeType[] {ntTemplate}), +// AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, +// AbstractJcrNodeTypeSource.NO_CHILD_NODES, +// AbstractJcrNodeTypeSource.NO_PROPERTIES, AbstractJcrNodeTypeSource.NOT_MIXIN, +// AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); +// +// List templates = Arrays.asList(new JcrNodeType[] {ntTemplate2, ntTemplate}); +// compareTemplatesToNodeTypes(templates, repoTypeManager.registerNodeTypes(sourceFor(ntTemplate2, ntTemplate))); +// } +// +// @Test +// public void shouldAllowDefinitionWithAProperty() throws Exception { +// ntTemplate = new JcrNodeType( +// context, +// AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, +// nameFor(TEST_TYPE_NAME), +// Arrays.asList(new JcrNodeType[] {base, referenceable}), +// AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, +// AbstractJcrNodeTypeSource.NO_CHILD_NODES, +// Arrays.asList(new JcrPropertyDefinition[] {new JcrPropertyDefinition( +// context, +// null, +// null, +// OnParentVersionBehavior.VERSION.getJcrValue(), +// false, +// false, +// false, +// AbstractJcrNodeTypeSource.NO_DEFAULT_VALUES, +// PropertyType.LONG, +// AbstractJcrNodeTypeSource.NO_CONSTRAINTS, +// false)}), +// AbstractJcrNodeTypeSource.NOT_MIXIN, AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); +// +// List templates = Arrays.asList(new JcrNodeType[] {ntTemplate}); +// compareTemplatesToNodeTypes(templates, repoTypeManager.registerNodeTypes(sourceFor(ntTemplate))); +// } +// +// @Test +// public void shouldAllowDefinitionWithProperties() throws Exception { +// +// ntTemplate = new JcrNodeType(context, AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, nameFor(TEST_TYPE_NAME), +// Arrays.asList(new JcrNodeType[] {base, referenceable}), +// AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, AbstractJcrNodeTypeSource.NO_CHILD_NODES, +// Arrays.asList(new JcrPropertyDefinition[] { +// new JcrPropertyDefinition(context, null, null, +// OnParentVersionBehavior.VERSION.getJcrValue(), false, false, +// false, AbstractJcrNodeTypeSource.NO_DEFAULT_VALUES, +// PropertyType.LONG, AbstractJcrNodeTypeSource.NO_CONSTRAINTS, +// false), +// new JcrPropertyDefinition(context, null, null, +// OnParentVersionBehavior.VERSION.getJcrValue(), false, false, +// false, AbstractJcrNodeTypeSource.NO_DEFAULT_VALUES, +// PropertyType.STRING, AbstractJcrNodeTypeSource.NO_CONSTRAINTS, +// true), +// new JcrPropertyDefinition(context, null, nameFor(TEST_PROPERTY_NAME), +// OnParentVersionBehavior.VERSION.getJcrValue(), false, false, +// false, AbstractJcrNodeTypeSource.NO_DEFAULT_VALUES, +// PropertyType.STRING, AbstractJcrNodeTypeSource.NO_CONSTRAINTS, +// false)}), AbstractJcrNodeTypeSource.NOT_MIXIN, +// AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); +// +// List templates = Arrays.asList(new JcrNodeType[] {ntTemplate}); +// compareTemplatesToNodeTypes(templates, repoTypeManager.registerNodeTypes(sourceFor(ntTemplate))); +// +// } +// +// @Test( expected = RepositoryException.class ) +// public void shouldNotAllowAutocreatedPropertyWithNoDefault() throws Exception { +// ntTemplate = new JcrNodeType( +// context, +// AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, +// nameFor(TEST_TYPE_NAME), +// Arrays.asList(new JcrNodeType[] {base, referenceable}), +// AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, +// AbstractJcrNodeTypeSource.NO_CHILD_NODES, +// Arrays.asList(new JcrPropertyDefinition[] {new JcrPropertyDefinition( +// context, +// null, +// nameFor(TEST_PROPERTY_NAME), +// OnParentVersionBehavior.VERSION.getJcrValue(), +// true, +// false, +// false, +// AbstractJcrNodeTypeSource.NO_DEFAULT_VALUES, +// PropertyType.LONG, +// AbstractJcrNodeTypeSource.NO_CONSTRAINTS, +// false),}), +// AbstractJcrNodeTypeSource.NOT_MIXIN, AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); +// +// List templates = Arrays.asList(new JcrNodeType[] {ntTemplate}); +// compareTemplatesToNodeTypes(templates, repoTypeManager.registerNodeTypes(sourceFor(ntTemplate))); +// +// } +// +// @Test( expected = RepositoryException.class ) +// public void shouldNotAllowAutocreatedResidualProperty() throws Exception { +// ntTemplate = new JcrNodeType( +// context, +// AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, +// nameFor(TEST_TYPE_NAME), +// Arrays.asList(new JcrNodeType[] {base, referenceable}), +// AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, +// AbstractJcrNodeTypeSource.NO_CHILD_NODES, +// Arrays.asList(new JcrPropertyDefinition[] {new JcrPropertyDefinition( +// context, +// null, +// null, +// OnParentVersionBehavior.VERSION.getJcrValue(), +// true, +// false, +// false, +// AbstractJcrNodeTypeSource.NO_DEFAULT_VALUES, +// PropertyType.UNDEFINED, +// AbstractJcrNodeTypeSource.NO_CONSTRAINTS, +// false),}), +// AbstractJcrNodeTypeSource.NOT_MIXIN, AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); +// +// List templates = Arrays.asList(new JcrNodeType[] {ntTemplate}); +// compareTemplatesToNodeTypes(templates, repoTypeManager.registerNodeTypes(sourceFor(ntTemplate))); +// +// } +// +// // @Test +// // public void shouldAllowAutocreatedNamedPropertyWithDefault() throws Exception { +// // ntTemplate.setName(TEST_TYPE_NAME); +// // ntTemplate.setDeclaredSupertypeNames(new String[] {"nt:base", "mix:referenceable"}); +// // +// // JcrPropertyDefinitionTemplate prop = new JcrPropertyDefinitionTemplate(this.context); +// // prop.setName(TEST_PROPERTY_NAME); +// // prop.setRequiredType(PropertyType.UNDEFINED); +// // prop.setAutoCreated(true); +// // prop.setDefaultValues(new String[] {""}); +// // ntTemplate.getPropertyDefinitionTemplates().add(prop); +// // +// // List templates = Arrays.asList(new NodeTypeDefinition[] {ntTemplate}); +// // compareTemplatesToNodeTypes(templates, repoTypeManager.registerNodeTypes(templates, false)); +// // } +// // +// // @Test( expected = RepositoryException.class ) +// // public void shouldNotAllowSingleValuedPropertyWithMultipleDefaults() throws Exception { +// // ntTemplate.setName(TEST_TYPE_NAME); +// // ntTemplate.setDeclaredSupertypeNames(new String[] {"nt:base", "mix:referenceable"}); +// // +// // JcrPropertyDefinitionTemplate prop = new JcrPropertyDefinitionTemplate(this.context); +// // prop.setName(TEST_PROPERTY_NAME); +// // prop.setRequiredType(PropertyType.UNDEFINED); +// // prop.setAutoCreated(true); +// // prop.setDefaultValues(new String[] {"", "too many values"}); +// // ntTemplate.getPropertyDefinitionTemplates().add(prop); +// // +// // List templates = Arrays.asList(new NodeTypeDefinition[] {ntTemplate}); +// // compareTemplatesToNodeTypes(templates, repoTypeManager.registerNodeTypes(templates, false)); +// // } +// +// @Test( expected = RepositoryException.class ) +// public void shouldNotAllowMandatoryResidualProperty() throws Exception { +// ntTemplate = new JcrNodeType( +// context, +// AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, +// nameFor(TEST_TYPE_NAME), +// Arrays.asList(new JcrNodeType[] {base, referenceable}), +// AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, +// AbstractJcrNodeTypeSource.NO_CHILD_NODES, +// Arrays.asList(new JcrPropertyDefinition[] {new JcrPropertyDefinition( +// context, +// null, +// null, +// OnParentVersionBehavior.VERSION.getJcrValue(), +// false, +// true, +// false, +// AbstractJcrNodeTypeSource.NO_DEFAULT_VALUES, +// PropertyType.UNDEFINED, +// AbstractJcrNodeTypeSource.NO_CONSTRAINTS, +// false),}), +// AbstractJcrNodeTypeSource.NOT_MIXIN, AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); +// +// List templates = Arrays.asList(new JcrNodeType[] {ntTemplate}); +// compareTemplatesToNodeTypes(templates, repoTypeManager.registerNodeTypes(sourceFor(ntTemplate))); +// +// } +// +// @Test +// public void shouldAllowTypeWithChildNode() throws Exception { +// ntTemplate = new JcrNodeType( +// context, +// AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, +// nameFor(TEST_TYPE_NAME), +// Arrays.asList(new JcrNodeType[] {base, referenceable}), +// AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, +// Arrays.asList(new JcrNodeDefinition[] {new JcrNodeDefinition( +// context, +// null, +// nameFor(TEST_CHILD_NODE_NAME), +// OnParentVersionBehavior.VERSION.getJcrValue(), +// false, false, false, true, +// JcrNtLexicon.BASE, +// new JcrNodeType[] {base})}), +// AbstractJcrNodeTypeSource.NO_PROPERTIES, AbstractJcrNodeTypeSource.NOT_MIXIN, +// AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); +// +// List templates = Arrays.asList(new JcrNodeType[] {ntTemplate}); +// compareTemplatesToNodeTypes(templates, repoTypeManager.registerNodeTypes(sourceFor(ntTemplate))); +// +// } +// +// @Test +// public void shouldAllowTypeWithMultipleChildNodes() throws Exception { +// ntTemplate = new JcrNodeType( +// context, +// AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, +// nameFor(TEST_TYPE_NAME), +// Arrays.asList(new JcrNodeType[] {base, referenceable}), +// AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, +// Arrays.asList(new JcrNodeDefinition[] { +// new JcrNodeDefinition(context, null, nameFor(TEST_CHILD_NODE_NAME), +// OnParentVersionBehavior.VERSION.getJcrValue(), false, false, +// false, true, JcrNtLexicon.BASE, new JcrNodeType[] {base}), +// new JcrNodeDefinition(context, null, nameFor(TEST_CHILD_NODE_NAME), +// OnParentVersionBehavior.VERSION.getJcrValue(), false, false, +// false, false, JcrNtLexicon.BASE, new JcrNodeType[] {unstructured}), +// new JcrNodeDefinition(context, null, nameFor(TEST_CHILD_NODE_NAME + "2"), +// OnParentVersionBehavior.VERSION.getJcrValue(), false, false, +// false, true, JcrNtLexicon.BASE, new JcrNodeType[] {base}), +// +// }), AbstractJcrNodeTypeSource.NO_PROPERTIES, AbstractJcrNodeTypeSource.NOT_MIXIN, +// AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); +// +// List templates = Arrays.asList(new JcrNodeType[] {ntTemplate}); +// compareTemplatesToNodeTypes(templates, repoTypeManager.registerNodeTypes(sourceFor(ntTemplate))); +// } +// +// @Test( expected = RepositoryException.class ) +// public void shouldNotAllowAutocreatedChildNodeWithNoDefaultPrimaryType() throws Exception { +// ntTemplate = new JcrNodeType( +// context, +// AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, +// nameFor(TEST_TYPE_NAME), +// Arrays.asList(new JcrNodeType[] {base, referenceable}), +// AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, +// Arrays.asList(new JcrNodeDefinition[] {new JcrNodeDefinition( +// context, +// null, +// nameFor(TEST_CHILD_NODE_NAME), +// OnParentVersionBehavior.VERSION.getJcrValue(), +// true, false, false, false, +// null, new JcrNodeType[] {base}),}), +// AbstractJcrNodeTypeSource.NO_PROPERTIES, AbstractJcrNodeTypeSource.NOT_MIXIN, +// AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); +// +// List templates = Arrays.asList(new JcrNodeType[] {ntTemplate}); +// compareTemplatesToNodeTypes(templates, repoTypeManager.registerNodeTypes(sourceFor(ntTemplate))); +// } +// +// @Test( expected = RepositoryException.class ) +// public void shouldNotAllowMandatoryResidualChildNode() throws Exception { +// ntTemplate = new JcrNodeType( +// context, +// AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, +// nameFor(TEST_TYPE_NAME), +// Arrays.asList(new JcrNodeType[] {base, referenceable}), +// AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, +// Arrays.asList(new JcrNodeDefinition[] {new JcrNodeDefinition( +// context, +// null, +// null, +// OnParentVersionBehavior.VERSION.getJcrValue(), +// false, true, false, false, +// JcrNtLexicon.BASE, +// new JcrNodeType[] {base}),}), +// AbstractJcrNodeTypeSource.NO_PROPERTIES, AbstractJcrNodeTypeSource.NOT_MIXIN, +// AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); +// +// List templates = Arrays.asList(new JcrNodeType[] {ntTemplate}); +// compareTemplatesToNodeTypes(templates, repoTypeManager.registerNodeTypes(sourceFor(ntTemplate))); +// } +// +// @Test( expected = RepositoryException.class ) +// public void shouldNotAllowOverridingProtectedProperty() throws Exception { +// ntTemplate = new JcrNodeType( +// context, +// AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, +// nameFor(TEST_TYPE_NAME), +// Arrays.asList(new JcrNodeType[] {base, referenceable}), +// AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, +// AbstractJcrNodeTypeSource.NO_CHILD_NODES, +// Arrays.asList(new JcrPropertyDefinition[] {new JcrPropertyDefinition( +// context, +// null, +// JcrLexicon.PRIMARY_TYPE, +// OnParentVersionBehavior.VERSION.getJcrValue(), +// false, +// false, +// false, +// AbstractJcrNodeTypeSource.NO_DEFAULT_VALUES, +// PropertyType.NAME, +// AbstractJcrNodeTypeSource.NO_CONSTRAINTS, +// false),}), +// AbstractJcrNodeTypeSource.NOT_MIXIN, AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); +// +// List templates = Arrays.asList(new JcrNodeType[] {ntTemplate}); +// compareTemplatesToNodeTypes(templates, repoTypeManager.registerNodeTypes(sourceFor(ntTemplate))); +// +// } +// +// @Test( expected = RepositoryException.class ) +// public void shouldNotAllowOverridingProtectedChildNode() throws Exception { +// ntTemplate = new JcrNodeType( +// context, +// AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, +// nameFor(TEST_TYPE_NAME), +// Arrays.asList(new JcrNodeType[] {root, referenceable}), +// AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, +// Arrays.asList(new JcrNodeDefinition[] {new JcrNodeDefinition( +// context, +// null, +// JcrLexicon.SYSTEM, +// OnParentVersionBehavior.VERSION.getJcrValue(), +// false, false, false, false, +// JcrNtLexicon.BASE, +// new JcrNodeType[] {base}),}), +// AbstractJcrNodeTypeSource.NO_PROPERTIES, AbstractJcrNodeTypeSource.NOT_MIXIN, +// AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); +// +// List templates = Arrays.asList(new JcrNodeType[] {ntTemplate}); +// compareTemplatesToNodeTypes(templates, repoTypeManager.registerNodeTypes(sourceFor(ntTemplate))); +// } +// +// @Test( expected = RepositoryException.class ) +// public void shouldNotAllowOverridingMandatoryChildNodeWithOptionalChildNode() throws Exception { +// ntTemplate = new JcrNodeType( +// context, +// AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, +// nameFor(TEST_TYPE_NAME), +// Arrays.asList(new JcrNodeType[] {file}), +// AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, +// Arrays.asList(new JcrNodeDefinition[] {new JcrNodeDefinition( +// context, +// null, +// JcrLexicon.CONTENT, +// OnParentVersionBehavior.VERSION.getJcrValue(), +// false, false, false, false, +// JcrNtLexicon.BASE, +// new JcrNodeType[] {base}),}), +// AbstractJcrNodeTypeSource.NO_PROPERTIES, AbstractJcrNodeTypeSource.NOT_MIXIN, +// AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); +// +// List templates = Arrays.asList(new JcrNodeType[] {ntTemplate}); +// compareTemplatesToNodeTypes(templates, repoTypeManager.registerNodeTypes(sourceFor(ntTemplate))); +// +// } +// +// @Test +// public void shouldAllowOverridingPropertyFromCommonAncestor() throws Exception { +// /* +// * testNode declares prop testProperty +// * testNodeB extends testNode +// * testNodeC extends testNode +// * testNodeD extends testNodeB and testNodeC and overrides testProperty --> LEGAL +// */ +// +// ntTemplate = new JcrNodeType( +// context, +// AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, +// nameFor(TEST_TYPE_NAME), +// Arrays.asList(new JcrNodeType[] {base, referenceable}), +// AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, +// AbstractJcrNodeTypeSource.NO_CHILD_NODES, +// Arrays.asList(new JcrPropertyDefinition[] {new JcrPropertyDefinition( +// context, +// null, +// nameFor(TEST_PROPERTY_NAME), +// OnParentVersionBehavior.VERSION.getJcrValue(), +// false, +// false, +// false, +// AbstractJcrNodeTypeSource.NO_DEFAULT_VALUES, +// PropertyType.UNDEFINED, +// AbstractJcrNodeTypeSource.NO_CONSTRAINTS, +// false),}), +// AbstractJcrNodeTypeSource.NOT_MIXIN, AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); +// +// JcrNodeType nodeBTemplate = new JcrNodeType(context, AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, +// nameFor(TEST_TYPE_NAME + "B"), Arrays.asList(new JcrNodeType[] {ntTemplate}), +// AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, +// AbstractJcrNodeTypeSource.NO_CHILD_NODES, +// AbstractJcrNodeTypeSource.NO_PROPERTIES, AbstractJcrNodeTypeSource.NOT_MIXIN, +// AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); +// +// JcrNodeType nodeCTemplate = new JcrNodeType(context, AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, +// nameFor(TEST_TYPE_NAME + "C"), Arrays.asList(new JcrNodeType[] {ntTemplate}), +// AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, +// AbstractJcrNodeTypeSource.NO_CHILD_NODES, +// AbstractJcrNodeTypeSource.NO_PROPERTIES, AbstractJcrNodeTypeSource.NOT_MIXIN, +// AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); +// +// JcrNodeType nodeDTemplate = new JcrNodeType( +// context, +// AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, +// nameFor(TEST_TYPE_NAME + "D"), +// Arrays.asList(new JcrNodeType[] {nodeBTemplate, nodeCTemplate}), +// AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, +// AbstractJcrNodeTypeSource.NO_CHILD_NODES, +// Arrays.asList(new JcrPropertyDefinition[] {new JcrPropertyDefinition( +// context, +// null, +// nameFor(TEST_PROPERTY_NAME), +// OnParentVersionBehavior.VERSION.getJcrValue(), +// false, +// false, +// false, +// AbstractJcrNodeTypeSource.NO_DEFAULT_VALUES, +// PropertyType.STRING, +// AbstractJcrNodeTypeSource.NO_CONSTRAINTS, +// false),}), +// AbstractJcrNodeTypeSource.NOT_MIXIN, +// AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); +// +// List templates = Arrays.asList(new JcrNodeType[] {ntTemplate, nodeBTemplate, nodeCTemplate, nodeDTemplate}); +// compareTemplatesToNodeTypes(templates, repoTypeManager.registerNodeTypes(sourceFor(ntTemplate, +// nodeBTemplate, +// nodeCTemplate, +// nodeDTemplate))); +// } +// +// @Test( expected = RepositoryException.class ) +// public void shouldNotAllowOverridingPropertyFromDifferentAncestors() throws Exception { +// /* +// * testNode +// * testNodeB extends testNode and declares prop testProperty +// * testNodeC extends testNode and declares prop testProperty +// * testNodeD extends testNodeB and testNodeC and overrides testProperty --> ILLEGAL +// */ +// +// ntTemplate = new JcrNodeType(context, AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, nameFor(TEST_TYPE_NAME), +// Arrays.asList(new JcrNodeType[] {base, referenceable}), +// AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, AbstractJcrNodeTypeSource.NO_CHILD_NODES, +// AbstractJcrNodeTypeSource.NO_PROPERTIES, AbstractJcrNodeTypeSource.NOT_MIXIN, +// AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); +// +// JcrNodeType nodeBTemplate = new JcrNodeType( +// context, +// AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, +// nameFor(TEST_TYPE_NAME + "B"), +// Arrays.asList(new JcrNodeType[] {ntTemplate}), +// AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, +// AbstractJcrNodeTypeSource.NO_CHILD_NODES, +// Arrays.asList(new JcrPropertyDefinition[] {new JcrPropertyDefinition( +// context, +// null, +// nameFor(TEST_PROPERTY_NAME), +// OnParentVersionBehavior.VERSION.getJcrValue(), +// false, +// false, +// false, +// AbstractJcrNodeTypeSource.NO_DEFAULT_VALUES, +// PropertyType.UNDEFINED, +// AbstractJcrNodeTypeSource.NO_CONSTRAINTS, +// false),}), +// AbstractJcrNodeTypeSource.NOT_MIXIN, +// AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); +// +// JcrNodeType nodeCTemplate = new JcrNodeType( +// context, +// AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, +// nameFor(TEST_TYPE_NAME + "C"), +// Arrays.asList(new JcrNodeType[] {ntTemplate}), +// AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, +// AbstractJcrNodeTypeSource.NO_CHILD_NODES, +// Arrays.asList(new JcrPropertyDefinition[] {new JcrPropertyDefinition( +// context, +// null, +// nameFor(TEST_PROPERTY_NAME), +// OnParentVersionBehavior.VERSION.getJcrValue(), +// false, +// false, +// false, +// AbstractJcrNodeTypeSource.NO_DEFAULT_VALUES, +// PropertyType.UNDEFINED, +// AbstractJcrNodeTypeSource.NO_CONSTRAINTS, +// false),}), +// AbstractJcrNodeTypeSource.NOT_MIXIN, +// AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); +// +// JcrNodeType nodeDTemplate = new JcrNodeType( +// context, +// AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, +// nameFor(TEST_TYPE_NAME + "D"), +// Arrays.asList(new JcrNodeType[] {nodeBTemplate, nodeCTemplate}), +// AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, +// AbstractJcrNodeTypeSource.NO_CHILD_NODES, +// Arrays.asList(new JcrPropertyDefinition[] {new JcrPropertyDefinition( +// context, +// null, +// nameFor(TEST_PROPERTY_NAME), +// OnParentVersionBehavior.VERSION.getJcrValue(), +// false, +// false, +// false, +// AbstractJcrNodeTypeSource.NO_DEFAULT_VALUES, +// PropertyType.STRING, +// AbstractJcrNodeTypeSource.NO_CONSTRAINTS, +// false),}), +// AbstractJcrNodeTypeSource.NOT_MIXIN, +// AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); +// +// List templates = Arrays.asList(new JcrNodeType[] {ntTemplate, nodeBTemplate, nodeCTemplate, nodeDTemplate}); +// compareTemplatesToNodeTypes(templates, repoTypeManager.registerNodeTypes(sourceFor(ntTemplate, +// nodeBTemplate, +// nodeCTemplate, +// nodeDTemplate))); +// } +// +// @Test +// public void shouldAllowOverridingChildNodeFromCommonAncestor() throws Exception { +// /* +// * testNode declares node testChildNode +// * testNodeB extends testNode +// * testNodeC extends testNode +// * testNodeD extends testNodeB and testNodeC and overrides testChildNode --> LEGAL +// */ +// ntTemplate = new JcrNodeType( +// context, +// AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, +// nameFor(TEST_TYPE_NAME), +// Arrays.asList(new JcrNodeType[] {base, referenceable}), +// AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, +// Arrays.asList(new JcrNodeDefinition[] {new JcrNodeDefinition( +// context, +// null, +// null, +// OnParentVersionBehavior.VERSION.getJcrValue(), +// false, false, false, false, +// JcrNtLexicon.BASE, +// new JcrNodeType[] {base}),}), +// AbstractJcrNodeTypeSource.NO_PROPERTIES, AbstractJcrNodeTypeSource.NOT_MIXIN, +// AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); +// +// JcrNodeType nodeBTemplate = new JcrNodeType(context, AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, +// nameFor(TEST_TYPE_NAME + "B"), Arrays.asList(new JcrNodeType[] {ntTemplate}), +// AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, +// AbstractJcrNodeTypeSource.NO_CHILD_NODES, +// AbstractJcrNodeTypeSource.NO_PROPERTIES, AbstractJcrNodeTypeSource.NOT_MIXIN, +// AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); +// +// JcrNodeType nodeCTemplate = new JcrNodeType(context, AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, +// nameFor(TEST_TYPE_NAME + "C"), Arrays.asList(new JcrNodeType[] {ntTemplate}), +// AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, +// AbstractJcrNodeTypeSource.NO_CHILD_NODES, +// AbstractJcrNodeTypeSource.NO_PROPERTIES, AbstractJcrNodeTypeSource.NOT_MIXIN, +// AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); +// +// JcrNodeType nodeDTemplate = new JcrNodeType( +// context, +// AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, +// nameFor(TEST_TYPE_NAME + "D"), +// Arrays.asList(new JcrNodeType[] {nodeBTemplate, nodeCTemplate}), +// AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, +// Arrays.asList(new JcrNodeDefinition[] {new JcrNodeDefinition( +// context, +// null, +// JcrLexicon.SYSTEM, +// OnParentVersionBehavior.VERSION.getJcrValue(), +// false, +// false, +// false, +// false, +// JcrNtLexicon.UNSTRUCTURED, +// new JcrNodeType[] {unstructured}),}), +// AbstractJcrNodeTypeSource.NO_PROPERTIES, AbstractJcrNodeTypeSource.NOT_MIXIN, +// +// AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); +// +// List templates = Arrays.asList(new JcrNodeType[] {ntTemplate, nodeBTemplate, nodeCTemplate, nodeDTemplate}); +// compareTemplatesToNodeTypes(templates, repoTypeManager.registerNodeTypes(sourceFor(ntTemplate, +// nodeBTemplate, +// nodeCTemplate, +// nodeDTemplate))); +// } +// +// @Test( expected = RepositoryException.class ) +// public void shouldNotAllowOverridingChildNodeFromDifferentAncestors() throws Exception { +// /* +// * testNode +// * testNodeB extends testNode and declares node testChildNode +// * testNodeC extends testNode and declares node testChildNode +// * testNodeD extends testNodeB and testNodeC and overrides testChildNode --> ILLEGAL +// */ +// ntTemplate = new JcrNodeType(context, AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, nameFor(TEST_TYPE_NAME), +// Arrays.asList(new JcrNodeType[] {base, referenceable}), +// AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, AbstractJcrNodeTypeSource.NO_CHILD_NODES, +// AbstractJcrNodeTypeSource.NO_PROPERTIES, AbstractJcrNodeTypeSource.NOT_MIXIN, +// AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); +// +// JcrNodeType nodeBTemplate = new JcrNodeType( +// context, +// AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, +// nameFor(TEST_TYPE_NAME + "B"), +// Arrays.asList(new JcrNodeType[] {ntTemplate}), +// AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, +// Arrays.asList(new JcrNodeDefinition[] {new JcrNodeDefinition( +// context, +// null, +// null, +// OnParentVersionBehavior.VERSION.getJcrValue(), +// false, +// false, +// false, +// false, +// JcrNtLexicon.BASE, +// new JcrNodeType[] {base}),}), +// +// AbstractJcrNodeTypeSource.NO_PROPERTIES, AbstractJcrNodeTypeSource.NOT_MIXIN, +// AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); +// +// JcrNodeType nodeCTemplate = new JcrNodeType( +// context, +// AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, +// nameFor(TEST_TYPE_NAME + "C"), +// Arrays.asList(new JcrNodeType[] {ntTemplate}), +// AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, +// Arrays.asList(new JcrNodeDefinition[] {new JcrNodeDefinition( +// context, +// null, +// null, +// OnParentVersionBehavior.VERSION.getJcrValue(), +// false, +// false, +// false, +// false, +// JcrNtLexicon.BASE, +// new JcrNodeType[] {base}),}), +// +// AbstractJcrNodeTypeSource.NO_PROPERTIES, AbstractJcrNodeTypeSource.NOT_MIXIN, +// AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); +// +// JcrNodeType nodeDTemplate = new JcrNodeType( +// context, +// AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, +// nameFor(TEST_TYPE_NAME + "D"), +// Arrays.asList(new JcrNodeType[] {nodeBTemplate, nodeCTemplate}), +// AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, +// Arrays.asList(new JcrNodeDefinition[] {new JcrNodeDefinition( +// context, +// null, +// JcrLexicon.SYSTEM, +// OnParentVersionBehavior.VERSION.getJcrValue(), +// false, +// false, +// false, +// false, +// JcrNtLexicon.UNSTRUCTURED, +// new JcrNodeType[] {unstructured}),}), +// AbstractJcrNodeTypeSource.NO_PROPERTIES, AbstractJcrNodeTypeSource.NOT_MIXIN, +// +// AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); +// +// List templates = Arrays.asList(new JcrNodeType[] {ntTemplate, nodeBTemplate, nodeCTemplate, nodeDTemplate}); +// compareTemplatesToNodeTypes(templates, repoTypeManager.registerNodeTypes(sourceFor(ntTemplate, +// nodeBTemplate, +// nodeCTemplate, +// nodeDTemplate))); +// } +// +// @Test( expected = RepositoryException.class ) +// public void shouldNotAllowExtendingChildNodeIfSnsChanges() throws Exception { +// /* +// * testNode declares node testChildNode with no SNS +// * testNodeB extends testNode with node testChildNode with SNS -> ILLEGAL +// */ +// ntTemplate = new JcrNodeType( +// context, +// AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, +// nameFor(TEST_TYPE_NAME), +// Arrays.asList(new JcrNodeType[] {base, referenceable}), +// AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, +// Arrays.asList(new JcrNodeDefinition[] {new JcrNodeDefinition( +// context, +// null, +// nameFor(TEST_CHILD_NODE_NAME), +// OnParentVersionBehavior.VERSION.getJcrValue(), +// false, false, false, false, +// null, new JcrNodeType[] {root}),}), +// AbstractJcrNodeTypeSource.NO_PROPERTIES, AbstractJcrNodeTypeSource.NOT_MIXIN, +// AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); +// +// JcrNodeType nodeBTemplate = new JcrNodeType( +// context, +// AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, +// nameFor(TEST_TYPE_NAME + "B"), +// Arrays.asList(new JcrNodeType[] {ntTemplate}), +// AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, +// Arrays.asList(new JcrNodeDefinition[] {new JcrNodeDefinition( +// context, +// null, +// nameFor(TEST_CHILD_NODE_NAME), +// OnParentVersionBehavior.VERSION.getJcrValue(), +// false, +// false, +// false, +// true, +// JcrNtLexicon.UNSTRUCTURED, +// new JcrNodeType[] {unstructured}),}), +// +// AbstractJcrNodeTypeSource.NO_PROPERTIES, AbstractJcrNodeTypeSource.NOT_MIXIN, +// AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); +// +// List templates = Arrays.asList(new JcrNodeType[] {ntTemplate, nodeBTemplate,}); +// compareTemplatesToNodeTypes(templates, repoTypeManager.registerNodeTypes(sourceFor(ntTemplate, nodeBTemplate))); +// +// } +// +// @Test +// public void shouldAllowExtendingPropertyIfMultipleChanges() throws Exception { +// /* +// * testNode declares SV property testProperty +// * testNodeB extends testNode with MV property testProperty with incompatible type -> LEGAL +// * testNodeC extends testNode, testNodeB -> LEGAL +// */ +// ntTemplate = new JcrNodeType( +// context, +// AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, +// nameFor(TEST_TYPE_NAME), +// Arrays.asList(new JcrNodeType[] {base, referenceable}), +// AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, +// AbstractJcrNodeTypeSource.NO_CHILD_NODES, +// Arrays.asList(new JcrPropertyDefinition[] {new JcrPropertyDefinition( +// context, +// null, +// nameFor(TEST_PROPERTY_NAME), +// OnParentVersionBehavior.VERSION.getJcrValue(), +// false, +// false, +// false, +// AbstractJcrNodeTypeSource.NO_DEFAULT_VALUES, +// PropertyType.LONG, +// AbstractJcrNodeTypeSource.NO_CONSTRAINTS, +// false),}), +// AbstractJcrNodeTypeSource.NOT_MIXIN, AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); +// +// JcrNodeType nodeBTemplate = new JcrNodeType( +// context, +// AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, +// nameFor(TEST_TYPE_NAME + "B"), +// Arrays.asList(new JcrNodeType[] {ntTemplate}), +// AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, +// AbstractJcrNodeTypeSource.NO_CHILD_NODES, +// Arrays.asList(new JcrPropertyDefinition[] {new JcrPropertyDefinition( +// context, +// null, +// nameFor(TEST_PROPERTY_NAME), +// OnParentVersionBehavior.VERSION.getJcrValue(), +// false, +// false, +// false, +// AbstractJcrNodeTypeSource.NO_DEFAULT_VALUES, +// PropertyType.DATE, +// AbstractJcrNodeTypeSource.NO_CONSTRAINTS, +// true),}), +// AbstractJcrNodeTypeSource.NOT_MIXIN, +// AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); +// +// JcrNodeType nodeCTemplate = new JcrNodeType(context, AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, +// nameFor(TEST_TYPE_NAME + "C"), Arrays.asList(new JcrNodeType[] {ntTemplate, +// nodeBTemplate}), AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, +// AbstractJcrNodeTypeSource.NO_CHILD_NODES, +// AbstractJcrNodeTypeSource.NO_PROPERTIES, AbstractJcrNodeTypeSource.NOT_MIXIN, +// AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); +// +// List templates = Arrays.asList(new JcrNodeType[] {ntTemplate, nodeBTemplate, nodeCTemplate,}); +// compareTemplatesToNodeTypes(templates, repoTypeManager.registerNodeTypes(sourceFor(ntTemplate, +// nodeBTemplate, +// nodeCTemplate))); +// } +// +// @Test +// public void shouldAllowOverridingPropertyIfTypeNarrows() throws Exception { +// /* +// * testNode declares SV property testProperty of type UNDEFINED +// * testNodeB extends testNode with SV property testProperty of type STRING -> LEGAL +// */ +// ntTemplate = new JcrNodeType( +// context, +// AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, +// nameFor(TEST_TYPE_NAME), +// Arrays.asList(new JcrNodeType[] {base, referenceable}), +// AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, +// AbstractJcrNodeTypeSource.NO_CHILD_NODES, +// Arrays.asList(new JcrPropertyDefinition[] {new JcrPropertyDefinition( +// context, +// null, +// nameFor(TEST_PROPERTY_NAME), +// OnParentVersionBehavior.VERSION.getJcrValue(), +// false, +// false, +// false, +// AbstractJcrNodeTypeSource.NO_DEFAULT_VALUES, +// PropertyType.STRING, +// AbstractJcrNodeTypeSource.NO_CONSTRAINTS, +// false),}), +// AbstractJcrNodeTypeSource.NOT_MIXIN, AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); +// +// JcrNodeType nodeBTemplate = new JcrNodeType( +// context, +// AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, +// nameFor(TEST_TYPE_NAME + "B"), +// Arrays.asList(new JcrNodeType[] {ntTemplate}), +// AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, +// AbstractJcrNodeTypeSource.NO_CHILD_NODES, +// Arrays.asList(new JcrPropertyDefinition[] {new JcrPropertyDefinition( +// context, +// null, +// nameFor(TEST_PROPERTY_NAME), +// OnParentVersionBehavior.VERSION.getJcrValue(), +// false, +// false, +// false, +// AbstractJcrNodeTypeSource.NO_DEFAULT_VALUES, +// PropertyType.LONG, +// AbstractJcrNodeTypeSource.NO_CONSTRAINTS, +// false),}), +// AbstractJcrNodeTypeSource.NOT_MIXIN, +// AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); +// +// List templates = Arrays.asList(new JcrNodeType[] {ntTemplate, nodeBTemplate,}); +// compareTemplatesToNodeTypes(templates, repoTypeManager.registerNodeTypes(sourceFor(ntTemplate, nodeBTemplate))); +// } +// +// @Test( expected = RepositoryException.class ) +// public void shouldNotAllowOverridingPropertyIfTypeDoesNotNarrow() throws Exception { +// /* +// * testNode declares SV property testProperty of type DATE +// * testNodeB extends testNode with SV property testProperty of type NAME -> ILLEGAL +// */ +// ntTemplate = new JcrNodeType( +// context, +// AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, +// nameFor(TEST_TYPE_NAME), +// Arrays.asList(new JcrNodeType[] {base, referenceable}), +// AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, +// AbstractJcrNodeTypeSource.NO_CHILD_NODES, +// Arrays.asList(new JcrPropertyDefinition[] {new JcrPropertyDefinition( +// context, +// null, +// nameFor(TEST_PROPERTY_NAME), +// OnParentVersionBehavior.VERSION.getJcrValue(), +// false, +// false, +// false, +// AbstractJcrNodeTypeSource.NO_DEFAULT_VALUES, +// PropertyType.DATE, +// AbstractJcrNodeTypeSource.NO_CONSTRAINTS, +// false),}), +// AbstractJcrNodeTypeSource.NOT_MIXIN, AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); +// +// JcrNodeType nodeBTemplate = new JcrNodeType( +// context, +// AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, +// nameFor(TEST_TYPE_NAME + "B"), +// Arrays.asList(new JcrNodeType[] {ntTemplate}), +// AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, +// AbstractJcrNodeTypeSource.NO_CHILD_NODES, +// Arrays.asList(new JcrPropertyDefinition[] {new JcrPropertyDefinition( +// context, +// null, +// nameFor(TEST_PROPERTY_NAME), +// OnParentVersionBehavior.VERSION.getJcrValue(), +// false, +// false, +// false, +// AbstractJcrNodeTypeSource.NO_DEFAULT_VALUES, +// PropertyType.NAME, +// AbstractJcrNodeTypeSource.NO_CONSTRAINTS, +// false),}), +// AbstractJcrNodeTypeSource.NOT_MIXIN, +// AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); +// +// List templates = Arrays.asList(new JcrNodeType[] {ntTemplate, nodeBTemplate,}); +// compareTemplatesToNodeTypes(templates, repoTypeManager.registerNodeTypes(sourceFor(ntTemplate, nodeBTemplate))); +// } +// +// @Test +// public void shouldAllowOverridingChildNodeIfRequiredTypesNarrow() throws Exception { +// /* +// * testNode declares No-SNS childNode testChildNode requiring type nt:hierarchy +// * testNodeB extends testNode with No-SNS childNode testChildNode requiring type nt:file -> LEGAL +// */ +// ntTemplate = new JcrNodeType( +// context, +// AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, +// nameFor(TEST_TYPE_NAME), +// Arrays.asList(new JcrNodeType[] {base, referenceable}), +// AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, +// Arrays.asList(new JcrNodeDefinition[] {new JcrNodeDefinition( +// context, +// null, +// nameFor(TEST_CHILD_NODE_NAME), +// OnParentVersionBehavior.VERSION.getJcrValue(), +// false, +// false, +// false, +// false, +// null, +// new JcrNodeType[] {hierarchyNode}),}), +// AbstractJcrNodeTypeSource.NO_PROPERTIES, AbstractJcrNodeTypeSource.NOT_MIXIN, +// AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); +// +// JcrNodeType nodeBTemplate = new JcrNodeType( +// context, +// AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, +// nameFor(TEST_TYPE_NAME + "B"), +// Arrays.asList(new JcrNodeType[] {ntTemplate}), +// AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, +// Arrays.asList(new JcrNodeDefinition[] {new JcrNodeDefinition( +// context, +// null, +// nameFor(TEST_CHILD_NODE_NAME), +// OnParentVersionBehavior.VERSION.getJcrValue(), +// false, +// false, +// false, +// true, +// null, +// new JcrNodeType[] {file}),}), +// +// AbstractJcrNodeTypeSource.NO_PROPERTIES, AbstractJcrNodeTypeSource.NOT_MIXIN, +// AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); +// +// List templates = Arrays.asList(new JcrNodeType[] {ntTemplate, nodeBTemplate,}); +// compareTemplatesToNodeTypes(templates, repoTypeManager.registerNodeTypes(sourceFor(ntTemplate, nodeBTemplate))); +// +// } +// +// @Test( expected = RepositoryException.class ) +// public void shouldNotAllowOverridingChildNodeIfRequiredTypesDoNotNarrow() throws Exception { +// /* +// * testNode declares No-SNS childNode testChildNode requiring type nt:hierarchy +// * testNodeB extends testNode with No-SNS childNode testChildNode requiring type nt:base -> ILLEGAL +// */ +// ntTemplate = new JcrNodeType( +// context, +// AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, +// nameFor(TEST_TYPE_NAME), +// Arrays.asList(new JcrNodeType[] {base, referenceable}), +// AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, +// Arrays.asList(new JcrNodeDefinition[] {new JcrNodeDefinition( +// context, +// null, +// nameFor(TEST_CHILD_NODE_NAME), +// OnParentVersionBehavior.VERSION.getJcrValue(), +// false, +// false, +// false, +// false, +// null, +// new JcrNodeType[] {hierarchyNode}),}), +// AbstractJcrNodeTypeSource.NO_PROPERTIES, AbstractJcrNodeTypeSource.NOT_MIXIN, +// AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); +// +// JcrNodeType nodeBTemplate = new JcrNodeType( +// context, +// AbstractJcrNodeTypeSource.NO_NODE_TYPE_MANAGER, +// nameFor(TEST_TYPE_NAME + "B"), +// Arrays.asList(new JcrNodeType[] {ntTemplate}), +// AbstractJcrNodeTypeSource.NO_PRIMARY_ITEM_NAME, +// Arrays.asList(new JcrNodeDefinition[] {new JcrNodeDefinition( +// context, +// null, +// nameFor(TEST_CHILD_NODE_NAME), +// OnParentVersionBehavior.VERSION.getJcrValue(), +// false, +// false, +// false, +// true, +// null, +// new JcrNodeType[] {base}),}), +// +// AbstractJcrNodeTypeSource.NO_PROPERTIES, AbstractJcrNodeTypeSource.NOT_MIXIN, +// AbstractJcrNodeTypeSource.UNORDERABLE_CHILD_NODES); +// +// List templates = Arrays.asList(new JcrNodeType[] {ntTemplate, nodeBTemplate,}); +// compareTemplatesToNodeTypes(templates, repoTypeManager.registerNodeTypes(sourceFor(ntTemplate, nodeBTemplate))); +// +// } +// +// private void compareTemplatesToNodeTypes( List templates, +// List nodeTypes ) { +// assertThat(templates.size(), is(nodeTypes.size())); +// +// for (int i = 0; i < nodeTypes.size(); i++) { +// JcrNodeType jntt = templates.get(i); +// compareTemplateToNodeType(jntt, null); +// compareTemplateToNodeType(jntt, nodeTypes.get(i)); +// } +// } +// +// private void compareTemplateToNodeType( JcrNodeType template, +// JcrNodeType nodeType ) { +// Name nodeTypeName = nameFactory.create(template.getName()); +// if (nodeType == null) { +// nodeType = repoTypeManager.getNodeType(nodeTypeName); +// assertThat(nodeType.nodeTypeManager(), is(notNullValue())); +// } +// +// assertThat(nodeType, is(notNullValue())); +// assertThat(nodeType.getName(), is(template.getName())); +// +// assertThat(nodeType.getDeclaredSupertypes().length, is(template.getDeclaredSupertypes().length)); +// for (int i = 0; i < template.getDeclaredSupertypes().length; i++) { +// assertThat(template.getDeclaredSupertypes()[i].getName(), is(nodeType.getDeclaredSupertypes()[i].getName())); +// } +// assertThat(template.isMixin(), is(nodeType.isMixin())); +// assertThat(template.hasOrderableChildNodes(), is(nodeType.hasOrderableChildNodes())); +// +// PropertyDefinition[] propertyDefs = nodeType.getDeclaredPropertyDefinitions(); +// List propertyTemplates = Arrays.asList(template.getDeclaredPropertyDefinitions()); +// +// assertThat(propertyDefs.length, is(propertyTemplates.size())); +// for (JcrPropertyDefinition pt : propertyTemplates) { +// JcrPropertyDefinition propertyTemplate = pt; +// +// PropertyDefinition matchingDefinition = null; +// for (int i = 0; i < propertyDefs.length; i++) { +// PropertyDefinition pd = propertyDefs[i]; +// +// String ptName = propertyTemplate.getName() == null ? JcrNodeType.RESIDUAL_ITEM_NAME : propertyTemplate.getName(); +// if (pd.getName().equals(ptName) && pd.getRequiredType() == propertyTemplate.getRequiredType() +// && pd.isMultiple() == propertyTemplate.isMultiple()) { +// matchingDefinition = pd; +// break; +// } +// } +// +// comparePropertyTemplateToPropertyDefinition(propertyTemplate, (JcrPropertyDefinition)matchingDefinition); +// } +// +// NodeDefinition[] childNodeDefs = nodeType.getDeclaredChildNodeDefinitions(); +// List childNodeTemplates = Arrays.asList(template.getDeclaredChildNodeDefinitions()); +// +// assertThat(childNodeDefs.length, is(childNodeTemplates.size())); +// for (JcrNodeDefinition nt : childNodeTemplates) { +// JcrNodeDefinition childNodeTemplate = nt; +// +// NodeDefinition matchingDefinition = null; +// for (int i = 0; i < childNodeDefs.length; i++) { +// JcrNodeDefinition nd = (JcrNodeDefinition)childNodeDefs[i]; +// +// String ntName = childNodeTemplate.getName() == null ? JcrNodeType.RESIDUAL_ITEM_NAME : childNodeTemplate.getName(); +// if (nd.getName().equals(ntName) && nd.allowsSameNameSiblings() == childNodeTemplate.allowsSameNameSiblings()) { +// +// boolean matchesOnRequiredTypes = childNodeTemplate.getRequiredPrimaryTypeNames() +// .equals(nd.getRequiredPrimaryTypeNames()); +// +// if (matchesOnRequiredTypes) { +// matchingDefinition = nd; +// break; +// } +// } +// } +// +// compareNodeTemplateToNodeDefinition(childNodeTemplate, (JcrNodeDefinition)matchingDefinition); +// } +// +// } +// +// private void comparePropertyTemplateToPropertyDefinition( JcrPropertyDefinition template, +// JcrPropertyDefinition definition ) { +// +// assertThat(definition, is(notNullValue())); +// assertThat(definition.getDeclaringNodeType(), is(notNullValue())); +// // Had to match on name to even get to the definition +// // assertThat(template.getName(), is(definition.getName())); +// +// assertThat(template.getValueConstraints(), is(definition.getValueConstraints())); +// assertThat(template.getOnParentVersion(), is(definition.getOnParentVersion())); +// assertThat(template.getRequiredType(), is(definition.getRequiredType())); +// assertThat(template.isAutoCreated(), is(definition.isAutoCreated())); +// assertThat(template.isMandatory(), is(definition.isMandatory())); +// assertThat(template.isMultiple(), is(definition.isMultiple())); +// assertThat(template.isProtected(), is(definition.isProtected())); +// } +// +// private void compareNodeTemplateToNodeDefinition( JcrNodeDefinition template, +// JcrNodeDefinition definition ) { +// assertThat(definition, is(notNullValue())); +// assertThat(definition.getDeclaringNodeType(), is(notNullValue())); +// // Had to match on name to even get to the definition +// // assertThat(template.getName(), is(definition.getName())); +// +// assertThat(template.getOnParentVersion(), is(definition.getOnParentVersion())); +// assertThat(template.isAutoCreated(), is(definition.isAutoCreated())); +// assertThat(template.isMandatory(), is(definition.isMandatory())); +// assertThat(template.isProtected(), is(definition.isProtected())); +// +// assertThat(template.with(repoTypeManager).getDefaultPrimaryType(), is(definition.getDefaultPrimaryType())); +// assertThat(template.allowsSameNameSiblings(), is(definition.allowsSameNameSiblings())); +// +// // assertThat(template.getRequiredPrimaryTypeNames(), is(definition.getRequiredPrimaryTypeNames())); +// +// } } Index: dna-jcr/src/test/resources/cndNodeTypeRegistration/existingType.cnd =================================================================== --- dna-jcr/src/test/resources/cndNodeTypeRegistration/existingType.cnd (revision 0) +++ dna-jcr/src/test/resources/cndNodeTypeRegistration/existingType.cnd (revision 0) @@ -0,0 +1,12 @@ +/* + * Redefinition of existing type + */ + + + + + + + +[nt:folder] > nt:base +- jcr:resource (string) primary protected version Index: dna-jcr/src/test/resources/cndNodeTypeRegistration/validType.cnd =================================================================== --- dna-jcr/src/test/resources/cndNodeTypeRegistration/validType.cnd (revision 0) +++ dna-jcr/src/test/resources/cndNodeTypeRegistration/validType.cnd (revision 0) @@ -0,0 +1,13 @@ +/* + * Valid test type + */ + + + + + + +[dnatest:testType] > mix:referenceable, mix:lockable mixin orderable ++ dnatest:namespace (dna:namespace) = dna:namespace protected version +- * (string) = 'foo' version < 'foo', 'bar', 'baz' + Index: dna-jcr/src/test/resources/tck_test_types.cnd =================================================================== --- dna-jcr/src/test/resources/tck_test_types.cnd (revision 0) +++ dna-jcr/src/test/resources/tck_test_types.cnd (revision 0) @@ -0,0 +1,23 @@ +/* + * Extra Node Types for JR TCK Test + */ + + + + + +[dnatest:noSameNameSibs] ++ * (nt:base) = nt:unstructured + +[dnatest:referenceableUnstructured] > nt:unstructured, mix:referenceable + +[dnatest:nodeWithMandatoryProperty] > nt:unstructured, mix:referenceable +- dnatest:mandatoryString (*) mandatory copy + +[dnatest:nodeWithMandatoryChild] > nt:unstructured, mix:referenceable ++ dnatest:mandatoryChild (nt:base) = nt:unstructured mandatory version + +[dnatest:unorderableUnstructured] +- * (*) copy +- * (*) multiple copy ++ * (nt:base) = dnatest:unorderableUnstructured multiple version