openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ppod...@apache.org
Subject svn commit: r713084 - in /openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test: AllowFailure.java PersistenceTestCase.java
Date Tue, 11 Nov 2008 17:01:43 GMT
Author: ppoddar
Date: Tue Nov 11 09:01:42 2008
New Revision: 713084

URL: http://svn.apache.org/viewvc?rev=713084&view=rev
Log:
OPENJPA-766: Allow Tests that fail to be included in the repository. Annotate the TestCase
or its specific methods with @AllowFailure(true|false)

Added:
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/AllowFailure.java
Modified:
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/PersistenceTestCase.java

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/AllowFailure.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/AllowFailure.java?rev=713084&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/AllowFailure.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/AllowFailure.java
Tue Nov 11 09:01:42 2008
@@ -0,0 +1,37 @@
+/**
+ * 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.openjpa.persistence.test;
+
+import java.lang.annotation.Target;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.ElementType.METHOD;
+import java.lang.annotation.Retention;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+/**
+ * Signals to the harness to ignore if the annotated test case/method fail.
+ * 
+ * @author Pinaki Poddar
+ *
+ */
+@Target({TYPE, METHOD})
+@Retention(RUNTIME)
+public @interface AllowFailure {
+    boolean value() default true;
+}

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/PersistenceTestCase.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/PersistenceTestCase.java?rev=713084&r1=713083&r2=713084&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/PersistenceTestCase.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/PersistenceTestCase.java
Tue Nov 11 09:01:42 2008
@@ -23,6 +23,7 @@
 import java.io.IOException;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
+import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
 import java.sql.SQLException;
 import java.util.ArrayList;
@@ -34,6 +35,7 @@
 import javax.persistence.EntityManagerFactory;
 import javax.persistence.Persistence;
 
+import junit.framework.AssertionFailedError;
 import junit.framework.TestCase;
 import junit.framework.TestResult;
 import org.apache.openjpa.kernel.AbstractBrokerFactory;
@@ -402,6 +404,43 @@
 			return;
 		printException(t.getCause(), tab+2);
 	}
-
-
+    
+    /**
+     * Overrides to allow tests annotated with @AllowFailure to fail. 
+     * If the test is in error then the normal pathway is executed.
+     */
+    @Override
+    public void runBare() throws Throwable {
+        try {
+            super.runBare();
+        } catch (Throwable t) {
+            if (allowFailure() && t instanceof AssertionFailedError) {
+                System.err.println("*** Failed but ignored:" + this);
+            } else {
+                throw t;
+            }
+        }
+    }
+    
+    /**
+     * Affirms if the test case or the test method is annotated with 
+     * @AllowFailure. Method level annotation has higher precedence than Class
+     * level annotation.
+     */
+    protected boolean allowFailure() {
+		try {
+            Method runMethod = getClass().getMethod(getName(), (Class[])null);
+            AllowFailure anno = runMethod.getAnnotation(AllowFailure.class);
+	    	if (anno != null)
+	    		return anno.value();
+		} catch (SecurityException e) {
+			//ignore
+		} catch (NoSuchMethodException e) {
+			//ignore
+		}
+		AllowFailure anno = getClass().getAnnotation(AllowFailure.class);
+    	if (anno != null) 
+            return anno.value();
+    	return false;
+    }
 }



Mime
View raw message