[hibernate-commits] Hibernate SVN: r10475 - in branches/Branch_3_2/Hibernate3/test/org/hibernate/test: . bytecode bytecode/cglib bytecode/javassist

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Fri Sep 8 09:59:01 EDT 2006


Author: steve.ebersole at jboss.com
Date: 2006-09-08 09:58:59 -0400 (Fri, 08 Sep 2006)
New Revision: 10475

Added:
   branches/Branch_3_2/Hibernate3/test/org/hibernate/test/bytecode/BytecodeSuite.java
   branches/Branch_3_2/Hibernate3/test/org/hibernate/test/bytecode/cglib/InvocationTargetExceptionTest.java
   branches/Branch_3_2/Hibernate3/test/org/hibernate/test/bytecode/javassist/InvocationTargetExceptionTest.java
Modified:
   branches/Branch_3_2/Hibernate3/test/org/hibernate/test/AllTests.java
   branches/Branch_3_2/Hibernate3/test/org/hibernate/test/bytecode/Bean.hbm.xml
   branches/Branch_3_2/Hibernate3/test/org/hibernate/test/bytecode/Bean.java
Log:
HHH-1986 : InvocationTargetException on JavassistLazyInitializer

Modified: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/AllTests.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/AllTests.java	2006-09-08 13:58:40 UTC (rev 10474)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/AllTests.java	2006-09-08 13:58:59 UTC (rev 10475)
@@ -4,7 +4,6 @@
 import junit.framework.Test;
 import junit.framework.TestSuite;
 import junit.textui.TestRunner;
-
 import org.hibernate.dialect.Dialect;
 import org.hibernate.test.abstractembeddedcomponents.cid.AbstractCompositeIdTest;
 import org.hibernate.test.abstractembeddedcomponents.propertyref.AbstractComponentPropertyRefTest;
@@ -14,6 +13,7 @@
 import org.hibernate.test.batchfetch.BatchFetchTest;
 import org.hibernate.test.bidi.AuctionTest;
 import org.hibernate.test.bidi.AuctionTest2;
+import org.hibernate.test.bytecode.BytecodeSuite;
 import org.hibernate.test.cache.CacheSuite;
 import org.hibernate.test.cascade.RefreshTest;
 import org.hibernate.test.cid.CompositeIdTest;
@@ -126,11 +126,11 @@
 import org.hibernate.test.unconstrained.UnconstrainedTest;
 import org.hibernate.test.unidir.BackrefTest;
 import org.hibernate.test.unionsubclass.UnionSubclassTest;
+import org.hibernate.test.util.UtilSuite;
 import org.hibernate.test.version.VersionTest;
 import org.hibernate.test.version.db.DbVersionTest;
 import org.hibernate.test.version.sybase.SybaseTimestampVersioningTest;
 import org.hibernate.test.where.WhereTest;
-import org.hibernate.test.util.UtilSuite;
 
 /**
  * @author Gavin King
@@ -286,8 +286,7 @@
 			suite.addTest( SequenceIdentityTest.suite() );
 			suite.addTest( InterceptorDynamicEntityTest.suite() );
 			suite.addTest( TuplizerDynamicEntityTest.suite() );
-			suite.addTest( org.hibernate.test.bytecode.cglib.ReflectionOptimizerTest.suite() );
-			suite.addTest( org.hibernate.test.bytecode.javassist.ReflectionOptimizerTest.suite() );
+			suite.addTest( BytecodeSuite.suite() );
 			suite.addTest( JPAComplianceSuite.suite() );
 			suite.addTest( AbstractComponentPropertyRefTest.suite() );
 			suite.addTest( AbstractCompositeIdTest.suite() );

Modified: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/bytecode/Bean.hbm.xml
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/bytecode/Bean.hbm.xml	2006-09-08 13:58:40 UTC (rev 10474)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/bytecode/Bean.hbm.xml	2006-09-08 13:58:59 UTC (rev 10475)
@@ -9,12 +9,12 @@
 		<id name="someString" type="string">
 			<generator class="assigned"/>
 		</id>
-        <property name="someLong" type="long"/>
-        <property name="someInteger" type="int"/>
-        <property name="someDate" type="timestamp"/>
-        <property name="somelong" type="long"/>
-        <property name="someint" type="int"/>
-        <property name="someObject" type="serializable"/>
+        <property name="someLong" type="long" column="S_LONG_1" />
+        <property name="someInteger" type="int" column="S_INT_1" />
+        <property name="someDate" type="timestamp" column="S_DATE_1" />
+        <property name="somelong" type="long" column="S_LONG_2" />
+        <property name="someint" type="int" column="S_INT_2" />
+        <property name="someObject" type="serializable" column="S_OBJ_1" />
 	</class>
 
 </hibernate-mapping>

Modified: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/bytecode/Bean.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/bytecode/Bean.java	2006-09-08 13:58:40 UTC (rev 10474)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/bytecode/Bean.java	2006-09-08 13:58:59 UTC (rev 10475)
@@ -1,6 +1,7 @@
 package org.hibernate.test.bytecode;
 
 import java.util.Date;
+import java.text.ParseException;
 
 /**
  * @author Steve Ebersole
@@ -70,4 +71,8 @@
 	public void setSomeObject(Object someObject) {
 		this.someObject = someObject;
 	}
+
+	public void throwException() throws ParseException {
+		throw new ParseException( "you asked for it...", 0 );
+	}
 }

Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/bytecode/BytecodeSuite.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/bytecode/BytecodeSuite.java	2006-09-08 13:58:40 UTC (rev 10474)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/bytecode/BytecodeSuite.java	2006-09-08 13:58:59 UTC (rev 10475)
@@ -0,0 +1,20 @@
+package org.hibernate.test.bytecode;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * todo: describe BytecodeSuite
+ *
+ * @author Steve Ebersole
+ */
+public class BytecodeSuite {
+	public static Test suite() {
+		TestSuite suite = new TestSuite( "BytecodeProvider tests" );
+		suite.addTest( org.hibernate.test.bytecode.cglib.ReflectionOptimizerTest.suite() );
+		suite.addTest( org.hibernate.test.bytecode.cglib.InvocationTargetExceptionTest.suite() );
+		suite.addTest( org.hibernate.test.bytecode.javassist.ReflectionOptimizerTest.suite() );
+		suite.addTest( org.hibernate.test.bytecode.javassist.InvocationTargetExceptionTest.suite() );
+		return suite;
+	}
+}

Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/bytecode/cglib/InvocationTargetExceptionTest.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/bytecode/cglib/InvocationTargetExceptionTest.java	2006-09-08 13:58:40 UTC (rev 10474)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/bytecode/cglib/InvocationTargetExceptionTest.java	2006-09-08 13:58:59 UTC (rev 10475)
@@ -0,0 +1,64 @@
+package org.hibernate.test.bytecode.cglib;
+
+import org.hibernate.test.TestCase;
+import org.hibernate.test.bytecode.Bean;
+import org.hibernate.Session;
+import org.hibernate.Hibernate;
+import org.hibernate.cfg.Environment;
+import junit.framework.TestSuite;
+
+import java.text.ParseException;
+
+/**
+ * Test that the Javassist-based lazy initializer properly handles
+ * InvocationTargetExceptions
+ *
+ * @author Steve Ebersole
+ */
+public class InvocationTargetExceptionTest extends TestCase {
+	public InvocationTargetExceptionTest(String name) {
+		super( name );
+	}
+
+	protected String[] getMappings() {
+		return new String[] { "bytecode/Bean.hbm.xml" };
+	}
+
+	public static TestSuite suite() {
+		return new TestSuite( InvocationTargetExceptionTest.class );
+	}
+
+	public void testProxiedInvocationException() {
+		if ( ! ( Environment.getBytecodeProvider() instanceof org.hibernate.bytecode.cglib.BytecodeProviderImpl ) ) {
+			// because of the scoping :(
+			reportSkip( "env not configured for cglib provider", "bytecode-provider InvocationTargetException handling" );
+			return;
+		}
+		Session s = openSession();
+		s.beginTransaction();
+		Bean bean = new Bean();
+		bean.setSomeString( "my-bean" );
+		s.save( bean );
+		s.getTransaction().commit();
+		s.close();
+
+		s = openSession();
+		s.beginTransaction();
+		bean = ( Bean ) s.load( Bean.class, bean.getSomeString() );
+		assertFalse( Hibernate.isInitialized( bean ) );
+		try {
+			bean.throwException();
+			fail( "exception not thrown" );
+		}
+		catch ( ParseException e ) {
+			// expected behavior
+		}
+		catch( Throwable t ) {
+			fail( "unexpected exception type : " + t );
+		}
+
+		s.delete( bean );
+		s.getTransaction().commit();
+		s.close();
+	}
+}

Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/bytecode/javassist/InvocationTargetExceptionTest.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/bytecode/javassist/InvocationTargetExceptionTest.java	2006-09-08 13:58:40 UTC (rev 10474)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/bytecode/javassist/InvocationTargetExceptionTest.java	2006-09-08 13:58:59 UTC (rev 10475)
@@ -0,0 +1,65 @@
+package org.hibernate.test.bytecode.javassist;
+
+import org.hibernate.test.TestCase;
+import org.hibernate.test.bytecode.Bean;
+import org.hibernate.Session;
+import org.hibernate.Hibernate;
+import org.hibernate.cfg.Environment;
+
+import java.text.ParseException;
+
+import junit.framework.TestSuite;
+
+/**
+ * Test that the Javassist-based lazy initializer properly handles
+ * InvocationTargetExceptions
+ *
+ * @author Steve Ebersole
+ */
+public class InvocationTargetExceptionTest extends TestCase {
+	public InvocationTargetExceptionTest(String name) {
+		super( name );
+	}
+
+	protected String[] getMappings() {
+		return new String[] { "bytecode/Bean.hbm.xml" };
+	}
+
+	public static TestSuite suite() {
+		return new TestSuite( InvocationTargetExceptionTest.class );
+	}
+
+	public void testProxiedInvocationException() {
+		if ( ! ( Environment.getBytecodeProvider() instanceof org.hibernate.bytecode.javassist.BytecodeProviderImpl ) ) {
+			// because of the scoping :(
+			reportSkip( "env not configured for javassist provider", "bytecode-provider InvocationTargetException handling" );
+			return;
+		}
+		Session s = openSession();
+		s.beginTransaction();
+		Bean bean = new Bean();
+		bean.setSomeString( "my-bean" );
+		s.save( bean );
+		s.getTransaction().commit();
+		s.close();
+
+		s = openSession();
+		s.beginTransaction();
+		bean = ( Bean ) s.load( Bean.class, bean.getSomeString() );
+		assertFalse( Hibernate.isInitialized( bean ) );
+		try {
+			bean.throwException();
+			fail( "exception not thrown" );
+		}
+		catch ( ParseException e ) {
+			// expected behavior
+		}
+		catch( Throwable t ) {
+			fail( "unexpected exception type : " + t );
+		}
+
+		s.delete( bean );
+		s.getTransaction().commit();
+		s.close();
+	}
+}




More information about the hibernate-commits mailing list