HHH-5942 - Migrate to JUnit 4

This commit is contained in:
Steve Ebersole 2011-03-07 16:20:53 -06:00
parent 74df160f31
commit 03ada52204
109 changed files with 3046 additions and 1224 deletions

View File

@ -3,5 +3,5 @@ apply plugin: 'java'
dependencies { dependencies {
compile( project( ':hibernate-core' ) ) compile( project( ':hibernate-core' ) )
compile( [group: 'c3p0', name: 'c3p0', version: '0.9.1'] ) compile( [group: 'c3p0', name: 'c3p0', version: '0.9.1'] )
testCompile( project(':hibernate-core').sourceSets.test.classes ) testCompile( project(':hibernate-testing') )
} }

View File

@ -17,6 +17,7 @@ dependencies {
provided( libraries.ant ) provided( libraries.ant )
provided( libraries.jacc ) provided( libraries.jacc )
provided( libraries.validation ) provided( libraries.validation )
testCompile( project(':hibernate-testing') )
testCompile( libraries.validation ) testCompile( libraries.validation )
testCompile( libraries.validator ) { testCompile( libraries.validator ) {
// for test runtime // for test runtime

View File

@ -72,8 +72,8 @@ public class DialectFactoryImpl implements DialectFactory {
try { try {
return ( Dialect ) classLoaderService.classForName( dialectName ).newInstance(); return ( Dialect ) classLoaderService.classForName( dialectName ).newInstance();
} }
catch ( ClassLoadingException cnfe ) { catch ( ClassLoadingException e ) {
throw new HibernateException( "Dialect class not found: " + dialectName, cnfe ); throw new HibernateException( "Dialect class not found: " + dialectName, e );
} }
catch ( HibernateException e ) { catch ( HibernateException e ) {
throw e; throw e;

View File

@ -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; package org.hibernate;
import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment; import org.hibernate.cfg.Environment;
import org.hibernate.dialect.Dialect; import org.hibernate.dialect.Dialect;
import org.hibernate.dialect.H2Dialect; import org.hibernate.dialect.H2Dialect;
/** /**
* TODO : javadoc
*
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class TestingDatabaseInfo { public class TestingDatabaseInfo {

View File

@ -1,10 +1,10 @@
/* /*
* Hibernate, Relational Persistence for Idiomatic Java * 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 * indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are * 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, * 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 * copy, or redistribute it subject to the terms and conditions of the GNU
@ -20,7 +20,6 @@
* Free Software Foundation, Inc. * Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*
*/ */
package org.hibernate.cache; package org.hibernate.cache;
@ -28,10 +27,13 @@ import java.io.Serializable;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import junit.framework.TestCase;
import org.junit.Test;
import org.hibernate.EntityMode; import org.hibernate.EntityMode;
import org.hibernate.internal.util.SerializationHelper; import org.hibernate.internal.util.SerializationHelper;
import org.hibernate.internal.util.collections.ArrayHelper; import org.hibernate.internal.util.collections.ArrayHelper;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import org.hibernate.transform.AliasToBeanResultTransformer; import org.hibernate.transform.AliasToBeanResultTransformer;
import org.hibernate.transform.AliasToEntityMapResultTransformer; import org.hibernate.transform.AliasToEntityMapResultTransformer;
import org.hibernate.transform.AliasedTupleSubsetResultTransformer; import org.hibernate.transform.AliasedTupleSubsetResultTransformer;
@ -49,7 +51,7 @@ import org.hibernate.transform.TupleSubsetResultTransformer;
* *
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class QueryKeyTest extends TestCase { public class QueryKeyTest extends BaseUnitTestCase {
private static final String QUERY_STRING = "the query string"; private static final String QUERY_STRING = "the query string";
public static class AClass implements Serializable { public static class AClass implements Serializable {
@ -73,6 +75,7 @@ public class QueryKeyTest extends TestCase {
} }
} }
@Test
public void testSerializedEqualityResultTransformer() throws Exception { public void testSerializedEqualityResultTransformer() throws Exception {
// settings are lazily initialized when calling transformTuple(), // settings are lazily initialized when calling transformTuple(),
// so they have not been initialized for the following test // 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"; assert transformer.equals( transformer2 ): "deep copy issue";
} }
@Test
public void testSerializedEquality() throws Exception { public void testSerializedEquality() throws Exception {
doTest( buildBasicKey( null ) ); 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 } ) ) ); doTest( buildBasicKey( CacheableResultTransformer.create( null, new String[] { "a", null }, new boolean[] { true, true } ) ) );
} }
@Test
public void testSerializedEqualityWithTupleSubsetResultTransfprmer() throws Exception { public void testSerializedEqualityWithTupleSubsetResultTransfprmer() throws Exception {
doTestWithTupleSubsetResultTransformer( doTestWithTupleSubsetResultTransformer(
new AliasToBeanResultTransformer( AClass.class ), new AliasToBeanResultTransformer( AClass.class ),

View File

@ -1,10 +1,10 @@
/* /*
* Hibernate, Relational Persistence for Idiomatic Java * 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 * indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are * 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, * 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 * copy, or redistribute it subject to the terms and conditions of the GNU
@ -20,20 +20,21 @@
* Free Software Foundation, Inc. * Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*
*/ */
package org.hibernate.connection; package org.hibernate.connection;
import java.util.Properties; 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.service.jdbc.connections.internal.ConnectionProviderInitiator;
import org.hibernate.testing.junit4.BaseUnitTestCase;
/** /**
* Undocumented
*
* @author kbow * @author kbow
*/ */
public class PropertiesTest extends BaseUnitTestCase {
public class PropertiesTest extends TestCase { @Test
public void testProperties() throws Exception { public void testProperties() throws Exception {
final Properties props = new Properties(); final Properties props = new Properties();
@ -46,8 +47,8 @@ public class PropertiesTest extends TestCase {
props.put("hibernate.connection.create", "true"); props.put("hibernate.connection.create", "true");
final Properties outputProps = ConnectionProviderInitiator.getConnectionProperties( props ); final Properties outputProps = ConnectionProviderInitiator.getConnectionProperties( props );
assertEquals(1, outputProps.size()); Assert.assertEquals( 1, outputProps.size() );
assertEquals("true", outputProps.get("create")); Assert.assertEquals( "true", outputProps.get( "create" ) );
} }
} }

View File

@ -22,14 +22,20 @@
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*/ */
package org.hibernate.dialect; 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 * @author Evan Leonard
*/ */
public class DerbyDialectTestCase extends TestCase { @TestForIssue( jiraKey = "HHH-3972" )
public class DerbyDialectTestCase extends BaseUnitTestCase {
private static class LocalDerbyDialect extends DerbyDialect { private static class LocalDerbyDialect extends DerbyDialect {
protected boolean isTenPointFiveReleaseOrNewer() { protected boolean isTenPointFiveReleaseOrNewer() {
@ -37,6 +43,7 @@ public class DerbyDialectTestCase extends TestCase {
} }
} }
@Test
public void testInsertLimitClause() { public void testInsertLimitClause() {
final int limit = 50; final int limit = 50;
final String input = "select * from tablename t where t.cat = 5"; final String input = "select * from tablename t where t.cat = 5";
@ -46,6 +53,7 @@ public class DerbyDialectTestCase extends TestCase {
assertEquals( expected, actual ); assertEquals( expected, actual );
} }
@Test
public void testInsertLimitWithOffsetClause() { public void testInsertLimitWithOffsetClause() {
final int limit = 50; final int limit = 50;
final int offset = 200; final int offset = 200;
@ -56,7 +64,7 @@ public class DerbyDialectTestCase extends TestCase {
assertEquals( expected, actual ); assertEquals( expected, actual );
} }
@Test
public void testInsertLimitWithForUpdateClause() { public void testInsertLimitWithForUpdateClause() {
final int limit = 50; final int limit = 50;
final int offset = 200; final int offset = 200;
@ -68,6 +76,7 @@ public class DerbyDialectTestCase extends TestCase {
assertEquals( expected, actual ); assertEquals( expected, actual );
} }
@Test
public void testInsertLimitWithWithClause() { public void testInsertLimitWithWithClause() {
final int limit = 50; final int limit = 50;
final int offset = 200; final int offset = 200;
@ -79,6 +88,7 @@ public class DerbyDialectTestCase extends TestCase {
assertEquals( expected, actual ); assertEquals( expected, actual );
} }
@Test
public void testInsertLimitWithForUpdateAndWithClauses() { public void testInsertLimitWithForUpdateAndWithClauses() {
final int limit = 50; final int limit = 50;
final int offset = 200; final int offset = 200;

View File

@ -1,10 +1,10 @@
/* /*
* Hibernate, Relational Persistence for Idiomatic Java * 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 * indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are * 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, * 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 * copy, or redistribute it subject to the terms and conditions of the GNU
@ -20,7 +20,6 @@
* Free Software Foundation, Inc. * Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*
*/ */
package org.hibernate.dialect; package org.hibernate.dialect;
import java.lang.reflect.InvocationHandler; import java.lang.reflect.InvocationHandler;
@ -31,10 +30,9 @@ import java.sql.DatabaseMetaData;
import java.sql.SQLException; import java.sql.SQLException;
/** /**
* TODO : javadoc
*
* @author Steve Ebersole * @author Steve Ebersole
*/ */
@SuppressWarnings( {"UnnecessaryBoxing"})
public class Mocks { public class Mocks {
public static Connection createConnection(String dbName, int version) { public static Connection createConnection(String dbName, int version) {
@ -77,7 +75,7 @@ public class Mocks {
} }
if ( "hashCode".equals( methodName ) ) { if ( "hashCode".equals( methodName ) ) {
return new Integer( this.hashCode() ); return Integer.valueOf( this.hashCode() );
} }
if ( canThrowSQLException( method ) ) { if ( canThrowSQLException( method ) ) {
@ -111,7 +109,7 @@ public class Mocks {
} }
if ( "getDatabaseMajorVersion".equals( methodName ) ) { if ( "getDatabaseMajorVersion".equals( methodName ) ) {
return new Integer( majorVersion ); return Integer.valueOf( majorVersion );
} }
if ( "getConnection".equals( methodName ) ) { if ( "getConnection".equals( methodName ) ) {
@ -137,8 +135,8 @@ public class Mocks {
private static boolean canThrowSQLException(Method method) { private static boolean canThrowSQLException(Method method) {
final Class[] exceptions = method.getExceptionTypes(); final Class[] exceptions = method.getExceptionTypes();
for ( int i = 0; i < exceptions.length; i++ ) { for ( Class exceptionType : exceptions ) {
if ( SQLException.class.isAssignableFrom( exceptions[i] ) ) { if ( SQLException.class.isAssignableFrom( exceptionType ) ) {
return true; return true;
} }
} }

View File

@ -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; 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 * Unit test of the behavior of the SQLServerDialect utility methods
* *
* @author Valotasion Yoryos * @author Valotasion Yoryos
*
*/ */
public class SQLServer2005DialectTestCase extends TestCase { public class SQLServer2005DialectTestCase extends BaseUnitTestCase {
@Test
public void testStripAliases() { public void testStripAliases() {
String input = "some_field1 as f1, some_fild2 as f2, _field3 as f3 "; String input = "some_field1 as f1, some_fild2 as f2, _field3 as f3 ";
assertEquals( "some_field1, some_fild2, _field3", SQLServer2005Dialect.stripAliases(input) ); assertEquals( "some_field1, some_fild2, _field3", SQLServer2005Dialect.stripAliases(input) );
} }
@Test
public void testGetSelectFieldsWithoutAliases() { public void testGetSelectFieldsWithoutAliases() {
StringBuilder input = new StringBuilder( "select some_field1 as f12, some_fild2 as f879, _field3 as _f24674_3 from...." ); StringBuilder input = new StringBuilder( "select some_field1 as f12, some_fild2 as f879, _field3 as _f24674_3 from...." );
String output = SQLServer2005Dialect.getSelectFieldsWithoutAliases( input ).toString(); String output = SQLServer2005Dialect.getSelectFieldsWithoutAliases( input ).toString();
@ -22,7 +51,7 @@ public class SQLServer2005DialectTestCase extends TestCase {
assertEquals( " some_field1, some_fild2, _field3", output ); assertEquals( " some_field1, some_fild2, _field3", output );
} }
@Test
public void testReplaceDistinctWithGroupBy() { public void testReplaceDistinctWithGroupBy() {
StringBuilder input = new StringBuilder( "select distinct f1, f2 as ff, f3 from table where f1 = 5" ); StringBuilder input = new StringBuilder( "select distinct f1, f2 as ff, f3 from table where f1 = 5" );
SQLServer2005Dialect.replaceDistinctWithGroupBy( input ); 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() ); assertEquals( "select f1, f2 as ff, f3 from table where f1 = 5 group by f1, f2, f3 ", input.toString() );
} }
@Test
public void testGetLimitString() { public void testGetLimitString() {
String input = "select distinct f1 as f53245 from table849752 order by f234, f67 desc"; String input = "select distinct f1 as f53245 from table849752 order by f234, f67 desc";

View File

@ -1,10 +1,10 @@
/* /*
* Hibernate, Relational Persistence for Idiomatic Java * 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 * indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are * 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, * 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 * copy, or redistribute it subject to the terms and conditions of the GNU
@ -20,7 +20,6 @@
* Free Software Foundation, Inc. * Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*
*/ */
package org.hibernate.dialect; package org.hibernate.dialect;
import java.sql.DatabaseMetaData; import java.sql.DatabaseMetaData;
@ -30,8 +29,6 @@ import org.hibernate.service.jdbc.dialect.internal.AbstractDialectResolver;
import org.hibernate.service.jdbc.dialect.internal.BasicDialectResolver; import org.hibernate.service.jdbc.dialect.internal.BasicDialectResolver;
/** /**
* TODO : javadoc
*
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class TestingDialects { public class TestingDialects {

View File

@ -1,10 +1,10 @@
/* /*
* Hibernate, Relational Persistence for Idiomatic Java * 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 * indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are * 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, * 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 * copy, or redistribute it subject to the terms and conditions of the GNU
@ -20,15 +20,15 @@
* Free Software Foundation, Inc. * Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*
*/ */
package org.hibernate.dialect.resolver; package org.hibernate.dialect.resolver;
import java.sql.Connection; import org.junit.Before;
import java.util.Properties; import org.junit.Test;
import junit.framework.Test; import static org.junit.Assert.assertEquals;
import junit.framework.TestCase; import static org.junit.Assert.assertNull;
import junit.framework.TestSuite; import static org.junit.Assert.fail;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.cfg.Environment; import org.hibernate.cfg.Environment;
import org.hibernate.dialect.DB2Dialect; import org.hibernate.dialect.DB2Dialect;
@ -47,73 +47,65 @@ import org.hibernate.dialect.SQLServerDialect;
import org.hibernate.dialect.SybaseASE15Dialect; import org.hibernate.dialect.SybaseASE15Dialect;
import org.hibernate.dialect.SybaseAnywhereDialect; import org.hibernate.dialect.SybaseAnywhereDialect;
import org.hibernate.dialect.TestingDialects; 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.DialectFactoryImpl;
import org.hibernate.service.jdbc.dialect.internal.DialectResolverSet; import org.hibernate.service.jdbc.dialect.internal.DialectResolverSet;
import org.hibernate.service.jdbc.dialect.internal.StandardDialectResolver; import org.hibernate.service.jdbc.dialect.internal.StandardDialectResolver;
import org.hibernate.service.jdbc.dialect.spi.DialectResolver; import org.hibernate.service.jdbc.dialect.spi.DialectResolver;
import org.hibernate.service.spi.ServiceRegistry; import org.hibernate.testing.junit4.BaseUnitTestCase;
import org.hibernate.testing.ServiceRegistryBuilder;
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 * @author Steve Ebersole
*/ */
public class DialectFactoryTest extends TestCase { public class DialectFactoryTest extends BaseUnitTestCase {
private ServiceRegistry serviceRegistry; private DialectFactoryImpl dialectFactory;
public DialectFactoryTest(String name) { @Before
super( name ); public void setUp() {
dialectFactory = new DialectFactoryImpl();
dialectFactory.setClassLoaderService( new ClassLoaderServiceImpl( getClass().getClassLoader() ) );
dialectFactory.setDialectResolver( new StandardDialectResolver() );
} }
@Override @Test
protected void setUp() { public void testExplicitlySuppliedDialectClassName() {
serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( Environment.getProperties() ); final Map<String,String> configValues = new HashMap<String,String>();
}
@Override configValues.put( Environment.DIALECT, "org.hibernate.dialect.HSQLDialect" );
protected void tearDown() { assertEquals( HSQLDialect.class, dialectFactory.buildDialect( configValues, null ).getClass() );
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.NoSuchDialect" );
try { try {
DialectFactory.constructDialect( "org.hibernate.dialect.NoSuchDialect" ); dialectFactory.buildDialect( configValues, null );
fail(); fail();
} }
catch ( HibernateException e ) { 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 { try {
DialectFactory.constructDialect( "java.lang.Object" ); dialectFactory.buildDialect( configValues, null );
fail(); fail();
} }
catch ( HibernateException e ) { 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() { public void testBuildDialectByProperties() {
Properties props = new Properties(); Properties props = new Properties();
try { try {
getDialectFactoryImpl( new StandardDialectResolver() ).buildDialect( props, null ); dialectFactory.buildDialect( props, null );
fail(); fail();
} }
catch ( HibernateException e ) { catch ( HibernateException e ) {
@ -121,16 +113,10 @@ public class DialectFactoryTest extends TestCase {
} }
props.setProperty( Environment.DIALECT, "org.hibernate.dialect.HSQLDialect" ); props.setProperty( Environment.DIALECT, "org.hibernate.dialect.HSQLDialect" );
assertTrue( getDialectFactoryImpl( new StandardDialectResolver() ).buildDialect( props, null ) instanceof HSQLDialect ); assertEquals( HSQLDialect.class, dialectFactory.buildDialect( props, null ).getClass() );
}
private DialectFactoryImpl getDialectFactoryImpl(DialectResolver dialectResolver) {
DialectFactoryImpl dialectFactoryImpl = new DialectFactoryImpl();
dialectFactoryImpl.setClassLoaderService( serviceRegistry.getService( ClassLoaderService.class ) );
dialectFactoryImpl.setDialectResolver( dialectResolver );
return dialectFactoryImpl;
} }
@Test
public void testPreregisteredDialects() { public void testPreregisteredDialects() {
DialectResolver resolver = new StandardDialectResolver(); DialectResolver resolver = new StandardDialectResolver();
testDetermination( "HSQL Database Engine", HSQLDialect.class, resolver ); testDetermination( "HSQL Database Engine", HSQLDialect.class, resolver );
@ -160,6 +146,7 @@ public class DialectFactoryTest extends TestCase {
testDetermination( "Oracle", 11, Oracle10gDialect.class, resolver ); testDetermination( "Oracle", 11, Oracle10gDialect.class, resolver );
} }
@Test
public void testCustomDialects() { public void testCustomDialects() {
DialectResolverSet resolvers = new DialectResolverSet(); DialectResolverSet resolvers = new DialectResolverSet();
resolvers.addResolver( new TestingDialects.MyDialectResolver1() ); resolvers.addResolver( new TestingDialects.MyDialectResolver1() );
@ -183,7 +170,6 @@ public class DialectFactoryTest extends TestCase {
fail(); fail();
} }
catch ( HibernateException e ) { catch ( HibernateException e ) {
// log.info( "Expected SQL error in resolveDialect and ignored", e );
} }
try { try {
@ -191,14 +177,14 @@ public class DialectFactoryTest extends TestCase {
fail(); fail();
} }
catch ( HibernateException e ) { catch ( HibernateException e ) {
// log.info( "Expected runtime error in resolveDialect", e );
} }
} }
@Test
public void testDialectNotFound() { public void testDialectNotFound() {
Properties properties = new Properties(); Map properties = Collections.EMPTY_MAP;
try { try {
getDialectFactoryImpl( new StandardDialectResolver() ).buildDialect( properties, Mocks.createConnection( "NoSuchDatabase", 666 ) ); dialectFactory.buildDialect( properties, Mocks.createConnection( "NoSuchDatabase", 666 ) );
fail(); fail();
} }
catch ( HibernateException e ) { catch ( HibernateException e ) {
@ -211,10 +197,9 @@ public class DialectFactoryTest extends TestCase {
} }
private void testDetermination(String databaseName, int databaseMajorVersion, Class clazz, DialectResolver resolver) { private void testDetermination(String databaseName, int databaseMajorVersion, Class clazz, DialectResolver resolver) {
DialectFactoryImpl dialectFactoryImpl = getDialectFactoryImpl( new StandardDialectResolver() ); dialectFactory.setDialectResolver( resolver );
dialectFactoryImpl.setDialectResolver( resolver );
Properties properties = new Properties(); Properties properties = new Properties();
Connection conn = Mocks.createConnection( databaseName, databaseMajorVersion ); Connection conn = Mocks.createConnection( databaseName, databaseMajorVersion );
assertEquals( clazz, dialectFactoryImpl.buildDialect( properties, conn ).getClass() ); assertEquals( clazz, dialectFactory.buildDialect( properties, conn ).getClass() );
} }
} }

View File

@ -1,10 +1,10 @@
/* /*
* Hibernate, Relational Persistence for Idiomatic Java * 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 * indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are * 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, * 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 * copy, or redistribute it subject to the terms and conditions of the GNU
@ -20,13 +20,14 @@
* Free Software Foundation, Inc. * Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*
*/ */
package org.hibernate.dialect.resolver; package org.hibernate.dialect.resolver;
import java.sql.SQLException; import java.sql.SQLException;
import junit.framework.Test;
import junit.framework.TestCase; import org.junit.Test;
import junit.framework.TestSuite; import static org.junit.Assert.fail;
import static org.junit.Assert.assertEquals;
import org.hibernate.dialect.Dialect; import org.hibernate.dialect.Dialect;
import org.hibernate.dialect.Mocks; import org.hibernate.dialect.Mocks;
import org.hibernate.dialect.TestingDialects; 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.BasicDialectResolver;
import org.hibernate.service.jdbc.dialect.internal.DialectResolverSet; import org.hibernate.service.jdbc.dialect.internal.DialectResolverSet;
import org.hibernate.service.jdbc.dialect.spi.DialectResolver; import org.hibernate.service.jdbc.dialect.spi.DialectResolver;
import org.hibernate.testing.junit4.BaseUnitTestCase;
/** /**
* TODO : javadoc
*
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class DialectResolverTest extends TestCase { public class DialectResolverTest extends BaseUnitTestCase {
@Test
public DialectResolverTest(String name) {
super( name );
}
public void testDialects() throws Exception { public void testDialects() throws Exception {
DialectResolverSet resolvers = new DialectResolverSet(); DialectResolverSet resolvers = new DialectResolverSet();
@ -62,6 +58,7 @@ public class DialectResolverTest extends TestCase {
testDetermination( resolvers, "MyTrickyDatabase1", 1, TestingDialects.MyDialect1.class ); testDetermination( resolvers, "MyTrickyDatabase1", 1, TestingDialects.MyDialect1.class );
} }
@Test
public void testErrorAndOrder() throws Exception { public void testErrorAndOrder() throws Exception {
DialectResolverSet resolvers = new DialectResolverSet(); DialectResolverSet resolvers = new DialectResolverSet();
resolvers.addResolverAtFirst( new TestingDialects.MyDialectResolver1() ); resolvers.addResolverAtFirst( new TestingDialects.MyDialectResolver1() );
@ -84,6 +81,7 @@ public class DialectResolverTest extends TestCase {
} }
} }
@Test
public void testBasicDialectResolver() throws Exception { public void testBasicDialectResolver() throws Exception {
DialectResolverSet resolvers = new DialectResolverSet(); DialectResolverSet resolvers = new DialectResolverSet();
// Simulating MyDialectResolver1 by BasicDialectResolvers // Simulating MyDialectResolver1 by BasicDialectResolvers
@ -114,8 +112,4 @@ public class DialectResolverTest extends TestCase {
assertEquals( dialectClass, dialect.getClass() ); assertEquals( dialectClass, dialect.getClass() );
} }
} }
public static Test suite() {
return new TestSuite( DialectResolverTest.class );
}
} }

View File

@ -23,14 +23,20 @@
* *
*/ */
package org.hibernate.engine.query; 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 * Unit tests of the ParameterParser class
* *
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class ParameterParserTest extends TestCase { public class ParameterParserTest extends BaseUnitTestCase {
@Test
public void testEscapeCallRecognition() { public void testEscapeCallRecognition() {
assertTrue( ParameterParser.startsWithEscapeCallTemplate( "{ ? = call abc(?) }" ) ); assertTrue( ParameterParser.startsWithEscapeCallTemplate( "{ ? = call abc(?) }" ) );
assertFalse( ParameterParser.startsWithEscapeCallTemplate( "from User u where u.userName = ? and u.userType = 'call'" ) ); assertFalse( ParameterParser.startsWithEscapeCallTemplate( "from User u where u.userName = ? and u.userType = 'call'" ) );

View File

@ -22,16 +22,23 @@
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*/ */
package org.hibernate.id; 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 * @author Steve Ebersole
*/ */
public abstract class AbstractHolderTest extends TestCase { @SuppressWarnings( {"UnusedDeclaration"})
public abstract class AbstractHolderTest extends BaseUnitTestCase {
protected abstract IntegralDataTypeHolder makeHolder(); protected abstract IntegralDataTypeHolder makeHolder();
@Test
@SuppressWarnings( {"EmptyCatchBlock"})
public void testInitializationChecking() { public void testInitializationChecking() {
IntegralDataTypeHolder holder = makeHolder(); IntegralDataTypeHolder holder = makeHolder();
try { try {

View File

@ -25,8 +25,6 @@ package org.hibernate.id;
import java.math.BigDecimal; import java.math.BigDecimal;
/** /**
* TODO : javadoc
*
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class BigDecimalHolderTest extends AbstractHolderTest { public class BigDecimalHolderTest extends AbstractHolderTest {

View File

@ -25,8 +25,6 @@ package org.hibernate.id;
import java.math.BigInteger; import java.math.BigInteger;
/** /**
* TODO : javadoc
*
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class BigIntegerHolderTest extends AbstractHolderTest { public class BigIntegerHolderTest extends AbstractHolderTest {

View File

@ -25,8 +25,6 @@ package org.hibernate.id;
/** /**
* TODO : javadoc
*
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class LongHolderTest extends AbstractHolderTest { public class LongHolderTest extends AbstractHolderTest {

View File

@ -28,7 +28,7 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.Properties; import java.util.Properties;
import junit.framework.TestCase;
import org.hibernate.Hibernate; import org.hibernate.Hibernate;
import org.hibernate.Session; import org.hibernate.Session;
import org.hibernate.TestingDatabaseInfo; import org.hibernate.TestingDatabaseInfo;
@ -52,7 +52,7 @@ import org.hibernate.testing.ServiceRegistryBuilder;
* @author Steve Ebersole * @author Steve Ebersole
*/ */
@SuppressWarnings({ "deprecation" }) @SuppressWarnings({ "deprecation" })
public class SequenceHiLoGeneratorNoIncrementTest extends TestCase { public class SequenceHiLoGeneratorNoIncrementTest extends BaseUnitTestCase {
private static final String TEST_SEQUENCE = "test_sequence"; private static final String TEST_SEQUENCE = "test_sequence";
private Configuration cfg; private Configuration cfg;
@ -60,7 +60,7 @@ public class SequenceHiLoGeneratorNoIncrementTest extends TestCase {
private SessionFactoryImplementor sessionFactory; private SessionFactoryImplementor sessionFactory;
private SequenceHiLoGenerator generator; private SequenceHiLoGenerator generator;
@Override @Before
protected void setUp() throws Exception { protected void setUp() throws Exception {
super.setUp(); super.setUp();
@ -100,7 +100,7 @@ public class SequenceHiLoGeneratorNoIncrementTest extends TestCase {
sessionFactory = (SessionFactoryImplementor) cfg.buildSessionFactory( serviceRegistry ); sessionFactory = (SessionFactoryImplementor) cfg.buildSessionFactory( serviceRegistry );
} }
@Override @After
protected void tearDown() throws Exception { protected void tearDown() throws Exception {
if ( sessionFactory != null ) { if ( sessionFactory != null ) {
sessionFactory.close(); sessionFactory.close();
@ -111,6 +111,7 @@ public class SequenceHiLoGeneratorNoIncrementTest extends TestCase {
super.tearDown(); super.tearDown();
} }
@Test
public void testHiLoAlgorithm() { public void testHiLoAlgorithm() {
SessionImpl session = (SessionImpl) sessionFactory.openSession(); SessionImpl session = (SessionImpl) sessionFactory.openSession();
session.beginTransaction(); session.beginTransaction();

View File

@ -28,7 +28,7 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.Properties; import java.util.Properties;
import junit.framework.TestCase;
import org.hibernate.Hibernate; import org.hibernate.Hibernate;
import org.hibernate.Session; import org.hibernate.Session;
import org.hibernate.TestingDatabaseInfo; import org.hibernate.TestingDatabaseInfo;
@ -43,7 +43,15 @@ import org.hibernate.impl.SessionImpl;
import org.hibernate.jdbc.Work; import org.hibernate.jdbc.Work;
import org.hibernate.mapping.SimpleAuxiliaryDatabaseObject; import org.hibernate.mapping.SimpleAuxiliaryDatabaseObject;
import org.hibernate.service.spi.ServiceRegistry; 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.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 * 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 * @author Steve Ebersole
*/ */
@SuppressWarnings({ "deprecation" }) @SuppressWarnings({ "deprecation" })
public class SequenceHiLoGeneratorTest extends TestCase { public class SequenceHiLoGeneratorTest extends BaseUnitTestCase {
private static final String TEST_SEQUENCE = "test_sequence"; private static final String TEST_SEQUENCE = "test_sequence";
private Configuration cfg; private Configuration cfg;
@ -60,10 +68,8 @@ public class SequenceHiLoGeneratorTest extends TestCase {
private SessionFactoryImplementor sessionFactory; private SessionFactoryImplementor sessionFactory;
private SequenceHiLoGenerator generator; private SequenceHiLoGenerator generator;
@Override @Before
protected void setUp() throws Exception { public void setUp() throws Exception {
super.setUp();
Properties properties = new Properties(); Properties properties = new Properties();
properties.setProperty( SequenceGenerator.SEQUENCE, TEST_SEQUENCE ); properties.setProperty( SequenceGenerator.SEQUENCE, TEST_SEQUENCE );
properties.setProperty( SequenceHiLoGenerator.MAX_LO, "3" ); properties.setProperty( SequenceHiLoGenerator.MAX_LO, "3" );
@ -99,17 +105,17 @@ public class SequenceHiLoGeneratorTest extends TestCase {
sessionFactory = (SessionFactoryImplementor) cfg.buildSessionFactory( serviceRegistry ); sessionFactory = (SessionFactoryImplementor) cfg.buildSessionFactory( serviceRegistry );
} }
@Override @After
protected void tearDown() throws Exception { public void tearDown() throws Exception {
if ( sessionFactory != null ) { if ( sessionFactory != null ) {
sessionFactory.close(); sessionFactory.close();
} }
if ( serviceRegistry != null ) { if ( serviceRegistry != null ) {
ServiceRegistryBuilder.destroy( serviceRegistry ); ServiceRegistryBuilder.destroy( serviceRegistry );
} }
super.tearDown();
} }
@Test
public void testHiLoAlgorithm() { public void testHiLoAlgorithm() {
SessionImpl session = (SessionImpl) sessionFactory.openSession(); SessionImpl session = (SessionImpl) sessionFactory.openSession();
session.beginTransaction(); session.beginTransaction();

View File

@ -27,8 +27,7 @@ import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.Properties;
import junit.framework.TestCase;
import org.hibernate.Hibernate; import org.hibernate.Hibernate;
import org.hibernate.Session; import org.hibernate.Session;
import org.hibernate.TestingDatabaseInfo; import org.hibernate.TestingDatabaseInfo;
@ -43,7 +42,15 @@ import org.hibernate.impl.SessionImpl;
import org.hibernate.jdbc.Work; import org.hibernate.jdbc.Work;
import org.hibernate.mapping.SimpleAuxiliaryDatabaseObject; import org.hibernate.mapping.SimpleAuxiliaryDatabaseObject;
import org.hibernate.service.spi.ServiceRegistry; 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.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 * 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 * @author Steve Ebersole
*/ */
@SuppressWarnings({ "deprecation" }) @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_TABLE = "generator_table";
private static final String GEN_COLUMN = TableHiLoGenerator.DEFAULT_COLUMN_NAME; private static final String GEN_COLUMN = TableHiLoGenerator.DEFAULT_COLUMN_NAME;
@ -61,10 +68,8 @@ public class TableHiLoGeneratorTest extends TestCase {
private SessionFactoryImplementor sessionFactory; private SessionFactoryImplementor sessionFactory;
private TableHiLoGenerator generator; private TableHiLoGenerator generator;
@Override @Before
protected void setUp() throws Exception { public void setUp() throws Exception {
super.setUp();
Properties properties = new Properties(); Properties properties = new Properties();
properties.setProperty( TableGenerator.TABLE, GEN_TABLE ); properties.setProperty( TableGenerator.TABLE, GEN_TABLE );
properties.setProperty( TableGenerator.COLUMN, GEN_COLUMN ); properties.setProperty( TableGenerator.COLUMN, GEN_COLUMN );
@ -109,18 +114,17 @@ public class TableHiLoGeneratorTest extends TestCase {
sessionFactory = (SessionFactoryImplementor) cfg.buildSessionFactory( serviceRegistry ); sessionFactory = (SessionFactoryImplementor) cfg.buildSessionFactory( serviceRegistry );
} }
@Override @After
protected void tearDown() throws Exception { public void tearDown() throws Exception {
if ( sessionFactory != null ) { if ( sessionFactory != null ) {
sessionFactory.close(); sessionFactory.close();
} }
if ( serviceRegistry != null ) { if ( serviceRegistry != null ) {
ServiceRegistryBuilder.destroy( serviceRegistry ); ServiceRegistryBuilder.destroy( serviceRegistry );
} }
super.tearDown();
} }
@Test
public void testHiLoAlgorithm() { public void testHiLoAlgorithm() {
SessionImpl session = (SessionImpl) sessionFactory.openSession(); SessionImpl session = (SessionImpl) sessionFactory.openSession();
session.beginTransaction(); session.beginTransaction();

View File

@ -22,27 +22,24 @@
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*/ */
package org.hibernate.id.enhanced; package org.hibernate.id.enhanced;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.hibernate.id.IdentifierGeneratorHelper; import org.hibernate.id.IdentifierGeneratorHelper;
import org.hibernate.id.IntegralDataTypeHolder; import org.hibernate.id.IntegralDataTypeHolder;
import org.junit.Test;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import static org.junit.Assert.assertEquals;
/** /**
* {@inheritDoc} * {@inheritDoc}
* *
* @author Steve Ebersole * @author Steve Ebersole
*/ */
@SuppressWarnings({ "deprecation" }) @SuppressWarnings({ "deprecation" })
public class OptimizerUnitTest extends TestCase { public class OptimizerUnitTest extends BaseUnitTestCase {
public OptimizerUnitTest(String string) { @Test
super( string );
}
public static Test suite() {
return new TestSuite( OptimizerUnitTest.class );
}
public void testBasicNoOptimizerUsage() { public void testBasicNoOptimizerUsage() {
// test historic sequence behavior, where the initial values start at 1... // test historic sequence behavior, where the initial values start at 1...
SourceMock sequence = new SourceMock( 1 ); SourceMock sequence = new SourceMock( 1 );
@ -65,6 +62,7 @@ public class OptimizerUnitTest extends TestCase {
assertEquals( 10, sequence.getCurrentValue() ); assertEquals( 10, sequence.getCurrentValue() );
} }
@Test
public void testBasicHiLoOptimizerUsage() { public void testBasicHiLoOptimizerUsage() {
int increment = 10; int increment = 10;
Long next; Long next;
@ -100,6 +98,7 @@ public class OptimizerUnitTest extends TestCase {
assertEquals( 2, sequence.getCurrentValue() ); assertEquals( 2, sequence.getCurrentValue() );
} }
@Test
public void testBasicPooledOptimizerUsage() { public void testBasicPooledOptimizerUsage() {
Long next; Long next;
// test historic sequence behavior, where the initial values start at 1... // test historic sequence behavior, where the initial values start at 1...
@ -118,6 +117,7 @@ public class OptimizerUnitTest extends TestCase {
assertEquals( 21, sequence.getCurrentValue() ); assertEquals( 21, sequence.getCurrentValue() );
} }
@Test
public void testSubsequentPooledOptimizerUsage() { public void testSubsequentPooledOptimizerUsage() {
// test the pooled optimizer in situation where the sequence is already beyond its initial value on init. // 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 // cheat by telling the sequence to start with 1000
@ -150,6 +150,7 @@ public class OptimizerUnitTest extends TestCase {
assertEquals( (1001+6), sequence.getCurrentValue() ); assertEquals( (1001+6), sequence.getCurrentValue() );
} }
@Test
public void testBasicPooledLoOptimizerUsage() { public void testBasicPooledLoOptimizerUsage() {
final SourceMock sequence = new SourceMock( 1, 3 ); final SourceMock sequence = new SourceMock( 1, 3 );
final Optimizer optimizer = OptimizerFactory.buildOptimizer( OptimizerFactory.POOL_LO, Long.class, 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() ); assertEquals( (1+3), sequence.getCurrentValue() );
} }
@Test
public void testSubsequentPooledLoOptimizerUsage() { public void testSubsequentPooledLoOptimizerUsage() {
// test the pooled optimizer in situation where the sequence is already beyond its initial value on init. // 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 // cheat by telling the sequence to start with 1000
@ -211,6 +213,7 @@ public class OptimizerUnitTest extends TestCase {
assertEquals( (1001+6), sequence.getCurrentValue() ); assertEquals( (1001+6), sequence.getCurrentValue() );
} }
@Test
public void testRecoveredPooledOptimizerUsage() { public void testRecoveredPooledOptimizerUsage() {
final SourceMock sequence = new SourceMock( 1, 3 ); final SourceMock sequence = new SourceMock( 1, 3 );
final Optimizer optimizer = OptimizerFactory.buildOptimizer( OptimizerFactory.POOL, Long.class, 3, 1 ); final Optimizer optimizer = OptimizerFactory.buildOptimizer( OptimizerFactory.POOL, Long.class, 3, 1 );
@ -231,6 +234,7 @@ public class OptimizerUnitTest extends TestCase {
assertEquals( 7, sequence.getCurrentValue() ); assertEquals( 7, sequence.getCurrentValue() );
} }
@Test
public void testRecoveredPooledLoOptimizerUsage() { public void testRecoveredPooledLoOptimizerUsage() {
final SourceMock sequence = new SourceMock( 1, 3 ); final SourceMock sequence = new SourceMock( 1, 3 );
final Optimizer optimizer = OptimizerFactory.buildOptimizer( OptimizerFactory.POOL_LO, Long.class, 3, 1 ); 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() + ")" );
// }
// }
} }

View File

@ -22,10 +22,9 @@
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*/ */
package org.hibernate.id.enhanced; package org.hibernate.id.enhanced;
import java.util.Properties; import java.util.Properties;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.hibernate.Hibernate; import org.hibernate.Hibernate;
import org.hibernate.MappingException; import org.hibernate.MappingException;
import org.hibernate.cfg.Environment; import org.hibernate.cfg.Environment;
@ -34,22 +33,20 @@ import org.hibernate.cfg.ObjectNameNormalizer;
import org.hibernate.dialect.Dialect; import org.hibernate.dialect.Dialect;
import org.hibernate.id.PersistentIdentifierGenerator; 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 * Tests that SequenceStyleGenerator configures itself as expected in various scenarios
* in various scenarios
* *
* @author Steve Ebersole * @author Steve Ebersole
*/ */
@SuppressWarnings({ "deprecation" }) @SuppressWarnings({ "deprecation" })
public class SequenceStyleConfigUnitTest extends TestCase { public class SequenceStyleConfigUnitTest extends BaseUnitTestCase {
public SequenceStyleConfigUnitTest(String string) {
super( string );
}
public static Test suite() {
return new TestSuite( SequenceStyleConfigUnitTest.class );
}
private void assertClassAssignability(Class expected, Class actual) { private void assertClassAssignability(Class expected, Class actual) {
if ( ! expected.isAssignableFrom( actual ) ) { if ( ! expected.isAssignableFrom( actual ) ) {
fail( "Actual type [" + actual.getName() + "] is not assignable to expected type [" + expected.getName() + "]" ); 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 all params defaulted with a dialect supporting sequences
*/ */
@Test
public void testDefaultedSequenceBackedConfiguration() { public void testDefaultedSequenceBackedConfiguration() {
Dialect dialect = new SequenceDialect(); Dialect dialect = new SequenceDialect();
Properties props = buildGeneratorPropertiesBase(); 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 all params defaulted with a dialect which does not support sequences
*/ */
@Test
public void testDefaultedTableBackedConfiguration() { public void testDefaultedTableBackedConfiguration() {
Dialect dialect = new TableDialect(); Dialect dialect = new TableDialect();
Properties props = buildGeneratorPropertiesBase(); Properties props = buildGeneratorPropertiesBase();
@ -107,6 +106,7 @@ public class SequenceStyleConfigUnitTest extends TestCase {
* based on the configured increment size; both in the case of the * based on the configured increment size; both in the case of the
* dialect supporting pooled sequences (pooled) and not (hilo) * dialect supporting pooled sequences (pooled) and not (hilo)
*/ */
@Test
public void testDefaultOptimizerBasedOnIncrementBackedBySequence() { public void testDefaultOptimizerBasedOnIncrementBackedBySequence() {
Properties props = buildGeneratorPropertiesBase(); Properties props = buildGeneratorPropertiesBase();
props.setProperty( SequenceStyleGenerator.INCREMENT_PARAM, "10" ); 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 * based on the configured increment size. Here we always prefer
* pooled. * pooled.
*/ */
@Test
public void testDefaultOptimizerBasedOnIncrementBackedByTable() { public void testDefaultOptimizerBasedOnIncrementBackedByTable() {
Properties props = buildGeneratorPropertiesBase(); Properties props = buildGeneratorPropertiesBase();
props.setProperty( SequenceStyleGenerator.INCREMENT_PARAM, "10" ); 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 forcing of table as backing strucuture with dialect supporting sequences
*/ */
@Test
public void testForceTableUse() { public void testForceTableUse() {
Dialect dialect = new SequenceDialect(); Dialect dialect = new SequenceDialect();
Properties props = buildGeneratorPropertiesBase(); Properties props = buildGeneratorPropertiesBase();
@ -161,6 +163,7 @@ public class SequenceStyleConfigUnitTest extends TestCase {
/** /**
* Test explicitly specifying both optimizer and increment * Test explicitly specifying both optimizer and increment
*/ */
@Test
public void testExplicitOptimizerWithExplicitIncrementSize() { public void testExplicitOptimizerWithExplicitIncrementSize() {
// with sequence ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // with sequence ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
final Dialect dialect = new SequenceDialect(); final Dialect dialect = new SequenceDialect();
@ -201,6 +204,7 @@ public class SequenceStyleConfigUnitTest extends TestCase {
assertEquals( 20, generator.getDatabaseStructure().getIncrementSize() ); assertEquals( 20, generator.getDatabaseStructure().getIncrementSize() );
} }
@Test
public void testPreferPooledLoSettingHonored() { public void testPreferPooledLoSettingHonored() {
final Dialect dialect = new PooledSequenceDialect(); final Dialect dialect = new PooledSequenceDialect();

View File

@ -19,22 +19,23 @@
* along with this distribution; if not, write to: * along with this distribution; if not, write to:
* Free Software Foundation, Inc. * Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USABasicFormatterTes
*/ */
package org.hibernate.id.uuid; 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 java.util.UUID;
import junit.framework.TestCase;
import org.hibernate.testing.junit4.BaseUnitTestCase;
/** /**
* TODO : javadoc
*
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class CustomVersionOneStrategyTest extends TestCase { public class CustomVersionOneStrategyTest extends BaseUnitTestCase {
public static void main(String[] args) { @Test
System.out.println( System.currentTimeMillis() );
System.out.println( Long.MAX_VALUE );
}
public void testUniqueCounter() { public void testUniqueCounter() {
CustomVersionOneStrategy strategy = new CustomVersionOneStrategy(); CustomVersionOneStrategy strategy = new CustomVersionOneStrategy();
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
@ -57,6 +58,7 @@ public class CustomVersionOneStrategyTest extends TestCase {
} }
} }
@Test
public void testRangeOfValues() { public void testRangeOfValues() {
CustomVersionOneStrategy strategy = new CustomVersionOneStrategy(); CustomVersionOneStrategy strategy = new CustomVersionOneStrategy();

View File

@ -23,37 +23,44 @@
*/ */
package org.hibernate.jdbc; 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.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.Reader; import java.io.Reader;
import java.io.Writer; 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 java.util.Properties;
import junit.framework.TestCase;
import org.hibernate.cfg.Environment; 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.ContextualLobCreator;
import org.hibernate.engine.jdbc.LobCreationContext; import org.hibernate.engine.jdbc.LobCreationContext;
import org.hibernate.engine.jdbc.LobCreator; 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.NClobImplementer;
import org.hibernate.engine.jdbc.NonContextualLobCreator;
import org.hibernate.engine.jdbc.WrappedBlob; import org.hibernate.engine.jdbc.WrappedBlob;
import org.hibernate.engine.jdbc.WrappedClob; 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 * @author Steve Ebersole
*/ */
public class LobCreatorTest extends TestCase { public class LobCreatorTest extends org.hibernate.testing.junit4.BaseUnitTestCase {
@Test
public void testConnectedLobCreator() throws SQLException { public void testConnectedLobCreator() throws SQLException {
final Connection connection = createConnectionProxy( 4, new JdbcLobBuilderImpl( true ) ); final Connection connection = createConnectionProxy( 4, new JdbcLobBuilderImpl( true ) );
LobCreationContext lobCreationContext = new LobCreationContextImpl( connection ); LobCreationContext lobCreationContext = new LobCreationContextImpl( connection );
@ -152,7 +159,7 @@ public class LobCreatorTest extends TestCase {
this.connection = connection; this.connection = connection;
} }
public Object execute( LobCreationContext.Callback callback) { public <T> T execute(LobCreationContext.Callback<T> callback) {
try { try {
return callback.executeOnConnection( connection ); return callback.executeOnConnection( connection );
} }

View File

@ -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, * 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 * 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 * Lesser General Public License, as published by the Free Software Foundation.
* 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.
* *
* 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; package org.hibernate.jdbc.util;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import junit.framework.TestCase;
import org.hibernate.engine.jdbc.internal.FormatStyle; 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 * BasicFormatterTest implementation
* *
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class BasicFormatterTest extends TestCase { public class BasicFormatterTest extends BaseUnitTestCase {
public BasicFormatterTest(String name) { @Test
super( name );
}
public void testNoLoss() { public void testNoLoss() {
assertNoLoss( "insert into Address (city, state, zip, \"from\") values (?, ?, ?, 'insert value')" ); assertNoLoss( "insert into Address (city, state, zip, \"from\") values (?, ?, ?, 'insert value')" );
assertNoLoss( "delete from Address where id = ? and version = ?" ); assertNoLoss( "delete from Address where id = ? and version = ?" );

View File

@ -22,14 +22,16 @@
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*/ */
package org.hibernate.jmx; 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 * @author Steve Ebersole
*/ */
public class TrivialTest extends TestCase { public class TrivialTest extends BaseUnitTestCase {
@Test
public void testService() throws Exception { public void testService() throws Exception {
HibernateService hs = new HibernateService(); HibernateService hs = new HibernateService();
hs.setJndiName( "SessionFactory" ); hs.setJndiName( "SessionFactory" );

View File

@ -22,18 +22,18 @@
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*/ */
package org.hibernate.metamodel.relational; 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 * @author Steve Ebersole
*/ */
public class ObjectNameTests extends UnitTestCase { public class ObjectNameTests extends BaseUnitTestCase {
public ObjectNameTests(String string) { @Test
super( string );
}
public void testMissingName() { public void testMissingName() {
try { try {
new ObjectName( (String)null, null, null ); new ObjectName( (String)null, null, null );
@ -50,6 +50,7 @@ public class ObjectNameTests extends UnitTestCase {
} }
} }
@Test
public void testIdentifierBuilding() { public void testIdentifierBuilding() {
ObjectName on = new ObjectName( "schema", "catalog", "name" ); ObjectName on = new ObjectName( "schema", "catalog", "name" );
assertEquals( "schema.catalog.name", on.getIdentifier() ); assertEquals( "schema.catalog.name", on.getIdentifier() );

View File

@ -22,22 +22,28 @@
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*/ */
package org.hibernate.metamodel.relational; package org.hibernate.metamodel.relational;
import java.sql.Types; 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 * TODO : javadoc
* *
* @author Steve Ebersole * @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 VARCHAR = new Datatype( Types.VARCHAR, "VARCHAR", String.class );
public static final Datatype INTEGER = new Datatype( Types.INTEGER, "INTEGER", Long.class ); public static final Datatype INTEGER = new Datatype( Types.INTEGER, "INTEGER", Long.class );
public TableManipulationTests(String string) { @Test
super( string );
}
public void testTableCreation() { public void testTableCreation() {
Table table = new Table( new ObjectName( null, null, "my_table" ) ); Table table = new Table( new ObjectName( null, null, "my_table" ) );
assertNull( table.getObjectName().getSchema() ); assertNull( table.getObjectName().getSchema() );
@ -80,6 +86,7 @@ public class TableManipulationTests extends UnitTestCase {
} }
} }
@Test
public void testBasicForeignKeyDefinition() { public void testBasicForeignKeyDefinition() {
Table book = new Table( new ObjectName( null, null, "BOOK" ) ); Table book = new Table( new ObjectName( null, null, "BOOK" ) );

View File

@ -22,14 +22,17 @@
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*/ */
package org.hibernate.property; 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 * @author Steve Ebersole
*/ */
public class BasicPropertyAccessorTest extends TestCase { public class BasicPropertyAccessorTest extends BaseUnitTestCase {
public static abstract class Super { public static abstract class Super {
public abstract Object getIt(); public abstract Object getIt();
public abstract void setIt(Object it); public abstract void setIt(Object it);
@ -80,6 +83,7 @@ public class BasicPropertyAccessorTest extends TestCase {
} }
} }
@Test
public void testBridgeMethodDisregarded() { public void testBridgeMethodDisregarded() {
BasicPropertyAccessor accessor = new BasicPropertyAccessor(); BasicPropertyAccessor accessor = new BasicPropertyAccessor();

View File

@ -1,10 +1,10 @@
/* /*
* Hibernate, Relational Persistence for Idiomatic Java * 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 * indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are * 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, * 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 * copy, or redistribute it subject to the terms and conditions of the GNU
@ -20,11 +20,11 @@
* Free Software Foundation, Inc. * Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*
*/ */
package org.hibernate.sql; package org.hibernate.sql;
import java.util.Collections; import java.util.Collections;
import junit.framework.TestCase;
import org.hibernate.QueryException; import org.hibernate.QueryException;
import org.hibernate.dialect.Dialect; import org.hibernate.dialect.Dialect;
import org.hibernate.dialect.HSQLDialect; 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.sql.ordering.antlr.ColumnMapper;
import org.hibernate.type.Type; 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 * @author Steve Ebersole
*/ */
public class TemplateTest extends TestCase { public class TemplateTest extends BaseUnitTestCase {
private static final PropertyMapping PROPERTY_MAPPING = new PropertyMapping() { private static final PropertyMapping PROPERTY_MAPPING = new PropertyMapping() {
public String[] toColumns(String propertyName) throws QueryException, UnsupportedOperationException { public String[] toColumns(String propertyName) throws QueryException, UnsupportedOperationException {
if ( "sql".equals( propertyName ) ) { 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 ); private static final SQLFunctionRegistry FUNCTION_REGISTRY = new SQLFunctionRegistry( DIALECT, Collections.EMPTY_MAP );
@Test
public void testSqlExtractFunction() { public void testSqlExtractFunction() {
String fragment = "extract( year from col )"; String fragment = "extract( year from col )";
String template = Template.renderWhereStringTemplate( fragment, Template.TEMPLATE, DIALECT, FUNCTION_REGISTRY ); 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 ); assertEquals( "extract(year from " + Template.TEMPLATE + ".col)", template );
} }
@Test
public void testSqlTrimFunction() { public void testSqlTrimFunction() {
String fragment = "trim( col )"; String fragment = "trim( col )";
String template = Template.renderWhereStringTemplate( fragment, Template.TEMPLATE, DIALECT, FUNCTION_REGISTRY ); 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 ); assertEquals( "trim(both 'b' from " + Template.TEMPLATE + ".col)", template );
} }
@Test
public void testSQLReferences() { public void testSQLReferences() {
String fragment = "sql asc, sql desc"; String fragment = "sql asc, sql desc";
String template = doStandardRendering( fragment ); String template = doStandardRendering( fragment );
@ -126,6 +133,7 @@ public class TemplateTest extends TestCase {
assertEquals( Template.TEMPLATE + ".sql asc, " + Template.TEMPLATE + ".sql desc", template ); assertEquals( Template.TEMPLATE + ".sql asc, " + Template.TEMPLATE + ".sql desc", template );
} }
@Test
public void testQuotedSQLReferences() { public void testQuotedSQLReferences() {
String fragment = "`sql` asc, `sql` desc"; String fragment = "`sql` asc, `sql` desc";
String template = doStandardRendering( fragment ); String template = doStandardRendering( fragment );
@ -133,6 +141,7 @@ public class TemplateTest extends TestCase {
assertEquals( Template.TEMPLATE + ".\"sql\" asc, " + Template.TEMPLATE + ".\"sql\" desc", template ); assertEquals( Template.TEMPLATE + ".\"sql\" asc, " + Template.TEMPLATE + ".\"sql\" desc", template );
} }
@Test
public void testPropertyReference() { public void testPropertyReference() {
String fragment = "property asc, property desc"; String fragment = "property asc, property desc";
String template = doStandardRendering( fragment ); String template = doStandardRendering( fragment );
@ -140,6 +149,7 @@ public class TemplateTest extends TestCase {
assertEquals( Template.TEMPLATE + ".prop asc, " + Template.TEMPLATE + ".prop desc", template ); assertEquals( Template.TEMPLATE + ".prop asc, " + Template.TEMPLATE + ".prop desc", template );
} }
@Test
public void testFunctionReference() { public void testFunctionReference() {
String fragment = "upper(sql) asc, lower(sql) desc"; String fragment = "upper(sql) asc, lower(sql) desc";
String template = doStandardRendering( fragment ); 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 ); assertEquals( "upper(" + Template.TEMPLATE + ".sql) asc, lower(" + Template.TEMPLATE + ".sql) desc", template );
} }
@Test
public void testQualifiedFunctionReference() { public void testQualifiedFunctionReference() {
String fragment = "qual.upper(property) asc, qual.lower(property) desc"; String fragment = "qual.upper(property) asc, qual.lower(property) desc";
String template = doStandardRendering( fragment ); 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 ); assertEquals( "qual.upper(" + Template.TEMPLATE + ".prop) asc, qual.lower(" + Template.TEMPLATE + ".prop) desc", template );
} }
@Test
public void testDoubleQualifiedFunctionReference() { public void testDoubleQualifiedFunctionReference() {
String fragment = "qual1.qual2.upper(property) asc, qual1.qual2.lower(property) desc"; String fragment = "qual1.qual2.upper(property) asc, qual1.qual2.lower(property) desc";
String template = doStandardRendering( fragment ); 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 ); assertEquals( "qual1.qual2.upper(" + Template.TEMPLATE + ".prop) asc, qual1.qual2.lower(" + Template.TEMPLATE + ".prop) desc", template );
} }
@Test
public void testFunctionWithPropertyReferenceAsParam() { public void testFunctionWithPropertyReferenceAsParam() {
String fragment = "upper(property) asc, lower(property) desc"; String fragment = "upper(property) asc, lower(property) desc";
String template = doStandardRendering( fragment ); 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 ); assertEquals( "upper(" + Template.TEMPLATE + ".prop) asc, lower(" + Template.TEMPLATE + ".prop) desc", template );
} }
@Test
public void testNestedFunctionReferences() { public void testNestedFunctionReferences() {
String fragment = "upper(lower(sql)) asc, lower(upper(sql)) desc"; String fragment = "upper(lower(sql)) asc, lower(upper(sql)) desc";
String template = doStandardRendering( fragment ); 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 ); assertEquals( "upper(lower(" + Template.TEMPLATE + ".sql)) asc, lower(upper(" + Template.TEMPLATE + ".sql)) desc", template );
} }
@Test
public void testComplexNestedFunctionReferences() { public void testComplexNestedFunctionReferences() {
String fragment = "mod(mod(sql,2),3) asc"; String fragment = "mod(mod(sql,2),3) asc";
String template = doStandardRendering( fragment ); String template = doStandardRendering( fragment );
@ -182,6 +197,7 @@ public class TemplateTest extends TestCase {
assertEquals( "mod(mod(" + Template.TEMPLATE + ".sql, 2), 3) asc", template ); assertEquals( "mod(mod(" + Template.TEMPLATE + ".sql, 2), 3) asc", template );
} }
@Test
public void testCollation() { public void testCollation() {
String fragment = "`sql` COLLATE my_collation, `sql` COLLATE your_collation"; String fragment = "`sql` COLLATE my_collation, `sql` COLLATE your_collation";
String template = doStandardRendering( fragment ); 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 ); assertEquals( Template.TEMPLATE + ".\"sql\" collate my_collation, " + Template.TEMPLATE + ".\"sql\" collate your_collation", template );
} }
@Test
public void testCollationAndOrdering() { public void testCollationAndOrdering() {
String fragment = "sql COLLATE my_collation, upper(prop) COLLATE your_collation asc, `sql` desc"; String fragment = "sql COLLATE my_collation, upper(prop) COLLATE your_collation asc, `sql` desc";
String template = doStandardRendering( fragment ); String template = doStandardRendering( fragment );
assertEquals( Template.TEMPLATE + ".sql collate my_collation, upper(" + Template.TEMPLATE + ".prop) collate your_collation asc, " + Template.TEMPLATE + ".\"sql\" desc", template ); assertEquals( Template.TEMPLATE + ".sql collate my_collation, upper(" + Template.TEMPLATE + ".prop) collate your_collation asc, " + Template.TEMPLATE + ".\"sql\" desc", template );
} }
@Test
public void testComponentReferences() { public void testComponentReferences() {
String fragment = "component asc"; String fragment = "component asc";
String template = doStandardRendering( fragment ); String template = doStandardRendering( fragment );
assertEquals( Template.TEMPLATE + ".comp_1 asc, " + Template.TEMPLATE + ".comp_2 asc", template ); assertEquals( Template.TEMPLATE + ".comp_1 asc, " + Template.TEMPLATE + ".comp_2 asc", template );
} }
@Test
public void testComponentDerefReferences() { public void testComponentDerefReferences() {
String fragment = "component.prop1 asc"; String fragment = "component.prop1 asc";
String template = doStandardRendering( fragment ); String template = doStandardRendering( fragment );

View File

@ -22,19 +22,21 @@
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*/ */
package org.hibernate.subclassProxyInterface; package org.hibernate.subclassProxyInterface;
import junit.framework.TestCase;
import org.junit.Test;
import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment; import org.hibernate.cfg.Environment;
import org.hibernate.dialect.H2Dialect; import org.hibernate.dialect.H2Dialect;
import org.hibernate.service.spi.ServiceRegistry; import org.hibernate.service.spi.ServiceRegistry;
import org.hibernate.testing.ServiceRegistryBuilder; import org.hibernate.testing.ServiceRegistryBuilder;
import org.hibernate.testing.junit4.BaseUnitTestCase;
/** /**
* TODO : javadoc
*
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class SubclassProxyInterfaceTest extends TestCase { public class SubclassProxyInterfaceTest extends BaseUnitTestCase {
@Test
public void testSubclassProxyInterfaces() { public void testSubclassProxyInterfaces() {
final Configuration cfg = new Configuration() final Configuration cfg = new Configuration()
.setProperty( Environment.DIALECT, H2Dialect.class.getName() ) .setProperty( Environment.DIALECT, H2Dialect.class.getName() )

View File

@ -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; package org.hibernate.test.ast;
import java.io.PrintWriter; 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.antlr.HqlTokenTypes;
import org.hibernate.hql.ast.HqlParser; import org.hibernate.hql.ast.HqlParser;
import org.hibernate.hql.ast.util.ASTIterator; import org.hibernate.hql.ast.util.ASTIterator;
import org.hibernate.hql.ast.util.ASTParentsFirstIterator; import org.hibernate.hql.ast.util.ASTParentsFirstIterator;
import org.hibernate.hql.ast.util.ASTPrinter; import org.hibernate.hql.ast.util.ASTPrinter;
import org.hibernate.hql.ast.util.ASTUtil; import org.hibernate.hql.ast.util.ASTUtil;
import org.hibernate.testing.junit.UnitTestCase;
import antlr.ASTFactory; import org.junit.Test;
import antlr.collections.AST;
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. * Test ASTIterator.
*/ */
public class ASTIteratorTest extends UnitTestCase { public class ASTIteratorTest extends BaseUnitTestCase {
private ASTFactory factory; private ASTFactory factory = new ASTFactory();
/** @Test
* 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.
*/
public void testSimpleTree() throws Exception { 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"; 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 ); HqlParser parser = HqlParser.getInstance( input );
@ -65,6 +75,7 @@ public class ASTIteratorTest extends UnitTestCase {
assertNotNull( uoe ); assertNotNull( uoe );
} }
@Test
public void testParentsFirstIterator() throws Exception { public void testParentsFirstIterator() throws Exception {
AST[] tree = new AST[4]; AST[] tree = new AST[4];
AST grandparent = tree[0] = ASTUtil.create( factory, 1, "grandparent" ); AST grandparent = tree[0] = ASTUtil.create( factory, 1, "grandparent" );

View File

@ -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; 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.ASTFactory;
import antlr.collections.AST; 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. * Unit test for ASTUtil.
*/ */
public class ASTUtilTest extends UnitTestCase { public class ASTUtilTest extends BaseUnitTestCase {
private ASTFactory factory; private ASTFactory factory = new ASTFactory();
/**
* 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();
}
@Test
public void testCreate() throws Exception { public void testCreate() throws Exception {
AST n = ASTUtil.create( factory, 1, "one"); AST n = ASTUtil.create( factory, 1, "one");
assertNull( n.getFirstChild() ); assertNull( n.getFirstChild() );
assertEquals("one",n.getText()); assertEquals( "one", n.getText() );
assertEquals(1,n.getType()); assertEquals( 1, n.getType() );
} }
/**
* Test adding a tree of children. @Test
*/
public void testCreateTree() throws Exception { public void testCreateTree() throws Exception {
AST[] tree = new AST[4]; AST[] tree = new AST[4];
AST grandparent = tree[0] = ASTUtil.create(factory, 1, "grandparent"); AST grandparent = tree[0] = ASTUtil.create(factory, 1, "grandparent");
@ -46,9 +62,10 @@ public class ASTUtilTest extends UnitTestCase {
assertSame(t,grandparent); assertSame(t,grandparent);
assertSame(parent,t.getFirstChild()); assertSame(parent,t.getFirstChild());
assertSame(child,t.getFirstChild().getFirstChild()); assertSame(child,t.getFirstChild().getFirstChild());
assertSame(baby,t.getFirstChild().getFirstChild().getFirstChild()); assertSame( baby, t.getFirstChild().getFirstChild().getFirstChild() );
} }
@Test
public void testFindPreviousSibling() throws Exception { public void testFindPreviousSibling() throws Exception {
AST child1 = ASTUtil.create(factory,2, "child1"); AST child1 = ASTUtil.create(factory,2, "child1");
AST child2 = ASTUtil.create(factory,3, "child2"); AST child2 = ASTUtil.create(factory,3, "child2");
@ -67,9 +84,4 @@ public class ASTUtilTest extends UnitTestCase {
} }
assertNotNull(e); assertNotNull(e);
} }
public static Test suite() {
return new TestSuite( ASTUtilTest.class );
}
} }

View File

@ -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; package org.hibernate.test.bytecode.cglib;
import junit.framework.TestSuite;
import org.hibernate.bytecode.ReflectionOptimizer; import org.hibernate.bytecode.ReflectionOptimizer;
import org.hibernate.bytecode.cglib.BytecodeProviderImpl; 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.Bean;
import org.hibernate.test.bytecode.BeanReflectionHelper; 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 * @author Steve Ebersole
*/ */
public class ReflectionOptimizerTest extends UnitTestCase { public class ReflectionOptimizerTest extends BaseUnitTestCase {
@Test
public ReflectionOptimizerTest(String string) {
super( string );
}
public void testReflectionOptimization() { public void testReflectionOptimization() {
BytecodeProviderImpl provider = new BytecodeProviderImpl(); BytecodeProviderImpl provider = new BytecodeProviderImpl();
ReflectionOptimizer optimizer = provider.getReflectionOptimizer( ReflectionOptimizer optimizer = provider.getReflectionOptimizer(
@ -43,8 +68,4 @@ public class ReflectionOptimizerTest extends UnitTestCase {
assertEquals( "different values at index [" + i + "]", checkValues[i], values[i] ); assertEquals( "different values at index [" + i + "]", checkValues[i], values[i] );
} }
} }
public static TestSuite suite() {
return new TestSuite( ReflectionOptimizerTest.class );
}
} }

View File

@ -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; package org.hibernate.test.bytecode.javassist;
import junit.framework.TestSuite;
import org.hibernate.bytecode.ReflectionOptimizer; import org.hibernate.bytecode.ReflectionOptimizer;
import org.hibernate.bytecode.javassist.BytecodeProviderImpl; 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.Bean;
import org.hibernate.test.bytecode.BeanReflectionHelper; 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 * @author Steve Ebersole
*/ */
public class ReflectionOptimizerTest extends UnitTestCase { public class ReflectionOptimizerTest extends BaseUnitTestCase {
@Test
public ReflectionOptimizerTest(String string) {
super( string );
}
public void testReflectionOptimization() { public void testReflectionOptimization() {
BytecodeProviderImpl provider = new BytecodeProviderImpl(); BytecodeProviderImpl provider = new BytecodeProviderImpl();
ReflectionOptimizer optimizer = provider.getReflectionOptimizer( ReflectionOptimizer optimizer = provider.getReflectionOptimizer(
@ -43,8 +68,4 @@ public class ReflectionOptimizerTest extends UnitTestCase {
assertEquals( "different values at index [" + i + "]", checkValues[i], values[i] ); assertEquals( "different values at index [" + i + "]", checkValues[i], values[i] );
} }
} }
public static TestSuite suite() {
return new TestSuite( ReflectionOptimizerTest.class );
}
} }

View File

@ -1,10 +1,10 @@
/* /*
* Hibernate, Relational Persistence for Idiomatic Java * 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 * indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are * 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, * 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 * copy, or redistribute it subject to the terms and conditions of the GNU
@ -22,28 +22,34 @@
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*/ */
package org.hibernate.test.cfg; package org.hibernate.test.cfg;
import java.io.File; import java.io.File;
import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Configuration;
import org.hibernate.internal.util.SerializationHelper; 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. * Tests using of cacheable configuration files.
* *
* @author Steve Ebersole * @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"; public static final String MAPPING = "org/hibernate/test/cfg/Cacheable.hbm.xml";
private File mappingFile; private File mappingFile;
private File mappingBinFile; private File mappingBinFile;
public CacheableFileTest(String string) { @Before
super( string ); public void setUp() throws Exception {
}
protected void setUp() throws Exception {
super.setUp();
mappingFile = new File( getClass().getClassLoader().getResource( MAPPING ).toURI() ); mappingFile = new File( getClass().getClassLoader().getResource( MAPPING ).toURI() );
assertTrue( mappingFile.exists() ); assertTrue( mappingFile.exists() );
mappingBinFile = new File( mappingFile.getParentFile(), mappingFile.getName() + ".bin" ); 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() ) { if ( mappingBinFile != null && mappingBinFile.exists() ) {
// be nice // be nice
//noinspection ResultOfMethodCallIgnored //noinspection ResultOfMethodCallIgnored
@ -61,9 +68,9 @@ public class CacheableFileTest extends UnitTestCase {
} }
mappingBinFile = null; mappingBinFile = null;
mappingFile = null; mappingFile = null;
super.tearDown();
} }
@Test
public void testCachedFiles() throws Exception { public void testCachedFiles() throws Exception {
assertFalse( mappingBinFile.exists() ); assertFalse( mappingBinFile.exists() );
// This call should create the cached file // This call should create the cached file

View File

@ -1,8 +1,10 @@
/* /*
* Copyright (c) 2009 by Red Hat Inc and/or its affiliates or by * Hibernate, Relational Persistence for Idiomatic Java
* third-party contributors as indicated by either @author tags or express *
* copyright attribution statements applied by the authors. All * Copyright (c) 2009-2011, Red Hat Inc. or third-party contributors as
* third-party contributions are distributed under license by Red Hat Inc. * 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, * 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 * 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: * along with this distribution; if not, write to:
* Free Software Foundation, Inc. * Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA\ * Boston, MA 02110-1301 USA
*/ */
package org.hibernate.test.cfg; package org.hibernate.test.cfg;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.Id; import javax.persistence.Id;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.hibernate.SessionFactory; import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Configuration;
import org.hibernate.internal.util.SerializationHelper; import org.hibernate.internal.util.SerializationHelper;
import org.hibernate.service.spi.ServiceRegistry; import org.hibernate.service.spi.ServiceRegistry;
import org.junit.Test;
import org.hibernate.testing.ServiceRegistryBuilder; import org.hibernate.testing.ServiceRegistryBuilder;
import org.hibernate.testing.junit.UnitTestCase; import org.hibernate.testing.junit4.BaseUnitTestCase;
/** /**
* Copied over mostly from ConfigurationPerformanceTest * Copied over mostly from ConfigurationPerformanceTest
@ -38,15 +42,7 @@ import org.hibernate.testing.junit.UnitTestCase;
* @author Steve Ebersole * @author Steve Ebersole
* @author Max Andersen * @author Max Andersen
*/ */
public class ConfigurationSerializationTest extends UnitTestCase { public class ConfigurationSerializationTest extends BaseUnitTestCase {
public ConfigurationSerializationTest(String string) {
super( string );
}
public static Test suite() {
return new TestSuite( ConfigurationSerializationTest.class );
}
private static final String[] FILES = new String[] { private static final String[] FILES = new String[] {
"legacy/ABC.hbm.xml", "legacy/ABC.hbm.xml",
"legacy/ABCExtends.hbm.xml", "legacy/ABCExtends.hbm.xml",
@ -92,7 +88,8 @@ public class ConfigurationSerializationTest extends UnitTestCase {
"cfg/orm-serializable.xml" "cfg/orm-serializable.xml"
}; };
public void testConfiguraionSerializability() { @Test
public void testConfigurationSerializability() {
Configuration cfg = new Configuration(); Configuration cfg = new Configuration();
for ( String file : FILES ) { for ( String file : FILES ) {
cfg.addResource( "org/hibernate/test/" + file ); cfg.addResource( "org/hibernate/test/" + file );

View File

@ -1,10 +1,10 @@
/* /*
* Hibernate, Relational Persistence for Idiomatic Java * 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 * indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are * 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, * 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 * 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.DeleteEvent;
import org.hibernate.event.DeleteEventListener; import org.hibernate.event.DeleteEventListener;
import org.hibernate.event.def.DefaultDeleteEventListener; 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 * @author Gail Badner
*/ */
public class ListenerTest extends UnitTestCase { public class ListenerTest extends BaseUnitTestCase {
public static class InvalidListenerForTest { public static class InvalidListenerForTest {
} }
@ -57,10 +63,7 @@ public class ListenerTest extends UnitTestCase {
} }
} }
public ListenerTest(String string) { @Test
super( string );
}
public void testSetListenerNullClass() { public void testSetListenerNullClass() {
Configuration cfg = new Configuration(); Configuration cfg = new Configuration();
assertNotNull( cfg.getEventListeners().getDeleteEventListeners() ); assertNotNull( cfg.getEventListeners().getDeleteEventListeners() );
@ -68,6 +71,7 @@ public class ListenerTest extends UnitTestCase {
assertEquals( 0, cfg.getEventListeners().getDeleteEventListeners().length ); assertEquals( 0, cfg.getEventListeners().getDeleteEventListeners().length );
} }
@Test
public void testSetListenersNullClass() { public void testSetListenersNullClass() {
Configuration cfg = new Configuration(); Configuration cfg = new Configuration();
assertNotNull( cfg.getEventListeners().getDeleteEventListeners() ); assertNotNull( cfg.getEventListeners().getDeleteEventListeners() );
@ -75,6 +79,7 @@ public class ListenerTest extends UnitTestCase {
assertEquals( 0, cfg.getEventListeners().getDeleteEventListeners().length ); assertEquals( 0, cfg.getEventListeners().getDeleteEventListeners().length );
} }
@Test
public void testSetListenerEmptyClassNameArray() { public void testSetListenerEmptyClassNameArray() {
Configuration cfg = new Configuration(); Configuration cfg = new Configuration();
assertNotNull( cfg.getEventListeners().getDeleteEventListeners() ); assertNotNull( cfg.getEventListeners().getDeleteEventListeners() );
@ -87,6 +92,7 @@ public class ListenerTest extends UnitTestCase {
} }
} }
@Test
public void testSetListenersEmptyClassNsmeArray() { public void testSetListenersEmptyClassNsmeArray() {
Configuration cfg = new Configuration(); Configuration cfg = new Configuration();
assertNotNull( cfg.getEventListeners().getDeleteEventListeners() ); assertNotNull( cfg.getEventListeners().getDeleteEventListeners() );
@ -94,6 +100,7 @@ public class ListenerTest extends UnitTestCase {
assertEquals( 0, cfg.getEventListeners().getDeleteEventListeners().length ); assertEquals( 0, cfg.getEventListeners().getDeleteEventListeners().length );
} }
@Test
public void testSetListenerEmptyClassObjectArray() { public void testSetListenerEmptyClassObjectArray() {
Configuration cfg = new Configuration(); Configuration cfg = new Configuration();
assertNotNull( cfg.getEventListeners().getDeleteEventListeners() ); assertNotNull( cfg.getEventListeners().getDeleteEventListeners() );
@ -106,6 +113,7 @@ public class ListenerTest extends UnitTestCase {
} }
} }
@Test
public void testSetListenersEmptyClassObjectArray() { public void testSetListenersEmptyClassObjectArray() {
Configuration cfg = new Configuration(); Configuration cfg = new Configuration();
assertNotNull( cfg.getEventListeners().getDeleteEventListeners() ); assertNotNull( cfg.getEventListeners().getDeleteEventListeners() );
@ -118,6 +126,7 @@ public class ListenerTest extends UnitTestCase {
} }
} }
@Test
public void testSetListenerEmptyClassArray() { public void testSetListenerEmptyClassArray() {
Configuration cfg = new Configuration(); Configuration cfg = new Configuration();
assertNotNull( cfg.getEventListeners().getDeleteEventListeners() ); assertNotNull( cfg.getEventListeners().getDeleteEventListeners() );
@ -130,6 +139,7 @@ public class ListenerTest extends UnitTestCase {
} }
} }
@Test
public void testSetListenersEmptyClassArray() { public void testSetListenersEmptyClassArray() {
Configuration cfg = new Configuration(); Configuration cfg = new Configuration();
assertNotNull( cfg.getEventListeners().getDeleteEventListeners() ); assertNotNull( cfg.getEventListeners().getDeleteEventListeners() );
@ -137,6 +147,7 @@ public class ListenerTest extends UnitTestCase {
assertEquals( 0, cfg.getEventListeners().getDeleteEventListeners().length ); assertEquals( 0, cfg.getEventListeners().getDeleteEventListeners().length );
} }
@Test
public void testSetListenerUnknownClassName() { public void testSetListenerUnknownClassName() {
Configuration cfg = new Configuration(); Configuration cfg = new Configuration();
assertNotNull( cfg.getEventListeners().getDeleteEventListeners() ); assertNotNull( cfg.getEventListeners().getDeleteEventListeners() );
@ -149,6 +160,7 @@ public class ListenerTest extends UnitTestCase {
} }
} }
@Test
public void testSetListenersUnknownClassName() { public void testSetListenersUnknownClassName() {
Configuration cfg = new Configuration(); Configuration cfg = new Configuration();
assertNotNull( cfg.getEventListeners().getDeleteEventListeners() ); assertNotNull( cfg.getEventListeners().getDeleteEventListeners() );
@ -161,6 +173,7 @@ public class ListenerTest extends UnitTestCase {
} }
} }
@Test
public void testSetListenerInvalidClassName() { public void testSetListenerInvalidClassName() {
Configuration cfg = new Configuration(); Configuration cfg = new Configuration();
assertNotNull( cfg.getEventListeners().getDeleteEventListeners() ); assertNotNull( cfg.getEventListeners().getDeleteEventListeners() );
@ -173,6 +186,7 @@ public class ListenerTest extends UnitTestCase {
} }
} }
@Test
public void testSetListenersInvalidClassName() { public void testSetListenersInvalidClassName() {
Configuration cfg = new Configuration(); Configuration cfg = new Configuration();
assertNotNull( cfg.getEventListeners().getDeleteEventListeners() ); assertNotNull( cfg.getEventListeners().getDeleteEventListeners() );
@ -185,6 +199,7 @@ public class ListenerTest extends UnitTestCase {
} }
} }
@Test
public void testSetListenerClassName() { public void testSetListenerClassName() {
Configuration cfg = new Configuration(); Configuration cfg = new Configuration();
assertNotNull( cfg.getEventListeners().getDeleteEventListeners() ); assertNotNull( cfg.getEventListeners().getDeleteEventListeners() );
@ -193,6 +208,7 @@ public class ListenerTest extends UnitTestCase {
assertTrue( cfg.getEventListeners().getDeleteEventListeners()[0] instanceof DeleteListenerForTest ); assertTrue( cfg.getEventListeners().getDeleteEventListeners()[0] instanceof DeleteListenerForTest );
} }
@Test
public void testSetListenersClassName() { public void testSetListenersClassName() {
Configuration cfg = new Configuration(); Configuration cfg = new Configuration();
assertNotNull( cfg.getEventListeners().getDeleteEventListeners() ); assertNotNull( cfg.getEventListeners().getDeleteEventListeners() );
@ -201,6 +217,7 @@ public class ListenerTest extends UnitTestCase {
assertTrue( cfg.getEventListeners().getDeleteEventListeners()[0] instanceof DeleteListenerForTest ); assertTrue( cfg.getEventListeners().getDeleteEventListeners()[0] instanceof DeleteListenerForTest );
} }
@Test
public void testSetListenerClassNames() { public void testSetListenerClassNames() {
Configuration cfg = new Configuration(); Configuration cfg = new Configuration();
assertNotNull( cfg.getEventListeners().getDeleteEventListeners() ); assertNotNull( cfg.getEventListeners().getDeleteEventListeners() );
@ -218,6 +235,7 @@ public class ListenerTest extends UnitTestCase {
} }
} }
@Test
public void testSetListenersClassNames() { public void testSetListenersClassNames() {
Configuration cfg = new Configuration(); Configuration cfg = new Configuration();
assertNotNull( cfg.getEventListeners().getDeleteEventListeners() ); assertNotNull( cfg.getEventListeners().getDeleteEventListeners() );
@ -232,6 +250,7 @@ public class ListenerTest extends UnitTestCase {
assertTrue( cfg.getEventListeners().getDeleteEventListeners()[1] instanceof AnotherDeleteListenerForTest ); assertTrue( cfg.getEventListeners().getDeleteEventListeners()[1] instanceof AnotherDeleteListenerForTest );
} }
@Test
public void testSetListenerClassInstance() { public void testSetListenerClassInstance() {
Configuration cfg = new Configuration(); Configuration cfg = new Configuration();
assertNotNull( cfg.getEventListeners().getDeleteEventListeners() ); assertNotNull( cfg.getEventListeners().getDeleteEventListeners() );
@ -239,6 +258,7 @@ public class ListenerTest extends UnitTestCase {
assertEquals( 1, cfg.getEventListeners().getDeleteEventListeners().length ); assertEquals( 1, cfg.getEventListeners().getDeleteEventListeners().length );
} }
@Test
public void testSetListenersClassInstances() { public void testSetListenersClassInstances() {
Configuration cfg = new Configuration(); Configuration cfg = new Configuration();
assertNotNull( cfg.getEventListeners().getDeleteEventListeners() ); assertNotNull( cfg.getEventListeners().getDeleteEventListeners() );
@ -253,6 +273,7 @@ public class ListenerTest extends UnitTestCase {
assertTrue( cfg.getEventListeners().getDeleteEventListeners()[1] instanceof AnotherDeleteListenerForTest ); assertTrue( cfg.getEventListeners().getDeleteEventListeners()[1] instanceof AnotherDeleteListenerForTest );
} }
@Test
public void testSetListenerInvalidClassInstance() { public void testSetListenerInvalidClassInstance() {
Configuration cfg = new Configuration(); Configuration cfg = new Configuration();
assertNotNull( cfg.getEventListeners().getDeleteEventListeners() ); assertNotNull( cfg.getEventListeners().getDeleteEventListeners() );
@ -265,6 +286,7 @@ public class ListenerTest extends UnitTestCase {
} }
} }
@Test
public void testSetListenersInvalidClassInstances() { public void testSetListenersInvalidClassInstances() {
Configuration cfg = new Configuration(); Configuration cfg = new Configuration();
assertNotNull( cfg.getEventListeners().getDeleteEventListeners() ); assertNotNull( cfg.getEventListeners().getDeleteEventListeners() );
@ -277,6 +299,7 @@ public class ListenerTest extends UnitTestCase {
} }
} }
@Test
public void testSetListenerNullType() { public void testSetListenerNullType() {
Configuration cfg = new Configuration(); Configuration cfg = new Configuration();
assertNotNull( cfg.getEventListeners().getDeleteEventListeners() ); assertNotNull( cfg.getEventListeners().getDeleteEventListeners() );
@ -289,6 +312,7 @@ public class ListenerTest extends UnitTestCase {
} }
} }
@Test
public void testSetListenersNullType() { public void testSetListenersNullType() {
Configuration cfg = new Configuration(); Configuration cfg = new Configuration();
assertNotNull( cfg.getEventListeners().getDeleteEventListeners() ); assertNotNull( cfg.getEventListeners().getDeleteEventListeners() );
@ -301,6 +325,7 @@ public class ListenerTest extends UnitTestCase {
} }
} }
@Test
public void testSetListenerUnknownType() { public void testSetListenerUnknownType() {
Configuration cfg = new Configuration(); Configuration cfg = new Configuration();
assertNotNull( cfg.getEventListeners().getDeleteEventListeners() ); assertNotNull( cfg.getEventListeners().getDeleteEventListeners() );
@ -313,6 +338,7 @@ public class ListenerTest extends UnitTestCase {
} }
} }
@Test
public void testSetListenersUnknownType() { public void testSetListenersUnknownType() {
Configuration cfg = new Configuration(); Configuration cfg = new Configuration();
assertNotNull( cfg.getEventListeners().getDeleteEventListeners() ); assertNotNull( cfg.getEventListeners().getDeleteEventListeners() );

View File

@ -25,17 +25,19 @@ import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Configuration;
import org.hibernate.persister.spi.PersisterClassResolver; import org.hibernate.persister.spi.PersisterClassResolver;
import org.hibernate.service.spi.ServiceRegistry; import org.hibernate.service.spi.ServiceRegistry;
import org.junit.Test;
import org.hibernate.testing.ServiceRegistryBuilder; 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 <emmanuel@hibernate.org> * @author Emmanuel Bernard <emmanuel@hibernate.org>
*/ */
public class PersisterClassProviderTest extends UnitTestCase { public class PersisterClassProviderTest extends BaseUnitTestCase {
public PersisterClassProviderTest(String string) { @Test
super( string );
}
public void testPersisterClassProvider() throws Exception { public void testPersisterClassProvider() throws Exception {
Configuration cfg = new Configuration(); Configuration cfg = new Configuration();

View File

@ -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; package org.hibernate.test.dialect.unit.lockhint;
import java.util.Collections; import java.util.Collections;
import org.hibernate.LockMode; import org.hibernate.LockMode;
import org.hibernate.LockOptions; import org.hibernate.LockOptions;
import org.hibernate.dialect.Dialect; import org.hibernate.dialect.Dialect;
import org.hibernate.internal.util.StringHelper; 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 * @author Steve Ebersole
*/ */
public abstract class AbstractLockHintTest extends UnitTestCase { public abstract class AbstractLockHintTest extends BaseUnitTestCase {
public AbstractLockHintTest(String string) {
super( string );
}
private Dialect dialect; private Dialect dialect;
protected abstract String getLockHintUsed(); protected abstract String getLockHintUsed();
protected abstract Dialect getDialectUnderTest(); protected abstract Dialect getDialectUnderTest();
@Override @Before
protected void setUp() throws Exception { public void setUp() throws Exception {
super.setUp();
this.dialect = getDialectUnderTest(); this.dialect = getDialectUnderTest();
} }
@Override @After
protected void tearDown() throws Exception { public void tearDown() throws Exception {
this.dialect = null; this.dialect = null;
super.tearDown();
} }
@Test
public void testBasicLocking() { public void testBasicLocking() {
new SyntaxChecker( "select xyz from ABC $HOLDER$", "a" ).verify(); new SyntaxChecker( "select xyz from ABC $HOLDER$", "a" ).verify();
new SyntaxChecker( "select xyz from ABC $HOLDER$ join DEF d", "a" ).verify(); new SyntaxChecker( "select xyz from ABC $HOLDER$ join DEF d", "a" ).verify();

View File

@ -1,20 +1,37 @@
/*
* 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; package org.hibernate.test.dialect.unit.lockhint;
import junit.framework.TestSuite;
import org.hibernate.dialect.Dialect; import org.hibernate.dialect.Dialect;
import org.hibernate.dialect.SQLServerDialect; import org.hibernate.dialect.SQLServerDialect;
/** /**
* {@inheritDoc}
*
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class SQLServerLockHintsTest extends AbstractLockHintTest { public class SQLServerLockHintsTest extends AbstractLockHintTest {
public static final Dialect DIALECT = new SQLServerDialect(); public static final Dialect DIALECT = new SQLServerDialect();
public SQLServerLockHintsTest(String string) {
super( string );
}
protected String getLockHintUsed() { protected String getLockHintUsed() {
return "with (updlock, rowlock)"; return "with (updlock, rowlock)";
} }
@ -22,8 +39,4 @@ public class SQLServerLockHintsTest extends AbstractLockHintTest {
protected Dialect getDialectUnderTest() { protected Dialect getDialectUnderTest() {
return DIALECT; return DIALECT;
} }
public static TestSuite suite() {
return new TestSuite( SQLServerLockHintsTest.class );
}
} }

View File

@ -1,11 +1,10 @@
//$Id $
/* /*
* Hibernate, Relational Persistence for Idiomatic Java * 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 * indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are * 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, * 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 * copy, or redistribute it subject to the terms and conditions of the GNU
@ -21,25 +20,18 @@
* Free Software Foundation, Inc. * Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*
*/ */
package org.hibernate.test.dialect.unit.lockhint; package org.hibernate.test.dialect.unit.lockhint;
import junit.framework.TestSuite;
import org.hibernate.dialect.Dialect; import org.hibernate.dialect.Dialect;
import org.hibernate.dialect.SybaseASE15Dialect; import org.hibernate.dialect.SybaseASE15Dialect;
/** /**
* {@inheritDoc}
*
* @author Gail Badner * @author Gail Badner
*/ */
public class SybaseASE15LockHintsTest extends AbstractLockHintTest { public class SybaseASE15LockHintsTest extends AbstractLockHintTest {
public static final Dialect DIALECT = new SybaseASE15Dialect(); public static final Dialect DIALECT = new SybaseASE15Dialect();
public SybaseASE15LockHintsTest(String string) {
super( string );
}
protected String getLockHintUsed() { protected String getLockHintUsed() {
return "holdlock"; return "holdlock";
} }
@ -47,8 +39,4 @@ public class SybaseASE15LockHintsTest extends AbstractLockHintTest {
protected Dialect getDialectUnderTest() { protected Dialect getDialectUnderTest() {
return DIALECT; return DIALECT;
} }
public static TestSuite suite() {
return new TestSuite( SybaseASE15LockHintsTest.class );
}
} }

View File

@ -1,20 +1,37 @@
/*
* 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; package org.hibernate.test.dialect.unit.lockhint;
import junit.framework.TestSuite;
import org.hibernate.dialect.Dialect; import org.hibernate.dialect.Dialect;
import org.hibernate.dialect.SybaseDialect; import org.hibernate.dialect.SybaseDialect;
/** /**
* {@inheritDoc}
*
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class SybaseLockHintsTest extends AbstractLockHintTest { public class SybaseLockHintsTest extends AbstractLockHintTest {
public static final Dialect DIALECT = new SybaseDialect(); public static final Dialect DIALECT = new SybaseDialect();
public SybaseLockHintsTest(String string) {
super( string );
}
protected String getLockHintUsed() { protected String getLockHintUsed() {
return "holdlock"; return "holdlock";
} }
@ -22,8 +39,4 @@ public class SybaseLockHintsTest extends AbstractLockHintTest {
protected Dialect getDialectUnderTest() { protected Dialect getDialectUnderTest() {
return DIALECT; return DIALECT;
} }
public static TestSuite suite() {
return new TestSuite( SybaseLockHintsTest.class );
}
} }

View File

@ -1,28 +1,42 @@
//$Id: ExtendsTest.java 10977 2006-12-12 23:28:04Z steve.ebersole@jboss.com $ //$Id: ExtendsTest.java 10977 2006-12-12 23:28:04Z steve.ebersole@jboss.com $
package org.hibernate.test.extendshbm; package org.hibernate.test.extendshbm;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.cfg.Configuration; 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 * @author Gavin King
*/ */
public class ExtendsTest extends UnitTestCase { public class ExtendsTest extends BaseUnitTestCase {
private ServiceRegistryImpl serviceRegistry;
public ExtendsTest(String str) { @Before
super( str ); public void setUp() {
serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry();
} }
public static Test suite() { @After
return new TestSuite( ExtendsTest.class ); public void tearDown() {
ServiceRegistryBuilder.destroy( serviceRegistry );
} }
private String getBaseForMappings() { private String getBaseForMappings() {
return "org/hibernate/test/"; return "org/hibernate/test/";
} }
@Test
public void testAllInOne() { public void testAllInOne() {
Configuration cfg = new Configuration(); Configuration cfg = new Configuration();
@ -33,6 +47,7 @@ public class ExtendsTest extends UnitTestCase {
assertNotNull( cfg.getClassMapping( "org.hibernate.test.extendshbm.Employee" ) ); assertNotNull( cfg.getClassMapping( "org.hibernate.test.extendshbm.Employee" ) );
} }
@Test
public void testOutOfOrder() { public void testOutOfOrder() {
Configuration cfg = new Configuration(); Configuration cfg = new Configuration();
@ -45,7 +60,7 @@ public class ExtendsTest extends UnitTestCase {
cfg.addResource( getBaseForMappings() + "extendshbm/Person.hbm.xml" ); cfg.addResource( getBaseForMappings() + "extendshbm/Person.hbm.xml" );
cfg.addResource( getBaseForMappings() + "extendshbm/Employee.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.Customer" ) );
assertNotNull( cfg.getClassMapping( "org.hibernate.test.extendshbm.Person" ) ); assertNotNull( cfg.getClassMapping( "org.hibernate.test.extendshbm.Person" ) );
@ -58,6 +73,7 @@ public class ExtendsTest extends UnitTestCase {
} }
@Test
public void testNwaitingForSuper() { public void testNwaitingForSuper() {
Configuration cfg = new Configuration(); Configuration cfg = new Configuration();
@ -90,6 +106,7 @@ public class ExtendsTest extends UnitTestCase {
} }
@Test
public void testMissingSuper() { public void testMissingSuper() {
Configuration cfg = new Configuration(); Configuration cfg = new Configuration();
@ -101,7 +118,7 @@ public class ExtendsTest extends UnitTestCase {
); );
cfg.addResource( getBaseForMappings() + "extendshbm/Employee.hbm.xml" ); 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" ); fail( "Should not be able to build sessionfactory without a Person" );
} }
@ -111,13 +128,14 @@ public class ExtendsTest extends UnitTestCase {
} }
@Test
public void testAllSeparateInOne() { public void testAllSeparateInOne() {
Configuration cfg = new Configuration(); Configuration cfg = new Configuration();
try { try {
cfg.addResource( getBaseForMappings() + "extendshbm/allseparateinone.hbm.xml" ); 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.Customer" ) );
assertNotNull( cfg.getClassMapping( "org.hibernate.test.extendshbm.Person" ) ); assertNotNull( cfg.getClassMapping( "org.hibernate.test.extendshbm.Person" ) );
@ -130,6 +148,7 @@ public class ExtendsTest extends UnitTestCase {
} }
@Test
public void testJoinedSubclassAndEntityNamesOnly() { public void testJoinedSubclassAndEntityNamesOnly() {
Configuration cfg = new Configuration(); Configuration cfg = new Configuration();
@ -149,6 +168,7 @@ public class ExtendsTest extends UnitTestCase {
} }
} }
@Test
public void testEntityNamesWithPackage() { public void testEntityNamesWithPackage() {
Configuration cfg = new Configuration(); Configuration cfg = new Configuration();
try { try {
@ -167,7 +187,7 @@ public class ExtendsTest extends UnitTestCase {
} }
} }
@Test
public void testUnionSubclass() { public void testUnionSubclass() {
Configuration cfg = new Configuration(); Configuration cfg = new Configuration();

View File

@ -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; package org.hibernate.test.instrument.buildtime;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.hibernate.intercept.FieldInterceptionHelper; 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.Executable;
import org.hibernate.test.instrument.cases.TestCustomColumnReadAndWrite; import org.hibernate.test.instrument.cases.TestCustomColumnReadAndWrite;
import org.hibernate.test.instrument.cases.TestDirtyCheckExecutable; 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.TestManyToOneProxyExecutable;
import org.hibernate.test.instrument.cases.TestSharedPKOneToOneExecutable; import org.hibernate.test.instrument.cases.TestSharedPKOneToOneExecutable;
import org.hibernate.test.instrument.domain.Document; import org.hibernate.test.instrument.domain.Document;
import org.hibernate.testing.junit.UnitTestCase;
/** /**
* @author Gavin King * @author Gavin King
*/ */
public class InstrumentTest extends UnitTestCase { @Skip(
message = "domain classes not instrumented for build-time instrumentation testing",
public InstrumentTest(String str) { condition = InstrumentTest.SkipCheck.class
super(str); )
} public class InstrumentTest extends BaseUnitTestCase {
@Test
public static Test suite() {
return new TestSuite( InstrumentTest.class );
}
public void testDirtyCheck() throws Exception { public void testDirtyCheck() throws Exception {
execute( new TestDirtyCheckExecutable() ); execute( new TestDirtyCheckExecutable() );
} }
@Test
public void testFetchAll() throws Exception { public void testFetchAll() throws Exception {
execute( new TestFetchAllExecutable() ); execute( new TestFetchAllExecutable() );
} }
@Test
public void testLazy() throws Exception { public void testLazy() throws Exception {
execute( new TestLazyExecutable() ); execute( new TestLazyExecutable() );
} }
@Test
public void testLazyManyToOne() throws Exception { public void testLazyManyToOne() throws Exception {
execute( new TestLazyManyToOneExecutable() ); execute( new TestLazyManyToOneExecutable() );
} }
@Test
public void testSetFieldInterceptor() throws Exception { public void testSetFieldInterceptor() throws Exception {
execute( new TestInjectFieldInterceptorExecutable() ); execute( new TestInjectFieldInterceptorExecutable() );
} }
@Test
public void testPropertyInitialized() throws Exception { public void testPropertyInitialized() throws Exception {
execute( new TestIsPropertyInitializedExecutable() ); execute( new TestIsPropertyInitializedExecutable() );
} }
@Test
public void testManyToOneProxy() throws Exception { public void testManyToOneProxy() throws Exception {
execute( new TestManyToOneProxyExecutable() ); execute( new TestManyToOneProxyExecutable() );
} }
@Test
public void testLazyPropertyCustomTypeExecutable() throws Exception { public void testLazyPropertyCustomTypeExecutable() throws Exception {
execute( new TestLazyPropertyCustomTypeExecutable() ); execute( new TestLazyPropertyCustomTypeExecutable() );
} }
@Test
public void testSharedPKOneToOne() throws Exception { public void testSharedPKOneToOne() throws Exception {
execute( new TestSharedPKOneToOneExecutable() ); execute( new TestSharedPKOneToOneExecutable() );
} }
@Test
public void testCustomColumnReadAndWrite() throws Exception { public void testCustomColumnReadAndWrite() throws Exception {
execute( new TestCustomColumnReadAndWrite() ); execute( new TestCustomColumnReadAndWrite() );
} }
@ -80,17 +110,11 @@ public class InstrumentTest extends UnitTestCase {
} }
} }
protected void runTest() throws Throwable { public static class SkipCheck implements Skip.Matcher {
if ( isRunnable() ) { @Override
super.runTest(); 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() );
} }
} }

View File

@ -1,5 +1,31 @@
/*
* 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; package org.hibernate.test.instrument.runtime;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import org.junit.Test;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.bytecode.BytecodeProvider; import org.hibernate.bytecode.BytecodeProvider;
import org.hibernate.bytecode.InstrumentedClassLoader; import org.hibernate.bytecode.InstrumentedClassLoader;
@ -12,10 +38,6 @@ import org.hibernate.testing.junit.AbstractClassLoaderIsolatedTestCase;
*/ */
public abstract class AbstractTransformingClassLoaderInstrumentTestCase extends AbstractClassLoaderIsolatedTestCase { public abstract class AbstractTransformingClassLoaderInstrumentTestCase extends AbstractClassLoaderIsolatedTestCase {
public AbstractTransformingClassLoaderInstrumentTestCase(String string) {
super( string );
}
protected ClassLoader buildIsolatedClassLoader(ClassLoader parent) { protected ClassLoader buildIsolatedClassLoader(ClassLoader parent) {
BytecodeProvider provider = buildBytecodeProvider(); BytecodeProvider provider = buildBytecodeProvider();
return new InstrumentedClassLoader( return new InstrumentedClassLoader(
@ -44,42 +66,52 @@ public abstract class AbstractTransformingClassLoaderInstrumentTestCase extends
// the tests ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // the tests ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@Test
public void testSetFieldInterceptor() { public void testSetFieldInterceptor() {
executeExecutable( "org.hibernate.test.instrument.cases.TestInjectFieldInterceptorExecutable" ); executeExecutable( "org.hibernate.test.instrument.cases.TestInjectFieldInterceptorExecutable" );
} }
@Test
public void testDirtyCheck() { public void testDirtyCheck() {
executeExecutable( "org.hibernate.test.instrument.cases.TestDirtyCheckExecutable" ); executeExecutable( "org.hibernate.test.instrument.cases.TestDirtyCheckExecutable" );
} }
@Test
public void testFetchAll() throws Exception { public void testFetchAll() throws Exception {
executeExecutable( "org.hibernate.test.instrument.cases.TestFetchAllExecutable" ); executeExecutable( "org.hibernate.test.instrument.cases.TestFetchAllExecutable" );
} }
@Test
public void testLazy() { public void testLazy() {
executeExecutable( "org.hibernate.test.instrument.cases.TestLazyExecutable" ); executeExecutable( "org.hibernate.test.instrument.cases.TestLazyExecutable" );
} }
@Test
public void testLazyManyToOne() { public void testLazyManyToOne() {
executeExecutable( "org.hibernate.test.instrument.cases.TestLazyManyToOneExecutable" ); executeExecutable( "org.hibernate.test.instrument.cases.TestLazyManyToOneExecutable" );
} }
@Test
public void testPropertyInitialized() { public void testPropertyInitialized() {
executeExecutable( "org.hibernate.test.instrument.cases.TestIsPropertyInitializedExecutable" ); executeExecutable( "org.hibernate.test.instrument.cases.TestIsPropertyInitializedExecutable" );
} }
@Test
public void testManyToOneProxy() { public void testManyToOneProxy() {
executeExecutable( "org.hibernate.test.instrument.cases.TestManyToOneProxyExecutable" ); executeExecutable( "org.hibernate.test.instrument.cases.TestManyToOneProxyExecutable" );
} }
@Test
public void testLazyPropertyCustomType() { public void testLazyPropertyCustomType() {
executeExecutable( "org.hibernate.test.instrument.cases.TestLazyPropertyCustomTypeExecutable" ); executeExecutable( "org.hibernate.test.instrument.cases.TestLazyPropertyCustomTypeExecutable" );
} }
@Test
public void testSharedPKOneToOne() { public void testSharedPKOneToOne() {
executeExecutable( "org.hibernate.test.instrument.cases.TestSharedPKOneToOneExecutable" ); executeExecutable( "org.hibernate.test.instrument.cases.TestSharedPKOneToOneExecutable" );
} }
@Test
public void testCustomColumnReadAndWrite() { public void testCustomColumnReadAndWrite() {
executeExecutable( "org.hibernate.test.instrument.cases.TestCustomColumnReadAndWrite" ); executeExecutable( "org.hibernate.test.instrument.cases.TestCustomColumnReadAndWrite" );
} }

View File

@ -1,6 +1,28 @@
/*
* 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; package org.hibernate.test.instrument.runtime;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.hibernate.bytecode.BytecodeProvider; import org.hibernate.bytecode.BytecodeProvider;
import org.hibernate.bytecode.cglib.BytecodeProviderImpl; import org.hibernate.bytecode.cglib.BytecodeProviderImpl;
@ -8,52 +30,7 @@ import org.hibernate.bytecode.cglib.BytecodeProviderImpl;
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class CGLIBInstrumentationTest extends AbstractTransformingClassLoaderInstrumentTestCase { public class CGLIBInstrumentationTest extends AbstractTransformingClassLoaderInstrumentTestCase {
public CGLIBInstrumentationTest(String string) {
super( string );
}
protected BytecodeProvider buildBytecodeProvider() { protected BytecodeProvider buildBytecodeProvider() {
return new BytecodeProviderImpl(); 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();
}
} }

View File

@ -1,7 +1,28 @@
//$Id: $ /*
* 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; package org.hibernate.test.instrument.runtime;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.hibernate.bytecode.BytecodeProvider; import org.hibernate.bytecode.BytecodeProvider;
import org.hibernate.bytecode.javassist.BytecodeProviderImpl; import org.hibernate.bytecode.javassist.BytecodeProviderImpl;
@ -9,52 +30,7 @@ import org.hibernate.bytecode.javassist.BytecodeProviderImpl;
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class JavassistInstrumentationTest extends AbstractTransformingClassLoaderInstrumentTestCase { public class JavassistInstrumentationTest extends AbstractTransformingClassLoaderInstrumentTestCase {
public JavassistInstrumentationTest(String string) {
super( string );
}
protected BytecodeProvider buildBytecodeProvider() { protected BytecodeProvider buildBytecodeProvider() {
return new BytecodeProviderImpl(); 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();
}
} }

View File

@ -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<TypeInfo> 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( "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" );
}
}
}

View File

@ -23,33 +23,36 @@
*/ */
package org.hibernate.test.jdbc.proxies; package org.hibernate.test.jdbc.proxies;
import static org.hibernate.TestLogger.LOG;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Statement; import java.sql.Statement;
import org.hibernate.ConnectionReleaseMode; import org.hibernate.ConnectionReleaseMode;
import org.hibernate.engine.jdbc.internal.LogicalConnectionImpl; import org.hibernate.engine.jdbc.internal.LogicalConnectionImpl;
import org.hibernate.engine.jdbc.internal.proxy.ProxyBuilder; 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.BasicTestingJdbcServiceImpl;
import org.hibernate.test.common.JournalingConnectionObserver; 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 * @author Steve Ebersole
*/ */
public class AggressiveReleaseTest extends UnitTestCase { public class AggressiveReleaseTest extends BaseUnitTestCase {
private BasicTestingJdbcServiceImpl services = new BasicTestingJdbcServiceImpl(); private BasicTestingJdbcServiceImpl services = new BasicTestingJdbcServiceImpl();
public AggressiveReleaseTest(String string) { @Before
super( string ); public void setUp() throws SQLException {
}
@Override
public void setUp() throws SQLException {
services.prepare( true ); services.prepare( true );
Connection connection = null; Connection connection = null;
@ -66,7 +69,6 @@ public class AggressiveReleaseTest extends UnitTestCase {
stmnt.close(); stmnt.close();
} }
catch ( SQLException ignore ) { catch ( SQLException ignore ) {
LOG.warn("could not close statement used to set up schema", ignore);
} }
} }
if ( connection != null ) { if ( connection != null ) {
@ -74,14 +76,13 @@ public class AggressiveReleaseTest extends UnitTestCase {
connection.close(); connection.close();
} }
catch ( SQLException ignore ) { catch ( SQLException ignore ) {
LOG.warn("could not close connection used to set up schema", ignore);
} }
} }
} }
} }
@Override @After
public void tearDown() throws SQLException { public void tearDown() throws SQLException {
Connection connection = null; Connection connection = null;
Statement stmnt = null; Statement stmnt = null;
try { try {
@ -95,7 +96,6 @@ public class AggressiveReleaseTest extends UnitTestCase {
stmnt.close(); stmnt.close();
} }
catch ( SQLException ignore ) { catch ( SQLException ignore ) {
LOG.warn("could not close statement used to set up schema", ignore);
} }
} }
if ( connection != null ) { if ( connection != null ) {
@ -103,7 +103,6 @@ public class AggressiveReleaseTest extends UnitTestCase {
connection.close(); connection.close();
} }
catch ( SQLException ignore ) { 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(); services.release();
} }
@Test
public void testBasicRelease() { public void testBasicRelease() {
LogicalConnectionImpl logicalConnection = new LogicalConnectionImpl( null, ConnectionReleaseMode.AFTER_STATEMENT, services ); LogicalConnectionImpl logicalConnection = new LogicalConnectionImpl( null, ConnectionReleaseMode.AFTER_STATEMENT, services );
Connection proxiedConnection = ProxyBuilder.buildConnection( logicalConnection ); Connection proxiedConnection = ProxyBuilder.buildConnection( logicalConnection );
@ -140,6 +140,7 @@ public class AggressiveReleaseTest extends UnitTestCase {
assertFalse( logicalConnection.getResourceRegistry().hasRegisteredResources() ); assertFalse( logicalConnection.getResourceRegistry().hasRegisteredResources() );
} }
@Test
public void testReleaseCircumventedByHeldResources() { public void testReleaseCircumventedByHeldResources() {
LogicalConnectionImpl logicalConnection = new LogicalConnectionImpl( null, ConnectionReleaseMode.AFTER_STATEMENT, services ); LogicalConnectionImpl logicalConnection = new LogicalConnectionImpl( null, ConnectionReleaseMode.AFTER_STATEMENT, services );
Connection proxiedConnection = ProxyBuilder.buildConnection( logicalConnection ); Connection proxiedConnection = ProxyBuilder.buildConnection( logicalConnection );
@ -193,6 +194,7 @@ public class AggressiveReleaseTest extends UnitTestCase {
assertEquals( 2, observer.getPhysicalConnectionReleasedCount() ); assertEquals( 2, observer.getPhysicalConnectionReleasedCount() );
} }
@Test
public void testReleaseCircumventedManually() { public void testReleaseCircumventedManually() {
LogicalConnectionImpl logicalConnection = new LogicalConnectionImpl( null, ConnectionReleaseMode.AFTER_STATEMENT, services ); LogicalConnectionImpl logicalConnection = new LogicalConnectionImpl( null, ConnectionReleaseMode.AFTER_STATEMENT, services );
Connection proxiedConnection = ProxyBuilder.buildConnection( logicalConnection ); Connection proxiedConnection = ProxyBuilder.buildConnection( logicalConnection );

View File

@ -28,33 +28,38 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Statement; 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.ConnectionReleaseMode;
import org.hibernate.JDBCException; import org.hibernate.JDBCException;
import org.hibernate.engine.jdbc.internal.LogicalConnectionImpl; import org.hibernate.engine.jdbc.internal.LogicalConnectionImpl;
import org.hibernate.engine.jdbc.internal.proxy.ProxyBuilder; import org.hibernate.engine.jdbc.internal.proxy.ProxyBuilder;
import org.hibernate.test.common.BasicTestingJdbcServiceImpl; import org.hibernate.test.common.BasicTestingJdbcServiceImpl;
import org.hibernate.testing.junit.UnitTestCase; import org.hibernate.testing.junit4.BaseUnitTestCase;
/** /**
* TODO : javadoc
*
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class BasicConnectionProxyTest extends UnitTestCase { public class BasicConnectionProxyTest extends BaseUnitTestCase {
private BasicTestingJdbcServiceImpl services = new BasicTestingJdbcServiceImpl(); private BasicTestingJdbcServiceImpl services = new BasicTestingJdbcServiceImpl();
public BasicConnectionProxyTest(String string) { @Before
super( string );
}
public void setUp() { public void setUp() {
services.prepare( false ); services.prepare( false );
} }
@After
public void tearDown() { public void tearDown() {
services.release(); services.release();
} }
@Test
public void testDatabaseMetaDataHandling() throws Throwable { public void testDatabaseMetaDataHandling() throws Throwable {
LogicalConnectionImpl logicalConnection = new LogicalConnectionImpl( LogicalConnectionImpl logicalConnection = new LogicalConnectionImpl(
null, null,
@ -73,7 +78,7 @@ public class BasicConnectionProxyTest extends UnitTestCase {
metaData.getSchemas(); metaData.getSchemas();
assertTrue( logicalConnection.getResourceRegistry().hasRegisteredResources() ); assertTrue( logicalConnection.getResourceRegistry().hasRegisteredResources() );
} }
catch ( SQLException sqle ) { catch ( SQLException e ) {
fail( "incorrect exception type : sqlexception" ); fail( "incorrect exception type : sqlexception" );
} }
finally { finally {
@ -82,6 +87,7 @@ public class BasicConnectionProxyTest extends UnitTestCase {
} }
} }
@Test
public void testExceptionHandling() { public void testExceptionHandling() {
LogicalConnectionImpl logicalConnection = new LogicalConnectionImpl( LogicalConnectionImpl logicalConnection = new LogicalConnectionImpl(
null, null,
@ -92,7 +98,7 @@ public class BasicConnectionProxyTest extends UnitTestCase {
try { try {
proxiedConnection.prepareStatement( "select count(*) from NON_EXISTENT" ).executeQuery(); proxiedConnection.prepareStatement( "select count(*) from NON_EXISTENT" ).executeQuery();
} }
catch ( SQLException sqle ) { catch ( SQLException e ) {
fail( "incorrect exception type : sqlexception" ); fail( "incorrect exception type : sqlexception" );
} }
catch ( JDBCException ok ) { catch ( JDBCException ok ) {
@ -103,6 +109,7 @@ public class BasicConnectionProxyTest extends UnitTestCase {
} }
} }
@Test
public void testBasicJdbcUsage() throws JDBCException { public void testBasicJdbcUsage() throws JDBCException {
LogicalConnectionImpl logicalConnection = new LogicalConnectionImpl( LogicalConnectionImpl logicalConnection = new LogicalConnectionImpl(
null, null,
@ -112,12 +119,12 @@ public class BasicConnectionProxyTest extends UnitTestCase {
Connection proxiedConnection = ProxyBuilder.buildConnection( logicalConnection ); Connection proxiedConnection = ProxyBuilder.buildConnection( logicalConnection );
try { try {
Statement stmnt = proxiedConnection.createStatement(); Statement statement = proxiedConnection.createStatement();
stmnt.execute( "drop table SANDBOX_JDBC_TST if exists" ); statement.execute( "drop table SANDBOX_JDBC_TST if exists" );
stmnt.execute( "create table SANDBOX_JDBC_TST ( ID integer, NAME varchar(100) )" ); statement.execute( "create table SANDBOX_JDBC_TST ( ID integer, NAME varchar(100) )" );
assertTrue( logicalConnection.getResourceRegistry().hasRegisteredResources() ); assertTrue( logicalConnection.getResourceRegistry().hasRegisteredResources() );
assertTrue( logicalConnection.isPhysicallyConnected() ); assertTrue( logicalConnection.isPhysicallyConnected() );
stmnt.close(); statement.close();
assertFalse( logicalConnection.getResourceRegistry().hasRegisteredResources() ); assertFalse( logicalConnection.getResourceRegistry().hasRegisteredResources() );
assertTrue( logicalConnection.isPhysicallyConnected() ); // after_transaction specified assertTrue( logicalConnection.isPhysicallyConnected() ); // after_transaction specified
@ -131,7 +138,7 @@ public class BasicConnectionProxyTest extends UnitTestCase {
assertTrue( logicalConnection.getResourceRegistry().hasRegisteredResources() ); assertTrue( logicalConnection.getResourceRegistry().hasRegisteredResources() );
} }
catch ( SQLException sqle ) { catch ( SQLException e ) {
fail( "incorrect exception type : sqlexception" ); fail( "incorrect exception type : sqlexception" );
} }
finally { finally {

View File

@ -23,6 +23,10 @@
*/ */
package org.hibernate.test.jdbc.proxies; 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.BasicBatchKey;
import org.hibernate.engine.jdbc.batch.internal.BatchBuilderImpl; import org.hibernate.engine.jdbc.batch.internal.BatchBuilderImpl;
import org.hibernate.engine.jdbc.batch.internal.BatchingBatch; 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.Expectation;
import org.hibernate.jdbc.Expectations; import org.hibernate.jdbc.Expectations;
import org.hibernate.service.internal.ServiceRegistryImpl; import org.hibernate.service.internal.ServiceRegistryImpl;
import org.hibernate.service.spi.ServiceRegistry;
import org.hibernate.service.spi.StandardServiceInitiators; 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.ConnectionProviderBuilder;
import org.hibernate.test.common.JournalingBatchObserver; import org.hibernate.test.common.JournalingBatchObserver;
import org.hibernate.test.common.JournalingTransactionObserver; import org.hibernate.test.common.JournalingTransactionObserver;
import org.hibernate.test.common.TransactionContextImpl; import org.hibernate.test.common.TransactionContextImpl;
import org.hibernate.test.common.TransactionEnvironmentImpl; import org.hibernate.test.common.TransactionEnvironmentImpl;
import org.hibernate.testing.junit.UnitTestCase;
import java.sql.Connection; import static org.junit.Assert.assertEquals;
import java.sql.PreparedStatement; import static org.junit.Assert.assertFalse;
import java.sql.Statement; import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
/** /**
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class BatchingTest extends UnitTestCase implements BatchKey { public class BatchingTest extends BaseUnitTestCase implements BatchKey {
private ServiceRegistry serviceRegistry; private ServiceRegistryImpl serviceRegistry;
public BatchingTest(String string) {
super( string );
}
@Before
public void setUp() throws Exception { public void setUp() throws Exception {
super.setUp();
serviceRegistry = new ServiceRegistryImpl( serviceRegistry = new ServiceRegistryImpl(
StandardServiceInitiators.LIST, StandardServiceInitiators.LIST,
ConnectionProviderBuilder.getConnectionProviderProperties() ConnectionProviderBuilder.getConnectionProviderProperties()
); );
} }
@After
public void tearDown() throws Exception { public void tearDown() throws Exception {
( (ServiceRegistryImpl) serviceRegistry).destroy(); serviceRegistry.destroy();
super.tearDown();
} }
@Override @Override
@ -84,6 +89,7 @@ public class BatchingTest extends UnitTestCase implements BatchKey {
return Expectations.BASIC; return Expectations.BASIC;
} }
@Test
public void testNonBatchingUsage() throws Exception { public void testNonBatchingUsage() throws Exception {
final TransactionContext transactionContext = new TransactionContextImpl( new TransactionEnvironmentImpl( serviceRegistry ) ); final TransactionContext transactionContext = new TransactionContextImpl( new TransactionEnvironmentImpl( serviceRegistry ) );
@ -141,6 +147,7 @@ public class BatchingTest extends UnitTestCase implements BatchKey {
logicalConnection.close(); logicalConnection.close();
} }
@Test
public void testBatchingUsage() throws Exception { public void testBatchingUsage() throws Exception {
final TransactionContext transactionContext = new TransactionContextImpl( new TransactionEnvironmentImpl( serviceRegistry ) ); final TransactionContext transactionContext = new TransactionContextImpl( new TransactionEnvironmentImpl( serviceRegistry ) );

View File

@ -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; package org.hibernate.test.legacy;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.hibernate.cache.Cache; import org.hibernate.cache.Cache;
import org.hibernate.cache.CacheConcurrencyStrategy; import org.hibernate.cache.CacheConcurrencyStrategy;
import org.hibernate.cache.CacheProvider; import org.hibernate.cache.CacheProvider;
import org.hibernate.cache.HashtableCacheProvider; import org.hibernate.cache.HashtableCacheProvider;
import org.hibernate.cache.ReadWriteCache; import org.hibernate.cache.ReadWriteCache;
import org.hibernate.cache.access.SoftLock; 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) { import org.hibernate.testing.junit4.BaseUnitTestCase;
super( name );
}
public static Test suite() { import static org.junit.Assert.assertTrue;
return new TestSuite( CacheTest.class );
}
public class CacheTest extends BaseUnitTestCase {
@Test
public void testCaches() throws Exception { public void testCaches() throws Exception {
doTestCache( new HashtableCacheProvider() ); doTestCache( new HashtableCacheProvider() );
} }
@ -30,111 +48,111 @@ public class CacheTest extends UnitTestCase {
long longBefore = cache.nextTimestamp(); long longBefore = cache.nextTimestamp();
Thread.sleep(15); Thread.sleep( 15 );
long before = cache.nextTimestamp(); long before = cache.nextTimestamp();
Thread.sleep(15); Thread.sleep( 15 );
//cache.setTimeout(1000); //cache.setTimeout(1000);
CacheConcurrencyStrategy ccs = new ReadWriteCache(); CacheConcurrencyStrategy ccs = new ReadWriteCache();
ccs.setCache(cache); ccs.setCache( cache );
// cache something // 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(); long after = cache.nextTimestamp();
assertTrue( ccs.get("foo", longBefore)==null ); assertTrue( ccs.get( "foo", longBefore ) == null );
assertTrue( ccs.get("foo", after).equals("foo") ); 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: // update it:
SoftLock lock = ccs.lock("foo", null); SoftLock lock = ccs.lock( "foo", null );
assertTrue( ccs.get("foo", after)==null ); assertTrue( ccs.get( "foo", after ) == null );
assertTrue( ccs.get("foo", longBefore)==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(); 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", after ) == null );
assertTrue( ccs.get("foo", longBefore)==null ); assertTrue( ccs.get( "foo", longBefore ) == null );
assertTrue( !ccs.put("foo", "bar", whileLocked, null, null, false) ); assertTrue( !ccs.put( "foo", "bar", whileLocked, null, null, false ) );
assertTrue( !ccs.put("foo", "bar", after, null, null, false) ); assertTrue( !ccs.put( "foo", "bar", after, null, null, false ) );
Thread.sleep(15); Thread.sleep( 15 );
long longAfter = cache.nextTimestamp(); 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", after ) == null );
assertTrue( ccs.get("foo", whileLocked)==null ); assertTrue( ccs.get( "foo", whileLocked ) == null );
Thread.sleep(15); Thread.sleep( 15 );
long longLongAfter = cache.nextTimestamp(); long longLongAfter = cache.nextTimestamp();
assertTrue( ccs.get("foo", longLongAfter).equals("baz") ); assertTrue( ccs.get( "foo", longLongAfter ).equals( "baz" ) );
// update it again, with multiple locks: // update it again, with multiple locks:
SoftLock lock1 = ccs.lock("foo", null); SoftLock lock1 = ccs.lock( "foo", null );
SoftLock lock2 = 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(); 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(); long betweenReleases = cache.nextTimestamp();
assertTrue( !ccs.put("foo", "bar", betweenReleases, null, null, false) ); assertTrue( !ccs.put( "foo", "bar", betweenReleases, null, null, false ) );
assertTrue( ccs.get("foo", betweenReleases)==null ); 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(); 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", whileLocked)==null ); assertTrue( ccs.get( "foo", whileLocked ) == null );
Thread.sleep(15); Thread.sleep( 15 );
longLongAfter = cache.nextTimestamp(); longLongAfter = cache.nextTimestamp();
assertTrue( ccs.get("foo", longLongAfter).equals("baz") ); assertTrue( ccs.get( "foo", longLongAfter ).equals( "baz" ) );
} }

View File

@ -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; package org.hibernate.test.legacy;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Configuration;
import org.hibernate.mapping.Bag; import org.hibernate.mapping.Bag;
import org.hibernate.mapping.Collection; import org.hibernate.mapping.Collection;
@ -11,38 +32,41 @@ import org.hibernate.mapping.Component;
import org.hibernate.mapping.MetaAttribute; import org.hibernate.mapping.MetaAttribute;
import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Property; 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; private Configuration cfg;
public NonReflectiveBinderTest(String x) {
super( x );
}
public String[] getMappings() { public String[] getMappings() {
return new String[] { "legacy/Wicked.hbm.xml"}; return new String[] { "legacy/Wicked.hbm.xml"};
} }
public static Test suite() { @Before
return new TestSuite( NonReflectiveBinderTest.class ); public void setUp() throws Exception {
}
protected void setUp() throws Exception {
super.setUp();
cfg = new Configuration() cfg = new Configuration()
.addResource( "org/hibernate/test/legacy/Wicked.hbm.xml" ) .addResource( "org/hibernate/test/legacy/Wicked.hbm.xml" )
.setProperty( "javax.persistence.validation.mode", "none" ); .setProperty( "javax.persistence.validation.mode", "none" );
cfg.buildMappings(); cfg.buildMappings();
} }
@After
protected void tearDown() throws Exception { protected void tearDown() throws Exception {
cfg = null; cfg = null;
super.tearDown();
} }
@Test
public void testMetaInheritance() { public void testMetaInheritance() {
PersistentClass cm = cfg.getClassMapping("org.hibernate.test.legacy.Wicked"); PersistentClass cm = cfg.getClassMapping("org.hibernate.test.legacy.Wicked");
Map m = cm.getMetaAttributes(); Map m = cm.getMetaAttributes();
@ -95,7 +119,8 @@ public class NonReflectiveBinderTest extends UnitTestCase {
} }
// HBX-718 @Test
@TestForIssue( jiraKey = "HBX-718" )
public void testNonMutatedInheritance() { public void testNonMutatedInheritance() {
PersistentClass cm = cfg.getClassMapping("org.hibernate.test.legacy.Wicked"); PersistentClass cm = cfg.getClassMapping("org.hibernate.test.legacy.Wicked");
MetaAttribute metaAttribute = cm.getMetaAttribute( "globalmutated" ); MetaAttribute metaAttribute = cm.getMetaAttribute( "globalmutated" );
@ -177,6 +202,7 @@ public class NonReflectiveBinderTest extends UnitTestCase {
} }
@Test
public void testComparator() { public void testComparator() {
PersistentClass cm = cfg.getClassMapping("org.hibernate.test.legacy.Wicked"); PersistentClass cm = cfg.getClassMapping("org.hibernate.test.legacy.Wicked");

View File

@ -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; 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.JoinedSubclass;
import org.hibernate.mapping.PersistentClassVisitor; import org.hibernate.mapping.PersistentClassVisitor;
import org.hibernate.mapping.RootClass; import org.hibernate.mapping.RootClass;
import org.hibernate.mapping.SingleTableSubclass; import org.hibernate.mapping.SingleTableSubclass;
import org.hibernate.mapping.Subclass; import org.hibernate.mapping.Subclass;
import org.hibernate.mapping.UnionSubclass; 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 class PersistentClassVisitorTest extends BaseUnitTestCase {
@Test
public PersistentClassVisitorTest(String string) { public void testProperCallbacks() {
super( string ); 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 { static public class PersistentClassVisitorValidator implements PersistentClassVisitor {
@ -53,24 +79,6 @@ public class PersistentClassVisitorTest extends UnitTestCase {
public Object accept(Subclass subclass) { public Object accept(Subclass subclass) {
return validate(Subclass.class, 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);
} }
} }

View File

@ -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; package org.hibernate.test.mapping;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Mappings; import org.hibernate.cfg.Mappings;
import org.hibernate.mapping.Any; import org.hibernate.mapping.Any;
@ -24,151 +42,16 @@ import org.hibernate.mapping.Set;
import org.hibernate.mapping.SimpleValue; import org.hibernate.mapping.SimpleValue;
import org.hibernate.mapping.Table; import org.hibernate.mapping.Table;
import org.hibernate.mapping.ValueVisitor; import org.hibernate.mapping.ValueVisitor;
import org.hibernate.testing.junit.UnitTestCase;
import org.junit.Test;
import org.hibernate.testing.junit4.BaseUnitTestCase;
/** /**
* @author max * @author max
*
*/ */
public class ValueVisitorTest extends UnitTestCase { public class ValueVisitorTest extends BaseUnitTestCase {
@Test
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 void testProperCallbacks() { public void testProperCallbacks() {
final Mappings mappings = new Configuration().createMappings(); final Mappings mappings = new Configuration().createMappings();
final Table tbl = new Table(); final Table tbl = new Table();
@ -190,13 +73,74 @@ public class ValueVisitorTest extends UnitTestCase {
new PrimitiveArray( mappings, rootClass ).accept(vv); new PrimitiveArray( mappings, rootClass ).accept(vv);
new Set( mappings, rootClass ).accept(vv); new Set( mappings, rootClass ).accept(vv);
new SimpleValue( mappings ).accept(vv); new SimpleValue( mappings ).accept(vv);
} }
public static Test suite() { static public class ValueVisitorValidator implements ValueVisitor {
return new TestSuite(ValueVisitorTest.class);
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);
}
} }
} }

View File

@ -8,8 +8,7 @@ import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.hibernate.DuplicateMappingException; import org.hibernate.DuplicateMappingException;
import org.hibernate.Hibernate; import org.hibernate.Hibernate;
import org.hibernate.InvalidMappingException; import org.hibernate.InvalidMappingException;
@ -17,23 +16,23 @@ import org.hibernate.MappingException;
import org.hibernate.MappingNotFoundException; import org.hibernate.MappingNotFoundException;
import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Configuration;
import org.hibernate.internal.util.ConfigHelper; 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. * Test for various mapping exceptions thrown when mappings are not found or invalid.
* *
* @author Max Rydahl Andersen * @author Max Rydahl Andersen
*/ */
public class MappingExceptionTest extends UnitTestCase { public class MappingExceptionTest extends BaseUnitTestCase {
@Test
public MappingExceptionTest(String name) {
super( name );
}
public static Test suite() {
return new TestSuite( MappingExceptionTest.class );
}
public void testNotFound() throws MappingException, MalformedURLException { public void testNotFound() throws MappingException, MalformedURLException {
Configuration cfg = new Configuration(); Configuration cfg = new Configuration();
@ -129,10 +128,16 @@ public class MappingExceptionTest extends UnitTestCase {
cfg.buildMappings(); cfg.buildMappings();
fail(); fail();
} }
catch ( InvalidMappingException inv ) { catch ( InvalidMappingException e ) {
assertEquals( inv.getType(), "resource" ); assertEquals( e.getType(), "resource" );
assertEquals( inv.getPath(), resourceName ); assertEquals( e.getPath(), resourceName );
assertClassAssignability( inv.getCause().getClass(), DuplicateMappingException.class ); 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() + "]" );
} }
} }

View File

@ -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; 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.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.SchemaExport;
import org.hibernate.tool.hbm2ddl.SchemaUpdate; import org.hibernate.tool.hbm2ddl.SchemaUpdate;
/** /**
* @author Max Rydahl Andersen * @author Max Rydahl Andersen
*/ */
public class MigrationTest extends UnitTestCase { public class MigrationTest extends BaseUnitTestCase {
private ServiceRegistry serviceRegistry;
public MigrationTest(String str) { @Before
super( str ); public void setUp() {
serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( Environment.getProperties() );
} }
public static Test suite() { @After
return new TestSuite( MigrationTest.class ); public void tearDown() {
ServiceRegistryBuilder.destroy( serviceRegistry );
serviceRegistry = null;
} }
protected JdbcServices getJdbcServices() {
return serviceRegistry.getService( JdbcServices.class );
}
@Test
public void testSimpleColumnAddition() { public void testSimpleColumnAddition() {
String resource1 = "org/hibernate/test/schemaupdate/1_Version.hbm.xml"; String resource1 = "org/hibernate/test/schemaupdate/1_Version.hbm.xml";
String resource2 = "org/hibernate/test/schemaupdate/2_Version.hbm.xml"; String resource2 = "org/hibernate/test/schemaupdate/2_Version.hbm.xml";

View File

@ -24,6 +24,11 @@
package org.hibernate.test.service; package org.hibernate.test.service;
import java.util.Properties; 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.cfg.Environment;
import org.hibernate.dialect.H2Dialect; import org.hibernate.dialect.H2Dialect;
import org.hibernate.engine.jdbc.spi.JdbcServices; 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.DriverManagerConnectionProviderImpl;
import org.hibernate.service.jdbc.connections.internal.UserSuppliedConnectionProviderImpl; import org.hibernate.service.jdbc.connections.internal.UserSuppliedConnectionProviderImpl;
import org.hibernate.service.jdbc.connections.spi.ConnectionProvider; import org.hibernate.service.jdbc.connections.spi.ConnectionProvider;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import org.hibernate.test.common.ConnectionProviderBuilder; import org.hibernate.test.common.ConnectionProviderBuilder;
import org.hibernate.testing.junit.UnitTestCase;
/** /**
* TODO : javadoc
*
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class ServiceBootstrappingTest extends UnitTestCase { public class ServiceBootstrappingTest extends BaseUnitTestCase {
public ServiceBootstrappingTest(String string) { @Test
super( string );
}
public void testBasicBuild() { public void testBasicBuild() {
ServiceRegistryImpl serviceRegistry = new ServiceRegistryImpl( ConnectionProviderBuilder.getConnectionProviderProperties() ); ServiceRegistryImpl serviceRegistry = new ServiceRegistryImpl( ConnectionProviderBuilder.getConnectionProviderProperties() );
JdbcServices jdbcServices = serviceRegistry.getService( JdbcServices.class ); JdbcServices jdbcServices = serviceRegistry.getService( JdbcServices.class );
@ -55,6 +56,7 @@ public class ServiceBootstrappingTest extends UnitTestCase {
serviceRegistry.destroy(); serviceRegistry.destroy();
} }
@Test
public void testBuildWithLogging() { public void testBuildWithLogging() {
Properties props = ConnectionProviderBuilder.getConnectionProviderProperties(); Properties props = ConnectionProviderBuilder.getConnectionProviderProperties();
props.put( Environment.SHOW_SQL, "true" ); props.put( Environment.SHOW_SQL, "true" );
@ -69,6 +71,7 @@ public class ServiceBootstrappingTest extends UnitTestCase {
serviceRegistry.destroy(); serviceRegistry.destroy();
} }
@Test
public void testBuildWithServiceOverride() { public void testBuildWithServiceOverride() {
Properties props = ConnectionProviderBuilder.getConnectionProviderProperties(); Properties props = ConnectionProviderBuilder.getConnectionProviderProperties();

View File

@ -23,50 +23,53 @@
*/ */
package org.hibernate.test.transaction.jdbc; 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.ConnectionReleaseMode;
import org.hibernate.engine.jdbc.spi.LogicalConnectionImplementor; import org.hibernate.engine.jdbc.spi.LogicalConnectionImplementor;
import org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl; import org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl;
import org.hibernate.engine.transaction.spi.TransactionContext; import org.hibernate.engine.transaction.spi.TransactionContext;
import org.hibernate.engine.transaction.spi.TransactionImplementor; import org.hibernate.engine.transaction.spi.TransactionImplementor;
import org.hibernate.service.internal.ServiceRegistryImpl; import org.hibernate.service.internal.ServiceRegistryImpl;
import org.hibernate.service.spi.ServiceRegistry;
import org.hibernate.service.spi.StandardServiceInitiators; 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.ConnectionProviderBuilder;
import org.hibernate.test.common.JournalingTransactionObserver; import org.hibernate.test.common.JournalingTransactionObserver;
import org.hibernate.test.common.TransactionContextImpl; import org.hibernate.test.common.TransactionContextImpl;
import org.hibernate.test.common.TransactionEnvironmentImpl; 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 * @author Steve Ebersole
*/ */
public class TestExpectedUsage extends UnitTestCase { public class TestExpectedUsage extends BaseUnitTestCase {
private ServiceRegistry serviceRegistry; private ServiceRegistryImpl serviceRegistry;
public TestExpectedUsage(String string) {
super( string );
}
@Before
public void setUp() throws Exception { public void setUp() throws Exception {
super.setUp();
serviceRegistry = new ServiceRegistryImpl( serviceRegistry = new ServiceRegistryImpl(
StandardServiceInitiators.LIST, StandardServiceInitiators.LIST,
ConnectionProviderBuilder.getConnectionProviderProperties() ConnectionProviderBuilder.getConnectionProviderProperties()
); );
} }
@After
public void tearDown() throws Exception { public void tearDown() throws Exception {
( (ServiceRegistryImpl) serviceRegistry).destroy(); serviceRegistry.destroy();
super.tearDown();
} }
@Test
public void testBasicUsage() { public void testBasicUsage() {
final TransactionContext transactionContext = new TransactionContextImpl( new TransactionEnvironmentImpl( serviceRegistry ) ) { final TransactionContext transactionContext = new TransactionContextImpl( new TransactionEnvironmentImpl( serviceRegistry ) ) {
@Override @Override

View File

@ -23,6 +23,21 @@
*/ */
package org.hibernate.test.transaction.jta; 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.cfg.Environment;
import org.hibernate.engine.jdbc.spi.LogicalConnectionImplementor; import org.hibernate.engine.jdbc.spi.LogicalConnectionImplementor;
import org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl; 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.internal.ServiceRegistryImpl;
import org.hibernate.service.jta.platform.internal.JtaPlatformInitiator; import org.hibernate.service.jta.platform.internal.JtaPlatformInitiator;
import org.hibernate.service.jta.platform.spi.JtaPlatform; 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.ConnectionProviderBuilder;
import org.hibernate.test.common.JournalingTransactionObserver; import org.hibernate.test.common.JournalingTransactionObserver;
import org.hibernate.test.common.TransactionContextImpl; import org.hibernate.test.common.TransactionContextImpl;
import org.hibernate.test.common.TransactionEnvironmentImpl; import org.hibernate.test.common.TransactionEnvironmentImpl;
import org.hibernate.test.common.jta.AtomikosDataSourceConnectionProvider; import org.hibernate.test.common.jta.AtomikosDataSourceConnectionProvider;
import org.hibernate.test.common.jta.AtomikosJtaPlatform; 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. * Testing transaction handling when the JTA transaction facade is the driver.
* *
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class BasicDrivingTest extends UnitTestCase { public class BasicDrivingTest extends BaseUnitTestCase {
private ServiceRegistry serviceRegistry; private ServiceRegistryImpl serviceRegistry;
public BasicDrivingTest(String string) {
super( string );
}
@Before
@SuppressWarnings( {"unchecked"})
public void setUp() throws Exception { public void setUp() throws Exception {
super.setUp();
Map configValues = new HashMap(); Map configValues = new HashMap();
configValues.putAll( ConnectionProviderBuilder.getConnectionProviderProperties() ); configValues.putAll( ConnectionProviderBuilder.getConnectionProviderProperties() );
configValues.put( Environment.TRANSACTION_STRATEGY, JtaTransactionFactory.class.getName() ); configValues.put( Environment.TRANSACTION_STRATEGY, JtaTransactionFactory.class.getName() );
configValues.put( JtaPlatformInitiator.JTA_PLATFORM, AtomikosJtaPlatform.class.getName() ); configValues.put( JtaPlatformInitiator.JTA_PLATFORM, AtomikosJtaPlatform.class.getName() );
configValues.put( Environment.CONNECTION_PROVIDER, AtomikosDataSourceConnectionProvider.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 { public void tearDown() throws Exception {
( (ServiceRegistryImpl) serviceRegistry).destroy(); serviceRegistry.destroy();
super.tearDown();
} }
@Test
public void testBasicUsage() throws Throwable { public void testBasicUsage() throws Throwable {
final TransactionContext transactionContext = new TransactionContextImpl( new TransactionEnvironmentImpl( serviceRegistry ) ); final TransactionContext transactionContext = new TransactionContextImpl( new TransactionEnvironmentImpl( serviceRegistry ) );

View File

@ -23,6 +23,14 @@
*/ */
package org.hibernate.test.transaction.jta; 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.ConnectionReleaseMode;
import org.hibernate.cfg.Environment; import org.hibernate.cfg.Environment;
import org.hibernate.engine.jdbc.spi.LogicalConnectionImplementor; 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.internal.ServiceRegistryImpl;
import org.hibernate.service.jta.platform.internal.JtaPlatformInitiator; import org.hibernate.service.jta.platform.internal.JtaPlatformInitiator;
import org.hibernate.service.jta.platform.spi.JtaPlatform; import org.hibernate.service.jta.platform.spi.JtaPlatform;
import org.hibernate.service.spi.ServiceRegistry;
import org.hibernate.service.spi.StandardServiceInitiators; 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.ConnectionProviderBuilder;
import org.hibernate.test.common.JournalingTransactionObserver; import org.hibernate.test.common.JournalingTransactionObserver;
import org.hibernate.test.common.TransactionContextImpl; import org.hibernate.test.common.TransactionContextImpl;
import org.hibernate.test.common.TransactionEnvironmentImpl; import org.hibernate.test.common.TransactionEnvironmentImpl;
import org.hibernate.test.common.jta.AtomikosDataSourceConnectionProvider; import org.hibernate.test.common.jta.AtomikosDataSourceConnectionProvider;
import org.hibernate.test.common.jta.AtomikosJtaPlatform; import org.hibernate.test.common.jta.AtomikosJtaPlatform;
import org.hibernate.testing.junit.UnitTestCase;
import javax.transaction.TransactionManager; import static org.junit.Assert.assertEquals;
import java.sql.Connection; import static org.junit.Assert.assertFalse;
import java.sql.PreparedStatement; import static org.junit.Assert.assertTrue;
import java.sql.SQLException; import static org.junit.Assert.fail;
import java.sql.Statement;
import java.util.HashMap;
import java.util.Map;
/** /**
* 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 * @author Steve Ebersole
*/ */
public class ManagedDrivingTest extends UnitTestCase { public class ManagedDrivingTest extends BaseUnitTestCase {
private ServiceRegistry serviceRegistry; private ServiceRegistryImpl serviceRegistry;
public ManagedDrivingTest(String string) {
super( string );
}
@Before
@SuppressWarnings( {"unchecked"})
public void setUp() throws Exception { public void setUp() throws Exception {
super.setUp();
Map configValues = new HashMap(); Map configValues = new HashMap();
configValues.putAll( ConnectionProviderBuilder.getConnectionProviderProperties() ); configValues.putAll( ConnectionProviderBuilder.getConnectionProviderProperties() );
configValues.put( Environment.TRANSACTION_STRATEGY, CMTTransactionFactory.class.getName() ); configValues.put( Environment.TRANSACTION_STRATEGY, CMTTransactionFactory.class.getName() );
@ -76,12 +81,12 @@ public class ManagedDrivingTest extends UnitTestCase {
serviceRegistry = new ServiceRegistryImpl( StandardServiceInitiators.LIST, configValues ); serviceRegistry = new ServiceRegistryImpl( StandardServiceInitiators.LIST, configValues );
} }
@After
public void tearDown() throws Exception { public void tearDown() throws Exception {
( (ServiceRegistryImpl) serviceRegistry).destroy(); serviceRegistry.destroy();
super.tearDown();
} }
@Test
public void testBasicUsage() throws Throwable { public void testBasicUsage() throws Throwable {
final TransactionContext transactionContext = new TransactionContextImpl( new TransactionEnvironmentImpl( serviceRegistry ) ) { final TransactionContext transactionContext = new TransactionContextImpl( new TransactionEnvironmentImpl( serviceRegistry ) ) {
@Override @Override

View File

@ -1,26 +1,27 @@
package org.hibernate.test.util; package org.hibernate.test.util;
import java.util.Properties; import java.util.Properties;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.hibernate.internal.util.config.ConfigurationHelper; 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 * @author Steve Ebersole
*/ */
public class PropertiesHelperTest extends UnitTestCase { public class PropertiesHelperTest extends BaseUnitTestCase {
private Properties props; private Properties props;
public PropertiesHelperTest(String string) { @Before
super( string ); public void setUp() throws Exception {
}
public static Test suite() {
return new TestSuite( PropertiesHelperTest.class );
}
protected void setUp() throws Exception {
props = new Properties(); props = new Properties();
props.setProperty( "my.nonexistent.prop", "${}" ); props.setProperty( "my.nonexistent.prop", "${}" );
@ -45,6 +46,7 @@ public class PropertiesHelperTest extends UnitTestCase {
props.setProperty( "parse.error", "steve" ); props.setProperty( "parse.error", "steve" );
} }
@Test
public void testPlaceholderReplacement() { public void testPlaceholderReplacement() {
ConfigurationHelper.resolvePlaceHolders( props ); ConfigurationHelper.resolvePlaceHolders( props );
@ -85,6 +87,7 @@ public class PropertiesHelperTest extends UnitTestCase {
assertEquals( "partial replacement (midst)", "basedir/tmp/myfile.txt", str ); assertEquals( "partial replacement (midst)", "basedir/tmp/myfile.txt", str );
} }
@Test
public void testParseExceptions() { public void testParseExceptions() {
boolean b = ConfigurationHelper.getBoolean( "parse.error", props ); boolean b = ConfigurationHelper.getBoolean( "parse.error", props );
assertFalse( "parse exception case - boolean", b ); assertFalse( "parse exception case - boolean", b );

View File

@ -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; package org.hibernate.test.util;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.hibernate.internal.util.StringHelper; import org.hibernate.internal.util.StringHelper;
import org.hibernate.testing.junit.UnitTestCase; 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 * @author Steve Ebersole
*/ */
public class StringHelperTest extends UnitTestCase { public class StringHelperTest extends BaseUnitTestCase {
@Test
public StringHelperTest(String string) {
super( string );
}
public static Test suite() {
return new TestSuite( StringHelperTest.class );
}
public void testAliasGeneration() { public void testAliasGeneration() {
assertSimpleAlias( "xyz", "xyz_" ); assertSimpleAlias( "xyz", "xyz_" );
assertSimpleAlias( "_xyz", "xyz_" ); assertSimpleAlias( "_xyz", "xyz_" );

View File

@ -1,23 +1,38 @@
/*
* 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; 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;
import org.junit.Test;
import org.hibernate.cfg.Configuration;
import org.hibernate.testing.junit4.BaseUnitTestCase;
/** /**
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class EntityResolverTest extends UnitTestCase { public class EntityResolverTest extends BaseUnitTestCase {
@Test
public EntityResolverTest(String name) {
super( name );
}
public static Test suite() {
return new TestSuite( EntityResolverTest.class );
}
public void testEntityIncludeResolution() { public void testEntityIncludeResolution() {
// Parent.hbm.xml contains the following entity include: // Parent.hbm.xml contains the following entity include:
// <!ENTITY child SYSTEM "classpath://org/hibernate/test/util/dtd/child.xml"> // <!ENTITY child SYSTEM "classpath://org/hibernate/test/util/dtd/child.xml">

View File

@ -24,28 +24,29 @@
package org.hibernate.testing.junit; 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 * A specialized TestCase for running tests in an isolated class-loader
* *
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public abstract class AbstractClassLoaderIsolatedTestCase extends UnitTestCase { public abstract class AbstractClassLoaderIsolatedTestCase extends BaseUnitTestCase {
private ClassLoader parentLoader; private ClassLoader parentLoader;
private ClassLoader isolatedLoader; private ClassLoader isolatedLoader;
public AbstractClassLoaderIsolatedTestCase(String string) { @Before
super( string ); public void setUp() throws Exception {
}
protected void setUp() throws Exception {
parentLoader = Thread.currentThread().getContextClassLoader(); parentLoader = Thread.currentThread().getContextClassLoader();
isolatedLoader = buildIsolatedClassLoader( parentLoader ); isolatedLoader = buildIsolatedClassLoader( parentLoader );
Thread.currentThread().setContextClassLoader( isolatedLoader ); Thread.currentThread().setContextClassLoader( isolatedLoader );
super.setUp();
} }
protected void tearDown() throws Exception { @After
super.tearDown(); public void tearDown() throws Exception {
Thread.currentThread().setContextClassLoader( parentLoader ); Thread.currentThread().setContextClassLoader( parentLoader );
releaseIsolatedClassLoader( isolatedLoader ); releaseIsolatedClassLoader( isolatedLoader );
parentLoader = null; parentLoader = null;

View File

@ -27,22 +27,29 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.UUID; 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.HibernateException;
import org.hibernate.engine.SessionImplementor; import org.hibernate.engine.SessionImplementor;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import org.hibernate.type.descriptor.java.StringTypeDescriptor; import org.hibernate.type.descriptor.java.StringTypeDescriptor;
import org.hibernate.type.descriptor.sql.VarcharTypeDescriptor; import org.hibernate.type.descriptor.sql.VarcharTypeDescriptor;
import org.hibernate.usertype.CompositeUserType; import org.hibernate.usertype.CompositeUserType;
import org.hibernate.usertype.UserType; import org.hibernate.usertype.UserType;
/** /**
* TODO : javadoc
*
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class BasicTypeRegistryTest extends TestCase { public class BasicTypeRegistryTest extends BaseUnitTestCase {
private final BasicTypeRegistry registry = new BasicTypeRegistry(); private final BasicTypeRegistry registry = new BasicTypeRegistry();
@Test
public void testOverriding() { public void testOverriding() {
BasicType type = registry.getRegisteredType( "uuid-binary" ); BasicType type = registry.getRegisteredType( "uuid-binary" );
assertSame( UUIDBinaryType.INSTANCE, type ); assertSame( UUIDBinaryType.INSTANCE, type );
@ -61,6 +68,7 @@ public class BasicTypeRegistryTest extends TestCase {
assertSame( override, type ); assertSame( override, type );
} }
@Test
public void testExpanding() { public void testExpanding() {
BasicType type = registry.getRegisteredType( SomeNoopType.INSTANCE.getName() ); BasicType type = registry.getRegisteredType( SomeNoopType.INSTANCE.getName() );
assertNull( type ); assertNull( type );
@ -71,6 +79,7 @@ public class BasicTypeRegistryTest extends TestCase {
assertSame( SomeNoopType.INSTANCE, type ); assertSame( SomeNoopType.INSTANCE, type );
} }
@Test
public void testRegisteringUserTypes() { public void testRegisteringUserTypes() {
registry.register( new TotallyIrrelevantUserType(), new String[] { "key" } ); registry.register( new TotallyIrrelevantUserType(), new String[] { "key" } );
BasicType type = registry.getRegisteredType( "key" ); BasicType type = registry.getRegisteredType( "key" );

View File

@ -36,19 +36,45 @@ import java.util.GregorianCalendar;
import java.util.Locale; import java.util.Locale;
import java.util.SimpleTimeZone; import java.util.SimpleTimeZone;
import java.util.TimeZone; 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.EntityMode;
import org.hibernate.Session; import org.hibernate.Session;
import org.hibernate.engine.SessionImplementor; import org.hibernate.engine.SessionImplementor;
import org.hibernate.internal.util.collections.ArrayHelper; import org.hibernate.internal.util.collections.ArrayHelper;
import org.hibernate.internal.util.SerializationHelper; import org.hibernate.internal.util.SerializationHelper;
import org.hibernate.testing.junit4.BaseUnitTestCase;
/** /**
* TODO : javadoc
*
* @author Steve Ebersole * @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() { public void testBigDecimalType() {
final BigDecimal original = BigDecimal.valueOf( 100 ); final BigDecimal original = BigDecimal.valueOf( 100 );
final BigDecimal copy = BigDecimal.valueOf( 100 ); final BigDecimal copy = BigDecimal.valueOf( 100 );
@ -57,6 +83,7 @@ public class TypeTest extends TestCase {
runBasicTests( BigDecimalType.INSTANCE, original, copy, different ); runBasicTests( BigDecimalType.INSTANCE, original, copy, different );
} }
@Test
public void testBigIntegerType() { public void testBigIntegerType() {
final BigInteger original = BigInteger.valueOf( 100 ); final BigInteger original = BigInteger.valueOf( 100 );
final BigInteger copy = BigInteger.valueOf( 100 ); final BigInteger copy = BigInteger.valueOf( 100 );
@ -65,6 +92,7 @@ public class TypeTest extends TestCase {
runBasicTests( BigIntegerType.INSTANCE, original, copy, different ); runBasicTests( BigIntegerType.INSTANCE, original, copy, different );
} }
@Test
public void testBinaryType() { public void testBinaryType() {
final byte[] original = new byte[] { 1, 2, 3, 4 }; final byte[] original = new byte[] { 1, 2, 3, 4 };
final byte[] copy = 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 ); runBasicTests( MaterializedBlobType.INSTANCE, original, copy, different );
} }
@Test
@SuppressWarnings( {"BooleanConstructorCall"})
public void testBooleanType() { public void testBooleanType() {
final Boolean original = Boolean.TRUE; final Boolean original = Boolean.TRUE;
final Boolean copy = new Boolean( true ); final Boolean copy = new Boolean( true );
@ -86,6 +116,7 @@ public class TypeTest extends TestCase {
runBasicTests( TrueFalseType.INSTANCE, original, copy, different ); runBasicTests( TrueFalseType.INSTANCE, original, copy, different );
} }
@Test
public void testByteType() { public void testByteType() {
final Byte original = 0; final Byte original = 0;
final Byte copy = new Byte( (byte) 0 ); final Byte copy = new Byte( (byte) 0 );
@ -94,6 +125,7 @@ public class TypeTest extends TestCase {
runBasicTests( ByteType.INSTANCE, original, copy, different ); runBasicTests( ByteType.INSTANCE, original, copy, different );
} }
@Test
public void testCalendarDateType() { public void testCalendarDateType() {
final Calendar original = new GregorianCalendar(); final Calendar original = new GregorianCalendar();
final Calendar copy = new GregorianCalendar(); final Calendar copy = new GregorianCalendar();
@ -105,6 +137,7 @@ public class TypeTest extends TestCase {
runBasicTests( CalendarDateType.INSTANCE, original, copy, different ); runBasicTests( CalendarDateType.INSTANCE, original, copy, different );
} }
@Test
public void testCalendarType() { public void testCalendarType() {
final long now = System.currentTimeMillis(); final long now = System.currentTimeMillis();
final Calendar original = new GregorianCalendar(); final Calendar original = new GregorianCalendar();
@ -119,6 +152,7 @@ public class TypeTest extends TestCase {
runBasicTests( CalendarType.INSTANCE, original, copy, different ); runBasicTests( CalendarType.INSTANCE, original, copy, different );
} }
@Test
public void testCharacterArrayType() { public void testCharacterArrayType() {
final Character[] original = new Character[] { 'a', 'b' }; final Character[] original = new Character[] { 'a', 'b' };
final Character[] copy = 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 ); runBasicTests( CharacterArrayType.INSTANCE, original, copy, different );
} }
@Test
public void testCharacterType() { public void testCharacterType() {
final Character original = 'a'; final Character original = 'a';
final Character copy = new Character( 'a' ); final Character copy = new Character( 'a' );
@ -135,6 +170,7 @@ public class TypeTest extends TestCase {
runBasicTests( CharacterType.INSTANCE, original, copy, different ); runBasicTests( CharacterType.INSTANCE, original, copy, different );
} }
@Test
public void testCharArrayType() { public void testCharArrayType() {
final char[] original = new char[] { 'a', 'b' }; final char[] original = new char[] { 'a', 'b' };
final char[] copy = 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 ); runBasicTests( CharArrayType.INSTANCE, original, copy, different );
} }
@Test
public void testClassType() { public void testClassType() {
final Class original = TypeTest.class; final Class original = TypeTest.class;
final Class copy = (Class) SerializationHelper.clone( original ); final Class copy = (Class) SerializationHelper.clone( original );
final Class different = TestCase.class; final Class different = String.class;
runBasicTests( ClassType.INSTANCE, original, copy, different ); runBasicTests( ClassType.INSTANCE, original, copy, different );
} }
@Test
public void testCurrencyType() { public void testCurrencyType() {
final Currency original = Currency.getInstance( Locale.US ); final Currency original = Currency.getInstance( Locale.US );
final Currency copy = 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 ); runBasicTests( CurrencyType.INSTANCE, original, copy, different );
} }
@Test
public void testDateType() { public void testDateType() {
final long now = System.currentTimeMillis(); final long now = System.currentTimeMillis();
final java.sql.Date original = new java.sql.Date( now ); 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 ); runBasicTests( DateType.INSTANCE, original, copy, different );
} }
@Test
public void testDoubleType() { public void testDoubleType() {
final Double original = Double.valueOf( 100 ); final Double original = Double.valueOf( 100 );
final Double copy = Double.valueOf( 100 ); final Double copy = Double.valueOf( 100 );
@ -181,6 +221,7 @@ public class TypeTest extends TestCase {
runBasicTests( DoubleType.INSTANCE, original, copy, different ); runBasicTests( DoubleType.INSTANCE, original, copy, different );
} }
@Test
public void testFloatType() { public void testFloatType() {
final Float original = Float.valueOf( 100 ); final Float original = Float.valueOf( 100 );
final Float copy = Float.valueOf( 100 ); final Float copy = Float.valueOf( 100 );
@ -189,6 +230,7 @@ public class TypeTest extends TestCase {
runBasicTests( FloatType.INSTANCE, original, copy, different ); runBasicTests( FloatType.INSTANCE, original, copy, different );
} }
@Test
public void testIntegerType() { public void testIntegerType() {
final Integer original = 100; final Integer original = 100;
final Integer copy = new Integer( 100 ); final Integer copy = new Integer( 100 );
@ -197,6 +239,7 @@ public class TypeTest extends TestCase {
runBasicTests( IntegerType.INSTANCE, original, copy, different ); runBasicTests( IntegerType.INSTANCE, original, copy, different );
} }
@Test
public void testLocaleType() { public void testLocaleType() {
final Locale original = new Locale( "ab" ); final Locale original = new Locale( "ab" );
final Locale copy = new Locale( "ab" ); final Locale copy = new Locale( "ab" );
@ -205,6 +248,7 @@ public class TypeTest extends TestCase {
runBasicTests( LocaleType.INSTANCE, original, copy, different ); runBasicTests( LocaleType.INSTANCE, original, copy, different );
} }
@Test
public void testLongType() { public void testLongType() {
final Long original = 100L; final Long original = 100L;
final Long copy = new Long( 100L ); final Long copy = new Long( 100L );
@ -218,10 +262,13 @@ public class TypeTest extends TestCase {
SerializableImpl(int number) { SerializableImpl(int number) {
this.number = number; this.number = number;
} }
@SuppressWarnings( {"EqualsWhichDoesntCheckParameterClass"})
public boolean equals(Object obj) { public boolean equals(Object obj) {
return this.number == ( (SerializableImpl) obj ).number; return this.number == ( (SerializableImpl) obj ).number;
} }
} }
@Test
public void testSerializableType() { public void testSerializableType() {
final SerializableImpl original = new SerializableImpl(1); final SerializableImpl original = new SerializableImpl(1);
final SerializableImpl copy = new SerializableImpl(1); final SerializableImpl copy = new SerializableImpl(1);
@ -231,6 +278,7 @@ public class TypeTest extends TestCase {
runBasicTests( new SerializableType<SerializableImpl>( SerializableImpl.class ), original, copy, different ); runBasicTests( new SerializableType<SerializableImpl>( SerializableImpl.class ), original, copy, different );
} }
@Test
public void testShortType() { public void testShortType() {
final Short original = 100; final Short original = 100;
final Short copy = new Short( (short) 100 ); final Short copy = new Short( (short) 100 );
@ -239,6 +287,7 @@ public class TypeTest extends TestCase {
runBasicTests( ShortType.INSTANCE, original, copy, different ); runBasicTests( ShortType.INSTANCE, original, copy, different );
} }
@Test
public void testStringType() { public void testStringType() {
final String original = "abc"; final String original = "abc";
final String copy = new String( original.toCharArray() ); final String copy = new String( original.toCharArray() );
@ -249,6 +298,7 @@ public class TypeTest extends TestCase {
runBasicTests( MaterializedClobType.INSTANCE, original, copy, different ); runBasicTests( MaterializedClobType.INSTANCE, original, copy, different );
} }
@Test
public void testTimestampType() { public void testTimestampType() {
final long now = System.currentTimeMillis(); final long now = System.currentTimeMillis();
final Timestamp original = new Timestamp( now ); final Timestamp original = new Timestamp( now );
@ -258,6 +308,7 @@ public class TypeTest extends TestCase {
runBasicTests( TimestampType.INSTANCE, original, copy, different ); runBasicTests( TimestampType.INSTANCE, original, copy, different );
} }
@Test
public void testTimeType() { public void testTimeType() {
final long now = System.currentTimeMillis(); final long now = System.currentTimeMillis();
final Time original = new Time( now ); final Time original = new Time( now );
@ -267,6 +318,7 @@ public class TypeTest extends TestCase {
runBasicTests( TimeType.INSTANCE, original, copy, different ); runBasicTests( TimeType.INSTANCE, original, copy, different );
} }
@Test
public void testDates() { public void testDates() {
final long now = System.currentTimeMillis(); final long now = System.currentTimeMillis();
final java.util.Date original = new java.util.Date( now ); 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 ); runBasicTests( DateType.INSTANCE, original, copy, different2 );
} }
@Test
public void testTimeZoneType() { public void testTimeZoneType() {
final TimeZone original = new SimpleTimeZone( -1, "abc" ); final TimeZone original = new SimpleTimeZone( -1, "abc" );
final TimeZone copy = 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 ); runBasicTests( TimeZoneType.INSTANCE, original, copy, different );
} }
protected <T> void runBasicTests(AbstractSingleColumnStandardBasicType<T> type, T original, T copy, T different) { protected <T> void runBasicTests(AbstractSingleColumnStandardBasicType<T> type, T original, T copy, T different) {
final boolean nonCopyable = Class.class.isInstance( original ) final boolean nonCopyable = Class.class.isInstance( original ) || Currency.class.isInstance( original );
|| Currency.class.isInstance( original );
if ( ! nonCopyable ) { if ( ! nonCopyable ) {
// these checks exclude classes which cannot really be cloned (singetons/enums) // these checks exclude classes which cannot really be cloned (singetons/enums)
assertFalse( original == copy ); assertFalse( original == copy );
@ -324,23 +374,4 @@ public class TypeTest extends TestCase {
assertTrue( type.isModified( original, different, ArrayHelper.TRUE, session ) ); 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() );
}
}
} }

View File

@ -25,14 +25,18 @@ package org.hibernate.type.descriptor.java;
import java.io.Serializable; import java.io.Serializable;
import java.sql.Blob; import java.sql.Blob;
import java.sql.Clob; 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 * @author Steve Ebersole
*/ */
public abstract class AbstractDescriptorTest<T> extends TestCase { public abstract class AbstractDescriptorTest<T> extends BaseUnitTestCase {
protected class Data<T> { protected class Data<T> {
private final T originalValue; private final T originalValue;
private final T copyOfOriginalValue; private final T copyOfOriginalValue;
@ -53,9 +57,8 @@ public abstract class AbstractDescriptorTest<T> extends TestCase {
private Data<T> testData; private Data<T> testData;
@Override @Before
protected void setUp() throws Exception { public void setUp() throws Exception {
super.setUp();
testData = getTestData(); testData = getTestData();
} }
@ -63,6 +66,7 @@ public abstract class AbstractDescriptorTest<T> extends TestCase {
protected abstract boolean shouldBeMutable(); protected abstract boolean shouldBeMutable();
@Test
public void testEquality() { public void testEquality() {
assertFalse( testData.originalValue == testData.copyOfOriginalValue ); assertFalse( testData.originalValue == testData.copyOfOriginalValue );
assertTrue( typeDescriptor.areEqual( testData.originalValue, testData.originalValue ) ); assertTrue( typeDescriptor.areEqual( testData.originalValue, testData.originalValue ) );
@ -70,6 +74,7 @@ public abstract class AbstractDescriptorTest<T> extends TestCase {
assertFalse( typeDescriptor.areEqual( testData.originalValue, testData.differentValue ) ); assertFalse( typeDescriptor.areEqual( testData.originalValue, testData.differentValue ) );
} }
@Test
public void testExternalization() { public void testExternalization() {
// ensure the symmetry of toString/fromString // ensure the symmetry of toString/fromString
String externalized = typeDescriptor.toString( testData.originalValue ); String externalized = typeDescriptor.toString( testData.originalValue );
@ -77,6 +82,7 @@ public abstract class AbstractDescriptorTest<T> extends TestCase {
assertTrue( typeDescriptor.areEqual( testData.originalValue, consumed ) ); assertTrue( typeDescriptor.areEqual( testData.originalValue, consumed ) );
} }
@Test
public void testMutabilityPlan() { public void testMutabilityPlan() {
assertTrue( shouldBeMutable() == typeDescriptor.getMutabilityPlan().isMutable() ); assertTrue( shouldBeMutable() == typeDescriptor.getMutabilityPlan().isMutable() );

View File

@ -25,8 +25,6 @@ package org.hibernate.type.descriptor.java;
import java.math.BigDecimal; import java.math.BigDecimal;
/** /**
* TODO : javadoc
*
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class BigDecimalDescriptorTest extends AbstractDescriptorTest<BigDecimal> { public class BigDecimalDescriptorTest extends AbstractDescriptorTest<BigDecimal> {

View File

@ -25,8 +25,6 @@ package org.hibernate.type.descriptor.java;
import java.math.BigInteger; import java.math.BigInteger;
/** /**
* TODO : javadoc
*
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class BigIntegerDescriptorTest extends AbstractDescriptorTest<BigInteger> { public class BigIntegerDescriptorTest extends AbstractDescriptorTest<BigInteger> {

View File

@ -24,11 +24,15 @@
package org.hibernate.type.descriptor.java; package org.hibernate.type.descriptor.java;
import java.sql.Blob; import java.sql.Blob;
import java.sql.SQLException; 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; import org.hibernate.engine.jdbc.BlobProxy;
/** /**
* TODO : javadoc
*
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class BlobDescriptorTest extends AbstractDescriptorTest<Blob> { public class BlobDescriptorTest extends AbstractDescriptorTest<Blob> {
@ -50,6 +54,7 @@ public class BlobDescriptorTest extends AbstractDescriptorTest<Blob> {
return false; return false;
} }
@Test
@Override @Override
public void testEquality() { public void testEquality() {
// blobs of the same internal value are not really comparable // blobs of the same internal value are not really comparable
@ -59,6 +64,7 @@ public class BlobDescriptorTest extends AbstractDescriptorTest<Blob> {
assertFalse( BlobTypeDescriptor.INSTANCE.areEqual( original, different ) ); assertFalse( BlobTypeDescriptor.INSTANCE.areEqual( original, different ) );
} }
@Test
@Override @Override
public void testExternalization() { public void testExternalization() {
// blobs of the same internal value are not really comparable // blobs of the same internal value are not really comparable

View File

@ -25,8 +25,6 @@ package org.hibernate.type.descriptor.java;
/** /**
* TODO : javadoc
*
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class BooleanDescriptorTest extends AbstractDescriptorTest<Boolean> { public class BooleanDescriptorTest extends AbstractDescriptorTest<Boolean> {

View File

@ -25,8 +25,6 @@ package org.hibernate.type.descriptor.java;
/** /**
* TODO : javadoc
*
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class StringDescriptorTest extends AbstractDescriptorTest<String> { public class StringDescriptorTest extends AbstractDescriptorTest<String> {

View File

@ -26,20 +26,23 @@ import java.sql.Clob;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; 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.LobCreator;
import org.hibernate.engine.jdbc.NonContextualLobCreator; import org.hibernate.engine.jdbc.NonContextualLobCreator;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import org.hibernate.type.descriptor.ValueBinder; import org.hibernate.type.descriptor.ValueBinder;
import org.hibernate.type.descriptor.ValueExtractor; import org.hibernate.type.descriptor.ValueExtractor;
import org.hibernate.type.descriptor.WrapperOptions; import org.hibernate.type.descriptor.WrapperOptions;
import org.hibernate.type.descriptor.java.StringTypeDescriptor; import org.hibernate.type.descriptor.java.StringTypeDescriptor;
/** /**
* TODO : javadoc
*
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class StringValueMappingTest extends TestCase { public class StringValueMappingTest extends BaseUnitTestCase {
private final StringTypeDescriptor stringJavaDescriptor = new StringTypeDescriptor(); private final StringTypeDescriptor stringJavaDescriptor = new StringTypeDescriptor();
private final VarcharTypeDescriptor varcharSqlDescriptor = new VarcharTypeDescriptor(); 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 String COLUMN_NAME = "n/a";
public static final int BIND_POSITION = -1; public static final int BIND_POSITION = -1;
@Test
public void testNormalVarcharHandling() throws SQLException { public void testNormalVarcharHandling() throws SQLException {
final ValueExtractor<String> extractor = varcharSqlDescriptor.getExtractor( stringJavaDescriptor ); final ValueExtractor<String> extractor = varcharSqlDescriptor.getExtractor( stringJavaDescriptor );
final ValueBinder<String> binder = varcharSqlDescriptor.getBinder( stringJavaDescriptor ); final ValueBinder<String> binder = varcharSqlDescriptor.getBinder( stringJavaDescriptor );
@ -76,6 +80,7 @@ public class StringValueMappingTest extends TestCase {
binder.bind( ps, fixture, BIND_POSITION, wrapperOptions ); binder.bind( ps, fixture, BIND_POSITION, wrapperOptions );
} }
@Test
public void testNullVarcharHandling() throws SQLException { public void testNullVarcharHandling() throws SQLException {
final ValueExtractor<String> extractor = varcharSqlDescriptor.getExtractor( stringJavaDescriptor ); final ValueExtractor<String> extractor = varcharSqlDescriptor.getExtractor( stringJavaDescriptor );
final ValueBinder<String> binder = varcharSqlDescriptor.getBinder( stringJavaDescriptor ); final ValueBinder<String> binder = varcharSqlDescriptor.getBinder( stringJavaDescriptor );
@ -90,6 +95,7 @@ public class StringValueMappingTest extends TestCase {
binder.bind( ps, fixture, BIND_POSITION, wrapperOptions ); binder.bind( ps, fixture, BIND_POSITION, wrapperOptions );
} }
@Test
public void testNormalClobHandling() throws SQLException { public void testNormalClobHandling() throws SQLException {
final ValueExtractor<String> extractor = clobSqlDescriptor.getExtractor( stringJavaDescriptor ); final ValueExtractor<String> extractor = clobSqlDescriptor.getExtractor( stringJavaDescriptor );
final ValueBinder<String> binder = clobSqlDescriptor.getBinder( stringJavaDescriptor ); final ValueBinder<String> binder = clobSqlDescriptor.getBinder( stringJavaDescriptor );
@ -105,6 +111,7 @@ public class StringValueMappingTest extends TestCase {
binder.bind( ps, fixture, BIND_POSITION, wrapperOptions ); binder.bind( ps, fixture, BIND_POSITION, wrapperOptions );
} }
@Test
public void testNullClobHandling() throws SQLException { public void testNullClobHandling() throws SQLException {
final ValueExtractor<String> extractor = clobSqlDescriptor.getExtractor( stringJavaDescriptor ); final ValueExtractor<String> extractor = clobSqlDescriptor.getExtractor( stringJavaDescriptor );
final ValueBinder<String> binder = clobSqlDescriptor.getBinder( stringJavaDescriptor ); final ValueBinder<String> binder = clobSqlDescriptor.getBinder( stringJavaDescriptor );

View File

@ -25,8 +25,6 @@ package org.hibernate.util;
import java.io.Serializable; import java.io.Serializable;
/** /**
* TODO : javadoc
*
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class SerializableThing implements Serializable { public class SerializableThing implements Serializable {

View File

@ -24,10 +24,17 @@
package org.hibernate.util; package org.hibernate.util;
import java.io.InputStream; import java.io.InputStream;
import java.io.Serializable; 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.LockMode;
import org.hibernate.bytecode.util.ByteCodeHelper; import org.hibernate.bytecode.util.ByteCodeHelper;
import org.hibernate.internal.util.SerializationHelper; 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} * 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 * @author Steve Ebersole
*/ */
public class SerializationHelperTest extends TestCase { public class SerializationHelperTest extends BaseUnitTestCase {
private ClassLoader original; private ClassLoader original;
private CustomClassLoader custom; private CustomClassLoader custom;
protected void setUp() throws Exception { @Before
public void setUp() throws Exception {
original = Thread.currentThread().getContextClassLoader(); original = Thread.currentThread().getContextClassLoader();
custom = new CustomClassLoader( original ); custom = new CustomClassLoader( original );
Thread.currentThread().setContextClassLoader( custom ); Thread.currentThread().setContextClassLoader( custom );
} }
protected void tearDown() throws Exception { @After
public void tearDown() throws Exception {
Thread.currentThread().setContextClassLoader( original ); Thread.currentThread().setContextClassLoader( original );
} }
@Test
public void testSerializeDeserialize() throws Exception { public void testSerializeDeserialize() throws Exception {
Class clazz = Thread.currentThread().getContextClassLoader().loadClass( "org.hibernate.util.SerializableThing" ); Class clazz = Thread.currentThread().getContextClassLoader().loadClass( "org.hibernate.util.SerializableThing" );
Object instance = clazz.newInstance(); Object instance = clazz.newInstance();

View File

@ -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 * indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are * 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, * 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 * copy, or redistribute it subject to the terms and conditions of the GNU
@ -20,32 +22,37 @@
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*/ */
package org.hibernate.util; 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.internal.util.StringHelper;
import org.hibernate.testing.junit4.BaseUnitTestCase;
/** /**
* TODO : javadoc
*
* @author Steve Ebersole * @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 BASE_PACKAGE = "org.hibernate";
private static final String STRING_HELPER_FQN = "org.hibernate.internal.util.StringHelper"; private static final String STRING_HELPER_FQN = "org.hibernate.internal.util.StringHelper";
private static final String STRING_HELPER_NAME = StringHelper.unqualify( STRING_HELPER_FQN ); private static final String STRING_HELPER_NAME = StringHelper.unqualify( STRING_HELPER_FQN );
@Test
public void testNameCollapsing() { public void testNameCollapsing() {
assertNull( StringHelper.collapse( null ) ); assertNull( StringHelper.collapse( null ) );
assertEquals( STRING_HELPER_NAME, StringHelper.collapse( STRING_HELPER_NAME ) ); assertEquals( STRING_HELPER_NAME, StringHelper.collapse( STRING_HELPER_NAME ) );
assertEquals( "o.h.i.u.StringHelper", StringHelper.collapse( STRING_HELPER_FQN ) ); assertEquals( "o.h.i.u.StringHelper", StringHelper.collapse( STRING_HELPER_FQN ) );
} }
@Test
public void testPartialNameUnqualification() { public void testPartialNameUnqualification() {
assertNull( StringHelper.partiallyUnqualify( null, BASE_PACKAGE ) ); assertNull( StringHelper.partiallyUnqualify( null, BASE_PACKAGE ) );
assertEquals( STRING_HELPER_NAME, StringHelper.partiallyUnqualify( STRING_HELPER_NAME, BASE_PACKAGE ) ); assertEquals( STRING_HELPER_NAME, StringHelper.partiallyUnqualify( STRING_HELPER_NAME, BASE_PACKAGE ) );
assertEquals( "internal.util.StringHelper", StringHelper.partiallyUnqualify( STRING_HELPER_FQN, BASE_PACKAGE ) ); assertEquals( "internal.util.StringHelper", StringHelper.partiallyUnqualify( STRING_HELPER_FQN, BASE_PACKAGE ) );
} }
@Test
public void testBasePackageCollapsing() { public void testBasePackageCollapsing() {
assertNull( StringHelper.collapseQualifierBase( null, BASE_PACKAGE ) ); assertNull( StringHelper.collapseQualifierBase( null, BASE_PACKAGE ) );
assertEquals( STRING_HELPER_NAME, StringHelper.collapseQualifierBase( STRING_HELPER_NAME, BASE_PACKAGE ) ); assertEquals( STRING_HELPER_NAME, StringHelper.collapseQualifierBase( STRING_HELPER_NAME, BASE_PACKAGE ) );

View File

@ -3,5 +3,5 @@
dependencies { dependencies {
compile( project( ':hibernate-core' ) ) compile( project( ':hibernate-core' ) )
compile( [group: 'net.sf.ehcache', name: 'ehcache-core', version: '2.3.1'] ) compile( [group: 'net.sf.ehcache', name: 'ehcache-core', version: '2.3.1'] )
testCompile( project(':hibernate-core').sourceSets.test.classes ) testCompile( project(':hibernate-testing') )
} }

View File

@ -21,12 +21,11 @@
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*/ */
package org.hibernate.testing.cache; package org.hibernate.cache;
import java.util.Map; import java.util.Map;
import org.hibernate.Session; import org.hibernate.Session;
import org.hibernate.Transaction; import org.hibernate.Transaction;
import org.hibernate.cache.ReadWriteCache;
import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment; import org.hibernate.cfg.Environment;
import org.hibernate.engine.transaction.internal.jdbc.JdbcTransactionFactory; import org.hibernate.engine.transaction.internal.jdbc.JdbcTransactionFactory;
@ -43,7 +42,7 @@ import org.hibernate.testing.tm.TransactionManagerLookupImpl;
*/ */
public abstract class BaseCacheProviderTestCase extends FunctionalTestCase { 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 // in creating specific tests for each CacheProvider that would extend
// from a base test case (this) for common requirement testing... // from a base test case (this) for common requirement testing...

View File

@ -24,7 +24,6 @@
package org.hibernate.cache; package org.hibernate.cache;
import junit.framework.Test; import junit.framework.Test;
import org.hibernate.cfg.Environment; import org.hibernate.cfg.Environment;
import org.hibernate.testing.cache.BaseCacheProviderTestCase;
import org.hibernate.testing.junit.functional.FunctionalTestClassTestSuite; import org.hibernate.testing.junit.functional.FunctionalTestClassTestSuite;
/** /**

View File

@ -21,7 +21,7 @@
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*/ */
package org.hibernate.testing.cache; package org.hibernate.cache;
/** /**

View File

@ -21,8 +21,7 @@
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*/ */
package org.hibernate.testing.cache; package org.hibernate.cache;
/** /**
* @author Steve Ebersole * @author Steve Ebersole

View File

@ -11,7 +11,7 @@ dependencies {
compile( libraries.jpa ) compile( libraries.jpa )
compile( libraries.jta ) compile( libraries.jta )
compile( libraries.javassist ) compile( libraries.javassist )
testCompile( project(':hibernate-core').sourceSets.test.classes ) testCompile( project(':hibernate-testing') )
testCompile( libraries.junit ) testCompile( libraries.junit )
testCompile( libraries.shrinkwrap_api ) testCompile( libraries.shrinkwrap_api )
testCompile( libraries.shrinkwrap ) testCompile( libraries.shrinkwrap )

View File

@ -22,26 +22,29 @@
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*/ */
package org.hibernate.ejb.test.cacheable.annotation; package org.hibernate.ejb.test.cacheable.annotation;
import java.util.Properties;
import javax.persistence.SharedCacheMode; import javax.persistence.SharedCacheMode;
import java.util.Properties;
import org.hibernate.cache.access.AccessType; import org.hibernate.cache.access.AccessType;
import org.hibernate.cache.impl.NoCachingRegionFactory; import org.hibernate.cache.impl.NoCachingRegionFactory;
import org.hibernate.cfg.Environment; import org.hibernate.cfg.Environment;
import org.hibernate.ejb.AvailableSettings; import org.hibernate.ejb.AvailableSettings;
import org.hibernate.ejb.Ejb3Configuration; import org.hibernate.ejb.Ejb3Configuration;
import org.hibernate.mapping.PersistentClass; 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 * @author Steve Ebersole
*/ */
public class ConfigurationTest extends UnitTestCase { public class ConfigurationTest extends BaseUnitTestCase {
public ConfigurationTest(String string) { @Test
super( string );
}
public void testSharedCacheModeNone() { public void testSharedCacheModeNone() {
Ejb3Configuration config = buildConfiguration( SharedCacheMode.NONE ); Ejb3Configuration config = buildConfiguration( SharedCacheMode.NONE );
@ -55,6 +58,7 @@ public class ConfigurationTest extends UnitTestCase {
assertNull( pc.getCacheConcurrencyStrategy() ); assertNull( pc.getCacheConcurrencyStrategy() );
} }
@Test
public void testSharedCacheModeUnspecified() { public void testSharedCacheModeUnspecified() {
Ejb3Configuration config = buildConfiguration( SharedCacheMode.UNSPECIFIED ); Ejb3Configuration config = buildConfiguration( SharedCacheMode.UNSPECIFIED );
@ -68,6 +72,7 @@ public class ConfigurationTest extends UnitTestCase {
assertNull( pc.getCacheConcurrencyStrategy() ); assertNull( pc.getCacheConcurrencyStrategy() );
} }
@Test
public void testSharedCacheModeAll() { public void testSharedCacheModeAll() {
Ejb3Configuration config = buildConfiguration( SharedCacheMode.ALL ); Ejb3Configuration config = buildConfiguration( SharedCacheMode.ALL );
@ -81,6 +86,7 @@ public class ConfigurationTest extends UnitTestCase {
assertNotNull( pc.getCacheConcurrencyStrategy() ); assertNotNull( pc.getCacheConcurrencyStrategy() );
} }
@Test
public void testSharedCacheModeEnable() { public void testSharedCacheModeEnable() {
Ejb3Configuration config = buildConfiguration( SharedCacheMode.ENABLE_SELECTIVE ); Ejb3Configuration config = buildConfiguration( SharedCacheMode.ENABLE_SELECTIVE );
@ -94,6 +100,7 @@ public class ConfigurationTest extends UnitTestCase {
assertNull( pc.getCacheConcurrencyStrategy() ); assertNull( pc.getCacheConcurrencyStrategy() );
} }
@Test
public void testSharedCacheModeDisable() { public void testSharedCacheModeDisable() {
Ejb3Configuration config = buildConfiguration( SharedCacheMode.DISABLE_SELECTIVE ); Ejb3Configuration config = buildConfiguration( SharedCacheMode.DISABLE_SELECTIVE );

View File

@ -12,7 +12,7 @@ dependencies {
} }
compile( libraries.ant ) compile( libraries.ant )
testCompile( libraries.testng ) testCompile( libraries.testng )
testCompile( project(':hibernate-core').sourceSets.test.classes ) testCompile( project(':hibernate-testing') )
testCompile( libraries.jpa ) testCompile( libraries.jpa )
testRuntime( libraries.h2 ) testRuntime( libraries.h2 )
testRuntime( libraries.javassist ) testRuntime( libraries.javassist )

View File

@ -3,6 +3,6 @@ apply plugin: 'java'
dependencies { dependencies {
compile( project( ':hibernate-core' ) ) compile( project( ':hibernate-core' ) )
compile( [group: 'proxool', name: 'proxool', version: '0.8.3'] ) compile( [group: 'proxool', name: 'proxool', version: '0.8.3'] )
testCompile( project(':hibernate-core').sourceSets.test.classes ) testCompile( project(':hibernate-testing') )
testRuntime( libraries.h2 ) testRuntime( libraries.h2 )
} }

View File

@ -0,0 +1,6 @@
apply plugin: 'java'
dependencies {
compile( project( ':hibernate-core' ) )
compile( [group: 'junit', name: 'junit', version: '4.8.2'] )
}

View File

@ -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 {
}

View File

@ -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 {
}

View File

@ -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 "";
}

View File

@ -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 {
}

View File

@ -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 {
}

View File

@ -23,17 +23,22 @@
*/ */
package org.hibernate.testing; package org.hibernate.testing;
import java.util.Map;
import java.util.Properties;
import org.hibernate.cfg.Environment; import org.hibernate.cfg.Environment;
import org.hibernate.internal.util.config.ConfigurationHelper; import org.hibernate.internal.util.config.ConfigurationHelper;
import org.hibernate.service.internal.ServiceRegistryImpl; import org.hibernate.service.internal.ServiceRegistryImpl;
import org.hibernate.service.spi.ServiceRegistry; import org.hibernate.service.spi.ServiceRegistry;
import java.util.Map;
import java.util.Properties;
/** /**
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class ServiceRegistryBuilder { public class ServiceRegistryBuilder {
public static ServiceRegistryImpl buildServiceRegistry() {
return buildServiceRegistry( Environment.getProperties() );
}
public static ServiceRegistryImpl buildServiceRegistry(Map serviceRegistryConfig) { public static ServiceRegistryImpl buildServiceRegistry(Map serviceRegistryConfig) {
Properties properties = new Properties(); Properties properties = new Properties();
properties.putAll( serviceRegistryConfig ); properties.putAll( serviceRegistryConfig );

View File

@ -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<? extends Matcher> condition();
/**
* A message describing the reason for the skip
*
* @return Descriptive message
*/
String message();
}

View File

@ -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();
}

View File

@ -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();
}
}

View File

@ -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();
}

View File

@ -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);
}
}

Some files were not shown because too many files have changed in this diff Show More