1 25 package org.objectweb.easybeans.tests.deploymentdesc; 26 27 import static org.testng.Assert.fail; 28 29 import java.sql.SQLException ; 30 31 import javax.naming.NamingException ; 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.stateless.containermanaged.ItfDatabaseManager; 37 import org.objectweb.easybeans.tests.common.ejbs.stateless.containermanaged.SLSBDatabaseManager; 38 import org.objectweb.easybeans.tests.common.ejbs.stateless.containermanaged.exception.ItfExceptionXML; 39 import org.objectweb.easybeans.tests.common.ejbs.stateless.containermanaged.exception.SLSBExceptionXML; 40 import org.objectweb.easybeans.tests.common.exception.CustomException00; 41 import org.objectweb.easybeans.tests.common.exception.CustomException01; 42 import org.objectweb.easybeans.tests.common.exception.IllegalException; 43 import org.objectweb.easybeans.tests.common.exception.RollbackApplicationException; 44 import org.objectweb.easybeans.tests.common.helper.EJBHelper; 45 import org.objectweb.easybeans.tests.common.helper.TransactionHelper; 46 import org.testng.annotations.BeforeMethod; 47 import org.testng.annotations.Test; 48 49 61 public class TestAppException { 62 63 66 public static final String DB_NAME = "jdbc_1"; 67 68 71 private ItfExceptionXML bean; 72 73 76 private static JLog logger = JLogFactory.getLog(TestAppException.class); 77 78 81 private ItfDatabaseManager slsbDatabaseManager; 82 83 87 @BeforeMethod 88 public void setup() throws Exception { 89 bean = EJBHelper.getBeanRemoteInstance(SLSBExceptionXML.class, ItfExceptionXML.class); 90 slsbDatabaseManager = EJBHelper.getBeanRemoteInstance(SLSBDatabaseManager.class, ItfDatabaseManager.class); 92 deleteTable(DB_NAME); 93 } 94 95 105 @Test 106 public void testAppExceptionWithoutRollback() throws Exception { 107 UserTransaction utx = TransactionHelper.getInternalUserTransaction(); 110 try{ 111 utx.begin(); 112 bean.createTableWithAppException(DB_NAME); 113 fail("The container did not re-throw the application exception."); 114 }catch(CustomException01 e){ 115 logger.debug("The container threw an expected exception {0}", e); 116 }finally{ 117 utx.commit(); 120 } 121 verifyTable(DB_NAME); 123 } 124 125 126 139 @Test 140 public void testAppExceptionWithRollbackOverride() throws Exception { 141 UserTransaction utx = TransactionHelper.getInternalUserTransaction(); 144 try{ 145 utx.begin(); 146 bean.createTableWithAppExceptionOverride(DB_NAME); 147 fail("The container did not re-throw the application exception."); 148 }catch(RollbackApplicationException e){ 149 logger.debug("The container threw an expected exception {0}", e); 150 }finally{ 151 utx.commit(); 154 } 155 verifyTable(DB_NAME); 157 } 158 168 @Test 169 public void testAppExceptionWithRollback() throws Exception { 170 UserTransaction utx = TransactionHelper.getInternalUserTransaction(); 173 try{ 174 utx.begin(); 175 bean.createTableWithAppExceptionAndRollback(DB_NAME); 176 fail("The container did not re-throw the application exception."); 177 }catch(CustomException00 e){ 178 logger.debug("The container threw an expected exception {0}", e); 179 }finally{ 180 try{ 183 utx.commit(); 184 fail("The container did not mark the transaction for rollback"); 185 }catch(Exception e){ 186 logger.debug("The container threw an expected exception {0}", e); 187 } 188 } 189 } 190 191 192 202 @Test 203 public void testAppExceptionWithRollbackDefault() throws Exception { 204 UserTransaction utx = TransactionHelper.getInternalUserTransaction(); 207 try{ 208 utx.begin(); 209 bean.createTableWithAppExceptionDefault(DB_NAME); 210 fail("The container did not re-throw the application exception."); 211 }catch(IllegalException e){ 212 logger.debug("The container threw an expected exception {0}", e); 213 }finally{ 214 utx.commit(); 217 } 218 verifyTable(DB_NAME); 220 } 221 222 223 229 protected void verifyTable(final String database) throws NamingException , SQLException { 230 slsbDatabaseManager.verifyTable(database, ItfExceptionXML.TABLE); 231 } 232 233 237 protected void deleteTable(final String dbName) { 238 try { 240 slsbDatabaseManager.deleteTable(dbName, ItfExceptionXML.TABLE); 241 } catch (SQLException e) { 242 logger.debug("The table delete threw an error during the execution {0}", e); 243 } catch (NamingException e) { 244 logger.debug("The table delete threw an error during the execution {0}", e); 245 } 246 } 247 248 249 } 250 | Popular Tags |