1 25 package org.objectweb.easybeans.tests.transaction.beanmanaged; 26 27 import static org.testng.Assert.assertEquals; 28 29 import java.sql.SQLException ; 30 31 import javax.naming.NamingException ; 32 import javax.transaction.Status ; 33 34 import org.objectweb.easybeans.log.JLog; 35 import org.objectweb.easybeans.log.JLogFactory; 36 import org.objectweb.easybeans.tests.common.asserts.Assert; 37 import org.objectweb.easybeans.tests.common.ejbs.stateful.beanmanaged.transaction.ItfBeanManagedTransaction; 38 import org.objectweb.easybeans.tests.common.ejbs.stateful.beanmanaged.transaction.SFSBBeanManagedTransaction; 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.BeforeClass; 44 import org.testng.annotations.BeforeMethod; 45 import org.testng.annotations.Test; 46 47 59 public class TestTransactionStatus { 60 61 64 private ItfBeanManagedTransaction sfsbBeanManagedTransaction; 65 66 69 private ItfDatabaseManager slsbDatabaseManager; 70 71 74 private static JLog logger = JLogFactory.getLog(TestTransactionStatus.class); 75 76 79 private static final String DATABASE = "jdbc_1"; 80 81 85 @BeforeClass 86 public void setup() throws Exception { 87 EmbeddedHelper.bindDatasource(); 91 slsbDatabaseManager = EJBHelper.getBeanRemoteInstance(SLSBDatabaseManager.class, ItfDatabaseManager.class); 93 94 } 95 96 103 @Test 104 public void testStatusBeforeBegin() throws Exception { 105 int intTransactionStatus = sfsbBeanManagedTransaction.getTransactionStatus(); 106 assertEquals(Status.STATUS_NO_TRANSACTION, intTransactionStatus); 107 108 } 109 110 116 @Test(dependsOnMethods = "testStatusBeforeBegin") 117 public void testStatusAfterBegin() throws Exception { 118 sfsbBeanManagedTransaction.insertTableWithoutCommitTransaction(); 120 int intTransactionStatus = sfsbBeanManagedTransaction.getTransactionStatus(); 122 assertEquals(Status.STATUS_ACTIVE, intTransactionStatus); 123 } 124 125 131 @Test 132 public void testStatusAfterCommit() throws Exception { 133 sfsbBeanManagedTransaction.insertTableWithBeginCommitTransaction(); 135 int intTransactionStatus = sfsbBeanManagedTransaction.getTransactionStatus(); 137 Integer [] expected = {new Integer (Status.STATUS_COMMITTED), new Integer (Status.STATUS_NO_TRANSACTION)}; 138 Assert.assertEquals(new Integer (intTransactionStatus), expected, 139 "The transaction status must be commited or no_transaction"); 140 141 } 142 143 149 @Test 150 public void testStatusAfterRollback() throws Exception { 151 sfsbBeanManagedTransaction.insertTableWithBeginRollback(); 153 int intTransactionStatus = sfsbBeanManagedTransaction.getTransactionStatus(); 155 Integer [] expected = {new Integer (Status.STATUS_ROLLEDBACK), new Integer (Status.STATUS_NO_TRANSACTION)}; 156 Assert.assertEquals(new Integer (intTransactionStatus), expected, 157 "The transaction status must be rolledback or no_transaction"); 158 159 } 160 161 164 @BeforeMethod 165 public void deletesTable() { 166 try { 168 slsbDatabaseManager.deleteTable(DATABASE, ItfBeanManagedTransaction.TABLE); 169 } catch (SQLException e) { 170 logger.debug("The table delete threw an error during the execution {0}", e); 171 } catch (NamingException e) { 172 logger.debug("The table delete threw an error during the execution {0}", e); 173 } 174 } 175 176 180 @BeforeMethod 181 public void createBean() throws Exception { 182 sfsbBeanManagedTransaction = EJBHelper.getBeanRemoteInstance(SFSBBeanManagedTransaction.class, 184 ItfBeanManagedTransaction.class); 185 sfsbBeanManagedTransaction.startup(ItfBeanManagedTransaction.CREATE_TABLE, DATABASE); 186 } 187 188 } 189 | Popular Tags |