1 25 package org.objectweb.easybeans.tests.deploymentdesc; 26 27 import static org.testng.Assert.assertTrue; 28 import static org.testng.Assert.fail; 29 30 import java.sql.SQLException ; 31 32 import javax.ejb.EJBException ; 33 import javax.naming.NamingException ; 34 import javax.transaction.UserTransaction ; 35 36 import org.objectweb.easybeans.log.JLog; 37 import org.objectweb.easybeans.log.JLogFactory; 38 import org.objectweb.easybeans.tests.common.ejbs.stateful.containermanaged.xmldescriptor.ItfCMTDeployDesc; 39 import org.objectweb.easybeans.tests.common.ejbs.stateful.containermanaged.xmldescriptor.SFSBCMTDeployDesc; 40 import org.objectweb.easybeans.tests.common.ejbs.stateless.containermanaged.ItfDatabaseManager; 41 import org.objectweb.easybeans.tests.common.ejbs.stateless.containermanaged.SLSBDatabaseManager; 42 import org.objectweb.easybeans.tests.common.helper.EJBHelper; 43 import org.objectweb.easybeans.tests.common.helper.TransactionHelper; 44 import org.testng.annotations.BeforeMethod; 45 import org.testng.annotations.Test; 46 47 58 public class TestCMTDefinition { 59 60 63 public static final String DB_NAME = "jdbc_1"; 64 65 68 public static final String TABLE_NAME = "test"; 69 70 73 private ItfCMTDeployDesc bean; 74 75 78 private static JLog logger = JLogFactory.getLog(TestCMTDefinition.class); 79 80 83 private ItfDatabaseManager slsbDatabaseManager; 84 85 89 @BeforeMethod 90 public void setup() throws Exception { 91 bean = EJBHelper.getBeanRemoteInstance(SFSBCMTDeployDesc.class, ItfCMTDeployDesc.class); 92 slsbDatabaseManager = EJBHelper.getBeanRemoteInstance(SLSBDatabaseManager.class, ItfDatabaseManager.class); 94 deleteTable(DB_NAME, TABLE_NAME); 95 } 96 97 107 @Test 108 public void verifyAllDefinition() throws Exception { 109 112 UserTransaction utx = TransactionHelper.getInternalUserTransaction(); 114 utx.begin(); 115 bean.insertTable01(DB_NAME, TABLE_NAME); 116 utx.commit(); 117 118 deleteTable(DB_NAME, TABLE_NAME); 120 121 bean.insertTable01(DB_NAME, TABLE_NAME); 123 } 124 125 131 @Test 132 public void verifyMethodWithoutParameterDefinition() { 133 138 try { 143 bean.insertTable02(DB_NAME, TABLE_NAME); 144 fail("A method with transaction attribute mandatory is not throwing an EJBException" 145 + " when it is called without transaction context"); 146 } catch (Exception e) { 147 assertTrue(e instanceof EJBException , "A method with transaction attribute " 148 + "mandatory is not throwing an EJBException when it is called without transaction context"); 149 } 150 deleteTable(DB_NAME, TABLE_NAME); 152 153 158 try { 159 bean.insertTable02(DB_NAME, TABLE_NAME, 1); 160 fail("A method with transaction attribute mandatory is not throwing an " 161 + "EJBException when it is called without transaction context"); 162 } catch (Exception e) { 163 assertTrue( 164 e instanceof EJBException , 165 "A method with transaction attribute mandatory is not throwing an " 166 + "EJBException when it is called without transaction context"); 167 } 168 } 169 170 177 @Test 178 public void verifyMethodWithParameterDefinition() throws Exception { 179 184 UserTransaction utx = TransactionHelper.getInternalUserTransaction(); 187 try { 188 utx.begin(); 189 bean.insertTable03(DB_NAME, TABLE_NAME); 190 fail("A method with transaction attribute never is not throwing an " 191 + "EJBException when it is called with transaction context"); 192 } catch (Exception e) { 193 assertTrue(e instanceof EJBException , 194 "A method with transaction attribute never is not throwing an " 195 + "EJBException when it is called with transaction context"); 196 } finally { 197 utx.rollback(); 198 } 199 200 deleteTable(DB_NAME, TABLE_NAME); 202 203 206 utx.begin(); 208 bean.insertTable03(DB_NAME, TABLE_NAME, 1); 209 utx.commit(); 210 211 deleteTable(DB_NAME, TABLE_NAME); 213 214 bean.insertTable03(DB_NAME, TABLE_NAME, 1); 216 } 217 218 223 protected void deleteTable(final String dbName, final String tableName) { 224 try { 226 slsbDatabaseManager.deleteTable(dbName, tableName); 227 } catch (SQLException e) { 228 logger.debug("The table delete threw an error during the execution {0}", e); 229 } catch (NamingException e) { 230 logger.debug("The table delete threw an error during the execution {0}", e); 231 } 232 } 233 } 234 | Popular Tags |