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 {
compile( project( ':hibernate-core' ) )
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.jacc )
provided( libraries.validation )
testCompile( project(':hibernate-testing') )
testCompile( libraries.validation )
testCompile( libraries.validator ) {
// for test runtime

View File

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

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

View File

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

View File

@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
* Copyright (c) 2008-2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Middleware LLC.
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@ -20,20 +20,21 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*
*/
package org.hibernate.connection;
import java.util.Properties;
import junit.framework.TestCase;
import org.junit.Assert;
import org.junit.Test;
import org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator;
import org.hibernate.testing.junit4.BaseUnitTestCase;
/**
* Undocumented
*
* @author kbow
*/
public class PropertiesTest extends TestCase {
public class PropertiesTest extends BaseUnitTestCase {
@Test
public void testProperties() throws Exception {
final Properties props = new Properties();
@ -46,8 +47,8 @@ public class PropertiesTest extends TestCase {
props.put("hibernate.connection.create", "true");
final Properties outputProps = ConnectionProviderInitiator.getConnectionProperties( props );
assertEquals(1, outputProps.size());
assertEquals("true", outputProps.get("create"));
Assert.assertEquals( 1, outputProps.size() );
Assert.assertEquals( "true", outputProps.get( "create" ) );
}
}

View File

@ -22,14 +22,20 @@
* Boston, MA 02110-1301 USA
*/
package org.hibernate.dialect;
import junit.framework.TestCase;
import org.junit.Test;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import static org.junit.Assert.assertEquals;
/**
* Testing of patched support for Derby limit and ofset queries; see HHH-3972
* Testing of patched support for Derby limit and offset queries; see HHH-3972
*
* @author Evan Leonard
*/
public class DerbyDialectTestCase extends TestCase {
@TestForIssue( jiraKey = "HHH-3972" )
public class DerbyDialectTestCase extends BaseUnitTestCase {
private static class LocalDerbyDialect extends DerbyDialect {
protected boolean isTenPointFiveReleaseOrNewer() {
@ -37,6 +43,7 @@ public class DerbyDialectTestCase extends TestCase {
}
}
@Test
public void testInsertLimitClause() {
final int limit = 50;
final String input = "select * from tablename t where t.cat = 5";
@ -46,6 +53,7 @@ public class DerbyDialectTestCase extends TestCase {
assertEquals( expected, actual );
}
@Test
public void testInsertLimitWithOffsetClause() {
final int limit = 50;
final int offset = 200;
@ -56,7 +64,7 @@ public class DerbyDialectTestCase extends TestCase {
assertEquals( expected, actual );
}
@Test
public void testInsertLimitWithForUpdateClause() {
final int limit = 50;
final int offset = 200;
@ -68,6 +76,7 @@ public class DerbyDialectTestCase extends TestCase {
assertEquals( expected, actual );
}
@Test
public void testInsertLimitWithWithClause() {
final int limit = 50;
final int offset = 200;
@ -79,6 +88,7 @@ public class DerbyDialectTestCase extends TestCase {
assertEquals( expected, actual );
}
@Test
public void testInsertLimitWithForUpdateAndWithClauses() {
final int limit = 50;
final int offset = 200;

View File

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

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

View File

@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
* Copyright (c) 2008-2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Middleware LLC.
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@ -20,7 +20,6 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*
*/
package org.hibernate.dialect;
import java.sql.DatabaseMetaData;
@ -30,8 +29,6 @@ import org.hibernate.service.jdbc.dialect.internal.AbstractDialectResolver;
import org.hibernate.service.jdbc.dialect.internal.BasicDialectResolver;
/**
* TODO : javadoc
*
* @author Steve Ebersole
*/
public class TestingDialects {

View File

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

View File

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

View File

@ -23,14 +23,20 @@
*
*/
package org.hibernate.engine.query;
import junit.framework.TestCase;
import org.junit.Test;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertFalse;
import org.hibernate.testing.junit4.BaseUnitTestCase;
/**
* Unit tests of the ParameterParser class
*
* @author Steve Ebersole
*/
public class ParameterParserTest extends TestCase {
public class ParameterParserTest extends BaseUnitTestCase {
@Test
public void testEscapeCallRecognition() {
assertTrue( ParameterParser.startsWithEscapeCallTemplate( "{ ? = call abc(?) }" ) );
assertFalse( ParameterParser.startsWithEscapeCallTemplate( "from User u where u.userName = ? and u.userType = 'call'" ) );

View File

@ -22,16 +22,23 @@
* Boston, MA 02110-1301 USA
*/
package org.hibernate.id;
import junit.framework.TestCase;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.fail;
import org.hibernate.testing.junit4.BaseUnitTestCase;
/**
* TODO : javadoc
*
* @author Steve Ebersole
*/
public abstract class AbstractHolderTest extends TestCase {
@SuppressWarnings( {"UnusedDeclaration"})
public abstract class AbstractHolderTest extends BaseUnitTestCase {
protected abstract IntegralDataTypeHolder makeHolder();
@Test
@SuppressWarnings( {"EmptyCatchBlock"})
public void testInitializationChecking() {
IntegralDataTypeHolder holder = makeHolder();
try {

View File

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

View File

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

View File

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

View File

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

View File

@ -28,7 +28,7 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Properties;
import junit.framework.TestCase;
import org.hibernate.Hibernate;
import org.hibernate.Session;
import org.hibernate.TestingDatabaseInfo;
@ -43,7 +43,15 @@ import org.hibernate.impl.SessionImpl;
import org.hibernate.jdbc.Work;
import org.hibernate.mapping.SimpleAuxiliaryDatabaseObject;
import org.hibernate.service.spi.ServiceRegistry;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.hibernate.testing.ServiceRegistryBuilder;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import static org.junit.Assert.assertEquals;
/**
* I went back to 3.3 source and grabbed the code/logic as it existed back then and crafted this
@ -52,7 +60,7 @@ import org.hibernate.testing.ServiceRegistryBuilder;
* @author Steve Ebersole
*/
@SuppressWarnings({ "deprecation" })
public class SequenceHiLoGeneratorTest extends TestCase {
public class SequenceHiLoGeneratorTest extends BaseUnitTestCase {
private static final String TEST_SEQUENCE = "test_sequence";
private Configuration cfg;
@ -60,10 +68,8 @@ public class SequenceHiLoGeneratorTest extends TestCase {
private SessionFactoryImplementor sessionFactory;
private SequenceHiLoGenerator generator;
@Override
protected void setUp() throws Exception {
super.setUp();
@Before
public void setUp() throws Exception {
Properties properties = new Properties();
properties.setProperty( SequenceGenerator.SEQUENCE, TEST_SEQUENCE );
properties.setProperty( SequenceHiLoGenerator.MAX_LO, "3" );
@ -99,17 +105,17 @@ public class SequenceHiLoGeneratorTest extends TestCase {
sessionFactory = (SessionFactoryImplementor) cfg.buildSessionFactory( serviceRegistry );
}
@Override
protected void tearDown() throws Exception {
@After
public void tearDown() throws Exception {
if ( sessionFactory != null ) {
sessionFactory.close();
}
if ( serviceRegistry != null ) {
ServiceRegistryBuilder.destroy( serviceRegistry );
}
super.tearDown();
}
@Test
public void testHiLoAlgorithm() {
SessionImpl session = (SessionImpl) sessionFactory.openSession();
session.beginTransaction();

View File

@ -27,8 +27,7 @@ import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Properties;
import junit.framework.TestCase;
import org.hibernate.Hibernate;
import org.hibernate.Session;
import org.hibernate.TestingDatabaseInfo;
@ -43,7 +42,15 @@ import org.hibernate.impl.SessionImpl;
import org.hibernate.jdbc.Work;
import org.hibernate.mapping.SimpleAuxiliaryDatabaseObject;
import org.hibernate.service.spi.ServiceRegistry;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.hibernate.testing.ServiceRegistryBuilder;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import static org.junit.Assert.assertEquals;
/**
* I went back to 3.3 source and grabbed the code/logic as it existed back then and crafted this
@ -52,7 +59,7 @@ import org.hibernate.testing.ServiceRegistryBuilder;
* @author Steve Ebersole
*/
@SuppressWarnings({ "deprecation" })
public class TableHiLoGeneratorTest extends TestCase {
public class TableHiLoGeneratorTest extends BaseUnitTestCase {
private static final String GEN_TABLE = "generator_table";
private static final String GEN_COLUMN = TableHiLoGenerator.DEFAULT_COLUMN_NAME;
@ -61,10 +68,8 @@ public class TableHiLoGeneratorTest extends TestCase {
private SessionFactoryImplementor sessionFactory;
private TableHiLoGenerator generator;
@Override
protected void setUp() throws Exception {
super.setUp();
@Before
public void setUp() throws Exception {
Properties properties = new Properties();
properties.setProperty( TableGenerator.TABLE, GEN_TABLE );
properties.setProperty( TableGenerator.COLUMN, GEN_COLUMN );
@ -109,18 +114,17 @@ public class TableHiLoGeneratorTest extends TestCase {
sessionFactory = (SessionFactoryImplementor) cfg.buildSessionFactory( serviceRegistry );
}
@Override
protected void tearDown() throws Exception {
@After
public void tearDown() throws Exception {
if ( sessionFactory != null ) {
sessionFactory.close();
}
if ( serviceRegistry != null ) {
ServiceRegistryBuilder.destroy( serviceRegistry );
}
super.tearDown();
}
@Test
public void testHiLoAlgorithm() {
SessionImpl session = (SessionImpl) sessionFactory.openSession();
session.beginTransaction();

View File

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

View File

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

View File

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

View File

@ -23,37 +23,44 @@
*/
package org.hibernate.jdbc;
import java.sql.*;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Reader;
import java.io.Writer;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.sql.Blob;
import java.sql.Clob;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.NClob;
import java.sql.SQLException;
import java.util.Properties;
import junit.framework.TestCase;
import org.hibernate.cfg.Environment;
import org.hibernate.engine.jdbc.internal.LobCreatorBuilder;
import org.hibernate.engine.jdbc.BlobImplementer;
import org.hibernate.engine.jdbc.ClobImplementer;
import org.hibernate.engine.jdbc.ContextualLobCreator;
import org.hibernate.engine.jdbc.LobCreationContext;
import org.hibernate.engine.jdbc.LobCreator;
import org.hibernate.engine.jdbc.BlobImplementer;
import org.hibernate.engine.jdbc.ClobImplementer;
import org.hibernate.engine.jdbc.NClobImplementer;
import org.hibernate.engine.jdbc.NonContextualLobCreator;
import org.hibernate.engine.jdbc.WrappedBlob;
import org.hibernate.engine.jdbc.WrappedClob;
import org.hibernate.engine.jdbc.NonContextualLobCreator;
import org.hibernate.engine.jdbc.internal.LobCreatorBuilder;
import org.junit.Test;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
/**
* TODO : javadoc
*
* @author Steve Ebersole
*/
public class LobCreatorTest extends TestCase {
public class LobCreatorTest extends org.hibernate.testing.junit4.BaseUnitTestCase {
@Test
public void testConnectedLobCreator() throws SQLException {
final Connection connection = createConnectionProxy( 4, new JdbcLobBuilderImpl( true ) );
LobCreationContext lobCreationContext = new LobCreationContextImpl( connection );
@ -152,7 +159,7 @@ public class LobCreatorTest extends TestCase {
this.connection = connection;
}
public Object execute( LobCreationContext.Callback callback) {
public <T> T execute(LobCreationContext.Callback<T> callback) {
try {
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,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, v. 2.1. This program is distributed in the
* hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details. You should have received a
* copy of the GNU Lesser General Public License, v.2.1 along with this
* distribution; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* Lesser General Public License, as published by the Free Software Foundation.
*
* Red Hat Author(s): Steve Ebersole
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.jdbc.util;
import java.util.StringTokenizer;
import junit.framework.TestCase;
import org.hibernate.engine.jdbc.internal.FormatStyle;
import org.junit.Test;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
/**
* BasicFormatterTest implementation
*
* @author Steve Ebersole
*/
public class BasicFormatterTest extends TestCase {
public BasicFormatterTest(String name) {
super( name );
}
public class BasicFormatterTest extends BaseUnitTestCase {
@Test
public void testNoLoss() {
assertNoLoss( "insert into Address (city, state, zip, \"from\") values (?, ?, ?, 'insert value')" );
assertNoLoss( "delete from Address where id = ? and version = ?" );

View File

@ -22,14 +22,16 @@
* Boston, MA 02110-1301 USA
*/
package org.hibernate.jmx;
import junit.framework.TestCase;
import org.junit.Test;
import org.hibernate.testing.junit4.BaseUnitTestCase;
/**
* Test copied over from o.h.t.legacy.FooBarTest
*
* @author Steve Ebersole
*/
public class TrivialTest extends TestCase {
public class TrivialTest extends BaseUnitTestCase {
@Test
public void testService() throws Exception {
HibernateService hs = new HibernateService();
hs.setJndiName( "SessionFactory" );

View File

@ -22,18 +22,18 @@
* Boston, MA 02110-1301 USA
*/
package org.hibernate.metamodel.relational;
import org.hibernate.testing.junit.UnitTestCase;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import org.hibernate.testing.junit4.BaseUnitTestCase;
/**
* TODO : javadoc
*
* @author Steve Ebersole
*/
public class ObjectNameTests extends UnitTestCase {
public ObjectNameTests(String string) {
super( string );
}
public class ObjectNameTests extends BaseUnitTestCase {
@Test
public void testMissingName() {
try {
new ObjectName( (String)null, null, null );
@ -50,6 +50,7 @@ public class ObjectNameTests extends UnitTestCase {
}
}
@Test
public void testIdentifierBuilding() {
ObjectName on = new ObjectName( "schema", "catalog", "name" );
assertEquals( "schema.catalog.name", on.getIdentifier() );

View File

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

View File

@ -22,14 +22,17 @@
* Boston, MA 02110-1301 USA
*/
package org.hibernate.property;
import junit.framework.TestCase;
import org.junit.Test;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import static org.junit.Assert.assertEquals;
/**
* TODO : javadoc
*
* @author Steve Ebersole
*/
public class BasicPropertyAccessorTest extends TestCase {
public class BasicPropertyAccessorTest extends BaseUnitTestCase {
public static abstract class Super {
public abstract Object getIt();
public abstract void setIt(Object it);
@ -80,6 +83,7 @@ public class BasicPropertyAccessorTest extends TestCase {
}
}
@Test
public void testBridgeMethodDisregarded() {
BasicPropertyAccessor accessor = new BasicPropertyAccessor();

View File

@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
* Copyright (c) 2008-2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Middleware LLC.
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@ -20,11 +20,11 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*
*/
package org.hibernate.sql;
import java.util.Collections;
import junit.framework.TestCase;
import org.hibernate.QueryException;
import org.hibernate.dialect.Dialect;
import org.hibernate.dialect.HSQLDialect;
@ -33,12 +33,16 @@ import org.hibernate.persister.entity.PropertyMapping;
import org.hibernate.sql.ordering.antlr.ColumnMapper;
import org.hibernate.type.Type;
import org.junit.Test;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import static org.junit.Assert.assertEquals;
/**
* TODO : javadoc
*
* @author Steve Ebersole
*/
public class TemplateTest extends TestCase {
public class TemplateTest extends BaseUnitTestCase {
private static final PropertyMapping PROPERTY_MAPPING = new PropertyMapping() {
public String[] toColumns(String propertyName) throws QueryException, UnsupportedOperationException {
if ( "sql".equals( propertyName ) ) {
@ -82,6 +86,7 @@ public class TemplateTest extends TestCase {
private static final SQLFunctionRegistry FUNCTION_REGISTRY = new SQLFunctionRegistry( DIALECT, Collections.EMPTY_MAP );
@Test
public void testSqlExtractFunction() {
String fragment = "extract( year from col )";
String template = Template.renderWhereStringTemplate( fragment, Template.TEMPLATE, DIALECT, FUNCTION_REGISTRY );
@ -89,6 +94,7 @@ public class TemplateTest extends TestCase {
assertEquals( "extract(year from " + Template.TEMPLATE + ".col)", template );
}
@Test
public void testSqlTrimFunction() {
String fragment = "trim( col )";
String template = Template.renderWhereStringTemplate( fragment, Template.TEMPLATE, DIALECT, FUNCTION_REGISTRY );
@ -119,6 +125,7 @@ public class TemplateTest extends TestCase {
assertEquals( "trim(both 'b' from " + Template.TEMPLATE + ".col)", template );
}
@Test
public void testSQLReferences() {
String fragment = "sql asc, sql desc";
String template = doStandardRendering( fragment );
@ -126,6 +133,7 @@ public class TemplateTest extends TestCase {
assertEquals( Template.TEMPLATE + ".sql asc, " + Template.TEMPLATE + ".sql desc", template );
}
@Test
public void testQuotedSQLReferences() {
String fragment = "`sql` asc, `sql` desc";
String template = doStandardRendering( fragment );
@ -133,6 +141,7 @@ public class TemplateTest extends TestCase {
assertEquals( Template.TEMPLATE + ".\"sql\" asc, " + Template.TEMPLATE + ".\"sql\" desc", template );
}
@Test
public void testPropertyReference() {
String fragment = "property asc, property desc";
String template = doStandardRendering( fragment );
@ -140,6 +149,7 @@ public class TemplateTest extends TestCase {
assertEquals( Template.TEMPLATE + ".prop asc, " + Template.TEMPLATE + ".prop desc", template );
}
@Test
public void testFunctionReference() {
String fragment = "upper(sql) asc, lower(sql) desc";
String template = doStandardRendering( fragment );
@ -147,6 +157,7 @@ public class TemplateTest extends TestCase {
assertEquals( "upper(" + Template.TEMPLATE + ".sql) asc, lower(" + Template.TEMPLATE + ".sql) desc", template );
}
@Test
public void testQualifiedFunctionReference() {
String fragment = "qual.upper(property) asc, qual.lower(property) desc";
String template = doStandardRendering( fragment );
@ -154,6 +165,7 @@ public class TemplateTest extends TestCase {
assertEquals( "qual.upper(" + Template.TEMPLATE + ".prop) asc, qual.lower(" + Template.TEMPLATE + ".prop) desc", template );
}
@Test
public void testDoubleQualifiedFunctionReference() {
String fragment = "qual1.qual2.upper(property) asc, qual1.qual2.lower(property) desc";
String template = doStandardRendering( fragment );
@ -161,6 +173,7 @@ public class TemplateTest extends TestCase {
assertEquals( "qual1.qual2.upper(" + Template.TEMPLATE + ".prop) asc, qual1.qual2.lower(" + Template.TEMPLATE + ".prop) desc", template );
}
@Test
public void testFunctionWithPropertyReferenceAsParam() {
String fragment = "upper(property) asc, lower(property) desc";
String template = doStandardRendering( fragment );
@ -168,6 +181,7 @@ public class TemplateTest extends TestCase {
assertEquals( "upper(" + Template.TEMPLATE + ".prop) asc, lower(" + Template.TEMPLATE + ".prop) desc", template );
}
@Test
public void testNestedFunctionReferences() {
String fragment = "upper(lower(sql)) asc, lower(upper(sql)) desc";
String template = doStandardRendering( fragment );
@ -175,6 +189,7 @@ public class TemplateTest extends TestCase {
assertEquals( "upper(lower(" + Template.TEMPLATE + ".sql)) asc, lower(upper(" + Template.TEMPLATE + ".sql)) desc", template );
}
@Test
public void testComplexNestedFunctionReferences() {
String fragment = "mod(mod(sql,2),3) asc";
String template = doStandardRendering( fragment );
@ -182,6 +197,7 @@ public class TemplateTest extends TestCase {
assertEquals( "mod(mod(" + Template.TEMPLATE + ".sql, 2), 3) asc", template );
}
@Test
public void testCollation() {
String fragment = "`sql` COLLATE my_collation, `sql` COLLATE your_collation";
String template = doStandardRendering( fragment );
@ -189,22 +205,23 @@ public class TemplateTest extends TestCase {
assertEquals( Template.TEMPLATE + ".\"sql\" collate my_collation, " + Template.TEMPLATE + ".\"sql\" collate your_collation", template );
}
@Test
public void testCollationAndOrdering() {
String fragment = "sql COLLATE my_collation, upper(prop) COLLATE your_collation asc, `sql` desc";
String template = doStandardRendering( fragment );
assertEquals( Template.TEMPLATE + ".sql collate my_collation, upper(" + Template.TEMPLATE + ".prop) collate your_collation asc, " + Template.TEMPLATE + ".\"sql\" desc", template );
}
@Test
public void testComponentReferences() {
String fragment = "component asc";
String template = doStandardRendering( fragment );
assertEquals( Template.TEMPLATE + ".comp_1 asc, " + Template.TEMPLATE + ".comp_2 asc", template );
}
@Test
public void testComponentDerefReferences() {
String fragment = "component.prop1 asc";
String template = doStandardRendering( fragment );

View File

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

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;
import java.io.PrintWriter;
import junit.framework.Test;
import junit.framework.TestSuite;
import antlr.ASTFactory;
import antlr.collections.AST;
import org.hibernate.hql.antlr.HqlTokenTypes;
import org.hibernate.hql.ast.HqlParser;
import org.hibernate.hql.ast.util.ASTIterator;
import org.hibernate.hql.ast.util.ASTParentsFirstIterator;
import org.hibernate.hql.ast.util.ASTPrinter;
import org.hibernate.hql.ast.util.ASTUtil;
import org.hibernate.testing.junit.UnitTestCase;
import antlr.ASTFactory;
import antlr.collections.AST;
import org.junit.Test;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
/**
* Test ASTIterator.
*/
public class ASTIteratorTest extends UnitTestCase {
private ASTFactory factory;
public class ASTIteratorTest extends BaseUnitTestCase {
private ASTFactory factory = new ASTFactory();
/**
* Standard JUnit test case constructor.
*
* @param name The name of the test case.
*/
public ASTIteratorTest(String name) {
super( name );
}
public static Test suite() {
return new TestSuite( ASTIteratorTest.class );
}
protected void setUp() throws Exception {
super.setUp();
factory = new ASTFactory();
}
/**
* Test a simple tree, make sure the iterator encounters every node.
*/
@Test
public void testSimpleTree() throws Exception {
String input = "select foo from foo in class org.hibernate.test.Foo, fee in class org.hibernate.test.Fee where foo.dependent = fee order by foo.string desc, foo.component.count asc, fee.id";
HqlParser parser = HqlParser.getInstance( input );
@ -65,6 +75,7 @@ public class ASTIteratorTest extends UnitTestCase {
assertNotNull( uoe );
}
@Test
public void testParentsFirstIterator() throws Exception {
AST[] tree = new AST[4];
AST grandparent = tree[0] = ASTUtil.create( factory, 1, "grandparent" );

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;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.hibernate.hql.ast.util.ASTUtil;
import org.hibernate.testing.junit.UnitTestCase;
import antlr.ASTFactory;
import antlr.collections.AST;
import org.hibernate.hql.ast.util.ASTUtil;
import org.junit.Test;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
/**
* Unit test for ASTUtil.
*/
public class ASTUtilTest extends UnitTestCase {
private ASTFactory factory;
/**
* Standard JUnit test case constructor.
*
* @param name The name of the test case.
*/
public ASTUtilTest(String name) {
super( name );
}
protected void setUp() throws Exception {
super.setUp();
factory = new ASTFactory();
}
public class ASTUtilTest extends BaseUnitTestCase {
private ASTFactory factory = new ASTFactory();
@Test
public void testCreate() throws Exception {
AST n = ASTUtil.create( factory, 1, "one");
assertNull( n.getFirstChild() );
assertEquals( "one", n.getText() );
assertEquals( 1, n.getType() );
}
/**
* Test adding a tree of children.
*/
@Test
public void testCreateTree() throws Exception {
AST[] tree = new AST[4];
AST grandparent = tree[0] = ASTUtil.create(factory, 1, "grandparent");
@ -49,6 +65,7 @@ public class ASTUtilTest extends UnitTestCase {
assertSame( baby, t.getFirstChild().getFirstChild().getFirstChild() );
}
@Test
public void testFindPreviousSibling() throws Exception {
AST child1 = ASTUtil.create(factory,2, "child1");
AST child2 = ASTUtil.create(factory,3, "child2");
@ -67,9 +84,4 @@ public class ASTUtilTest extends UnitTestCase {
}
assertNotNull(e);
}
public static Test suite() {
return new TestSuite( ASTUtilTest.class );
}
}

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

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

View File

@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2009, Red Hat Middleware LLC or third-party contributors as
* Copyright (c) 2009-2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Middleware LLC.
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@ -22,28 +22,34 @@
* Boston, MA 02110-1301 USA
*/
package org.hibernate.test.cfg;
import java.io.File;
import org.hibernate.cfg.Configuration;
import org.hibernate.internal.util.SerializationHelper;
import org.hibernate.testing.junit.UnitTestCase;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
/**
* Tests using of cacheable configuration files.
*
* @author Steve Ebersole
*/
public class CacheableFileTest extends UnitTestCase {
public class CacheableFileTest extends BaseUnitTestCase {
public static final String MAPPING = "org/hibernate/test/cfg/Cacheable.hbm.xml";
private File mappingFile;
private File mappingBinFile;
public CacheableFileTest(String string) {
super( string );
}
protected void setUp() throws Exception {
super.setUp();
@Before
public void setUp() throws Exception {
mappingFile = new File( getClass().getClassLoader().getResource( MAPPING ).toURI() );
assertTrue( mappingFile.exists() );
mappingBinFile = new File( mappingFile.getParentFile(), mappingFile.getName() + ".bin" );
@ -53,7 +59,8 @@ public class CacheableFileTest extends UnitTestCase {
}
}
protected void tearDown() throws Exception {
@After
public void tearDown() throws Exception {
if ( mappingBinFile != null && mappingBinFile.exists() ) {
// be nice
//noinspection ResultOfMethodCallIgnored
@ -61,9 +68,9 @@ public class CacheableFileTest extends UnitTestCase {
}
mappingBinFile = null;
mappingFile = null;
super.tearDown();
}
@Test
public void testCachedFiles() throws Exception {
assertFalse( mappingBinFile.exists() );
// This call should create the cached file

View File

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

View File

@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2009, Red Hat Middleware LLC or third-party contributors as
* Copyright (c) 2009-2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Middleware LLC.
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@ -29,14 +29,20 @@ import org.hibernate.cfg.Configuration;
import org.hibernate.event.DeleteEvent;
import org.hibernate.event.DeleteEventListener;
import org.hibernate.event.def.DefaultDeleteEventListener;
import org.hibernate.testing.junit.UnitTestCase;
import org.junit.Test;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
/**
* {@inheritDoc}
*
* @author Gail Badner
*/
public class ListenerTest extends UnitTestCase {
public class ListenerTest extends BaseUnitTestCase {
public static class InvalidListenerForTest {
}
@ -57,10 +63,7 @@ public class ListenerTest extends UnitTestCase {
}
}
public ListenerTest(String string) {
super( string );
}
@Test
public void testSetListenerNullClass() {
Configuration cfg = new Configuration();
assertNotNull( cfg.getEventListeners().getDeleteEventListeners() );
@ -68,6 +71,7 @@ public class ListenerTest extends UnitTestCase {
assertEquals( 0, cfg.getEventListeners().getDeleteEventListeners().length );
}
@Test
public void testSetListenersNullClass() {
Configuration cfg = new Configuration();
assertNotNull( cfg.getEventListeners().getDeleteEventListeners() );
@ -75,6 +79,7 @@ public class ListenerTest extends UnitTestCase {
assertEquals( 0, cfg.getEventListeners().getDeleteEventListeners().length );
}
@Test
public void testSetListenerEmptyClassNameArray() {
Configuration cfg = new Configuration();
assertNotNull( cfg.getEventListeners().getDeleteEventListeners() );
@ -87,6 +92,7 @@ public class ListenerTest extends UnitTestCase {
}
}
@Test
public void testSetListenersEmptyClassNsmeArray() {
Configuration cfg = new Configuration();
assertNotNull( cfg.getEventListeners().getDeleteEventListeners() );
@ -94,6 +100,7 @@ public class ListenerTest extends UnitTestCase {
assertEquals( 0, cfg.getEventListeners().getDeleteEventListeners().length );
}
@Test
public void testSetListenerEmptyClassObjectArray() {
Configuration cfg = new Configuration();
assertNotNull( cfg.getEventListeners().getDeleteEventListeners() );
@ -106,6 +113,7 @@ public class ListenerTest extends UnitTestCase {
}
}
@Test
public void testSetListenersEmptyClassObjectArray() {
Configuration cfg = new Configuration();
assertNotNull( cfg.getEventListeners().getDeleteEventListeners() );
@ -118,6 +126,7 @@ public class ListenerTest extends UnitTestCase {
}
}
@Test
public void testSetListenerEmptyClassArray() {
Configuration cfg = new Configuration();
assertNotNull( cfg.getEventListeners().getDeleteEventListeners() );
@ -130,6 +139,7 @@ public class ListenerTest extends UnitTestCase {
}
}
@Test
public void testSetListenersEmptyClassArray() {
Configuration cfg = new Configuration();
assertNotNull( cfg.getEventListeners().getDeleteEventListeners() );
@ -137,6 +147,7 @@ public class ListenerTest extends UnitTestCase {
assertEquals( 0, cfg.getEventListeners().getDeleteEventListeners().length );
}
@Test
public void testSetListenerUnknownClassName() {
Configuration cfg = new Configuration();
assertNotNull( cfg.getEventListeners().getDeleteEventListeners() );
@ -149,6 +160,7 @@ public class ListenerTest extends UnitTestCase {
}
}
@Test
public void testSetListenersUnknownClassName() {
Configuration cfg = new Configuration();
assertNotNull( cfg.getEventListeners().getDeleteEventListeners() );
@ -161,6 +173,7 @@ public class ListenerTest extends UnitTestCase {
}
}
@Test
public void testSetListenerInvalidClassName() {
Configuration cfg = new Configuration();
assertNotNull( cfg.getEventListeners().getDeleteEventListeners() );
@ -173,6 +186,7 @@ public class ListenerTest extends UnitTestCase {
}
}
@Test
public void testSetListenersInvalidClassName() {
Configuration cfg = new Configuration();
assertNotNull( cfg.getEventListeners().getDeleteEventListeners() );
@ -185,6 +199,7 @@ public class ListenerTest extends UnitTestCase {
}
}
@Test
public void testSetListenerClassName() {
Configuration cfg = new Configuration();
assertNotNull( cfg.getEventListeners().getDeleteEventListeners() );
@ -193,6 +208,7 @@ public class ListenerTest extends UnitTestCase {
assertTrue( cfg.getEventListeners().getDeleteEventListeners()[0] instanceof DeleteListenerForTest );
}
@Test
public void testSetListenersClassName() {
Configuration cfg = new Configuration();
assertNotNull( cfg.getEventListeners().getDeleteEventListeners() );
@ -201,6 +217,7 @@ public class ListenerTest extends UnitTestCase {
assertTrue( cfg.getEventListeners().getDeleteEventListeners()[0] instanceof DeleteListenerForTest );
}
@Test
public void testSetListenerClassNames() {
Configuration cfg = new Configuration();
assertNotNull( cfg.getEventListeners().getDeleteEventListeners() );
@ -218,6 +235,7 @@ public class ListenerTest extends UnitTestCase {
}
}
@Test
public void testSetListenersClassNames() {
Configuration cfg = new Configuration();
assertNotNull( cfg.getEventListeners().getDeleteEventListeners() );
@ -232,6 +250,7 @@ public class ListenerTest extends UnitTestCase {
assertTrue( cfg.getEventListeners().getDeleteEventListeners()[1] instanceof AnotherDeleteListenerForTest );
}
@Test
public void testSetListenerClassInstance() {
Configuration cfg = new Configuration();
assertNotNull( cfg.getEventListeners().getDeleteEventListeners() );
@ -239,6 +258,7 @@ public class ListenerTest extends UnitTestCase {
assertEquals( 1, cfg.getEventListeners().getDeleteEventListeners().length );
}
@Test
public void testSetListenersClassInstances() {
Configuration cfg = new Configuration();
assertNotNull( cfg.getEventListeners().getDeleteEventListeners() );
@ -253,6 +273,7 @@ public class ListenerTest extends UnitTestCase {
assertTrue( cfg.getEventListeners().getDeleteEventListeners()[1] instanceof AnotherDeleteListenerForTest );
}
@Test
public void testSetListenerInvalidClassInstance() {
Configuration cfg = new Configuration();
assertNotNull( cfg.getEventListeners().getDeleteEventListeners() );
@ -265,6 +286,7 @@ public class ListenerTest extends UnitTestCase {
}
}
@Test
public void testSetListenersInvalidClassInstances() {
Configuration cfg = new Configuration();
assertNotNull( cfg.getEventListeners().getDeleteEventListeners() );
@ -277,6 +299,7 @@ public class ListenerTest extends UnitTestCase {
}
}
@Test
public void testSetListenerNullType() {
Configuration cfg = new Configuration();
assertNotNull( cfg.getEventListeners().getDeleteEventListeners() );
@ -289,6 +312,7 @@ public class ListenerTest extends UnitTestCase {
}
}
@Test
public void testSetListenersNullType() {
Configuration cfg = new Configuration();
assertNotNull( cfg.getEventListeners().getDeleteEventListeners() );
@ -301,6 +325,7 @@ public class ListenerTest extends UnitTestCase {
}
}
@Test
public void testSetListenerUnknownType() {
Configuration cfg = new Configuration();
assertNotNull( cfg.getEventListeners().getDeleteEventListeners() );
@ -313,6 +338,7 @@ public class ListenerTest extends UnitTestCase {
}
}
@Test
public void testSetListenersUnknownType() {
Configuration cfg = new Configuration();
assertNotNull( cfg.getEventListeners().getDeleteEventListeners() );

View File

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

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

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

View File

@ -1,11 +1,10 @@
//$Id $
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2009, Red Hat Middleware LLC or third-party contributors as
* Copyright (c) 2009-2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Middleware LLC.
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@ -21,25 +20,18 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*
*/
package org.hibernate.test.dialect.unit.lockhint;
import junit.framework.TestSuite;
import org.hibernate.dialect.Dialect;
import org.hibernate.dialect.SybaseASE15Dialect;
/**
* {@inheritDoc}
*
* @author Gail Badner
*/
public class SybaseASE15LockHintsTest extends AbstractLockHintTest {
public static final Dialect DIALECT = new SybaseASE15Dialect();
public SybaseASE15LockHintsTest(String string) {
super( string );
}
protected String getLockHintUsed() {
return "holdlock";
}
@ -47,8 +39,4 @@ public class SybaseASE15LockHintsTest extends AbstractLockHintTest {
protected Dialect getDialectUnderTest() {
return DIALECT;
}
public static TestSuite suite() {
return new TestSuite( SybaseASE15LockHintsTest.class );
}
}

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

View File

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

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

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

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;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.hibernate.bytecode.BytecodeProvider;
import org.hibernate.bytecode.cglib.BytecodeProviderImpl;
@ -8,52 +30,7 @@ import org.hibernate.bytecode.cglib.BytecodeProviderImpl;
* @author Steve Ebersole
*/
public class CGLIBInstrumentationTest extends AbstractTransformingClassLoaderInstrumentTestCase {
public CGLIBInstrumentationTest(String string) {
super( string );
}
protected BytecodeProvider buildBytecodeProvider() {
return new BytecodeProviderImpl();
}
public static Test suite() {
return new TestSuite( CGLIBInstrumentationTest.class );
}
public void testSetFieldInterceptor() {
super.testSetFieldInterceptor(); //To change body of overridden methods use File | Settings | File Templates.
}
public void testDirtyCheck() {
super.testDirtyCheck(); //To change body of overridden methods use File | Settings | File Templates.
}
public void testFetchAll() throws Exception {
super.testFetchAll(); //To change body of overridden methods use File | Settings | File Templates.
}
public void testLazy() {
super.testLazy(); //To change body of overridden methods use File | Settings | File Templates.
}
public void testLazyManyToOne() {
super.testLazyManyToOne(); //To change body of overridden methods use File | Settings | File Templates.
}
public void testPropertyInitialized() {
super.testPropertyInitialized(); //To change body of overridden methods use File | Settings | File Templates.
}
public void testManyToOneProxy() {
super.testManyToOneProxy(); //To change body of overridden methods use File | Settings | File Templates.
}
public void testSharedPKOneToOne() {
super.testSharedPKOneToOne();
}
public void testCustomColumnReadAndWrite() {
super.testCustomColumnReadAndWrite();
}
}

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;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.hibernate.bytecode.BytecodeProvider;
import org.hibernate.bytecode.javassist.BytecodeProviderImpl;
@ -9,52 +30,7 @@ import org.hibernate.bytecode.javassist.BytecodeProviderImpl;
* @author Steve Ebersole
*/
public class JavassistInstrumentationTest extends AbstractTransformingClassLoaderInstrumentTestCase {
public JavassistInstrumentationTest(String string) {
super( string );
}
protected BytecodeProvider buildBytecodeProvider() {
return new BytecodeProviderImpl();
}
public static Test suite() {
return new TestSuite( JavassistInstrumentationTest.class );
}
public void testSetFieldInterceptor() {
super.testSetFieldInterceptor();
}
public void testDirtyCheck() {
super.testDirtyCheck();
}
public void testFetchAll() throws Exception {
super.testFetchAll();
}
public void testLazy() {
super.testLazy();
}
public void testLazyManyToOne() {
super.testLazyManyToOne();
}
public void testPropertyInitialized() {
super.testPropertyInitialized();
}
public void testManyToOneProxy() {
super.testManyToOneProxy();
}
public void testSharedPKOneToOne() {
super.testSharedPKOneToOne();
}
public void testCustomColumnReadAndWrite() {
super.testCustomColumnReadAndWrite();
}
}

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

View File

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

View File

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

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;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.hibernate.cache.Cache;
import org.hibernate.cache.CacheConcurrencyStrategy;
import org.hibernate.cache.CacheProvider;
import org.hibernate.cache.HashtableCacheProvider;
import org.hibernate.cache.ReadWriteCache;
import org.hibernate.cache.access.SoftLock;
import org.hibernate.testing.junit.UnitTestCase;
public class CacheTest extends UnitTestCase {
import org.junit.Test;
public CacheTest(String name) {
super( name );
}
import org.hibernate.testing.junit4.BaseUnitTestCase;
public static Test suite() {
return new TestSuite( CacheTest.class );
}
import static org.junit.Assert.assertTrue;
public class CacheTest extends BaseUnitTestCase {
@Test
public void testCaches() throws Exception {
doTestCache( new HashtableCacheProvider() );
}

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;
import java.util.Iterator;
import java.util.Map;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.hibernate.cfg.Configuration;
import org.hibernate.mapping.Bag;
import org.hibernate.mapping.Collection;
@ -11,38 +32,41 @@ import org.hibernate.mapping.Component;
import org.hibernate.mapping.MetaAttribute;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Property;
import org.hibernate.testing.junit.UnitTestCase;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
public class NonReflectiveBinderTest extends UnitTestCase {
public class NonReflectiveBinderTest extends BaseUnitTestCase {
private Configuration cfg;
public NonReflectiveBinderTest(String x) {
super( x );
}
public String[] getMappings() {
return new String[] { "legacy/Wicked.hbm.xml"};
}
public static Test suite() {
return new TestSuite( NonReflectiveBinderTest.class );
}
protected void setUp() throws Exception {
super.setUp();
@Before
public void setUp() throws Exception {
cfg = new Configuration()
.addResource( "org/hibernate/test/legacy/Wicked.hbm.xml" )
.setProperty( "javax.persistence.validation.mode", "none" );
cfg.buildMappings();
}
@After
protected void tearDown() throws Exception {
cfg = null;
super.tearDown();
}
@Test
public void testMetaInheritance() {
PersistentClass cm = cfg.getClassMapping("org.hibernate.test.legacy.Wicked");
Map m = cm.getMetaAttributes();
@ -95,7 +119,8 @@ public class NonReflectiveBinderTest extends UnitTestCase {
}
// HBX-718
@Test
@TestForIssue( jiraKey = "HBX-718" )
public void testNonMutatedInheritance() {
PersistentClass cm = cfg.getClassMapping("org.hibernate.test.legacy.Wicked");
MetaAttribute metaAttribute = cm.getMetaAttribute( "globalmutated" );
@ -177,6 +202,7 @@ public class NonReflectiveBinderTest extends UnitTestCase {
}
@Test
public void testComparator() {
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;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.junit.Test;
import org.hibernate.mapping.JoinedSubclass;
import org.hibernate.mapping.PersistentClassVisitor;
import org.hibernate.mapping.RootClass;
import org.hibernate.mapping.SingleTableSubclass;
import org.hibernate.mapping.Subclass;
import org.hibernate.mapping.UnionSubclass;
import org.hibernate.testing.junit.UnitTestCase;
import org.hibernate.testing.junit4.BaseUnitTestCase;
/**
* @author max
* Simple smoke style tests to make sure visitors keep working.
*
* @author max
*/
public class PersistentClassVisitorTest extends UnitTestCase {
public PersistentClassVisitorTest(String string) {
super( string );
public class PersistentClassVisitorTest extends BaseUnitTestCase {
@Test
public void testProperCallbacks() {
PersistentClassVisitorValidator vv = new PersistentClassVisitorValidator();
new RootClass().accept( vv );
new Subclass( new RootClass() ).accept( vv );
new JoinedSubclass( new RootClass() ).accept( vv );
new SingleTableSubclass( new RootClass() ).accept( vv );
new UnionSubclass( new RootClass() ).accept( vv );
}
static public class PersistentClassVisitorValidator implements PersistentClassVisitor {
@ -53,24 +79,6 @@ public class PersistentClassVisitorTest extends UnitTestCase {
public Object accept(Subclass subclass) {
return validate(Subclass.class, subclass);
}
};
public void testProperCallbacks() {
PersistentClassVisitorValidator vv = new PersistentClassVisitorValidator();
new RootClass().accept(vv);
new Subclass(new RootClass()).accept(vv);
new JoinedSubclass(new RootClass()).accept(vv);
new SingleTableSubclass(new RootClass()).accept(vv);
new UnionSubclass(new RootClass()).accept(vv);
}
public static Test suite() {
return new TestSuite(PersistentClassVisitorTest.class);
}
}

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;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Mappings;
import org.hibernate.mapping.Any;
@ -24,151 +42,16 @@ import org.hibernate.mapping.Set;
import org.hibernate.mapping.SimpleValue;
import org.hibernate.mapping.Table;
import org.hibernate.mapping.ValueVisitor;
import org.hibernate.testing.junit.UnitTestCase;
import org.junit.Test;
import org.hibernate.testing.junit4.BaseUnitTestCase;
/**
* @author max
*
*/
public class ValueVisitorTest extends UnitTestCase {
public ValueVisitorTest(String string) {
super( string );
}
static public class ValueVisitorValidator implements ValueVisitor {
/* (non-Javadoc)
* @see org.hibernate.mapping.ValueVisitor#accept(org.hibernate.mapping.PrimitiveArray)
*/
public Object accept(PrimitiveArray primitiveArray) {
return validate(PrimitiveArray.class,primitiveArray);
}
/*
* (non-Javadoc)
*
* @see org.hibernate.mapping.ValueVisitor#accept(org.hibernate.mapping.Bag)
*/
public Object accept(Bag bag) {
return validate(Bag.class, bag);
}
/* (non-Javadoc)
* @see org.hibernate.mapping.ValueVisitor#accept(org.hibernate.mapping.DependantValue)
*/
public Object accept(DependantValue value) {
return validate(DependantValue.class, value);
}
/**
* @param expectedClass
* @param visitee
*/
private Object validate(Class expectedClass, Object visitee) {
if (!visitee.getClass().getName().equals(expectedClass.getName())) {
throw new IllegalStateException(visitee.getClass().getName()
+ " did not call proper accept method. Was "
+ expectedClass.getName());
}
return null;
}
/*
* (non-Javadoc)
*
* @see org.hibernate.mapping.ValueVisitor#accept(org.hibernate.mapping.IdentifierBag)
*/
public Object accept(IdentifierBag bag) {
return validate(IdentifierBag.class, bag);
}
/*
* (non-Javadoc)
*
* @see org.hibernate.mapping.ValueVisitor#accept(org.hibernate.mapping.List)
*/
public Object accept(List list) {
return validate(List.class, list);
}
/*
* (non-Javadoc)
*
* @see org.hibernate.mapping.ValueVisitor#accept(org.hibernate.mapping.Map)
*/
public Object accept(Map map) {
return validate(Map.class, map);
}
/* (non-Javadoc)
* @see org.hibernate.mapping.ValueVisitor#accept(org.hibernate.mapping.Array)
*/
public Object accept(Array list) {
return validate(Array.class, list);
}
/*
* (non-Javadoc)
*
* @see org.hibernate.mapping.ValueVisitor#accept(org.hibernate.mapping.OneToMany)
*/
public Object accept(OneToMany many) {
return validate(OneToMany.class, many);
}
/*
* (non-Javadoc)
*
* @see org.hibernate.mapping.ValueVisitor#accept(org.hibernate.mapping.Set)
*/
public Object accept(Set set) {
return validate(Set.class, set);
}
/*
* (non-Javadoc)
*
* @see org.hibernate.mapping.ValueVisitor#accept(org.hibernate.mapping.Any)
*/
public Object accept(Any any) {
return validate(Any.class, any);
}
/*
* (non-Javadoc)
*
* @see org.hibernate.mapping.ValueVisitor#accept(org.hibernate.mapping.SimpleValue)
*/
public Object accept(SimpleValue value) {
return validate(SimpleValue.class, value);
}
/* (non-Javadoc)
* @see org.hibernate.mapping.ValueVisitor#accept(org.hibernate.mapping.Component)
*/
public Object accept(Component component) {
return validate(Component.class, component);
}
/* (non-Javadoc)
* @see org.hibernate.mapping.ValueVisitor#accept(org.hibernate.mapping.ManyToOne)
*/
public Object accept(ManyToOne mto) {
return validate(ManyToOne.class, mto);
}
/* (non-Javadoc)
* @see org.hibernate.mapping.ValueVisitor#accept(org.hibernate.mapping.OneToOne)
*/
public Object accept(OneToOne oto) {
return validate(OneToOne.class, oto);
}
};
public class ValueVisitorTest extends BaseUnitTestCase {
@Test
public void testProperCallbacks() {
final Mappings mappings = new Configuration().createMappings();
final Table tbl = new Table();
@ -190,13 +73,74 @@ public class ValueVisitorTest extends UnitTestCase {
new PrimitiveArray( mappings, rootClass ).accept(vv);
new Set( mappings, rootClass ).accept(vv);
new SimpleValue( mappings ).accept(vv);
}
public static Test suite() {
return new TestSuite(ValueVisitorTest.class);
static public class ValueVisitorValidator implements ValueVisitor {
public Object accept(PrimitiveArray primitiveArray) {
return validate(PrimitiveArray.class,primitiveArray);
}
public Object accept(Bag bag) {
return validate(Bag.class, bag);
}
public Object accept(DependantValue value) {
return validate(DependantValue.class, value);
}
private Object validate(Class expectedClass, Object visitee) {
if (!visitee.getClass().getName().equals(expectedClass.getName())) {
throw new IllegalStateException(visitee.getClass().getName()
+ " did not call proper accept method. Was "
+ expectedClass.getName());
}
return null;
}
public Object accept(IdentifierBag bag) {
return validate(IdentifierBag.class, bag);
}
public Object accept(List list) {
return validate(List.class, list);
}
public Object accept(Map map) {
return validate(Map.class, map);
}
public Object accept(Array list) {
return validate(Array.class, list);
}
public Object accept(OneToMany many) {
return validate(OneToMany.class, many);
}
public Object accept(Set set) {
return validate(Set.class, set);
}
public Object accept(Any any) {
return validate(Any.class, any);
}
public Object accept(SimpleValue value) {
return validate(SimpleValue.class, value);
}
public Object accept(Component component) {
return validate(Component.class, component);
}
public Object accept(ManyToOne mto) {
return validate(ManyToOne.class, mto);
}
public Object accept(OneToOne oto) {
return validate(OneToOne.class, oto);
}
}
}

View File

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

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

View File

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

View File

@ -23,50 +23,53 @@
*/
package org.hibernate.test.transaction.jdbc;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
import org.hibernate.ConnectionReleaseMode;
import org.hibernate.engine.jdbc.spi.LogicalConnectionImplementor;
import org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl;
import org.hibernate.engine.transaction.spi.TransactionContext;
import org.hibernate.engine.transaction.spi.TransactionImplementor;
import org.hibernate.service.internal.ServiceRegistryImpl;
import org.hibernate.service.spi.ServiceRegistry;
import org.hibernate.service.spi.StandardServiceInitiators;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import org.hibernate.test.common.ConnectionProviderBuilder;
import org.hibernate.test.common.JournalingTransactionObserver;
import org.hibernate.test.common.TransactionContextImpl;
import org.hibernate.test.common.TransactionEnvironmentImpl;
import org.hibernate.testing.junit.UnitTestCase;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
/**
* TODO : javadoc
*
* @author Steve Ebersole
*/
public class TestExpectedUsage extends UnitTestCase {
private ServiceRegistry serviceRegistry;
public TestExpectedUsage(String string) {
super( string );
}
public class TestExpectedUsage extends BaseUnitTestCase {
private ServiceRegistryImpl serviceRegistry;
@Before
public void setUp() throws Exception {
super.setUp();
serviceRegistry = new ServiceRegistryImpl(
StandardServiceInitiators.LIST,
ConnectionProviderBuilder.getConnectionProviderProperties()
);
}
@After
public void tearDown() throws Exception {
( (ServiceRegistryImpl) serviceRegistry).destroy();
super.tearDown();
serviceRegistry.destroy();
}
@Test
public void testBasicUsage() {
final TransactionContext transactionContext = new TransactionContextImpl( new TransactionEnvironmentImpl( serviceRegistry ) ) {
@Override

View File

@ -23,6 +23,21 @@
*/
package org.hibernate.test.transaction.jta;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.HashMap;
import java.util.Map;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import org.hibernate.cfg.Environment;
import org.hibernate.engine.jdbc.spi.LogicalConnectionImplementor;
import org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl;
@ -33,51 +48,40 @@ import org.hibernate.service.internal.ServiceProxy;
import org.hibernate.service.internal.ServiceRegistryImpl;
import org.hibernate.service.jta.platform.internal.JtaPlatformInitiator;
import org.hibernate.service.jta.platform.spi.JtaPlatform;
import org.hibernate.service.spi.ServiceRegistry;
import org.hibernate.service.spi.StandardServiceInitiators;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import org.hibernate.test.common.ConnectionProviderBuilder;
import org.hibernate.test.common.JournalingTransactionObserver;
import org.hibernate.test.common.TransactionContextImpl;
import org.hibernate.test.common.TransactionEnvironmentImpl;
import org.hibernate.test.common.jta.AtomikosDataSourceConnectionProvider;
import org.hibernate.test.common.jta.AtomikosJtaPlatform;
import org.hibernate.testing.junit.UnitTestCase;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.HashMap;
import java.util.Map;
/**
* Testing transaction handling when the JTA transaction facade is the driver.
*
* @author Steve Ebersole
*/
public class BasicDrivingTest extends UnitTestCase {
private ServiceRegistry serviceRegistry;
public BasicDrivingTest(String string) {
super( string );
}
public class BasicDrivingTest extends BaseUnitTestCase {
private ServiceRegistryImpl serviceRegistry;
@Before
@SuppressWarnings( {"unchecked"})
public void setUp() throws Exception {
super.setUp();
Map configValues = new HashMap();
configValues.putAll( ConnectionProviderBuilder.getConnectionProviderProperties() );
configValues.put( Environment.TRANSACTION_STRATEGY, JtaTransactionFactory.class.getName() );
configValues.put( JtaPlatformInitiator.JTA_PLATFORM, AtomikosJtaPlatform.class.getName() );
configValues.put( Environment.CONNECTION_PROVIDER, AtomikosDataSourceConnectionProvider.class.getName() );
serviceRegistry = new ServiceRegistryImpl( StandardServiceInitiators.LIST, configValues );
serviceRegistry = new ServiceRegistryImpl( configValues );
}
@After
public void tearDown() throws Exception {
( (ServiceRegistryImpl) serviceRegistry).destroy();
super.tearDown();
serviceRegistry.destroy();
}
@Test
public void testBasicUsage() throws Throwable {
final TransactionContext transactionContext = new TransactionContextImpl( new TransactionEnvironmentImpl( serviceRegistry ) );

View File

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

View File

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

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

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;
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
*/
public class EntityResolverTest extends UnitTestCase {
public EntityResolverTest(String name) {
super( name );
}
public static Test suite() {
return new TestSuite( EntityResolverTest.class );
}
public class EntityResolverTest extends BaseUnitTestCase {
@Test
public void testEntityIncludeResolution() {
// Parent.hbm.xml contains the following entity include:
// <!ENTITY child SYSTEM "classpath://org/hibernate/test/util/dtd/child.xml">

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -24,10 +24,17 @@
package org.hibernate.util;
import java.io.InputStream;
import java.io.Serializable;
import junit.framework.TestCase;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import org.hibernate.LockMode;
import org.hibernate.bytecode.util.ByteCodeHelper;
import org.hibernate.internal.util.SerializationHelper;
import org.hibernate.testing.junit4.BaseUnitTestCase;
/**
* This is basically a test to assert the expectations of {@link org.hibernate.type.SerializableType}
@ -35,21 +42,23 @@ import org.hibernate.internal.util.SerializationHelper;
*
* @author Steve Ebersole
*/
public class SerializationHelperTest extends TestCase {
public class SerializationHelperTest extends BaseUnitTestCase {
private ClassLoader original;
private CustomClassLoader custom;
protected void setUp() throws Exception {
@Before
public void setUp() throws Exception {
original = Thread.currentThread().getContextClassLoader();
custom = new CustomClassLoader( original );
Thread.currentThread().setContextClassLoader( custom );
}
protected void tearDown() throws Exception {
@After
public void tearDown() throws Exception {
Thread.currentThread().setContextClassLoader( original );
}
@Test
public void testSerializeDeserialize() throws Exception {
Class clazz = Thread.currentThread().getContextClassLoader().loadClass( "org.hibernate.util.SerializableThing" );
Object instance = clazz.newInstance();

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
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Middleware LLC.
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@ -20,32 +22,37 @@
* Boston, MA 02110-1301 USA
*/
package org.hibernate.util;
import junit.framework.TestCase;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.testing.junit4.BaseUnitTestCase;
/**
* TODO : javadoc
*
* @author Steve Ebersole
*/
public class StringHelperTest extends TestCase {
public class StringHelperTest extends BaseUnitTestCase {
private static final String BASE_PACKAGE = "org.hibernate";
private static final String STRING_HELPER_FQN = "org.hibernate.internal.util.StringHelper";
private static final String STRING_HELPER_NAME = StringHelper.unqualify( STRING_HELPER_FQN );
@Test
public void testNameCollapsing() {
assertNull( StringHelper.collapse( null ) );
assertEquals( STRING_HELPER_NAME, StringHelper.collapse( STRING_HELPER_NAME ) );
assertEquals( "o.h.i.u.StringHelper", StringHelper.collapse( STRING_HELPER_FQN ) );
}
@Test
public void testPartialNameUnqualification() {
assertNull( StringHelper.partiallyUnqualify( null, BASE_PACKAGE ) );
assertEquals( STRING_HELPER_NAME, StringHelper.partiallyUnqualify( STRING_HELPER_NAME, BASE_PACKAGE ) );
assertEquals( "internal.util.StringHelper", StringHelper.partiallyUnqualify( STRING_HELPER_FQN, BASE_PACKAGE ) );
}
@Test
public void testBasePackageCollapsing() {
assertNull( StringHelper.collapseQualifierBase( null, BASE_PACKAGE ) );
assertEquals( STRING_HELPER_NAME, StringHelper.collapseQualifierBase( STRING_HELPER_NAME, BASE_PACKAGE ) );

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

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;
import java.util.Map;
import java.util.Properties;
import org.hibernate.cfg.Environment;
import org.hibernate.internal.util.config.ConfigurationHelper;
import org.hibernate.service.internal.ServiceRegistryImpl;
import org.hibernate.service.spi.ServiceRegistry;
import java.util.Map;
import java.util.Properties;
/**
* @author Steve Ebersole
*/
public class ServiceRegistryBuilder {
public static ServiceRegistryImpl buildServiceRegistry() {
return buildServiceRegistry( Environment.getProperties() );
}
public static ServiceRegistryImpl buildServiceRegistry(Map serviceRegistryConfig) {
Properties properties = new Properties();
properties.putAll( serviceRegistryConfig );

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