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