[hibernate-commits] Hibernate SVN: r10472 - in trunk/Hibernate3/test/org/hibernate/test/bytecode: . cglib javassist
hibernate-commits at lists.jboss.org
hibernate-commits at lists.jboss.org
Fri Sep 8 09:55:35 EDT 2006
Author: steve.ebersole at jboss.com
Date: 2006-09-08 09:55:33 -0400 (Fri, 08 Sep 2006)
New Revision: 10472
Added:
trunk/Hibernate3/test/org/hibernate/test/bytecode/BytecodeSuite.java
trunk/Hibernate3/test/org/hibernate/test/bytecode/cglib/InvocationTargetExceptionTest.java
trunk/Hibernate3/test/org/hibernate/test/bytecode/javassist/InvocationTargetExceptionTest.java
Modified:
trunk/Hibernate3/test/org/hibernate/test/bytecode/Bean.hbm.xml
trunk/Hibernate3/test/org/hibernate/test/bytecode/Bean.java
Log:
HHH-1986 : InvocationTargetException on JavassistLazyInitializer
Modified: trunk/Hibernate3/test/org/hibernate/test/bytecode/Bean.hbm.xml
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/bytecode/Bean.hbm.xml 2006-09-08 13:55:13 UTC (rev 10471)
+++ trunk/Hibernate3/test/org/hibernate/test/bytecode/Bean.hbm.xml 2006-09-08 13:55:33 UTC (rev 10472)
@@ -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: trunk/Hibernate3/test/org/hibernate/test/bytecode/Bean.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/bytecode/Bean.java 2006-09-08 13:55:13 UTC (rev 10471)
+++ trunk/Hibernate3/test/org/hibernate/test/bytecode/Bean.java 2006-09-08 13:55:33 UTC (rev 10472)
@@ -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: trunk/Hibernate3/test/org/hibernate/test/bytecode/BytecodeSuite.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/bytecode/BytecodeSuite.java 2006-09-08 13:55:13 UTC (rev 10471)
+++ trunk/Hibernate3/test/org/hibernate/test/bytecode/BytecodeSuite.java 2006-09-08 13:55:33 UTC (rev 10472)
@@ -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: trunk/Hibernate3/test/org/hibernate/test/bytecode/cglib/InvocationTargetExceptionTest.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/bytecode/cglib/InvocationTargetExceptionTest.java 2006-09-08 13:55:13 UTC (rev 10471)
+++ trunk/Hibernate3/test/org/hibernate/test/bytecode/cglib/InvocationTargetExceptionTest.java 2006-09-08 13:55:33 UTC (rev 10472)
@@ -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: trunk/Hibernate3/test/org/hibernate/test/bytecode/javassist/InvocationTargetExceptionTest.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/bytecode/javassist/InvocationTargetExceptionTest.java 2006-09-08 13:55:13 UTC (rev 10471)
+++ trunk/Hibernate3/test/org/hibernate/test/bytecode/javassist/InvocationTargetExceptionTest.java 2006-09-08 13:55:33 UTC (rev 10472)
@@ -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