HHH-5942 - Migrate to JUnit 4
This commit is contained in:
parent
a4562f4da1
commit
0a908cb518
|
@ -34,6 +34,8 @@ import org.hibernate.cfg.Configuration;
|
|||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.hql.ast.ASTQueryTranslatorFactory;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.testing.FailureExpected;
|
||||
|
@ -75,12 +77,7 @@ public class ASTParserLoadingOrderByTest extends BaseCoreFunctionalTestCase {
|
|||
cfg.setProperty( Environment.QUERY_TRANSLATOR, ASTQueryTranslatorFactory.class.getName() );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void prepareTest() {
|
||||
cleanupData();
|
||||
}
|
||||
|
||||
protected void createData() {
|
||||
private void createData() {
|
||||
stateProvince = new StateProvince();
|
||||
stateProvince.setName( "IL" );
|
||||
|
||||
|
@ -156,7 +153,7 @@ public class ASTParserLoadingOrderByTest extends BaseCoreFunctionalTestCase {
|
|||
zoosWithSameAddress.add( zoo2 );
|
||||
}
|
||||
|
||||
protected void cleanupData() {
|
||||
private void cleanupData() {
|
||||
Session s = openSession();
|
||||
Transaction t = s.beginTransaction();
|
||||
if ( zoo1 != null ) {
|
||||
|
|
|
@ -61,7 +61,6 @@ import org.hibernate.testing.OnExpectedFailure;
|
|||
import org.hibernate.testing.OnFailure;
|
||||
import org.hibernate.testing.SkipLog;
|
||||
|
||||
import static org.hibernate.testing.TestLogger.LOG;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
/**
|
||||
|
@ -110,7 +109,6 @@ public abstract class BaseCoreFunctionalTestCase extends BaseUnitTestCase {
|
|||
|
||||
@BeforeClassOnce
|
||||
private void buildSessionFactory() {
|
||||
LOG.trace( "Building session factory" );
|
||||
configuration = buildConfiguration();
|
||||
serviceRegistry = buildServiceRegistry( configuration );
|
||||
sessionFactory = (SessionFactoryImplementor) configuration.buildSessionFactory( serviceRegistry );
|
||||
|
@ -273,7 +271,6 @@ public abstract class BaseCoreFunctionalTestCase extends BaseUnitTestCase {
|
|||
if ( sessionFactory == null ) {
|
||||
return;
|
||||
}
|
||||
LOG.trace( "Releasing session factory" );
|
||||
sessionFactory.close();
|
||||
sessionFactory = null;
|
||||
configuration = null;
|
||||
|
@ -282,13 +279,12 @@ public abstract class BaseCoreFunctionalTestCase extends BaseUnitTestCase {
|
|||
@OnFailure
|
||||
@OnExpectedFailure
|
||||
public void onFailure() {
|
||||
LOG.trace( "Processing failure-expected ignore" );
|
||||
if ( ! rebuildSessionFactoryOnError() ) {
|
||||
return;
|
||||
}
|
||||
// cleanupSession();
|
||||
|
||||
if ( rebuildSessionFactoryOnError() ) {
|
||||
rebuildSessionFactory();
|
||||
}
|
||||
}
|
||||
|
||||
protected void rebuildSessionFactory() {
|
||||
if ( sessionFactory == null ) {
|
||||
|
@ -307,6 +303,7 @@ public abstract class BaseCoreFunctionalTestCase extends BaseUnitTestCase {
|
|||
|
||||
@Before
|
||||
public final void beforeTest() throws Exception {
|
||||
System.out.println( " IN @Before CALLBACK!" );
|
||||
prepareTest();
|
||||
}
|
||||
|
||||
|
@ -315,23 +312,24 @@ public abstract class BaseCoreFunctionalTestCase extends BaseUnitTestCase {
|
|||
|
||||
@After
|
||||
public final void afterTest() throws Exception {
|
||||
System.out.println( " IN @After CALLBACK!" );
|
||||
cleanupTest();
|
||||
|
||||
cleanupSession();
|
||||
|
||||
assertAllDataRemoved();
|
||||
}
|
||||
|
||||
private void cleanupSession() {
|
||||
if ( session != null && ! ( (SessionImplementor) session ).isClosed() ) {
|
||||
if ( session.isConnected() ) {
|
||||
session.doWork( new RollbackWork() );
|
||||
}
|
||||
session.close();
|
||||
session = null;
|
||||
LOG.debug( "unclosed session" );
|
||||
}
|
||||
else {
|
||||
session = null;
|
||||
}
|
||||
|
||||
assertAllDataRemoved();
|
||||
}
|
||||
|
||||
public class RollbackWork implements Work {
|
||||
public void execute(Connection connection) throws SQLException {
|
||||
connection.rollback();
|
||||
|
|
|
@ -90,20 +90,12 @@ public class CustomRunner extends BlockJUnit4ClassRunner {
|
|||
);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected Statement methodInvoker(FrameworkMethod method, final Object test) {
|
||||
protected Statement methodBlock(FrameworkMethod method) {
|
||||
final Statement originalMethodBlock = super.methodBlock( method );
|
||||
final ExtendedFrameworkMethod extendedFrameworkMethod = (ExtendedFrameworkMethod) method;
|
||||
|
||||
|
||||
final Statement invoker = super.methodInvoker( method, test );
|
||||
|
||||
return new TestMethodInvoker( invoker, testClassMetadata, extendedFrameworkMethod, test );
|
||||
}
|
||||
|
||||
public static class FailureExpectedTestPassedException extends Exception {
|
||||
public FailureExpectedTestPassedException(FrameworkMethod frameworkMethod) {
|
||||
super( "Test marked as FailureExpected, but did not fail : " + Helper.extractTestName( frameworkMethod ) );
|
||||
}
|
||||
return new FailureExpectedHandler( originalMethodBlock, testClassMetadata, extendedFrameworkMethod, testInstance );
|
||||
}
|
||||
|
||||
private Object testInstance;
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
*/
|
||||
package org.hibernate.testing.junit4;
|
||||
|
||||
import org.junit.runners.model.FrameworkMethod;
|
||||
import org.junit.runners.model.Statement;
|
||||
|
||||
import org.hibernate.testing.FailureExpected;
|
||||
|
@ -31,13 +32,13 @@ import org.hibernate.testing.TestLogger;
|
|||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
class TestMethodInvoker extends Statement {
|
||||
class FailureExpectedHandler extends Statement {
|
||||
private final TestClassMetadata testClassMetadata;
|
||||
private final ExtendedFrameworkMethod extendedFrameworkMethod;
|
||||
private final Statement realInvoker;
|
||||
private final Object testInstance;
|
||||
|
||||
public TestMethodInvoker(
|
||||
public FailureExpectedHandler(
|
||||
Statement realInvoker,
|
||||
TestClassMetadata testClassMetadata,
|
||||
ExtendedFrameworkMethod extendedFrameworkMethod,
|
||||
|
@ -55,10 +56,10 @@ class TestMethodInvoker extends Statement {
|
|||
realInvoker.evaluate();
|
||||
// reaching here is expected, unless the test is marked as an expected failure
|
||||
if ( failureExpected != null ) {
|
||||
throw new CustomRunner.FailureExpectedTestPassedException( extendedFrameworkMethod );
|
||||
throw new FailureExpectedTestPassedException( extendedFrameworkMethod );
|
||||
}
|
||||
}
|
||||
catch (CustomRunner.FailureExpectedTestPassedException e) {
|
||||
catch (FailureExpectedTestPassedException e) {
|
||||
// just pass this along
|
||||
throw e;
|
||||
}
|
||||
|
@ -81,4 +82,10 @@ class TestMethodInvoker extends Statement {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class FailureExpectedTestPassedException extends Exception {
|
||||
public FailureExpectedTestPassedException(FrameworkMethod frameworkMethod) {
|
||||
super( "Test marked as FailureExpected, but did not fail : " + Helper.extractTestName( frameworkMethod ) );
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue