Hibernate SVN: r10416 - branches/Branch_3_2/Hibernate3/test/org/hibernate/test/subclassfilter
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2006-09-01 16:36:18 -0400 (Fri, 01 Sep 2006)
New Revision: 10416
Modified:
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/subclassfilter/JoinedSubclassFilterTest.java
Log:
test data cleanup
Modified: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/subclassfilter/JoinedSubclassFilterTest.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/subclassfilter/JoinedSubclassFilterTest.java 2006-09-01 20:36:02 UTC (rev 10415)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/subclassfilter/JoinedSubclassFilterTest.java 2006-09-01 20:36:18 UTC (rev 10416)
@@ -48,7 +48,7 @@
final Person p = ( Person ) itr.next();
if ( p.getName().equals( "John Doe" ) ) {
Employee john = ( Employee ) p;
- assertEquals( "Incorrect fecthed minions count", 2, john.getMinions().size() );
+ assertEquals( "Incorrect fetched minions count", 2, john.getMinions().size() );
break;
}
}
@@ -66,7 +66,7 @@
final Person p = ( Person ) itr.next();
if ( p.getName().equals( "John Doe" ) ) {
Employee john = ( Employee ) p;
- assertEquals( "Incorrect fecthed minions count", 2, john.getMinions().size() );
+ assertEquals( "Incorrect fetched minions count", 2, john.getMinions().size() );
break;
}
}
@@ -80,13 +80,19 @@
final Person p = ( Person ) itr.next();
if ( p.getName().equals( "John Doe" ) ) {
Employee john = ( Employee ) p;
- assertEquals( "Incorrect fecthed minions count", 2, john.getMinions().size() );
+ assertEquals( "Incorrect fetched minions count", 2, john.getMinions().size() );
break;
}
}
t.commit();
s.close();
+
+ s = openSession();
+ t = s.beginTransaction();
+ s.createQuery( "delete Person" ).executeUpdate();
+ t.commit();
+ s.close();
}
private void prepareTestData(Session s) {
18 years, 4 months
Hibernate SVN: r10415 - trunk/Hibernate3/test/org/hibernate/test/subclassfilter
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2006-09-01 16:36:02 -0400 (Fri, 01 Sep 2006)
New Revision: 10415
Modified:
trunk/Hibernate3/test/org/hibernate/test/subclassfilter/JoinedSubclassFilterTest.java
Log:
test data cleanup
Modified: trunk/Hibernate3/test/org/hibernate/test/subclassfilter/JoinedSubclassFilterTest.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/subclassfilter/JoinedSubclassFilterTest.java 2006-09-01 20:30:43 UTC (rev 10414)
+++ trunk/Hibernate3/test/org/hibernate/test/subclassfilter/JoinedSubclassFilterTest.java 2006-09-01 20:36:02 UTC (rev 10415)
@@ -87,6 +87,12 @@
t.commit();
s.close();
+
+ s = openSession();
+ t = s.beginTransaction();
+ s.createQuery( "delete Person" ).executeUpdate();
+ t.commit();
+ s.close();
}
private void prepareTestData(Session s) {
18 years, 4 months
Hibernate SVN: r10414 - branches/Branch_3_2/Hibernate3/test/org/hibernate/test/typedmanytoone
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2006-09-01 16:30:43 -0400 (Fri, 01 Sep 2006)
New Revision: 10414
Modified:
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/typedmanytoone/Customer.hbm.xml
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/typedmanytoone/TypedManyToOneTest.java
Log:
test data cleanup
Modified: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/typedmanytoone/Customer.hbm.xml
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/typedmanytoone/Customer.hbm.xml 2006-09-01 20:30:22 UTC (rev 10413)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/typedmanytoone/Customer.hbm.xml 2006-09-01 20:30:43 UTC (rev 10414)
@@ -27,7 +27,7 @@
<many-to-one name="billingAddress"
entity-name="BillingAddress"
- cascade="persist,save-update"
+ cascade="persist,save-update,delete"
fetch="join">
<column name="billingAddressId"/>
<formula>'BILLING'</formula>
@@ -35,7 +35,7 @@
<many-to-one name="shippingAddress"
entity-name="ShippingAddress"
- cascade="persist,save-update"
+ cascade="persist,save-update,delete"
fetch="join">
<column name="shippingAddressId"/>
<formula>'SHIPPING'</formula>
Modified: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/typedmanytoone/TypedManyToOneTest.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/typedmanytoone/TypedManyToOneTest.java 2006-09-01 20:30:22 UTC (rev 10413)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/typedmanytoone/TypedManyToOneTest.java 2006-09-01 20:30:43 UTC (rev 10414)
@@ -72,6 +72,7 @@
s.delete("ShippingAddress", ship);
s.flush();
assertNull( s.get( "ShippingAddress", ship.getAddressId() ) );
+ s.delete( cust );
t.commit();
s.close();
}
@@ -94,9 +95,9 @@
cust = (Customer) results.get(0);
assertNull( cust.getShippingAddress() );
assertNull( cust.getBillingAddress() );
+ s.delete( cust );
t.commit();
s.close();
-
}
protected String[] getMappings() {
18 years, 4 months
Hibernate SVN: r10413 - trunk/Hibernate3/test/org/hibernate/test/typedmanytoone
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2006-09-01 16:30:22 -0400 (Fri, 01 Sep 2006)
New Revision: 10413
Modified:
trunk/Hibernate3/test/org/hibernate/test/typedmanytoone/Customer.hbm.xml
trunk/Hibernate3/test/org/hibernate/test/typedmanytoone/TypedManyToOneTest.java
Log:
test data cleanup
Modified: trunk/Hibernate3/test/org/hibernate/test/typedmanytoone/Customer.hbm.xml
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/typedmanytoone/Customer.hbm.xml 2006-09-01 20:26:37 UTC (rev 10412)
+++ trunk/Hibernate3/test/org/hibernate/test/typedmanytoone/Customer.hbm.xml 2006-09-01 20:30:22 UTC (rev 10413)
@@ -27,7 +27,7 @@
<many-to-one name="billingAddress"
entity-name="BillingAddress"
- cascade="persist,save-update"
+ cascade="persist,save-update,delete"
fetch="join">
<column name="billingAddressId"/>
<formula>'BILLING'</formula>
@@ -35,7 +35,7 @@
<many-to-one name="shippingAddress"
entity-name="ShippingAddress"
- cascade="persist,save-update"
+ cascade="persist,save-update,delete"
fetch="join">
<column name="shippingAddressId"/>
<formula>'SHIPPING'</formula>
Modified: trunk/Hibernate3/test/org/hibernate/test/typedmanytoone/TypedManyToOneTest.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/typedmanytoone/TypedManyToOneTest.java 2006-09-01 20:26:37 UTC (rev 10412)
+++ trunk/Hibernate3/test/org/hibernate/test/typedmanytoone/TypedManyToOneTest.java 2006-09-01 20:30:22 UTC (rev 10413)
@@ -72,6 +72,7 @@
s.delete("ShippingAddress", ship);
s.flush();
assertNull( s.get( "ShippingAddress", ship.getAddressId() ) );
+ s.delete( cust );
t.commit();
s.close();
}
@@ -94,6 +95,7 @@
cust = (Customer) results.get(0);
assertNull( cust.getShippingAddress() );
assertNull( cust.getBillingAddress() );
+ s.delete( cust );
t.commit();
s.close();
18 years, 4 months
Hibernate SVN: r10412 - trunk/Hibernate3/test/org/hibernate/test/typedonetoone
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2006-09-01 16:26:37 -0400 (Fri, 01 Sep 2006)
New Revision: 10412
Modified:
trunk/Hibernate3/test/org/hibernate/test/typedonetoone/Customer.hbm.xml
trunk/Hibernate3/test/org/hibernate/test/typedonetoone/TypedOneToOneTest.java
Log:
test data cleanup
Modified: trunk/Hibernate3/test/org/hibernate/test/typedonetoone/Customer.hbm.xml
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/typedonetoone/Customer.hbm.xml 2006-09-01 20:26:21 UTC (rev 10411)
+++ trunk/Hibernate3/test/org/hibernate/test/typedonetoone/Customer.hbm.xml 2006-09-01 20:26:37 UTC (rev 10412)
@@ -26,13 +26,13 @@
<one-to-one name="billingAddress"
entity-name="BillingAddress"
property-ref="customer"
- cascade="persist"
+ cascade="persist, delete"
fetch="join"/>
<one-to-one name="shippingAddress"
entity-name="ShippingAddress"
property-ref="customer"
- cascade="persist"
+ cascade="persist, delete"
fetch="join"/>
</class>
Modified: trunk/Hibernate3/test/org/hibernate/test/typedonetoone/TypedOneToOneTest.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/typedonetoone/TypedOneToOneTest.java 2006-09-01 20:26:21 UTC (rev 10411)
+++ trunk/Hibernate3/test/org/hibernate/test/typedonetoone/TypedOneToOneTest.java 2006-09-01 20:26:37 UTC (rev 10412)
@@ -61,10 +61,10 @@
assertEquals( "30326", cust.getShippingAddress().getZip() );
assertEquals( "BILLING", cust.getBillingAddress().getAddressId().getType() );
assertEquals( "SHIPPING", cust.getShippingAddress().getAddressId().getType() );
-
+ s.delete( cust );
t.commit();
s.close();
-
+
}
public void testCreateQueryNull() {
18 years, 4 months
Hibernate SVN: r10411 - branches/Branch_3_2/Hibernate3/test/org/hibernate/test/typedonetoone
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2006-09-01 16:26:21 -0400 (Fri, 01 Sep 2006)
New Revision: 10411
Modified:
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/typedonetoone/Customer.hbm.xml
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/typedonetoone/TypedOneToOneTest.java
Log:
test data cleanup
Modified: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/typedonetoone/Customer.hbm.xml
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/typedonetoone/Customer.hbm.xml 2006-09-01 20:06:15 UTC (rev 10410)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/typedonetoone/Customer.hbm.xml 2006-09-01 20:26:21 UTC (rev 10411)
@@ -26,13 +26,13 @@
<one-to-one name="billingAddress"
entity-name="BillingAddress"
property-ref="customer"
- cascade="persist"
+ cascade="persist, delete"
fetch="join"/>
<one-to-one name="shippingAddress"
entity-name="ShippingAddress"
property-ref="customer"
- cascade="persist"
+ cascade="persist, delete"
fetch="join"/>
</class>
Modified: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/typedonetoone/TypedOneToOneTest.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/typedonetoone/TypedOneToOneTest.java 2006-09-01 20:06:15 UTC (rev 10410)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/typedonetoone/TypedOneToOneTest.java 2006-09-01 20:26:21 UTC (rev 10411)
@@ -61,10 +61,9 @@
assertEquals( "30326", cust.getShippingAddress().getZip() );
assertEquals( "BILLING", cust.getBillingAddress().getAddressId().getType() );
assertEquals( "SHIPPING", cust.getShippingAddress().getAddressId().getType() );
-
+ s.delete( cust );
t.commit();
s.close();
-
}
public void testCreateQueryNull() {
18 years, 4 months
Hibernate SVN: r10410 - trunk/Hibernate3/test/org/hibernate/test/optlock
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2006-09-01 16:06:15 -0400 (Fri, 01 Sep 2006)
New Revision: 10410
Modified:
trunk/Hibernate3/test/org/hibernate/test/optlock/Document.hbm.xml
trunk/Hibernate3/test/org/hibernate/test/optlock/OptimisticLockTest.java
Log:
fixed failures on SQLServer
Modified: trunk/Hibernate3/test/org/hibernate/test/optlock/Document.hbm.xml
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/optlock/Document.hbm.xml 2006-09-01 20:05:56 UTC (rev 10409)
+++ trunk/Hibernate3/test/org/hibernate/test/optlock/Document.hbm.xml 2006-09-01 20:06:15 UTC (rev 10410)
@@ -14,7 +14,7 @@
<hibernate-mapping package="org.hibernate.test.optlock">
<class name="Document"
- entity-name="Dirty"
+ entity-name="LockDirty"
table="Document"
optimistic-lock="dirty"
dynamic-update="true">
@@ -33,7 +33,7 @@
</class>
<class name="Document"
- entity-name="All"
+ entity-name="LockAll"
table="Document"
optimistic-lock="all"
dynamic-update="true">
Modified: trunk/Hibernate3/test/org/hibernate/test/optlock/OptimisticLockTest.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/optlock/OptimisticLockTest.java 2006-09-01 20:05:56 UTC (rev 10409)
+++ trunk/Hibernate3/test/org/hibernate/test/optlock/OptimisticLockTest.java 2006-09-01 20:06:15 UTC (rev 10410)
@@ -7,6 +7,8 @@
import org.hibernate.Session;
import org.hibernate.StaleObjectStateException;
import org.hibernate.Transaction;
+import org.hibernate.JDBCException;
+import org.hibernate.dialect.SQLServerDialect;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
import org.hibernate.test.TestCase;
@@ -37,19 +39,19 @@
}
public void testOptimisticLockDirty() {
- testUpdateOptimisticLockFailure( "Dirty" );
+ testUpdateOptimisticLockFailure( "LockDirty" );
}
public void testOptimisticLockAll() {
- testUpdateOptimisticLockFailure( "All" );
+ testUpdateOptimisticLockFailure( "LockAll" );
}
public void testOptimisticLockDirtyDelete() {
- testDeleteOptimisticLockFailure( "Dirty" );
+ testDeleteOptimisticLockFailure( "LockDirty" );
}
public void testOptimisticLockAllDelete() {
- testDeleteOptimisticLockFailure( "All" );
+ testDeleteOptimisticLockFailure( "LockAll" );
}
private void testUpdateOptimisticLockFailure(String entityName) {
@@ -84,6 +86,18 @@
catch ( StaleObjectStateException expected ) {
// expected result...
}
+ catch( JDBCException e ) {
+ // SQLServer will report this condition via a SQLException
+ // when using its SNAPSHOT transaction isolation...
+ if ( ! ( getDialect() instanceof SQLServerDialect && e.getErrorCode() == 3960 ) ) {
+ throw e;
+ }
+ else {
+ // it seems to "lose track" of the transaction as well...
+ t.rollback();
+ t = s.beginTransaction();
+ }
+ }
s.clear();
t.commit();
s.close();
@@ -134,6 +148,18 @@
catch ( StaleObjectStateException e ) {
// expected
}
+ catch( JDBCException e ) {
+ // SQLServer will report this condition via a SQLException
+ // when using its SNAPSHOT transaction isolation...
+ if ( ! ( getDialect() instanceof SQLServerDialect && e.getErrorCode() == 3960 ) ) {
+ throw e;
+ }
+ else {
+ // it seems to "lose track" of the transaction as well...
+ t.rollback();
+ t = s.beginTransaction();
+ }
+ }
s.clear();
t.commit();
s.close();
18 years, 4 months
Hibernate SVN: r10409 - branches/Branch_3_2/Hibernate3/test/org/hibernate/test/optlock
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2006-09-01 16:05:56 -0400 (Fri, 01 Sep 2006)
New Revision: 10409
Modified:
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/optlock/Document.hbm.xml
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/optlock/OptimisticLockTest.java
Log:
fixed failures on SQLServer
Modified: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/optlock/Document.hbm.xml
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/optlock/Document.hbm.xml 2006-09-01 18:43:11 UTC (rev 10408)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/optlock/Document.hbm.xml 2006-09-01 20:05:56 UTC (rev 10409)
@@ -14,7 +14,7 @@
<hibernate-mapping package="org.hibernate.test.optlock">
<class name="Document"
- entity-name="Dirty"
+ entity-name="LockDirty"
table="Document"
optimistic-lock="dirty"
dynamic-update="true">
@@ -33,7 +33,7 @@
</class>
<class name="Document"
- entity-name="All"
+ entity-name="LockAll"
table="Document"
optimistic-lock="all"
dynamic-update="true">
Modified: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/optlock/OptimisticLockTest.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/optlock/OptimisticLockTest.java 2006-09-01 18:43:11 UTC (rev 10408)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/optlock/OptimisticLockTest.java 2006-09-01 20:05:56 UTC (rev 10409)
@@ -7,6 +7,8 @@
import org.hibernate.Session;
import org.hibernate.StaleObjectStateException;
import org.hibernate.Transaction;
+import org.hibernate.JDBCException;
+import org.hibernate.dialect.SQLServerDialect;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
import org.hibernate.test.TestCase;
@@ -37,19 +39,19 @@
}
public void testOptimisticLockDirty() {
- testUpdateOptimisticLockFailure( "Dirty" );
+ testUpdateOptimisticLockFailure( "LockDirty" );
}
public void testOptimisticLockAll() {
- testUpdateOptimisticLockFailure( "All" );
+ testUpdateOptimisticLockFailure( "LockAll" );
}
public void testOptimisticLockDirtyDelete() {
- testDeleteOptimisticLockFailure( "Dirty" );
+ testDeleteOptimisticLockFailure( "LockDirty" );
}
public void testOptimisticLockAllDelete() {
- testDeleteOptimisticLockFailure( "All" );
+ testDeleteOptimisticLockFailure( "LockAll" );
}
private void testUpdateOptimisticLockFailure(String entityName) {
@@ -84,6 +86,18 @@
catch ( StaleObjectStateException expected ) {
// expected result...
}
+ catch( JDBCException e ) {
+ // SQLServer will report this condition via a SQLException
+ // when using its SNAPSHOT transaction isolation...
+ if ( ! ( getDialect() instanceof SQLServerDialect && e.getErrorCode() == 3960 ) ) {
+ throw e;
+ }
+ else {
+ // it seems to "lose track" of the transaction as well...
+ t.rollback();
+ t = s.beginTransaction();
+ }
+ }
s.clear();
t.commit();
s.close();
@@ -134,6 +148,18 @@
catch ( StaleObjectStateException e ) {
// expected
}
+ catch( JDBCException e ) {
+ // SQLServer will report this condition via a SQLException
+ // when using its SNAPSHOT transaction isolation...
+ if ( ! ( getDialect() instanceof SQLServerDialect && e.getErrorCode() == 3960 ) ) {
+ throw e;
+ }
+ else {
+ // it seems to "lose track" of the transaction as well...
+ t.rollback();
+ t = s.beginTransaction();
+ }
+ }
s.clear();
t.commit();
s.close();
18 years, 4 months
Hibernate SVN: r10408 - branches/Branch_3_2/Hibernate3/test/org/hibernate/test
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2006-09-01 14:43:11 -0400 (Fri, 01 Sep 2006)
New Revision: 10408
Modified:
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/TestCase.java
Log:
code cleanup; javadoc
Modified: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/TestCase.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/TestCase.java 2006-09-01 18:42:57 UTC (rev 10407)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/TestCase.java 2006-09-01 18:43:11 UTC (rev 10408)
@@ -7,9 +7,10 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import java.util.Properties;
import junit.framework.AssertionFailedError;
+import junit.framework.TestResult;
+import junit.framework.TestListener;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -28,6 +29,7 @@
import org.hibernate.dialect.SQLServerDialect;
import org.hibernate.dialect.SybaseDialect;
import org.hibernate.dialect.TimesTenDialect;
+import org.hibernate.dialect.DerbyDialect;
import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.mapping.Collection;
import org.hibernate.mapping.PersistentClass;
@@ -41,46 +43,146 @@
private static Dialect dialect;
private static Class lastTestClass;
private org.hibernate.classic.Session session;
-
+
+ public TestCase(String name) {
+ super( name );
+ }
+
+
+ // methods for subclasses to change test environment ~~~~~~~~~~~~~~~~~~~~~~
+
+ /**
+ * Get the mapping resources to be used to build the configuration.
+ * <p/>
+ * Resources should be relative to {@link #getBaseForMappings()}
+ *
+ * @return The mapping resources
+ */
+ protected abstract String[] getMappings();
+
+ /**
+ * The base name for relative mapping resources. The default is
+ * <tt>org/hibernate/test/</tt>
+ *
+ * @return the mapping resource base
+ */
+ protected String getBaseForMappings() {
+ return "org/hibernate/test/";
+ }
+
+ /**
+ * Should the database schema be (re)created
+ *
+ * @return True for auto export (including recreation on test failure).
+ */
protected boolean recreateSchema() {
return true;
}
- public TestCase(String name) {
- super( name );
+ protected boolean dropAfterFailure() {
+ return true;
}
- protected void configure(Configuration cfg) {}
+ /**
+ * Apply any test-specific configuration prior to building the factory.
+ *
+ * @param cfg The configuration which will be used to construct the factory.
+ */
+ protected void configure(Configuration cfg) {
+ }
- private void buildSessionFactory(String[] files) throws Exception {
+ protected boolean overrideCacheStrategy() {
+ return true;
+ }
- if ( getSessions()!=null ) getSessions().close();
+ protected String getCacheConcurrencyStrategy() {
+ return "nonstrict-read-write";
+ }
- setDialect( Dialect.getDialect() );
- if ( ! appliesTo( getDialect() ) ) {
- return;
- }
- try {
+ // methods for subclasses to access environment ~~~~~~~~~~~~~~~~~~~~~~~~~~~
- setCfg( new Configuration() );
+ /**
+ * Get the factory for this test environment.
+ *
+ * @return The factory.
+ */
+ protected SessionFactory getSessions() {
+ return sessions;
+ }
- cfg.addProperties( getExtraProperties() );
+ /**
+ * Get the factory for this test environment, casted to {@link SessionFactoryImplementor}.
+ * <p/>
+ * Shorthand for ( {@link SessionFactoryImplementor} ) {@link #getSessions()}...
+ *
+ * @return The factory
+ */
+ protected SessionFactoryImplementor sfi() {
+ return ( SessionFactoryImplementor ) getSessions();
+ }
- if( recreateSchema() ) {
- cfg.setProperty(Environment.HBM2DDL_AUTO, "create-drop");
- }
+ protected Dialect getDialect() {
+ return dialect;
+ }
- Configuration cfg2 = getCfg();
+ protected Configuration getCfg() {
+ return cfg;
+ }
- addMappings( files, cfg2 );
+ public org.hibernate.classic.Session openSession() throws HibernateException {
+ session = getSessions().openSession();
+ return session;
+ }
- cfg.setProperty( Environment.CACHE_PROVIDER, "org.hibernate.cache.HashtableCacheProvider" );
+ public org.hibernate.classic.Session openSession(Interceptor interceptor)
+ throws HibernateException {
+ session = getSessions().openSession(interceptor);
+ return session;
+ }
- configure(cfg);
- if ( getCacheConcurrencyStrategy()!=null ) {
+ // JUnit hooks ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ /**
+ * The Hibernate test suite tries to only build the db schema once
+ * per test class (not test case which = instance) hence all the
+ * static vars.
+ * <p/>
+ * Here is the crux of that attempt. We only build a factory when one was
+ * not previously built, or when we start a new test class.
+ *
+ * @throws Exception
+ */
+ protected void setUp() throws Exception {
+ if ( getSessions() == null || lastTestClass != getClass() ) {
+ buildSessionFactory();
+ lastTestClass = getClass();
+ }
+ }
+
+
+ private void buildSessionFactory() throws Exception {
+ if ( getSessions()!=null ) {
+ getSessions().close();
+ }
+
+ TestCase.dialect = Dialect.getDialect();
+ if ( ! appliesTo( getDialect() ) ) {
+ return;
+ }
+
+ try {
+
+ TestCase.cfg = new Configuration();
+ cfg.setProperty( Environment.CACHE_PROVIDER, "org.hibernate.cache.HashtableCacheProvider" );
+ if( recreateSchema() ) {
+ cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
+ }
+ addMappings( getMappings(), cfg );
+ configure( cfg );
+
+ if ( getCacheConcurrencyStrategy() != null ) {
Iterator iter = cfg.getClassMappings();
while ( iter.hasNext() ) {
PersistentClass clazz = (PersistentClass) iter.next();
@@ -90,8 +192,12 @@
Property prop = (Property) props.next();
if ( prop.getValue().isSimpleValue() ) {
String type = ( (SimpleValue) prop.getValue() ).getTypeName();
- if ( "blob".equals(type) || "clob".equals(type) ) hasLob = true;
- if ( Blob.class.getName().equals(type) || Clob.class.getName().equals(type) ) hasLob = true;
+ if ( "blob".equals( type ) || "clob".equals( type ) ) {
+ hasLob = true;
+ }
+ if ( Blob.class.getName().equals( type ) || Clob.class.getName().equals( type ) ) {
+ hasLob = true;
+ }
}
}
if ( !hasLob && !clazz.isInherited() && overrideCacheStrategy() ) {
@@ -101,7 +207,6 @@
);
}
}
-
iter = cfg.getCollectionMappings();
while ( iter.hasNext() ) {
Collection coll = (Collection) iter.next();
@@ -110,22 +215,24 @@
getCacheConcurrencyStrategy()
);
}
-
}
- setSessions( cfg2.buildSessionFactory( /*new TestInterceptor()*/ ) );
-
+ // make sure we use the same dialect...
+ cfg.setProperty( Environment.DIALECT, TestCase.dialect.getClass().getName() );
+ TestCase.sessions = cfg.buildSessionFactory();
afterSessionFactoryBuilt();
}
- catch (Exception e) {
+ catch ( Exception e ) {
e.printStackTrace();
throw e;
}
}
protected void addMappings(String[] files, Configuration cfg) {
- for (int i=0; i<files.length; i++) {
- if ( !files[i].startsWith("net/") ) files[i] = getBaseForMappings() + files[i];
+ for ( int i = 0; i < files.length; i++ ) {
+ if ( !files[i].startsWith( "net/" ) ) {
+ files[i] = getBaseForMappings() + files[i];
+ }
cfg.addResource( files[i], TestCase.class.getClassLoader() );
}
}
@@ -135,146 +242,120 @@
// when SF (re)built...
}
- protected boolean overrideCacheStrategy() {
- return true;
- }
-
- protected String getBaseForMappings() {
- return "org/hibernate/test/";
- }
-
- public String getCacheConcurrencyStrategy() {
- return "nonstrict-read-write";
- }
-
- protected void setUp() throws Exception {
- if ( getSessions()==null || lastTestClass!=getClass() ) {
- buildSessionFactory( getMappings() );
- lastTestClass = getClass();
- }
- }
-
protected void runTest() throws Throwable {
- final boolean stats = ( (SessionFactoryImplementor) sessions ).getStatistics().isStatisticsEnabled();
+ final boolean stats = sessions.getStatistics().isStatisticsEnabled();
try {
- if (stats) sessions.getStatistics().clear();
+ if ( stats ) {
+ sessions.getStatistics().clear();
+ }
super.runTest();
- if (stats) sessions.getStatistics().logSummary();
+ if ( stats ) {
+ sessions.getStatistics().logSummary();
+ }
- if ( session!=null && session.isOpen() ) {
- if ( session.isConnected() ) session.connection().rollback();
+ if ( session != null && session.isOpen() ) {
+ if ( session.isConnected() ) {
+ session.connection().rollback();
+ }
session.close();
session = null;
- fail("unclosed session");
+ fail( "unclosed session" );
}
else {
- session=null;
-
- //assertAllDataRemoved();
-
+ session = null;
}
+ assertAllDataRemoved();
}
- catch (Throwable e) {
+ catch ( Throwable e ) {
try {
- if ( session!=null && session.isOpen() ) {
- if ( session.isConnected() ) session.connection().rollback();
+ if ( session != null && session.isOpen() ) {
+ if ( session.isConnected() ) {
+ session.connection().rollback();
+ }
session.close();
}
}
- catch (Exception ignore) {}
+ catch ( Exception ignore ) {
+ }
try {
- if ( dropAfterFailure() && sessions!=null ) {
+ if ( dropAfterFailure() && sessions != null ) {
sessions.close();
- sessions=null;
+ sessions = null;
}
}
- catch (Exception ignore) {}
+ catch ( Exception ignore ) {
+ }
throw e;
}
}
+ public void runBare() throws Throwable {
+ String sysPropName = "hibernate.test.validatefailureexpected";
+ assertNotNull( getName() );
+ if ( Boolean.getBoolean( sysPropName ) ) {
+ if ( getName().endsWith( "FailureExpected" ) ) {
+ Throwable t = null;
+ try {
+ super.runBare();
+ }
+ catch ( Throwable afe ) {
+ t = afe;
+ }
+ if ( t == null ) {
+ fail( "Test where marked as FailureExpected, but did not fail!" );
+ }
+ else {
+ reportSkip( "ignoring *FailuredExpected methods", "Failed with: " + t.toString() );
+ }
+ }
+ else {
+ super.runBare();
+ }
+ }
+ else {
+ super.runBare();
+ }
+ }
+
protected void assertAllDataRemoved() {
- if(!recreateSchema()) {
+ if ( !recreateSchema() ) {
return; // no tables were created...
}
-
- Session tmpSession = openSession();
- List list = tmpSession.createQuery( "from java.lang.Object" ).list();
-
- StringBuffer sb = new StringBuffer();
- Map items = new HashMap();
-
- if(!list.isEmpty()) {
- for (Iterator iter = list.iterator(); iter.hasNext();) {
- Object element = iter.next();
- Integer l = (Integer) items.get(tmpSession.getEntityName( element ));
- if(l==null) {
- l = new Integer(0);
+ if ( Boolean.getBoolean( "hibernate.test.skipCleanupValidation" ) ) {
+ return;
+ }
+
+ Session tmpSession = sessions.openSession();
+ try {
+ List list = tmpSession.createQuery( "from java.lang.Object" ).list();
+
+ Map items = new HashMap();
+ if ( !list.isEmpty() ) {
+ for ( Iterator iter = list.iterator(); iter.hasNext(); ) {
+ Object element = iter.next();
+ Integer l = ( Integer ) items.get( tmpSession.getEntityName( element ) );
+ if ( l == null ) {
+ l = new Integer( 0 );
+ }
+ l = new Integer( l.intValue() + 1 );
+ items.put( tmpSession.getEntityName( element ), l );
+ System.out.println( "Data left: " + element );
}
- l = new Integer(l.intValue()+1);
- items.put(tmpSession.getEntityName( element ), l);
- System.out.println("Data left: " + element);
+ fail( "Data is left in the database: " + items.toString() );
}
+ }
+ finally {
try {
tmpSession.close();
- } finally {
- fail("Data is left in the database: " + items.toString() );
}
- } else {
- tmpSession.close();
+ catch( Throwable t ) {
+ // intentionally empty
+ }
}
}
- protected boolean dropAfterFailure() {
- return true;
- }
-
- public org.hibernate.classic.Session openSession() throws HibernateException {
- session = getSessions().openSession();
- return session;
- }
-
- public org.hibernate.classic.Session openSession(Interceptor interceptor)
- throws HibernateException {
- session = getSessions().openSession(interceptor);
- return session;
- }
-
- protected abstract String[] getMappings();
-
- private void setSessions(SessionFactory sessions) {
- TestCase.sessions = sessions;
- }
-
- protected SessionFactory getSessions() {
- return sessions;
- }
-
- private void setDialect(Dialect dialect) {
- TestCase.dialect = dialect;
- }
-
- protected Dialect getDialect() {
- return dialect;
- }
-
- protected static void setCfg(Configuration cfg) {
- TestCase.cfg = cfg;
- }
-
- protected static Configuration getCfg() {
- return cfg;
- }
-
- /**
- * @deprecated
- */
- public Properties getExtraProperties() {
- return new Properties();
- }
-
public static void assertElementTypeAssignability(java.util.Collection collection, Class clazz) throws AssertionFailedError {
Iterator itr = collection.iterator();
while ( itr.hasNext() ) {
@@ -291,6 +372,19 @@
}
}
+
+ // test skipping ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ protected static final Log SKIP_LOG = LogFactory.getLog("org.hibernate.test.SKIPPED");
+
+ public String fullTestName() {
+ return this.getName() + " (" + this.getClass().getName() + ")";
+ }
+
+ protected void reportSkip(String reason, String testDescription) {
+ SKIP_LOG.warn( "*** skipping [" + fullTestName() + "] - " + testDescription + " : " + reason, new Exception() );
+ }
+
/**
* Intended to indicate that this test class as a whole is intended for
* a dialect or series of dialects. Skips here (appliesTo = false), therefore
@@ -303,8 +397,18 @@
return true;
}
- protected static final Log SKIP_LOG = LogFactory.getLog("org.hibernate.test.SKIPPED");
-
+ /**
+ * Is connection at least read committed?
+ * <p/>
+ * Not, that this skip check relies on the JDBC driver reporting
+ * the true isolation level correctly. HSQLDB, for example, will
+ * report whatever you specify as the isolation
+ * (Connection.setTransationIsolation()), even though it only supports
+ * read-uncommitted.
+ *
+ * @param scenario text description of the scenario being tested.
+ * @return true if read-committed isolation is maintained.
+ */
protected boolean readCommittedIsolationMaintained(String scenario) {
int isolation = java.sql.Connection.TRANSACTION_READ_UNCOMMITTED;
Session testSession = null;
@@ -315,9 +419,9 @@
catch( Throwable ignore ) {
}
finally {
- if ( session != null ) {
+ if ( testSession != null ) {
try {
- session.close();
+ testSession.close();
}
catch( Throwable ignore ) {
}
@@ -332,33 +436,86 @@
}
}
- protected boolean dialectSupportsEmptyInList(String testdescription) {
- return reportSkip( "Dialect does not support SQL: \'x in ()\'.", testdescription, dialectIsNot(new Class[] {
- Oracle9Dialect.class,
- MySQLDialect.class,
- DB2Dialect.class,
- HSQLDialect.class,
- SQLServerDialect.class,
- SybaseDialect.class,
- PostgreSQLDialect.class,
- TimesTenDialect.class
- } ));
+ /**
+ * Does the db/dialect support using a column's physical name in the order-by clause
+ * even after it has been aliased in the select clause. This is not actually
+ * required by the SQL spec, although virtually ever DB in the world supports this
+ * (the most glaring omission here being IBM-variant DBs ala DB2 and Derby).
+ *
+ * @param testDescription description of the scenario being tested.
+ * @return true if is allowed
+ */
+ protected boolean allowsPhysicalColumnNameInOrderby(String testDescription) {
+ if ( DB2Dialect.class.isInstance( getDialect() ) ) {
+ // https://issues.apache.org/jira/browse/DERBY-1624
+ reportSkip( "Dialect does not support physical column name in order-by clause after it is aliased", testDescription );
+ return false;
+ }
+ return true;
}
- protected boolean dialectIsCaseSensitive(String testdescription) {
- // MySQL and SQLServer is case insensitive on strings (at least in default installation)
- return reportSkip( "Dialect is case sensitive. ", testdescription, dialectIsNot(new Class[] { MySQLDialect.class, SQLServerDialect.class }));
+ /**
+ * Does the db/dialect support using a column's physical name in the having clause
+ * even after it has been aliased in the select/group-by clause. This is not actually
+ * required by the SQL spec, although virtually ever DB in the world supports this.
+ *
+ * @param testDescription description of the scenario being tested.
+ * @return true if is allowed
+ */
+ protected boolean allowsPhysicalColumnNameInHaving(String testDescription) {
+ // I only *know* of this being a limitation on Derby, although I highly suspect
+ // it is a limitation on any IBM/DB2 variant
+ if ( DerbyDialect.class.isInstance( getDialect() ) ) {
+ // https://issues.apache.org/jira/browse/DERBY-1624
+ reportSkip( "Dialect does not support physical column name in having clause after it is aliased", testDescription );
+ return false;
+ }
+ return true;
}
- protected boolean reportSkip(String reason, String testDescription, boolean canDoIt) {
+ /**
+ * Does the db/dialect support empty lists in the IN operator?
+ * <p/>
+ * For example, is "... a.b IN () ..." supported?
+ *
+ * @param testDescription description of the scenario being tested.
+ * @return true if is allowed
+ */
+ protected boolean dialectSupportsEmptyInList(String testDescription) {
+ boolean canDoIt = dialectIsNot(
+ new Class[] {
+ Oracle9Dialect.class,
+ MySQLDialect.class,
+ DB2Dialect.class,
+ HSQLDialect.class,
+ SQLServerDialect.class,
+ SybaseDialect.class,
+ PostgreSQLDialect.class,
+ TimesTenDialect.class
+ }
+ );
+
if ( !canDoIt ) {
- reportSkip( reason, testDescription );
+ reportSkip( "Dialect does not support SQL: \'x in ()\'.", testDescription );
}
return canDoIt;
}
- protected void reportSkip(String reason, String testDescription) {
- SKIP_LOG.warn( "*** skipping [" + fullTestName() + "] - " + testDescription + " : " + reason, new Exception() );
+ /**
+ * Is the db/dialect sensitive in terms of string comparisons?
+ * @param testDescription description of the scenario being tested.
+ * @return true if sensitive
+ */
+ protected boolean dialectIsCaseSensitive(String testDescription) {
+ // MySQL and SQLServer is case insensitive on strings (at least in default installation)
+ boolean canDoIt = dialectIsNot(
+ new Class[] { MySQLDialect.class, SQLServerDialect.class }
+ );
+
+ if ( !canDoIt ) {
+ reportSkip( "Dialect is case sensitive. ", testDescription );
+ }
+ return canDoIt;
}
private boolean dialectIsNot(Class[] dialectClasses) {
@@ -371,35 +528,4 @@
return true;
}
- public String fullTestName() {
- return this.getName() + " (" + this.getClass().getName() + ")";
- }
-
- protected SessionFactoryImplementor sfi() {
- return ( SessionFactoryImplementor ) getSessions();
- }
-
- public void runBare() throws Throwable {
- assertNotNull(getName());
- String string = "hibernate.test.validatefailureexpected";
- if(Boolean.getBoolean( string )) {
- if(getName().endsWith( "FailureExpected" ) ) {
- Throwable t = null;
- try {
- super.runBare();
- } catch(Throwable afe) {
- t = afe;
- }
- if(t==null) {
- fail("Test where marked as FailureExpected, but did not fail!");
- } else {
- reportSkip( "ignoring *FailuredExpected methods", "Failed with: " + t.toString() );
- }
- } else {
- super.runBare();
- }
- } else {
- super.runBare();
- }
- }
}
\ No newline at end of file
18 years, 4 months
Hibernate SVN: r10407 - trunk/Hibernate3/test/org/hibernate/test
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2006-09-01 14:42:57 -0400 (Fri, 01 Sep 2006)
New Revision: 10407
Modified:
trunk/Hibernate3/test/org/hibernate/test/TestCase.java
Log:
code cleanup; javadoc
Modified: trunk/Hibernate3/test/org/hibernate/test/TestCase.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/TestCase.java 2006-09-01 18:41:02 UTC (rev 10406)
+++ trunk/Hibernate3/test/org/hibernate/test/TestCase.java 2006-09-01 18:42:57 UTC (rev 10407)
@@ -7,7 +7,6 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import java.util.Properties;
import junit.framework.AssertionFailedError;
@@ -43,45 +42,145 @@
private static Class lastTestClass;
private org.hibernate.classic.Session session;
+ public TestCase(String name) {
+ super( name );
+ }
+
+
+ // methods for subclasses to change test environment ~~~~~~~~~~~~~~~~~~~~~~
+
+ /**
+ * Get the mapping resources to be used to build the configuration.
+ * <p/>
+ * Resources should be relative to {@link #getBaseForMappings()}
+ *
+ * @return The mapping resources
+ */
+ protected abstract String[] getMappings();
+
+ /**
+ * The base name for relative mapping resources. The default is
+ * <tt>org/hibernate/test/</tt>
+ *
+ * @return the mapping resource base
+ */
+ protected String getBaseForMappings() {
+ return "org/hibernate/test/";
+ }
+
+ /**
+ * Should the database schema be (re)created
+ *
+ * @return True for auto export (including recreation on test failure).
+ */
protected boolean recreateSchema() {
return true;
}
- public TestCase(String name) {
- super( name );
+ protected boolean dropAfterFailure() {
+ return true;
}
- protected void configure(Configuration cfg) {}
+ /**
+ * Apply any test-specific configuration prior to building the factory.
+ *
+ * @param cfg The configuration which will be used to construct the factory.
+ */
+ protected void configure(Configuration cfg) {
+ }
- private void buildSessionFactory(String[] files) throws Exception {
+ protected boolean overrideCacheStrategy() {
+ return true;
+ }
- if ( getSessions()!=null ) getSessions().close();
+ protected String getCacheConcurrencyStrategy() {
+ return "nonstrict-read-write";
+ }
- setDialect( Dialect.getDialect() );
- if ( ! appliesTo( getDialect() ) ) {
- return;
- }
- try {
+ // methods for subclasses to access environment ~~~~~~~~~~~~~~~~~~~~~~~~~~~
- setCfg( new Configuration() );
+ /**
+ * Get the factory for this test environment.
+ *
+ * @return The factory.
+ */
+ protected SessionFactory getSessions() {
+ return sessions;
+ }
- cfg.addProperties( getExtraProperties() );
+ /**
+ * Get the factory for this test environment, casted to {@link SessionFactoryImplementor}.
+ * <p/>
+ * Shorthand for ( {@link SessionFactoryImplementor} ) {@link #getSessions()}...
+ *
+ * @return The factory
+ */
+ protected SessionFactoryImplementor sfi() {
+ return ( SessionFactoryImplementor ) getSessions();
+ }
- if( recreateSchema() ) {
- cfg.setProperty(Environment.HBM2DDL_AUTO, "create-drop");
- }
+ protected Dialect getDialect() {
+ return dialect;
+ }
- Configuration cfg2 = getCfg();
+ protected Configuration getCfg() {
+ return cfg;
+ }
- addMappings( files, cfg2 );
+ public org.hibernate.classic.Session openSession() throws HibernateException {
+ session = getSessions().openSession();
+ return session;
+ }
- cfg.setProperty( Environment.CACHE_PROVIDER, "org.hibernate.cache.HashtableCacheProvider" );
+ public org.hibernate.classic.Session openSession(Interceptor interceptor)
+ throws HibernateException {
+ session = getSessions().openSession(interceptor);
+ return session;
+ }
- configure(cfg);
- if ( getCacheConcurrencyStrategy()!=null ) {
+ // JUnit hooks ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ /**
+ * The Hibernate test suite tries to only build the db schema once
+ * per test class (not test case which = instance) hence all the
+ * static vars.
+ * <p/>
+ * Here is the crux of that attempt. We only build a factory when one was
+ * not previously built, or when we start a new test class.
+ *
+ * @throws Exception
+ */
+ protected void setUp() throws Exception {
+ if ( getSessions() == null || lastTestClass != getClass() ) {
+ buildSessionFactory();
+ lastTestClass = getClass();
+ }
+ }
+
+
+ private void buildSessionFactory() throws Exception {
+ if ( getSessions()!=null ) {
+ getSessions().close();
+ }
+
+ TestCase.dialect = Dialect.getDialect();
+ if ( ! appliesTo( getDialect() ) ) {
+ return;
+ }
+
+ try {
+
+ TestCase.cfg = new Configuration();
+ cfg.setProperty( Environment.CACHE_PROVIDER, "org.hibernate.cache.HashtableCacheProvider" );
+ if( recreateSchema() ) {
+ cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
+ }
+ addMappings( getMappings(), cfg );
+ configure( cfg );
+
+ if ( getCacheConcurrencyStrategy() != null ) {
Iterator iter = cfg.getClassMappings();
while ( iter.hasNext() ) {
PersistentClass clazz = (PersistentClass) iter.next();
@@ -102,7 +201,6 @@
);
}
}
-
iter = cfg.getCollectionMappings();
while ( iter.hasNext() ) {
Collection coll = (Collection) iter.next();
@@ -111,22 +209,24 @@
getCacheConcurrencyStrategy()
);
}
-
}
- setSessions( cfg2.buildSessionFactory( /*new TestInterceptor()*/ ) );
-
+ // make sure we use the same dialect...
+ cfg.setProperty( Environment.DIALECT, TestCase.dialect.getClass().getName() );
+ TestCase.sessions = cfg.buildSessionFactory();
afterSessionFactoryBuilt();
}
- catch (Exception e) {
+ catch ( Exception e ) {
e.printStackTrace();
throw e;
}
}
protected void addMappings(String[] files, Configuration cfg) {
- for (int i=0; i<files.length; i++) {
- if ( !files[i].startsWith("net/") ) files[i] = getBaseForMappings() + files[i];
+ for ( int i = 0; i < files.length; i++ ) {
+ if ( !files[i].startsWith( "net/" ) ) {
+ files[i] = getBaseForMappings() + files[i];
+ }
cfg.addResource( files[i], TestCase.class.getClassLoader() );
}
}
@@ -136,66 +236,51 @@
// when SF (re)built...
}
- protected boolean overrideCacheStrategy() {
- return true;
- }
-
- protected String getBaseForMappings() {
- return "org/hibernate/test/";
- }
-
- public String getCacheConcurrencyStrategy() {
- return "nonstrict-read-write";
- }
-
- protected SessionFactoryImplementor sfi() {
- return ( SessionFactoryImplementor ) getSessions();
- }
-
- protected void setUp() throws Exception {
- if ( getSessions()==null || lastTestClass!=getClass() ) {
- buildSessionFactory( getMappings() );
- lastTestClass = getClass();
- }
- }
-
protected void runTest() throws Throwable {
- final boolean stats = ( (SessionFactoryImplementor) sessions ).getStatistics().isStatisticsEnabled();
+ final boolean stats = sessions.getStatistics().isStatisticsEnabled();
try {
- if (stats) sessions.getStatistics().clear();
+ if ( stats ) {
+ sessions.getStatistics().clear();
+ }
super.runTest();
- if (stats) sessions.getStatistics().logSummary();
+ if ( stats ) {
+ sessions.getStatistics().logSummary();
+ }
- if ( session!=null && session.isOpen() ) {
- if ( session.isConnected() ) session.connection().rollback();
+ if ( session != null && session.isOpen() ) {
+ if ( session.isConnected() ) {
+ session.connection().rollback();
+ }
session.close();
session = null;
- fail("unclosed session");
+ fail( "unclosed session" );
}
else {
- session=null;
-
- //assertAllDataRemoved();
-
+ session = null;
}
+ assertAllDataRemoved();
}
- catch (Throwable e) {
+ catch ( Throwable e ) {
try {
- if ( session!=null && session.isOpen() ) {
- if ( session.isConnected() ) session.connection().rollback();
+ if ( session != null && session.isOpen() ) {
+ if ( session.isConnected() ) {
+ session.connection().rollback();
+ }
session.close();
}
}
- catch (Exception ignore) {}
+ catch ( Exception ignore ) {
+ }
try {
- if ( dropAfterFailure() && sessions!=null ) {
+ if ( dropAfterFailure() && sessions != null ) {
sessions.close();
- sessions=null;
+ sessions = null;
}
}
- catch (Exception ignore) {}
+ catch ( Exception ignore ) {
+ }
throw e;
}
}
@@ -232,84 +317,39 @@
if ( !recreateSchema() ) {
return; // no tables were created...
}
+ if ( Boolean.getBoolean( "hibernate.test.skipCleanupValidation" ) ) {
+ return;
+ }
- Session tmpSession = openSession();
- List list = tmpSession.createQuery( "from java.lang.Object" ).list();
+ Session tmpSession = sessions.openSession();
+ try {
+ List list = tmpSession.createQuery( "from java.lang.Object" ).list();
- StringBuffer sb = new StringBuffer();
- Map items = new HashMap();
-
- if ( !list.isEmpty() ) {
- for ( Iterator iter = list.iterator(); iter.hasNext(); ) {
- Object element = iter.next();
- Integer l = ( Integer ) items.get( tmpSession.getEntityName( element ) );
- if ( l == null ) {
- l = new Integer( 0 );
+ Map items = new HashMap();
+ if ( !list.isEmpty() ) {
+ for ( Iterator iter = list.iterator(); iter.hasNext(); ) {
+ Object element = iter.next();
+ Integer l = ( Integer ) items.get( tmpSession.getEntityName( element ) );
+ if ( l == null ) {
+ l = new Integer( 0 );
+ }
+ l = new Integer( l.intValue() + 1 );
+ items.put( tmpSession.getEntityName( element ), l );
+ System.out.println( "Data left: " + element );
}
- l = new Integer( l.intValue() + 1 );
- items.put( tmpSession.getEntityName( element ), l );
- System.out.println( "Data left: " + element );
+ fail( "Data is left in the database: " + items.toString() );
}
+ }
+ finally {
try {
tmpSession.close();
}
- finally {
- fail( "Data is left in the database: " + items.toString() );
+ catch( Throwable t ) {
+ // intentionally empty
}
}
- else {
- tmpSession.close();
- }
}
- protected boolean dropAfterFailure() {
- return true;
- }
-
- public org.hibernate.classic.Session openSession() throws HibernateException {
- session = getSessions().openSession();
- return session;
- }
-
- public org.hibernate.classic.Session openSession(Interceptor interceptor)
- throws HibernateException {
- session = getSessions().openSession(interceptor);
- return session;
- }
-
- protected abstract String[] getMappings();
-
- private void setSessions(SessionFactory sessions) {
- TestCase.sessions = sessions;
- }
-
- protected SessionFactory getSessions() {
- return sessions;
- }
-
- private void setDialect(Dialect dialect) {
- TestCase.dialect = dialect;
- }
-
- protected Dialect getDialect() {
- return dialect;
- }
-
- protected static void setCfg(Configuration cfg) {
- TestCase.cfg = cfg;
- }
-
- protected static Configuration getCfg() {
- return cfg;
- }
-
- /**
- * @deprecated
- */
- public Properties getExtraProperties() {
- return new Properties();
- }
-
public static void assertElementTypeAssignability(java.util.Collection collection, Class clazz) throws AssertionFailedError {
Iterator itr = collection.iterator();
while ( itr.hasNext() ) {
@@ -329,6 +369,16 @@
// test skipping ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ protected static final Log SKIP_LOG = LogFactory.getLog("org.hibernate.test.SKIPPED");
+
+ public String fullTestName() {
+ return this.getName() + " (" + this.getClass().getName() + ")";
+ }
+
+ protected void reportSkip(String reason, String testDescription) {
+ SKIP_LOG.warn( "*** skipping [" + fullTestName() + "] - " + testDescription + " : " + reason, new Exception() );
+ }
+
/**
* Intended to indicate that this test class as a whole is intended for
* a dialect or series of dialects. Skips here (appliesTo = false), therefore
@@ -341,8 +391,18 @@
return true;
}
- protected static final Log SKIP_LOG = LogFactory.getLog("org.hibernate.test.SKIPPED");
-
+ /**
+ * Is connection at least read committed?
+ * <p/>
+ * Not, that this skip check relies on the JDBC driver reporting
+ * the true isolation level correctly. HSQLDB, for example, will
+ * report whatever you specify as the isolation
+ * (Connection.setTransationIsolation()), even though it only supports
+ * read-uncommitted.
+ *
+ * @param scenario text description of the scenario being tested.
+ * @return true if read-committed isolation is maintained.
+ */
protected boolean readCommittedIsolationMaintained(String scenario) {
int isolation = java.sql.Connection.TRANSACTION_READ_UNCOMMITTED;
Session testSession = null;
@@ -353,9 +413,9 @@
catch( Throwable ignore ) {
}
finally {
- if ( session != null ) {
+ if ( testSession != null ) {
try {
- session.close();
+ testSession.close();
}
catch( Throwable ignore ) {
}
@@ -370,22 +430,51 @@
}
}
+ /**
+ * Does the db/dialect support using a column's physical name in the order-by clause
+ * even after it has been aliased in the select clause. This is not actually
+ * required by the SQL spec, although virtually ever DB in the world supports this
+ * (the most glaring omission here being IBM-variant DBs ala DB2 and Derby).
+ *
+ * @param testDescription description of the scenario being tested.
+ * @return true if is allowed
+ */
protected boolean allowsPhysicalColumnNameInOrderby(String testDescription) {
- if ( DerbyDialect.class.isInstance( getDialect() ) ) {
+ if ( DB2Dialect.class.isInstance( getDialect() ) ) {
+ // https://issues.apache.org/jira/browse/DERBY-1624
reportSkip( "Dialect does not support physical column name in order-by clause after it is aliased", testDescription );
return false;
}
return true;
}
+ /**
+ * Does the db/dialect support using a column's physical name in the having clause
+ * even after it has been aliased in the select/group-by clause. This is not actually
+ * required by the SQL spec, although virtually ever DB in the world supports this.
+ *
+ * @param testDescription description of the scenario being tested.
+ * @return true if is allowed
+ */
protected boolean allowsPhysicalColumnNameInHaving(String testDescription) {
+ // I only *know* of this being a limitation on Derby, although I highly suspect
+ // it is a limitation on any IBM/DB2 variant
if ( DerbyDialect.class.isInstance( getDialect() ) ) {
+ // https://issues.apache.org/jira/browse/DERBY-1624
reportSkip( "Dialect does not support physical column name in having clause after it is aliased", testDescription );
return false;
}
return true;
}
+ /**
+ * Does the db/dialect support empty lists in the IN operator?
+ * <p/>
+ * For example, is "... a.b IN () ..." supported?
+ *
+ * @param testDescription description of the scenario being tested.
+ * @return true if is allowed
+ */
protected boolean dialectSupportsEmptyInList(String testDescription) {
boolean canDoIt = dialectIsNot(
new Class[] {
@@ -406,6 +495,11 @@
return canDoIt;
}
+ /**
+ * Is the db/dialect sensitive in terms of string comparisons?
+ * @param testDescription description of the scenario being tested.
+ * @return true if sensitive
+ */
protected boolean dialectIsCaseSensitive(String testDescription) {
// MySQL and SQLServer is case insensitive on strings (at least in default installation)
boolean canDoIt = dialectIsNot(
@@ -418,14 +512,6 @@
return canDoIt;
}
- protected void reportSkip(String reason, String testDescription) {
- SKIP_LOG.warn( "*** skipping [" + fullTestName() + "] - " + testDescription + " : " + reason, new Exception() );
- }
-
- public String fullTestName() {
- return this.getName() + " (" + this.getClass().getName() + ")";
- }
-
private boolean dialectIsNot(Class[] dialectClasses) {
for (int i = 0; i < dialectClasses.length; i++) {
Class dialectClass = dialectClasses[i];
18 years, 4 months