You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by mr...@apache.org on 2018/11/07 16:38:37 UTC

svn commit: r1846057 - in /jackrabbit/oak/trunk/oak-core/src/test: java/org/apache/jackrabbit/oak/plugins/nodetype/write/NodeTypeRegistryTest.java resources/org/apache/jackrabbit/oak/plugins/nodetype/write/ntResource.cnd

Author: mreutegg
Date: Wed Nov  7 16:38:37 2018
New Revision: 1846057

URL: http://svn.apache.org/viewvc?rev=1846057&view=rev
Log:
OAK-7886: Re-registering node type may corrupt registry

Add ignored test

Added:
    jackrabbit/oak/trunk/oak-core/src/test/resources/org/apache/jackrabbit/oak/plugins/nodetype/write/ntResource.cnd   (with props)
Modified:
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/nodetype/write/NodeTypeRegistryTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/nodetype/write/NodeTypeRegistryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/nodetype/write/NodeTypeRegistryTest.java?rev=1846057&r1=1846056&r2=1846057&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/nodetype/write/NodeTypeRegistryTest.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/nodetype/write/NodeTypeRegistryTest.java Wed Nov  7 16:38:37 2018
@@ -22,6 +22,7 @@ import static com.google.common.collect.
 import static java.nio.charset.StandardCharsets.UTF_8;
 import static org.apache.jackrabbit.JcrConstants.JCR_MIXINTYPES;
 import static org.apache.jackrabbit.JcrConstants.JCR_PRIMARYTYPE;
+import static org.apache.jackrabbit.JcrConstants.NT_BASE;
 import static org.apache.jackrabbit.JcrConstants.NT_FOLDER;
 import static org.apache.jackrabbit.JcrConstants.NT_UNSTRUCTURED;
 import static org.apache.jackrabbit.JcrConstants.JCR_CONTENT;
@@ -40,11 +41,14 @@ import java.io.Closeable;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
+import java.util.Arrays;
 import java.util.List;
 
+import javax.annotation.Nonnull;
 import javax.jcr.NamespaceRegistry;
 import javax.jcr.NoSuchWorkspaceException;
 import javax.jcr.ValueFactory;
+import javax.jcr.nodetype.NodeType;
 import javax.jcr.nodetype.NodeTypeDefinition;
 import javax.jcr.nodetype.NodeTypeManager;
 import javax.jcr.nodetype.NodeTypeTemplate;
@@ -66,6 +70,7 @@ import org.apache.jackrabbit.oak.api.Typ
 import org.apache.jackrabbit.oak.namepath.impl.GlobalNameMapper;
 import org.apache.jackrabbit.oak.namepath.impl.NamePathMapperImpl;
 import org.apache.jackrabbit.oak.plugins.name.ReadOnlyNamespaceRegistry;
+import org.apache.jackrabbit.oak.plugins.name.ReadWriteNamespaceRegistry;
 import org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeDefDiff;
 import org.apache.jackrabbit.oak.plugins.nodetype.ReadOnlyNodeTypeManager;
 import org.apache.jackrabbit.oak.plugins.nodetype.TypeEditorProvider;
@@ -75,9 +80,12 @@ import org.apache.jackrabbit.oak.plugins
 import org.jetbrains.annotations.NotNull;
 import org.junit.After;
 import org.junit.Before;
+import org.junit.Ignore;
 import org.junit.Test;
 
+import static org.hamcrest.Matchers.hasItem;
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
 
 public class NodeTypeRegistryTest {
@@ -223,4 +231,54 @@ public class NodeTypeRegistryTest {
         NodeTypeDefDiff diff = NodeTypeDefDiff.create(beforeDef, afterDef);
         assertFalse(diff.isMajor());
     }
+
+    // OAK-7886
+    @Ignore("OAK-7886")
+    @Test
+    public void reRegisterNtResource() throws Exception {
+        NodeTypeManager ntMgr = new ReadWriteNodeTypeManager() {
+            @Override
+            protected Tree getTypes() {
+                return root.getTree(NODE_TYPES_PATH);
+            }
+
+            @Nonnull
+            @Override
+            protected Root getWriteRoot() {
+                return root;
+            }
+        };
+        ValueFactory vf = new ValueFactoryImpl(
+                root, new NamePathMapperImpl(new GlobalNameMapper(root)));
+        NamespaceRegistry nsReg = new ReadWriteNamespaceRegistry(root) {
+            @Override
+            protected Root getWriteRoot() {
+                return root;
+            }
+        };
+        DefinitionBuilderFactory<NodeTypeTemplate, NamespaceRegistry> factory
+                = new TemplateBuilderFactory(ntMgr, vf, nsReg);
+
+        NodeType ntResource = ntMgr.getNodeType(NT_RESOURCE);
+        List<String> supertypeNames = Arrays.asList(ntResource.getDeclaredSupertypeNames());
+        assertThat(supertypeNames, hasItem(NT_BASE));
+
+        List<NodeTypeTemplate> templates;
+        InputStream in = NodeTypeRegistryTest.class.getResourceAsStream("ntResource.cnd");
+        try {
+            CompactNodeTypeDefReader<NodeTypeTemplate, NamespaceRegistry> reader
+                    = new CompactNodeTypeDefReader<NodeTypeTemplate, NamespaceRegistry>(
+                    new InputStreamReader(in, UTF_8), "ntResource.cnd", factory);
+            templates = reader.getNodeTypeDefinitions();
+        } finally {
+            in.close();
+        }
+        for (NodeTypeTemplate t : templates) {
+            ntMgr.registerNodeType(t, true);
+        }
+
+        ntResource = ntMgr.getNodeType(NT_RESOURCE);
+        supertypeNames = Arrays.asList(ntResource.getDeclaredSupertypeNames());
+        assertThat(supertypeNames, hasItem(NT_BASE));
+    }
 }

Added: jackrabbit/oak/trunk/oak-core/src/test/resources/org/apache/jackrabbit/oak/plugins/nodetype/write/ntResource.cnd
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/resources/org/apache/jackrabbit/oak/plugins/nodetype/write/ntResource.cnd?rev=1846057&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/resources/org/apache/jackrabbit/oak/plugins/nodetype/write/ntResource.cnd (added)
+++ jackrabbit/oak/trunk/oak-core/src/test/resources/org/apache/jackrabbit/oak/plugins/nodetype/write/ntResource.cnd Wed Nov  7 16:38:37 2018
@@ -0,0 +1,23 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+<'nt'='http://www.jcp.org/jcr/nt/1.0'>
+<'jcr'='http://www.jcp.org/jcr/1.0'>
+<'mix'='http://www.jcp.org/jcr/mix/1.0'>
+
+[nt:resource] > mix:lastModified, mix:mimeType, mix:referenceable
+  primaryitem jcr:data
+  - jcr:data (binary) mandatory

Propchange: jackrabbit/oak/trunk/oak-core/src/test/resources/org/apache/jackrabbit/oak/plugins/nodetype/write/ntResource.cnd
------------------------------------------------------------------------------
    svn:eol-style = native