core tests no longer failing
This commit is contained in:
parent
21bc0e8cc4
commit
b00ed51536
|
@ -48,7 +48,6 @@ public class SessionFactorySerializationTest extends BaseUnitTestCase {
|
|||
public static final String NAME = "mySF";
|
||||
|
||||
@Test
|
||||
@FailureExpectedWithNewMetamodel
|
||||
public void testNamedSessionFactorySerialization() throws Exception {
|
||||
Configuration cfg = new Configuration()
|
||||
.setProperty( AvailableSettings.SESSION_FACTORY_NAME, NAME )
|
||||
|
@ -75,7 +74,6 @@ public class SessionFactorySerializationTest extends BaseUnitTestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
@FailureExpectedWithNewMetamodel
|
||||
public void testUnNamedSessionFactorySerialization() throws Exception {
|
||||
// IMPL NOTE : this test is a control to testNamedSessionFactorySerialization
|
||||
// here, the test should fail based just on attempted uuid resolution
|
||||
|
|
|
@ -46,6 +46,7 @@ import org.hibernate.SessionFactory;
|
|||
import org.hibernate.Transaction;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.testing.DialectChecks;
|
||||
import org.hibernate.testing.FailureExpected;
|
||||
import org.hibernate.testing.FailureExpectedWithNewMetamodel;
|
||||
import org.hibernate.testing.RequiresDialectFeature;
|
||||
import org.hibernate.testing.ServiceRegistryBuilder;
|
||||
|
@ -113,7 +114,7 @@ public class BasicHibernateAnnotationsTest extends BaseCoreFunctionalTestCase {
|
|||
tx.commit();
|
||||
s.close();
|
||||
|
||||
Session parallelSession = openSession();
|
||||
Session parallelSession = openSecondarySession();
|
||||
Transaction parallelTx = parallelSession.beginTransaction();
|
||||
s = openSession();
|
||||
tx = s.beginTransaction();
|
||||
|
@ -131,7 +132,13 @@ public class BasicHibernateAnnotationsTest extends BaseCoreFunctionalTestCase {
|
|||
fail( "All optimistic locking should have make it fail" );
|
||||
}
|
||||
catch (HibernateException e) {
|
||||
if ( parallelTx != null ) parallelTx.rollback();
|
||||
if ( parallelTx != null ) {
|
||||
try {
|
||||
parallelTx.rollback();
|
||||
}
|
||||
catch (Exception ignore) {
|
||||
}
|
||||
}
|
||||
}
|
||||
finally {
|
||||
parallelSession.close();
|
||||
|
@ -532,7 +539,6 @@ public class BasicHibernateAnnotationsTest extends BaseCoreFunctionalTestCase {
|
|||
|
||||
@Test
|
||||
@RequiresDialectFeature( DialectChecks.SupportsExpectedLobUsagePattern.class )
|
||||
@FailureExpectedWithNewMetamodel
|
||||
public void testSerialized() throws Exception {
|
||||
Forest forest = new Forest();
|
||||
forest.setName( "Shire" );
|
||||
|
|
|
@ -23,12 +23,18 @@
|
|||
*/
|
||||
package org.hibernate.testing.junit4;
|
||||
|
||||
import org.hibernate.internal.SessionFactoryRegistry;
|
||||
|
||||
import org.junit.runners.model.Statement;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class AfterClassCallbackHandler extends Statement {
|
||||
private static final Logger log = Logger.getLogger( AfterClassCallbackHandler.class );
|
||||
|
||||
private final CustomRunner runner;
|
||||
private final Statement wrappedStatement;
|
||||
|
||||
|
@ -41,5 +47,11 @@ public class AfterClassCallbackHandler extends Statement {
|
|||
public void evaluate() throws Throwable {
|
||||
wrappedStatement.evaluate();
|
||||
runner.getTestClassMetadata().performAfterClassCallbacks( runner.getTestInstance() );
|
||||
if ( SessionFactoryRegistry.INSTANCE.hasRegistrations() ) {
|
||||
log.warnf(
|
||||
"SessionFactory may be leaked during execution of test : %s",
|
||||
runner.getTestClassMetadata().getTestClass().getName()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ import java.sql.Clob;
|
|||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
@ -94,6 +95,7 @@ public abstract class BaseCoreFunctionalTestCase extends BaseUnitTestCase {
|
|||
private final boolean isMetadataUsed;
|
||||
|
||||
protected Session session;
|
||||
private List<Session> secondarySessions;
|
||||
|
||||
protected static Dialect getDialect() {
|
||||
return DIALECT;
|
||||
|
@ -130,15 +132,42 @@ public abstract class BaseCoreFunctionalTestCase extends BaseUnitTestCase {
|
|||
}
|
||||
|
||||
protected Session openSession() throws HibernateException {
|
||||
registerPreviousSessionIfNeeded( session );
|
||||
session = sessionFactory().openSession();
|
||||
return session;
|
||||
}
|
||||
|
||||
private void registerPreviousSessionIfNeeded(Session session) {
|
||||
if ( session == null ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( !session.isOpen() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
registerSecondarySession( session );
|
||||
}
|
||||
|
||||
protected Session openSession(Interceptor interceptor) throws HibernateException {
|
||||
registerPreviousSessionIfNeeded( session );
|
||||
session = sessionFactory().withOptions().interceptor( interceptor ).openSession();
|
||||
return session;
|
||||
}
|
||||
|
||||
protected Session openSecondarySession() throws HibernateException {
|
||||
Session session = sessionFactory().openSession();
|
||||
registerSecondarySession( session );
|
||||
return session;
|
||||
}
|
||||
|
||||
protected void registerSecondarySession(Session session) {
|
||||
if ( secondarySessions == null ) {
|
||||
secondarySessions = new LinkedList<Session>();
|
||||
}
|
||||
secondarySessions.add( session );
|
||||
}
|
||||
|
||||
|
||||
// before/after test class ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
@ -455,7 +484,12 @@ public abstract class BaseCoreFunctionalTestCase extends BaseUnitTestCase {
|
|||
}
|
||||
cleanupTest();
|
||||
|
||||
cleanupSession();
|
||||
cleanupSession( session );
|
||||
if ( secondarySessions != null ) {
|
||||
for ( Session session: secondarySessions ) {
|
||||
cleanupSession( session );
|
||||
}
|
||||
}
|
||||
|
||||
assertAllDataRemoved();
|
||||
|
||||
|
@ -470,22 +504,33 @@ public abstract class BaseCoreFunctionalTestCase extends BaseUnitTestCase {
|
|||
protected boolean isCleanupTestDataRequired() { return false; }
|
||||
|
||||
protected void cleanupTestData() throws Exception {
|
||||
Session s = openSession();
|
||||
Session s = sessionFactory.openSession();
|
||||
try {
|
||||
s.beginTransaction();
|
||||
try {
|
||||
s.createQuery( "delete from java.lang.Object" ).executeUpdate();
|
||||
s.getTransaction().commit();
|
||||
}
|
||||
catch (Exception e) {
|
||||
try {
|
||||
s.doWork( new RollbackWork() );
|
||||
}
|
||||
catch (Exception ignore) {
|
||||
}
|
||||
}
|
||||
}
|
||||
finally {
|
||||
s.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void cleanupSession() {
|
||||
private void cleanupSession(Session session) {
|
||||
if ( session != null && ! ( (SessionImplementor) session ).isClosed() ) {
|
||||
if ( session.isConnected() ) {
|
||||
session.doWork( new RollbackWork() );
|
||||
}
|
||||
session.close();
|
||||
}
|
||||
session = null;
|
||||
}
|
||||
|
||||
public class RollbackWork implements Work {
|
||||
|
|
|
@ -45,11 +45,11 @@ public class BeforeClassCallbackHandler extends Statement {
|
|||
try {
|
||||
runner.getTestClassMetadata().performBeforeClassCallbacks( runner.getTestInstance() );
|
||||
wrappedStatement.evaluate();
|
||||
} catch ( Throwable error ) {
|
||||
}
|
||||
catch ( Throwable error ) {
|
||||
runner.setBeforeClassMethodFailed();
|
||||
if ( runner.getTestClass().getJavaClass().getAnnotation( FailureExpected.class ) == null &&
|
||||
( !runner.useNewMetamodel() ||
|
||||
runner.getTestClass().getJavaClass().getAnnotation( FailureExpectedWithNewMetamodel.class ) == null ) ) {
|
||||
if ( runner.getTestClass().getJavaClass().getAnnotation( FailureExpected.class ) == null
|
||||
&& runner.getTestClass().getJavaClass().getAnnotation( FailureExpectedWithNewMetamodel.class ) == null ) {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -133,17 +133,12 @@ public class CustomRunner extends BlockJUnit4ClassRunner {
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @see org.junit.runners.ParentRunner#classBlock(org.junit.runner.notification.RunNotifier)
|
||||
*/
|
||||
@Override
|
||||
protected Statement classBlock( RunNotifier notifier ) {
|
||||
log.info( BeforeClass.class.getSimpleName() + ": " + getName() );
|
||||
|
||||
if ( getTestClass().getJavaClass().getAnnotation( FailureExpected.class ) != null
|
||||
|| ( useNewMetamodel() && getTestClass().getJavaClass().getAnnotation( FailureExpectedWithNewMetamodel.class ) != null ) ) {
|
||||
|| getTestClass().getJavaClass().getAnnotation( FailureExpectedWithNewMetamodel.class ) != null ) {
|
||||
log.info( FailureExpected.class.getSimpleName() );
|
||||
}
|
||||
|
||||
|
@ -155,7 +150,7 @@ public class CustomRunner extends BlockJUnit4ClassRunner {
|
|||
log.info( Test.class.getSimpleName() + ": " + method.getName() );
|
||||
|
||||
if ( method.getAnnotation( FailureExpected.class ) != null
|
||||
|| ( useNewMetamodel() && method.getAnnotation( FailureExpectedWithNewMetamodel.class ) != null ) ) {
|
||||
|| method.getAnnotation( FailureExpectedWithNewMetamodel.class ) != null ) {
|
||||
log.info( FailureExpected.class.getSimpleName() );
|
||||
}
|
||||
|
||||
|
@ -214,33 +209,14 @@ public class CustomRunner extends BlockJUnit4ClassRunner {
|
|||
Ignore virtualIgnore;
|
||||
|
||||
for ( FrameworkMethod frameworkMethod : methods ) {
|
||||
// Convert @FailureExpectedWithNewMetamodel annotations to @FailureExpected annotations
|
||||
FailureExpected failureExpected = null;
|
||||
if ( useNewMetamodel() ) {
|
||||
final FailureExpectedWithNewMetamodel failureExpectedWithNewMetamodel =
|
||||
Helper.locateAnnotation( FailureExpectedWithNewMetamodel.class, frameworkMethod, getTestClass() );
|
||||
if ( failureExpectedWithNewMetamodel != null ) {
|
||||
failureExpected = new FailureExpected() {
|
||||
|
||||
@Override
|
||||
public Class< ? extends Annotation > annotationType() {
|
||||
return FailureExpected.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String message() {
|
||||
return failureExpectedWithNewMetamodel.message();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String jiraKey() {
|
||||
return failureExpectedWithNewMetamodel.jiraKey();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
FailureExpected failureExpected = Helper.locateAnnotation( FailureExpected.class, frameworkMethod, getTestClass() );
|
||||
if ( failureExpected == null ) {
|
||||
failureExpected = Helper.locateAnnotation( FailureExpected.class, frameworkMethod, getTestClass() );
|
||||
// see if there is a FailureExpectedWithNewMetamodel, and if so treat it like FailureExpected
|
||||
final FailureExpectedWithNewMetamodel failureExpectedWithNewMetamodel
|
||||
= Helper.locateAnnotation( FailureExpectedWithNewMetamodel.class, frameworkMethod, getTestClass() );
|
||||
if ( failureExpectedWithNewMetamodel != null ) {
|
||||
failureExpected = new FailureExpectedWithNewMetamodelAdapter( failureExpectedWithNewMetamodel );
|
||||
}
|
||||
}
|
||||
// potentially ignore based on expected failure
|
||||
if ( failureExpected != null && !doValidation ) {
|
||||
|
@ -288,19 +264,6 @@ public class CustomRunner extends BlockJUnit4ClassRunner {
|
|||
}
|
||||
}
|
||||
|
||||
boolean useNewMetamodel() {
|
||||
try {
|
||||
Object object = getTestInstance();
|
||||
if ( object != null && object instanceof BaseCoreFunctionalTestCase ) {
|
||||
return ( (BaseCoreFunctionalTestCase) object ).isMetadataUsed();
|
||||
}
|
||||
}
|
||||
catch ( Exception e ) {
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
protected Ignore convertSkipToIgnore(FrameworkMethod frameworkMethod) {
|
||||
// @Skip
|
||||
Skip skip = Helper.locateAnnotation( Skip.class, frameworkMethod, getTestClass() );
|
||||
|
@ -414,4 +377,26 @@ public class CustomRunner extends BlockJUnit4ClassRunner {
|
|||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("ClassExplicitlyAnnotation")
|
||||
private class FailureExpectedWithNewMetamodelAdapter implements FailureExpected {
|
||||
private final FailureExpectedWithNewMetamodel failureExpectedWithNewMetamodel;
|
||||
|
||||
public FailureExpectedWithNewMetamodelAdapter(FailureExpectedWithNewMetamodel failureExpectedWithNewMetamodel) {
|
||||
this.failureExpectedWithNewMetamodel = failureExpectedWithNewMetamodel;
|
||||
}
|
||||
@Override
|
||||
public Class< ? extends Annotation > annotationType() {
|
||||
return FailureExpected.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String message() {
|
||||
return failureExpectedWithNewMetamodel.message();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String jiraKey() {
|
||||
return failureExpectedWithNewMetamodel.jiraKey();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,12 +42,15 @@ import org.hibernate.testing.OnFailure;
|
|||
public class TestClassMetadata {
|
||||
private static final Object[] NO_ARGS = new Object[0];
|
||||
|
||||
private Class testClass;
|
||||
|
||||
private LinkedHashSet<Method> beforeClassOnceMethods;
|
||||
private LinkedHashSet<Method> afterClassOnceMethods;
|
||||
private LinkedHashSet<Method> onFailureCallbacks;
|
||||
private LinkedHashSet<Method> onExpectedFailureCallbacks;
|
||||
|
||||
public TestClassMetadata(Class testClass) {
|
||||
this.testClass = testClass;
|
||||
processClassHierarchy( testClass );
|
||||
}
|
||||
|
||||
|
@ -74,6 +77,10 @@ public class TestClassMetadata {
|
|||
}
|
||||
}
|
||||
|
||||
public Class getTestClass() {
|
||||
return testClass;
|
||||
}
|
||||
|
||||
private void addBeforeClassOnceCallback(Method method) {
|
||||
if ( beforeClassOnceMethods == null ) {
|
||||
beforeClassOnceMethods = new LinkedHashSet<Method>();
|
||||
|
|
Loading…
Reference in New Issue