jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r158754 - in incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test: AbstractJCRTest.java JCRTestResult.java
Date Wed, 23 Mar 2005 11:07:41 GMT
Author: mreutegg
Date: Wed Mar 23 03:07:39 2005
New Revision: 158754

URL: http://svn.apache.org/viewcvs?view=rev&rev=158754
Log:
- Test case should not result in error if NotExecutableException is thrown.

Added:
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/JCRTestResult.java   (with
props)
Modified:
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/AbstractJCRTest.java

Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/AbstractJCRTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/AbstractJCRTest.java?view=diff&r1=158753&r2=158754
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/AbstractJCRTest.java (original)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/AbstractJCRTest.java Wed
Mar 23 03:07:39 2005
@@ -16,6 +16,8 @@
  */
 package org.apache.jackrabbit.test;
 
+import junit.framework.TestResult;
+
 import javax.jcr.Node;
 import javax.jcr.Session;
 import javax.jcr.NodeIterator;
@@ -241,6 +243,7 @@
     protected Node testRootNode;
 
     protected void setUp() throws Exception {
+        super.setUp();
         testRoot = getProperty(RepositoryStub.PROP_TESTROOT);
         if (testRoot == null) {
             fail("Property '" + RepositoryStub.PROP_TESTROOT + "' is not defined.");
@@ -383,9 +386,44 @@
                 superuser.logout();
             }
         }
+        super.tearDown();
     }
 
-    public String getProperty(String name) throws RepositoryException {
+    /**
+     * Runs the test cases of this test class and reports the results to
+     * <code>testResult</code>. In contrast to the default implementation of
+     * <code>TestCase.run()</code> this method will suppress tests errors with
+     * a {@link NotExecutableException}. That is, test cases that throw this
+     * exception will still result as successful.
+     * @param testResult the test result.
+     */
+    public void run(TestResult testResult) {
+        super.run(new JCRTestResult(testResult));
+    }
+
+    /**
+     * Returns the value of the configuration property with <code>propName</code>.
+     * The sequence how configuration properties are read is the follwoing:
+     * <ol>
+     * <li><code>javax.jcr.tck.&lt;testClassName>.&lt;testCaseName>.&lt;propName></code></li>
+     * <li><code>javax.jcr.tck.&lt;testClassName>.&lt;propName></code></li>
+     * <li><code>javax.jcr.tck.&lt;packageName>.&lt;propName></code></li>
+     * <li><code>javax.jcr.tck.&lt;propName></code></li>
+     * </ol>
+     * Where:
+     * <ul>
+     * <li><code>&lt;testClassName></code> is the name of the test
class without package prefix.</li>
+     * <li><code>&lt;testMethodName></code> is the name of the test
method</li>
+     * <li><code>&lt;packageName></code> is the name of the package
of the test class.
+     * Example: packageName for <code>org.apache.jackrabbit.test.api.BooleanPropertyTest</code>:
<code>api</code></li>
+     * </ul>
+     * @param propName the propName of the configration property.
+     * @return the value of the property or <code>null</code> if the property
+     *  does not exist.
+     * @throws RepositoryException if an error occurs while reading from
+     *  the configuration.
+     */
+    public String getProperty(String propName) throws RepositoryException {
         String testCaseName = getName();
         String testClassName = getClass().getName();
         String testPackName = "";
@@ -397,27 +435,27 @@
 
         // 1) test case specific property first
         String value = helper.getProperty(RepositoryStub.PROP_PREFIX + "."
-                + testClassName + "." + testCaseName + "." + name);
+                + testClassName + "." + testCaseName + "." + propName);
         if (value != null) {
             return value;
         }
 
         // 2) check test class property
         value = helper.getProperty(RepositoryStub.PROP_PREFIX + "."
-                + testClassName + "." + name);
+                + testClassName + "." + propName);
         if (value != null) {
             return value;
         }
 
         // 3) check package property
         value = helper.getProperty(RepositoryStub.PROP_PREFIX + "."
-                + testPackName + "." + name);
+                + testPackName + "." + propName);
         if (value != null) {
             return value;
         }
 
         // finally try global property
-        return helper.getProperty(RepositoryStub.PROP_PREFIX + "." + name);
+        return helper.getProperty(RepositoryStub.PROP_PREFIX + "." + propName);
     }
 
     /**

Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/JCRTestResult.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/JCRTestResult.java?view=auto&rev=158754
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/JCRTestResult.java (added)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/JCRTestResult.java Wed
Mar 23 03:07:39 2005
@@ -0,0 +1,110 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed 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.test;
+
+import junit.framework.TestResult;
+import junit.framework.Test;
+import junit.framework.AssertionFailedError;
+import junit.framework.TestListener;
+
+import java.util.Enumeration;
+
+/**
+ * Extends the standard JUnit TestResult class. This class ignores test errors
+ * that originated in throwing a {@link NotExecutableException}.
+ */
+public class JCRTestResult extends TestResult {
+
+    /** The original TestResult we delegate to */
+    private final TestResult orig;
+
+    /**
+     * Creates a new JCRTestResult that delegates to <code>orig</code>.
+     * @param orig the original TestResult this result wraps.
+     */
+    public JCRTestResult(TestResult orig) {
+        this.orig = orig;
+    }
+
+    /**
+     * Only add an error if <code>throwable</code> is not of type
+     * {@link NotExecutableException}.
+     * @param test the test.
+     * @param throwable the exception thrown by the test.
+     */
+    public synchronized void addError(Test test, Throwable throwable) {
+        if (throwable instanceof NotExecutableException) {
+            // ignore
+        } else {
+            orig.addError(test, throwable);
+        }
+    }
+
+    //-----------------------< default overwrites >-----------------------------
+
+    public synchronized void addFailure(Test test, AssertionFailedError assertionFailedError)
{
+        orig.addFailure(test, assertionFailedError);
+    }
+
+    public synchronized void addListener(TestListener testListener) {
+        orig.addListener(testListener);
+    }
+
+    public synchronized void removeListener(TestListener testListener) {
+        orig.removeListener(testListener);
+    }
+
+    public void endTest(Test test) {
+        orig.endTest(test);
+    }
+
+    public synchronized int errorCount() {
+        return orig.errorCount();
+    }
+
+    public synchronized Enumeration errors() {
+        return orig.errors();
+    }
+
+    public synchronized int failureCount() {
+        return orig.failureCount();
+    }
+
+    public synchronized Enumeration failures() {
+        return orig.failures();
+    }
+
+    public synchronized int runCount() {
+        return orig.runCount();
+    }
+
+    public synchronized boolean shouldStop() {
+        return orig.shouldStop();
+    }
+
+    public void startTest(Test test) {
+        orig.startTest(test);
+    }
+
+    public synchronized void stop() {
+        orig.stop();
+    }
+
+    public synchronized boolean wasSuccessful() {
+        return orig.wasSuccessful();
+    }
+}

Propchange: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/JCRTestResult.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message