diff --git a/hibernate-c3p0/hibernate-c3p0.gradle b/hibernate-c3p0/hibernate-c3p0.gradle index deb030c947..30cdcfac71 100644 --- a/hibernate-c3p0/hibernate-c3p0.gradle +++ b/hibernate-c3p0/hibernate-c3p0.gradle @@ -3,5 +3,5 @@ apply plugin: 'java' dependencies { compile( project( ':hibernate-core' ) ) compile( [group: 'c3p0', name: 'c3p0', version: '0.9.1'] ) - testCompile( project(':hibernate-core').sourceSets.test.classes ) + testCompile( project(':hibernate-testing') ) } \ No newline at end of file diff --git a/hibernate-core/hibernate-core.gradle b/hibernate-core/hibernate-core.gradle index e094b8872b..e3d2e0086c 100644 --- a/hibernate-core/hibernate-core.gradle +++ b/hibernate-core/hibernate-core.gradle @@ -17,6 +17,7 @@ dependencies { provided( libraries.ant ) provided( libraries.jacc ) provided( libraries.validation ) + testCompile( project(':hibernate-testing') ) testCompile( libraries.validation ) testCompile( libraries.validator ) { // for test runtime diff --git a/hibernate-core/src/main/java/org/hibernate/service/jdbc/dialect/internal/DialectFactoryImpl.java b/hibernate-core/src/main/java/org/hibernate/service/jdbc/dialect/internal/DialectFactoryImpl.java index d2e395e82a..969f115e43 100644 --- a/hibernate-core/src/main/java/org/hibernate/service/jdbc/dialect/internal/DialectFactoryImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/service/jdbc/dialect/internal/DialectFactoryImpl.java @@ -72,8 +72,8 @@ public class DialectFactoryImpl implements DialectFactory { try { return ( Dialect ) classLoaderService.classForName( dialectName ).newInstance(); } - catch ( ClassLoadingException cnfe ) { - throw new HibernateException( "Dialect class not found: " + dialectName, cnfe ); + catch ( ClassLoadingException e ) { + throw new HibernateException( "Dialect class not found: " + dialectName, e ); } catch ( HibernateException e ) { throw e; diff --git a/hibernate-core/src/test/java/org/hibernate/TestingDatabaseInfo.java b/hibernate-core/src/test/java/org/hibernate/TestingDatabaseInfo.java index 14c9db8a99..8102fbeef5 100644 --- a/hibernate-core/src/test/java/org/hibernate/TestingDatabaseInfo.java +++ b/hibernate-core/src/test/java/org/hibernate/TestingDatabaseInfo.java @@ -1,12 +1,34 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2010, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ package org.hibernate; + import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Environment; import org.hibernate.dialect.Dialect; import org.hibernate.dialect.H2Dialect; /** - * TODO : javadoc - * * @author Steve Ebersole */ public class TestingDatabaseInfo { diff --git a/hibernate-core/src/test/java/org/hibernate/cache/QueryKeyTest.java b/hibernate-core/src/test/java/org/hibernate/cache/QueryKeyTest.java index 06f10aa40d..a81a7a83c8 100644 --- a/hibernate-core/src/test/java/org/hibernate/cache/QueryKeyTest.java +++ b/hibernate-core/src/test/java/org/hibernate/cache/QueryKeyTest.java @@ -1,10 +1,10 @@ /* * Hibernate, Relational Persistence for Idiomatic Java * - * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as + * Copyright (c) 2008-2011, Red Hat Inc. or third-party contributors as * indicated by the @author tags or express copyright attribution * statements applied by the authors. All third-party contributions are - * distributed under license by Red Hat Middleware LLC. + * distributed under license by Red Hat Inc. * * This copyrighted material is made available to anyone wishing to use, modify, * copy, or redistribute it subject to the terms and conditions of the GNU @@ -20,7 +20,6 @@ * Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA - * */ package org.hibernate.cache; @@ -28,10 +27,13 @@ import java.io.Serializable; import java.util.Collections; import java.util.HashMap; import java.util.Map; -import junit.framework.TestCase; + +import org.junit.Test; + import org.hibernate.EntityMode; import org.hibernate.internal.util.SerializationHelper; import org.hibernate.internal.util.collections.ArrayHelper; +import org.hibernate.testing.junit4.BaseUnitTestCase; import org.hibernate.transform.AliasToBeanResultTransformer; import org.hibernate.transform.AliasToEntityMapResultTransformer; import org.hibernate.transform.AliasedTupleSubsetResultTransformer; @@ -49,7 +51,7 @@ import org.hibernate.transform.TupleSubsetResultTransformer; * * @author Steve Ebersole */ -public class QueryKeyTest extends TestCase { +public class QueryKeyTest extends BaseUnitTestCase { private static final String QUERY_STRING = "the query string"; public static class AClass implements Serializable { @@ -73,6 +75,7 @@ public class QueryKeyTest extends TestCase { } } + @Test public void testSerializedEqualityResultTransformer() throws Exception { // settings are lazily initialized when calling transformTuple(), // so they have not been initialized for the following test @@ -127,6 +130,7 @@ public class QueryKeyTest extends TestCase { assert transformer.equals( transformer2 ): "deep copy issue"; } + @Test public void testSerializedEquality() throws Exception { doTest( buildBasicKey( null ) ); @@ -138,6 +142,7 @@ public class QueryKeyTest extends TestCase { doTest( buildBasicKey( CacheableResultTransformer.create( null, new String[] { "a", null }, new boolean[] { true, true } ) ) ); } + @Test public void testSerializedEqualityWithTupleSubsetResultTransfprmer() throws Exception { doTestWithTupleSubsetResultTransformer( new AliasToBeanResultTransformer( AClass.class ), diff --git a/hibernate-core/src/test/java/org/hibernate/connection/PropertiesTest.java b/hibernate-core/src/test/java/org/hibernate/connection/PropertiesTest.java index 88122c6883..c1a0e70f7f 100644 --- a/hibernate-core/src/test/java/org/hibernate/connection/PropertiesTest.java +++ b/hibernate-core/src/test/java/org/hibernate/connection/PropertiesTest.java @@ -1,10 +1,10 @@ /* * Hibernate, Relational Persistence for Idiomatic Java * - * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as + * Copyright (c) 2008-2011, Red Hat Inc. or third-party contributors as * indicated by the @author tags or express copyright attribution * statements applied by the authors. All third-party contributions are - * distributed under license by Red Hat Middleware LLC. + * distributed under license by Red Hat Inc. * * This copyrighted material is made available to anyone wishing to use, modify, * copy, or redistribute it subject to the terms and conditions of the GNU @@ -20,20 +20,21 @@ * Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA - * */ package org.hibernate.connection; import java.util.Properties; -import junit.framework.TestCase; + +import org.junit.Assert; +import org.junit.Test; + import org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator; +import org.hibernate.testing.junit4.BaseUnitTestCase; /** - * Undocumented - * * @author kbow */ - -public class PropertiesTest extends TestCase { +public class PropertiesTest extends BaseUnitTestCase { + @Test public void testProperties() throws Exception { final Properties props = new Properties(); @@ -46,8 +47,8 @@ public class PropertiesTest extends TestCase { props.put("hibernate.connection.create", "true"); final Properties outputProps = ConnectionProviderInitiator.getConnectionProperties( props ); - assertEquals(1, outputProps.size()); - assertEquals("true", outputProps.get("create")); + Assert.assertEquals( 1, outputProps.size() ); + Assert.assertEquals( "true", outputProps.get( "create" ) ); } } diff --git a/hibernate-core/src/test/java/org/hibernate/dialect/DerbyDialectTestCase.java b/hibernate-core/src/test/java/org/hibernate/dialect/DerbyDialectTestCase.java index d6a9df4886..adc8ff0298 100644 --- a/hibernate-core/src/test/java/org/hibernate/dialect/DerbyDialectTestCase.java +++ b/hibernate-core/src/test/java/org/hibernate/dialect/DerbyDialectTestCase.java @@ -22,14 +22,20 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.dialect; -import junit.framework.TestCase; + +import org.junit.Test; + +import org.hibernate.testing.TestForIssue; +import org.hibernate.testing.junit4.BaseUnitTestCase; +import static org.junit.Assert.assertEquals; /** - * Testing of patched support for Derby limit and ofset queries; see HHH-3972 + * Testing of patched support for Derby limit and offset queries; see HHH-3972 * * @author Evan Leonard */ -public class DerbyDialectTestCase extends TestCase { +@TestForIssue( jiraKey = "HHH-3972" ) +public class DerbyDialectTestCase extends BaseUnitTestCase { private static class LocalDerbyDialect extends DerbyDialect { protected boolean isTenPointFiveReleaseOrNewer() { @@ -37,6 +43,7 @@ public class DerbyDialectTestCase extends TestCase { } } + @Test public void testInsertLimitClause() { final int limit = 50; final String input = "select * from tablename t where t.cat = 5"; @@ -46,6 +53,7 @@ public class DerbyDialectTestCase extends TestCase { assertEquals( expected, actual ); } + @Test public void testInsertLimitWithOffsetClause() { final int limit = 50; final int offset = 200; @@ -56,7 +64,7 @@ public class DerbyDialectTestCase extends TestCase { assertEquals( expected, actual ); } - + @Test public void testInsertLimitWithForUpdateClause() { final int limit = 50; final int offset = 200; @@ -68,6 +76,7 @@ public class DerbyDialectTestCase extends TestCase { assertEquals( expected, actual ); } + @Test public void testInsertLimitWithWithClause() { final int limit = 50; final int offset = 200; @@ -79,6 +88,7 @@ public class DerbyDialectTestCase extends TestCase { assertEquals( expected, actual ); } + @Test public void testInsertLimitWithForUpdateAndWithClauses() { final int limit = 50; final int offset = 200; diff --git a/hibernate-core/src/test/java/org/hibernate/dialect/Mocks.java b/hibernate-core/src/test/java/org/hibernate/dialect/Mocks.java index 3c8252ab4c..e20357b321 100644 --- a/hibernate-core/src/test/java/org/hibernate/dialect/Mocks.java +++ b/hibernate-core/src/test/java/org/hibernate/dialect/Mocks.java @@ -1,10 +1,10 @@ /* * Hibernate, Relational Persistence for Idiomatic Java * - * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as + * Copyright (c) 2008-2011, Red Hat Inc. or third-party contributors as * indicated by the @author tags or express copyright attribution * statements applied by the authors. All third-party contributions are - * distributed under license by Red Hat Middleware LLC. + * distributed under license by Red Hat Inc. * * This copyrighted material is made available to anyone wishing to use, modify, * copy, or redistribute it subject to the terms and conditions of the GNU @@ -20,7 +20,6 @@ * Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA - * */ package org.hibernate.dialect; import java.lang.reflect.InvocationHandler; @@ -31,10 +30,9 @@ import java.sql.DatabaseMetaData; import java.sql.SQLException; /** - * TODO : javadoc - * * @author Steve Ebersole */ +@SuppressWarnings( {"UnnecessaryBoxing"}) public class Mocks { public static Connection createConnection(String dbName, int version) { @@ -77,7 +75,7 @@ public class Mocks { } if ( "hashCode".equals( methodName ) ) { - return new Integer( this.hashCode() ); + return Integer.valueOf( this.hashCode() ); } if ( canThrowSQLException( method ) ) { @@ -111,7 +109,7 @@ public class Mocks { } if ( "getDatabaseMajorVersion".equals( methodName ) ) { - return new Integer( majorVersion ); + return Integer.valueOf( majorVersion ); } if ( "getConnection".equals( methodName ) ) { @@ -137,8 +135,8 @@ public class Mocks { private static boolean canThrowSQLException(Method method) { final Class[] exceptions = method.getExceptionTypes(); - for ( int i = 0; i < exceptions.length; i++ ) { - if ( SQLException.class.isAssignableFrom( exceptions[i] ) ) { + for ( Class exceptionType : exceptions ) { + if ( SQLException.class.isAssignableFrom( exceptionType ) ) { return true; } } diff --git a/hibernate-core/src/test/java/org/hibernate/dialect/SQLServer2005DialectTestCase.java b/hibernate-core/src/test/java/org/hibernate/dialect/SQLServer2005DialectTestCase.java index 081d06b8e9..f3375fcf7f 100644 --- a/hibernate-core/src/test/java/org/hibernate/dialect/SQLServer2005DialectTestCase.java +++ b/hibernate-core/src/test/java/org/hibernate/dialect/SQLServer2005DialectTestCase.java @@ -1,20 +1,49 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ package org.hibernate.dialect; -import junit.framework.TestCase; + +import org.junit.Test; + +import org.hibernate.testing.junit4.BaseUnitTestCase; + +import static org.junit.Assert.assertEquals; /** * Unit test of the behavior of the SQLServerDialect utility methods * * @author Valotasion Yoryos - * */ -public class SQLServer2005DialectTestCase extends TestCase { +public class SQLServer2005DialectTestCase extends BaseUnitTestCase { + @Test public void testStripAliases() { String input = "some_field1 as f1, some_fild2 as f2, _field3 as f3 "; assertEquals( "some_field1, some_fild2, _field3", SQLServer2005Dialect.stripAliases(input) ); } + @Test public void testGetSelectFieldsWithoutAliases() { StringBuilder input = new StringBuilder( "select some_field1 as f12, some_fild2 as f879, _field3 as _f24674_3 from...." ); String output = SQLServer2005Dialect.getSelectFieldsWithoutAliases( input ).toString(); @@ -22,7 +51,7 @@ public class SQLServer2005DialectTestCase extends TestCase { assertEquals( " some_field1, some_fild2, _field3", output ); } - + @Test public void testReplaceDistinctWithGroupBy() { StringBuilder input = new StringBuilder( "select distinct f1, f2 as ff, f3 from table where f1 = 5" ); SQLServer2005Dialect.replaceDistinctWithGroupBy( input ); @@ -30,7 +59,7 @@ public class SQLServer2005DialectTestCase extends TestCase { assertEquals( "select f1, f2 as ff, f3 from table where f1 = 5 group by f1, f2, f3 ", input.toString() ); } - + @Test public void testGetLimitString() { String input = "select distinct f1 as f53245 from table849752 order by f234, f67 desc"; diff --git a/hibernate-core/src/test/java/org/hibernate/dialect/TestingDialects.java b/hibernate-core/src/test/java/org/hibernate/dialect/TestingDialects.java index 119df3069e..d4ce2eec5a 100644 --- a/hibernate-core/src/test/java/org/hibernate/dialect/TestingDialects.java +++ b/hibernate-core/src/test/java/org/hibernate/dialect/TestingDialects.java @@ -1,10 +1,10 @@ /* * Hibernate, Relational Persistence for Idiomatic Java * - * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as + * Copyright (c) 2008-2011, Red Hat Inc. or third-party contributors as * indicated by the @author tags or express copyright attribution * statements applied by the authors. All third-party contributions are - * distributed under license by Red Hat Middleware LLC. + * distributed under license by Red Hat Inc. * * This copyrighted material is made available to anyone wishing to use, modify, * copy, or redistribute it subject to the terms and conditions of the GNU @@ -20,7 +20,6 @@ * Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA - * */ package org.hibernate.dialect; import java.sql.DatabaseMetaData; @@ -30,8 +29,6 @@ import org.hibernate.service.jdbc.dialect.internal.AbstractDialectResolver; import org.hibernate.service.jdbc.dialect.internal.BasicDialectResolver; /** - * TODO : javadoc - * * @author Steve Ebersole */ public class TestingDialects { diff --git a/hibernate-core/src/test/java/org/hibernate/dialect/resolver/DialectFactoryTest.java b/hibernate-core/src/test/java/org/hibernate/dialect/resolver/DialectFactoryTest.java index fc579ee3db..aae0a88109 100644 --- a/hibernate-core/src/test/java/org/hibernate/dialect/resolver/DialectFactoryTest.java +++ b/hibernate-core/src/test/java/org/hibernate/dialect/resolver/DialectFactoryTest.java @@ -1,10 +1,10 @@ /* * Hibernate, Relational Persistence for Idiomatic Java * - * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as + * Copyright (c) 2008-2011, Red Hat Inc. or third-party contributors as * indicated by the @author tags or express copyright attribution * statements applied by the authors. All third-party contributions are - * distributed under license by Red Hat Middleware LLC. + * distributed under license by Red Hat Inc. * * This copyrighted material is made available to anyone wishing to use, modify, * copy, or redistribute it subject to the terms and conditions of the GNU @@ -20,15 +20,15 @@ * Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA - * */ package org.hibernate.dialect.resolver; -import java.sql.Connection; -import java.util.Properties; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import org.junit.Before; +import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.fail; + import org.hibernate.HibernateException; import org.hibernate.cfg.Environment; import org.hibernate.dialect.DB2Dialect; @@ -47,73 +47,65 @@ import org.hibernate.dialect.SQLServerDialect; import org.hibernate.dialect.SybaseASE15Dialect; import org.hibernate.dialect.SybaseAnywhereDialect; import org.hibernate.dialect.TestingDialects; -import org.hibernate.service.classloading.spi.ClassLoaderService; +import org.hibernate.service.classloading.internal.ClassLoaderServiceImpl; +import org.hibernate.service.classloading.spi.ClassLoadingException; import org.hibernate.service.jdbc.dialect.internal.DialectFactoryImpl; import org.hibernate.service.jdbc.dialect.internal.DialectResolverSet; import org.hibernate.service.jdbc.dialect.internal.StandardDialectResolver; import org.hibernate.service.jdbc.dialect.spi.DialectResolver; -import org.hibernate.service.spi.ServiceRegistry; -import org.hibernate.testing.ServiceRegistryBuilder; +import org.hibernate.testing.junit4.BaseUnitTestCase; + +import java.sql.Connection; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; /** - * TODO : javadoc - * * @author Steve Ebersole */ -public class DialectFactoryTest extends TestCase { - private ServiceRegistry serviceRegistry; +public class DialectFactoryTest extends BaseUnitTestCase { + private DialectFactoryImpl dialectFactory; - public DialectFactoryTest(String name) { - super( name ); + @Before + public void setUp() { + dialectFactory = new DialectFactoryImpl(); + dialectFactory.setClassLoaderService( new ClassLoaderServiceImpl( getClass().getClassLoader() ) ); + dialectFactory.setDialectResolver( new StandardDialectResolver() ); } - @Override - protected void setUp() { - serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( Environment.getProperties() ); - } + @Test + public void testExplicitlySuppliedDialectClassName() { + final Map configValues = new HashMap(); - @Override - protected void tearDown() { - if ( serviceRegistry != null ) { - ServiceRegistryBuilder.destroy( serviceRegistry ); - } - } - - public static Test suite() { - return new TestSuite( DialectFactoryTest.class ); - } - - // TODO: is it still possible to build a dialect using a class name??? - /* - public void testBuildDialectByClass() { - assertEquals( - HSQLDialect.class, - DialectFactory.constructDialect( "org.hibernate.dialect.HSQLDialect" ).getClass() - ); + configValues.put( Environment.DIALECT, "org.hibernate.dialect.HSQLDialect" ); + assertEquals( HSQLDialect.class, dialectFactory.buildDialect( configValues, null ).getClass() ); + configValues.put( Environment.DIALECT, "org.hibernate.dialect.NoSuchDialect" ); try { - DialectFactory.constructDialect( "org.hibernate.dialect.NoSuchDialect" ); + dialectFactory.buildDialect( configValues, null ); fail(); } catch ( HibernateException e ) { - assertEquals( "unexpected exception type", e.getCause().getClass(), ClassNotFoundException.class ); + assertEquals( "unexpected exception type", ClassLoadingException.class, e.getCause().getClass() ); } + configValues.put( Environment.DIALECT, "java.lang.Object" ); try { - DialectFactory.constructDialect( "java.lang.Object" ); + dialectFactory.buildDialect( configValues, null ); fail(); } catch ( HibernateException e ) { - assertEquals( "unexpected exception type", e.getCause().getClass(), ClassCastException.class ); + assertEquals( "unexpected exception type", ClassCastException.class, e.getCause().getClass() ); } } - */ + @Test public void testBuildDialectByProperties() { Properties props = new Properties(); try { - getDialectFactoryImpl( new StandardDialectResolver() ).buildDialect( props, null ); + dialectFactory.buildDialect( props, null ); fail(); } catch ( HibernateException e ) { @@ -121,16 +113,10 @@ public class DialectFactoryTest extends TestCase { } props.setProperty( Environment.DIALECT, "org.hibernate.dialect.HSQLDialect" ); - assertTrue( getDialectFactoryImpl( new StandardDialectResolver() ).buildDialect( props, null ) instanceof HSQLDialect ); - } - - private DialectFactoryImpl getDialectFactoryImpl(DialectResolver dialectResolver) { - DialectFactoryImpl dialectFactoryImpl = new DialectFactoryImpl(); - dialectFactoryImpl.setClassLoaderService( serviceRegistry.getService( ClassLoaderService.class ) ); - dialectFactoryImpl.setDialectResolver( dialectResolver ); - return dialectFactoryImpl; + assertEquals( HSQLDialect.class, dialectFactory.buildDialect( props, null ).getClass() ); } + @Test public void testPreregisteredDialects() { DialectResolver resolver = new StandardDialectResolver(); testDetermination( "HSQL Database Engine", HSQLDialect.class, resolver ); @@ -160,6 +146,7 @@ public class DialectFactoryTest extends TestCase { testDetermination( "Oracle", 11, Oracle10gDialect.class, resolver ); } + @Test public void testCustomDialects() { DialectResolverSet resolvers = new DialectResolverSet(); resolvers.addResolver( new TestingDialects.MyDialectResolver1() ); @@ -183,7 +170,6 @@ public class DialectFactoryTest extends TestCase { fail(); } catch ( HibernateException e ) { -// log.info( "Expected SQL error in resolveDialect and ignored", e ); } try { @@ -191,14 +177,14 @@ public class DialectFactoryTest extends TestCase { fail(); } catch ( HibernateException e ) { -// log.info( "Expected runtime error in resolveDialect", e ); } } + @Test public void testDialectNotFound() { - Properties properties = new Properties(); + Map properties = Collections.EMPTY_MAP; try { - getDialectFactoryImpl( new StandardDialectResolver() ).buildDialect( properties, Mocks.createConnection( "NoSuchDatabase", 666 ) ); + dialectFactory.buildDialect( properties, Mocks.createConnection( "NoSuchDatabase", 666 ) ); fail(); } catch ( HibernateException e ) { @@ -211,10 +197,9 @@ public class DialectFactoryTest extends TestCase { } private void testDetermination(String databaseName, int databaseMajorVersion, Class clazz, DialectResolver resolver) { - DialectFactoryImpl dialectFactoryImpl = getDialectFactoryImpl( new StandardDialectResolver() ); - dialectFactoryImpl.setDialectResolver( resolver ); + dialectFactory.setDialectResolver( resolver ); Properties properties = new Properties(); Connection conn = Mocks.createConnection( databaseName, databaseMajorVersion ); - assertEquals( clazz, dialectFactoryImpl.buildDialect( properties, conn ).getClass() ); + assertEquals( clazz, dialectFactory.buildDialect( properties, conn ).getClass() ); } } diff --git a/hibernate-core/src/test/java/org/hibernate/dialect/resolver/DialectResolverTest.java b/hibernate-core/src/test/java/org/hibernate/dialect/resolver/DialectResolverTest.java index 76acb4308c..c8609122dc 100644 --- a/hibernate-core/src/test/java/org/hibernate/dialect/resolver/DialectResolverTest.java +++ b/hibernate-core/src/test/java/org/hibernate/dialect/resolver/DialectResolverTest.java @@ -1,10 +1,10 @@ /* * Hibernate, Relational Persistence for Idiomatic Java * - * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as + * Copyright (c) 2008-2011, Red Hat Inc. or third-party contributors as * indicated by the @author tags or express copyright attribution * statements applied by the authors. All third-party contributions are - * distributed under license by Red Hat Middleware LLC. + * distributed under license by Red Hat Inc. * * This copyrighted material is made available to anyone wishing to use, modify, * copy, or redistribute it subject to the terms and conditions of the GNU @@ -20,13 +20,14 @@ * Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA - * */ package org.hibernate.dialect.resolver; import java.sql.SQLException; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; + +import org.junit.Test; +import static org.junit.Assert.fail; +import static org.junit.Assert.assertEquals; + import org.hibernate.dialect.Dialect; import org.hibernate.dialect.Mocks; import org.hibernate.dialect.TestingDialects; @@ -34,18 +35,13 @@ import org.hibernate.exception.JDBCConnectionException; import org.hibernate.service.jdbc.dialect.internal.BasicDialectResolver; import org.hibernate.service.jdbc.dialect.internal.DialectResolverSet; import org.hibernate.service.jdbc.dialect.spi.DialectResolver; +import org.hibernate.testing.junit4.BaseUnitTestCase; /** - * TODO : javadoc - * * @author Steve Ebersole */ -public class DialectResolverTest extends TestCase { - - public DialectResolverTest(String name) { - super( name ); - } - +public class DialectResolverTest extends BaseUnitTestCase { + @Test public void testDialects() throws Exception { DialectResolverSet resolvers = new DialectResolverSet(); @@ -62,6 +58,7 @@ public class DialectResolverTest extends TestCase { testDetermination( resolvers, "MyTrickyDatabase1", 1, TestingDialects.MyDialect1.class ); } + @Test public void testErrorAndOrder() throws Exception { DialectResolverSet resolvers = new DialectResolverSet(); resolvers.addResolverAtFirst( new TestingDialects.MyDialectResolver1() ); @@ -84,6 +81,7 @@ public class DialectResolverTest extends TestCase { } } + @Test public void testBasicDialectResolver() throws Exception { DialectResolverSet resolvers = new DialectResolverSet(); // Simulating MyDialectResolver1 by BasicDialectResolvers @@ -114,8 +112,4 @@ public class DialectResolverTest extends TestCase { assertEquals( dialectClass, dialect.getClass() ); } } - - public static Test suite() { - return new TestSuite( DialectResolverTest.class ); - } } diff --git a/hibernate-core/src/test/java/org/hibernate/engine/query/ParameterParserTest.java b/hibernate-core/src/test/java/org/hibernate/engine/query/ParameterParserTest.java index a610f40f5e..45c554cac3 100644 --- a/hibernate-core/src/test/java/org/hibernate/engine/query/ParameterParserTest.java +++ b/hibernate-core/src/test/java/org/hibernate/engine/query/ParameterParserTest.java @@ -23,14 +23,20 @@ * */ package org.hibernate.engine.query; -import junit.framework.TestCase; + +import org.junit.Test; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertFalse; + +import org.hibernate.testing.junit4.BaseUnitTestCase; /** * Unit tests of the ParameterParser class * * @author Steve Ebersole */ -public class ParameterParserTest extends TestCase { +public class ParameterParserTest extends BaseUnitTestCase { + @Test public void testEscapeCallRecognition() { assertTrue( ParameterParser.startsWithEscapeCallTemplate( "{ ? = call abc(?) }" ) ); assertFalse( ParameterParser.startsWithEscapeCallTemplate( "from User u where u.userName = ? and u.userType = 'call'" ) ); diff --git a/hibernate-core/src/test/java/org/hibernate/id/AbstractHolderTest.java b/hibernate-core/src/test/java/org/hibernate/id/AbstractHolderTest.java index e45fc7046e..e418b54449 100644 --- a/hibernate-core/src/test/java/org/hibernate/id/AbstractHolderTest.java +++ b/hibernate-core/src/test/java/org/hibernate/id/AbstractHolderTest.java @@ -22,16 +22,23 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.id; -import junit.framework.TestCase; + +import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.fail; + +import org.hibernate.testing.junit4.BaseUnitTestCase; /** - * TODO : javadoc - * * @author Steve Ebersole */ -public abstract class AbstractHolderTest extends TestCase { +@SuppressWarnings( {"UnusedDeclaration"}) +public abstract class AbstractHolderTest extends BaseUnitTestCase { protected abstract IntegralDataTypeHolder makeHolder(); + @Test + @SuppressWarnings( {"EmptyCatchBlock"}) public void testInitializationChecking() { IntegralDataTypeHolder holder = makeHolder(); try { diff --git a/hibernate-core/src/test/java/org/hibernate/id/BigDecimalHolderTest.java b/hibernate-core/src/test/java/org/hibernate/id/BigDecimalHolderTest.java index 30794c5585..c87af14445 100644 --- a/hibernate-core/src/test/java/org/hibernate/id/BigDecimalHolderTest.java +++ b/hibernate-core/src/test/java/org/hibernate/id/BigDecimalHolderTest.java @@ -25,8 +25,6 @@ package org.hibernate.id; import java.math.BigDecimal; /** - * TODO : javadoc - * * @author Steve Ebersole */ public class BigDecimalHolderTest extends AbstractHolderTest { diff --git a/hibernate-core/src/test/java/org/hibernate/id/BigIntegerHolderTest.java b/hibernate-core/src/test/java/org/hibernate/id/BigIntegerHolderTest.java index 206bbc83fe..e1cdc8eaa5 100644 --- a/hibernate-core/src/test/java/org/hibernate/id/BigIntegerHolderTest.java +++ b/hibernate-core/src/test/java/org/hibernate/id/BigIntegerHolderTest.java @@ -25,8 +25,6 @@ package org.hibernate.id; import java.math.BigInteger; /** - * TODO : javadoc - * * @author Steve Ebersole */ public class BigIntegerHolderTest extends AbstractHolderTest { diff --git a/hibernate-core/src/test/java/org/hibernate/id/LongHolderTest.java b/hibernate-core/src/test/java/org/hibernate/id/LongHolderTest.java index d793c2399f..0659640d16 100644 --- a/hibernate-core/src/test/java/org/hibernate/id/LongHolderTest.java +++ b/hibernate-core/src/test/java/org/hibernate/id/LongHolderTest.java @@ -25,8 +25,6 @@ package org.hibernate.id; /** - * TODO : javadoc - * * @author Steve Ebersole */ public class LongHolderTest extends AbstractHolderTest { diff --git a/hibernate-core/src/test/java/org/hibernate/id/SequenceHiLoGeneratorNoIncrementTest.java b/hibernate-core/src/test/java/org/hibernate/id/SequenceHiLoGeneratorNoIncrementTest.java index 263589263d..bd85bcd2f6 100644 --- a/hibernate-core/src/test/java/org/hibernate/id/SequenceHiLoGeneratorNoIncrementTest.java +++ b/hibernate-core/src/test/java/org/hibernate/id/SequenceHiLoGeneratorNoIncrementTest.java @@ -28,7 +28,7 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.Properties; -import junit.framework.TestCase; + import org.hibernate.Hibernate; import org.hibernate.Session; import org.hibernate.TestingDatabaseInfo; @@ -52,7 +52,7 @@ import org.hibernate.testing.ServiceRegistryBuilder; * @author Steve Ebersole */ @SuppressWarnings({ "deprecation" }) -public class SequenceHiLoGeneratorNoIncrementTest extends TestCase { +public class SequenceHiLoGeneratorNoIncrementTest extends BaseUnitTestCase { private static final String TEST_SEQUENCE = "test_sequence"; private Configuration cfg; @@ -60,7 +60,7 @@ public class SequenceHiLoGeneratorNoIncrementTest extends TestCase { private SessionFactoryImplementor sessionFactory; private SequenceHiLoGenerator generator; - @Override + @Before protected void setUp() throws Exception { super.setUp(); @@ -100,7 +100,7 @@ public class SequenceHiLoGeneratorNoIncrementTest extends TestCase { sessionFactory = (SessionFactoryImplementor) cfg.buildSessionFactory( serviceRegistry ); } - @Override + @After protected void tearDown() throws Exception { if ( sessionFactory != null ) { sessionFactory.close(); @@ -111,6 +111,7 @@ public class SequenceHiLoGeneratorNoIncrementTest extends TestCase { super.tearDown(); } + @Test public void testHiLoAlgorithm() { SessionImpl session = (SessionImpl) sessionFactory.openSession(); session.beginTransaction(); diff --git a/hibernate-core/src/test/java/org/hibernate/id/SequenceHiLoGeneratorTest.java b/hibernate-core/src/test/java/org/hibernate/id/SequenceHiLoGeneratorTest.java index 7b1308d4fb..ab072fb57b 100644 --- a/hibernate-core/src/test/java/org/hibernate/id/SequenceHiLoGeneratorTest.java +++ b/hibernate-core/src/test/java/org/hibernate/id/SequenceHiLoGeneratorTest.java @@ -28,7 +28,7 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.Properties; -import junit.framework.TestCase; + import org.hibernate.Hibernate; import org.hibernate.Session; import org.hibernate.TestingDatabaseInfo; @@ -43,7 +43,15 @@ import org.hibernate.impl.SessionImpl; import org.hibernate.jdbc.Work; import org.hibernate.mapping.SimpleAuxiliaryDatabaseObject; import org.hibernate.service.spi.ServiceRegistry; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + import org.hibernate.testing.ServiceRegistryBuilder; +import org.hibernate.testing.junit4.BaseUnitTestCase; + +import static org.junit.Assert.assertEquals; /** * I went back to 3.3 source and grabbed the code/logic as it existed back then and crafted this @@ -52,7 +60,7 @@ import org.hibernate.testing.ServiceRegistryBuilder; * @author Steve Ebersole */ @SuppressWarnings({ "deprecation" }) -public class SequenceHiLoGeneratorTest extends TestCase { +public class SequenceHiLoGeneratorTest extends BaseUnitTestCase { private static final String TEST_SEQUENCE = "test_sequence"; private Configuration cfg; @@ -60,10 +68,8 @@ public class SequenceHiLoGeneratorTest extends TestCase { private SessionFactoryImplementor sessionFactory; private SequenceHiLoGenerator generator; - @Override - protected void setUp() throws Exception { - super.setUp(); - + @Before + public void setUp() throws Exception { Properties properties = new Properties(); properties.setProperty( SequenceGenerator.SEQUENCE, TEST_SEQUENCE ); properties.setProperty( SequenceHiLoGenerator.MAX_LO, "3" ); @@ -99,17 +105,17 @@ public class SequenceHiLoGeneratorTest extends TestCase { sessionFactory = (SessionFactoryImplementor) cfg.buildSessionFactory( serviceRegistry ); } - @Override - protected void tearDown() throws Exception { + @After + public void tearDown() throws Exception { if ( sessionFactory != null ) { sessionFactory.close(); } if ( serviceRegistry != null ) { ServiceRegistryBuilder.destroy( serviceRegistry ); } - super.tearDown(); } + @Test public void testHiLoAlgorithm() { SessionImpl session = (SessionImpl) sessionFactory.openSession(); session.beginTransaction(); diff --git a/hibernate-core/src/test/java/org/hibernate/id/TableHiLoGeneratorTest.java b/hibernate-core/src/test/java/org/hibernate/id/TableHiLoGeneratorTest.java index 922263ca61..e5447b44b7 100644 --- a/hibernate-core/src/test/java/org/hibernate/id/TableHiLoGeneratorTest.java +++ b/hibernate-core/src/test/java/org/hibernate/id/TableHiLoGeneratorTest.java @@ -27,8 +27,7 @@ import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; -import java.util.Properties; -import junit.framework.TestCase; + import org.hibernate.Hibernate; import org.hibernate.Session; import org.hibernate.TestingDatabaseInfo; @@ -43,7 +42,15 @@ import org.hibernate.impl.SessionImpl; import org.hibernate.jdbc.Work; import org.hibernate.mapping.SimpleAuxiliaryDatabaseObject; import org.hibernate.service.spi.ServiceRegistry; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + import org.hibernate.testing.ServiceRegistryBuilder; +import org.hibernate.testing.junit4.BaseUnitTestCase; + +import static org.junit.Assert.assertEquals; /** * I went back to 3.3 source and grabbed the code/logic as it existed back then and crafted this @@ -52,7 +59,7 @@ import org.hibernate.testing.ServiceRegistryBuilder; * @author Steve Ebersole */ @SuppressWarnings({ "deprecation" }) -public class TableHiLoGeneratorTest extends TestCase { +public class TableHiLoGeneratorTest extends BaseUnitTestCase { private static final String GEN_TABLE = "generator_table"; private static final String GEN_COLUMN = TableHiLoGenerator.DEFAULT_COLUMN_NAME; @@ -61,10 +68,8 @@ public class TableHiLoGeneratorTest extends TestCase { private SessionFactoryImplementor sessionFactory; private TableHiLoGenerator generator; - @Override - protected void setUp() throws Exception { - super.setUp(); - + @Before + public void setUp() throws Exception { Properties properties = new Properties(); properties.setProperty( TableGenerator.TABLE, GEN_TABLE ); properties.setProperty( TableGenerator.COLUMN, GEN_COLUMN ); @@ -109,18 +114,17 @@ public class TableHiLoGeneratorTest extends TestCase { sessionFactory = (SessionFactoryImplementor) cfg.buildSessionFactory( serviceRegistry ); } - @Override - protected void tearDown() throws Exception { + @After + public void tearDown() throws Exception { if ( sessionFactory != null ) { sessionFactory.close(); } if ( serviceRegistry != null ) { ServiceRegistryBuilder.destroy( serviceRegistry ); } - - super.tearDown(); } + @Test public void testHiLoAlgorithm() { SessionImpl session = (SessionImpl) sessionFactory.openSession(); session.beginTransaction(); diff --git a/hibernate-core/src/test/java/org/hibernate/id/enhanced/OptimizerUnitTest.java b/hibernate-core/src/test/java/org/hibernate/id/enhanced/OptimizerUnitTest.java index 9931128cdf..b34fb8eafe 100644 --- a/hibernate-core/src/test/java/org/hibernate/id/enhanced/OptimizerUnitTest.java +++ b/hibernate-core/src/test/java/org/hibernate/id/enhanced/OptimizerUnitTest.java @@ -21,28 +21,25 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.id.enhanced; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; +package org.hibernate.id.enhanced; + import org.hibernate.id.IdentifierGeneratorHelper; import org.hibernate.id.IntegralDataTypeHolder; +import org.junit.Test; + +import org.hibernate.testing.junit4.BaseUnitTestCase; + +import static org.junit.Assert.assertEquals; + /** * {@inheritDoc} * * @author Steve Ebersole */ @SuppressWarnings({ "deprecation" }) -public class OptimizerUnitTest extends TestCase { - public OptimizerUnitTest(String string) { - super( string ); - } - - public static Test suite() { - return new TestSuite( OptimizerUnitTest.class ); - } - +public class OptimizerUnitTest extends BaseUnitTestCase { + @Test public void testBasicNoOptimizerUsage() { // test historic sequence behavior, where the initial values start at 1... SourceMock sequence = new SourceMock( 1 ); @@ -65,6 +62,7 @@ public class OptimizerUnitTest extends TestCase { assertEquals( 10, sequence.getCurrentValue() ); } + @Test public void testBasicHiLoOptimizerUsage() { int increment = 10; Long next; @@ -100,6 +98,7 @@ public class OptimizerUnitTest extends TestCase { assertEquals( 2, sequence.getCurrentValue() ); } + @Test public void testBasicPooledOptimizerUsage() { Long next; // test historic sequence behavior, where the initial values start at 1... @@ -118,6 +117,7 @@ public class OptimizerUnitTest extends TestCase { assertEquals( 21, sequence.getCurrentValue() ); } + @Test public void testSubsequentPooledOptimizerUsage() { // test the pooled optimizer in situation where the sequence is already beyond its initial value on init. // cheat by telling the sequence to start with 1000 @@ -150,6 +150,7 @@ public class OptimizerUnitTest extends TestCase { assertEquals( (1001+6), sequence.getCurrentValue() ); } + @Test public void testBasicPooledLoOptimizerUsage() { final SourceMock sequence = new SourceMock( 1, 3 ); final Optimizer optimizer = OptimizerFactory.buildOptimizer( OptimizerFactory.POOL_LO, Long.class, 3 ); @@ -179,6 +180,7 @@ public class OptimizerUnitTest extends TestCase { assertEquals( (1+3), sequence.getCurrentValue() ); } + @Test public void testSubsequentPooledLoOptimizerUsage() { // test the pooled optimizer in situation where the sequence is already beyond its initial value on init. // cheat by telling the sequence to start with 1000 @@ -211,6 +213,7 @@ public class OptimizerUnitTest extends TestCase { assertEquals( (1001+6), sequence.getCurrentValue() ); } + @Test public void testRecoveredPooledOptimizerUsage() { final SourceMock sequence = new SourceMock( 1, 3 ); final Optimizer optimizer = OptimizerFactory.buildOptimizer( OptimizerFactory.POOL, Long.class, 3, 1 ); @@ -231,6 +234,7 @@ public class OptimizerUnitTest extends TestCase { assertEquals( 7, sequence.getCurrentValue() ); } + @Test public void testRecoveredPooledLoOptimizerUsage() { final SourceMock sequence = new SourceMock( 1, 3 ); final Optimizer optimizer = OptimizerFactory.buildOptimizer( OptimizerFactory.POOL_LO, Long.class, 3, 1 ); @@ -306,30 +310,4 @@ public class OptimizerUnitTest extends TestCase { } } -// public void testNoopDumping() { -// SourceMock sequence = new SourceMock( 1 ); -// Optimizer optimizer = OptimizerFactory.buildOptimizer( OptimizerFactory.NONE, Long.class, 1 ); -// for ( int i = 1; i <= 41; i++ ) { -// System.out.println( i + " => " + optimizer.generate( sequence ) + " (" + sequence.getCurrentValue() + ")" ); -// } -// } -// -// public void testHiLoDumping() { -// int increment = 10; -// SourceMock sequence = new SourceMock( 1 ); -// Optimizer optimizer = OptimizerFactory.buildOptimizer( OptimizerFactory.HILO, Long.class, increment ); -// for ( int i = 1; i <= 41; i++ ) { -// System.out.println( i + " => " + optimizer.generate( sequence ) + " (" + sequence.getCurrentValue() + ")" ); -// } -// } -// -// public void testPooledDumping() { -// int increment = 10; -// SourceMock sequence = new SourceMock( 1, increment ); -// Optimizer optimizer = OptimizerFactory.buildOptimizer( OptimizerFactory.POOL, Long.class, increment ); -// for ( int i = 1; i <= 41; i++ ) { -// System.out.println( i + " => " + optimizer.generate( sequence ) + " (" + sequence.getCurrentValue() + ")" ); -// } -// } - } diff --git a/hibernate-core/src/test/java/org/hibernate/id/enhanced/SequenceStyleConfigUnitTest.java b/hibernate-core/src/test/java/org/hibernate/id/enhanced/SequenceStyleConfigUnitTest.java index 2d0479b7ff..e77a6e9859 100644 --- a/hibernate-core/src/test/java/org/hibernate/id/enhanced/SequenceStyleConfigUnitTest.java +++ b/hibernate-core/src/test/java/org/hibernate/id/enhanced/SequenceStyleConfigUnitTest.java @@ -21,11 +21,10 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.id.enhanced; +package org.hibernate.id.enhanced; + import java.util.Properties; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; + import org.hibernate.Hibernate; import org.hibernate.MappingException; import org.hibernate.cfg.Environment; @@ -34,22 +33,20 @@ import org.hibernate.cfg.ObjectNameNormalizer; import org.hibernate.dialect.Dialect; import org.hibernate.id.PersistentIdentifierGenerator; +import org.junit.Test; + +import org.hibernate.testing.junit4.BaseUnitTestCase; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + /** - * Tests that SequenceStyleGenerator configures itself as expected - * in various scenarios + * Tests that SequenceStyleGenerator configures itself as expected in various scenarios * * @author Steve Ebersole */ @SuppressWarnings({ "deprecation" }) -public class SequenceStyleConfigUnitTest extends TestCase { - public SequenceStyleConfigUnitTest(String string) { - super( string ); - } - - public static Test suite() { - return new TestSuite( SequenceStyleConfigUnitTest.class ); - } - +public class SequenceStyleConfigUnitTest extends BaseUnitTestCase { private void assertClassAssignability(Class expected, Class actual) { if ( ! expected.isAssignableFrom( actual ) ) { fail( "Actual type [" + actual.getName() + "] is not assignable to expected type [" + expected.getName() + "]" ); @@ -60,6 +57,7 @@ public class SequenceStyleConfigUnitTest extends TestCase { /** * Test all params defaulted with a dialect supporting sequences */ + @Test public void testDefaultedSequenceBackedConfiguration() { Dialect dialect = new SequenceDialect(); Properties props = buildGeneratorPropertiesBase(); @@ -91,6 +89,7 @@ public class SequenceStyleConfigUnitTest extends TestCase { /** * Test all params defaulted with a dialect which does not support sequences */ + @Test public void testDefaultedTableBackedConfiguration() { Dialect dialect = new TableDialect(); Properties props = buildGeneratorPropertiesBase(); @@ -107,6 +106,7 @@ public class SequenceStyleConfigUnitTest extends TestCase { * based on the configured increment size; both in the case of the * dialect supporting pooled sequences (pooled) and not (hilo) */ + @Test public void testDefaultOptimizerBasedOnIncrementBackedBySequence() { Properties props = buildGeneratorPropertiesBase(); props.setProperty( SequenceStyleGenerator.INCREMENT_PARAM, "10" ); @@ -133,6 +133,7 @@ public class SequenceStyleConfigUnitTest extends TestCase { * based on the configured increment size. Here we always prefer * pooled. */ + @Test public void testDefaultOptimizerBasedOnIncrementBackedByTable() { Properties props = buildGeneratorPropertiesBase(); props.setProperty( SequenceStyleGenerator.INCREMENT_PARAM, "10" ); @@ -147,6 +148,7 @@ public class SequenceStyleConfigUnitTest extends TestCase { /** * Test forcing of table as backing strucuture with dialect supporting sequences */ + @Test public void testForceTableUse() { Dialect dialect = new SequenceDialect(); Properties props = buildGeneratorPropertiesBase(); @@ -161,6 +163,7 @@ public class SequenceStyleConfigUnitTest extends TestCase { /** * Test explicitly specifying both optimizer and increment */ + @Test public void testExplicitOptimizerWithExplicitIncrementSize() { // with sequence ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ final Dialect dialect = new SequenceDialect(); @@ -201,6 +204,7 @@ public class SequenceStyleConfigUnitTest extends TestCase { assertEquals( 20, generator.getDatabaseStructure().getIncrementSize() ); } + @Test public void testPreferPooledLoSettingHonored() { final Dialect dialect = new PooledSequenceDialect(); diff --git a/hibernate-core/src/test/java/org/hibernate/id/uuid/CustomVersionOneStrategyTest.java b/hibernate-core/src/test/java/org/hibernate/id/uuid/CustomVersionOneStrategyTest.java index 8c17c20b81..242eb7f2ab 100644 --- a/hibernate-core/src/test/java/org/hibernate/id/uuid/CustomVersionOneStrategyTest.java +++ b/hibernate-core/src/test/java/org/hibernate/id/uuid/CustomVersionOneStrategyTest.java @@ -19,22 +19,23 @@ * along with this distribution; if not, write to: * Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor - * Boston, MA 02110-1301 USA + * Boston, MA 02110-1301 USABasicFormatterTes */ package org.hibernate.id.uuid; + +import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; + import java.util.UUID; -import junit.framework.TestCase; + +import org.hibernate.testing.junit4.BaseUnitTestCase; /** - * TODO : javadoc - * * @author Steve Ebersole */ -public class CustomVersionOneStrategyTest extends TestCase { - public static void main(String[] args) { - System.out.println( System.currentTimeMillis() ); - System.out.println( Long.MAX_VALUE ); - } +public class CustomVersionOneStrategyTest extends BaseUnitTestCase { + @Test public void testUniqueCounter() { CustomVersionOneStrategy strategy = new CustomVersionOneStrategy(); long now = System.currentTimeMillis(); @@ -57,6 +58,7 @@ public class CustomVersionOneStrategyTest extends TestCase { } } + @Test public void testRangeOfValues() { CustomVersionOneStrategy strategy = new CustomVersionOneStrategy(); diff --git a/hibernate-core/src/test/java/org/hibernate/jdbc/LobCreatorTest.java b/hibernate-core/src/test/java/org/hibernate/jdbc/LobCreatorTest.java index 7935df13cb..e632d19e88 100644 --- a/hibernate-core/src/test/java/org/hibernate/jdbc/LobCreatorTest.java +++ b/hibernate-core/src/test/java/org/hibernate/jdbc/LobCreatorTest.java @@ -23,37 +23,44 @@ */ package org.hibernate.jdbc; -import java.sql.*; -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.Method; -import java.lang.reflect.Proxy; import java.io.InputStream; import java.io.OutputStream; import java.io.Reader; import java.io.Writer; +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; +import java.lang.reflect.Proxy; +import java.sql.Blob; +import java.sql.Clob; +import java.sql.Connection; +import java.sql.DatabaseMetaData; +import java.sql.NClob; +import java.sql.SQLException; import java.util.Properties; -import junit.framework.TestCase; - import org.hibernate.cfg.Environment; -import org.hibernate.engine.jdbc.internal.LobCreatorBuilder; +import org.hibernate.engine.jdbc.BlobImplementer; +import org.hibernate.engine.jdbc.ClobImplementer; import org.hibernate.engine.jdbc.ContextualLobCreator; import org.hibernate.engine.jdbc.LobCreationContext; import org.hibernate.engine.jdbc.LobCreator; -import org.hibernate.engine.jdbc.BlobImplementer; -import org.hibernate.engine.jdbc.ClobImplementer; import org.hibernate.engine.jdbc.NClobImplementer; +import org.hibernate.engine.jdbc.NonContextualLobCreator; import org.hibernate.engine.jdbc.WrappedBlob; import org.hibernate.engine.jdbc.WrappedClob; -import org.hibernate.engine.jdbc.NonContextualLobCreator; +import org.hibernate.engine.jdbc.internal.LobCreatorBuilder; + +import org.junit.Test; + +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; /** - * TODO : javadoc - * * @author Steve Ebersole */ -public class LobCreatorTest extends TestCase { +public class LobCreatorTest extends org.hibernate.testing.junit4.BaseUnitTestCase { + @Test public void testConnectedLobCreator() throws SQLException { final Connection connection = createConnectionProxy( 4, new JdbcLobBuilderImpl( true ) ); LobCreationContext lobCreationContext = new LobCreationContextImpl( connection ); @@ -152,7 +159,7 @@ public class LobCreatorTest extends TestCase { this.connection = connection; } - public Object execute( LobCreationContext.Callback callback) { + public T execute(LobCreationContext.Callback callback) { try { return callback.executeOnConnection( connection ); } diff --git a/hibernate-core/src/test/java/org/hibernate/jdbc/util/BasicFormatterTest.java b/hibernate-core/src/test/java/org/hibernate/jdbc/util/BasicFormatterTest.java index 189ca1e4eb..03bf6b0602 100644 --- a/hibernate-core/src/test/java/org/hibernate/jdbc/util/BasicFormatterTest.java +++ b/hibernate-core/src/test/java/org/hibernate/jdbc/util/BasicFormatterTest.java @@ -1,34 +1,46 @@ /* - * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved. + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2007-2011, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. * * This copyrighted material is made available to anyone wishing to use, modify, * copy, or redistribute it subject to the terms and conditions of the GNU - * Lesser General Public License, v. 2.1. This program is distributed in the - * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. You should have received a - * copy of the GNU Lesser General Public License, v.2.1 along with this - * distribution; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * Lesser General Public License, as published by the Free Software Foundation. * - * Red Hat Author(s): Steve Ebersole + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA */ package org.hibernate.jdbc.util; + import java.util.StringTokenizer; -import junit.framework.TestCase; import org.hibernate.engine.jdbc.internal.FormatStyle; +import org.junit.Test; + +import org.hibernate.testing.junit4.BaseUnitTestCase; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; + /** * BasicFormatterTest implementation * * @author Steve Ebersole */ -public class BasicFormatterTest extends TestCase { - public BasicFormatterTest(String name) { - super( name ); - } - +public class BasicFormatterTest extends BaseUnitTestCase { + @Test public void testNoLoss() { assertNoLoss( "insert into Address (city, state, zip, \"from\") values (?, ?, ?, 'insert value')" ); assertNoLoss( "delete from Address where id = ? and version = ?" ); diff --git a/hibernate-core/src/test/java/org/hibernate/jmx/TrivialTest.java b/hibernate-core/src/test/java/org/hibernate/jmx/TrivialTest.java index 4a7f15f485..5ff5e054f1 100644 --- a/hibernate-core/src/test/java/org/hibernate/jmx/TrivialTest.java +++ b/hibernate-core/src/test/java/org/hibernate/jmx/TrivialTest.java @@ -22,14 +22,16 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.jmx; -import junit.framework.TestCase; + +import org.junit.Test; + +import org.hibernate.testing.junit4.BaseUnitTestCase; /** - * Test copied over from o.h.t.legacy.FooBarTest - * * @author Steve Ebersole */ -public class TrivialTest extends TestCase { +public class TrivialTest extends BaseUnitTestCase { + @Test public void testService() throws Exception { HibernateService hs = new HibernateService(); hs.setJndiName( "SessionFactory" ); diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/relational/ObjectNameTests.java b/hibernate-core/src/test/java/org/hibernate/metamodel/relational/ObjectNameTests.java index c1c56d3c6d..d5af47764b 100644 --- a/hibernate-core/src/test/java/org/hibernate/metamodel/relational/ObjectNameTests.java +++ b/hibernate-core/src/test/java/org/hibernate/metamodel/relational/ObjectNameTests.java @@ -22,18 +22,18 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.metamodel.relational; -import org.hibernate.testing.junit.UnitTestCase; + +import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +import org.hibernate.testing.junit4.BaseUnitTestCase; /** - * TODO : javadoc - * * @author Steve Ebersole */ -public class ObjectNameTests extends UnitTestCase { - public ObjectNameTests(String string) { - super( string ); - } - +public class ObjectNameTests extends BaseUnitTestCase { + @Test public void testMissingName() { try { new ObjectName( (String)null, null, null ); @@ -50,6 +50,7 @@ public class ObjectNameTests extends UnitTestCase { } } + @Test public void testIdentifierBuilding() { ObjectName on = new ObjectName( "schema", "catalog", "name" ); assertEquals( "schema.catalog.name", on.getIdentifier() ); diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/relational/TableManipulationTests.java b/hibernate-core/src/test/java/org/hibernate/metamodel/relational/TableManipulationTests.java index ba3344d3b2..6abe6932f5 100644 --- a/hibernate-core/src/test/java/org/hibernate/metamodel/relational/TableManipulationTests.java +++ b/hibernate-core/src/test/java/org/hibernate/metamodel/relational/TableManipulationTests.java @@ -22,22 +22,28 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.metamodel.relational; + import java.sql.Types; -import org.hibernate.testing.junit.UnitTestCase; + +import org.junit.Test; + +import org.hibernate.testing.junit4.BaseUnitTestCase; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; /** * TODO : javadoc * * @author Steve Ebersole */ -public class TableManipulationTests extends UnitTestCase { +public class TableManipulationTests extends BaseUnitTestCase { public static final Datatype VARCHAR = new Datatype( Types.VARCHAR, "VARCHAR", String.class ); public static final Datatype INTEGER = new Datatype( Types.INTEGER, "INTEGER", Long.class ); - public TableManipulationTests(String string) { - super( string ); - } - + @Test public void testTableCreation() { Table table = new Table( new ObjectName( null, null, "my_table" ) ); assertNull( table.getObjectName().getSchema() ); @@ -80,6 +86,7 @@ public class TableManipulationTests extends UnitTestCase { } } + @Test public void testBasicForeignKeyDefinition() { Table book = new Table( new ObjectName( null, null, "BOOK" ) ); diff --git a/hibernate-core/src/test/java/org/hibernate/property/BasicPropertyAccessorTest.java b/hibernate-core/src/test/java/org/hibernate/property/BasicPropertyAccessorTest.java index 2e9d6cd3a1..be34eef058 100644 --- a/hibernate-core/src/test/java/org/hibernate/property/BasicPropertyAccessorTest.java +++ b/hibernate-core/src/test/java/org/hibernate/property/BasicPropertyAccessorTest.java @@ -22,14 +22,17 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.property; -import junit.framework.TestCase; + +import org.junit.Test; + +import org.hibernate.testing.junit4.BaseUnitTestCase; + +import static org.junit.Assert.assertEquals; /** - * TODO : javadoc - * * @author Steve Ebersole */ -public class BasicPropertyAccessorTest extends TestCase { +public class BasicPropertyAccessorTest extends BaseUnitTestCase { public static abstract class Super { public abstract Object getIt(); public abstract void setIt(Object it); @@ -80,6 +83,7 @@ public class BasicPropertyAccessorTest extends TestCase { } } + @Test public void testBridgeMethodDisregarded() { BasicPropertyAccessor accessor = new BasicPropertyAccessor(); diff --git a/hibernate-core/src/test/java/org/hibernate/sql/TemplateTest.java b/hibernate-core/src/test/java/org/hibernate/sql/TemplateTest.java index c4ffcb75c9..c166163404 100644 --- a/hibernate-core/src/test/java/org/hibernate/sql/TemplateTest.java +++ b/hibernate-core/src/test/java/org/hibernate/sql/TemplateTest.java @@ -1,10 +1,10 @@ /* * Hibernate, Relational Persistence for Idiomatic Java * - * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as + * Copyright (c) 2008-2011, Red Hat Inc. or third-party contributors as * indicated by the @author tags or express copyright attribution * statements applied by the authors. All third-party contributions are - * distributed under license by Red Hat Middleware LLC. + * distributed under license by Red Hat Inc. * * This copyrighted material is made available to anyone wishing to use, modify, * copy, or redistribute it subject to the terms and conditions of the GNU @@ -20,11 +20,11 @@ * Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA - * */ package org.hibernate.sql; + import java.util.Collections; -import junit.framework.TestCase; + import org.hibernate.QueryException; import org.hibernate.dialect.Dialect; import org.hibernate.dialect.HSQLDialect; @@ -33,12 +33,16 @@ import org.hibernate.persister.entity.PropertyMapping; import org.hibernate.sql.ordering.antlr.ColumnMapper; import org.hibernate.type.Type; +import org.junit.Test; + +import org.hibernate.testing.junit4.BaseUnitTestCase; + +import static org.junit.Assert.assertEquals; + /** - * TODO : javadoc - * * @author Steve Ebersole */ -public class TemplateTest extends TestCase { +public class TemplateTest extends BaseUnitTestCase { private static final PropertyMapping PROPERTY_MAPPING = new PropertyMapping() { public String[] toColumns(String propertyName) throws QueryException, UnsupportedOperationException { if ( "sql".equals( propertyName ) ) { @@ -82,6 +86,7 @@ public class TemplateTest extends TestCase { private static final SQLFunctionRegistry FUNCTION_REGISTRY = new SQLFunctionRegistry( DIALECT, Collections.EMPTY_MAP ); + @Test public void testSqlExtractFunction() { String fragment = "extract( year from col )"; String template = Template.renderWhereStringTemplate( fragment, Template.TEMPLATE, DIALECT, FUNCTION_REGISTRY ); @@ -89,6 +94,7 @@ public class TemplateTest extends TestCase { assertEquals( "extract(year from " + Template.TEMPLATE + ".col)", template ); } + @Test public void testSqlTrimFunction() { String fragment = "trim( col )"; String template = Template.renderWhereStringTemplate( fragment, Template.TEMPLATE, DIALECT, FUNCTION_REGISTRY ); @@ -119,6 +125,7 @@ public class TemplateTest extends TestCase { assertEquals( "trim(both 'b' from " + Template.TEMPLATE + ".col)", template ); } + @Test public void testSQLReferences() { String fragment = "sql asc, sql desc"; String template = doStandardRendering( fragment ); @@ -126,6 +133,7 @@ public class TemplateTest extends TestCase { assertEquals( Template.TEMPLATE + ".sql asc, " + Template.TEMPLATE + ".sql desc", template ); } + @Test public void testQuotedSQLReferences() { String fragment = "`sql` asc, `sql` desc"; String template = doStandardRendering( fragment ); @@ -133,6 +141,7 @@ public class TemplateTest extends TestCase { assertEquals( Template.TEMPLATE + ".\"sql\" asc, " + Template.TEMPLATE + ".\"sql\" desc", template ); } + @Test public void testPropertyReference() { String fragment = "property asc, property desc"; String template = doStandardRendering( fragment ); @@ -140,6 +149,7 @@ public class TemplateTest extends TestCase { assertEquals( Template.TEMPLATE + ".prop asc, " + Template.TEMPLATE + ".prop desc", template ); } + @Test public void testFunctionReference() { String fragment = "upper(sql) asc, lower(sql) desc"; String template = doStandardRendering( fragment ); @@ -147,6 +157,7 @@ public class TemplateTest extends TestCase { assertEquals( "upper(" + Template.TEMPLATE + ".sql) asc, lower(" + Template.TEMPLATE + ".sql) desc", template ); } + @Test public void testQualifiedFunctionReference() { String fragment = "qual.upper(property) asc, qual.lower(property) desc"; String template = doStandardRendering( fragment ); @@ -154,6 +165,7 @@ public class TemplateTest extends TestCase { assertEquals( "qual.upper(" + Template.TEMPLATE + ".prop) asc, qual.lower(" + Template.TEMPLATE + ".prop) desc", template ); } + @Test public void testDoubleQualifiedFunctionReference() { String fragment = "qual1.qual2.upper(property) asc, qual1.qual2.lower(property) desc"; String template = doStandardRendering( fragment ); @@ -161,6 +173,7 @@ public class TemplateTest extends TestCase { assertEquals( "qual1.qual2.upper(" + Template.TEMPLATE + ".prop) asc, qual1.qual2.lower(" + Template.TEMPLATE + ".prop) desc", template ); } + @Test public void testFunctionWithPropertyReferenceAsParam() { String fragment = "upper(property) asc, lower(property) desc"; String template = doStandardRendering( fragment ); @@ -168,6 +181,7 @@ public class TemplateTest extends TestCase { assertEquals( "upper(" + Template.TEMPLATE + ".prop) asc, lower(" + Template.TEMPLATE + ".prop) desc", template ); } + @Test public void testNestedFunctionReferences() { String fragment = "upper(lower(sql)) asc, lower(upper(sql)) desc"; String template = doStandardRendering( fragment ); @@ -175,6 +189,7 @@ public class TemplateTest extends TestCase { assertEquals( "upper(lower(" + Template.TEMPLATE + ".sql)) asc, lower(upper(" + Template.TEMPLATE + ".sql)) desc", template ); } + @Test public void testComplexNestedFunctionReferences() { String fragment = "mod(mod(sql,2),3) asc"; String template = doStandardRendering( fragment ); @@ -182,6 +197,7 @@ public class TemplateTest extends TestCase { assertEquals( "mod(mod(" + Template.TEMPLATE + ".sql, 2), 3) asc", template ); } + @Test public void testCollation() { String fragment = "`sql` COLLATE my_collation, `sql` COLLATE your_collation"; String template = doStandardRendering( fragment ); @@ -189,22 +205,23 @@ public class TemplateTest extends TestCase { assertEquals( Template.TEMPLATE + ".\"sql\" collate my_collation, " + Template.TEMPLATE + ".\"sql\" collate your_collation", template ); } + @Test public void testCollationAndOrdering() { String fragment = "sql COLLATE my_collation, upper(prop) COLLATE your_collation asc, `sql` desc"; String template = doStandardRendering( fragment ); assertEquals( Template.TEMPLATE + ".sql collate my_collation, upper(" + Template.TEMPLATE + ".prop) collate your_collation asc, " + Template.TEMPLATE + ".\"sql\" desc", template ); - } + @Test public void testComponentReferences() { String fragment = "component asc"; String template = doStandardRendering( fragment ); assertEquals( Template.TEMPLATE + ".comp_1 asc, " + Template.TEMPLATE + ".comp_2 asc", template ); - } + @Test public void testComponentDerefReferences() { String fragment = "component.prop1 asc"; String template = doStandardRendering( fragment ); diff --git a/hibernate-core/src/test/java/org/hibernate/subclassProxyInterface/SubclassProxyInterfaceTest.java b/hibernate-core/src/test/java/org/hibernate/subclassProxyInterface/SubclassProxyInterfaceTest.java index da82e280b4..72c0126c50 100644 --- a/hibernate-core/src/test/java/org/hibernate/subclassProxyInterface/SubclassProxyInterfaceTest.java +++ b/hibernate-core/src/test/java/org/hibernate/subclassProxyInterface/SubclassProxyInterfaceTest.java @@ -22,19 +22,21 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.subclassProxyInterface; -import junit.framework.TestCase; + +import org.junit.Test; + import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Environment; import org.hibernate.dialect.H2Dialect; import org.hibernate.service.spi.ServiceRegistry; import org.hibernate.testing.ServiceRegistryBuilder; +import org.hibernate.testing.junit4.BaseUnitTestCase; /** - * TODO : javadoc - * * @author Steve Ebersole */ -public class SubclassProxyInterfaceTest extends TestCase { +public class SubclassProxyInterfaceTest extends BaseUnitTestCase { + @Test public void testSubclassProxyInterfaces() { final Configuration cfg = new Configuration() .setProperty( Environment.DIALECT, H2Dialect.class.getName() ) diff --git a/hibernate-core/src/test/java/org/hibernate/test/ast/ASTIteratorTest.java b/hibernate-core/src/test/java/org/hibernate/test/ast/ASTIteratorTest.java index 0f5d0c53b4..9fd05e0177 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/ast/ASTIteratorTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/ast/ASTIteratorTest.java @@ -1,45 +1,55 @@ -// $Id: ASTIteratorTest.java 10977 2006-12-12 23:28:04Z steve.ebersole@jboss.com $ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2006-2011, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ package org.hibernate.test.ast; + import java.io.PrintWriter; -import junit.framework.Test; -import junit.framework.TestSuite; + +import antlr.ASTFactory; +import antlr.collections.AST; + import org.hibernate.hql.antlr.HqlTokenTypes; import org.hibernate.hql.ast.HqlParser; import org.hibernate.hql.ast.util.ASTIterator; import org.hibernate.hql.ast.util.ASTParentsFirstIterator; import org.hibernate.hql.ast.util.ASTPrinter; import org.hibernate.hql.ast.util.ASTUtil; -import org.hibernate.testing.junit.UnitTestCase; -import antlr.ASTFactory; -import antlr.collections.AST; + +import org.junit.Test; + +import org.hibernate.testing.junit4.BaseUnitTestCase; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; /** * Test ASTIterator. */ -public class ASTIteratorTest extends UnitTestCase { - private ASTFactory factory; +public class ASTIteratorTest extends BaseUnitTestCase { + private ASTFactory factory = new ASTFactory(); - /** - * Standard JUnit test case constructor. - * - * @param name The name of the test case. - */ - public ASTIteratorTest(String name) { - super( name ); - } - - public static Test suite() { - return new TestSuite( ASTIteratorTest.class ); - } - - protected void setUp() throws Exception { - super.setUp(); - factory = new ASTFactory(); - } - - /** - * Test a simple tree, make sure the iterator encounters every node. - */ + @Test public void testSimpleTree() throws Exception { String input = "select foo from foo in class org.hibernate.test.Foo, fee in class org.hibernate.test.Fee where foo.dependent = fee order by foo.string desc, foo.component.count asc, fee.id"; HqlParser parser = HqlParser.getInstance( input ); @@ -65,6 +75,7 @@ public class ASTIteratorTest extends UnitTestCase { assertNotNull( uoe ); } + @Test public void testParentsFirstIterator() throws Exception { AST[] tree = new AST[4]; AST grandparent = tree[0] = ASTUtil.create( factory, 1, "grandparent" ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/ast/ASTUtilTest.java b/hibernate-core/src/test/java/org/hibernate/test/ast/ASTUtilTest.java index ad7be25ad6..52efcf2549 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/ast/ASTUtilTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/ast/ASTUtilTest.java @@ -1,41 +1,57 @@ -// $Id: ASTUtilTest.java 10977 2006-12-12 23:28:04Z steve.ebersole@jboss.com $ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2006-2011, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ package org.hibernate.test.ast; -import junit.framework.Test; -import junit.framework.TestSuite; -import org.hibernate.hql.ast.util.ASTUtil; -import org.hibernate.testing.junit.UnitTestCase; + import antlr.ASTFactory; import antlr.collections.AST; +import org.hibernate.hql.ast.util.ASTUtil; + +import org.junit.Test; + +import org.hibernate.testing.junit4.BaseUnitTestCase; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; + /** * Unit test for ASTUtil. */ -public class ASTUtilTest extends UnitTestCase { - private ASTFactory factory; - - /** - * Standard JUnit test case constructor. - * - * @param name The name of the test case. - */ - public ASTUtilTest(String name) { - super( name ); - } - - protected void setUp() throws Exception { - super.setUp(); - factory = new ASTFactory(); - } +public class ASTUtilTest extends BaseUnitTestCase { + private ASTFactory factory = new ASTFactory(); + @Test public void testCreate() throws Exception { AST n = ASTUtil.create( factory, 1, "one"); assertNull( n.getFirstChild() ); - assertEquals("one",n.getText()); - assertEquals(1,n.getType()); + assertEquals( "one", n.getText() ); + assertEquals( 1, n.getType() ); } - /** - * Test adding a tree of children. - */ + + @Test public void testCreateTree() throws Exception { AST[] tree = new AST[4]; AST grandparent = tree[0] = ASTUtil.create(factory, 1, "grandparent"); @@ -46,9 +62,10 @@ public class ASTUtilTest extends UnitTestCase { assertSame(t,grandparent); assertSame(parent,t.getFirstChild()); assertSame(child,t.getFirstChild().getFirstChild()); - assertSame(baby,t.getFirstChild().getFirstChild().getFirstChild()); + assertSame( baby, t.getFirstChild().getFirstChild().getFirstChild() ); } + @Test public void testFindPreviousSibling() throws Exception { AST child1 = ASTUtil.create(factory,2, "child1"); AST child2 = ASTUtil.create(factory,3, "child2"); @@ -67,9 +84,4 @@ public class ASTUtilTest extends UnitTestCase { } assertNotNull(e); } - - public static Test suite() { - return new TestSuite( ASTUtilTest.class ); - } - } diff --git a/hibernate-core/src/test/java/org/hibernate/test/bytecode/cglib/ReflectionOptimizerTest.java b/hibernate-core/src/test/java/org/hibernate/test/bytecode/cglib/ReflectionOptimizerTest.java index 7bde23efe4..3eae32b076 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/bytecode/cglib/ReflectionOptimizerTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/bytecode/cglib/ReflectionOptimizerTest.java @@ -1,20 +1,45 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ package org.hibernate.test.bytecode.cglib; -import junit.framework.TestSuite; + import org.hibernate.bytecode.ReflectionOptimizer; import org.hibernate.bytecode.cglib.BytecodeProviderImpl; + +import org.junit.Test; + +import org.hibernate.testing.junit4.BaseUnitTestCase; import org.hibernate.test.bytecode.Bean; import org.hibernate.test.bytecode.BeanReflectionHelper; -import org.hibernate.testing.junit.UnitTestCase; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; /** * @author Steve Ebersole */ -public class ReflectionOptimizerTest extends UnitTestCase { - - public ReflectionOptimizerTest(String string) { - super( string ); - } - +public class ReflectionOptimizerTest extends BaseUnitTestCase { + @Test public void testReflectionOptimization() { BytecodeProviderImpl provider = new BytecodeProviderImpl(); ReflectionOptimizer optimizer = provider.getReflectionOptimizer( @@ -43,8 +68,4 @@ public class ReflectionOptimizerTest extends UnitTestCase { assertEquals( "different values at index [" + i + "]", checkValues[i], values[i] ); } } - - public static TestSuite suite() { - return new TestSuite( ReflectionOptimizerTest.class ); - } } diff --git a/hibernate-core/src/test/java/org/hibernate/test/bytecode/javassist/ReflectionOptimizerTest.java b/hibernate-core/src/test/java/org/hibernate/test/bytecode/javassist/ReflectionOptimizerTest.java index 8cf64d6670..852fadf4d3 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/bytecode/javassist/ReflectionOptimizerTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/bytecode/javassist/ReflectionOptimizerTest.java @@ -1,20 +1,45 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ package org.hibernate.test.bytecode.javassist; -import junit.framework.TestSuite; + import org.hibernate.bytecode.ReflectionOptimizer; import org.hibernate.bytecode.javassist.BytecodeProviderImpl; + +import org.junit.Test; + +import org.hibernate.testing.junit4.BaseUnitTestCase; import org.hibernate.test.bytecode.Bean; import org.hibernate.test.bytecode.BeanReflectionHelper; -import org.hibernate.testing.junit.UnitTestCase; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; /** * @author Steve Ebersole */ -public class ReflectionOptimizerTest extends UnitTestCase { - - public ReflectionOptimizerTest(String string) { - super( string ); - } - +public class ReflectionOptimizerTest extends BaseUnitTestCase { + @Test public void testReflectionOptimization() { BytecodeProviderImpl provider = new BytecodeProviderImpl(); ReflectionOptimizer optimizer = provider.getReflectionOptimizer( @@ -43,8 +68,4 @@ public class ReflectionOptimizerTest extends UnitTestCase { assertEquals( "different values at index [" + i + "]", checkValues[i], values[i] ); } } - - public static TestSuite suite() { - return new TestSuite( ReflectionOptimizerTest.class ); - } } diff --git a/hibernate-core/src/test/java/org/hibernate/test/cfg/CacheableFileTest.java b/hibernate-core/src/test/java/org/hibernate/test/cfg/CacheableFileTest.java index 9f5e817f99..4a0439de8b 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/cfg/CacheableFileTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/cfg/CacheableFileTest.java @@ -1,10 +1,10 @@ /* * Hibernate, Relational Persistence for Idiomatic Java * - * Copyright (c) 2009, Red Hat Middleware LLC or third-party contributors as + * Copyright (c) 2009-2011, Red Hat Inc. or third-party contributors as * indicated by the @author tags or express copyright attribution * statements applied by the authors. All third-party contributions are - * distributed under license by Red Hat Middleware LLC. + * distributed under license by Red Hat Inc. * * This copyrighted material is made available to anyone wishing to use, modify, * copy, or redistribute it subject to the terms and conditions of the GNU @@ -21,29 +21,35 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.test.cfg; +package org.hibernate.test.cfg; + import java.io.File; + import org.hibernate.cfg.Configuration; import org.hibernate.internal.util.SerializationHelper; -import org.hibernate.testing.junit.UnitTestCase; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import org.hibernate.testing.junit4.BaseUnitTestCase; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; /** * Tests using of cacheable configuration files. * * @author Steve Ebersole */ -public class CacheableFileTest extends UnitTestCase { +public class CacheableFileTest extends BaseUnitTestCase { public static final String MAPPING = "org/hibernate/test/cfg/Cacheable.hbm.xml"; private File mappingFile; private File mappingBinFile; - public CacheableFileTest(String string) { - super( string ); - } - - protected void setUp() throws Exception { - super.setUp(); + @Before + public void setUp() throws Exception { mappingFile = new File( getClass().getClassLoader().getResource( MAPPING ).toURI() ); assertTrue( mappingFile.exists() ); mappingBinFile = new File( mappingFile.getParentFile(), mappingFile.getName() + ".bin" ); @@ -53,7 +59,8 @@ public class CacheableFileTest extends UnitTestCase { } } - protected void tearDown() throws Exception { + @After + public void tearDown() throws Exception { if ( mappingBinFile != null && mappingBinFile.exists() ) { // be nice //noinspection ResultOfMethodCallIgnored @@ -61,9 +68,9 @@ public class CacheableFileTest extends UnitTestCase { } mappingBinFile = null; mappingFile = null; - super.tearDown(); } + @Test public void testCachedFiles() throws Exception { assertFalse( mappingBinFile.exists() ); // This call should create the cached file diff --git a/hibernate-core/src/test/java/org/hibernate/test/cfg/ConfigurationSerializationTest.java b/hibernate-core/src/test/java/org/hibernate/test/cfg/ConfigurationSerializationTest.java index aa05c8e961..414f58269a 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/cfg/ConfigurationSerializationTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/cfg/ConfigurationSerializationTest.java @@ -1,8 +1,10 @@ /* - * Copyright (c) 2009 by Red Hat Inc and/or its affiliates or by - * third-party contributors as indicated by either @author tags or express - * copyright attribution statements applied by the authors. All - * third-party contributions are distributed under license by Red Hat Inc. + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2009-2011, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. * * This copyrighted material is made available to anyone wishing to use, modify, * copy, or redistribute it subject to the terms and conditions of the GNU @@ -17,20 +19,22 @@ * along with this distribution; if not, write to: * Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor - * Boston, MA 02110-1301 USA\ + * Boston, MA 02110-1301 USA */ package org.hibernate.test.cfg; import javax.persistence.Entity; import javax.persistence.Id; -import junit.framework.Test; -import junit.framework.TestSuite; + import org.hibernate.SessionFactory; import org.hibernate.cfg.Configuration; import org.hibernate.internal.util.SerializationHelper; import org.hibernate.service.spi.ServiceRegistry; + +import org.junit.Test; + import org.hibernate.testing.ServiceRegistryBuilder; -import org.hibernate.testing.junit.UnitTestCase; +import org.hibernate.testing.junit4.BaseUnitTestCase; /** * Copied over mostly from ConfigurationPerformanceTest @@ -38,15 +42,7 @@ import org.hibernate.testing.junit.UnitTestCase; * @author Steve Ebersole * @author Max Andersen */ -public class ConfigurationSerializationTest extends UnitTestCase { - public ConfigurationSerializationTest(String string) { - super( string ); - } - - public static Test suite() { - return new TestSuite( ConfigurationSerializationTest.class ); - } - +public class ConfigurationSerializationTest extends BaseUnitTestCase { private static final String[] FILES = new String[] { "legacy/ABC.hbm.xml", "legacy/ABCExtends.hbm.xml", @@ -92,7 +88,8 @@ public class ConfigurationSerializationTest extends UnitTestCase { "cfg/orm-serializable.xml" }; - public void testConfiguraionSerializability() { + @Test + public void testConfigurationSerializability() { Configuration cfg = new Configuration(); for ( String file : FILES ) { cfg.addResource( "org/hibernate/test/" + file ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/cfg/ListenerTest.java b/hibernate-core/src/test/java/org/hibernate/test/cfg/ListenerTest.java index 3fc4272845..a1563ec160 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/cfg/ListenerTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/cfg/ListenerTest.java @@ -1,10 +1,10 @@ /* * Hibernate, Relational Persistence for Idiomatic Java * - * Copyright (c) 2009, Red Hat Middleware LLC or third-party contributors as + * Copyright (c) 2009-2011, Red Hat Inc. or third-party contributors as * indicated by the @author tags or express copyright attribution * statements applied by the authors. All third-party contributions are - * distributed under license by Red Hat Middleware LLC. + * distributed under license by Red Hat Inc. * * This copyrighted material is made available to anyone wishing to use, modify, * copy, or redistribute it subject to the terms and conditions of the GNU @@ -29,14 +29,20 @@ import org.hibernate.cfg.Configuration; import org.hibernate.event.DeleteEvent; import org.hibernate.event.DeleteEventListener; import org.hibernate.event.def.DefaultDeleteEventListener; -import org.hibernate.testing.junit.UnitTestCase; + +import org.junit.Test; + +import org.hibernate.testing.junit4.BaseUnitTestCase; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; /** - * {@inheritDoc} - * * @author Gail Badner */ -public class ListenerTest extends UnitTestCase { +public class ListenerTest extends BaseUnitTestCase { public static class InvalidListenerForTest { } @@ -57,10 +63,7 @@ public class ListenerTest extends UnitTestCase { } } - public ListenerTest(String string) { - super( string ); - } - + @Test public void testSetListenerNullClass() { Configuration cfg = new Configuration(); assertNotNull( cfg.getEventListeners().getDeleteEventListeners() ); @@ -68,6 +71,7 @@ public class ListenerTest extends UnitTestCase { assertEquals( 0, cfg.getEventListeners().getDeleteEventListeners().length ); } + @Test public void testSetListenersNullClass() { Configuration cfg = new Configuration(); assertNotNull( cfg.getEventListeners().getDeleteEventListeners() ); @@ -75,6 +79,7 @@ public class ListenerTest extends UnitTestCase { assertEquals( 0, cfg.getEventListeners().getDeleteEventListeners().length ); } + @Test public void testSetListenerEmptyClassNameArray() { Configuration cfg = new Configuration(); assertNotNull( cfg.getEventListeners().getDeleteEventListeners() ); @@ -87,6 +92,7 @@ public class ListenerTest extends UnitTestCase { } } + @Test public void testSetListenersEmptyClassNsmeArray() { Configuration cfg = new Configuration(); assertNotNull( cfg.getEventListeners().getDeleteEventListeners() ); @@ -94,6 +100,7 @@ public class ListenerTest extends UnitTestCase { assertEquals( 0, cfg.getEventListeners().getDeleteEventListeners().length ); } + @Test public void testSetListenerEmptyClassObjectArray() { Configuration cfg = new Configuration(); assertNotNull( cfg.getEventListeners().getDeleteEventListeners() ); @@ -106,6 +113,7 @@ public class ListenerTest extends UnitTestCase { } } + @Test public void testSetListenersEmptyClassObjectArray() { Configuration cfg = new Configuration(); assertNotNull( cfg.getEventListeners().getDeleteEventListeners() ); @@ -118,6 +126,7 @@ public class ListenerTest extends UnitTestCase { } } + @Test public void testSetListenerEmptyClassArray() { Configuration cfg = new Configuration(); assertNotNull( cfg.getEventListeners().getDeleteEventListeners() ); @@ -130,6 +139,7 @@ public class ListenerTest extends UnitTestCase { } } + @Test public void testSetListenersEmptyClassArray() { Configuration cfg = new Configuration(); assertNotNull( cfg.getEventListeners().getDeleteEventListeners() ); @@ -137,6 +147,7 @@ public class ListenerTest extends UnitTestCase { assertEquals( 0, cfg.getEventListeners().getDeleteEventListeners().length ); } + @Test public void testSetListenerUnknownClassName() { Configuration cfg = new Configuration(); assertNotNull( cfg.getEventListeners().getDeleteEventListeners() ); @@ -149,6 +160,7 @@ public class ListenerTest extends UnitTestCase { } } + @Test public void testSetListenersUnknownClassName() { Configuration cfg = new Configuration(); assertNotNull( cfg.getEventListeners().getDeleteEventListeners() ); @@ -161,6 +173,7 @@ public class ListenerTest extends UnitTestCase { } } + @Test public void testSetListenerInvalidClassName() { Configuration cfg = new Configuration(); assertNotNull( cfg.getEventListeners().getDeleteEventListeners() ); @@ -173,6 +186,7 @@ public class ListenerTest extends UnitTestCase { } } + @Test public void testSetListenersInvalidClassName() { Configuration cfg = new Configuration(); assertNotNull( cfg.getEventListeners().getDeleteEventListeners() ); @@ -185,6 +199,7 @@ public class ListenerTest extends UnitTestCase { } } + @Test public void testSetListenerClassName() { Configuration cfg = new Configuration(); assertNotNull( cfg.getEventListeners().getDeleteEventListeners() ); @@ -193,6 +208,7 @@ public class ListenerTest extends UnitTestCase { assertTrue( cfg.getEventListeners().getDeleteEventListeners()[0] instanceof DeleteListenerForTest ); } + @Test public void testSetListenersClassName() { Configuration cfg = new Configuration(); assertNotNull( cfg.getEventListeners().getDeleteEventListeners() ); @@ -201,6 +217,7 @@ public class ListenerTest extends UnitTestCase { assertTrue( cfg.getEventListeners().getDeleteEventListeners()[0] instanceof DeleteListenerForTest ); } + @Test public void testSetListenerClassNames() { Configuration cfg = new Configuration(); assertNotNull( cfg.getEventListeners().getDeleteEventListeners() ); @@ -218,6 +235,7 @@ public class ListenerTest extends UnitTestCase { } } + @Test public void testSetListenersClassNames() { Configuration cfg = new Configuration(); assertNotNull( cfg.getEventListeners().getDeleteEventListeners() ); @@ -232,6 +250,7 @@ public class ListenerTest extends UnitTestCase { assertTrue( cfg.getEventListeners().getDeleteEventListeners()[1] instanceof AnotherDeleteListenerForTest ); } + @Test public void testSetListenerClassInstance() { Configuration cfg = new Configuration(); assertNotNull( cfg.getEventListeners().getDeleteEventListeners() ); @@ -239,6 +258,7 @@ public class ListenerTest extends UnitTestCase { assertEquals( 1, cfg.getEventListeners().getDeleteEventListeners().length ); } + @Test public void testSetListenersClassInstances() { Configuration cfg = new Configuration(); assertNotNull( cfg.getEventListeners().getDeleteEventListeners() ); @@ -253,6 +273,7 @@ public class ListenerTest extends UnitTestCase { assertTrue( cfg.getEventListeners().getDeleteEventListeners()[1] instanceof AnotherDeleteListenerForTest ); } + @Test public void testSetListenerInvalidClassInstance() { Configuration cfg = new Configuration(); assertNotNull( cfg.getEventListeners().getDeleteEventListeners() ); @@ -265,6 +286,7 @@ public class ListenerTest extends UnitTestCase { } } + @Test public void testSetListenersInvalidClassInstances() { Configuration cfg = new Configuration(); assertNotNull( cfg.getEventListeners().getDeleteEventListeners() ); @@ -277,6 +299,7 @@ public class ListenerTest extends UnitTestCase { } } + @Test public void testSetListenerNullType() { Configuration cfg = new Configuration(); assertNotNull( cfg.getEventListeners().getDeleteEventListeners() ); @@ -289,6 +312,7 @@ public class ListenerTest extends UnitTestCase { } } + @Test public void testSetListenersNullType() { Configuration cfg = new Configuration(); assertNotNull( cfg.getEventListeners().getDeleteEventListeners() ); @@ -301,6 +325,7 @@ public class ListenerTest extends UnitTestCase { } } + @Test public void testSetListenerUnknownType() { Configuration cfg = new Configuration(); assertNotNull( cfg.getEventListeners().getDeleteEventListeners() ); @@ -313,6 +338,7 @@ public class ListenerTest extends UnitTestCase { } } + @Test public void testSetListenersUnknownType() { Configuration cfg = new Configuration(); assertNotNull( cfg.getEventListeners().getDeleteEventListeners() ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/cfg/persister/PersisterClassProviderTest.java b/hibernate-core/src/test/java/org/hibernate/test/cfg/persister/PersisterClassProviderTest.java index 46211c597c..a8154b1b47 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/cfg/persister/PersisterClassProviderTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/cfg/persister/PersisterClassProviderTest.java @@ -25,17 +25,19 @@ import org.hibernate.SessionFactory; import org.hibernate.cfg.Configuration; import org.hibernate.persister.spi.PersisterClassResolver; import org.hibernate.service.spi.ServiceRegistry; + +import org.junit.Test; + import org.hibernate.testing.ServiceRegistryBuilder; -import org.hibernate.testing.junit.UnitTestCase; +import org.hibernate.testing.junit4.BaseUnitTestCase; + +import static org.junit.Assert.assertEquals; /** * @author Emmanuel Bernard */ -public class PersisterClassProviderTest extends UnitTestCase { - public PersisterClassProviderTest(String string) { - super( string ); - } - +public class PersisterClassProviderTest extends BaseUnitTestCase { + @Test public void testPersisterClassProvider() throws Exception { Configuration cfg = new Configuration(); diff --git a/hibernate-core/src/test/java/org/hibernate/test/dialect/unit/lockhint/AbstractLockHintTest.java b/hibernate-core/src/test/java/org/hibernate/test/dialect/unit/lockhint/AbstractLockHintTest.java index 1b2057a06e..0405931b60 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/dialect/unit/lockhint/AbstractLockHintTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/dialect/unit/lockhint/AbstractLockHintTest.java @@ -1,39 +1,63 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2008-2011, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ package org.hibernate.test.dialect.unit.lockhint; import java.util.Collections; + import org.hibernate.LockMode; import org.hibernate.LockOptions; import org.hibernate.dialect.Dialect; import org.hibernate.internal.util.StringHelper; -import org.hibernate.testing.junit.UnitTestCase; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import org.hibernate.testing.junit4.BaseUnitTestCase; + +import static org.junit.Assert.assertEquals; /** - * {@inheritDoc} - * * @author Steve Ebersole */ -public abstract class AbstractLockHintTest extends UnitTestCase { - public AbstractLockHintTest(String string) { - super( string ); - } - +public abstract class AbstractLockHintTest extends BaseUnitTestCase { private Dialect dialect; protected abstract String getLockHintUsed(); protected abstract Dialect getDialectUnderTest(); - @Override - protected void setUp() throws Exception { - super.setUp(); + @Before + public void setUp() throws Exception { this.dialect = getDialectUnderTest(); } - @Override - protected void tearDown() throws Exception { + @After + public void tearDown() throws Exception { this.dialect = null; - super.tearDown(); } + @Test public void testBasicLocking() { new SyntaxChecker( "select xyz from ABC $HOLDER$", "a" ).verify(); new SyntaxChecker( "select xyz from ABC $HOLDER$ join DEF d", "a" ).verify(); diff --git a/hibernate-core/src/test/java/org/hibernate/test/dialect/unit/lockhint/SQLServerLockHintsTest.java b/hibernate-core/src/test/java/org/hibernate/test/dialect/unit/lockhint/SQLServerLockHintsTest.java index efd276a313..60db14619d 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/dialect/unit/lockhint/SQLServerLockHintsTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/dialect/unit/lockhint/SQLServerLockHintsTest.java @@ -1,20 +1,37 @@ -package org.hibernate.test.dialect.unit.lockhint; -import junit.framework.TestSuite; -import org.hibernate.dialect.Dialect; -import org.hibernate.dialect.SQLServerDialect; +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2008-2011, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package org.hibernate.test.dialect.unit.lockhint; + +import org.hibernate.dialect.Dialect; +import org.hibernate.dialect.SQLServerDialect; /** - * {@inheritDoc} - * * @author Steve Ebersole */ public class SQLServerLockHintsTest extends AbstractLockHintTest { public static final Dialect DIALECT = new SQLServerDialect(); - public SQLServerLockHintsTest(String string) { - super( string ); - } - protected String getLockHintUsed() { return "with (updlock, rowlock)"; } @@ -22,8 +39,4 @@ public class SQLServerLockHintsTest extends AbstractLockHintTest { protected Dialect getDialectUnderTest() { return DIALECT; } - - public static TestSuite suite() { - return new TestSuite( SQLServerLockHintsTest.class ); - } } diff --git a/hibernate-core/src/test/java/org/hibernate/test/dialect/unit/lockhint/SybaseASE15LockHintsTest.java b/hibernate-core/src/test/java/org/hibernate/test/dialect/unit/lockhint/SybaseASE15LockHintsTest.java index 2a389ad41d..f588693b92 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/dialect/unit/lockhint/SybaseASE15LockHintsTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/dialect/unit/lockhint/SybaseASE15LockHintsTest.java @@ -1,11 +1,10 @@ -//$Id $ /* * Hibernate, Relational Persistence for Idiomatic Java * - * Copyright (c) 2009, Red Hat Middleware LLC or third-party contributors as + * Copyright (c) 2009-2011, Red Hat Inc. or third-party contributors as * indicated by the @author tags or express copyright attribution * statements applied by the authors. All third-party contributions are - * distributed under license by Red Hat Middleware LLC. + * distributed under license by Red Hat Inc. * * This copyrighted material is made available to anyone wishing to use, modify, * copy, or redistribute it subject to the terms and conditions of the GNU @@ -21,25 +20,18 @@ * Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA - * */ -package org.hibernate.test.dialect.unit.lockhint; -import junit.framework.TestSuite; +package org.hibernate.test.dialect.unit.lockhint; + import org.hibernate.dialect.Dialect; import org.hibernate.dialect.SybaseASE15Dialect; /** - * {@inheritDoc} - * * @author Gail Badner */ public class SybaseASE15LockHintsTest extends AbstractLockHintTest { public static final Dialect DIALECT = new SybaseASE15Dialect(); - public SybaseASE15LockHintsTest(String string) { - super( string ); - } - protected String getLockHintUsed() { return "holdlock"; } @@ -47,8 +39,4 @@ public class SybaseASE15LockHintsTest extends AbstractLockHintTest { protected Dialect getDialectUnderTest() { return DIALECT; } - - public static TestSuite suite() { - return new TestSuite( SybaseASE15LockHintsTest.class ); - } } diff --git a/hibernate-core/src/test/java/org/hibernate/test/dialect/unit/lockhint/SybaseLockHintsTest.java b/hibernate-core/src/test/java/org/hibernate/test/dialect/unit/lockhint/SybaseLockHintsTest.java index 8feee95dd7..7de11eaa5e 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/dialect/unit/lockhint/SybaseLockHintsTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/dialect/unit/lockhint/SybaseLockHintsTest.java @@ -1,20 +1,37 @@ -package org.hibernate.test.dialect.unit.lockhint; -import junit.framework.TestSuite; -import org.hibernate.dialect.Dialect; -import org.hibernate.dialect.SybaseDialect; +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2008-2011, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package org.hibernate.test.dialect.unit.lockhint; + +import org.hibernate.dialect.Dialect; +import org.hibernate.dialect.SybaseDialect; /** - * {@inheritDoc} - * * @author Steve Ebersole */ public class SybaseLockHintsTest extends AbstractLockHintTest { public static final Dialect DIALECT = new SybaseDialect(); - public SybaseLockHintsTest(String string) { - super( string ); - } - protected String getLockHintUsed() { return "holdlock"; } @@ -22,8 +39,4 @@ public class SybaseLockHintsTest extends AbstractLockHintTest { protected Dialect getDialectUnderTest() { return DIALECT; } - - public static TestSuite suite() { - return new TestSuite( SybaseLockHintsTest.class ); - } } diff --git a/hibernate-core/src/test/java/org/hibernate/test/extendshbm/ExtendsTest.java b/hibernate-core/src/test/java/org/hibernate/test/extendshbm/ExtendsTest.java index 2069a7e776..e58a755ba0 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/extendshbm/ExtendsTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/extendshbm/ExtendsTest.java @@ -1,28 +1,42 @@ //$Id: ExtendsTest.java 10977 2006-12-12 23:28:04Z steve.ebersole@jboss.com $ package org.hibernate.test.extendshbm; -import junit.framework.Test; -import junit.framework.TestSuite; + import org.hibernate.HibernateException; import org.hibernate.cfg.Configuration; -import org.hibernate.testing.junit.UnitTestCase; +import org.hibernate.service.internal.ServiceRegistryImpl; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import org.hibernate.testing.ServiceRegistryBuilder; +import org.hibernate.testing.junit4.BaseUnitTestCase; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.fail; /** * @author Gavin King */ -public class ExtendsTest extends UnitTestCase { +public class ExtendsTest extends BaseUnitTestCase { + private ServiceRegistryImpl serviceRegistry; - public ExtendsTest(String str) { - super( str ); + @Before + public void setUp() { + serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry(); } - public static Test suite() { - return new TestSuite( ExtendsTest.class ); + @After + public void tearDown() { + ServiceRegistryBuilder.destroy( serviceRegistry ); } private String getBaseForMappings() { return "org/hibernate/test/"; } + @Test public void testAllInOne() { Configuration cfg = new Configuration(); @@ -33,6 +47,7 @@ public class ExtendsTest extends UnitTestCase { assertNotNull( cfg.getClassMapping( "org.hibernate.test.extendshbm.Employee" ) ); } + @Test public void testOutOfOrder() { Configuration cfg = new Configuration(); @@ -45,7 +60,7 @@ public class ExtendsTest extends UnitTestCase { cfg.addResource( getBaseForMappings() + "extendshbm/Person.hbm.xml" ); cfg.addResource( getBaseForMappings() + "extendshbm/Employee.hbm.xml" ); - cfg.buildSessionFactory( getServiceRegistry(cfg.getProperties()) ); + cfg.buildSessionFactory( serviceRegistry ); assertNotNull( cfg.getClassMapping( "org.hibernate.test.extendshbm.Customer" ) ); assertNotNull( cfg.getClassMapping( "org.hibernate.test.extendshbm.Person" ) ); @@ -58,6 +73,7 @@ public class ExtendsTest extends UnitTestCase { } + @Test public void testNwaitingForSuper() { Configuration cfg = new Configuration(); @@ -90,6 +106,7 @@ public class ExtendsTest extends UnitTestCase { } + @Test public void testMissingSuper() { Configuration cfg = new Configuration(); @@ -101,7 +118,7 @@ public class ExtendsTest extends UnitTestCase { ); cfg.addResource( getBaseForMappings() + "extendshbm/Employee.hbm.xml" ); - cfg.buildSessionFactory( getServiceRegistry( cfg.getProperties() ) ); + cfg.buildSessionFactory( serviceRegistry ); fail( "Should not be able to build sessionfactory without a Person" ); } @@ -111,13 +128,14 @@ public class ExtendsTest extends UnitTestCase { } + @Test public void testAllSeparateInOne() { Configuration cfg = new Configuration(); try { cfg.addResource( getBaseForMappings() + "extendshbm/allseparateinone.hbm.xml" ); - cfg.buildSessionFactory( getServiceRegistry( cfg.getProperties() ) ); + cfg.buildSessionFactory( serviceRegistry ); assertNotNull( cfg.getClassMapping( "org.hibernate.test.extendshbm.Customer" ) ); assertNotNull( cfg.getClassMapping( "org.hibernate.test.extendshbm.Person" ) ); @@ -130,6 +148,7 @@ public class ExtendsTest extends UnitTestCase { } + @Test public void testJoinedSubclassAndEntityNamesOnly() { Configuration cfg = new Configuration(); @@ -149,6 +168,7 @@ public class ExtendsTest extends UnitTestCase { } } + @Test public void testEntityNamesWithPackage() { Configuration cfg = new Configuration(); try { @@ -167,7 +187,7 @@ public class ExtendsTest extends UnitTestCase { } } - + @Test public void testUnionSubclass() { Configuration cfg = new Configuration(); diff --git a/hibernate-core/src/test/java/org/hibernate/test/instrument/buildtime/InstrumentTest.java b/hibernate-core/src/test/java/org/hibernate/test/instrument/buildtime/InstrumentTest.java index 1f8f145cbb..6a04dd2e2a 100755 --- a/hibernate-core/src/test/java/org/hibernate/test/instrument/buildtime/InstrumentTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/instrument/buildtime/InstrumentTest.java @@ -1,8 +1,34 @@ -//$Id: InstrumentTest.java 10976 2006-12-12 23:22:26Z steve.ebersole@jboss.com $ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2006-2011, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ package org.hibernate.test.instrument.buildtime; -import junit.framework.Test; -import junit.framework.TestSuite; + import org.hibernate.intercept.FieldInterceptionHelper; + +import org.junit.Test; + +import org.hibernate.testing.Skip; +import org.hibernate.testing.junit4.BaseUnitTestCase; import org.hibernate.test.instrument.cases.Executable; import org.hibernate.test.instrument.cases.TestCustomColumnReadAndWrite; import org.hibernate.test.instrument.cases.TestDirtyCheckExecutable; @@ -15,57 +41,61 @@ import org.hibernate.test.instrument.cases.TestLazyPropertyCustomTypeExecutable; import org.hibernate.test.instrument.cases.TestManyToOneProxyExecutable; import org.hibernate.test.instrument.cases.TestSharedPKOneToOneExecutable; import org.hibernate.test.instrument.domain.Document; -import org.hibernate.testing.junit.UnitTestCase; /** * @author Gavin King */ -public class InstrumentTest extends UnitTestCase { - - public InstrumentTest(String str) { - super(str); - } - - public static Test suite() { - return new TestSuite( InstrumentTest.class ); - } - +@Skip( + message = "domain classes not instrumented for build-time instrumentation testing", + condition = InstrumentTest.SkipCheck.class +) +public class InstrumentTest extends BaseUnitTestCase { + @Test public void testDirtyCheck() throws Exception { execute( new TestDirtyCheckExecutable() ); } + @Test public void testFetchAll() throws Exception { execute( new TestFetchAllExecutable() ); } + @Test public void testLazy() throws Exception { execute( new TestLazyExecutable() ); } + @Test public void testLazyManyToOne() throws Exception { execute( new TestLazyManyToOneExecutable() ); } + @Test public void testSetFieldInterceptor() throws Exception { execute( new TestInjectFieldInterceptorExecutable() ); } + @Test public void testPropertyInitialized() throws Exception { execute( new TestIsPropertyInitializedExecutable() ); } + @Test public void testManyToOneProxy() throws Exception { execute( new TestManyToOneProxyExecutable() ); } + @Test public void testLazyPropertyCustomTypeExecutable() throws Exception { execute( new TestLazyPropertyCustomTypeExecutable() ); } + @Test public void testSharedPKOneToOne() throws Exception { execute( new TestSharedPKOneToOneExecutable() ); } + @Test public void testCustomColumnReadAndWrite() throws Exception { execute( new TestCustomColumnReadAndWrite() ); } @@ -80,17 +110,11 @@ public class InstrumentTest extends UnitTestCase { } } - protected void runTest() throws Throwable { - if ( isRunnable() ) { - super.runTest(); + public static class SkipCheck implements Skip.Matcher { + @Override + public boolean isMatch() { + return ! FieldInterceptionHelper.isInstrumented( new Document() ); } - else { - reportSkip( "domain classes not instrumented", "build-time instrumentation" ); - } - } - - public static boolean isRunnable() { - return FieldInterceptionHelper.isInstrumented( new Document() ); } } diff --git a/hibernate-core/src/test/java/org/hibernate/test/instrument/runtime/AbstractTransformingClassLoaderInstrumentTestCase.java b/hibernate-core/src/test/java/org/hibernate/test/instrument/runtime/AbstractTransformingClassLoaderInstrumentTestCase.java index 069d74f9ba..deb3704ca2 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/instrument/runtime/AbstractTransformingClassLoaderInstrumentTestCase.java +++ b/hibernate-core/src/test/java/org/hibernate/test/instrument/runtime/AbstractTransformingClassLoaderInstrumentTestCase.java @@ -1,21 +1,43 @@ -package org.hibernate.test.instrument.runtime; -import java.lang.reflect.InvocationTargetException; -import org.hibernate.HibernateException; -import org.hibernate.bytecode.BytecodeProvider; -import org.hibernate.bytecode.InstrumentedClassLoader; -import org.hibernate.bytecode.util.BasicClassFilter; -import org.hibernate.bytecode.util.FieldFilter; -import org.hibernate.testing.junit.AbstractClassLoaderIsolatedTestCase; +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2008-2011, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package org.hibernate.test.instrument.runtime; +import java.lang.reflect.InvocationTargetException; + +import org.junit.Test; + +import org.hibernate.HibernateException; +import org.hibernate.bytecode.BytecodeProvider; +import org.hibernate.bytecode.InstrumentedClassLoader; +import org.hibernate.bytecode.util.BasicClassFilter; +import org.hibernate.bytecode.util.FieldFilter; +import org.hibernate.testing.junit.AbstractClassLoaderIsolatedTestCase; /** * @author Steve Ebersole */ public abstract class AbstractTransformingClassLoaderInstrumentTestCase extends AbstractClassLoaderIsolatedTestCase { - public AbstractTransformingClassLoaderInstrumentTestCase(String string) { - super( string ); - } - protected ClassLoader buildIsolatedClassLoader(ClassLoader parent) { BytecodeProvider provider = buildBytecodeProvider(); return new InstrumentedClassLoader( @@ -44,42 +66,52 @@ public abstract class AbstractTransformingClassLoaderInstrumentTestCase extends // the tests ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + @Test public void testSetFieldInterceptor() { executeExecutable( "org.hibernate.test.instrument.cases.TestInjectFieldInterceptorExecutable" ); } + @Test public void testDirtyCheck() { executeExecutable( "org.hibernate.test.instrument.cases.TestDirtyCheckExecutable" ); } + @Test public void testFetchAll() throws Exception { executeExecutable( "org.hibernate.test.instrument.cases.TestFetchAllExecutable" ); } + @Test public void testLazy() { executeExecutable( "org.hibernate.test.instrument.cases.TestLazyExecutable" ); } + @Test public void testLazyManyToOne() { executeExecutable( "org.hibernate.test.instrument.cases.TestLazyManyToOneExecutable" ); } + @Test public void testPropertyInitialized() { executeExecutable( "org.hibernate.test.instrument.cases.TestIsPropertyInitializedExecutable" ); } + @Test public void testManyToOneProxy() { executeExecutable( "org.hibernate.test.instrument.cases.TestManyToOneProxyExecutable" ); } + @Test public void testLazyPropertyCustomType() { executeExecutable( "org.hibernate.test.instrument.cases.TestLazyPropertyCustomTypeExecutable" ); } + @Test public void testSharedPKOneToOne() { executeExecutable( "org.hibernate.test.instrument.cases.TestSharedPKOneToOneExecutable" ); } + @Test public void testCustomColumnReadAndWrite() { executeExecutable( "org.hibernate.test.instrument.cases.TestCustomColumnReadAndWrite" ); } diff --git a/hibernate-core/src/test/java/org/hibernate/test/instrument/runtime/CGLIBInstrumentationTest.java b/hibernate-core/src/test/java/org/hibernate/test/instrument/runtime/CGLIBInstrumentationTest.java index 90bf1ef946..4938684e44 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/instrument/runtime/CGLIBInstrumentationTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/instrument/runtime/CGLIBInstrumentationTest.java @@ -1,59 +1,36 @@ -package org.hibernate.test.instrument.runtime; -import junit.framework.Test; -import junit.framework.TestSuite; -import org.hibernate.bytecode.BytecodeProvider; -import org.hibernate.bytecode.cglib.BytecodeProviderImpl; +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package org.hibernate.test.instrument.runtime; + +import org.hibernate.bytecode.BytecodeProvider; +import org.hibernate.bytecode.cglib.BytecodeProviderImpl; /** * @author Steve Ebersole */ public class CGLIBInstrumentationTest extends AbstractTransformingClassLoaderInstrumentTestCase { - public CGLIBInstrumentationTest(String string) { - super( string ); - } - protected BytecodeProvider buildBytecodeProvider() { return new BytecodeProviderImpl(); } - - public static Test suite() { - return new TestSuite( CGLIBInstrumentationTest.class ); - } - - public void testSetFieldInterceptor() { - super.testSetFieldInterceptor(); //To change body of overridden methods use File | Settings | File Templates. - } - - public void testDirtyCheck() { - super.testDirtyCheck(); //To change body of overridden methods use File | Settings | File Templates. - } - - public void testFetchAll() throws Exception { - super.testFetchAll(); //To change body of overridden methods use File | Settings | File Templates. - } - - public void testLazy() { - super.testLazy(); //To change body of overridden methods use File | Settings | File Templates. - } - - public void testLazyManyToOne() { - super.testLazyManyToOne(); //To change body of overridden methods use File | Settings | File Templates. - } - - public void testPropertyInitialized() { - super.testPropertyInitialized(); //To change body of overridden methods use File | Settings | File Templates. - } - - public void testManyToOneProxy() { - super.testManyToOneProxy(); //To change body of overridden methods use File | Settings | File Templates. - } - - public void testSharedPKOneToOne() { - super.testSharedPKOneToOne(); - } - - public void testCustomColumnReadAndWrite() { - super.testCustomColumnReadAndWrite(); - } - } diff --git a/hibernate-core/src/test/java/org/hibernate/test/instrument/runtime/JavassistInstrumentationTest.java b/hibernate-core/src/test/java/org/hibernate/test/instrument/runtime/JavassistInstrumentationTest.java index 05c54bac74..c0c0f4394e 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/instrument/runtime/JavassistInstrumentationTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/instrument/runtime/JavassistInstrumentationTest.java @@ -1,7 +1,28 @@ -//$Id: $ -package org.hibernate.test.instrument.runtime; -import junit.framework.Test; -import junit.framework.TestSuite; +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package org.hibernate.test.instrument.runtime; + import org.hibernate.bytecode.BytecodeProvider; import org.hibernate.bytecode.javassist.BytecodeProviderImpl; @@ -9,52 +30,7 @@ import org.hibernate.bytecode.javassist.BytecodeProviderImpl; * @author Steve Ebersole */ public class JavassistInstrumentationTest extends AbstractTransformingClassLoaderInstrumentTestCase { - public JavassistInstrumentationTest(String string) { - super( string ); - } - protected BytecodeProvider buildBytecodeProvider() { return new BytecodeProviderImpl(); } - - public static Test suite() { - return new TestSuite( JavassistInstrumentationTest.class ); - } - - public void testSetFieldInterceptor() { - super.testSetFieldInterceptor(); - } - - public void testDirtyCheck() { - super.testDirtyCheck(); - } - - public void testFetchAll() throws Exception { - super.testFetchAll(); - } - - public void testLazy() { - super.testLazy(); - } - - public void testLazyManyToOne() { - super.testLazyManyToOne(); - } - - public void testPropertyInitialized() { - super.testPropertyInitialized(); - } - - public void testManyToOneProxy() { - super.testManyToOneProxy(); - } - - public void testSharedPKOneToOne() { - super.testSharedPKOneToOne(); - } - - public void testCustomColumnReadAndWrite() { - super.testCustomColumnReadAndWrite(); - } - } diff --git a/hibernate-core/src/test/java/org/hibernate/test/jdbc/TypeInfoTest.java b/hibernate-core/src/test/java/org/hibernate/test/jdbc/TypeInfoTest.java deleted file mode 100644 index 35c32911d8..0000000000 --- a/hibernate-core/src/test/java/org/hibernate/test/jdbc/TypeInfoTest.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * Copyright (c) 2010, Red Hat Inc. or third-party contributors as - * indicated by the @author tags or express copyright attribution - * statements applied by the authors. All third-party contributions are - * distributed under license by Red Hat Inc. - * - * This copyrighted material is made available to anyone wishing to use, modify, - * copy, or redistribute it subject to the terms and conditions of the GNU - * Lesser General Public License, as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this distribution; if not, write to: - * Free Software Foundation, Inc. - * 51 Franklin Street, Fifth Floor - * Boston, MA 02110-1301 USA - */ -package org.hibernate.test.jdbc; - -import java.sql.Connection; -import java.sql.SQLException; -import java.util.LinkedHashSet; -import org.hibernate.engine.jdbc.internal.TypeInfo; -import org.hibernate.engine.jdbc.internal.TypeInfoExtracter; -import org.hibernate.internal.util.collections.ArrayHelper; -import org.hibernate.service.jdbc.connections.spi.ConnectionProvider; -import org.hibernate.test.common.ConnectionProviderBuilder; -import org.hibernate.testing.junit.UnitTestCase; - -/** - * TODO : javadoc - * - * @author Steve Ebersole - */ -public class TypeInfoTest extends UnitTestCase { - - public TypeInfoTest(String string) { - super( string ); - } - - public void testExtractTypeInfo() throws SQLException { - ConnectionProvider connectionProvider = ConnectionProviderBuilder.buildConnectionProvider(); - Connection connection = connectionProvider.getConnection(); - LinkedHashSet typeInfoSet = TypeInfoExtracter.extractTypeInfo( connection.getMetaData() ); - for ( TypeInfo typeInfo : typeInfoSet ) { - System.out.println( "~~~~~~ TYPE ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" ); - System.out.println( " type name : " + typeInfo.getTypeName() ); - System.out.println( " data type : " + typeInfo.getJdbcTypeCode() ); - System.out.println( " create params : " + ArrayHelper.toString( typeInfo.getCreateParams() ) ); - System.out.println( " unsigned : " + typeInfo.isUnsigned() ); - System.out.println( " precision : " + typeInfo.getPrecision() ); - System.out.println( " minimum scale : " + typeInfo.getMinimumScale() ); - System.out.println( " maximum scale : " + typeInfo.getMaximumScale() ); - System.out.println( " fixed-precision scale : " + typeInfo.isFixedPrecisionScale() ); - System.out.println( " literal prefix : " + typeInfo.getLiteralPrefix() ); - System.out.println( " literal suffix : " + typeInfo.getLiteralSuffix() ); - System.out.println( " case sensitive : " + typeInfo.isCaseSensitive() ); - System.out.println( " searchable : " + typeInfo.getSearchability().toString() ); - System.out.println( " nulability : " + typeInfo.getNullability().toString() ); - System.out.println( "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" ); - } - } -} diff --git a/hibernate-core/src/test/java/org/hibernate/test/jdbc/proxies/AggressiveReleaseTest.java b/hibernate-core/src/test/java/org/hibernate/test/jdbc/proxies/AggressiveReleaseTest.java index ea1519e393..91b0b2bad9 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/jdbc/proxies/AggressiveReleaseTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/jdbc/proxies/AggressiveReleaseTest.java @@ -23,33 +23,36 @@ */ package org.hibernate.test.jdbc.proxies; -import static org.hibernate.TestLogger.LOG; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.SQLException; import java.sql.Statement; + import org.hibernate.ConnectionReleaseMode; import org.hibernate.engine.jdbc.internal.LogicalConnectionImpl; import org.hibernate.engine.jdbc.internal.proxy.ProxyBuilder; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import org.hibernate.testing.junit4.BaseUnitTestCase; import org.hibernate.test.common.BasicTestingJdbcServiceImpl; import org.hibernate.test.common.JournalingConnectionObserver; -import org.hibernate.testing.junit.UnitTestCase; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; /** - * TODO : javadoc - * * @author Steve Ebersole */ -public class AggressiveReleaseTest extends UnitTestCase { - +public class AggressiveReleaseTest extends BaseUnitTestCase { private BasicTestingJdbcServiceImpl services = new BasicTestingJdbcServiceImpl(); - public AggressiveReleaseTest(String string) { - super( string ); - } - - @Override - public void setUp() throws SQLException { + @Before + public void setUp() throws SQLException { services.prepare( true ); Connection connection = null; @@ -66,7 +69,6 @@ public class AggressiveReleaseTest extends UnitTestCase { stmnt.close(); } catch ( SQLException ignore ) { - LOG.warn("could not close statement used to set up schema", ignore); } } if ( connection != null ) { @@ -74,14 +76,13 @@ public class AggressiveReleaseTest extends UnitTestCase { connection.close(); } catch ( SQLException ignore ) { - LOG.warn("could not close connection used to set up schema", ignore); } } } } - @Override - public void tearDown() throws SQLException { + @After + public void tearDown() throws SQLException { Connection connection = null; Statement stmnt = null; try { @@ -95,7 +96,6 @@ public class AggressiveReleaseTest extends UnitTestCase { stmnt.close(); } catch ( SQLException ignore ) { - LOG.warn("could not close statement used to set up schema", ignore); } } if ( connection != null ) { @@ -103,7 +103,6 @@ public class AggressiveReleaseTest extends UnitTestCase { connection.close(); } catch ( SQLException ignore ) { - LOG.warn("could not close connection used to set up schema", ignore); } } } @@ -111,6 +110,7 @@ public class AggressiveReleaseTest extends UnitTestCase { services.release(); } + @Test public void testBasicRelease() { LogicalConnectionImpl logicalConnection = new LogicalConnectionImpl( null, ConnectionReleaseMode.AFTER_STATEMENT, services ); Connection proxiedConnection = ProxyBuilder.buildConnection( logicalConnection ); @@ -140,6 +140,7 @@ public class AggressiveReleaseTest extends UnitTestCase { assertFalse( logicalConnection.getResourceRegistry().hasRegisteredResources() ); } + @Test public void testReleaseCircumventedByHeldResources() { LogicalConnectionImpl logicalConnection = new LogicalConnectionImpl( null, ConnectionReleaseMode.AFTER_STATEMENT, services ); Connection proxiedConnection = ProxyBuilder.buildConnection( logicalConnection ); @@ -193,6 +194,7 @@ public class AggressiveReleaseTest extends UnitTestCase { assertEquals( 2, observer.getPhysicalConnectionReleasedCount() ); } + @Test public void testReleaseCircumventedManually() { LogicalConnectionImpl logicalConnection = new LogicalConnectionImpl( null, ConnectionReleaseMode.AFTER_STATEMENT, services ); Connection proxiedConnection = ProxyBuilder.buildConnection( logicalConnection ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/jdbc/proxies/BasicConnectionProxyTest.java b/hibernate-core/src/test/java/org/hibernate/test/jdbc/proxies/BasicConnectionProxyTest.java index d7762bc20a..b41e42c62b 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/jdbc/proxies/BasicConnectionProxyTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/jdbc/proxies/BasicConnectionProxyTest.java @@ -28,33 +28,38 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + import org.hibernate.ConnectionReleaseMode; import org.hibernate.JDBCException; import org.hibernate.engine.jdbc.internal.LogicalConnectionImpl; import org.hibernate.engine.jdbc.internal.proxy.ProxyBuilder; import org.hibernate.test.common.BasicTestingJdbcServiceImpl; -import org.hibernate.testing.junit.UnitTestCase; +import org.hibernate.testing.junit4.BaseUnitTestCase; /** - * TODO : javadoc - * * @author Steve Ebersole */ -public class BasicConnectionProxyTest extends UnitTestCase { +public class BasicConnectionProxyTest extends BaseUnitTestCase { private BasicTestingJdbcServiceImpl services = new BasicTestingJdbcServiceImpl(); - public BasicConnectionProxyTest(String string) { - super( string ); - } - + @Before public void setUp() { services.prepare( false ); } + @After public void tearDown() { services.release(); } + @Test public void testDatabaseMetaDataHandling() throws Throwable { LogicalConnectionImpl logicalConnection = new LogicalConnectionImpl( null, @@ -73,7 +78,7 @@ public class BasicConnectionProxyTest extends UnitTestCase { metaData.getSchemas(); assertTrue( logicalConnection.getResourceRegistry().hasRegisteredResources() ); } - catch ( SQLException sqle ) { + catch ( SQLException e ) { fail( "incorrect exception type : sqlexception" ); } finally { @@ -82,6 +87,7 @@ public class BasicConnectionProxyTest extends UnitTestCase { } } + @Test public void testExceptionHandling() { LogicalConnectionImpl logicalConnection = new LogicalConnectionImpl( null, @@ -92,7 +98,7 @@ public class BasicConnectionProxyTest extends UnitTestCase { try { proxiedConnection.prepareStatement( "select count(*) from NON_EXISTENT" ).executeQuery(); } - catch ( SQLException sqle ) { + catch ( SQLException e ) { fail( "incorrect exception type : sqlexception" ); } catch ( JDBCException ok ) { @@ -103,6 +109,7 @@ public class BasicConnectionProxyTest extends UnitTestCase { } } + @Test public void testBasicJdbcUsage() throws JDBCException { LogicalConnectionImpl logicalConnection = new LogicalConnectionImpl( null, @@ -112,12 +119,12 @@ public class BasicConnectionProxyTest extends UnitTestCase { Connection proxiedConnection = ProxyBuilder.buildConnection( logicalConnection ); try { - Statement stmnt = proxiedConnection.createStatement(); - stmnt.execute( "drop table SANDBOX_JDBC_TST if exists" ); - stmnt.execute( "create table SANDBOX_JDBC_TST ( ID integer, NAME varchar(100) )" ); + Statement statement = proxiedConnection.createStatement(); + statement.execute( "drop table SANDBOX_JDBC_TST if exists" ); + statement.execute( "create table SANDBOX_JDBC_TST ( ID integer, NAME varchar(100) )" ); assertTrue( logicalConnection.getResourceRegistry().hasRegisteredResources() ); assertTrue( logicalConnection.isPhysicallyConnected() ); - stmnt.close(); + statement.close(); assertFalse( logicalConnection.getResourceRegistry().hasRegisteredResources() ); assertTrue( logicalConnection.isPhysicallyConnected() ); // after_transaction specified @@ -131,7 +138,7 @@ public class BasicConnectionProxyTest extends UnitTestCase { assertTrue( logicalConnection.getResourceRegistry().hasRegisteredResources() ); } - catch ( SQLException sqle ) { + catch ( SQLException e ) { fail( "incorrect exception type : sqlexception" ); } finally { diff --git a/hibernate-core/src/test/java/org/hibernate/test/jdbc/proxies/BatchingTest.java b/hibernate-core/src/test/java/org/hibernate/test/jdbc/proxies/BatchingTest.java index 9fee757052..54bbd710a4 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/jdbc/proxies/BatchingTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/jdbc/proxies/BatchingTest.java @@ -23,6 +23,10 @@ */ package org.hibernate.test.jdbc.proxies; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.Statement; + import org.hibernate.engine.jdbc.batch.internal.BasicBatchKey; import org.hibernate.engine.jdbc.batch.internal.BatchBuilderImpl; import org.hibernate.engine.jdbc.batch.internal.BatchingBatch; @@ -38,40 +42,41 @@ import org.hibernate.engine.transaction.spi.TransactionImplementor; import org.hibernate.jdbc.Expectation; import org.hibernate.jdbc.Expectations; import org.hibernate.service.internal.ServiceRegistryImpl; -import org.hibernate.service.spi.ServiceRegistry; import org.hibernate.service.spi.StandardServiceInitiators; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import org.hibernate.testing.junit4.BaseUnitTestCase; import org.hibernate.test.common.ConnectionProviderBuilder; import org.hibernate.test.common.JournalingBatchObserver; import org.hibernate.test.common.JournalingTransactionObserver; import org.hibernate.test.common.TransactionContextImpl; import org.hibernate.test.common.TransactionEnvironmentImpl; -import org.hibernate.testing.junit.UnitTestCase; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.Statement; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; /** * @author Steve Ebersole */ -public class BatchingTest extends UnitTestCase implements BatchKey { - private ServiceRegistry serviceRegistry; - - public BatchingTest(String string) { - super( string ); - } +public class BatchingTest extends BaseUnitTestCase implements BatchKey { + private ServiceRegistryImpl serviceRegistry; + @Before public void setUp() throws Exception { - super.setUp(); serviceRegistry = new ServiceRegistryImpl( StandardServiceInitiators.LIST, ConnectionProviderBuilder.getConnectionProviderProperties() ); } + @After public void tearDown() throws Exception { - ( (ServiceRegistryImpl) serviceRegistry).destroy(); - super.tearDown(); + serviceRegistry.destroy(); } @Override @@ -84,6 +89,7 @@ public class BatchingTest extends UnitTestCase implements BatchKey { return Expectations.BASIC; } + @Test public void testNonBatchingUsage() throws Exception { final TransactionContext transactionContext = new TransactionContextImpl( new TransactionEnvironmentImpl( serviceRegistry ) ); @@ -141,6 +147,7 @@ public class BatchingTest extends UnitTestCase implements BatchKey { logicalConnection.close(); } + @Test public void testBatchingUsage() throws Exception { final TransactionContext transactionContext = new TransactionContextImpl( new TransactionEnvironmentImpl( serviceRegistry ) ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/legacy/CacheTest.java b/hibernate-core/src/test/java/org/hibernate/test/legacy/CacheTest.java index 4393362441..0c7c1c2f43 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/legacy/CacheTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/legacy/CacheTest.java @@ -1,25 +1,43 @@ -//$Id: CacheTest.java 11398 2007-04-10 14:54:07Z steve.ebersole@jboss.com $ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2007-2011, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ package org.hibernate.test.legacy; -import junit.framework.Test; -import junit.framework.TestSuite; + import org.hibernate.cache.Cache; import org.hibernate.cache.CacheConcurrencyStrategy; import org.hibernate.cache.CacheProvider; import org.hibernate.cache.HashtableCacheProvider; import org.hibernate.cache.ReadWriteCache; import org.hibernate.cache.access.SoftLock; -import org.hibernate.testing.junit.UnitTestCase; -public class CacheTest extends UnitTestCase { +import org.junit.Test; - public CacheTest(String name) { - super( name ); - } +import org.hibernate.testing.junit4.BaseUnitTestCase; - public static Test suite() { - return new TestSuite( CacheTest.class ); - } +import static org.junit.Assert.assertTrue; +public class CacheTest extends BaseUnitTestCase { + @Test public void testCaches() throws Exception { doTestCache( new HashtableCacheProvider() ); } @@ -30,111 +48,111 @@ public class CacheTest extends UnitTestCase { long longBefore = cache.nextTimestamp(); - Thread.sleep(15); + Thread.sleep( 15 ); long before = cache.nextTimestamp(); - Thread.sleep(15); + Thread.sleep( 15 ); //cache.setTimeout(1000); CacheConcurrencyStrategy ccs = new ReadWriteCache(); - ccs.setCache(cache); + ccs.setCache( cache ); // cache something - assertTrue( ccs.put("foo", "foo", before, null, null, false) ); + assertTrue( ccs.put( "foo", "foo", before, null, null, false ) ); - Thread.sleep(15); + Thread.sleep( 15 ); long after = cache.nextTimestamp(); - assertTrue( ccs.get("foo", longBefore)==null ); - assertTrue( ccs.get("foo", after).equals("foo") ); + assertTrue( ccs.get( "foo", longBefore ) == null ); + assertTrue( ccs.get( "foo", after ).equals( "foo" ) ); - assertTrue( !ccs.put("foo", "foo", before, null, null, false) ); + assertTrue( !ccs.put( "foo", "foo", before, null, null, false ) ); // update it: - SoftLock lock = ccs.lock("foo", null); + SoftLock lock = ccs.lock( "foo", null ); - assertTrue( ccs.get("foo", after)==null ); - assertTrue( ccs.get("foo", longBefore)==null ); + assertTrue( ccs.get( "foo", after ) == null ); + assertTrue( ccs.get( "foo", longBefore ) == null ); - assertTrue( !ccs.put("foo", "foo", before, null, null, false) ); + assertTrue( !ccs.put( "foo", "foo", before, null, null, false ) ); - Thread.sleep(15); + Thread.sleep( 15 ); long whileLocked = cache.nextTimestamp(); - assertTrue( !ccs.put("foo", "foo", whileLocked, null, null, false) ); + assertTrue( !ccs.put( "foo", "foo", whileLocked, null, null, false ) ); - Thread.sleep(15); + Thread.sleep( 15 ); - ccs.release("foo", lock); + ccs.release( "foo", lock ); - assertTrue( ccs.get("foo", after)==null ); - assertTrue( ccs.get("foo", longBefore)==null ); + assertTrue( ccs.get( "foo", after ) == null ); + assertTrue( ccs.get( "foo", longBefore ) == null ); - assertTrue( !ccs.put("foo", "bar", whileLocked, null, null, false) ); - assertTrue( !ccs.put("foo", "bar", after, null, null, false) ); + assertTrue( !ccs.put( "foo", "bar", whileLocked, null, null, false ) ); + assertTrue( !ccs.put( "foo", "bar", after, null, null, false ) ); - Thread.sleep(15); + Thread.sleep( 15 ); long longAfter = cache.nextTimestamp(); - assertTrue( ccs.put("foo", "baz", longAfter, null, null, false) ); + assertTrue( ccs.put( "foo", "baz", longAfter, null, null, false ) ); - assertTrue( ccs.get("foo", after)==null ); - assertTrue( ccs.get("foo", whileLocked)==null ); + assertTrue( ccs.get( "foo", after ) == null ); + assertTrue( ccs.get( "foo", whileLocked ) == null ); - Thread.sleep(15); + Thread.sleep( 15 ); long longLongAfter = cache.nextTimestamp(); - assertTrue( ccs.get("foo", longLongAfter).equals("baz") ); + assertTrue( ccs.get( "foo", longLongAfter ).equals( "baz" ) ); // update it again, with multiple locks: - SoftLock lock1 = ccs.lock("foo", null); - SoftLock lock2 = ccs.lock("foo", null); + SoftLock lock1 = ccs.lock( "foo", null ); + SoftLock lock2 = ccs.lock( "foo", null ); - assertTrue( ccs.get("foo", longLongAfter)==null ); + assertTrue( ccs.get( "foo", longLongAfter ) == null ); - Thread.sleep(15); + Thread.sleep( 15 ); whileLocked = cache.nextTimestamp(); - assertTrue( !ccs.put("foo", "foo", whileLocked, null, null, false) ); + assertTrue( !ccs.put( "foo", "foo", whileLocked, null, null, false ) ); - Thread.sleep(15); + Thread.sleep( 15 ); - ccs.release("foo", lock2); + ccs.release( "foo", lock2 ); - Thread.sleep(15); + Thread.sleep( 15 ); long betweenReleases = cache.nextTimestamp(); - assertTrue( !ccs.put("foo", "bar", betweenReleases, null, null, false) ); - assertTrue( ccs.get("foo", betweenReleases)==null ); + assertTrue( !ccs.put( "foo", "bar", betweenReleases, null, null, false ) ); + assertTrue( ccs.get( "foo", betweenReleases ) == null ); - Thread.sleep(15); + Thread.sleep( 15 ); - ccs.release("foo", lock1); + ccs.release( "foo", lock1 ); - assertTrue( !ccs.put("foo", "bar", whileLocked, null, null, false) ); + assertTrue( !ccs.put( "foo", "bar", whileLocked, null, null, false ) ); - Thread.sleep(15); + Thread.sleep( 15 ); longAfter = cache.nextTimestamp(); - assertTrue( ccs.put("foo", "baz", longAfter, null, null, false) ); - assertTrue( ccs.get("foo", whileLocked)==null ); + assertTrue( ccs.put( "foo", "baz", longAfter, null, null, false ) ); + assertTrue( ccs.get( "foo", whileLocked ) == null ); - Thread.sleep(15); + Thread.sleep( 15 ); longLongAfter = cache.nextTimestamp(); - assertTrue( ccs.get("foo", longLongAfter).equals("baz") ); + assertTrue( ccs.get( "foo", longLongAfter ).equals( "baz" ) ); } diff --git a/hibernate-core/src/test/java/org/hibernate/test/legacy/NonReflectiveBinderTest.java b/hibernate-core/src/test/java/org/hibernate/test/legacy/NonReflectiveBinderTest.java index fb9360c06d..d5fd8cea07 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/legacy/NonReflectiveBinderTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/legacy/NonReflectiveBinderTest.java @@ -1,9 +1,30 @@ -//$Id: NonReflectiveBinderTest.java 10977 2006-12-12 23:28:04Z steve.ebersole@jboss.com $ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2006-2011, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ package org.hibernate.test.legacy; import java.util.Iterator; import java.util.Map; -import junit.framework.Test; -import junit.framework.TestSuite; + import org.hibernate.cfg.Configuration; import org.hibernate.mapping.Bag; import org.hibernate.mapping.Collection; @@ -11,38 +32,41 @@ import org.hibernate.mapping.Component; import org.hibernate.mapping.MetaAttribute; import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.Property; -import org.hibernate.testing.junit.UnitTestCase; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import org.hibernate.testing.TestForIssue; +import org.hibernate.testing.junit4.BaseUnitTestCase; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; -public class NonReflectiveBinderTest extends UnitTestCase { - +public class NonReflectiveBinderTest extends BaseUnitTestCase { private Configuration cfg; - public NonReflectiveBinderTest(String x) { - super( x ); - } - public String[] getMappings() { return new String[] { "legacy/Wicked.hbm.xml"}; } - public static Test suite() { - return new TestSuite( NonReflectiveBinderTest.class ); - } - - protected void setUp() throws Exception { - super.setUp(); + @Before + public void setUp() throws Exception { cfg = new Configuration() .addResource( "org/hibernate/test/legacy/Wicked.hbm.xml" ) .setProperty( "javax.persistence.validation.mode", "none" ); cfg.buildMappings(); } + @After protected void tearDown() throws Exception { cfg = null; - super.tearDown(); } + @Test public void testMetaInheritance() { PersistentClass cm = cfg.getClassMapping("org.hibernate.test.legacy.Wicked"); Map m = cm.getMetaAttributes(); @@ -95,7 +119,8 @@ public class NonReflectiveBinderTest extends UnitTestCase { } - // HBX-718 + @Test + @TestForIssue( jiraKey = "HBX-718" ) public void testNonMutatedInheritance() { PersistentClass cm = cfg.getClassMapping("org.hibernate.test.legacy.Wicked"); MetaAttribute metaAttribute = cm.getMetaAttribute( "globalmutated" ); @@ -176,7 +201,8 @@ public class NonReflectiveBinderTest extends UnitTestCase { } - + + @Test public void testComparator() { PersistentClass cm = cfg.getClassMapping("org.hibernate.test.legacy.Wicked"); diff --git a/hibernate-core/src/test/java/org/hibernate/test/mapping/PersistentClassVisitorTest.java b/hibernate-core/src/test/java/org/hibernate/test/mapping/PersistentClassVisitorTest.java index 9c38e31039..f487e67466 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/mapping/PersistentClassVisitorTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/mapping/PersistentClassVisitorTest.java @@ -1,26 +1,52 @@ /* -* Created on 06-Dec-2004 -* -*/ + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2004-2011, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ package org.hibernate.test.mapping; -import junit.framework.Test; -import junit.framework.TestSuite; + +import org.junit.Test; + import org.hibernate.mapping.JoinedSubclass; import org.hibernate.mapping.PersistentClassVisitor; import org.hibernate.mapping.RootClass; import org.hibernate.mapping.SingleTableSubclass; import org.hibernate.mapping.Subclass; import org.hibernate.mapping.UnionSubclass; -import org.hibernate.testing.junit.UnitTestCase; +import org.hibernate.testing.junit4.BaseUnitTestCase; /** - * @author max + * Simple smoke style tests to make sure visitors keep working. * + * @author max */ -public class PersistentClassVisitorTest extends UnitTestCase { - - public PersistentClassVisitorTest(String string) { - super( string ); +public class PersistentClassVisitorTest extends BaseUnitTestCase { + @Test + public void testProperCallbacks() { + PersistentClassVisitorValidator vv = new PersistentClassVisitorValidator(); + new RootClass().accept( vv ); + new Subclass( new RootClass() ).accept( vv ); + new JoinedSubclass( new RootClass() ).accept( vv ); + new SingleTableSubclass( new RootClass() ).accept( vv ); + new UnionSubclass( new RootClass() ).accept( vv ); } static public class PersistentClassVisitorValidator implements PersistentClassVisitor { @@ -53,24 +79,6 @@ public class PersistentClassVisitorTest extends UnitTestCase { public Object accept(Subclass subclass) { return validate(Subclass.class, subclass); } - - - }; - - public void testProperCallbacks() { - - PersistentClassVisitorValidator vv = new PersistentClassVisitorValidator(); - - new RootClass().accept(vv); - new Subclass(new RootClass()).accept(vv); - new JoinedSubclass(new RootClass()).accept(vv); - new SingleTableSubclass(new RootClass()).accept(vv); - new UnionSubclass(new RootClass()).accept(vv); - - } - - public static Test suite() { - return new TestSuite(PersistentClassVisitorTest.class); } } diff --git a/hibernate-core/src/test/java/org/hibernate/test/mapping/ValueVisitorTest.java b/hibernate-core/src/test/java/org/hibernate/test/mapping/ValueVisitorTest.java index 0347793d53..0b7439e1f3 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/mapping/ValueVisitorTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/mapping/ValueVisitorTest.java @@ -1,10 +1,28 @@ /* - * Created on 06-Dec-2004 + * Hibernate, Relational Persistence for Idiomatic Java * + * Copyright (c) 2004-2011, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA */ package org.hibernate.test.mapping; -import junit.framework.Test; -import junit.framework.TestSuite; + import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Mappings; import org.hibernate.mapping.Any; @@ -24,158 +42,23 @@ import org.hibernate.mapping.Set; import org.hibernate.mapping.SimpleValue; import org.hibernate.mapping.Table; import org.hibernate.mapping.ValueVisitor; -import org.hibernate.testing.junit.UnitTestCase; + +import org.junit.Test; + +import org.hibernate.testing.junit4.BaseUnitTestCase; /** * @author max - * */ -public class ValueVisitorTest extends UnitTestCase { - - public ValueVisitorTest(String string) { - super( string ); - } - - static public class ValueVisitorValidator implements ValueVisitor { - - /* (non-Javadoc) - * @see org.hibernate.mapping.ValueVisitor#accept(org.hibernate.mapping.PrimitiveArray) - */ - public Object accept(PrimitiveArray primitiveArray) { - return validate(PrimitiveArray.class,primitiveArray); - } - /* - * (non-Javadoc) - * - * @see org.hibernate.mapping.ValueVisitor#accept(org.hibernate.mapping.Bag) - */ - public Object accept(Bag bag) { - return validate(Bag.class, bag); - } - - /* (non-Javadoc) - * @see org.hibernate.mapping.ValueVisitor#accept(org.hibernate.mapping.DependantValue) - */ - public Object accept(DependantValue value) { - return validate(DependantValue.class, value); - } - /** - * @param expectedClass - * @param visitee - */ - private Object validate(Class expectedClass, Object visitee) { - if (!visitee.getClass().getName().equals(expectedClass.getName())) { - throw new IllegalStateException(visitee.getClass().getName() - + " did not call proper accept method. Was " - + expectedClass.getName()); - } - return null; - } - - /* - * (non-Javadoc) - * - * @see org.hibernate.mapping.ValueVisitor#accept(org.hibernate.mapping.IdentifierBag) - */ - public Object accept(IdentifierBag bag) { - return validate(IdentifierBag.class, bag); - - } - - /* - * (non-Javadoc) - * - * @see org.hibernate.mapping.ValueVisitor#accept(org.hibernate.mapping.List) - */ - public Object accept(List list) { - return validate(List.class, list); - - } - - /* - * (non-Javadoc) - * - * @see org.hibernate.mapping.ValueVisitor#accept(org.hibernate.mapping.Map) - */ - public Object accept(Map map) { - return validate(Map.class, map); - - } - - /* (non-Javadoc) - * @see org.hibernate.mapping.ValueVisitor#accept(org.hibernate.mapping.Array) - */ - public Object accept(Array list) { - return validate(Array.class, list); - } - /* - * (non-Javadoc) - * - * @see org.hibernate.mapping.ValueVisitor#accept(org.hibernate.mapping.OneToMany) - */ - public Object accept(OneToMany many) { - return validate(OneToMany.class, many); - } - - /* - * (non-Javadoc) - * - * @see org.hibernate.mapping.ValueVisitor#accept(org.hibernate.mapping.Set) - */ - public Object accept(Set set) { - return validate(Set.class, set); - } - - /* - * (non-Javadoc) - * - * @see org.hibernate.mapping.ValueVisitor#accept(org.hibernate.mapping.Any) - */ - public Object accept(Any any) { - return validate(Any.class, any); - - } - - /* - * (non-Javadoc) - * - * @see org.hibernate.mapping.ValueVisitor#accept(org.hibernate.mapping.SimpleValue) - */ - public Object accept(SimpleValue value) { - return validate(SimpleValue.class, value); - - } - - /* (non-Javadoc) - * @see org.hibernate.mapping.ValueVisitor#accept(org.hibernate.mapping.Component) - */ - public Object accept(Component component) { - return validate(Component.class, component); - } - - /* (non-Javadoc) - * @see org.hibernate.mapping.ValueVisitor#accept(org.hibernate.mapping.ManyToOne) - */ - public Object accept(ManyToOne mto) { - return validate(ManyToOne.class, mto); - } - - /* (non-Javadoc) - * @see org.hibernate.mapping.ValueVisitor#accept(org.hibernate.mapping.OneToOne) - */ - public Object accept(OneToOne oto) { - return validate(OneToOne.class, oto); - } - - }; - +public class ValueVisitorTest extends BaseUnitTestCase { + @Test public void testProperCallbacks() { final Mappings mappings = new Configuration().createMappings(); final Table tbl = new Table(); final RootClass rootClass = new RootClass(); ValueVisitor vv = new ValueVisitorValidator(); - + new Any( mappings, tbl ).accept(vv); new Array( mappings, rootClass ).accept(vv); new Bag( mappings, rootClass ).accept(vv); @@ -190,13 +73,74 @@ public class ValueVisitorTest extends UnitTestCase { new PrimitiveArray( mappings, rootClass ).accept(vv); new Set( mappings, rootClass ).accept(vv); new SimpleValue( mappings ).accept(vv); - - } - public static Test suite() { - return new TestSuite(ValueVisitorTest.class); + static public class ValueVisitorValidator implements ValueVisitor { + + public Object accept(PrimitiveArray primitiveArray) { + return validate(PrimitiveArray.class,primitiveArray); + } + + public Object accept(Bag bag) { + return validate(Bag.class, bag); + } + + public Object accept(DependantValue value) { + return validate(DependantValue.class, value); + } + + private Object validate(Class expectedClass, Object visitee) { + if (!visitee.getClass().getName().equals(expectedClass.getName())) { + throw new IllegalStateException(visitee.getClass().getName() + + " did not call proper accept method. Was " + + expectedClass.getName()); + } + return null; + } + + public Object accept(IdentifierBag bag) { + return validate(IdentifierBag.class, bag); + } + + public Object accept(List list) { + return validate(List.class, list); + } + + public Object accept(Map map) { + return validate(Map.class, map); + } + + public Object accept(Array list) { + return validate(Array.class, list); + } + + public Object accept(OneToMany many) { + return validate(OneToMany.class, many); + } + + public Object accept(Set set) { + return validate(Set.class, set); + } + + public Object accept(Any any) { + return validate(Any.class, any); + } + + public Object accept(SimpleValue value) { + return validate(SimpleValue.class, value); + } + + public Object accept(Component component) { + return validate(Component.class, component); + } + + public Object accept(ManyToOne mto) { + return validate(ManyToOne.class, mto); + } + + public Object accept(OneToOne oto) { + return validate(OneToOne.class, oto); + } + } - - } diff --git a/hibernate-core/src/test/java/org/hibernate/test/mappingexception/MappingExceptionTest.java b/hibernate-core/src/test/java/org/hibernate/test/mappingexception/MappingExceptionTest.java index dc8fd825e2..badca60ee8 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/mappingexception/MappingExceptionTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/mappingexception/MappingExceptionTest.java @@ -1,5 +1,5 @@ // $Id: SQLExceptionConversionTest.java 6847 2005-05-21 15:46:41Z oneovthafew $ -package org.hibernate.test.mappingexception; +package org.hibernate.test.mappingexception; import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileOutputStream; @@ -8,8 +8,7 @@ import java.io.InputStream; import java.io.OutputStream; import java.net.MalformedURLException; import java.net.URL; -import junit.framework.Test; -import junit.framework.TestSuite; + import org.hibernate.DuplicateMappingException; import org.hibernate.Hibernate; import org.hibernate.InvalidMappingException; @@ -17,23 +16,23 @@ import org.hibernate.MappingException; import org.hibernate.MappingNotFoundException; import org.hibernate.cfg.Configuration; import org.hibernate.internal.util.ConfigHelper; -import org.hibernate.testing.junit.UnitTestCase; + +import org.junit.Test; + +import org.hibernate.testing.junit4.BaseUnitTestCase; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; /** * Test for various mapping exceptions thrown when mappings are not found or invalid. * * @author Max Rydahl Andersen */ -public class MappingExceptionTest extends UnitTestCase { - - public MappingExceptionTest(String name) { - super( name ); - } - - public static Test suite() { - return new TestSuite( MappingExceptionTest.class ); - } - +public class MappingExceptionTest extends BaseUnitTestCase { + @Test public void testNotFound() throws MappingException, MalformedURLException { Configuration cfg = new Configuration(); @@ -129,10 +128,16 @@ public class MappingExceptionTest extends UnitTestCase { cfg.buildMappings(); fail(); } - catch ( InvalidMappingException inv ) { - assertEquals( inv.getType(), "resource" ); - assertEquals( inv.getPath(), resourceName ); - assertClassAssignability( inv.getCause().getClass(), DuplicateMappingException.class ); + catch ( InvalidMappingException e ) { + assertEquals( e.getType(), "resource" ); + assertEquals( e.getPath(), resourceName ); + assertClassAssignability( DuplicateMappingException.class, e.getCause().getClass() ); + } + } + + private void assertClassAssignability(Class expected, Class actual) { + if ( !expected.isAssignableFrom( actual ) ) { + fail( "Actual class [" + actual.getName() + "] not assignable to expected [" + expected.getName() + "]" ); } } diff --git a/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/MigrationTest.java b/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/MigrationTest.java index 18b0cf9186..c7dd356f79 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/MigrationTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/MigrationTest.java @@ -1,24 +1,66 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ package org.hibernate.test.schemaupdate; -import junit.framework.Test; -import junit.framework.TestSuite; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import static org.junit.Assert.assertEquals; + import org.hibernate.cfg.Configuration; -import org.hibernate.testing.junit.UnitTestCase; + +import org.hibernate.testing.ServiceRegistryBuilder; +import org.hibernate.testing.junit4.BaseUnitTestCase; + +import org.hibernate.cfg.Environment; +import org.hibernate.engine.jdbc.spi.JdbcServices; +import org.hibernate.service.spi.ServiceRegistry; import org.hibernate.tool.hbm2ddl.SchemaExport; import org.hibernate.tool.hbm2ddl.SchemaUpdate; /** * @author Max Rydahl Andersen */ -public class MigrationTest extends UnitTestCase { +public class MigrationTest extends BaseUnitTestCase { + private ServiceRegistry serviceRegistry; - public MigrationTest(String str) { - super( str ); + @Before + public void setUp() { + serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( Environment.getProperties() ); } - public static Test suite() { - return new TestSuite( MigrationTest.class ); + @After + public void tearDown() { + ServiceRegistryBuilder.destroy( serviceRegistry ); + serviceRegistry = null; } + protected JdbcServices getJdbcServices() { + return serviceRegistry.getService( JdbcServices.class ); + } + + @Test public void testSimpleColumnAddition() { String resource1 = "org/hibernate/test/schemaupdate/1_Version.hbm.xml"; String resource2 = "org/hibernate/test/schemaupdate/2_Version.hbm.xml"; diff --git a/hibernate-core/src/test/java/org/hibernate/test/service/ServiceBootstrappingTest.java b/hibernate-core/src/test/java/org/hibernate/test/service/ServiceBootstrappingTest.java index a222b9c600..4cc2b31656 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/service/ServiceBootstrappingTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/service/ServiceBootstrappingTest.java @@ -24,6 +24,11 @@ package org.hibernate.test.service; import java.util.Properties; + +import org.junit.Test; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + import org.hibernate.cfg.Environment; import org.hibernate.dialect.H2Dialect; import org.hibernate.engine.jdbc.spi.JdbcServices; @@ -31,19 +36,15 @@ import org.hibernate.service.internal.ServiceRegistryImpl; import org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl; import org.hibernate.service.jdbc.connections.internal.UserSuppliedConnectionProviderImpl; import org.hibernate.service.jdbc.connections.spi.ConnectionProvider; + +import org.hibernate.testing.junit4.BaseUnitTestCase; import org.hibernate.test.common.ConnectionProviderBuilder; -import org.hibernate.testing.junit.UnitTestCase; /** - * TODO : javadoc - * * @author Steve Ebersole */ -public class ServiceBootstrappingTest extends UnitTestCase { - public ServiceBootstrappingTest(String string) { - super( string ); - } - +public class ServiceBootstrappingTest extends BaseUnitTestCase { + @Test public void testBasicBuild() { ServiceRegistryImpl serviceRegistry = new ServiceRegistryImpl( ConnectionProviderBuilder.getConnectionProviderProperties() ); JdbcServices jdbcServices = serviceRegistry.getService( JdbcServices.class ); @@ -55,6 +56,7 @@ public class ServiceBootstrappingTest extends UnitTestCase { serviceRegistry.destroy(); } + @Test public void testBuildWithLogging() { Properties props = ConnectionProviderBuilder.getConnectionProviderProperties(); props.put( Environment.SHOW_SQL, "true" ); @@ -69,6 +71,7 @@ public class ServiceBootstrappingTest extends UnitTestCase { serviceRegistry.destroy(); } + @Test public void testBuildWithServiceOverride() { Properties props = ConnectionProviderBuilder.getConnectionProviderProperties(); diff --git a/hibernate-core/src/test/java/org/hibernate/test/transaction/jdbc/TestExpectedUsage.java b/hibernate-core/src/test/java/org/hibernate/test/transaction/jdbc/TestExpectedUsage.java index 871f544f9c..ac5d81fd1a 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/transaction/jdbc/TestExpectedUsage.java +++ b/hibernate-core/src/test/java/org/hibernate/test/transaction/jdbc/TestExpectedUsage.java @@ -23,50 +23,53 @@ */ package org.hibernate.test.transaction.jdbc; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.SQLException; +import java.sql.Statement; + import org.hibernate.ConnectionReleaseMode; import org.hibernate.engine.jdbc.spi.LogicalConnectionImplementor; import org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl; import org.hibernate.engine.transaction.spi.TransactionContext; import org.hibernate.engine.transaction.spi.TransactionImplementor; import org.hibernate.service.internal.ServiceRegistryImpl; -import org.hibernate.service.spi.ServiceRegistry; import org.hibernate.service.spi.StandardServiceInitiators; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import org.hibernate.testing.junit4.BaseUnitTestCase; import org.hibernate.test.common.ConnectionProviderBuilder; import org.hibernate.test.common.JournalingTransactionObserver; import org.hibernate.test.common.TransactionContextImpl; import org.hibernate.test.common.TransactionEnvironmentImpl; -import org.hibernate.testing.junit.UnitTestCase; - -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.SQLException; -import java.sql.Statement; /** - * TODO : javadoc - * * @author Steve Ebersole */ -public class TestExpectedUsage extends UnitTestCase { - private ServiceRegistry serviceRegistry; - - public TestExpectedUsage(String string) { - super( string ); - } +public class TestExpectedUsage extends BaseUnitTestCase { + private ServiceRegistryImpl serviceRegistry; + @Before public void setUp() throws Exception { - super.setUp(); serviceRegistry = new ServiceRegistryImpl( StandardServiceInitiators.LIST, ConnectionProviderBuilder.getConnectionProviderProperties() ); } + @After public void tearDown() throws Exception { - ( (ServiceRegistryImpl) serviceRegistry).destroy(); - super.tearDown(); + serviceRegistry.destroy(); } + @Test public void testBasicUsage() { final TransactionContext transactionContext = new TransactionContextImpl( new TransactionEnvironmentImpl( serviceRegistry ) ) { @Override diff --git a/hibernate-core/src/test/java/org/hibernate/test/transaction/jta/BasicDrivingTest.java b/hibernate-core/src/test/java/org/hibernate/test/transaction/jta/BasicDrivingTest.java index d38a056c02..a06fae5fe6 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/transaction/jta/BasicDrivingTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/transaction/jta/BasicDrivingTest.java @@ -23,6 +23,21 @@ */ package org.hibernate.test.transaction.jta; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.HashMap; +import java.util.Map; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + import org.hibernate.cfg.Environment; import org.hibernate.engine.jdbc.spi.LogicalConnectionImplementor; import org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl; @@ -33,51 +48,40 @@ import org.hibernate.service.internal.ServiceProxy; import org.hibernate.service.internal.ServiceRegistryImpl; import org.hibernate.service.jta.platform.internal.JtaPlatformInitiator; import org.hibernate.service.jta.platform.spi.JtaPlatform; -import org.hibernate.service.spi.ServiceRegistry; -import org.hibernate.service.spi.StandardServiceInitiators; + +import org.hibernate.testing.junit4.BaseUnitTestCase; import org.hibernate.test.common.ConnectionProviderBuilder; import org.hibernate.test.common.JournalingTransactionObserver; import org.hibernate.test.common.TransactionContextImpl; import org.hibernate.test.common.TransactionEnvironmentImpl; import org.hibernate.test.common.jta.AtomikosDataSourceConnectionProvider; import org.hibernate.test.common.jta.AtomikosJtaPlatform; -import org.hibernate.testing.junit.UnitTestCase; - -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.SQLException; -import java.sql.Statement; -import java.util.HashMap; -import java.util.Map; /** * Testing transaction handling when the JTA transaction facade is the driver. * * @author Steve Ebersole */ -public class BasicDrivingTest extends UnitTestCase { - private ServiceRegistry serviceRegistry; - - public BasicDrivingTest(String string) { - super( string ); - } +public class BasicDrivingTest extends BaseUnitTestCase { + private ServiceRegistryImpl serviceRegistry; + @Before + @SuppressWarnings( {"unchecked"}) public void setUp() throws Exception { - super.setUp(); - Map configValues = new HashMap(); configValues.putAll( ConnectionProviderBuilder.getConnectionProviderProperties() ); configValues.put( Environment.TRANSACTION_STRATEGY, JtaTransactionFactory.class.getName() ); configValues.put( JtaPlatformInitiator.JTA_PLATFORM, AtomikosJtaPlatform.class.getName() ); configValues.put( Environment.CONNECTION_PROVIDER, AtomikosDataSourceConnectionProvider.class.getName() ); - serviceRegistry = new ServiceRegistryImpl( StandardServiceInitiators.LIST, configValues ); + serviceRegistry = new ServiceRegistryImpl( configValues ); } + @After public void tearDown() throws Exception { - ( (ServiceRegistryImpl) serviceRegistry).destroy(); - super.tearDown(); + serviceRegistry.destroy(); } + @Test public void testBasicUsage() throws Throwable { final TransactionContext transactionContext = new TransactionContextImpl( new TransactionEnvironmentImpl( serviceRegistry ) ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/transaction/jta/ManagedDrivingTest.java b/hibernate-core/src/test/java/org/hibernate/test/transaction/jta/ManagedDrivingTest.java index 746497f89a..93ca458dcf 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/transaction/jta/ManagedDrivingTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/transaction/jta/ManagedDrivingTest.java @@ -23,6 +23,14 @@ */ package org.hibernate.test.transaction.jta; +import javax.transaction.TransactionManager; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.HashMap; +import java.util.Map; + import org.hibernate.ConnectionReleaseMode; import org.hibernate.cfg.Environment; import org.hibernate.engine.jdbc.spi.LogicalConnectionImplementor; @@ -34,39 +42,36 @@ import org.hibernate.service.internal.ServiceProxy; import org.hibernate.service.internal.ServiceRegistryImpl; import org.hibernate.service.jta.platform.internal.JtaPlatformInitiator; import org.hibernate.service.jta.platform.spi.JtaPlatform; -import org.hibernate.service.spi.ServiceRegistry; import org.hibernate.service.spi.StandardServiceInitiators; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import org.hibernate.testing.junit4.BaseUnitTestCase; import org.hibernate.test.common.ConnectionProviderBuilder; import org.hibernate.test.common.JournalingTransactionObserver; import org.hibernate.test.common.TransactionContextImpl; import org.hibernate.test.common.TransactionEnvironmentImpl; import org.hibernate.test.common.jta.AtomikosDataSourceConnectionProvider; import org.hibernate.test.common.jta.AtomikosJtaPlatform; -import org.hibernate.testing.junit.UnitTestCase; -import javax.transaction.TransactionManager; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.SQLException; -import java.sql.Statement; -import java.util.HashMap; -import java.util.Map; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; /** - * Testing transaction facacde handling when the transaction is being driven by somethign other than the facade. + * Testing transaction facade handling when the transaction is being driven by something other than the facade. * * @author Steve Ebersole */ -public class ManagedDrivingTest extends UnitTestCase { - private ServiceRegistry serviceRegistry; - - public ManagedDrivingTest(String string) { - super( string ); - } +public class ManagedDrivingTest extends BaseUnitTestCase { + private ServiceRegistryImpl serviceRegistry; + @Before + @SuppressWarnings( {"unchecked"}) public void setUp() throws Exception { - super.setUp(); - Map configValues = new HashMap(); configValues.putAll( ConnectionProviderBuilder.getConnectionProviderProperties() ); configValues.put( Environment.TRANSACTION_STRATEGY, CMTTransactionFactory.class.getName() ); @@ -76,12 +81,12 @@ public class ManagedDrivingTest extends UnitTestCase { serviceRegistry = new ServiceRegistryImpl( StandardServiceInitiators.LIST, configValues ); } - + @After public void tearDown() throws Exception { - ( (ServiceRegistryImpl) serviceRegistry).destroy(); - super.tearDown(); + serviceRegistry.destroy(); } + @Test public void testBasicUsage() throws Throwable { final TransactionContext transactionContext = new TransactionContextImpl( new TransactionEnvironmentImpl( serviceRegistry ) ) { @Override diff --git a/hibernate-core/src/test/java/org/hibernate/test/util/PropertiesHelperTest.java b/hibernate-core/src/test/java/org/hibernate/test/util/PropertiesHelperTest.java index fcbc7d848d..58d491b88e 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/util/PropertiesHelperTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/util/PropertiesHelperTest.java @@ -1,26 +1,27 @@ package org.hibernate.test.util; import java.util.Properties; -import junit.framework.Test; -import junit.framework.TestSuite; + import org.hibernate.internal.util.config.ConfigurationHelper; -import org.hibernate.testing.junit.UnitTestCase; + +import org.junit.Before; +import org.junit.Test; + +import org.hibernate.testing.junit4.BaseUnitTestCase; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; /** * @author Steve Ebersole */ -public class PropertiesHelperTest extends UnitTestCase { - +public class PropertiesHelperTest extends BaseUnitTestCase { private Properties props; - public PropertiesHelperTest(String string) { - super( string ); - } - - public static Test suite() { - return new TestSuite( PropertiesHelperTest.class ); - } - - protected void setUp() throws Exception { + @Before + public void setUp() throws Exception { props = new Properties(); props.setProperty( "my.nonexistent.prop", "${}" ); @@ -45,6 +46,7 @@ public class PropertiesHelperTest extends UnitTestCase { props.setProperty( "parse.error", "steve" ); } + @Test public void testPlaceholderReplacement() { ConfigurationHelper.resolvePlaceHolders( props ); @@ -85,6 +87,7 @@ public class PropertiesHelperTest extends UnitTestCase { assertEquals( "partial replacement (midst)", "basedir/tmp/myfile.txt", str ); } + @Test public void testParseExceptions() { boolean b = ConfigurationHelper.getBoolean( "parse.error", props ); assertFalse( "parse exception case - boolean", b ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/util/StringHelperTest.java b/hibernate-core/src/test/java/org/hibernate/test/util/StringHelperTest.java index 42bbcdb2d5..1efabee28a 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/util/StringHelperTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/util/StringHelperTest.java @@ -1,23 +1,42 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ package org.hibernate.test.util; -import junit.framework.Test; -import junit.framework.TestSuite; import org.hibernate.internal.util.StringHelper; import org.hibernate.testing.junit.UnitTestCase; +import org.junit.Test; + +import org.hibernate.testing.junit4.BaseUnitTestCase; + +import static org.junit.Assert.assertEquals; + /** * @author Steve Ebersole */ -public class StringHelperTest extends UnitTestCase { - - public StringHelperTest(String string) { - super( string ); - } - - public static Test suite() { - return new TestSuite( StringHelperTest.class ); - } - +public class StringHelperTest extends BaseUnitTestCase { + @Test public void testAliasGeneration() { assertSimpleAlias( "xyz", "xyz_" ); assertSimpleAlias( "_xyz", "xyz_" ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/util/dtd/EntityResolverTest.java b/hibernate-core/src/test/java/org/hibernate/test/util/dtd/EntityResolverTest.java index cb7779a258..7809f6ff98 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/util/dtd/EntityResolverTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/util/dtd/EntityResolverTest.java @@ -1,23 +1,38 @@ -package org.hibernate.test.util.dtd; -import junit.framework.Test; -import junit.framework.TestSuite; -import org.hibernate.cfg.Configuration; -import org.hibernate.testing.junit.UnitTestCase; +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2008-2011, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package org.hibernate.test.util.dtd; +import org.junit.Test; + +import org.hibernate.cfg.Configuration; +import org.hibernate.testing.junit4.BaseUnitTestCase; /** * @author Steve Ebersole */ -public class EntityResolverTest extends UnitTestCase { - - public EntityResolverTest(String name) { - super( name ); - } - - public static Test suite() { - return new TestSuite( EntityResolverTest.class ); - } - +public class EntityResolverTest extends BaseUnitTestCase { + @Test public void testEntityIncludeResolution() { // Parent.hbm.xml contains the following entity include: // diff --git a/hibernate-core/src/test/java/org/hibernate/testing/junit/AbstractClassLoaderIsolatedTestCase.java b/hibernate-core/src/test/java/org/hibernate/testing/junit/AbstractClassLoaderIsolatedTestCase.java index 527f71a775..82e4877d74 100644 --- a/hibernate-core/src/test/java/org/hibernate/testing/junit/AbstractClassLoaderIsolatedTestCase.java +++ b/hibernate-core/src/test/java/org/hibernate/testing/junit/AbstractClassLoaderIsolatedTestCase.java @@ -24,28 +24,29 @@ package org.hibernate.testing.junit; +import org.junit.After; +import org.junit.Before; + +import org.hibernate.testing.junit4.BaseUnitTestCase; + /** * A specialized TestCase for running tests in an isolated class-loader * * @author Steve Ebersole */ -public abstract class AbstractClassLoaderIsolatedTestCase extends UnitTestCase { +public abstract class AbstractClassLoaderIsolatedTestCase extends BaseUnitTestCase { private ClassLoader parentLoader; private ClassLoader isolatedLoader; - public AbstractClassLoaderIsolatedTestCase(String string) { - super( string ); - } - - protected void setUp() throws Exception { + @Before + public void setUp() throws Exception { parentLoader = Thread.currentThread().getContextClassLoader(); isolatedLoader = buildIsolatedClassLoader( parentLoader ); Thread.currentThread().setContextClassLoader( isolatedLoader ); - super.setUp(); } - protected void tearDown() throws Exception { - super.tearDown(); + @After + public void tearDown() throws Exception { Thread.currentThread().setContextClassLoader( parentLoader ); releaseIsolatedClassLoader( isolatedLoader ); parentLoader = null; diff --git a/hibernate-core/src/test/java/org/hibernate/type/BasicTypeRegistryTest.java b/hibernate-core/src/test/java/org/hibernate/type/BasicTypeRegistryTest.java index 0f5ef84e3a..485a582488 100644 --- a/hibernate-core/src/test/java/org/hibernate/type/BasicTypeRegistryTest.java +++ b/hibernate-core/src/test/java/org/hibernate/type/BasicTypeRegistryTest.java @@ -27,22 +27,29 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.UUID; -import junit.framework.TestCase; + +import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotSame; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; + import org.hibernate.HibernateException; import org.hibernate.engine.SessionImplementor; +import org.hibernate.testing.junit4.BaseUnitTestCase; import org.hibernate.type.descriptor.java.StringTypeDescriptor; import org.hibernate.type.descriptor.sql.VarcharTypeDescriptor; import org.hibernate.usertype.CompositeUserType; import org.hibernate.usertype.UserType; /** - * TODO : javadoc - * * @author Steve Ebersole */ -public class BasicTypeRegistryTest extends TestCase { +public class BasicTypeRegistryTest extends BaseUnitTestCase { private final BasicTypeRegistry registry = new BasicTypeRegistry(); + @Test public void testOverriding() { BasicType type = registry.getRegisteredType( "uuid-binary" ); assertSame( UUIDBinaryType.INSTANCE, type ); @@ -61,6 +68,7 @@ public class BasicTypeRegistryTest extends TestCase { assertSame( override, type ); } + @Test public void testExpanding() { BasicType type = registry.getRegisteredType( SomeNoopType.INSTANCE.getName() ); assertNull( type ); @@ -71,6 +79,7 @@ public class BasicTypeRegistryTest extends TestCase { assertSame( SomeNoopType.INSTANCE, type ); } + @Test public void testRegisteringUserTypes() { registry.register( new TotallyIrrelevantUserType(), new String[] { "key" } ); BasicType type = registry.getRegisteredType( "key" ); diff --git a/hibernate-core/src/test/java/org/hibernate/type/TypeTest.java b/hibernate-core/src/test/java/org/hibernate/type/TypeTest.java index 4ae83309b7..a7c2239577 100644 --- a/hibernate-core/src/test/java/org/hibernate/type/TypeTest.java +++ b/hibernate-core/src/test/java/org/hibernate/type/TypeTest.java @@ -36,19 +36,45 @@ import java.util.GregorianCalendar; import java.util.Locale; import java.util.SimpleTimeZone; import java.util.TimeZone; -import junit.framework.TestCase; + +import org.junit.Before; +import org.junit.Test; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + import org.hibernate.EntityMode; import org.hibernate.Session; import org.hibernate.engine.SessionImplementor; import org.hibernate.internal.util.collections.ArrayHelper; import org.hibernate.internal.util.SerializationHelper; +import org.hibernate.testing.junit4.BaseUnitTestCase; /** - * TODO : javadoc - * * @author Steve Ebersole */ -public class TypeTest extends TestCase { +@SuppressWarnings( {"UnnecessaryBoxing"}) +public class TypeTest extends BaseUnitTestCase { + private SessionImplementor session; + + @Before + public void setUp() throws Exception { + session = (SessionImplementor) Proxy.newProxyInstance( + getClass().getClassLoader(), + new Class[] { Session.class, SessionImplementor.class }, + new SessionProxyHandler() + ); + } + + public static class SessionProxyHandler implements InvocationHandler { + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + if ( "getEntityMode".equals( method.getName() ) ) { + return EntityMode.POJO; + } + throw new UnsupportedOperationException( "Unexpected method call : " + method.getName() ); + } + } + + @Test public void testBigDecimalType() { final BigDecimal original = BigDecimal.valueOf( 100 ); final BigDecimal copy = BigDecimal.valueOf( 100 ); @@ -57,6 +83,7 @@ public class TypeTest extends TestCase { runBasicTests( BigDecimalType.INSTANCE, original, copy, different ); } + @Test public void testBigIntegerType() { final BigInteger original = BigInteger.valueOf( 100 ); final BigInteger copy = BigInteger.valueOf( 100 ); @@ -65,6 +92,7 @@ public class TypeTest extends TestCase { runBasicTests( BigIntegerType.INSTANCE, original, copy, different ); } + @Test public void testBinaryType() { final byte[] original = new byte[] { 1, 2, 3, 4 }; final byte[] copy = new byte[] { 1, 2, 3, 4 }; @@ -75,6 +103,8 @@ public class TypeTest extends TestCase { runBasicTests( MaterializedBlobType.INSTANCE, original, copy, different ); } + @Test + @SuppressWarnings( {"BooleanConstructorCall"}) public void testBooleanType() { final Boolean original = Boolean.TRUE; final Boolean copy = new Boolean( true ); @@ -86,6 +116,7 @@ public class TypeTest extends TestCase { runBasicTests( TrueFalseType.INSTANCE, original, copy, different ); } + @Test public void testByteType() { final Byte original = 0; final Byte copy = new Byte( (byte) 0 ); @@ -94,6 +125,7 @@ public class TypeTest extends TestCase { runBasicTests( ByteType.INSTANCE, original, copy, different ); } + @Test public void testCalendarDateType() { final Calendar original = new GregorianCalendar(); final Calendar copy = new GregorianCalendar(); @@ -105,6 +137,7 @@ public class TypeTest extends TestCase { runBasicTests( CalendarDateType.INSTANCE, original, copy, different ); } + @Test public void testCalendarType() { final long now = System.currentTimeMillis(); final Calendar original = new GregorianCalendar(); @@ -119,6 +152,7 @@ public class TypeTest extends TestCase { runBasicTests( CalendarType.INSTANCE, original, copy, different ); } + @Test public void testCharacterArrayType() { final Character[] original = new Character[] { 'a', 'b' }; final Character[] copy = new Character[] { 'a', 'b' }; @@ -127,6 +161,7 @@ public class TypeTest extends TestCase { runBasicTests( CharacterArrayType.INSTANCE, original, copy, different ); } + @Test public void testCharacterType() { final Character original = 'a'; final Character copy = new Character( 'a' ); @@ -135,6 +170,7 @@ public class TypeTest extends TestCase { runBasicTests( CharacterType.INSTANCE, original, copy, different ); } + @Test public void testCharArrayType() { final char[] original = new char[] { 'a', 'b' }; final char[] copy = new char[] { 'a', 'b' }; @@ -144,14 +180,16 @@ public class TypeTest extends TestCase { runBasicTests( CharArrayType.INSTANCE, original, copy, different ); } + @Test public void testClassType() { final Class original = TypeTest.class; final Class copy = (Class) SerializationHelper.clone( original ); - final Class different = TestCase.class; + final Class different = String.class; runBasicTests( ClassType.INSTANCE, original, copy, different ); } + @Test public void testCurrencyType() { final Currency original = Currency.getInstance( Locale.US ); final Currency copy = Currency.getInstance( Locale.US ); @@ -160,6 +198,7 @@ public class TypeTest extends TestCase { runBasicTests( CurrencyType.INSTANCE, original, copy, different ); } + @Test public void testDateType() { final long now = System.currentTimeMillis(); final java.sql.Date original = new java.sql.Date( now ); @@ -173,6 +212,7 @@ public class TypeTest extends TestCase { runBasicTests( DateType.INSTANCE, original, copy, different ); } + @Test public void testDoubleType() { final Double original = Double.valueOf( 100 ); final Double copy = Double.valueOf( 100 ); @@ -181,6 +221,7 @@ public class TypeTest extends TestCase { runBasicTests( DoubleType.INSTANCE, original, copy, different ); } + @Test public void testFloatType() { final Float original = Float.valueOf( 100 ); final Float copy = Float.valueOf( 100 ); @@ -189,6 +230,7 @@ public class TypeTest extends TestCase { runBasicTests( FloatType.INSTANCE, original, copy, different ); } + @Test public void testIntegerType() { final Integer original = 100; final Integer copy = new Integer( 100 ); @@ -197,6 +239,7 @@ public class TypeTest extends TestCase { runBasicTests( IntegerType.INSTANCE, original, copy, different ); } + @Test public void testLocaleType() { final Locale original = new Locale( "ab" ); final Locale copy = new Locale( "ab" ); @@ -205,6 +248,7 @@ public class TypeTest extends TestCase { runBasicTests( LocaleType.INSTANCE, original, copy, different ); } + @Test public void testLongType() { final Long original = 100L; final Long copy = new Long( 100L ); @@ -218,10 +262,13 @@ public class TypeTest extends TestCase { SerializableImpl(int number) { this.number = number; } + @SuppressWarnings( {"EqualsWhichDoesntCheckParameterClass"}) public boolean equals(Object obj) { return this.number == ( (SerializableImpl) obj ).number; } } + + @Test public void testSerializableType() { final SerializableImpl original = new SerializableImpl(1); final SerializableImpl copy = new SerializableImpl(1); @@ -231,6 +278,7 @@ public class TypeTest extends TestCase { runBasicTests( new SerializableType( SerializableImpl.class ), original, copy, different ); } + @Test public void testShortType() { final Short original = 100; final Short copy = new Short( (short) 100 ); @@ -239,6 +287,7 @@ public class TypeTest extends TestCase { runBasicTests( ShortType.INSTANCE, original, copy, different ); } + @Test public void testStringType() { final String original = "abc"; final String copy = new String( original.toCharArray() ); @@ -249,6 +298,7 @@ public class TypeTest extends TestCase { runBasicTests( MaterializedClobType.INSTANCE, original, copy, different ); } + @Test public void testTimestampType() { final long now = System.currentTimeMillis(); final Timestamp original = new Timestamp( now ); @@ -258,6 +308,7 @@ public class TypeTest extends TestCase { runBasicTests( TimestampType.INSTANCE, original, copy, different ); } + @Test public void testTimeType() { final long now = System.currentTimeMillis(); final Time original = new Time( now ); @@ -267,6 +318,7 @@ public class TypeTest extends TestCase { runBasicTests( TimeType.INSTANCE, original, copy, different ); } + @Test public void testDates() { final long now = System.currentTimeMillis(); final java.util.Date original = new java.util.Date( now ); @@ -279,6 +331,7 @@ public class TypeTest extends TestCase { runBasicTests( DateType.INSTANCE, original, copy, different2 ); } + @Test public void testTimeZoneType() { final TimeZone original = new SimpleTimeZone( -1, "abc" ); final TimeZone copy = new SimpleTimeZone( -1, "abc" ); @@ -287,11 +340,8 @@ public class TypeTest extends TestCase { runBasicTests( TimeZoneType.INSTANCE, original, copy, different ); } - - protected void runBasicTests(AbstractSingleColumnStandardBasicType type, T original, T copy, T different) { - final boolean nonCopyable = Class.class.isInstance( original ) - || Currency.class.isInstance( original ); + final boolean nonCopyable = Class.class.isInstance( original ) || Currency.class.isInstance( original ); if ( ! nonCopyable ) { // these checks exclude classes which cannot really be cloned (singetons/enums) assertFalse( original == copy ); @@ -324,23 +374,4 @@ public class TypeTest extends TestCase { assertTrue( type.isModified( original, different, ArrayHelper.TRUE, session ) ); } - private SessionImplementor session; - - @Override - protected void setUp() throws Exception { - session = (SessionImplementor) Proxy.newProxyInstance( - getClass().getClassLoader(), - new Class[] { Session.class, SessionImplementor.class }, - new SessionProxyHandler() - ); - } - - public static class SessionProxyHandler implements InvocationHandler { - public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { - if ( "getEntityMode".equals( method.getName() ) ) { - return EntityMode.POJO; - } - throw new UnsupportedOperationException( "Unexpected method call : " + method.getName() ); - } - } } diff --git a/hibernate-core/src/test/java/org/hibernate/type/descriptor/java/AbstractDescriptorTest.java b/hibernate-core/src/test/java/org/hibernate/type/descriptor/java/AbstractDescriptorTest.java index dff80e51ec..5f4aaee97c 100644 --- a/hibernate-core/src/test/java/org/hibernate/type/descriptor/java/AbstractDescriptorTest.java +++ b/hibernate-core/src/test/java/org/hibernate/type/descriptor/java/AbstractDescriptorTest.java @@ -25,14 +25,18 @@ package org.hibernate.type.descriptor.java; import java.io.Serializable; import java.sql.Blob; import java.sql.Clob; -import junit.framework.TestCase; + +import org.junit.Before; +import org.junit.Test; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import org.hibernate.testing.junit4.BaseUnitTestCase; /** - * TODO : javadoc - * * @author Steve Ebersole */ -public abstract class AbstractDescriptorTest extends TestCase { +public abstract class AbstractDescriptorTest extends BaseUnitTestCase { protected class Data { private final T originalValue; private final T copyOfOriginalValue; @@ -53,9 +57,8 @@ public abstract class AbstractDescriptorTest extends TestCase { private Data testData; - @Override - protected void setUp() throws Exception { - super.setUp(); + @Before + public void setUp() throws Exception { testData = getTestData(); } @@ -63,6 +66,7 @@ public abstract class AbstractDescriptorTest extends TestCase { protected abstract boolean shouldBeMutable(); + @Test public void testEquality() { assertFalse( testData.originalValue == testData.copyOfOriginalValue ); assertTrue( typeDescriptor.areEqual( testData.originalValue, testData.originalValue ) ); @@ -70,6 +74,7 @@ public abstract class AbstractDescriptorTest extends TestCase { assertFalse( typeDescriptor.areEqual( testData.originalValue, testData.differentValue ) ); } + @Test public void testExternalization() { // ensure the symmetry of toString/fromString String externalized = typeDescriptor.toString( testData.originalValue ); @@ -77,6 +82,7 @@ public abstract class AbstractDescriptorTest extends TestCase { assertTrue( typeDescriptor.areEqual( testData.originalValue, consumed ) ); } + @Test public void testMutabilityPlan() { assertTrue( shouldBeMutable() == typeDescriptor.getMutabilityPlan().isMutable() ); diff --git a/hibernate-core/src/test/java/org/hibernate/type/descriptor/java/BigDecimalDescriptorTest.java b/hibernate-core/src/test/java/org/hibernate/type/descriptor/java/BigDecimalDescriptorTest.java index 44cbcf4514..c3924ffadd 100644 --- a/hibernate-core/src/test/java/org/hibernate/type/descriptor/java/BigDecimalDescriptorTest.java +++ b/hibernate-core/src/test/java/org/hibernate/type/descriptor/java/BigDecimalDescriptorTest.java @@ -25,8 +25,6 @@ package org.hibernate.type.descriptor.java; import java.math.BigDecimal; /** - * TODO : javadoc - * * @author Steve Ebersole */ public class BigDecimalDescriptorTest extends AbstractDescriptorTest { diff --git a/hibernate-core/src/test/java/org/hibernate/type/descriptor/java/BigIntegerDescriptorTest.java b/hibernate-core/src/test/java/org/hibernate/type/descriptor/java/BigIntegerDescriptorTest.java index ed2b54aff2..fceb752037 100644 --- a/hibernate-core/src/test/java/org/hibernate/type/descriptor/java/BigIntegerDescriptorTest.java +++ b/hibernate-core/src/test/java/org/hibernate/type/descriptor/java/BigIntegerDescriptorTest.java @@ -25,8 +25,6 @@ package org.hibernate.type.descriptor.java; import java.math.BigInteger; /** - * TODO : javadoc - * * @author Steve Ebersole */ public class BigIntegerDescriptorTest extends AbstractDescriptorTest { diff --git a/hibernate-core/src/test/java/org/hibernate/type/descriptor/java/BlobDescriptorTest.java b/hibernate-core/src/test/java/org/hibernate/type/descriptor/java/BlobDescriptorTest.java index b612bddeb8..243f9fdbd6 100644 --- a/hibernate-core/src/test/java/org/hibernate/type/descriptor/java/BlobDescriptorTest.java +++ b/hibernate-core/src/test/java/org/hibernate/type/descriptor/java/BlobDescriptorTest.java @@ -24,11 +24,15 @@ package org.hibernate.type.descriptor.java; import java.sql.Blob; import java.sql.SQLException; + +import org.junit.Test; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + import org.hibernate.engine.jdbc.BlobProxy; /** - * TODO : javadoc - * * @author Steve Ebersole */ public class BlobDescriptorTest extends AbstractDescriptorTest { @@ -50,6 +54,7 @@ public class BlobDescriptorTest extends AbstractDescriptorTest { return false; } + @Test @Override public void testEquality() { // blobs of the same internal value are not really comparable @@ -59,6 +64,7 @@ public class BlobDescriptorTest extends AbstractDescriptorTest { assertFalse( BlobTypeDescriptor.INSTANCE.areEqual( original, different ) ); } + @Test @Override public void testExternalization() { // blobs of the same internal value are not really comparable diff --git a/hibernate-core/src/test/java/org/hibernate/type/descriptor/java/BooleanDescriptorTest.java b/hibernate-core/src/test/java/org/hibernate/type/descriptor/java/BooleanDescriptorTest.java index 416a2119f8..15cb04dd24 100644 --- a/hibernate-core/src/test/java/org/hibernate/type/descriptor/java/BooleanDescriptorTest.java +++ b/hibernate-core/src/test/java/org/hibernate/type/descriptor/java/BooleanDescriptorTest.java @@ -25,8 +25,6 @@ package org.hibernate.type.descriptor.java; /** - * TODO : javadoc - * * @author Steve Ebersole */ public class BooleanDescriptorTest extends AbstractDescriptorTest { diff --git a/hibernate-core/src/test/java/org/hibernate/type/descriptor/java/StringDescriptorTest.java b/hibernate-core/src/test/java/org/hibernate/type/descriptor/java/StringDescriptorTest.java index 6235b6a301..496358865c 100644 --- a/hibernate-core/src/test/java/org/hibernate/type/descriptor/java/StringDescriptorTest.java +++ b/hibernate-core/src/test/java/org/hibernate/type/descriptor/java/StringDescriptorTest.java @@ -25,8 +25,6 @@ package org.hibernate.type.descriptor.java; /** - * TODO : javadoc - * * @author Steve Ebersole */ public class StringDescriptorTest extends AbstractDescriptorTest { diff --git a/hibernate-core/src/test/java/org/hibernate/type/descriptor/sql/StringValueMappingTest.java b/hibernate-core/src/test/java/org/hibernate/type/descriptor/sql/StringValueMappingTest.java index 85a29cc881..8c3972a593 100644 --- a/hibernate-core/src/test/java/org/hibernate/type/descriptor/sql/StringValueMappingTest.java +++ b/hibernate-core/src/test/java/org/hibernate/type/descriptor/sql/StringValueMappingTest.java @@ -26,20 +26,23 @@ import java.sql.Clob; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; -import junit.framework.TestCase; + +import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + import org.hibernate.engine.jdbc.LobCreator; import org.hibernate.engine.jdbc.NonContextualLobCreator; +import org.hibernate.testing.junit4.BaseUnitTestCase; import org.hibernate.type.descriptor.ValueBinder; import org.hibernate.type.descriptor.ValueExtractor; import org.hibernate.type.descriptor.WrapperOptions; import org.hibernate.type.descriptor.java.StringTypeDescriptor; /** - * TODO : javadoc - * * @author Steve Ebersole */ -public class StringValueMappingTest extends TestCase { +public class StringValueMappingTest extends BaseUnitTestCase { private final StringTypeDescriptor stringJavaDescriptor = new StringTypeDescriptor(); private final VarcharTypeDescriptor varcharSqlDescriptor = new VarcharTypeDescriptor(); @@ -62,6 +65,7 @@ public class StringValueMappingTest extends TestCase { public static final String COLUMN_NAME = "n/a"; public static final int BIND_POSITION = -1; + @Test public void testNormalVarcharHandling() throws SQLException { final ValueExtractor extractor = varcharSqlDescriptor.getExtractor( stringJavaDescriptor ); final ValueBinder binder = varcharSqlDescriptor.getBinder( stringJavaDescriptor ); @@ -76,6 +80,7 @@ public class StringValueMappingTest extends TestCase { binder.bind( ps, fixture, BIND_POSITION, wrapperOptions ); } + @Test public void testNullVarcharHandling() throws SQLException { final ValueExtractor extractor = varcharSqlDescriptor.getExtractor( stringJavaDescriptor ); final ValueBinder binder = varcharSqlDescriptor.getBinder( stringJavaDescriptor ); @@ -90,6 +95,7 @@ public class StringValueMappingTest extends TestCase { binder.bind( ps, fixture, BIND_POSITION, wrapperOptions ); } + @Test public void testNormalClobHandling() throws SQLException { final ValueExtractor extractor = clobSqlDescriptor.getExtractor( stringJavaDescriptor ); final ValueBinder binder = clobSqlDescriptor.getBinder( stringJavaDescriptor ); @@ -105,6 +111,7 @@ public class StringValueMappingTest extends TestCase { binder.bind( ps, fixture, BIND_POSITION, wrapperOptions ); } + @Test public void testNullClobHandling() throws SQLException { final ValueExtractor extractor = clobSqlDescriptor.getExtractor( stringJavaDescriptor ); final ValueBinder binder = clobSqlDescriptor.getBinder( stringJavaDescriptor ); diff --git a/hibernate-core/src/test/java/org/hibernate/util/SerializableThing.java b/hibernate-core/src/test/java/org/hibernate/util/SerializableThing.java index 98da337629..ef446503de 100644 --- a/hibernate-core/src/test/java/org/hibernate/util/SerializableThing.java +++ b/hibernate-core/src/test/java/org/hibernate/util/SerializableThing.java @@ -25,8 +25,6 @@ package org.hibernate.util; import java.io.Serializable; /** - * TODO : javadoc - * * @author Steve Ebersole */ public class SerializableThing implements Serializable { diff --git a/hibernate-core/src/test/java/org/hibernate/util/SerializationHelperTest.java b/hibernate-core/src/test/java/org/hibernate/util/SerializationHelperTest.java index a5c5920892..a69f22ad50 100644 --- a/hibernate-core/src/test/java/org/hibernate/util/SerializationHelperTest.java +++ b/hibernate-core/src/test/java/org/hibernate/util/SerializationHelperTest.java @@ -24,10 +24,17 @@ package org.hibernate.util; import java.io.InputStream; import java.io.Serializable; -import junit.framework.TestCase; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertSame; + import org.hibernate.LockMode; import org.hibernate.bytecode.util.ByteCodeHelper; import org.hibernate.internal.util.SerializationHelper; +import org.hibernate.testing.junit4.BaseUnitTestCase; /** * This is basically a test to assert the expectations of {@link org.hibernate.type.SerializableType} @@ -35,21 +42,23 @@ import org.hibernate.internal.util.SerializationHelper; * * @author Steve Ebersole */ -public class SerializationHelperTest extends TestCase { +public class SerializationHelperTest extends BaseUnitTestCase { private ClassLoader original; private CustomClassLoader custom; - protected void setUp() throws Exception { + @Before + public void setUp() throws Exception { original = Thread.currentThread().getContextClassLoader(); custom = new CustomClassLoader( original ); Thread.currentThread().setContextClassLoader( custom ); - } - protected void tearDown() throws Exception { + @After + public void tearDown() throws Exception { Thread.currentThread().setContextClassLoader( original ); } + @Test public void testSerializeDeserialize() throws Exception { Class clazz = Thread.currentThread().getContextClassLoader().loadClass( "org.hibernate.util.SerializableThing" ); Object instance = clazz.newInstance(); diff --git a/hibernate-core/src/test/java/org/hibernate/util/StringHelperTest.java b/hibernate-core/src/test/java/org/hibernate/util/StringHelperTest.java index 240acd8db8..b872b4de6c 100644 --- a/hibernate-core/src/test/java/org/hibernate/util/StringHelperTest.java +++ b/hibernate-core/src/test/java/org/hibernate/util/StringHelperTest.java @@ -1,8 +1,10 @@ /* - * Copyright (c) 2009, Red Hat Middleware LLC or third-party contributors as + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2009-2011, Red Hat Inc. or third-party contributors as * indicated by the @author tags or express copyright attribution * statements applied by the authors. All third-party contributions are - * distributed under license by Red Hat Middleware LLC. + * distributed under license by Red Hat Inc. * * This copyrighted material is made available to anyone wishing to use, modify, * copy, or redistribute it subject to the terms and conditions of the GNU @@ -20,32 +22,37 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.util; -import junit.framework.TestCase; + +import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; import org.hibernate.internal.util.StringHelper; +import org.hibernate.testing.junit4.BaseUnitTestCase; /** - * TODO : javadoc - * * @author Steve Ebersole */ -public class StringHelperTest extends TestCase { +public class StringHelperTest extends BaseUnitTestCase { private static final String BASE_PACKAGE = "org.hibernate"; private static final String STRING_HELPER_FQN = "org.hibernate.internal.util.StringHelper"; private static final String STRING_HELPER_NAME = StringHelper.unqualify( STRING_HELPER_FQN ); + @Test public void testNameCollapsing() { assertNull( StringHelper.collapse( null ) ); assertEquals( STRING_HELPER_NAME, StringHelper.collapse( STRING_HELPER_NAME ) ); assertEquals( "o.h.i.u.StringHelper", StringHelper.collapse( STRING_HELPER_FQN ) ); } + @Test public void testPartialNameUnqualification() { assertNull( StringHelper.partiallyUnqualify( null, BASE_PACKAGE ) ); assertEquals( STRING_HELPER_NAME, StringHelper.partiallyUnqualify( STRING_HELPER_NAME, BASE_PACKAGE ) ); assertEquals( "internal.util.StringHelper", StringHelper.partiallyUnqualify( STRING_HELPER_FQN, BASE_PACKAGE ) ); } + @Test public void testBasePackageCollapsing() { assertNull( StringHelper.collapseQualifierBase( null, BASE_PACKAGE ) ); assertEquals( STRING_HELPER_NAME, StringHelper.collapseQualifierBase( STRING_HELPER_NAME, BASE_PACKAGE ) ); diff --git a/hibernate-ehcache/hibernate-ehcache.gradle b/hibernate-ehcache/hibernate-ehcache.gradle index 2dc20638b1..cad959dafb 100644 --- a/hibernate-ehcache/hibernate-ehcache.gradle +++ b/hibernate-ehcache/hibernate-ehcache.gradle @@ -3,5 +3,5 @@ dependencies { compile( project( ':hibernate-core' ) ) compile( [group: 'net.sf.ehcache', name: 'ehcache-core', version: '2.3.1'] ) - testCompile( project(':hibernate-core').sourceSets.test.classes ) + testCompile( project(':hibernate-testing') ) } diff --git a/hibernate-core/src/test/java/org/hibernate/testing/cache/BaseCacheProviderTestCase.java b/hibernate-ehcache/src/test/java/org/hibernate/cache/BaseCacheProviderTestCase.java similarity index 98% rename from hibernate-core/src/test/java/org/hibernate/testing/cache/BaseCacheProviderTestCase.java rename to hibernate-ehcache/src/test/java/org/hibernate/cache/BaseCacheProviderTestCase.java index 61cd155a43..29f858bc3a 100644 --- a/hibernate-core/src/test/java/org/hibernate/testing/cache/BaseCacheProviderTestCase.java +++ b/hibernate-ehcache/src/test/java/org/hibernate/cache/BaseCacheProviderTestCase.java @@ -21,12 +21,11 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.testing.cache; +package org.hibernate.cache; import java.util.Map; import org.hibernate.Session; import org.hibernate.Transaction; -import org.hibernate.cache.ReadWriteCache; import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Environment; import org.hibernate.engine.transaction.internal.jdbc.JdbcTransactionFactory; @@ -43,7 +42,7 @@ import org.hibernate.testing.tm.TransactionManagerLookupImpl; */ public abstract class BaseCacheProviderTestCase extends FunctionalTestCase { - // note that a lot of the fucntionality here is intended to be used + // note that a lot of the functionality here is intended to be used // in creating specific tests for each CacheProvider that would extend // from a base test case (this) for common requirement testing... diff --git a/hibernate-ehcache/src/test/java/org/hibernate/cache/EhCacheTest.java b/hibernate-ehcache/src/test/java/org/hibernate/cache/EhCacheTest.java index 539cbe45f7..2a229dfceb 100644 --- a/hibernate-ehcache/src/test/java/org/hibernate/cache/EhCacheTest.java +++ b/hibernate-ehcache/src/test/java/org/hibernate/cache/EhCacheTest.java @@ -21,10 +21,9 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.cache; +package org.hibernate.cache; import junit.framework.Test; import org.hibernate.cfg.Environment; -import org.hibernate.testing.cache.BaseCacheProviderTestCase; import org.hibernate.testing.junit.functional.FunctionalTestClassTestSuite; /** diff --git a/hibernate-core/src/test/java/org/hibernate/testing/cache/Item.hbm.xml b/hibernate-ehcache/src/test/java/org/hibernate/cache/Item.hbm.xml similarity index 100% rename from hibernate-core/src/test/java/org/hibernate/testing/cache/Item.hbm.xml rename to hibernate-ehcache/src/test/java/org/hibernate/cache/Item.hbm.xml diff --git a/hibernate-core/src/test/java/org/hibernate/testing/cache/Item.java b/hibernate-ehcache/src/test/java/org/hibernate/cache/Item.java similarity index 97% rename from hibernate-core/src/test/java/org/hibernate/testing/cache/Item.java rename to hibernate-ehcache/src/test/java/org/hibernate/cache/Item.java index acac04b062..3052474bd8 100755 --- a/hibernate-core/src/test/java/org/hibernate/testing/cache/Item.java +++ b/hibernate-ehcache/src/test/java/org/hibernate/cache/Item.java @@ -21,7 +21,7 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.testing.cache; +package org.hibernate.cache; /** diff --git a/hibernate-core/src/test/java/org/hibernate/testing/cache/VersionedItem.java b/hibernate-ehcache/src/test/java/org/hibernate/cache/VersionedItem.java similarity index 97% rename from hibernate-core/src/test/java/org/hibernate/testing/cache/VersionedItem.java rename to hibernate-ehcache/src/test/java/org/hibernate/cache/VersionedItem.java index 013b6f3e2a..89dc0417b4 100644 --- a/hibernate-core/src/test/java/org/hibernate/testing/cache/VersionedItem.java +++ b/hibernate-ehcache/src/test/java/org/hibernate/cache/VersionedItem.java @@ -21,8 +21,7 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.testing.cache; - +package org.hibernate.cache; /** * @author Steve Ebersole diff --git a/hibernate-entitymanager/hibernate-entitymanager.gradle b/hibernate-entitymanager/hibernate-entitymanager.gradle index ec3c256a46..b6a8946f37 100644 --- a/hibernate-entitymanager/hibernate-entitymanager.gradle +++ b/hibernate-entitymanager/hibernate-entitymanager.gradle @@ -11,7 +11,7 @@ dependencies { compile( libraries.jpa ) compile( libraries.jta ) compile( libraries.javassist ) - testCompile( project(':hibernate-core').sourceSets.test.classes ) + testCompile( project(':hibernate-testing') ) testCompile( libraries.junit ) testCompile( libraries.shrinkwrap_api ) testCompile( libraries.shrinkwrap ) diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/cacheable/annotation/ConfigurationTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/cacheable/annotation/ConfigurationTest.java index c9af19971f..03ff90b5f1 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/cacheable/annotation/ConfigurationTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/cacheable/annotation/ConfigurationTest.java @@ -22,26 +22,29 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.ejb.test.cacheable.annotation; -import java.util.Properties; + import javax.persistence.SharedCacheMode; +import java.util.Properties; + import org.hibernate.cache.access.AccessType; import org.hibernate.cache.impl.NoCachingRegionFactory; import org.hibernate.cfg.Environment; import org.hibernate.ejb.AvailableSettings; import org.hibernate.ejb.Ejb3Configuration; import org.hibernate.mapping.PersistentClass; -import org.hibernate.testing.junit.UnitTestCase; + +import org.junit.Test; + +import org.hibernate.testing.junit4.BaseUnitTestCase; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; /** - * TODO : javadoc - * * @author Steve Ebersole */ -public class ConfigurationTest extends UnitTestCase { - public ConfigurationTest(String string) { - super( string ); - } - +public class ConfigurationTest extends BaseUnitTestCase { + @Test public void testSharedCacheModeNone() { Ejb3Configuration config = buildConfiguration( SharedCacheMode.NONE ); @@ -55,6 +58,7 @@ public class ConfigurationTest extends UnitTestCase { assertNull( pc.getCacheConcurrencyStrategy() ); } + @Test public void testSharedCacheModeUnspecified() { Ejb3Configuration config = buildConfiguration( SharedCacheMode.UNSPECIFIED ); @@ -68,6 +72,7 @@ public class ConfigurationTest extends UnitTestCase { assertNull( pc.getCacheConcurrencyStrategy() ); } + @Test public void testSharedCacheModeAll() { Ejb3Configuration config = buildConfiguration( SharedCacheMode.ALL ); @@ -81,6 +86,7 @@ public class ConfigurationTest extends UnitTestCase { assertNotNull( pc.getCacheConcurrencyStrategy() ); } + @Test public void testSharedCacheModeEnable() { Ejb3Configuration config = buildConfiguration( SharedCacheMode.ENABLE_SELECTIVE ); @@ -94,6 +100,7 @@ public class ConfigurationTest extends UnitTestCase { assertNull( pc.getCacheConcurrencyStrategy() ); } + @Test public void testSharedCacheModeDisable() { Ejb3Configuration config = buildConfiguration( SharedCacheMode.DISABLE_SELECTIVE ); diff --git a/hibernate-envers/hibernate-envers.gradle b/hibernate-envers/hibernate-envers.gradle index f67eca22e5..18a5b9bd4c 100644 --- a/hibernate-envers/hibernate-envers.gradle +++ b/hibernate-envers/hibernate-envers.gradle @@ -12,7 +12,7 @@ dependencies { } compile( libraries.ant ) testCompile( libraries.testng ) - testCompile( project(':hibernate-core').sourceSets.test.classes ) + testCompile( project(':hibernate-testing') ) testCompile( libraries.jpa ) testRuntime( libraries.h2 ) testRuntime( libraries.javassist ) diff --git a/hibernate-proxool/hibernate-proxool.gradle b/hibernate-proxool/hibernate-proxool.gradle index 1727fe9103..61c48fc20e 100644 --- a/hibernate-proxool/hibernate-proxool.gradle +++ b/hibernate-proxool/hibernate-proxool.gradle @@ -3,6 +3,6 @@ apply plugin: 'java' dependencies { compile( project( ':hibernate-core' ) ) compile( [group: 'proxool', name: 'proxool', version: '0.8.3'] ) - testCompile( project(':hibernate-core').sourceSets.test.classes ) + testCompile( project(':hibernate-testing') ) testRuntime( libraries.h2 ) } diff --git a/hibernate-testing/hibernate-testing.gradle b/hibernate-testing/hibernate-testing.gradle new file mode 100644 index 0000000000..40cc895d66 --- /dev/null +++ b/hibernate-testing/hibernate-testing.gradle @@ -0,0 +1,6 @@ +apply plugin: 'java' + +dependencies { + compile( project( ':hibernate-core' ) ) + compile( [group: 'junit', name: 'junit', version: '4.8.2'] ) +} \ No newline at end of file diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/AfterClassOnce.java b/hibernate-testing/src/main/java/org/hibernate/testing/AfterClassOnce.java new file mode 100644 index 0000000000..5385816a21 --- /dev/null +++ b/hibernate-testing/src/main/java/org/hibernate/testing/AfterClassOnce.java @@ -0,0 +1,41 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package org.hibernate.testing; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Annotation used to mark a method which should be run once after the last + * test execution for the given class. Much like JUnit's own {@link org.junit.AfterClass}, + * except this annotation need not be attached to a static method + * + * @author Steve Ebersole + */ +@Retention(RetentionPolicy.RUNTIME) +@Target({ ElementType.METHOD, ElementType.TYPE }) +public @interface AfterClassOnce { +} diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/BeforeClassOnce.java b/hibernate-testing/src/main/java/org/hibernate/testing/BeforeClassOnce.java new file mode 100644 index 0000000000..c573fd3fdc --- /dev/null +++ b/hibernate-testing/src/main/java/org/hibernate/testing/BeforeClassOnce.java @@ -0,0 +1,42 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package org.hibernate.testing; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Annotation used to mark a method which should be run once before the first + * test execution for the given class. Much like JUnit's own {@link org.junit.BeforeClass}, + * except this annotation need not be attached to a static method + * + * @author Steve Ebersole + */ +@Retention(RetentionPolicy.RUNTIME) +@Target({ ElementType.METHOD, ElementType.TYPE }) +public @interface BeforeClassOnce { +} + diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/FailureExpected.java b/hibernate-testing/src/main/java/org/hibernate/testing/FailureExpected.java new file mode 100644 index 0000000000..eed621a4ce --- /dev/null +++ b/hibernate-testing/src/main/java/org/hibernate/testing/FailureExpected.java @@ -0,0 +1,51 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package org.hibernate.testing; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Annotation used to mark a test as an expected failure. + * + * @author Hardy Ferentschik + * @author Steve Ebersole + */ +@Retention(RetentionPolicy.RUNTIME) +@Target({ ElementType.METHOD, ElementType.TYPE }) +public @interface FailureExpected { + /** + * The key of a JIRA issue which covers this expected failure. + * @return The jira issue key + */ + String jiraKey(); + + /** + * A message explaining the reason for the expected failure. Optional. + * @return The reason + */ + String message() default ""; +} diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/OnExpectedFailure.java b/hibernate-testing/src/main/java/org/hibernate/testing/OnExpectedFailure.java new file mode 100644 index 0000000000..9457c07366 --- /dev/null +++ b/hibernate-testing/src/main/java/org/hibernate/testing/OnExpectedFailure.java @@ -0,0 +1,40 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package org.hibernate.testing; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Annotation used to identify a method as a callback to be executed whenever a {@link FailureExpected} is handled. + * + * @author Steve Ebersole + * @see + */ +@Retention( RetentionPolicy.RUNTIME ) +@Target( ElementType.METHOD ) +public @interface OnExpectedFailure { +} diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/OnFailure.java b/hibernate-testing/src/main/java/org/hibernate/testing/OnFailure.java new file mode 100644 index 0000000000..a87c40489c --- /dev/null +++ b/hibernate-testing/src/main/java/org/hibernate/testing/OnFailure.java @@ -0,0 +1,39 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package org.hibernate.testing; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Annotation used to identify a method as a callback to be executed on test failures. + * + * @author Steve Ebersole + */ +@Retention( RetentionPolicy.RUNTIME ) +@Target( ElementType.METHOD ) +public @interface OnFailure { +} diff --git a/hibernate-core/src/test/java/org/hibernate/testing/ServiceRegistryBuilder.java b/hibernate-testing/src/main/java/org/hibernate/testing/ServiceRegistryBuilder.java similarity index 93% rename from hibernate-core/src/test/java/org/hibernate/testing/ServiceRegistryBuilder.java rename to hibernate-testing/src/main/java/org/hibernate/testing/ServiceRegistryBuilder.java index ae29b096ac..b773ebd7c3 100644 --- a/hibernate-core/src/test/java/org/hibernate/testing/ServiceRegistryBuilder.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/ServiceRegistryBuilder.java @@ -23,17 +23,22 @@ */ package org.hibernate.testing; -import java.util.Map; -import java.util.Properties; import org.hibernate.cfg.Environment; import org.hibernate.internal.util.config.ConfigurationHelper; import org.hibernate.service.internal.ServiceRegistryImpl; import org.hibernate.service.spi.ServiceRegistry; +import java.util.Map; +import java.util.Properties; + /** * @author Steve Ebersole */ public class ServiceRegistryBuilder { + public static ServiceRegistryImpl buildServiceRegistry() { + return buildServiceRegistry( Environment.getProperties() ); + } + public static ServiceRegistryImpl buildServiceRegistry(Map serviceRegistryConfig) { Properties properties = new Properties(); properties.putAll( serviceRegistryConfig ); diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/Skip.java b/hibernate-testing/src/main/java/org/hibernate/testing/Skip.java new file mode 100644 index 0000000000..aaaddce469 --- /dev/null +++ b/hibernate-testing/src/main/java/org/hibernate/testing/Skip.java @@ -0,0 +1,64 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package org.hibernate.testing; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * An annotation, used in combination with {@link Matcher}, to determine when/if tests should be skipped. + * + * @author Steve Ebersole + */ +@Retention( RetentionPolicy.RUNTIME ) +@Target({ ElementType.METHOD, ElementType.TYPE }) +public @interface Skip { + /** + * Simple boolean assertion + */ + public static interface Matcher { + /** + * Do we have a match to the underlying condition? + * + * @return True/false ;) + */ + public boolean isMatch(); + } + + /** + * The condition which causes a skip + * + * @return The condition + */ + Class condition(); + + /** + * A message describing the reason for the skip + * + * @return Descriptive message + */ + String message(); +} diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/TestForIssue.java b/hibernate-testing/src/main/java/org/hibernate/testing/TestForIssue.java new file mode 100644 index 0000000000..d8cf1286eb --- /dev/null +++ b/hibernate-testing/src/main/java/org/hibernate/testing/TestForIssue.java @@ -0,0 +1,44 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package org.hibernate.testing; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * A documentation annotation for notating what JIRA issue is being tested. + * + * @author Steve Ebersole + */ +@Retention(RetentionPolicy.RUNTIME) +@Target({ ElementType.METHOD, ElementType.TYPE }) +public @interface TestForIssue { + /** + * The key of a JIRA issue tested. + * @return The jira issue key + */ + String jiraKey(); +} diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseCoreFunctionalTestCase.java b/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseCoreFunctionalTestCase.java new file mode 100644 index 0000000000..047aa50e32 --- /dev/null +++ b/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseCoreFunctionalTestCase.java @@ -0,0 +1,144 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package org.hibernate.testing.junit4; + +import org.hibernate.cfg.Configuration; +import org.hibernate.cfg.Environment; +import org.hibernate.engine.SessionFactoryImplementor; +import org.hibernate.internal.util.config.ConfigurationHelper; +import org.hibernate.service.internal.ServiceRegistryImpl; +import org.hibernate.testing.AfterClassOnce; +import org.hibernate.testing.BeforeClassOnce; +import org.hibernate.testing.OnExpectedFailure; +import org.hibernate.testing.OnFailure; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Properties; + +/** + * Applies functional testing logic for core Hibernate testing on top of {@link BaseUnitTestCase} + * + * @author Steve Ebersole + */ +public class BaseCoreFunctionalTestCase extends BaseUnitTestCase { + private static final Logger log = LoggerFactory.getLogger( BaseCoreFunctionalTestCase.class ); + + private static Configuration configuration; + private static ServiceRegistryImpl serviceRegistry; + private static SessionFactoryImplementor sessionFactory; + + public static Configuration getConfiguration() { + return configuration; + } + + public static SessionFactoryImplementor getSessionFactory() { + return sessionFactory; + } + + @BeforeClassOnce + private void buildSessionFactory() { + log.trace( "Building session factory" ); + configuration = buildConfiguration(); + serviceRegistry = buildServiceRegistry( configuration ); + sessionFactory = (SessionFactoryImplementor) configuration.buildSessionFactory( serviceRegistry ); + afterSessionFactoryBuilt(); + } + + protected Configuration buildConfiguration() { + Configuration cfg = constructConfiguration(); + configure( cfg ); + addMappings( cfg ); + cfg.buildMappings(); + afterConfigurationBuilt( cfg ); + return cfg; + } + + protected Configuration constructConfiguration() { + return new Configuration(); + } + + protected void configure(Configuration cfg) { + } + + protected void addMappings(Configuration cfg) { + } + + protected void afterConfigurationBuilt(Configuration configuration) { + } + + protected ServiceRegistryImpl buildServiceRegistry(Configuration configuration) { + Properties properties = new Properties(); + properties.putAll( configuration.getProperties() ); + Environment.verifyProperties( properties ); + ConfigurationHelper.resolvePlaceHolders( properties ); + ServiceRegistryImpl serviceRegistry = new ServiceRegistryImpl( properties ); + applyServices( serviceRegistry ); + return serviceRegistry; + } + + protected void applyServices(ServiceRegistryImpl serviceRegistry) { + } + + protected void afterSessionFactoryBuilt() { + } + + protected boolean rebuildSessionFactoryOnError() { + return true; + } + + @AfterClassOnce + private void releaseSessionFactory() { + if ( sessionFactory == null ) { + return; + } + log.trace( "Releasing session factory" ); + sessionFactory.close(); + sessionFactory = null; + configuration = null; + } + + @OnFailure + @OnExpectedFailure + public void onFailure() { + log.trace( "Processing failure-expected ignore" ); + if ( ! rebuildSessionFactoryOnError() ) { + return; + } + + rebuildSessionFactory(); + } + + protected void rebuildSessionFactory() { + if ( sessionFactory == null ) { + return; + } + sessionFactory.close(); + serviceRegistry.destroy(); + + serviceRegistry = buildServiceRegistry( configuration ); + sessionFactory = (SessionFactoryImplementor) configuration.buildSessionFactory( serviceRegistry ); + afterSessionFactoryBuilt(); + } +} diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseUnitTestCase.java b/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseUnitTestCase.java new file mode 100644 index 0000000000..31cfd49039 --- /dev/null +++ b/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseUnitTestCase.java @@ -0,0 +1,38 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package org.hibernate.testing.junit4; + +import org.junit.Rule; +import org.junit.runner.RunWith; + +/** + * The most test adapter. Applies both the {@link CustomRunner} and {@link Processor} rule. + * + * @author Steve Ebersole + */ +@RunWith( CustomRunner.class ) +public abstract class BaseUnitTestCase { + @Rule + public Processor processor = new Processor(); +} diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/junit4/CallbackException.java b/hibernate-testing/src/main/java/org/hibernate/testing/junit4/CallbackException.java new file mode 100644 index 0000000000..24fad231d0 --- /dev/null +++ b/hibernate-testing/src/main/java/org/hibernate/testing/junit4/CallbackException.java @@ -0,0 +1,49 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package org.hibernate.testing.junit4; + +import java.lang.reflect.Method; + +/** + * Indicates an exception while performing a callback on the test + * + * @author Steve Ebersole + */ +public class CallbackException extends RuntimeException { + public CallbackException(Method method) { + this( Helper.extractMethodName( method ) ); + } + + public CallbackException(String message) { + super( message ); + } + + public CallbackException(Method method, Throwable cause) { + this( Helper.extractMethodName( method ), cause ); + } + + public CallbackException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/junit4/CustomRunner.java b/hibernate-testing/src/main/java/org/hibernate/testing/junit4/CustomRunner.java new file mode 100644 index 0000000000..0b1e948fb5 --- /dev/null +++ b/hibernate-testing/src/main/java/org/hibernate/testing/junit4/CustomRunner.java @@ -0,0 +1,123 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package org.hibernate.testing.junit4; + +import org.junit.runner.manipulation.NoTestsRemainException; +import org.junit.runners.BlockJUnit4ClassRunner; +import org.junit.runners.model.FrameworkMethod; +import org.junit.runners.model.InitializationError; + +import org.hibernate.testing.FailureExpected; +import org.hibernate.testing.Skip; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.List; + +/** + * The Hibernate-specific {@link org.junit.runner.Runner} implementation which layers {@link ExtendedFrameworkMethod} + * support on top of the standard JUnit {@link FrameworkMethod} for extra information after checking to make sure the + * test should be run. + * + * @author Steve Ebersole + * @see Processor + */ +public class CustomRunner extends BlockJUnit4ClassRunner { + private static final Logger log = LoggerFactory.getLogger( CustomRunner.class ); + + private List computedTestMethods; + + public CustomRunner(Class clazz) throws InitializationError, NoTestsRemainException { + super( clazz ); + } + + public List getComputedTestMethods() { + return computedTestMethods; + } + + public int getNumberOfComputedTestMethods() { + return getComputedTestMethods().size(); + } + + @Override + protected List computeTestMethods() { + if ( computedTestMethods == null ) { + computedTestMethods = doComputation(); + } + return computedTestMethods; + } + + protected List doComputation() { + // First, build the callback metadata for the test class... + TestClassCallbackMetadata callbackMetadata = new TestClassCallbackMetadata( getTestClass().getJavaClass() ); + + // Next, get all the test methods as understood by JUnit + final List methods = super.computeTestMethods(); + + // Now process that full list of test methods and build our custom result + final List result = new ArrayList(); + final boolean doValidation = Boolean.getBoolean( Helper.VALIDATE_FAILURE_EXPECTED ); + int testCount = 0; + + for ( FrameworkMethod frameworkMethod : methods ) { + // potentially ignore based on expected failure + final FailureExpected failureExpected = Helper.locateFailureExpectedAnnotation( frameworkMethod ); + if ( failureExpected != null && !doValidation ) { + log.info( Helper.extractIgnoreMessage( failureExpected, frameworkMethod ) ); + continue; + } + + // next, check specific exclusions + final Skip skip = Helper.locateSkipAnnotation( frameworkMethod ); + if ( skip != null ) { + if ( isMatch( skip.condition() ) ) { + log.info( Helper.extractIgnoreMessage( skip, frameworkMethod ) ); + continue; + } + } + + testCount++; + log.trace( "adding test " + Helper.extractTestName( frameworkMethod ) + " [#" + testCount + "]" ); + result.add( new ExtendedFrameworkMethod( frameworkMethod, failureExpected, callbackMetadata, this ) ); + } + return result; + } + + private boolean isMatch(Class condition) { + try { + Skip.Matcher matcher = condition.newInstance(); + return matcher.isMatch(); + } + catch (Exception e) { + throw new MatcherInstantiationException( condition, e ); + } + } + + private static class MatcherInstantiationException extends RuntimeException { + private MatcherInstantiationException(Class matcherClass, Throwable cause) { + super( "Unable to instantiate specified Matcher [" + matcherClass.getName(), cause ); + } + } +} diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/junit4/ExtendedFrameworkMethod.java b/hibernate-testing/src/main/java/org/hibernate/testing/junit4/ExtendedFrameworkMethod.java new file mode 100644 index 0000000000..35c469216b --- /dev/null +++ b/hibernate-testing/src/main/java/org/hibernate/testing/junit4/ExtendedFrameworkMethod.java @@ -0,0 +1,128 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package org.hibernate.testing.junit4; + +import org.hibernate.testing.FailureExpected; +import org.junit.runners.model.FrameworkMethod; + +import java.lang.annotation.Annotation; +import java.lang.reflect.Method; +import java.util.List; + +/** + * Defines an extension to the standard JUnit {@link FrameworkMethod} information about a test method. + * + * @author Steve Ebersole + */ +public class ExtendedFrameworkMethod extends FrameworkMethod { + private static final Object[] NO_ARGS = new Object[0]; + + private final FrameworkMethod delegatee; + private final FailureExpected failureExpectedAnnotation; + private final TestClassCallbackMetadata callbackMetadata; + private final CustomRunner unitRunner; + + public ExtendedFrameworkMethod( + FrameworkMethod delegatee, + FailureExpected failureExpectedAnnotation, + TestClassCallbackMetadata callbackMetadata, + CustomRunner unitRunner) { + super( delegatee.getMethod() ); + this.delegatee = delegatee; + this.failureExpectedAnnotation = failureExpectedAnnotation; + this.callbackMetadata = callbackMetadata; + this.unitRunner = unitRunner; + } + + public CustomRunner getUnitRunner() { + return unitRunner; + } + + public boolean isMarkedAsFailureExpected() { + return failureExpectedAnnotation != null; + } + + public FailureExpected getFailureExpectedAnnotation() { + return failureExpectedAnnotation; + } + + public TestClassCallbackMetadata getCallbackMetadata() { + return callbackMetadata; + } + + @Override + public Method getMethod() { + return delegatee.getMethod(); + } + + @Override + public Object invokeExplosively(Object target, Object... params) throws Throwable { + return delegatee.invokeExplosively( target, params ); + } + + @Override + public String getName() { + return delegatee.getName(); + } + + @Override + public void validatePublicVoidNoArg(boolean isStatic, List errors) { + delegatee.validatePublicVoidNoArg( isStatic, errors ); + } + + @Override + public void validatePublicVoid(boolean isStatic, List errors) { + delegatee.validatePublicVoid( isStatic, errors ); + } + + @Override + public boolean isShadowedBy(FrameworkMethod other) { + return delegatee.isShadowedBy( other ); + } + + @Override + public boolean equals(Object obj) { + return delegatee.equals( obj ); + } + + @Override + public int hashCode() { + return delegatee.hashCode(); + } + + @Override + public boolean producesType(Class type) { + return delegatee.producesType( type ); + } + + @Override + public Annotation[] getAnnotations() { + return delegatee.getAnnotations(); + } + + @Override + public T getAnnotation(Class annotationType) { + return delegatee.getAnnotation( annotationType ); + } +} diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/junit4/Helper.java b/hibernate-testing/src/main/java/org/hibernate/testing/junit4/Helper.java new file mode 100644 index 0000000000..a13eaf8595 --- /dev/null +++ b/hibernate-testing/src/main/java/org/hibernate/testing/junit4/Helper.java @@ -0,0 +1,113 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package org.hibernate.testing.junit4; + +import org.junit.runners.model.FrameworkMethod; + +import org.hibernate.testing.FailureExpected; +import org.hibernate.testing.Skip; + +import java.lang.reflect.Method; + +/** + * Centralized utility functionality + * + * @author Steve Ebersole + */ +public class Helper { + public static final String VALIDATE_FAILURE_EXPECTED = "hibernate.test.validatefailureexpected"; + + + /** + * Standard string content checking. + * + * @param string The string to check + * @return Are its content empty or the reference null? + */ + public static boolean isNotEmpty(String string) { + return string != null && string.length() > 0; + } + + /** + * Extract a nice test name representation for display + * + * @param frameworkMethod The test method. + * @return The display representation + */ + public static String extractTestName(FrameworkMethod frameworkMethod) { + return frameworkMethod.getMethod().getDeclaringClass().getName() + '#' + frameworkMethod.getName(); + } + + /** + * Extract a nice method name representation for display + * + * @param method The method. + * @return The display representation + */ + public static String extractMethodName(Method method) { + return method.getDeclaringClass().getName() + "#" + method.getName(); + } + + public static FailureExpected locateFailureExpectedAnnotation(FrameworkMethod frameworkMethod) { + FailureExpected failureExpected = frameworkMethod.getAnnotation( FailureExpected.class ); + if ( failureExpected == null ) { + failureExpected = frameworkMethod.getMethod().getDeclaringClass().getAnnotation( FailureExpected.class ); + } + return failureExpected; + } + + public static Skip locateSkipAnnotation(FrameworkMethod frameworkMethod) { + Skip skip = frameworkMethod.getAnnotation( Skip.class ); + if ( skip == null ) { + skip = frameworkMethod.getMethod().getDeclaringClass().getAnnotation( Skip.class ); + } + return skip; + } + + public static String extractMessage(FailureExpected failureExpected) { + StringBuilder buffer = new StringBuilder(); + buffer.append( '(' ).append( failureExpected.jiraKey() ).append( ')' ); + if ( isNotEmpty( failureExpected.message() ) ) { + buffer.append( " : " ).append( failureExpected.message() ); + } + return buffer.toString(); + } + + public static String extractIgnoreMessage(FailureExpected failureExpected, FrameworkMethod frameworkMethod) { + return new StringBuilder( "Not adding test [" ) + .append( Helper.extractTestName( frameworkMethod ) ) + .append( "] due to @FailureExpected - " ) + .append( extractMessage( failureExpected ) ) + .toString(); + } + + public static String extractIgnoreMessage(Skip skip, FrameworkMethod frameworkMethod) { + return new StringBuilder( "Not adding test [" ) + .append( Helper.extractTestName( frameworkMethod ) ) + .append( "] due to @Skip - " ) + .append( skip.message() ) + .toString(); + } + +} diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/junit4/InvalidMethodForAnnotationException.java b/hibernate-testing/src/main/java/org/hibernate/testing/junit4/InvalidMethodForAnnotationException.java new file mode 100644 index 0000000000..3c99d43eb5 --- /dev/null +++ b/hibernate-testing/src/main/java/org/hibernate/testing/junit4/InvalidMethodForAnnotationException.java @@ -0,0 +1,40 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package org.hibernate.testing.junit4; + + +/** + * Indicates that an annotations was attached to a method incorrectly. + * + * @author Steve Ebersole + */ +public class InvalidMethodForAnnotationException extends RuntimeException { + public InvalidMethodForAnnotationException(String message) { + super( message ); + } + + public InvalidMethodForAnnotationException(String message, Throwable cause) { + super( message, cause ); + } +} diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/junit4/Processor.java b/hibernate-testing/src/main/java/org/hibernate/testing/junit4/Processor.java new file mode 100644 index 0000000000..65fdd2a7bd --- /dev/null +++ b/hibernate-testing/src/main/java/org/hibernate/testing/junit4/Processor.java @@ -0,0 +1,112 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package org.hibernate.testing.junit4; + +import org.junit.rules.MethodRule; +import org.junit.runners.model.FrameworkMethod; +import org.junit.runners.model.Statement; + +import org.hibernate.testing.FailureExpected; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * A custom JUnit {@link MethodRule} which essentially acts as "around advice" for test method execution. Works + * in conjunction with the information collected as part of {@link CustomRunner}. + * + * @author Steve Ebersole + * @see CustomRunner + */ +public class Processor implements MethodRule { + private static final Logger log = LoggerFactory.getLogger( Processor.class ); + + private int runPosition = 0; + + public Statement apply(final Statement statement, final FrameworkMethod frameworkMethod, final Object target) { + log.trace( "Preparing to start test {}", Helper.extractTestName( frameworkMethod ) ); + if ( ! ExtendedFrameworkMethod.class.isInstance( frameworkMethod ) ) { + throw new IllegalStateException( + "Use of " + getClass().getName() + " only supported in combination with use of " + + CustomRunner.class.getName() + ); + } + + final ExtendedFrameworkMethod extendedFrameworkMethod = (ExtendedFrameworkMethod) frameworkMethod; + + runPosition++; + final boolean isFirst = runPosition == 1; + final boolean isLast = runPosition > extendedFrameworkMethod.getUnitRunner().getNumberOfComputedTestMethods(); + + final FailureExpected failureExpected = extendedFrameworkMethod.getFailureExpectedAnnotation(); + + return new Statement() { + @Override + public void evaluate() throws Throwable { + if ( isFirst ) { + extendedFrameworkMethod.getCallbackMetadata().performBeforeClassCallbacks( target ); + } + try { + statement.evaluate(); + // reaching here is expected, unless the test is marked as an expected failure + if ( failureExpected != null ) { + throw new FailureExpectedTestPassedException( extendedFrameworkMethod ); + } + } + catch ( FailureExpectedTestPassedException e ) { + // just pass this along + throw e; + } + catch ( Throwable e ) { + // on error handling is very different based on whether the test was marked as an expected failure + if ( failureExpected != null ) { + // handle the expected failure case + log.info( + "Ignoring expected failure [{}] : {}", + Helper.extractTestName( frameworkMethod ), + Helper.extractMessage( failureExpected ) + ); + extendedFrameworkMethod.getCallbackMetadata().performOnExpectedFailureCallback( target ); + // most importantly, do not propagate exception... + } + else { + // handle the non-expected failure case + extendedFrameworkMethod.getCallbackMetadata().performOnFailureCallback( target ); + throw e; + } + } + finally { + if ( isLast ) { + extendedFrameworkMethod.getCallbackMetadata().performAfterClassCallbacks( target ); + } + } + } + }; + } + + public static class FailureExpectedTestPassedException extends Exception { + public FailureExpectedTestPassedException(FrameworkMethod frameworkMethod) { + super( "Test marked as FailureExpected, but did not fail : " + Helper.extractTestName( frameworkMethod ) ); + } + } +} diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/junit4/TestClassCallbackMetadata.java b/hibernate-testing/src/main/java/org/hibernate/testing/junit4/TestClassCallbackMetadata.java new file mode 100644 index 0000000000..da2d7c8a29 --- /dev/null +++ b/hibernate-testing/src/main/java/org/hibernate/testing/junit4/TestClassCallbackMetadata.java @@ -0,0 +1,178 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package org.hibernate.testing.junit4; + +import org.hibernate.testing.AfterClassOnce; +import org.hibernate.testing.BeforeClassOnce; +import org.hibernate.testing.OnExpectedFailure; +import org.hibernate.testing.OnFailure; + +import java.lang.annotation.Annotation; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.LinkedHashSet; + +/** + * Metadata about various types of callback methods on a given test class. + * + * @author Steve Ebersole + */ +public class TestClassCallbackMetadata { + private static final Object[] NO_ARGS = new Object[0]; + + private LinkedHashSet beforeClassOnceMethods; + private LinkedHashSet afterClassOnceMethods; + private LinkedHashSet onFailureCallbacks; + private LinkedHashSet onExpectedFailureCallbacks; + + public TestClassCallbackMetadata(Class testClass) { + processClassHierarchy( testClass ); + } + + private void processClassHierarchy(Class testClass) { + // NOTE recursive on itself + for ( Method method : testClass.getDeclaredMethods() ) { + if ( method.getAnnotation( CallbackType.BEFORE_CLASS_ONCE.annotationClass ) != null ) { + addBeforeClassOnceCallback( method ); + } + if ( method.getAnnotation( CallbackType.AFTER_CLASS_ONCE.annotationClass ) != null ) { + addAfterClassOnceCallback( method ); + } + if ( method.getAnnotation( CallbackType.ON_FAILURE.annotationClass ) != null ) { + addOnFailureCallback( method ); + } + if ( method.getAnnotation( CallbackType.ON_EXPECTED_FAILURE.annotationClass ) != null ) { + addOnExpectedFailureCallback( method ); + } + } + + Class superClass = testClass.getSuperclass(); + if ( superClass != null ) { + processClassHierarchy( superClass ); + } + } + + private static enum CallbackType { + BEFORE_CLASS_ONCE( BeforeClassOnce.class ), + AFTER_CLASS_ONCE( AfterClassOnce.class ), + ON_FAILURE( OnFailure.class ), + ON_EXPECTED_FAILURE( OnExpectedFailure.class ); + + private final Class annotationClass; + + private CallbackType(Class annotationClass) { + this.annotationClass = annotationClass; + } + + public Class getAnnotationClass() { + return annotationClass; + } + + public String buildTypeMarker() { + return "@" + getAnnotationClass().getSimpleName(); + } + } + + private void addBeforeClassOnceCallback(Method method) { + validateCallbackMethod( method, CallbackType.BEFORE_CLASS_ONCE ); + beforeClassOnceMethods = new LinkedHashSet(); + beforeClassOnceMethods.add( method ); + } + + private void validateCallbackMethod(Method method, CallbackType type) { + if ( method.getParameterTypes().length > 0 ) { + throw new InvalidMethodForAnnotationException( + type.buildTypeMarker() + " callback only valid on no-arg methods : " + + Helper.extractMethodName( method ) + ); + } + if ( !method.isAccessible() ) { + try { + method.setAccessible( true ); + } + catch (Exception e) { + throw new InvalidMethodForAnnotationException( + type.buildTypeMarker() + " attached to inaccessible method and unable to make accessible" + ); + } + } + } + + private void addAfterClassOnceCallback(Method method) { + validateCallbackMethod( method, TestClassCallbackMetadata.CallbackType.AFTER_CLASS_ONCE ); + afterClassOnceMethods = new LinkedHashSet(); + afterClassOnceMethods.add( method ); + } + + private void addOnFailureCallback(Method method) { + validateCallbackMethod( method, TestClassCallbackMetadata.CallbackType.ON_FAILURE ); + onFailureCallbacks = new LinkedHashSet(); + onFailureCallbacks.add( method ); + } + + private void addOnExpectedFailureCallback(Method method) { + validateCallbackMethod( method, TestClassCallbackMetadata.CallbackType.ON_EXPECTED_FAILURE ); + onExpectedFailureCallbacks = new LinkedHashSet(); + onExpectedFailureCallbacks.add( method ); + } + + + public void performBeforeClassCallbacks(Object target) { + performCallbacks( beforeClassOnceMethods, target ); + } + + private void performCallbacks(LinkedHashSet callbackMethods, Object target) { + if ( callbackMethods == null ) { + return; + } + + for ( Method callbackMethod : callbackMethods ) { + invokeCallback( callbackMethod, target ); + } + } + + private void invokeCallback(Method callback, Object target) { + try { + callback.invoke( target, NO_ARGS ); + } + catch (InvocationTargetException e) { + throw new CallbackException( callback, e.getTargetException() ); + } + catch (IllegalAccessException e) { + throw new CallbackException( callback, e ); + } + } + + public void performAfterClassCallbacks(Object target) { + performCallbacks( afterClassOnceMethods, target ); + } + + public void performOnFailureCallback(Object target) { + performCallbacks( onFailureCallbacks, target ); + } + + public void performOnExpectedFailureCallback(Object target) { + performCallbacks( onExpectedFailureCallbacks, target ); + } +} diff --git a/hibernate-testing/src/test/java/org/hibernate/testing/junit4/FailureExpectedTest.java b/hibernate-testing/src/test/java/org/hibernate/testing/junit4/FailureExpectedTest.java new file mode 100644 index 0000000000..efcace7e45 --- /dev/null +++ b/hibernate-testing/src/test/java/org/hibernate/testing/junit4/FailureExpectedTest.java @@ -0,0 +1,107 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package org.hibernate.testing.junit4; + +import org.junit.Test; +import org.junit.runner.JUnitCore; +import org.junit.runner.Result; + +import org.hibernate.testing.FailureExpected; +import org.hibernate.testing.OnExpectedFailure; +import org.hibernate.testing.OnFailure; + +import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.assertTrue; + +/** + * @author Steve Ebersole + */ +public class FailureExpectedTest { + private static int onFailureCount = 0; + + @Test + public void testWithoutValidation() { + onFailureCount = 0; + Result result = JUnitCore.runClasses( FixtureTests.class ); + assertEquals( 3, result.getRunCount() ); + assertEquals( 2, result.getFailureCount() ); + assertEquals( 2, onFailureCount ); + assertEquals( 0, result.getIgnoreCount() ); + } + + @Test + public void testWithValidation() { + onFailureCount = 0; + String original = System.getProperty( Helper.VALIDATE_FAILURE_EXPECTED ); + System.setProperty( Helper.VALIDATE_FAILURE_EXPECTED, "true" ); + try { + Result result = JUnitCore.runClasses( FixtureTests.class ); + assertEquals( 5, result.getRunCount() ); + assertEquals( 3, result.getFailureCount() ); + assertEquals( 3, onFailureCount ); + assertEquals( 0, result.getIgnoreCount() ); + } + finally { + if ( original == null ) { + System.getProperties().remove( Helper.VALIDATE_FAILURE_EXPECTED ); + } + else { + System.setProperty( Helper.VALIDATE_FAILURE_EXPECTED, original ); + } + } + } + + public static class FixtureTests extends BaseUnitTestCase { + @Test + public void control() { + } + + @Test + public void failureControl() { + assertTrue( false ); + } + + @Test + public void exceptionControl() { + throw new RuntimeException(); + } + + @Test + @FailureExpected( jiraKey = "n/a" ) + public void correctlyDefinedFailureExcepted() { + throw new RuntimeException(); + } + + @Test + @FailureExpected( jiraKey = "n/a" ) + public void incorrectlyDefinedFailureExcepted() { + } + + @OnFailure + @OnExpectedFailure + void handleError() { + onFailureCount++; + } + } +} diff --git a/hibernate-testing/src/test/java/org/hibernate/testing/junit4/FunctionalTestCaseTest.java b/hibernate-testing/src/test/java/org/hibernate/testing/junit4/FunctionalTestCaseTest.java new file mode 100644 index 0000000000..bc1451444d --- /dev/null +++ b/hibernate-testing/src/test/java/org/hibernate/testing/junit4/FunctionalTestCaseTest.java @@ -0,0 +1,85 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package org.hibernate.testing.junit4; + +import org.junit.Test; +import org.junit.runner.JUnitCore; +import org.junit.runner.Result; + +import org.hibernate.testing.FailureExpected; + +import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.assertNotNull; + +/** + * @author Steve Ebersole + */ +public class FunctionalTestCaseTest { + @Test + public void testWithoutValidation() { + Result result = JUnitCore.runClasses( FixtureTests.class ); + assertEquals( 1, result.getRunCount() ); + assertEquals( 0, result.getFailureCount() ); + assertEquals( 0, result.getIgnoreCount() ); + } + + @Test + public void testWithValidation() { + String original = System.getProperty( Helper.VALIDATE_FAILURE_EXPECTED ); + System.setProperty( Helper.VALIDATE_FAILURE_EXPECTED, "true" ); + try { + Result result = JUnitCore.runClasses( FixtureTests.class ); + assertEquals( 3, result.getRunCount() ); + assertEquals( 1, result.getFailureCount() ); + assertEquals( 0, result.getIgnoreCount() ); + } + finally { + if ( original == null ) { + System.getProperties().remove( Helper.VALIDATE_FAILURE_EXPECTED ); + } + else { + System.setProperty( Helper.VALIDATE_FAILURE_EXPECTED, original ); + } + } + } + + public static class FixtureTests extends BaseCoreFunctionalTestCase { + @Test + public void checkSessionFactoryAvailable() { + assertNotNull( getConfiguration() ); + assertNotNull( getSessionFactory() ); + } + + @Test + @FailureExpected( jiraKey = "n/a" ) + public void correctlyDefinedFailureExcepted() { + throw new RuntimeException(); + } + + @Test + @FailureExpected( jiraKey = "n/a" ) + public void incorrectlyDefinedFailureExcepted() { + } + } +} diff --git a/settings.gradle b/settings.gradle index 70fbf6d0ca..9cdf257915 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,4 +1,5 @@ include 'hibernate-core' +include 'hibernate-testing' include 'hibernate-entitymanager' include 'hibernate-envers'