1 22 package org.jboss.ejb3.test.initial; 23 24 import org.jboss.tm.TransactionManagerService; 25 26 import javax.naming.InitialContext ; 27 import javax.transaction.Transaction ; 28 import javax.transaction.TransactionManager ; 29 30 36 public class TxTester implements TxTesterMBean 37 { 38 public void testTransactions() throws Exception 39 { 40 InitialContext ctx = new InitialContext (); 41 TransactionManager tm = (TransactionManager ) ctx.lookup(TransactionManagerService.JNDI_NAME); 42 TestLocal test = (TestLocal) ctx.lookup("TestBean/local"); 43 callNever(tm, test); 44 callNotSupported(tm, test); 45 callSupportsWithTx(tm, test); 46 callSupportsWithoutTx(tm, test); 47 test.required(); 48 callMandatoryNoTx(tm, test); 49 callMandatoryWithTx(tm, test); 50 callRequiresNew(tm, test); 51 } 52 53 public void callRequiresNew(TransactionManager tm, TestLocal test) throws Exception 54 { 55 tm.begin(); 56 Transaction tx = tm.getTransaction(); 57 test.requiresNew(tx); 58 tm.commit(); 59 } 60 61 public void callNever(TransactionManager tm, TestLocal test) throws Exception 62 { 63 boolean exceptionThrown = false; 64 tm.begin(); 65 try 66 { 67 test.never(); 68 } 69 catch (Exception ex) 70 { 71 exceptionThrown = true; 75 } 76 tm.rollback(); 77 if (!exceptionThrown) throw new Exception ("failed on mandatory no tx call"); 78 } 79 80 public void callNotSupported(TransactionManager tm, TestLocal test) throws Exception 81 { 82 tm.begin(); 83 test.notSupported(); 84 tm.commit(); 85 } 86 87 public void callSupportsWithTx(TransactionManager tm, TestLocal test) throws Exception 88 { 89 tm.begin(); 90 Transaction tx = tm.getTransaction(); 91 test.supports(tx); 92 tm.commit(); 93 } 94 95 public void callSupportsWithoutTx(TransactionManager tm, TestLocal test) throws Exception 96 { 97 test.supports(null); 98 } 99 100 public void callMandatoryNoTx(TransactionManager tm, TestLocal test) throws Exception 101 { 102 boolean exceptionThrown = false; 103 try 104 { 105 test.mandatory(); 106 } 107 catch (Exception ex) 108 { 109 exceptionThrown = true; 110 } 111 if (!exceptionThrown) throw new Exception ("failed on mandatory no tx call"); 112 } 113 114 public void callMandatoryWithTx(TransactionManager tm, Test test) throws Exception 115 { 116 tm.begin(); 117 test.mandatory(); 118 tm.commit(); 119 } 120 } 121 122 123 124 | Popular Tags |