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