1 22 package org.jboss.ejb3.test.bmt; 23 24 import javax.ejb.EJB ; 25 import javax.ejb.TransactionAttribute ; 26 import javax.ejb.TransactionAttributeType ; 27 import javax.ejb.Stateless ; 28 import javax.transaction.TransactionManager ; 29 import javax.transaction.Transaction ; 30 import javax.naming.InitialContext ; 31 import org.jboss.logging.Logger; 32 import org.jboss.annotation.JndiInject; 33 34 40 @Stateless 41 public class TesterBean implements TesterRemote 42 { 43 @EJB StatelessLocal stateless; 44 @JndiInject(jndiName="java:/TransactionManager") TransactionManager tm; 45 46 47 protected static Logger log = Logger.getLogger(TesterBean.class); 48 49 public void testStatelessWithTx() throws Exception 50 { 51 stateless.beginCommitEnd(); 52 stateless.beginRollbackEnd(); 53 54 try 55 { 56 stateless.beginNoEnd(); 57 } 58 catch (Exception e) 59 { 60 if (e instanceof TestException) throw e; 61 log.info("should be EJBException thrown that begin and no end was called: ", e); 62 } 63 } 64 65 @TransactionAttribute (TransactionAttributeType.NOT_SUPPORTED) 66 public void testStatelessWithoutTx() throws Exception 67 { 68 stateless.beginCommitEnd(); 69 if (tm.getTransaction() != null) throw new RuntimeException ("tx is associated"); 70 stateless.beginRollbackEnd(); 71 if (tm.getTransaction() != null) throw new RuntimeException ("tx is associated"); 72 73 try 74 { 75 stateless.beginNoEnd(); 76 } 77 catch (Exception e) 78 { 79 if (e instanceof TestException) throw e; 80 log.info("should be EJBException thrown that begin and no end was called: ", e); 81 } 82 if (tm.getTransaction() != null) throw new RuntimeException ("tx is associated"); 83 } 84 85 StatefulLocal getStateful() throws Exception 86 { 87 InitialContext ctx = new InitialContext (); 88 return (StatefulLocal)ctx.lookup("StatefulBean/local"); 89 } 90 91 public void testStatefulWithTx() throws Exception 92 { 93 StatefulLocal stateful = getStateful(); 94 Transaction tx = stateful.beginNoEnd(); 95 stateful.endCommit(tx); 96 tx = stateful.beginNoEnd(); 97 stateful.endRollback(tx); 98 99 stateful.beginCommitEnd(); 100 stateful.beginRollbackEnd(); 101 102 } 103 104 @TransactionAttribute (TransactionAttributeType.NOT_SUPPORTED) 105 public void testStatefulWithoutTx() throws Exception 106 { 107 StatefulLocal stateful = getStateful(); 108 Transaction tx = stateful.beginNoEnd(); 109 if (tm.getTransaction() != null) throw new RuntimeException ("tx is associated"); 110 stateful.endCommit(tx); 111 if (tm.getTransaction() != null) throw new RuntimeException ("tx is associated"); 112 tx = stateful.beginNoEnd(); 113 if (tm.getTransaction() != null) throw new RuntimeException ("tx is associated"); 114 stateful.endRollback(tx); 115 if (tm.getTransaction() != null) throw new RuntimeException ("tx is associated"); 116 117 stateful.beginCommitEnd(); 118 if (tm.getTransaction() != null) throw new RuntimeException ("tx is associated"); 119 stateful.beginRollbackEnd(); 120 if (tm.getTransaction() != null) throw new RuntimeException ("tx is associated"); 121 122 } 123 } 124 | Popular Tags |