OPENJPA-1234:

AllowFailure checks for system property before running or logging exceptions from test methods.

git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@802587 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Dick 2009-08-09 20:38:58 +00:00
parent 3ec9136da7
commit fb2a45a739
3 changed files with 43 additions and 14 deletions

View File

@ -57,7 +57,7 @@ public class SimpleEntity implements Serializable {
@Id @Id
@GeneratedValue @GeneratedValue
@Column(name = "ID") @Column(name = "ID",columnDefinition="")
private long id; private long id;
@Basic @Basic

View File

@ -41,6 +41,7 @@
<dbcp.args>MaxActive=${dbcp.maxActive},MaxIdle=${dbcp.maxIdle},MinIdle=${dbcp.minIdle},MaxWait=${dbcp.maxWait}</dbcp.args> <dbcp.args>MaxActive=${dbcp.maxActive},MaxIdle=${dbcp.maxIdle},MinIdle=${dbcp.minIdle},MaxWait=${dbcp.maxWait}</dbcp.args>
<derby.locks.waitTimeout>60</derby.locks.waitTimeout> <derby.locks.waitTimeout>60</derby.locks.waitTimeout>
<derby.locks.deadlockTimeout>5</derby.locks.deadlockTimeout> <derby.locks.deadlockTimeout>5</derby.locks.deadlockTimeout>
<tests.openjpa.allowfailure>ignore</tests.openjpa.allowfailure>
</properties> </properties>
<profiles> <profiles>
@ -80,6 +81,10 @@
<name>openjpa.ConnectionProperties</name> <name>openjpa.ConnectionProperties</name>
<value>DriverClassName=${connection.driver.name},Url=${connection.url},Username=${connection.username},Password=${connection.password},${dbcp.args}</value> <value>DriverClassName=${connection.driver.name},Url=${connection.url},Username=${connection.username},Password=${connection.password},${dbcp.args}</value>
</property> </property>
<property>
<name>tests.openjpa.allowfailure</name>
<value>${tests.openjpa.allowfailure}</value>
</property>
</systemProperties> </systemProperties>
</configuration> </configuration>
</plugin> </plugin>
@ -855,6 +860,10 @@
<name>openjpa.ConnectionProperties</name> <name>openjpa.ConnectionProperties</name>
<value>DriverClassName=${connection.driver.name},Url=${connection.url},Username=${connection.username},Password=${connection.password},${dbcp.args}</value> <value>DriverClassName=${connection.driver.name},Url=${connection.url},Username=${connection.username},Password=${connection.password},${dbcp.args}</value>
</property> </property>
<property>
<name>tests.openjpa.allowfailure</name>
<value>${tests.openjpa.allowfailure}</value>
</property>
</systemProperties> </systemProperties>
</configuration> </configuration>
</plugin> </plugin>

View File

@ -66,6 +66,12 @@ public abstract class PersistenceTestCase
public static final String RETAIN_DATA = "Retain data after test run"; public static final String RETAIN_DATA = "Retain data after test run";
private boolean retainDataOnTearDown; private boolean retainDataOnTearDown;
protected boolean _fresh = false; protected boolean _fresh = false;
public static String ALLOW_FAILURE_LOG = "log";
public static String ALLOW_FAILURE_IGNORE = "ignore";
public static String ALLOW_FAILURE_SYS_PROP= "tests.openjpa.allowfailure";
private static String allowFailureConfig = System.getProperty(ALLOW_FAILURE_SYS_PROP, ALLOW_FAILURE_IGNORE);
/** /**
* Marker object you pass to {@link #setUp} to indicate that the * Marker object you pass to {@link #setUp} to indicate that the
* database table rows should be cleared. * database table rows should be cleared.
@ -469,16 +475,26 @@ public abstract class PersistenceTestCase
*/ */
@Override @Override
public void runBare() throws Throwable { public void runBare() throws Throwable {
if (!isRunsOnCurrentPlatform()) if (!isRunsOnCurrentPlatform()) {
return; return;
}
runBare(getAllowFailure());
}
protected void runBare(AllowFailure allowFailureAnnotation) throws Throwable {
boolean allowFailureValue = allowFailureAnnotation == null ? false : allowFailureAnnotation.value();
if(allowFailureValue) {
if(ALLOW_FAILURE_IGNORE.equalsIgnoreCase(allowFailureConfig)){
return; // skip this test
}
else {
try { try {
super.runBare(); super.runBare();
} catch (Throwable t) { } catch (Throwable t) {
AllowFailure allowFailure = getAllowFailure(); if (ALLOW_FAILURE_LOG.equalsIgnoreCase(allowFailureConfig)) {
if ( allowFailure != null && allowFailure.value()==true) {
System.err.println("*** FAILED (but ignored): " + this); System.err.println("*** FAILED (but ignored): " + this);
System.err.println("*** Reason : " System.err.println("*** Reason : " + allowFailureAnnotation.message());
+ allowFailure.message());
System.err.println("Stacktrace of failure"); System.err.println("Stacktrace of failure");
t.printStackTrace(); t.printStackTrace();
} else { } else {
@ -486,6 +502,10 @@ public abstract class PersistenceTestCase
} }
} }
} }
} else {
super.runBare();
}
}
/** /**
* Affirms if the test case or the test method is annotated with * Affirms if the test case or the test method is annotated with