1 22 package org.jboss.ejb3.test.stateful; 23 24 import javax.annotation.Resource; 25 import javax.ejb.Remote ; 26 import javax.ejb.Stateless ; 27 import javax.ejb.TransactionManagement ; 28 import javax.ejb.TransactionManagementType ; 29 import javax.naming.InitialContext ; 30 import javax.transaction.UserTransaction ; 31 32 38 @Stateless() 39 @TransactionManagement (TransactionManagementType.BEAN) 40 @Remote (Tester.class) 41 public class TesterBean implements Tester 42 { 43 @Resource private UserTransaction ut; 44 45 public void testSessionSynchronization() throws Exception 46 { 47 StatefulSyncLocal sfsb = (StatefulSyncLocal)new InitialContext ().lookup("StatefulSyncBean/local"); 48 sfsb.setState("hello"); 49 sfsb.setBeforeCalled(false); 50 51 ut.begin(); 52 sfsb.setState("world"); 53 ut.rollback(); 54 55 if (!sfsb.getState().equals("hello")) throw new RuntimeException ("rollback didn't work"); 56 if (!sfsb.isBeforeCalled()) throw new RuntimeException ("BEFORE WAS NOT CALLED"); 57 58 60 sfsb = (StatefulSyncLocal)new InitialContext ().lookup("StatefulSyncBean/local"); 61 if (sfsb.getState() != null) throw new RuntimeException ("State should be null: " + sfsb.getState()); 62 } 63 64 public void testRollback1() throws Exception 65 { 66 RemoveTest test = (RemoveTest)new InitialContext ().lookup("RemoveTestBean/local"); 67 ut.begin(); 68 test.callRollbackOnly(); 69 ut.rollback(); 70 } 71 public void testRollback2() throws Exception 72 { 73 RemoveTest test = (RemoveTest)new InitialContext ().lookup("RemoveTestBean/local"); 74 ut.begin(); 75 ut.setRollbackOnly(); 76 test.removeit(); 77 ut.rollback(); 78 } 79 } 80 | Popular Tags |