1 16 17 package org.springframework.transaction.support; 18 19 import javax.transaction.TransactionManager ; 20 import javax.transaction.UserTransaction ; 21 22 import junit.framework.TestCase; 23 import org.easymock.MockControl; 24 25 import org.springframework.mock.jndi.SimpleNamingContextBuilder; 26 import org.springframework.transaction.jta.JtaTransactionManager; 27 import org.springframework.util.SerializationTestUtils; 28 29 32 public class JtaTransactionManagerSerializationTests extends TestCase { 33 34 public void testSerializable() throws Exception { 35 MockControl utMock = MockControl.createControl(UserTransaction .class); 36 UserTransaction ut = (UserTransaction ) utMock.getMock(); 37 MockControl ut2Mock = MockControl.createControl(UserTransaction .class); 38 UserTransaction ut2 = (UserTransaction ) ut2Mock.getMock(); 39 MockControl tmMock = MockControl.createControl(TransactionManager .class); 40 TransactionManager tm = (TransactionManager ) tmMock.getMock(); 41 42 JtaTransactionManager jtam = new JtaTransactionManager(); 43 jtam.setUserTransaction(ut); 44 jtam.setTransactionManager(tm); 45 jtam.afterPropertiesSet(); 46 47 SimpleNamingContextBuilder jndiEnv = SimpleNamingContextBuilder.emptyActivatedContextBuilder(); 48 jndiEnv.bind(JtaTransactionManager.DEFAULT_USER_TRANSACTION_NAME, ut2); 49 JtaTransactionManager jtam2 = (JtaTransactionManager) SerializationTestUtils.serializeAndDeserialize(jtam); 50 51 assertNotNull("Logger must survive serialization", jtam2.logger); 53 assertTrue("UserTransaction looked up on client", jtam2.getUserTransaction() == ut2); 54 assertNull("TransactionManager didn't survive", jtam2.getTransactionManager()); 55 } 56 57 } 58 | Popular Tags |