/** * Verifies if the container throws the EJBException when the bean throws a RuntimeException, * discards the bean and does the rollback in this case. * * @throws Exception if an error during the tests occurs. */ public void testNotUsingClientTransWithRuntimeException() throws Exception { // verifies if the container threw the correct exception try { sfsbContainerTransactionRuntime.insertCorrectFirstErrorSecond(DATABASE_1, DATABASE_2); fail("The container did not throw the EJBException."); } catch (EJBException e) { logger.debug("The bean threw an expected error during the execution {0}", e); } // verifies if the bean was discarded assertTrue( ExceptionHandleUtil.isDiscarded(sfsbContainerTransactionRuntime), "There was a runtime exception and the container did not discarded the bean."); // TODO - verifies if the container log the error. // verifies if the table was created in the DATABASE_1 ExceptionHandleUtil.verifyTable(DATABASE_1, ItfContainerTransaction.TABLE); }
/** * Verifies if the container throws the correct exception (EJBException for RequiresNew and * NotSupports, and EJBTransactionRolledbackException for Require, Supports and Mandatory) when * the bean throws a RuntimeException, discards the bean and does the rollback if the bean uses * the client transaction. * * @param expectedException EJBException for RequiresNew and NotSupports, and * EJBTransactionRolledbackException for Require, Supports and Mandatory * @param canCommit true if the bean does not use the client transaction. * @throws Exception if an error during the tests occurs. */ public void testUsingClientTransWithRuntimeException( final Class expectedException, final boolean canCommit) throws Exception { UserTransaction utx = ExceptionHandleUtil.getUserTransaction(); utx.begin(); // verifies if the exception thrown is correct try { sfsbContainerTransactionRuntime.insertCorrectFirstErrorSecond(DATABASE_1, DATABASE_2); } catch (Exception e) { assertTrue( ExceptionHelper.isEquals(e, expectedException), "The container did not throw the correct exception, the expected exception is " + expectedException.getName() + ", but the container threw " + e.getClass().getName()); } // tries to commit try { utx.commit(); if (!canCommit) { fail("The transaction was marked as rolled back, the client cannot make the commit."); } } catch (Exception e) { logger.debug("The bean threw an expected error during the execution {0}", e); } // verifies if the bean was discarded assertTrue( ExceptionHandleUtil.isDiscarded(sfsbContainerTransactionRuntime), "There was a runtime exception and the container did not discarded the bean."); // verifies if the transaction was rolled back if (!canCommit) { try { // verifies if the table was created in the DATABASE_1 ExceptionHandleUtil.verifyTable(DATABASE_1, ItfContainerTransaction.TABLE); fail("There was an error during the commit and the transaction was not rolled back."); } catch (SQLException e) { logger.debug("The bean threw an expected error during the execution {0}", e); } } // TODO - verifies if the container log the error. }