1 25 package org.objectweb.easybeans.tests.transaction.beanmanaged; 26 27 import static org.testng.Assert.fail; 28 29 import java.sql.SQLException ; 30 31 import javax.ejb.EJBException ; 32 import javax.ejb.NoSuchEJBException ; 33 import javax.naming.NamingException ; 34 35 import org.objectweb.easybeans.log.JLog; 36 import org.objectweb.easybeans.log.JLogFactory; 37 import org.objectweb.easybeans.tests.common.ejbs.stateful.beanmanaged.transaction.ItfBeanManagedException; 38 import org.objectweb.easybeans.tests.common.ejbs.stateful.beanmanaged.transaction.SFSBBeanManagedException; 39 import org.objectweb.easybeans.tests.common.ejbs.stateless.containermanaged.ItfDatabaseManager; 40 import org.objectweb.easybeans.tests.common.ejbs.stateless.containermanaged.SLSBDatabaseManager; 41 import org.objectweb.easybeans.tests.common.exception.RollbackAppRuntimeException; 42 import org.objectweb.easybeans.tests.common.helper.EJBHelper; 43 import org.testng.annotations.BeforeMethod; 44 import org.testng.annotations.Test; 45 46 58 public class TestBeanManagedException { 59 60 63 private ItfBeanManagedException bean; 64 65 68 private ItfDatabaseManager slsbDatabaseManager; 69 70 73 private static final String DATABASE = "jdbc_1"; 74 75 78 private static JLog logger = JLogFactory.getLog(TestBeanManagedException.class); 79 80 84 @BeforeMethod 85 public void setup() throws Exception { 86 slsbDatabaseManager = EJBHelper.getBeanRemoteInstance(SLSBDatabaseManager.class, ItfDatabaseManager.class); 88 89 deleteTable(); 91 92 bean = EJBHelper.getBeanRemoteInstance(SFSBBeanManagedException.class, ItfBeanManagedException.class); 94 bean.startup(DATABASE); 95 } 96 97 104 @Test 105 public void insertTableWithAppException() throws Exception { 106 try { 107 bean.insertTableWithAppException(); 108 fail("The container did not throw the application exception"); 109 } catch (RollbackAppRuntimeException e) { 110 logger.debug("The table delete threw an error during the execution {0}", e); 111 } 112 slsbDatabaseManager.verifyTable(DATABASE, ItfBeanManagedException.TABLE); 114 } 115 116 124 @Test 125 public void insertTableWithRuntimeException() throws Exception { 126 try { 127 bean.insertTableWithRuntimeException(); 128 fail("The container did not throw EJBEexception"); 129 } catch (EJBException e) { 130 logger.debug("The table delete threw an error during the execution {0}", e); 131 } 132 try { 134 bean.emptyMethod(); 135 fail("The instance was not discarded"); 136 } catch (NoSuchEJBException e) { 137 logger.debug("The bean threw an expected error during the execution {0}", e); 138 } 139 140 142 try { 144 slsbDatabaseManager.verifyTable(DATABASE, ItfBeanManagedException.TABLE); 145 fail("The transaction was not rolled back"); 146 } catch (SQLException e) { 147 logger.debug("The bean threw an expected error during the execution {0}", e); 148 } 149 150 } 151 152 156 public void deleteTable() { 157 try { 159 slsbDatabaseManager.deleteTable(DATABASE, ItfBeanManagedException.TABLE); 161 } catch (SQLException e) { 162 logger.debug("The table delete threw an error during the execution {0}", e); 163 } catch (NamingException e) { 164 logger.debug("The table delete threw an error during the execution {0}", e); 165 } 166 } 167 } 168 | Popular Tags |