HHH-6742 move unit tests back to src/test
This commit is contained in:
parent
98e68aab4b
commit
036b9579d6
|
@ -26,6 +26,7 @@ package org.hibernate.test.version.sybase;
|
|||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.dialect.SybaseASE15Dialect;
|
||||
import org.hibernate.dialect.SybaseDialect;
|
||||
import org.hibernate.type.BinaryType;
|
||||
|
||||
|
@ -43,7 +44,7 @@ import static org.junit.Assert.fail;
|
|||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
@RequiresDialect( SybaseDialect.class )
|
||||
@RequiresDialect( SybaseASE15Dialect.class )
|
||||
public class SybaseTimestampVersioningTest extends BaseCoreFunctionalTestCase {
|
||||
public String[] getMappings() {
|
||||
return new String[] { "version/sybase/User.hbm.xml" };
|
||||
|
|
|
@ -1,158 +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.testing.tm;
|
||||
|
||||
import javax.transaction.HeuristicMixedException;
|
||||
import javax.transaction.HeuristicRollbackException;
|
||||
import javax.transaction.RollbackException;
|
||||
import javax.transaction.Status;
|
||||
import javax.transaction.Synchronization;
|
||||
import javax.transaction.SystemException;
|
||||
import javax.transaction.Transaction;
|
||||
import javax.transaction.xa.XAResource;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.LinkedList;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
/**
|
||||
* SimpleJtaTransactionImpl implementation
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class SimpleJtaTransactionImpl implements Transaction {
|
||||
private static final Logger log = Logger.getLogger( SimpleJtaTransactionImpl.class );
|
||||
|
||||
private int status;
|
||||
private LinkedList synchronizations;
|
||||
private Connection connection; // the only resource we care about is jdbc connection
|
||||
private final SimpleJtaTransactionManagerImpl jtaTransactionManager;
|
||||
|
||||
public SimpleJtaTransactionImpl(SimpleJtaTransactionManagerImpl jtaTransactionManager) {
|
||||
this.jtaTransactionManager = jtaTransactionManager;
|
||||
this.status = Status.STATUS_ACTIVE;
|
||||
}
|
||||
|
||||
public int getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void commit()
|
||||
throws RollbackException, HeuristicMixedException, HeuristicRollbackException, IllegalStateException, SystemException {
|
||||
|
||||
if ( status == Status.STATUS_MARKED_ROLLBACK ) {
|
||||
log.trace("on commit, status was marked for rollback-only");
|
||||
rollback();
|
||||
}
|
||||
else {
|
||||
status = Status.STATUS_PREPARING;
|
||||
|
||||
for ( int i = 0; i < synchronizations.size(); i++ ) {
|
||||
Synchronization s = ( Synchronization ) synchronizations.get( i );
|
||||
s.beforeCompletion();
|
||||
}
|
||||
|
||||
status = Status.STATUS_COMMITTING;
|
||||
|
||||
if ( connection != null ) {
|
||||
try {
|
||||
connection.commit();
|
||||
connection.close();
|
||||
}
|
||||
catch ( SQLException sqle ) {
|
||||
status = Status.STATUS_UNKNOWN;
|
||||
throw new SystemException();
|
||||
}
|
||||
}
|
||||
|
||||
status = Status.STATUS_COMMITTED;
|
||||
|
||||
for ( int i = 0; i < synchronizations.size(); i++ ) {
|
||||
Synchronization s = ( Synchronization ) synchronizations.get( i );
|
||||
s.afterCompletion( status );
|
||||
}
|
||||
|
||||
//status = Status.STATUS_NO_TRANSACTION;
|
||||
jtaTransactionManager.endCurrent( this );
|
||||
}
|
||||
}
|
||||
|
||||
public void rollback() throws IllegalStateException, SystemException {
|
||||
status = Status.STATUS_ROLLEDBACK;
|
||||
|
||||
if ( connection != null ) {
|
||||
try {
|
||||
connection.rollback();
|
||||
connection.close();
|
||||
}
|
||||
catch ( SQLException sqle ) {
|
||||
status = Status.STATUS_UNKNOWN;
|
||||
throw new SystemException();
|
||||
}
|
||||
}
|
||||
|
||||
for ( int i = 0; i < synchronizations.size(); i++ ) {
|
||||
Synchronization s = ( Synchronization ) synchronizations.get( i );
|
||||
s.afterCompletion( status );
|
||||
}
|
||||
|
||||
//status = Status.STATUS_NO_TRANSACTION;
|
||||
jtaTransactionManager.endCurrent( this );
|
||||
}
|
||||
|
||||
public void setRollbackOnly() throws IllegalStateException, SystemException {
|
||||
status = Status.STATUS_MARKED_ROLLBACK;
|
||||
}
|
||||
|
||||
public void registerSynchronization(Synchronization synchronization)
|
||||
throws RollbackException, IllegalStateException, SystemException {
|
||||
// todo : find the spec-allowable statuses during which synch can be registered...
|
||||
if ( synchronizations == null ) {
|
||||
synchronizations = new LinkedList();
|
||||
}
|
||||
synchronizations.add( synchronization );
|
||||
}
|
||||
|
||||
public void enlistConnection(Connection connection) {
|
||||
if ( this.connection != null ) {
|
||||
throw new IllegalStateException( "Connection already registered" );
|
||||
}
|
||||
this.connection = connection;
|
||||
}
|
||||
|
||||
public Connection getEnlistedConnection() {
|
||||
return connection;
|
||||
}
|
||||
|
||||
|
||||
public boolean enlistResource(XAResource xaResource)
|
||||
throws RollbackException, IllegalStateException, SystemException {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean delistResource(XAResource xaResource, int i) throws IllegalStateException, SystemException {
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -1,109 +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.testing.tm;
|
||||
import javax.transaction.HeuristicMixedException;
|
||||
import javax.transaction.HeuristicRollbackException;
|
||||
import javax.transaction.InvalidTransactionException;
|
||||
import javax.transaction.NotSupportedException;
|
||||
import javax.transaction.RollbackException;
|
||||
import javax.transaction.Status;
|
||||
import javax.transaction.SystemException;
|
||||
import javax.transaction.Transaction;
|
||||
import javax.transaction.TransactionManager;
|
||||
|
||||
/**
|
||||
* TransactionManager implementation specifically designed for use in test suite and simple usage
|
||||
* scenarios. For example, it assumes that there is only ever a single transaction active at a
|
||||
* given time.
|
||||
*
|
||||
* @author Gavin King
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class SimpleJtaTransactionManagerImpl implements TransactionManager {
|
||||
private static final SimpleJtaTransactionManagerImpl INSTANCE = new SimpleJtaTransactionManagerImpl();
|
||||
|
||||
private SimpleJtaTransactionImpl currentTransaction;
|
||||
|
||||
public static SimpleJtaTransactionManagerImpl getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
public int getStatus() throws SystemException {
|
||||
return currentTransaction == null ? Status.STATUS_NO_TRANSACTION : currentTransaction.getStatus();
|
||||
}
|
||||
|
||||
public Transaction getTransaction() throws SystemException {
|
||||
return currentTransaction;
|
||||
}
|
||||
|
||||
public SimpleJtaTransactionImpl getCurrentTransaction() {
|
||||
return currentTransaction;
|
||||
}
|
||||
|
||||
public void begin() throws NotSupportedException, SystemException {
|
||||
currentTransaction = new SimpleJtaTransactionImpl( this );
|
||||
}
|
||||
|
||||
public Transaction suspend() throws SystemException {
|
||||
SimpleJtaTransactionImpl suspended = currentTransaction;
|
||||
currentTransaction = null;
|
||||
return suspended;
|
||||
}
|
||||
|
||||
public void resume(Transaction transaction)
|
||||
throws InvalidTransactionException, IllegalStateException, SystemException {
|
||||
currentTransaction = ( SimpleJtaTransactionImpl ) transaction;
|
||||
}
|
||||
|
||||
public void commit()
|
||||
throws RollbackException, HeuristicMixedException, HeuristicRollbackException, SecurityException, IllegalStateException, SystemException {
|
||||
if ( currentTransaction == null ) {
|
||||
throw new IllegalStateException( "no current transaction to commit" );
|
||||
}
|
||||
currentTransaction.commit();
|
||||
}
|
||||
|
||||
public void rollback() throws IllegalStateException, SecurityException, SystemException {
|
||||
if ( currentTransaction == null ) {
|
||||
throw new IllegalStateException( "no current transaction" );
|
||||
}
|
||||
currentTransaction.rollback();
|
||||
}
|
||||
|
||||
public void setRollbackOnly() throws IllegalStateException, SystemException {
|
||||
if ( currentTransaction == null ) {
|
||||
throw new IllegalStateException( "no current transaction" );
|
||||
}
|
||||
currentTransaction.setRollbackOnly();
|
||||
}
|
||||
|
||||
public void setTransactionTimeout(int i) throws SystemException {
|
||||
}
|
||||
|
||||
void endCurrent(SimpleJtaTransactionImpl transaction) {
|
||||
if ( transaction == currentTransaction ) {
|
||||
currentTransaction = null;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,38 +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
|
||||
-->
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
||||
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<TITLE>Package Information - org.hibernate.test.tm</TITLE>
|
||||
</HEAD>
|
||||
<BODY>
|
||||
<p>
|
||||
Defines a simplified JTA TransactionManager and transactional connection pool
|
||||
designed for use in test suite and simple usage scenarios. For example, it
|
||||
is assumed that there is only ever a single transaction active at a given time.
|
||||
Also, the only 'resource' that the transaction tracks is a single JDBC connection.
|
||||
</p>
|
||||
</BODY>
|
||||
</HTML>
|
|
@ -142,7 +142,7 @@ public abstract class AbstractHolderTest extends BaseUnitTestCase {
|
|||
}
|
||||
assertEquals( holder.copy().initialize( i ), holder );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasicHiloAlgorithm() {
|
||||
// mimic an initialValue of 1 and increment of 20
|
||||
final long initialValue = 1;
|
||||
|
|
|
@ -73,7 +73,7 @@ public class LobCreatorTest extends org.hibernate.testing.junit4.BaseUnitTestCas
|
|||
|
||||
connection.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJdbc3LobCreator() throws SQLException {
|
||||
final Connection connection = createConnectionProxy( 3, new JdbcLobBuilderImpl( false) );
|
||||
LobCreationContext lobCreationContext = new LobCreationContextImpl( connection );
|
||||
|
@ -86,7 +86,7 @@ public class LobCreatorTest extends org.hibernate.testing.junit4.BaseUnitTestCas
|
|||
testLobCreation( lobCreator );
|
||||
connection.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJdbc4UnsupportedLobCreator() throws SQLException {
|
||||
final Connection connection = createConnectionProxy( 4, new JdbcLobBuilderImpl( false ) );
|
||||
LobCreationContext lobCreationContext = new LobCreationContextImpl( connection );
|
||||
|
@ -99,7 +99,7 @@ public class LobCreatorTest extends org.hibernate.testing.junit4.BaseUnitTestCas
|
|||
testLobCreation( lobCreator );
|
||||
connection.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConfiguredNonContextualLobCreator() throws SQLException {
|
||||
final Connection connection = createConnectionProxy( 4, new JdbcLobBuilderImpl( true ) );
|
||||
LobCreationContext lobCreationContext = new LobCreationContextImpl( connection );
|
||||
|
|
|
@ -1,124 +0,0 @@
|
|||
// $Id$
|
||||
/*
|
||||
* 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.ejb.test.ejb3configuration;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import javax.persistence.Persistence;
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.ejb.AvailableSettings;
|
||||
import org.hibernate.ejb.Ejb3Configuration;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
public abstract class TestCase extends junit.framework.TestCase {
|
||||
protected Ejb3Configuration configuration;
|
||||
private Class lastTestClass;
|
||||
|
||||
public TestCase() {
|
||||
super();
|
||||
}
|
||||
|
||||
public TestCase(String name) {
|
||||
super( name );
|
||||
}
|
||||
|
||||
public void setUp() {
|
||||
if ( configuration == null || lastTestClass != getClass() ) {
|
||||
buildConfiguration();
|
||||
lastTestClass = getClass();
|
||||
}
|
||||
//factory = new HibernatePersistence().createEntityManagerFactory( getConfig() );
|
||||
}
|
||||
|
||||
protected boolean recreateSchema() {
|
||||
return true;
|
||||
}
|
||||
|
||||
private void buildConfiguration() {
|
||||
configuration = new Ejb3Configuration();
|
||||
configuration.addProperties( loadProperties() );
|
||||
if ( recreateSchema() ) {
|
||||
configuration.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
|
||||
}
|
||||
|
||||
for ( Class clazz : getAnnotatedClasses() ) {
|
||||
configuration.addAnnotatedClass( clazz );
|
||||
}
|
||||
|
||||
for ( Map.Entry<Class, String> entry : getCachedClasses().entrySet() ) {
|
||||
configuration.setProperty(
|
||||
AvailableSettings.CLASS_CACHE_PREFIX + "." + entry.getKey().getName(),
|
||||
entry.getValue()
|
||||
);
|
||||
}
|
||||
for ( Map.Entry<String, String> entry : getCachedCollections().entrySet() ) {
|
||||
configuration.setProperty(
|
||||
AvailableSettings.COLLECTION_CACHE_PREFIX + "." + entry.getKey(),
|
||||
entry.getValue()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public abstract Class[] getAnnotatedClasses();
|
||||
|
||||
public Map<Class, String> getCachedClasses() {
|
||||
return new HashMap<Class, String>();
|
||||
}
|
||||
|
||||
public Map<String, String> getCachedCollections() {
|
||||
return new HashMap<String, String>();
|
||||
}
|
||||
|
||||
public static Properties loadProperties() {
|
||||
Properties props = new Properties();
|
||||
InputStream stream = Persistence.class.getResourceAsStream( "/hibernate.properties" );
|
||||
if ( stream != null ) {
|
||||
try {
|
||||
props.load( stream );
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new RuntimeException( "could not load hibernate.properties" );
|
||||
}
|
||||
finally {
|
||||
try {
|
||||
stream.close();
|
||||
}
|
||||
catch (IOException ioe) {
|
||||
}
|
||||
}
|
||||
}
|
||||
return props;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
configuration = null; //avoid side effects
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue