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 TestSupportsException extends TestContainerTransactionException { 60 61 64 private static JLog logger = JLogFactory.getLog(TestSupportsException.class); 65 66 75 public void testCallOtherBeanNotSupWithTrans() throws Exception { 76 UserTransaction utx = ExceptionHandleUtil.getUserTransaction(); 77 utx.begin(); 78 79 try { 80 getRuntimeBean().insertTablesUsingAuxBeanNotSup(DATABASE_1, DATABASE_2); 81 fail("The container did not throw the EJBTransactionRolledbackException."); 82 } catch (EJBTransactionRolledbackException e) { 83 logger.debug("The bean threw an expected error during the execution {0}", e); 84 } 85 if (!ExceptionHandleUtil.isDiscarded(getRuntimeBean())) { 87 fail("The bean was not discarded."); 88 } 89 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 123 public void testCallOtherBeanReqWithTrans() 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 EJBTransactionRolledbackException."); 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 144 try { 146 ExceptionHandleUtil.verifyTable(DATABASE_1, ItfContainerTransaction.TABLE); 147 fail("The container did not make a rollback in the transaction."); 148 } catch (SQLException e) { 149 logger.debug("The test threw an expected excpetion {0}", e); 150 } 151 try { 155 ExceptionHandleUtil.verifyTable(DATABASE_2, ItfTransactionMisc00.TABLE); 156 fail("The container did not make a rollback in the transaction."); 157 } catch (SQLException e) { 158 logger.debug("The test threw an expected exception {0}", e); 159 } 160 } 161 162 172 public void testCallOtherBeanNotSupWithoutTrans() throws Exception { 173 super.testCallOtherBeanNotSup(); 174 verifyCallOtherBean(); 175 } 176 177 185 public void testCallOtherBeanReqWithoutTrans() throws Exception { 186 super.testCallOtherBeanReq(); 187 verifyCallOtherBean(); 188 } 189 190 195 private void verifyCallOtherBean() throws Exception { 196 try { 198 ExceptionHandleUtil.verifyTable(DATABASE_1, ItfContainerTransaction.TABLE); 199 } catch (SQLException e) { 200 fail("The container made a rollback in the transaction."); 201 } 202 try { 206 ExceptionHandleUtil.verifyTable(DATABASE_2, ItfTransactionMisc00.TABLE); 207 } catch (SQLException e) { 208 fail("The container made a rollback in the transaction."); 209 } 210 } 211 212 } 213 | Popular Tags |