1 25 package org.objectweb.easybeans.tests.transaction.beanmanaged; 26 27 import static org.objectweb.easybeans.tests.common.helper.ExceptionHelper.checkCause; 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 35 import org.objectweb.easybeans.log.JLog; 36 import org.objectweb.easybeans.log.JLogFactory; 37 import org.objectweb.easybeans.tests.common.ejbs.stateless.beanmanaged.transaction.ItfBeanManagedTransaction; 38 import org.objectweb.easybeans.tests.common.ejbs.stateless.beanmanaged.transaction.SLSBBeanManagedTransaction; 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.helper.EJBHelper; 42 import org.objectweb.easybeans.tests.common.helper.EmbeddedHelper; 43 import org.testng.annotations.AfterClass; 44 import org.testng.annotations.BeforeClass; 45 import org.testng.annotations.BeforeMethod; 46 import org.testng.annotations.Test; 47 48 60 public class TestTransactionCommitSLSB { 61 62 65 private ItfBeanManagedTransaction slsbBeanManagedTransaction; 66 67 70 private ItfDatabaseManager slsbDatabaseManager; 71 72 75 private static JLog logger = JLogFactory.getLog(TestTransactionCommitSLSB.class); 76 77 80 private static final String DATABASE = "jdbc_1"; 81 82 86 @BeforeClass 87 public void setup() throws Exception { 88 EmbeddedHelper.bindDatasource(); 92 slsbDatabaseManager = EJBHelper.getBeanRemoteInstance(SLSBDatabaseManager.class, ItfDatabaseManager.class); 94 } 95 96 110 @Test 111 public void testBeginWithoutCommit() throws Exception { 112 try { 113 slsbBeanManagedTransaction.insertTableWithoutCommit(ItfBeanManagedTransaction.CREATE_TABLE, DATABASE); 115 fail("The container must to throw the javax.ejb.EJBException, if the stateless bean does not make the commit. " 116 + "However the container did not throw any exception."); 117 } catch (Exception e) { 118 if (!(e instanceof javax.ejb.EJBException )) { 119 fail("The container must to throw the javax.ejb.EJBException, if the stateless bean does not makes the commit. " 120 + "However the container did not throw the correct exception."); 121 } 122 } 123 try { 125 slsbDatabaseManager.verifyTable(DATABASE, ItfBeanManagedTransaction.TABLE); 126 fail("The container must to make the rollback, if the stateless bean does not make the commit."); 127 } catch (SQLException e) { 128 logger.debug("the container made the rollback {0}", e); 129 } 130 132 } 135 136 143 @Test 144 public void testTransInSameMethod() throws Exception { 145 slsbBeanManagedTransaction.insertTableWithBeginCommit(ItfBeanManagedTransaction.CREATE_TABLE, DATABASE); 146 slsbDatabaseManager.verifyTable(DATABASE, ItfBeanManagedTransaction.TABLE); 148 } 149 150 157 @Test 158 public void testSetRollbackOnly() throws Exception { 159 try { 160 slsbBeanManagedTransaction.setRollbackOnly(); 162 } catch (Exception e) { 163 checkCause(e, IllegalStateException .class); 164 } 165 } 166 167 173 @Test 174 public void testGetRollbackOnly() { 175 try { 176 slsbBeanManagedTransaction.getRollbackOnly(); 178 } catch (EJBException e) { 179 checkCause(e, IllegalStateException .class); 180 } catch (NamingException e) { 181 fail("Shouldn't throw Naming Exception" + e.getMessage()); 182 } 183 } 184 185 189 @AfterClass 190 public void tierDown() throws Exception { 191 EmbeddedHelper.unbindDatasource(); 194 } 195 196 199 @BeforeMethod 200 public void deletesTable() { 201 try { 203 slsbDatabaseManager.deleteTable(DATABASE, ItfBeanManagedTransaction.TABLE); 204 } catch (SQLException e) { 205 logger.debug("The table delete threw an error during the execution {0}", e); 206 } catch (NamingException e) { 207 logger.debug("The table delete threw an error during the execution {0}", e); 208 } 209 } 210 211 216 @BeforeMethod 217 public void createBean() throws Exception { 218 slsbBeanManagedTransaction = EJBHelper.getBeanRemoteInstance(SLSBBeanManagedTransaction.class, 220 ItfBeanManagedTransaction.class); 221 } 222 223 } 224 | Popular Tags |