1 16 17 package org.springframework.transaction.interceptor; 18 19 import java.util.HashMap ; 20 import java.util.Map ; 21 22 import javax.servlet.ServletException ; 23 24 import junit.framework.TestCase; 25 26 import org.springframework.transaction.TransactionDefinition; 27 28 36 public class TransactionAttributeSourceTests extends TestCase { 37 38 public void testMatchAlwaysTransactionAttributeSource() throws Exception { 39 MatchAlwaysTransactionAttributeSource tas = new MatchAlwaysTransactionAttributeSource(); 40 TransactionAttribute ta = tas.getTransactionAttribute( 41 Object .class.getMethod("hashCode", (Class []) null), null); 42 assertNotNull(ta); 43 assertTrue(TransactionDefinition.PROPAGATION_REQUIRED == ta.getPropagationBehavior()); 44 45 tas.setTransactionAttribute(new DefaultTransactionAttribute(TransactionDefinition.PROPAGATION_SUPPORTS)); 46 ta = tas.getTransactionAttribute( 47 ServletException .class.getMethod("getMessage", (Class []) null), ServletException .class); 48 assertNotNull(ta); 49 assertTrue(TransactionDefinition.PROPAGATION_SUPPORTS == ta.getPropagationBehavior()); 50 } 51 52 public void testMethodMapTransactionAttributeSource() throws NoSuchMethodException { 53 MethodMapTransactionAttributeSource tas = new MethodMapTransactionAttributeSource(); 54 Map methodMap = new HashMap (); 55 methodMap.put(Object .class.getName() + ".hashCode", "PROPAGATION_REQUIRED"); 56 methodMap.put(Object .class.getName() + ".toString", 57 new DefaultTransactionAttribute(TransactionDefinition.PROPAGATION_SUPPORTS)); 58 tas.setMethodMap(methodMap); 59 TransactionAttribute ta = tas.getTransactionAttribute( 60 Object .class.getMethod("hashCode", (Class []) null), null); 61 assertNotNull(ta); 62 assertEquals(TransactionDefinition.PROPAGATION_REQUIRED, ta.getPropagationBehavior()); 63 ta = tas.getTransactionAttribute(Object .class.getMethod("toString", (Class []) null), null); 64 assertNotNull(ta); 65 assertEquals(TransactionDefinition.PROPAGATION_SUPPORTS, ta.getPropagationBehavior()); 66 } 67 68 public void testNameMatchTransactionAttributeSource() throws NoSuchMethodException { 69 NameMatchTransactionAttributeSource tas = new NameMatchTransactionAttributeSource(); 70 Map methodMap = new HashMap (); 71 methodMap.put("hashCode", "PROPAGATION_REQUIRED"); 72 methodMap.put("toString", new DefaultTransactionAttribute(TransactionDefinition.PROPAGATION_SUPPORTS)); 73 tas.setNameMap(methodMap); 74 TransactionAttribute ta = tas.getTransactionAttribute( 75 Object .class.getMethod("hashCode", (Class []) null), null); 76 assertNotNull(ta); 77 assertEquals(TransactionDefinition.PROPAGATION_REQUIRED, ta.getPropagationBehavior()); 78 ta = tas.getTransactionAttribute(Object .class.getMethod("toString", (Class []) null), null); 79 assertNotNull(ta); 80 assertEquals(TransactionDefinition.PROPAGATION_SUPPORTS, ta.getPropagationBehavior()); 81 } 82 83 } 84 | Popular Tags |