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 kw...@apache.org on 2021/10/25 06:40:25 UTC

[jackrabbit-oak] branch trunk updated: OAK-9584 add failing but ignored test when accessing rep:authorizableId via expanded name (#376)

This is an automated email from the ASF dual-hosted git repository.

kwin pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git


The following commit(s) were added to refs/heads/trunk by this push:
     new ca5367d  OAK-9584 add failing but ignored test when accessing rep:authorizableId via expanded name (#376)
ca5367d is described below

commit ca5367d8279ab72b8b839bc751ec4f817b4dc45f
Author: Konrad Windszus <kw...@apache.org>
AuthorDate: Mon Oct 25 08:40:19 2021 +0200

    OAK-9584 add failing but ignored test when accessing rep:authorizableId via expanded name (#376)
    
    add custom rule to ignore JUnit4 tests given via "known.issues"
---
 oak-jcr/pom.xml                                    |   1 +
 .../apache/jackrabbit/oak/jcr/ValidNamesTest.java  |  23 ++++
 .../oak/jcr/util/KnownIssuesIgnoreRule.java        | 130 +++++++++++++++++++++
 oak-parent/pom.xml                                 |   6 +
 4 files changed, 160 insertions(+)

diff --git a/oak-jcr/pom.xml b/oak-jcr/pom.xml
index 5f33bc1..f85da55 100644
--- a/oak-jcr/pom.xml
+++ b/oak-jcr/pom.xml
@@ -52,6 +52,7 @@
       org.apache.jackrabbit.test.api.WorkspaceCopyTest#testCopyNodesLocked                             <!-- OAK-118 -->
       org.apache.jackrabbit.test.api.WorkspaceMoveSameNameSibsTest#testMoveNodesOrderingSupportedByParent <!-- OAK-118 -->
       org.apache.jackrabbit.test.api.WorkspaceMoveTest#testMoveNodesLocked                             <!-- OAK-118 -->
+      org.apache.jackrabbit.oak.jcr.ValidNamesTest#testRepNamespaceUri                                 <!-- OAK-74 -->
 
       <!-- Locking : not fully implemented -->
       org.apache.jackrabbit.test.api.lock.LockTest#testNodeLocked <!-- OAK-3482 -->
diff --git a/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/ValidNamesTest.java b/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/ValidNamesTest.java
index bcff29c..bcd7671 100644
--- a/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/ValidNamesTest.java
+++ b/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/ValidNamesTest.java
@@ -32,17 +32,25 @@ import javax.jcr.Repository;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 
+import org.apache.jackrabbit.api.JackrabbitSession;
+import org.apache.jackrabbit.api.security.user.User;
+import org.apache.jackrabbit.api.security.user.UserManager;
 import org.apache.jackrabbit.oak.fixture.NodeStoreFixture;
+import org.apache.jackrabbit.oak.jcr.util.KnownIssuesIgnoreRule;
 import org.apache.jackrabbit.oak.spi.state.NodeStore;
 import org.junit.After;
 import org.junit.AfterClass;
 import org.junit.Before;
+import org.junit.Rule;
 import org.junit.Test;
 
 import com.google.common.collect.Maps;
 
 public class ValidNamesTest extends AbstractRepositoryTest {
 
+    @Rule
+    public KnownIssuesIgnoreRule customIgnoreRule = new KnownIssuesIgnoreRule();
+    
     private static final String TEST_NODE = "test_node";
     private static final String TEST_PATH = '/' + TEST_NODE;
     private static final Map<NodeStoreFixture, NodeStore> STORES = Maps.newConcurrentMap();
@@ -235,6 +243,21 @@ public class ValidNamesTest extends AbstractRepositoryTest {
         assertEquals(testPrefix + ":foo", n.getName());
     }
 
+    // OAK-74 and OAK-9584
+    @Test
+    public void testRepNamespaceUri() throws RepositoryException {
+        JackrabbitSession jrSession = (JackrabbitSession)session;
+        UserManager userManager = jrSession.getUserManager();
+        User user = userManager.createUser("test", "test");
+
+        session.save();
+        Node n = session.getNode(user.getPath());
+
+        String repNamespaceUri = session.getNamespaceURI("rep");
+        assertTrue(n.hasProperty("rep:authorizableId"));
+        assertTrue(n.hasProperty("{"+repNamespaceUri+"}authorizableId"));
+    }
+ 
     // TODO: questionable exception
     @Test
     public void testValidNamespaceUriInCurlysWrongPlace() {
diff --git a/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/util/KnownIssuesIgnoreRule.java b/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/util/KnownIssuesIgnoreRule.java
new file mode 100644
index 0000000..a64f594
--- /dev/null
+++ b/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/util/KnownIssuesIgnoreRule.java
@@ -0,0 +1,130 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.oak.jcr.util;
+
+import java.util.HashSet;
+import java.util.Set;
+import java.util.StringTokenizer;
+
+import org.apache.jackrabbit.test.AbstractJCRTest;
+import org.apache.jackrabbit.test.JCRTestResult;
+import org.junit.Assume;
+import org.junit.rules.MethodRule;
+import org.junit.runners.model.FrameworkMethod;
+import org.junit.runners.model.Statement;
+
+/**
+ * Evaluates the system properties "known.issues" and "known.issues.override" to skip failing for certain test method failures.
+ * This is the JUnit4 equivalent of {@link JCRTestResult} which is used by the JUnit3 base class {@link AbstractJCRTest}.
+ */
+public class KnownIssuesIgnoreRule implements MethodRule {
+
+    /**
+     * Set of Strings that identify the test methods that currently fails but
+     * are recognized as known issues. Those will not be reported as errors.
+     */
+    private static final Set<String> KNOWN_ISSUES = tokenize("known.issues");
+    private static final Set<String> KNOWN_ISSUES_OVERRIDE = tokenize("known.issues.override");
+
+    // copied from https://github.com/apache/jackrabbit/blob/ed3124e5fe223dada33ce6ddf53bc666063c3f2f/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/JCRTestResult.java#L161-L177
+    /**
+     * Takes the named system property and returns the set of string tokens
+     * in the property value. Returns an empty set if the named property does
+     * not exist.
+     *
+     * @param name name of the system property
+     * @return set of string tokens
+     */
+    private static Set<String> tokenize(String name) {
+        Set<String> tokens = new HashSet<String>();
+        StringTokenizer tokenizer =
+            new StringTokenizer(System.getProperty(name, ""));
+        while (tokenizer.hasMoreTokens()) {
+            tokens.add(tokenizer.nextToken());
+        }
+        return tokens;
+    }
+    
+    // similar to https://github.com/apache/jackrabbit/blob/ed3124e5fe223dada33ce6ddf53bc666063c3f2f/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/JCRTestResult.java#L179-L215
+    /**
+     * Checks if a variation of the name of the given test case is included
+     * in the given set of token. The tested variations are:
+     * <ul>
+     *   <li>package name</li>
+     *   <li>non-qualified class name</li>
+     *   <li>fully qualified class name</li>
+     *   <li>non-qualified method name</li>
+     *   <li>class-qualified method name</li>
+     *   <li>fully-qualified method name</li>
+     * </ul>
+     *
+     * @param tokens set of string tokens
+     * @param className the fully qualified class name
+     * @param methodName the method name
+     * @return <code>true</code> if the test case name is included,
+     *         <code>false</code> otherwise
+     */
+    private static boolean contains(Set<String> tokens, String className, String methodName) {
+        int i = className.lastIndexOf('.');
+        if (i >= 0) {
+            String packageName = className.substring(0, i);
+            String shortName = className.substring(i + 1);
+            return tokens.contains(packageName)
+                || tokens.contains(shortName)
+                || tokens.contains(className)
+                || tokens.contains(methodName)
+                || tokens.contains(shortName + "#" + methodName)
+                || tokens.contains(className + "#" + methodName);
+        } else {
+            return tokens.contains(className)
+                || tokens.contains(methodName)
+                || tokens.contains(className + "#" + methodName);
+        }
+    }
+   
+    // similar to https://github.com/apache/jackrabbit/blob/ed3124e5fe223dada33ce6ddf53bc666063c3f2f/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/JCRTestResult.java#L217-L231
+    private static boolean isKnownIssue(String className, String methodName) {
+        return contains(KNOWN_ISSUES, className, methodName)
+                && !contains(KNOWN_ISSUES_OVERRIDE, className, methodName);
+    }
+
+
+    @Override
+    public Statement apply(Statement base, FrameworkMethod method, Object target) {
+        return new IgnorableStatement(base, method.getDeclaringClass().getName(), method.getName());
+    }
+
+    private class IgnorableStatement extends Statement {
+
+        private final Statement base;
+        private final String className;
+        private final String methodName;
+
+        public IgnorableStatement(Statement base, String className, String methodName) {
+            this.base = base;
+            this.className = className;
+            this.methodName = methodName;
+        }
+
+        @Override
+        public void evaluate() throws Throwable {
+            Assume.assumeTrue("Test is ignored through system property 'known.issues'!", !isKnownIssue(className, methodName));
+            base.evaluate();
+        }
+    }
+
+}
diff --git a/oak-parent/pom.xml b/oak-parent/pom.xml
index 8b132a0..2f19fd6 100644
--- a/oak-parent/pom.xml
+++ b/oak-parent/pom.xml
@@ -297,6 +297,9 @@
             <argLine>${test.opts}</argLine>
             <trimStackTrace>false</trimStackTrace>
             <systemPropertyVariables>
+              <!-- evaluated in oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/util/KnownIssuesIgnoreRule.java (JUnit4) and
+                   https://github.com/apache/jackrabbit/blob/ed3124e5fe223dada33ce6ddf53bc666063c3f2f/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/AbstractJCRTest.java#L476 (JUnit3)
+               -->
               <known.issues>${known.issues}</known.issues>
               <mongo.host>${mongo.host}</mongo.host>
               <mongo.port>${mongo.port}</mongo.port>
@@ -317,6 +320,9 @@
             <argLine>${test.opts}</argLine>
             <trimStackTrace>false</trimStackTrace>
             <systemPropertyVariables>
+              <!-- evaluated in oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/util/KnownIssuesIgnoreRule.java (JUnit4) and
+                   https://github.com/apache/jackrabbit/blob/ed3124e5fe223dada33ce6ddf53bc666063c3f2f/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/AbstractJCRTest.java#L476 (JUnit3)
+               -->
               <known.issues>${known.issues}</known.issues>
               <mongo.host>${mongo.host}</mongo.host>
               <mongo.port>${mongo.port}</mongo.port>