FileDocCategorySizeDatePackage
InvocationTargetExceptionTest.javaAPI DocHibernate 3.2.51943Tue Dec 12 16:22:26 GMT 2006org.hibernate.test.bytecode.cglib

InvocationTargetExceptionTest

public class InvocationTargetExceptionTest extends org.hibernate.junit.functional.FunctionalTestCase
Test that the Javassist-based lazy initializer properly handles InvocationTargetExceptions
author
Steve Ebersole

Fields Summary
Constructors Summary
public InvocationTargetExceptionTest(String name)

		super( name );
	
Methods Summary
public java.lang.String[]getMappings()

		return new String[] { "bytecode/Bean.hbm.xml" };
	
public static junit.framework.TestSuitesuite()

		return new FunctionalTestClassTestSuite( InvocationTargetExceptionTest.class );
	
public voidtestProxiedInvocationException()

		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();