1 16 17 package org.springframework.transaction.interceptor; 18 19 import java.io.Serializable ; 20 import java.util.Properties ; 21 22 import org.springframework.aop.framework.ProxyFactory; 23 import org.springframework.transaction.PlatformTransactionManager; 24 import org.springframework.transaction.TransactionDefinition; 25 import org.springframework.transaction.TransactionException; 26 import org.springframework.transaction.TransactionStatus; 27 import org.springframework.util.SerializationTestUtils; 28 29 35 public class TransactionInterceptorTests extends AbstractTransactionAspectTests { 36 37 42 protected Object advised(Object target, PlatformTransactionManager ptm, TransactionAttributeSource tas) { 43 TransactionInterceptor ti = new TransactionInterceptor(); 44 ti.setTransactionManager(ptm); 45 assertEquals(ptm, ti.getTransactionManager()); 46 ti.setTransactionAttributeSource(tas); 47 assertEquals(tas, ti.getTransactionAttributeSource()); 48 49 ProxyFactory pf = new ProxyFactory(target); 50 pf.addAdvice(0, ti); 51 return pf.getProxy(); 52 } 53 54 58 public void testSerializableWithAttributeProperties() throws Exception { 59 TransactionInterceptor ti = new TransactionInterceptor(); 60 Properties p = new Properties (); 61 p.setProperty("methodName", "PROPAGATION_REQUIRED"); 62 ti.setTransactionAttributes(p); 63 PlatformTransactionManager ptm = new SerializableTransactionManager(); 64 ti.setTransactionManager(ptm); 65 ti = (TransactionInterceptor) SerializationTestUtils.serializeAndDeserialize(ti); 66 assertNotNull(ti.logger); 68 assertTrue(ti.getTransactionManager() instanceof SerializableTransactionManager); 69 } 70 71 72 75 private static class SerializableTransactionManager implements PlatformTransactionManager, Serializable { 76 77 public TransactionStatus getTransaction(TransactionDefinition definition) throws TransactionException { 78 throw new UnsupportedOperationException (); 79 } 80 81 public void commit(TransactionStatus status) throws TransactionException { 82 throw new UnsupportedOperationException (); 83 } 84 85 public void rollback(TransactionStatus status) throws TransactionException { 86 throw new UnsupportedOperationException (); 87 } 88 89 } 90 } 91 | Popular Tags |