1 25 package org.objectweb.easybeans.tests.transaction.containermanaged.base; 26 27 import static org.testng.Assert.fail; 28 29 import java.sql.SQLException ; 30 31 import javax.ejb.EJBTransactionRolledbackException ; 32 import javax.transaction.UserTransaction ; 33 34 import org.objectweb.easybeans.log.JLog; 35 import org.objectweb.easybeans.log.JLogFactory; 36 import org.objectweb.easybeans.tests.common.ejbs.base.transaction.ItfContainerTransaction; 37 import org.objectweb.easybeans.tests.common.ejbs.stateless.containermanaged.transaction.ItfTransactionMisc00; 38 39 59 public abstract class TestMandatoryException extends TestContainerTransactionException { 60 61 64 private static JLog logger = JLogFactory.getLog(TestMandatoryException.class); 65 66 73 @Override 74 public void testCallOtherBeanNotSup() throws Exception { 75 UserTransaction utx = ExceptionHandleUtil.getUserTransaction(); 76 utx.begin(); 77 try { 78 getRuntimeBean().insertTablesUsingAuxBeanNotSup(DATABASE_1, DATABASE_2); 79 fail("The container did not throw the EJBTransactionRolledbackException."); 80 } catch (EJBTransactionRolledbackException e) { 81 logger.debug("The bean threw an expected error during the execution {0}", e); 82 } 83 if (!ExceptionHandleUtil.isDiscarded(getRuntimeBean())) { 85 fail("The bean was not discarded."); 86 } 87 88 90 try { 92 utx.commit(); 93 fail("The transaction is marked as rollback. The client cannot make the commit."); 94 } catch (Exception e) { 95 logger.debug("Expected exception {0}", e); 96 } 97 98 try { 100 ExceptionHandleUtil.verifyTable(DATABASE_1, ItfContainerTransaction.TABLE); 101 fail("The container did not make a rollback in the transaction."); 102 } catch (SQLException e) { 103 logger.debug("The test threw an expected exception{0}", e); 104 } 105 try { 109 ExceptionHandleUtil.verifyTable(DATABASE_2, ItfTransactionMisc00.TABLE); 110 } catch (SQLException e) { 111 fail("The container made a rollback in the transaction."); 112 } 113 } 114 115 122 @Override 123 public void testCallOtherBeanReq() throws Exception { 124 UserTransaction utx = ExceptionHandleUtil.getUserTransaction(); 125 utx.begin(); 126 try { 127 getRuntimeBean().insertTablesUsingAuxBeanReq(DATABASE_1, DATABASE_2); 128 fail("The container did not throw the EJBException."); 129 } catch (EJBTransactionRolledbackException e) { 130 logger.debug("The bean threw an expected error during the execution {0}", e); 131 } 132 if (!ExceptionHandleUtil.isDiscarded(getRuntimeBean())) { 134 fail("The bean was not discarded."); 135 } 136 try { 138 utx.commit(); 139 fail("The transaction is marked as rollback. The client cannot make the commit."); 140 } catch (Exception e) { 141 logger.debug("Expected exception {0}", e); 142 } 143 try { 145 ExceptionHandleUtil.verifyTable(DATABASE_1, ItfContainerTransaction.TABLE); 146 fail("The container did not make a rollback in the transaction."); 147 } catch (SQLException e) { 148 logger.debug("The test threw an expected exception{0}", e); 149 } 150 try { 154 ExceptionHandleUtil.verifyTable(DATABASE_2, ItfTransactionMisc00.TABLE); 155 fail("The container did not make a rollback in the transaction."); 156 } catch (SQLException e) { 157 logger.debug("The test threw an expected exception{0}", e); 158 } 159 } 160 161 } 162 | Popular Tags |