Browse Source

[SPR-8092] cleaning up ignored and broken ORM tests; suppressing warnings; fixed Eclipse classpath for tests.

pull/7/head
Sam Brannen 14 years ago
parent
commit
daa074734f
  1. 87
      org.springframework.orm/.classpath
  2. 165
      org.springframework.orm/src/test/java/org/springframework/orm/hibernate3/HibernateJtaTransactionTests.java
  3. 7
      org.springframework.orm/src/test/java/org/springframework/orm/jpa/AbstractContainerEntityManagerFactoryIntegrationTests.java
  4. 6
      org.springframework.orm/src/test/java/org/springframework/orm/jpa/hibernate/HibernateEntityManagerFactoryIntegrationTests.java

87
org.springframework.orm/.classpath

@ -1,43 +1,44 @@ @@ -1,43 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src/main/java"/>
<classpathentry kind="src" path="src/main/resources"/>
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
<classpathentry kind="src" output="target/test-classes" path="src/test/resources"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry combineaccessrules="false" kind="src" path="/org.springframework.aop"/>
<classpathentry combineaccessrules="false" kind="src" path="/org.springframework.beans"/>
<classpathentry combineaccessrules="false" kind="src" path="/org.springframework.context"/>
<classpathentry combineaccessrules="false" kind="src" path="/org.springframework.core"/>
<classpathentry combineaccessrules="false" kind="src" path="/org.springframework.jdbc"/>
<classpathentry combineaccessrules="false" kind="src" path="/org.springframework.transaction"/>
<classpathentry combineaccessrules="false" kind="src" path="/org.springframework.web"/>
<classpathentry kind="var" path="IVY_CACHE/org.hibernate/com.springsource.org.hibernate.annotations.common/3.3.0.ga/com.springsource.org.hibernate.annotations.common-3.3.0.ga.jar" sourcepath="/IVY_CACHE/org.hibernate/com.springsource.org.hibernate.annotations.common/3.3.0.ga/com.springsource.org.hibernate.annotations-sources-3.3.0.common.ga.jar"/>
<classpathentry kind="var" path="IVY_CACHE/javax.persistence/com.springsource.javax.persistence/1.0.0/com.springsource.javax.persistence-1.0.0.jar" sourcepath="/IVY_CACHE/javax.persistence/com.springsource.javax.persistence/1.0.0/com.springsource.javax.persistence-sources-1.0.0.jar"/>
<classpathentry kind="var" path="IVY_CACHE/javax.persistence/com.springsource.javax.persistence/1.0.0/com.springsource.javax.persistence-sources-1.0.0.jar"/>
<classpathentry kind="var" path="IVY_CACHE/com.oracle.toplink.essentials/com.springsource.oracle.toplink.essentials/2.0.0.b41-beta2/com.springsource.oracle.toplink.essentials-2.0.0.b41-beta2.jar" sourcepath="/IVY_CACHE/com.oracle.toplink.essentials/com.springsource.oracle.toplink.essentials/2.0.0.b41-beta2/com.springsource.oracle.toplink.essentials-sources-2.0.0.b41-beta2.jar"/>
<classpathentry kind="var" path="IVY_CACHE/org.apache.openjpa/com.springsource.org.apache.openjpa/1.1.0/com.springsource.org.apache.openjpa-1.1.0.jar" sourcepath="/IVY_CACHE/org.apache.openjpa/com.springsource.org.apache.openjpa.java5/1.0.2/com.springsource.org.apache.openjpa.java5-sources-1.0.2.jar"/>
<classpathentry kind="var" path="IVY_CACHE/javax.transaction/com.springsource.javax.transaction/1.1.0/com.springsource.javax.transaction-1.1.0.jar" sourcepath="/IVY_CACHE/javax.transaction/com.springsource.javax.transaction/1.1.0/com.springsource.javax.transaction-sources-1.1.0.jar"/>
<classpathentry kind="var" path="IVY_CACHE/org.junit/com.springsource.org.junit/4.8.1/com.springsource.org.junit-4.8.1.jar" sourcepath="/IVY_CACHE/org.junit/com.springsource.org.junit/4.8.1/com.springsource.org.junit-sources-4.8.1.jar"/>
<classpathentry kind="var" path="IVY_CACHE/org.apache.commons/com.springsource.org.apache.commons.logging/1.1.1/com.springsource.org.apache.commons.logging-1.1.1.jar" sourcepath="/IVY_CACHE/org.apache.commons/com.springsource.org.apache.commons.logging/1.1.1/com.springsource.org.apache.commons.logging-sources-1.1.1.jar"/>
<classpathentry kind="var" path="IVY_CACHE/org.eclipse.persistence/com.springsource.org.eclipse.persistence.jpa/1.0.1/com.springsource.org.eclipse.persistence.jpa-1.0.1.jar" sourcepath="/IVY_CACHE/org.eclipse.persistence/com.springsource.org.eclipse.persistence.jpa/1.0.1/com.springsource.org.eclipse.persistence.jpa-sources-1.0.1.jar"/>
<classpathentry kind="var" path="IVY_CACHE/org.eclipse.persistence/com.springsource.org.eclipse.persistence/1.0.1/com.springsource.org.eclipse.persistence-1.0.1.jar" sourcepath="/IVY_CACHE/org.eclipse.persistence/com.springsource.org.eclipse.persistence/1.0.1/com.springsource.org.eclipse.persistence-sources-1.0.1.jar"/>
<classpathentry kind="var" path="IVY_CACHE/org.aopalliance/com.springsource.org.aopalliance/1.0.0/com.springsource.org.aopalliance-1.0.0.jar" sourcepath="/IVY_CACHE/org.aopalliance/com.springsource.org.aopalliance/1.0.0/com.springsource.org.aopalliance-sources-1.0.0.jar"/>
<classpathentry kind="var" path="IVY_CACHE/org.aspectj/com.springsource.org.aspectj.weaver/1.6.8.RELEASE/com.springsource.org.aspectj.weaver-1.6.8.RELEASE.jar"/>
<classpathentry kind="var" path="IVY_CACHE/org.apache.ibatis/com.springsource.com.ibatis/2.3.4.726/com.springsource.com.ibatis-2.3.4.726.jar" sourcepath="/IVY_CACHE/org.apache.ibatis/com.springsource.com.ibatis/2.3.4.726/com.springsource.com.ibatis-sources-2.3.4.726.jar"/>
<classpathentry kind="var" path="IVY_CACHE/javax.jdo/com.springsource.javax.jdo/2.1.0/com.springsource.javax.jdo-2.1.0.jar" sourcepath="/IVY_CACHE/javax.jdo/com.springsource.javax.jdo/2.1.0/com.springsource.javax.jdo-sources-2.1.0.jar"/>
<classpathentry kind="var" path="IVY_CACHE/javax.servlet/com.springsource.javax.servlet/2.5.0/com.springsource.javax.servlet-2.5.0.jar" sourcepath="/IVY_CACHE/javax.servlet/com.springsource.javax.servlet/2.5.0/com.springsource.javax.servlet-sources-2.5.0.jar"/>
<classpathentry kind="var" path="IVY_CACHE/javax.ejb/com.springsource.javax.ejb/3.0.0/com.springsource.javax.ejb-3.0.0.jar" sourcepath="/IVY_CACHE/javax.ejb/com.springsource.javax.ejb/3.0.0/com.springsource.javax.ejb-sources-3.0.0.jar"/>
<classpathentry kind="var" path="IVY_CACHE/org.easymock/com.springsource.org.easymock/2.5.1/com.springsource.org.easymock-2.5.1.jar" sourcepath="/IVY_CACHE/org.easymock/com.springsource.org.easymock/2.5.1/com.springsource.org.easymock-sources-2.5.1.jar"/>
<classpathentry kind="var" path="IVY_CACHE/org.dom4j/com.springsource.org.dom4j/1.6.1/com.springsource.org.dom4j-1.6.1.jar" sourcepath="/IVY_CACHE/org.dom4j/com.springsource.org.dom4j/1.6.1/com.springsource.org.dom4j-sources-1.6.1.jar"/>
<classpathentry kind="var" path="IVY_CACHE/org.apache.commons/com.springsource.org.apache.commons.dbcp/1.2.2.osgi/com.springsource.org.apache.commons.dbcp-1.2.2.osgi.jar" sourcepath="/IVY_CACHE/org.apache.commons/com.springsource.org.apache.commons.dbcp/1.2.2.osgi/com.springsource.org.apache.commons.dbcp-sources-1.2.2.osgi.jar"/>
<classpathentry kind="var" path="IVY_CACHE/org.hsqldb/com.springsource.org.hsqldb/1.8.0.9/com.springsource.org.hsqldb-1.8.0.9.jar" sourcepath="/IVY_CACHE/org.hsqldb/com.springsource.org.hsqldb/1.8.0.9/com.springsource.org.hsqldb-sources-1.8.0.9.jar"/>
<classpathentry kind="var" path="IVY_CACHE/org.apache.commons/com.springsource.org.apache.commons.lang/2.1.0/com.springsource.org.apache.commons.lang-2.1.0.jar" sourcepath="/IVY_CACHE/org.apache.commons/com.springsource.org.apache.commons.lang/2.1.0/com.springsource.org.apache.commons.lang-sources-2.1.0.jar"/>
<classpathentry kind="var" path="IVY_CACHE/net.sourceforge.serp/com.springsource.serp/1.13.1/com.springsource.serp-1.13.1.jar"/>
<classpathentry kind="var" path="IVY_CACHE/edu.oswego.cs.concurrent/com.springsource.edu.oswego.cs.dl.util.concurrent/1.3.4/com.springsource.edu.oswego.cs.dl.util.concurrent-1.3.4.jar" sourcepath="/IVY_CACHE/edu.oswego.cs.concurrent/com.springsource.edu.oswego.cs.dl.util.concurrent/1.3.4/com.springsource.edu.oswego.cs.dl.util.concurrent-sources-1.3.4.jar"/>
<classpathentry kind="var" path="IVY_CACHE"/>
<classpathentry kind="var" path="IVY_CACHE/org.hibernate/com.springsource.org.hibernate/3.3.1.GA/com.springsource.org.hibernate-3.3.1.GA.jar"/>
<classpathentry kind="var" path="IVY_CACHE/org.hibernate/com.springsource.org.hibernate.annotations/3.4.0.GA/com.springsource.org.hibernate.annotations-3.4.0.GA.jar"/>
<classpathentry kind="var" path="IVY_CACHE/org.hibernate/com.springsource.org.hibernate.ejb/3.4.0.GA/com.springsource.org.hibernate.ejb-3.4.0.GA.jar"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src/main/java"/>
<classpathentry kind="src" path="src/main/resources"/>
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
<classpathentry kind="src" output="target/test-classes" path="src/test/resources"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry combineaccessrules="false" kind="src" path="/org.springframework.aop"/>
<classpathentry combineaccessrules="false" kind="src" path="/org.springframework.beans"/>
<classpathentry combineaccessrules="false" kind="src" path="/org.springframework.context"/>
<classpathentry combineaccessrules="false" kind="src" path="/org.springframework.core"/>
<classpathentry combineaccessrules="false" kind="src" path="/org.springframework.jdbc"/>
<classpathentry combineaccessrules="false" kind="src" path="/org.springframework.transaction"/>
<classpathentry combineaccessrules="false" kind="src" path="/org.springframework.web"/>
<classpathentry kind="var" path="IVY_CACHE/com.oracle.toplink.essentials/com.springsource.oracle.toplink.essentials/2.0.0.b41-beta2/com.springsource.oracle.toplink.essentials-2.0.0.b41-beta2.jar" sourcepath="/IVY_CACHE/com.oracle.toplink.essentials/com.springsource.oracle.toplink.essentials/2.0.0.b41-beta2/com.springsource.oracle.toplink.essentials-sources-2.0.0.b41-beta2.jar"/>
<classpathentry kind="var" path="IVY_CACHE/edu.oswego.cs.concurrent/com.springsource.edu.oswego.cs.dl.util.concurrent/1.3.4/com.springsource.edu.oswego.cs.dl.util.concurrent-1.3.4.jar" sourcepath="/IVY_CACHE/edu.oswego.cs.concurrent/com.springsource.edu.oswego.cs.dl.util.concurrent/1.3.4/com.springsource.edu.oswego.cs.dl.util.concurrent-sources-1.3.4.jar"/>
<classpathentry kind="var" path="IVY_CACHE/javax.ejb/com.springsource.javax.ejb/3.0.0/com.springsource.javax.ejb-3.0.0.jar" sourcepath="/IVY_CACHE/javax.ejb/com.springsource.javax.ejb/3.0.0/com.springsource.javax.ejb-sources-3.0.0.jar"/>
<classpathentry kind="var" path="IVY_CACHE/javax.jdo/com.springsource.javax.jdo/2.1.0/com.springsource.javax.jdo-2.1.0.jar" sourcepath="/IVY_CACHE/javax.jdo/com.springsource.javax.jdo/2.1.0/com.springsource.javax.jdo-sources-2.1.0.jar"/>
<classpathentry kind="var" path="IVY_CACHE/javax.persistence/com.springsource.javax.persistence/1.0.0/com.springsource.javax.persistence-1.0.0.jar" sourcepath="/IVY_CACHE/javax.persistence/com.springsource.javax.persistence/1.0.0/com.springsource.javax.persistence-sources-1.0.0.jar"/>
<classpathentry kind="var" path="IVY_CACHE/javax.servlet/com.springsource.javax.servlet/2.5.0/com.springsource.javax.servlet-2.5.0.jar" sourcepath="/IVY_CACHE/javax.servlet/com.springsource.javax.servlet/2.5.0/com.springsource.javax.servlet-sources-2.5.0.jar"/>
<classpathentry kind="var" path="IVY_CACHE/javax.transaction/com.springsource.javax.transaction/1.1.0/com.springsource.javax.transaction-1.1.0.jar" sourcepath="/IVY_CACHE/javax.transaction/com.springsource.javax.transaction/1.1.0/com.springsource.javax.transaction-sources-1.1.0.jar"/>
<classpathentry kind="var" path="IVY_CACHE/org.antlr/com.springsource.antlr/2.7.7/com.springsource.antlr-2.7.7.jar" sourcepath="/IVY_CACHE/org.antlr/com.springsource.antlr/2.7.7/com.springsource.antlr-sources-2.7.7.jar"/>
<classpathentry kind="var" path="IVY_CACHE/org.aopalliance/com.springsource.org.aopalliance/1.0.0/com.springsource.org.aopalliance-1.0.0.jar" sourcepath="/IVY_CACHE/org.aopalliance/com.springsource.org.aopalliance/1.0.0/com.springsource.org.aopalliance-sources-1.0.0.jar"/>
<classpathentry kind="var" path="IVY_CACHE/org.apache.commons/com.springsource.org.apache.commons.collections/3.2.1/com.springsource.org.apache.commons.collections-3.2.1.jar" sourcepath="/IVY_CACHE/org.apache.commons/com.springsource.org.apache.commons.collections/3.2.1/com.springsource.org.apache.commons.collections-sources-3.2.1.jar"/>
<classpathentry kind="var" path="IVY_CACHE/org.apache.commons/com.springsource.org.apache.commons.dbcp/1.2.2.osgi/com.springsource.org.apache.commons.dbcp-1.2.2.osgi.jar" sourcepath="/IVY_CACHE/org.apache.commons/com.springsource.org.apache.commons.dbcp/1.2.2.osgi/com.springsource.org.apache.commons.dbcp-sources-1.2.2.osgi.jar"/>
<classpathentry kind="var" path="IVY_CACHE/org.apache.commons/com.springsource.org.apache.commons.lang/2.1.0/com.springsource.org.apache.commons.lang-2.1.0.jar" sourcepath="/IVY_CACHE/org.apache.commons/com.springsource.org.apache.commons.lang/2.1.0/com.springsource.org.apache.commons.lang-sources-2.1.0.jar"/>
<classpathentry kind="var" path="IVY_CACHE/org.apache.commons/com.springsource.org.apache.commons.logging/1.1.1/com.springsource.org.apache.commons.logging-1.1.1.jar" sourcepath="/IVY_CACHE/org.apache.commons/com.springsource.org.apache.commons.logging/1.1.1/com.springsource.org.apache.commons.logging-sources-1.1.1.jar"/>
<classpathentry kind="var" path="IVY_CACHE/org.apache.ibatis/com.springsource.com.ibatis/2.3.4.726/com.springsource.com.ibatis-2.3.4.726.jar" sourcepath="/IVY_CACHE/org.apache.ibatis/com.springsource.com.ibatis/2.3.4.726/com.springsource.com.ibatis-sources-2.3.4.726.jar"/>
<classpathentry kind="var" path="IVY_CACHE/org.apache.openjpa/com.springsource.org.apache.openjpa/1.1.0/com.springsource.org.apache.openjpa-1.1.0.jar" sourcepath="/IVY_CACHE/org.apache.openjpa/com.springsource.org.apache.openjpa.java5/1.0.2/com.springsource.org.apache.openjpa.java5-sources-1.0.2.jar"/>
<classpathentry kind="var" path="IVY_CACHE/org.aspectj/com.springsource.org.aspectj.weaver/1.6.8.RELEASE/com.springsource.org.aspectj.weaver-1.6.8.RELEASE.jar"/>
<classpathentry kind="var" path="IVY_CACHE/org.dom4j/com.springsource.org.dom4j/1.6.1/com.springsource.org.dom4j-1.6.1.jar" sourcepath="/IVY_CACHE/org.dom4j/com.springsource.org.dom4j/1.6.1/com.springsource.org.dom4j-sources-1.6.1.jar"/>
<classpathentry kind="var" path="IVY_CACHE/org.easymock/com.springsource.org.easymock/2.5.1/com.springsource.org.easymock-2.5.1.jar" sourcepath="/IVY_CACHE/org.easymock/com.springsource.org.easymock/2.5.1/com.springsource.org.easymock-sources-2.5.1.jar"/>
<classpathentry kind="var" path="IVY_CACHE/org.eclipse.persistence/com.springsource.org.eclipse.persistence/1.0.1/com.springsource.org.eclipse.persistence-1.0.1.jar" sourcepath="/IVY_CACHE/org.eclipse.persistence/com.springsource.org.eclipse.persistence/1.0.1/com.springsource.org.eclipse.persistence-sources-1.0.1.jar"/>
<classpathentry kind="var" path="IVY_CACHE/org.eclipse.persistence/com.springsource.org.eclipse.persistence.jpa/1.0.1/com.springsource.org.eclipse.persistence.jpa-1.0.1.jar" sourcepath="/IVY_CACHE/org.eclipse.persistence/com.springsource.org.eclipse.persistence.jpa/1.0.1/com.springsource.org.eclipse.persistence.jpa-sources-1.0.1.jar"/>
<classpathentry kind="var" path="IVY_CACHE/org.hibernate/com.springsource.org.hibernate/3.3.1.GA/com.springsource.org.hibernate-3.3.1.GA.jar"/>
<classpathentry kind="var" path="IVY_CACHE/org.hibernate/com.springsource.org.hibernate.ejb/3.4.0.GA/com.springsource.org.hibernate.ejb-3.4.0.GA.jar"/>
<classpathentry kind="var" path="IVY_CACHE/org.hibernate/com.springsource.org.hibernate.annotations/3.4.0.GA/com.springsource.org.hibernate.annotations-3.4.0.GA.jar"/>
<classpathentry kind="var" path="IVY_CACHE/org.hibernate/com.springsource.org.hibernate.annotations.common/3.3.0.ga/com.springsource.org.hibernate.annotations.common-3.3.0.ga.jar" sourcepath="/IVY_CACHE/org.hibernate/com.springsource.org.hibernate.annotations.common/3.3.0.ga/com.springsource.org.hibernate.annotations-sources-3.3.0.common.ga.jar"/>
<classpathentry kind="var" path="IVY_CACHE/org.hsqldb/com.springsource.org.hsqldb/1.8.0.9/com.springsource.org.hsqldb-1.8.0.9.jar" sourcepath="/IVY_CACHE/org.hsqldb/com.springsource.org.hsqldb/1.8.0.9/com.springsource.org.hsqldb-sources-1.8.0.9.jar"/>
<classpathentry kind="var" path="IVY_CACHE/org.jboss.javassist/com.springsource.javassist/3.3.0.ga/com.springsource.javassist-3.3.0.ga.jar" sourcepath="/IVY_CACHE/org.jboss.javassist/com.springsource.javassist/3.3.0.ga/com.springsource.javassist-sources-3.3.0.ga.jar"/>
<classpathentry kind="var" path="IVY_CACHE/org.junit/com.springsource.org.junit/4.8.1/com.springsource.org.junit-4.8.1.jar" sourcepath="/IVY_CACHE/org.junit/com.springsource.org.junit/4.8.1/com.springsource.org.junit-sources-4.8.1.jar"/>
<classpathentry kind="var" path="IVY_CACHE/net.sourceforge.serp/com.springsource.serp/1.13.1/com.springsource.serp-1.13.1.jar"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>

165
org.springframework.orm/src/test/java/org/springframework/orm/hibernate3/HibernateJtaTransactionTests.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2009 the original author or authors.
* Copyright 2002-2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -16,8 +16,15 @@ @@ -16,8 +16,15 @@
package org.springframework.orm.hibernate3;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.ArrayList;
import java.util.List;
import javax.transaction.RollbackException;
import javax.transaction.Status;
import javax.transaction.Synchronization;
@ -25,7 +32,6 @@ import javax.transaction.SystemException; @@ -25,7 +32,6 @@ import javax.transaction.SystemException;
import javax.transaction.TransactionManager;
import javax.transaction.UserTransaction;
import junit.framework.TestCase;
import org.easymock.MockControl;
import org.hibernate.FlushMode;
import org.hibernate.HibernateException;
@ -35,7 +41,7 @@ import org.hibernate.classic.Session; @@ -35,7 +41,7 @@ import org.hibernate.classic.Session;
import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.engine.SessionImplementor;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.dao.DataAccessException;
import org.springframework.transaction.MockJtaTransaction;
import org.springframework.transaction.TransactionDefinition;
@ -52,25 +58,30 @@ import org.springframework.transaction.support.TransactionTemplate; @@ -52,25 +58,30 @@ import org.springframework.transaction.support.TransactionTemplate;
* @author Juergen Hoeller
* @since 05.03.2005
*/
@Ignore // getting errors on mocks
public class HibernateJtaTransactionTests extends TestCase {
@SuppressWarnings("deprecation")
public class HibernateJtaTransactionTests {
@Test
public void testJtaTransactionCommit() throws Exception {
doTestJtaTransactionCommit(Status.STATUS_NO_TRANSACTION, false);
}
@Test
public void testJtaTransactionCommitWithReadOnly() throws Exception {
doTestJtaTransactionCommit(Status.STATUS_NO_TRANSACTION, true);
}
@Test
public void testJtaTransactionCommitWithExisting() throws Exception {
doTestJtaTransactionCommit(Status.STATUS_ACTIVE, false);
}
@Test
public void testJtaTransactionCommitWithExistingAndReadOnly() throws Exception {
doTestJtaTransactionCommit(Status.STATUS_ACTIVE, true);
}
@SuppressWarnings({ "rawtypes", "unchecked" })
private void doTestJtaTransactionCommit(int status, final boolean readOnly) throws Exception {
MockControl utControl = MockControl.createControl(UserTransaction.class);
UserTransaction ut = (UserTransaction) utControl.getMock();
@ -125,13 +136,16 @@ public class HibernateJtaTransactionTests extends TestCase { @@ -125,13 +136,16 @@ public class HibernateJtaTransactionTests extends TestCase {
assertTrue("Hasn't thread session", !TransactionSynchronizationManager.hasResource(sf));
Object result = tt.execute(new TransactionCallback() {
public Object doInTransaction(TransactionStatus status) {
try {
assertTrue("JTA synchronizations active", TransactionSynchronizationManager.isSynchronizationActive());
assertTrue("JTA synchronizations active",
TransactionSynchronizationManager.isSynchronizationActive());
assertTrue("Hasn't thread session", !TransactionSynchronizationManager.hasResource(sf));
HibernateTemplate ht = new HibernateTemplate(sf);
ht.setExposeNativeSession(true);
ht.executeFind(new HibernateCallback() {
public Object doInHibernate(org.hibernate.Session sess) {
assertTrue("Has thread session", TransactionSynchronizationManager.hasResource(sf));
assertEquals(session, sess);
@ -140,6 +154,7 @@ public class HibernateJtaTransactionTests extends TestCase { @@ -140,6 +154,7 @@ public class HibernateJtaTransactionTests extends TestCase {
});
ht = new HibernateTemplate(sf);
List htl = ht.executeFind(new HibernateCallback() {
public Object doInHibernate(org.hibernate.Session sess) {
assertTrue("Has thread session", TransactionSynchronizationManager.hasResource(sf));
return sess.createQuery("some query string").list();
@ -176,14 +191,17 @@ public class HibernateJtaTransactionTests extends TestCase { @@ -176,14 +191,17 @@ public class HibernateJtaTransactionTests extends TestCase {
sessionControl.verify();
}
@Test
public void testJtaTransactionCommitWithJtaTm() throws Exception {
doTestJtaTransactionCommitWithJtaTm(Status.STATUS_NO_TRANSACTION);
}
@Test
public void testJtaTransactionCommitWithJtaTmAndExisting() throws Exception {
doTestJtaTransactionCommitWithJtaTm(Status.STATUS_ACTIVE);
}
@SuppressWarnings({ "rawtypes", "unchecked" })
private void doTestJtaTransactionCommitWithJtaTm(int status) throws Exception {
MockControl utControl = MockControl.createControl(UserTransaction.class);
UserTransaction ut = (UserTransaction) utControl.getMock();
@ -228,13 +246,16 @@ public class HibernateJtaTransactionTests extends TestCase { @@ -228,13 +246,16 @@ public class HibernateJtaTransactionTests extends TestCase {
assertTrue("Hasn't thread session", !TransactionSynchronizationManager.hasResource(sf));
Object result = tt.execute(new TransactionCallback() {
public Object doInTransaction(TransactionStatus status) {
try {
assertTrue("JTA synchronizations active", TransactionSynchronizationManager.isSynchronizationActive());
assertTrue("JTA synchronizations active",
TransactionSynchronizationManager.isSynchronizationActive());
assertTrue("Hasn't thread session", !TransactionSynchronizationManager.hasResource(sf));
HibernateTemplate ht = new HibernateTemplate(sf);
ht.setExposeNativeSession(true);
List htl = ht.executeFind(new HibernateCallback() {
public Object doInHibernate(org.hibernate.Session sess) {
assertTrue("Has thread session", TransactionSynchronizationManager.hasResource(sf));
assertEquals(session, sess);
@ -244,6 +265,7 @@ public class HibernateJtaTransactionTests extends TestCase { @@ -244,6 +265,7 @@ public class HibernateJtaTransactionTests extends TestCase {
ht = new HibernateTemplate(sf);
ht.setExposeNativeSession(true);
htl = ht.executeFind(new HibernateCallback() {
public Object doInHibernate(org.hibernate.Session sess) {
assertTrue("Has thread session", TransactionSynchronizationManager.hasResource(sf));
assertEquals(session, sess);
@ -278,6 +300,8 @@ public class HibernateJtaTransactionTests extends TestCase { @@ -278,6 +300,8 @@ public class HibernateJtaTransactionTests extends TestCase {
sessionControl.verify();
}
@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void testJtaTransactionWithFlushFailure() throws Exception {
MockControl utControl = MockControl.createControl(UserTransaction.class);
UserTransaction ut = (UserTransaction) utControl.getMock();
@ -314,13 +338,16 @@ public class HibernateJtaTransactionTests extends TestCase { @@ -314,13 +338,16 @@ public class HibernateJtaTransactionTests extends TestCase {
try {
tt.execute(new TransactionCallback() {
public Object doInTransaction(TransactionStatus status) {
try {
assertTrue("JTA synchronizations active", TransactionSynchronizationManager.isSynchronizationActive());
assertTrue("JTA synchronizations active",
TransactionSynchronizationManager.isSynchronizationActive());
assertTrue("Hasn't thread session", !TransactionSynchronizationManager.hasResource(sf));
HibernateTemplate ht = new HibernateTemplate(sf);
ht.setExposeNativeSession(true);
List htl = ht.executeFind(new HibernateCallback() {
public Object doInHibernate(org.hibernate.Session sess) {
assertTrue("Has thread session", TransactionSynchronizationManager.hasResource(sf));
assertEquals(session, sess);
@ -330,6 +357,7 @@ public class HibernateJtaTransactionTests extends TestCase { @@ -330,6 +357,7 @@ public class HibernateJtaTransactionTests extends TestCase {
ht = new HibernateTemplate(sf);
ht.setExposeNativeSession(true);
htl = ht.executeFind(new HibernateCallback() {
public Object doInHibernate(org.hibernate.Session sess) {
assertTrue("Has thread session", TransactionSynchronizationManager.hasResource(sf));
assertEquals(session, sess);
@ -368,14 +396,17 @@ public class HibernateJtaTransactionTests extends TestCase { @@ -368,14 +396,17 @@ public class HibernateJtaTransactionTests extends TestCase {
sessionControl.verify();
}
@Test
public void testJtaTransactionRollback() throws Exception {
doTestJtaTransactionRollback(false);
}
@Test
public void testJtaTransactionRollbackWithFlush() throws Exception {
doTestJtaTransactionRollback(true);
}
@SuppressWarnings({ "rawtypes", "unchecked" })
private void doTestJtaTransactionRollback(final boolean flush) throws Exception {
MockControl utControl = MockControl.createControl(UserTransaction.class);
UserTransaction ut = (UserTransaction) utControl.getMock();
@ -411,11 +442,14 @@ public class HibernateJtaTransactionTests extends TestCase { @@ -411,11 +442,14 @@ public class HibernateJtaTransactionTests extends TestCase {
assertTrue("JTA synchronizations not active", !TransactionSynchronizationManager.isSynchronizationActive());
Object result = tt.execute(new TransactionCallback() {
public Object doInTransaction(TransactionStatus status) {
try {
assertTrue("JTA synchronizations active", TransactionSynchronizationManager.isSynchronizationActive());
assertTrue("JTA synchronizations active",
TransactionSynchronizationManager.isSynchronizationActive());
HibernateTemplate ht = new HibernateTemplate(sf);
List htl = ht.executeFind(new HibernateCallback() {
public Object doInHibernate(org.hibernate.Session session) {
return l;
}
@ -445,40 +479,49 @@ public class HibernateJtaTransactionTests extends TestCase { @@ -445,40 +479,49 @@ public class HibernateJtaTransactionTests extends TestCase {
sessionControl.verify();
}
@Test
public void testJtaTransactionCommitWithPreBound() throws Exception {
doTestJtaTransactionCommitWithPreBound(false, false, false);
}
@Test
public void testJtaTransactionCommitWithPreBoundAndReadOnly() throws Exception {
doTestJtaTransactionCommitWithPreBound(false, false, true);
}
@Test
public void testJtaTransactionCommitWithPreBoundAndFlushModeNever() throws Exception {
doTestJtaTransactionCommitWithPreBound(false, true, false);
}
@Test
public void testJtaTransactionCommitWithPreBoundAndFlushModeNeverAndReadOnly() throws Exception {
doTestJtaTransactionCommitWithPreBound(false, true, true);
}
@Test
public void testJtaTransactionCommitWithJtaTmAndPreBound() throws Exception {
doTestJtaTransactionCommitWithPreBound(true, false, false);
}
@Test
public void testJtaTransactionCommitWithJtaTmAndPreBoundAndReadOnly() throws Exception {
doTestJtaTransactionCommitWithPreBound(true, false, true);
}
@Test
public void testJtaTransactionCommitWithJtaTmAndPreBoundAndFlushModeNever() throws Exception {
doTestJtaTransactionCommitWithPreBound(true, true, false);
}
@Test
public void testJtaTransactionCommitWithJtaTmAndPreBoundAndFlushModeNeverAndReadOnly() throws Exception {
doTestJtaTransactionCommitWithPreBound(true, true, true);
}
protected void doTestJtaTransactionCommitWithPreBound(
boolean jtaTm, final boolean flushNever, final boolean readOnly) throws Exception {
@SuppressWarnings({ "rawtypes", "unchecked" })
protected void doTestJtaTransactionCommitWithPreBound(boolean jtaTm, final boolean flushNever,
final boolean readOnly) throws Exception {
MockControl utControl = MockControl.createControl(UserTransaction.class);
UserTransaction ut = (UserTransaction) utControl.getMock();
@ -535,15 +578,18 @@ public class HibernateJtaTransactionTests extends TestCase { @@ -535,15 +578,18 @@ public class HibernateJtaTransactionTests extends TestCase {
assertTrue("Has thread session", TransactionSynchronizationManager.hasResource(sf));
Object result = tt.execute(new TransactionCallback() {
public Object doInTransaction(TransactionStatus status) {
try {
assertTrue("JTA synchronizations active", TransactionSynchronizationManager.isSynchronizationActive());
assertTrue("JTA synchronizations active",
TransactionSynchronizationManager.isSynchronizationActive());
assertTrue("Has thread session", TransactionSynchronizationManager.hasResource(sf));
HibernateTemplate ht = new HibernateTemplate(sf);
ht.setExposeNativeSession(true);
List htl = null;
for (int i = 0; i < 5; i++) {
htl = ht.executeFind(new HibernateCallback() {
public Object doInHibernate(org.hibernate.Session sess) {
assertTrue("Has thread session", TransactionSynchronizationManager.hasResource(sf));
assertEquals(session, sess);
@ -592,6 +638,8 @@ public class HibernateJtaTransactionTests extends TestCase { @@ -592,6 +638,8 @@ public class HibernateJtaTransactionTests extends TestCase {
sessionControl.verify();
}
@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void testJtaTransactionRollbackWithPreBound() throws Exception {
MockControl utControl = MockControl.createControl(UserTransaction.class);
UserTransaction ut = (UserTransaction) utControl.getMock();
@ -631,19 +679,24 @@ public class HibernateJtaTransactionTests extends TestCase { @@ -631,19 +679,24 @@ public class HibernateJtaTransactionTests extends TestCase {
assertTrue("Has thread session", TransactionSynchronizationManager.hasResource(sf));
tt.execute(new TransactionCallbackWithoutResult() {
public void doInTransactionWithoutResult(TransactionStatus status) {
tt.execute(new TransactionCallbackWithoutResult() {
public void doInTransactionWithoutResult(TransactionStatus status) {
status.setRollbackOnly();
try {
assertTrue("JTA synchronizations active", TransactionSynchronizationManager.isSynchronizationActive());
assertTrue("JTA synchronizations active",
TransactionSynchronizationManager.isSynchronizationActive());
assertTrue("Has thread session", TransactionSynchronizationManager.hasResource(sf));
HibernateTemplate ht = new HibernateTemplate(sf);
ht.setExposeNativeSession(true);
for (int i = 0; i < 5; i++) {
ht.execute(new HibernateCallback() {
public Object doInHibernate(org.hibernate.Session sess) {
assertTrue("Has thread session", TransactionSynchronizationManager.hasResource(sf));
assertTrue("Has thread session",
TransactionSynchronizationManager.hasResource(sf));
assertEquals(session, sess);
return null;
}
@ -685,14 +738,17 @@ public class HibernateJtaTransactionTests extends TestCase { @@ -685,14 +738,17 @@ public class HibernateJtaTransactionTests extends TestCase {
sessionControl.verify();
}
@Test
public void testJtaTransactionCommitWithRequiresNew() throws Exception {
doTestJtaTransactionWithRequiresNew(false);
}
@Test
public void testJtaTransactionRollbackWithRequiresNew() throws Exception {
doTestJtaTransactionWithRequiresNew(true);
}
@SuppressWarnings({ "rawtypes", "unchecked" })
protected void doTestJtaTransactionWithRequiresNew(final boolean rollback) throws Exception {
MockControl utControl = MockControl.createControl(UserTransaction.class);
UserTransaction ut = (UserTransaction) utControl.getMock();
@ -773,6 +829,7 @@ public class HibernateJtaTransactionTests extends TestCase { @@ -773,6 +829,7 @@ public class HibernateJtaTransactionTests extends TestCase {
assertTrue("Hasn't thread session", !TransactionSynchronizationManager.hasResource(sf));
try {
tt.execute(new TransactionCallback() {
public Object doInTransaction(TransactionStatus status) {
org.hibernate.Session outerSession = SessionFactoryUtils.getSession(sf, false);
assertSame(session1, outerSession);
@ -780,12 +837,14 @@ public class HibernateJtaTransactionTests extends TestCase { @@ -780,12 +837,14 @@ public class HibernateJtaTransactionTests extends TestCase {
assertTrue("Has thread session", holder != null);
try {
tt.execute(new TransactionCallback() {
public Object doInTransaction(TransactionStatus status) {
org.hibernate.Session innerSession = SessionFactoryUtils.getSession(sf, false);
assertSame(session2, innerSession);
HibernateTemplate ht = new HibernateTemplate(sf);
ht.setFlushMode(HibernateTemplate.FLUSH_EAGER);
return ht.executeFind(new HibernateCallback() {
public Object doInHibernate(org.hibernate.Session innerSession) {
if (rollback) {
throw new HibernateException("");
@ -798,7 +857,8 @@ public class HibernateJtaTransactionTests extends TestCase { @@ -798,7 +857,8 @@ public class HibernateJtaTransactionTests extends TestCase {
return null;
}
finally {
assertTrue("Same thread session as before", outerSession == SessionFactoryUtils.getSession(sf, false));
assertTrue("Same thread session as before",
outerSession == SessionFactoryUtils.getSession(sf, false));
}
}
});
@ -822,14 +882,17 @@ public class HibernateJtaTransactionTests extends TestCase { @@ -822,14 +882,17 @@ public class HibernateJtaTransactionTests extends TestCase {
session2Control.verify();
}
@Test
public void testJtaTransactionWithRequiresNewAndSuspendException() throws Exception {
doTestJtaTransactionWithRequiresNewAndException(true);
}
@Test
public void testJtaTransactionWithRequiresNewAndBeginException() throws Exception {
doTestJtaTransactionWithRequiresNewAndException(false);
}
@SuppressWarnings({ "rawtypes", "unchecked" })
protected void doTestJtaTransactionWithRequiresNewAndException(boolean suspendException) throws Exception {
MockControl utControl = MockControl.createControl(UserTransaction.class);
UserTransaction ut = (UserTransaction) utControl.getMock();
@ -886,12 +949,14 @@ public class HibernateJtaTransactionTests extends TestCase { @@ -886,12 +949,14 @@ public class HibernateJtaTransactionTests extends TestCase {
assertTrue("Hasn't thread session", !TransactionSynchronizationManager.hasResource(sf));
try {
tt.execute(new TransactionCallback() {
public Object doInTransaction(TransactionStatus status) {
org.hibernate.Session outerSession = SessionFactoryUtils.getSession(sf, false);
assertSame(session1, outerSession);
SessionHolder holder = (SessionHolder) TransactionSynchronizationManager.getResource(sf);
assertTrue("Has thread session", holder != null);
tt.execute(new TransactionCallback() {
public Object doInTransaction(TransactionStatus status) {
return null;
}
@ -914,14 +979,17 @@ public class HibernateJtaTransactionTests extends TestCase { @@ -914,14 +979,17 @@ public class HibernateJtaTransactionTests extends TestCase {
session1Control.verify();
}
@Test
public void testJtaTransactionCommitWithRequiresNewAndJtaTm() throws Exception {
doTestJtaTransactionWithRequiresNewAndJtaTm(false);
}
@Test
public void testJtaTransactionRollbackWithRequiresNewAndJtaTm() throws Exception {
doTestJtaTransactionWithRequiresNewAndJtaTm(true);
}
@SuppressWarnings({ "rawtypes", "unchecked" })
protected void doTestJtaTransactionWithRequiresNewAndJtaTm(final boolean rollback) throws Exception {
MockControl utControl = MockControl.createControl(UserTransaction.class);
UserTransaction ut = (UserTransaction) utControl.getMock();
@ -1006,6 +1074,7 @@ public class HibernateJtaTransactionTests extends TestCase { @@ -1006,6 +1074,7 @@ public class HibernateJtaTransactionTests extends TestCase {
assertTrue("Hasn't thread session", !TransactionSynchronizationManager.hasResource(sf));
try {
tt.execute(new TransactionCallback() {
public Object doInTransaction(TransactionStatus status) {
org.hibernate.Session outerSession = SessionFactoryUtils.getSession(sf, false);
assertSame(session1, outerSession);
@ -1013,12 +1082,14 @@ public class HibernateJtaTransactionTests extends TestCase { @@ -1013,12 +1082,14 @@ public class HibernateJtaTransactionTests extends TestCase {
assertTrue("Has thread session", holder != null);
try {
tt.execute(new TransactionCallback() {
public Object doInTransaction(TransactionStatus status) {
org.hibernate.Session innerSession = SessionFactoryUtils.getSession(sf, false);
assertSame(session2, innerSession);
HibernateTemplate ht = new HibernateTemplate(sf);
ht.setFlushMode(HibernateTemplate.FLUSH_EAGER);
return ht.executeFind(new HibernateCallback() {
public Object doInHibernate(org.hibernate.Session innerSession) {
if (rollback) {
throw new HibernateException("");
@ -1031,7 +1102,8 @@ public class HibernateJtaTransactionTests extends TestCase { @@ -1031,7 +1102,8 @@ public class HibernateJtaTransactionTests extends TestCase {
return null;
}
finally {
assertTrue("Same thread session as before", outerSession == SessionFactoryUtils.getSession(sf, false));
assertTrue("Same thread session as before",
outerSession == SessionFactoryUtils.getSession(sf, false));
}
}
});
@ -1055,6 +1127,8 @@ public class HibernateJtaTransactionTests extends TestCase { @@ -1055,6 +1127,8 @@ public class HibernateJtaTransactionTests extends TestCase {
session2Control.verify();
}
@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void testTransactionWithPropagationSupports() throws Exception {
MockControl utControl = MockControl.createControl(UserTransaction.class);
UserTransaction ut = (UserTransaction) utControl.getMock();
@ -1098,6 +1172,7 @@ public class HibernateJtaTransactionTests extends TestCase { @@ -1098,6 +1172,7 @@ public class HibernateJtaTransactionTests extends TestCase {
assertTrue("Hasn't thread session", !TransactionSynchronizationManager.hasResource(sf));
tt.execute(new TransactionCallback() {
public Object doInTransaction(TransactionStatus status) {
assertTrue("Hasn't thread session", !TransactionSynchronizationManager.hasResource(sf));
assertTrue("Is not new transaction", !status.isNewTransaction());
@ -1106,6 +1181,7 @@ public class HibernateJtaTransactionTests extends TestCase { @@ -1106,6 +1181,7 @@ public class HibernateJtaTransactionTests extends TestCase {
HibernateTemplate ht = new HibernateTemplate(sf);
ht.setFlushMode(HibernateTemplate.FLUSH_EAGER);
ht.execute(new HibernateCallback() {
public Object doInHibernate(org.hibernate.Session session) {
return null;
}
@ -1120,6 +1196,8 @@ public class HibernateJtaTransactionTests extends TestCase { @@ -1120,6 +1196,8 @@ public class HibernateJtaTransactionTests extends TestCase {
sessionControl.verify();
}
@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void testTransactionWithPropagationSupportsAndInnerTransaction() throws Exception {
MockControl utControl = MockControl.createControl(UserTransaction.class);
UserTransaction ut = (UserTransaction) utControl.getMock();
@ -1161,6 +1239,7 @@ public class HibernateJtaTransactionTests extends TestCase { @@ -1161,6 +1239,7 @@ public class HibernateJtaTransactionTests extends TestCase {
assertTrue("Hasn't thread session", !TransactionSynchronizationManager.hasResource(sf));
tt.execute(new TransactionCallback() {
public Object doInTransaction(TransactionStatus status) {
assertTrue("Hasn't thread session", !TransactionSynchronizationManager.hasResource(sf));
assertTrue("Is not new transaction", !status.isNewTransaction());
@ -1169,19 +1248,22 @@ public class HibernateJtaTransactionTests extends TestCase { @@ -1169,19 +1248,22 @@ public class HibernateJtaTransactionTests extends TestCase {
HibernateTemplate ht = new HibernateTemplate(sf);
ht.setFlushMode(HibernateTemplate.FLUSH_EAGER);
ht.execute(new HibernateCallback() {
public Object doInHibernate(org.hibernate.Session session) {
return null;
}
});
assertTrue("Has thread session", TransactionSynchronizationManager.hasResource(sf));
tt2.execute(new TransactionCallback() {
public Object doInTransaction(TransactionStatus status) {
HibernateTemplate ht = new HibernateTemplate(sf);
ht.setFlushMode(HibernateTemplate.FLUSH_EAGER);
return ht.executeFind(new HibernateCallback() {
public Object doInHibernate(org.hibernate.Session session) {
assertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
//assertTrue(TransactionSynchronizationManager.isActualTransactionActive());
// assertTrue(TransactionSynchronizationManager.isActualTransactionActive());
return null;
}
});
@ -1198,6 +1280,8 @@ public class HibernateJtaTransactionTests extends TestCase { @@ -1198,6 +1280,8 @@ public class HibernateJtaTransactionTests extends TestCase {
sessionControl.verify();
}
@Test
@SuppressWarnings("rawtypes")
public void testJtaSessionSynchronization() throws Exception {
MockControl tmControl = MockControl.createControl(TransactionManager.class);
TransactionManager tm = (TransactionManager) tmControl.getMock();
@ -1231,6 +1315,7 @@ public class HibernateJtaTransactionTests extends TestCase { @@ -1231,6 +1315,7 @@ public class HibernateJtaTransactionTests extends TestCase {
ht.setExposeNativeSession(true);
for (int i = 0; i < 5; i++) {
ht.executeFind(new HibernateCallback() {
public Object doInHibernate(org.hibernate.Session sess) {
assertTrue("Has thread session", TransactionSynchronizationManager.hasResource(sf));
assertEquals(session, sess);
@ -1252,6 +1337,8 @@ public class HibernateJtaTransactionTests extends TestCase { @@ -1252,6 +1337,8 @@ public class HibernateJtaTransactionTests extends TestCase {
sessionControl.verify();
}
@Test
@SuppressWarnings("rawtypes")
public void testJtaSessionSynchronizationWithRollback() throws Exception {
MockControl tmControl = MockControl.createControl(TransactionManager.class);
TransactionManager tm = (TransactionManager) tmControl.getMock();
@ -1281,6 +1368,7 @@ public class HibernateJtaTransactionTests extends TestCase { @@ -1281,6 +1368,7 @@ public class HibernateJtaTransactionTests extends TestCase {
ht.setExposeNativeSession(true);
for (int i = 0; i < 5; i++) {
ht.executeFind(new HibernateCallback() {
public Object doInHibernate(org.hibernate.Session sess) {
assertTrue("Has thread session", TransactionSynchronizationManager.hasResource(sf));
assertEquals(session, sess);
@ -1301,6 +1389,8 @@ public class HibernateJtaTransactionTests extends TestCase { @@ -1301,6 +1389,8 @@ public class HibernateJtaTransactionTests extends TestCase {
sessionControl.verify();
}
@Test
@SuppressWarnings("rawtypes")
public void testJtaSessionSynchronizationWithRollbackByOtherThread() throws Exception {
MockControl tmControl = MockControl.createControl(TransactionManager.class);
TransactionManager tm = (TransactionManager) tmControl.getMock();
@ -1334,6 +1424,7 @@ public class HibernateJtaTransactionTests extends TestCase { @@ -1334,6 +1424,7 @@ public class HibernateJtaTransactionTests extends TestCase {
ht.setExposeNativeSession(true);
for (int i = 0; i < 5; i++) {
ht.executeFind(new HibernateCallback() {
public Object doInHibernate(org.hibernate.Session sess) {
assertTrue("Has thread session", TransactionSynchronizationManager.hasResource(sf));
assertEquals(session, sess);
@ -1345,6 +1436,7 @@ public class HibernateJtaTransactionTests extends TestCase { @@ -1345,6 +1436,7 @@ public class HibernateJtaTransactionTests extends TestCase {
final Synchronization synchronization = transaction.getSynchronization();
assertTrue("JTA synchronization registered", synchronization != null);
Thread thread = new Thread() {
public void run() {
synchronization.afterCompletion(Status.STATUS_ROLLEDBACK);
}
@ -1359,10 +1451,12 @@ public class HibernateJtaTransactionTests extends TestCase { @@ -1359,10 +1451,12 @@ public class HibernateJtaTransactionTests extends TestCase {
tt.setPropagationBehavior(TransactionDefinition.PROPAGATION_SUPPORTS);
tt.setReadOnly(true);
tt.execute(new TransactionCallbackWithoutResult() {
protected void doInTransactionWithoutResult(TransactionStatus status) {
assertTrue("JTA synchronizations active", TransactionSynchronizationManager.isSynchronizationActive());
for (int i = 0; i < 5; i++) {
ht.executeFind(new HibernateCallback() {
public Object doInHibernate(org.hibernate.Session sess) {
assertTrue("Has thread session", TransactionSynchronizationManager.hasResource(sf));
assertEquals(session, sess);
@ -1381,6 +1475,8 @@ public class HibernateJtaTransactionTests extends TestCase { @@ -1381,6 +1475,8 @@ public class HibernateJtaTransactionTests extends TestCase {
sessionControl.verify();
}
@Test
@SuppressWarnings("rawtypes")
public void testJtaSessionSynchronizationWithFlushFailure() throws Exception {
MockControl tmControl = MockControl.createControl(TransactionManager.class);
TransactionManager tm = (TransactionManager) tmControl.getMock();
@ -1417,6 +1513,7 @@ public class HibernateJtaTransactionTests extends TestCase { @@ -1417,6 +1513,7 @@ public class HibernateJtaTransactionTests extends TestCase {
ht.setExposeNativeSession(true);
for (int i = 0; i < 5; i++) {
ht.executeFind(new HibernateCallback() {
public Object doInHibernate(org.hibernate.Session sess) {
assertTrue("Has thread session", TransactionSynchronizationManager.hasResource(sf));
assertEquals(session, sess);
@ -1444,6 +1541,8 @@ public class HibernateJtaTransactionTests extends TestCase { @@ -1444,6 +1541,8 @@ public class HibernateJtaTransactionTests extends TestCase {
sessionControl.verify();
}
@Test
@SuppressWarnings("rawtypes")
public void testJtaSessionSynchronizationWithSuspendedTransaction() throws Exception {
MockControl tmControl = MockControl.createControl(TransactionManager.class);
TransactionManager tm = (TransactionManager) tmControl.getMock();
@ -1488,6 +1587,7 @@ public class HibernateJtaTransactionTests extends TestCase { @@ -1488,6 +1587,7 @@ public class HibernateJtaTransactionTests extends TestCase {
HibernateTemplate ht = new HibernateTemplate(sf);
ht.setExposeNativeSession(true);
ht.executeFind(new HibernateCallback() {
public Object doInHibernate(org.hibernate.Session sess) {
assertTrue("Has thread session", TransactionSynchronizationManager.hasResource(sf));
assertEquals(session1, sess);
@ -1495,6 +1595,7 @@ public class HibernateJtaTransactionTests extends TestCase { @@ -1495,6 +1595,7 @@ public class HibernateJtaTransactionTests extends TestCase {
}
});
ht.executeFind(new HibernateCallback() {
public Object doInHibernate(org.hibernate.Session sess) {
assertTrue("Has thread session", TransactionSynchronizationManager.hasResource(sf));
assertEquals(session2, sess);
@ -1521,6 +1622,8 @@ public class HibernateJtaTransactionTests extends TestCase { @@ -1521,6 +1622,8 @@ public class HibernateJtaTransactionTests extends TestCase {
session2Control.verify();
}
@Test
@SuppressWarnings("rawtypes")
public void testJtaSessionSynchronizationWithNonSessionFactoryImplementor() throws Exception {
MockControl tmControl = MockControl.createControl(TransactionManager.class);
TransactionManager tm = (TransactionManager) tmControl.getMock();
@ -1559,6 +1662,7 @@ public class HibernateJtaTransactionTests extends TestCase { @@ -1559,6 +1662,7 @@ public class HibernateJtaTransactionTests extends TestCase {
ht.setExposeNativeSession(true);
for (int i = 0; i < 5; i++) {
ht.executeFind(new HibernateCallback() {
public Object doInHibernate(org.hibernate.Session sess) {
assertTrue("Has thread session", TransactionSynchronizationManager.hasResource(sf));
assertEquals(session, sess);
@ -1581,6 +1685,9 @@ public class HibernateJtaTransactionTests extends TestCase { @@ -1581,6 +1685,9 @@ public class HibernateJtaTransactionTests extends TestCase {
sfiControl.verify();
}
@Ignore("getting error on UserTransaction mock")
@Test
@SuppressWarnings("rawtypes")
public void testJtaSessionSynchronizationWithSpringTransactionLaterOn() throws Exception {
MockControl utControl = MockControl.createControl(UserTransaction.class);
UserTransaction ut = (UserTransaction) utControl.getMock();
@ -1619,6 +1726,7 @@ public class HibernateJtaTransactionTests extends TestCase { @@ -1619,6 +1726,7 @@ public class HibernateJtaTransactionTests extends TestCase {
ht.setExposeNativeSession(true);
for (int i = 0; i < 2; i++) {
ht.executeFind(new HibernateCallback() {
public Object doInHibernate(org.hibernate.Session sess) {
assertTrue("Has thread session", TransactionSynchronizationManager.hasResource(sf));
assertEquals(session, sess);
@ -1629,9 +1737,11 @@ public class HibernateJtaTransactionTests extends TestCase { @@ -1629,9 +1737,11 @@ public class HibernateJtaTransactionTests extends TestCase {
TransactionTemplate tt = new TransactionTemplate(new JtaTransactionManager(ut));
tt.execute(new TransactionCallbackWithoutResult() {
protected void doInTransactionWithoutResult(TransactionStatus status) {
for (int i = 2; i < 5; i++) {
ht.executeFind(new HibernateCallback() {
public Object doInHibernate(org.hibernate.Session sess) {
assertTrue("Has thread session", TransactionSynchronizationManager.hasResource(sf));
assertEquals(session, sess);
@ -1656,14 +1766,17 @@ public class HibernateJtaTransactionTests extends TestCase { @@ -1656,14 +1766,17 @@ public class HibernateJtaTransactionTests extends TestCase {
sessionControl.verify();
}
@Test
public void testJtaSessionSynchronizationWithPreBound() throws Exception {
doTestJtaSessionSynchronizationWithPreBound(false);
}
@Test
public void testJtaJtaSessionSynchronizationWithPreBoundAndFlushNever() throws Exception {
doTestJtaSessionSynchronizationWithPreBound(true);
}
@SuppressWarnings("rawtypes")
private void doTestJtaSessionSynchronizationWithPreBound(boolean flushNever) throws Exception {
MockControl tmControl = MockControl.createControl(TransactionManager.class);
TransactionManager tm = (TransactionManager) tmControl.getMock();
@ -1701,6 +1814,7 @@ public class HibernateJtaTransactionTests extends TestCase { @@ -1701,6 +1814,7 @@ public class HibernateJtaTransactionTests extends TestCase {
ht.setExposeNativeSession(true);
for (int i = 0; i < 5; i++) {
ht.executeFind(new HibernateCallback() {
public Object doInHibernate(org.hibernate.Session sess) {
assertTrue("Has thread session", TransactionSynchronizationManager.hasResource(sf));
assertEquals(session, sess);
@ -1739,6 +1853,8 @@ public class HibernateJtaTransactionTests extends TestCase { @@ -1739,6 +1853,8 @@ public class HibernateJtaTransactionTests extends TestCase {
sessionControl.verify();
}
@Test
@SuppressWarnings("rawtypes")
public void testJtaSessionSynchronizationWithRemoteTransaction() throws Exception {
MockControl tmControl = MockControl.createControl(TransactionManager.class);
TransactionManager tm = (TransactionManager) tmControl.getMock();
@ -1785,6 +1901,7 @@ public class HibernateJtaTransactionTests extends TestCase { @@ -1785,6 +1901,7 @@ public class HibernateJtaTransactionTests extends TestCase {
ht.setExposeNativeSession(true);
for (int i = 0; i < 5; i++) {
ht.executeFind(new HibernateCallback() {
public Object doInHibernate(org.hibernate.Session sess) {
assertTrue("Has thread session", TransactionSynchronizationManager.hasResource(sf));
assertEquals(session, sess);
@ -1796,9 +1913,12 @@ public class HibernateJtaTransactionTests extends TestCase { @@ -1796,9 +1913,12 @@ public class HibernateJtaTransactionTests extends TestCase {
final Synchronization synchronization = transaction.getSynchronization();
assertTrue("JTA synchronization registered", synchronization != null);
// Call synchronization in a new thread, to simulate a synchronization
// triggered by a new remote call from a remote transaction coordinator.
// Call synchronization in a new thread, to simulate a
// synchronization
// triggered by a new remote call from a remote transaction
// coordinator.
Thread synch = new Thread() {
public void run() {
synchronization.beforeCompletion();
synchronization.afterCompletion(Status.STATUS_COMMITTED);
@ -1829,9 +1949,10 @@ public class HibernateJtaTransactionTests extends TestCase { @@ -1829,9 +1949,10 @@ public class HibernateJtaTransactionTests extends TestCase {
/**
* Interface that combines Hibernate's Session and SessionImplementor interface.
* Necessary for creating a mock that implements both interfaces.
* Note: Hibernate 3.1's SessionImplementor interface does not extend Session anymore.
* Interface that combines Hibernate's Session and SessionImplementor
* interface. Necessary for creating a mock that implements both interfaces.
* Note: Hibernate 3.1's SessionImplementor interface does not extend
* Session anymore.
*/
public static interface ExtendedSession extends Session, SessionImplementor {

7
org.springframework.orm/src/test/java/org/springframework/orm/jpa/AbstractContainerEntityManagerFactoryIntegrationTests.java

@ -40,6 +40,7 @@ import org.springframework.util.SerializationTestUtils; @@ -40,6 +40,7 @@ import org.springframework.util.SerializationTestUtils;
* @author Rod Johnson
* @author Juergen Hoeller
*/
@SuppressWarnings("deprecation")
public abstract class AbstractContainerEntityManagerFactoryIntegrationTests
extends AbstractEntityManagerFactoryIntegrationTests {
@ -73,6 +74,7 @@ public abstract class AbstractContainerEntityManagerFactoryIntegrationTests @@ -73,6 +74,7 @@ public abstract class AbstractContainerEntityManagerFactoryIntegrationTests
}
//@NotTransactional
@SuppressWarnings({ "unused", "unchecked" })
public void testEntityManagerProxyIsProxy() {
assertTrue(Proxy.isProxyClass(sharedEntityManager.getClass()));
Query q = sharedEntityManager.createQuery("select p from Person as p");
@ -127,6 +129,7 @@ public abstract class AbstractContainerEntityManagerFactoryIntegrationTests @@ -127,6 +129,7 @@ public abstract class AbstractContainerEntityManagerFactoryIntegrationTests
}
}
@SuppressWarnings("unchecked")
public void testMultipleResults() {
// Add with JDBC
String firstName = "Tony";
@ -185,6 +188,7 @@ public abstract class AbstractContainerEntityManagerFactoryIntegrationTests @@ -185,6 +188,7 @@ public abstract class AbstractContainerEntityManagerFactoryIntegrationTests
assertEquals("1 row must have been inserted", 1, countRowsInTable("person"));
}
@SuppressWarnings("unchecked")
public void testQueryNoPersons() {
EntityManager em = entityManagerFactory.createEntityManager();
Query q = em.createQuery("select p from Person as p");
@ -200,6 +204,7 @@ public abstract class AbstractContainerEntityManagerFactoryIntegrationTests @@ -200,6 +204,7 @@ public abstract class AbstractContainerEntityManagerFactoryIntegrationTests
}
@NotTransactional
@SuppressWarnings("unchecked")
public void testQueryNoPersonsNotTransactional() {
EntityManager em = entityManagerFactory.createEntityManager();
Query q = em.createQuery("select p from Person as p");
@ -214,6 +219,7 @@ public abstract class AbstractContainerEntityManagerFactoryIntegrationTests @@ -214,6 +219,7 @@ public abstract class AbstractContainerEntityManagerFactoryIntegrationTests
}
}
@SuppressWarnings({ "unused", "unchecked" })
public void testQueryNoPersonsShared() {
EntityManager em = SharedEntityManagerCreator.createSharedEntityManager(entityManagerFactory);
Query q = em.createQuery("select p from Person as p");
@ -229,6 +235,7 @@ public abstract class AbstractContainerEntityManagerFactoryIntegrationTests @@ -229,6 +235,7 @@ public abstract class AbstractContainerEntityManagerFactoryIntegrationTests
}
@NotTransactional
@SuppressWarnings("unchecked")
public void testQueryNoPersonsSharedNotTransactional() {
EntityManager em = SharedEntityManagerCreator.createSharedEntityManager(entityManagerFactory);
Query q = em.createQuery("select p from Person as p");

6
org.springframework.orm/src/test/java/org/springframework/orm/jpa/hibernate/HibernateEntityManagerFactoryIntegrationTests.java

@ -22,11 +22,10 @@ import org.hibernate.Query; @@ -22,11 +22,10 @@ import org.hibernate.Query;
import org.hibernate.SessionFactory;
import org.hibernate.ejb.HibernateEntityManager;
import org.hibernate.ejb.HibernateEntityManagerFactory;
import org.junit.Ignore;
import org.springframework.orm.jpa.AbstractContainerEntityManagerFactoryIntegrationTests;
import org.springframework.orm.jpa.EntityManagerFactoryInfo;
import org.springframework.orm.jpa.domain.Person;
import org.springframework.test.annotation.IfProfileValue;
/**
* Hibernate-specific JPA tests.
@ -34,7 +33,8 @@ import org.springframework.orm.jpa.domain.Person; @@ -34,7 +33,8 @@ import org.springframework.orm.jpa.domain.Person;
* @author Juergen Hoeller
* @author Rod Johnson
*/
@Ignore // cannot find AnnotationBeanConfigurerAspect
// Essentially @Ignore-d since AnnotationBeanConfigurerAspect cannot be found
@IfProfileValue(name="test-group", value="broken")
public class HibernateEntityManagerFactoryIntegrationTests extends
AbstractContainerEntityManagerFactoryIntegrationTests {

Loading…
Cancel
Save