Search in sources :

Example 11 with RollbackRuleAttribute

use of org.springframework.transaction.interceptor.RollbackRuleAttribute in project spring-framework by spring-projects.

the class AnnotationTransactionAttributeSourceTests method customMethodAttributeDetected.

@Test
public void customMethodAttributeDetected() throws Exception {
    Method method = TestBean6.class.getMethod("getAge");
    AnnotationTransactionAttributeSource atas = new AnnotationTransactionAttributeSource();
    TransactionAttribute actual = atas.getTransactionAttribute(method, TestBean6.class);
    RuleBasedTransactionAttribute rbta = new RuleBasedTransactionAttribute();
    rbta.getRollbackRules().add(new RollbackRuleAttribute(Exception.class));
    rbta.getRollbackRules().add(new NoRollbackRuleAttribute(IOException.class));
    assertEquals(rbta.getRollbackRules(), ((RuleBasedTransactionAttribute) actual).getRollbackRules());
}
Also used : TransactionAttribute(org.springframework.transaction.interceptor.TransactionAttribute) RuleBasedTransactionAttribute(org.springframework.transaction.interceptor.RuleBasedTransactionAttribute) RollbackRuleAttribute(org.springframework.transaction.interceptor.RollbackRuleAttribute) NoRollbackRuleAttribute(org.springframework.transaction.interceptor.NoRollbackRuleAttribute) RuleBasedTransactionAttribute(org.springframework.transaction.interceptor.RuleBasedTransactionAttribute) Method(java.lang.reflect.Method) NoRollbackRuleAttribute(org.springframework.transaction.interceptor.NoRollbackRuleAttribute) IOException(java.io.IOException) IOException(java.io.IOException) Test(org.junit.Test)

Example 12 with RollbackRuleAttribute

use of org.springframework.transaction.interceptor.RollbackRuleAttribute in project spring-framework by spring-projects.

the class AnnotationTransactionAttributeSourceTests method defaultsToClassTransactionAttribute.

/**
	 * Test that transaction attribute is inherited from class
	 * if not specified on method.
	 */
@Test
public void defaultsToClassTransactionAttribute() throws Exception {
    Method method = TestBean4.class.getMethod("getAge");
    AnnotationTransactionAttributeSource atas = new AnnotationTransactionAttributeSource();
    TransactionAttribute actual = atas.getTransactionAttribute(method, TestBean4.class);
    RuleBasedTransactionAttribute rbta = new RuleBasedTransactionAttribute();
    rbta.getRollbackRules().add(new RollbackRuleAttribute(Exception.class));
    rbta.getRollbackRules().add(new NoRollbackRuleAttribute(IOException.class));
    assertEquals(rbta.getRollbackRules(), ((RuleBasedTransactionAttribute) actual).getRollbackRules());
}
Also used : TransactionAttribute(org.springframework.transaction.interceptor.TransactionAttribute) RuleBasedTransactionAttribute(org.springframework.transaction.interceptor.RuleBasedTransactionAttribute) RollbackRuleAttribute(org.springframework.transaction.interceptor.RollbackRuleAttribute) NoRollbackRuleAttribute(org.springframework.transaction.interceptor.NoRollbackRuleAttribute) RuleBasedTransactionAttribute(org.springframework.transaction.interceptor.RuleBasedTransactionAttribute) Method(java.lang.reflect.Method) NoRollbackRuleAttribute(org.springframework.transaction.interceptor.NoRollbackRuleAttribute) IOException(java.io.IOException) IOException(java.io.IOException) Test(org.junit.Test)

Example 13 with RollbackRuleAttribute

use of org.springframework.transaction.interceptor.RollbackRuleAttribute in project spring-framework by spring-projects.

the class AnnotationTransactionAttributeSourceTests method customClassAttributeWithReadOnlyOverrideDetected.

@Test
public void customClassAttributeWithReadOnlyOverrideDetected() throws Exception {
    Method method = TestBean7.class.getMethod("getAge");
    AnnotationTransactionAttributeSource atas = new AnnotationTransactionAttributeSource();
    TransactionAttribute actual = atas.getTransactionAttribute(method, TestBean7.class);
    RuleBasedTransactionAttribute rbta = new RuleBasedTransactionAttribute();
    rbta.getRollbackRules().add(new RollbackRuleAttribute(Exception.class));
    rbta.getRollbackRules().add(new NoRollbackRuleAttribute(IOException.class));
    assertEquals(rbta.getRollbackRules(), ((RuleBasedTransactionAttribute) actual).getRollbackRules());
    assertTrue(actual.isReadOnly());
}
Also used : TransactionAttribute(org.springframework.transaction.interceptor.TransactionAttribute) RuleBasedTransactionAttribute(org.springframework.transaction.interceptor.RuleBasedTransactionAttribute) RollbackRuleAttribute(org.springframework.transaction.interceptor.RollbackRuleAttribute) NoRollbackRuleAttribute(org.springframework.transaction.interceptor.NoRollbackRuleAttribute) RuleBasedTransactionAttribute(org.springframework.transaction.interceptor.RuleBasedTransactionAttribute) Method(java.lang.reflect.Method) NoRollbackRuleAttribute(org.springframework.transaction.interceptor.NoRollbackRuleAttribute) IOException(java.io.IOException) IOException(java.io.IOException) Test(org.junit.Test)

Example 14 with RollbackRuleAttribute

use of org.springframework.transaction.interceptor.RollbackRuleAttribute in project spring-framework by spring-projects.

the class AnnotationTransactionAttributeSourceTests method customMethodAttributeWithReadOnlyOverrideOnInterface.

@Test
public void customMethodAttributeWithReadOnlyOverrideOnInterface() throws Exception {
    Method method = TestInterface10.class.getMethod("getAge");
    Transactional annotation = AnnotationUtils.findAnnotation(method, Transactional.class);
    assertNotNull("AnnotationUtils.findAnnotation failed to find @Transactional for TestBean10.getAge()", annotation);
    annotation = AnnotationUtils.findAnnotation(TestBean10.class, Transactional.class);
    assertNull("AnnotationUtils.findAnnotation should not find @Transactional for TestBean10", annotation);
    AnnotationTransactionAttributeSource atas = new AnnotationTransactionAttributeSource();
    TransactionAttribute actual = atas.getTransactionAttribute(method, TestBean10.class);
    assertNotNull("Failed to retrieve TransactionAttribute for TestBean10.getAge()", actual);
    RuleBasedTransactionAttribute rbta = new RuleBasedTransactionAttribute();
    rbta.getRollbackRules().add(new RollbackRuleAttribute(Exception.class));
    rbta.getRollbackRules().add(new NoRollbackRuleAttribute(IOException.class));
    assertEquals(rbta.getRollbackRules(), ((RuleBasedTransactionAttribute) actual).getRollbackRules());
    assertTrue(actual.isReadOnly());
}
Also used : TransactionAttribute(org.springframework.transaction.interceptor.TransactionAttribute) RuleBasedTransactionAttribute(org.springframework.transaction.interceptor.RuleBasedTransactionAttribute) RollbackRuleAttribute(org.springframework.transaction.interceptor.RollbackRuleAttribute) NoRollbackRuleAttribute(org.springframework.transaction.interceptor.NoRollbackRuleAttribute) RuleBasedTransactionAttribute(org.springframework.transaction.interceptor.RuleBasedTransactionAttribute) Method(java.lang.reflect.Method) NoRollbackRuleAttribute(org.springframework.transaction.interceptor.NoRollbackRuleAttribute) IOException(java.io.IOException) IOException(java.io.IOException) Test(org.junit.Test)

Example 15 with RollbackRuleAttribute

use of org.springframework.transaction.interceptor.RollbackRuleAttribute in project spring-framework by spring-projects.

the class AnnotationTransactionAttributeSourceTests method transactionAttributeDeclaredOnCglibClassMethod.

/**
	 * Test the important case where the invocation is on a proxied interface method
	 * but the attribute is defined on the target class.
	 */
@Test
public void transactionAttributeDeclaredOnCglibClassMethod() throws Exception {
    Method classMethod = ITestBean.class.getMethod("getAge");
    TestBean1 tb = new TestBean1();
    ProxyFactory pf = new ProxyFactory(tb);
    pf.setProxyTargetClass(true);
    Object proxy = pf.getProxy();
    AnnotationTransactionAttributeSource atas = new AnnotationTransactionAttributeSource();
    TransactionAttribute actual = atas.getTransactionAttribute(classMethod, proxy.getClass());
    RuleBasedTransactionAttribute rbta = new RuleBasedTransactionAttribute();
    rbta.getRollbackRules().add(new RollbackRuleAttribute(Exception.class));
    assertEquals(rbta.getRollbackRules(), ((RuleBasedTransactionAttribute) actual).getRollbackRules());
}
Also used : TransactionAttribute(org.springframework.transaction.interceptor.TransactionAttribute) RuleBasedTransactionAttribute(org.springframework.transaction.interceptor.RuleBasedTransactionAttribute) RollbackRuleAttribute(org.springframework.transaction.interceptor.RollbackRuleAttribute) NoRollbackRuleAttribute(org.springframework.transaction.interceptor.NoRollbackRuleAttribute) ProxyFactory(org.springframework.aop.framework.ProxyFactory) RuleBasedTransactionAttribute(org.springframework.transaction.interceptor.RuleBasedTransactionAttribute) GroovyObject(groovy.lang.GroovyObject) Method(java.lang.reflect.Method) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

NoRollbackRuleAttribute (org.springframework.transaction.interceptor.NoRollbackRuleAttribute)15 RollbackRuleAttribute (org.springframework.transaction.interceptor.RollbackRuleAttribute)15 RuleBasedTransactionAttribute (org.springframework.transaction.interceptor.RuleBasedTransactionAttribute)14 IOException (java.io.IOException)11 Method (java.lang.reflect.Method)11 Test (org.junit.Test)11 TransactionAttribute (org.springframework.transaction.interceptor.TransactionAttribute)11 ArrayList (java.util.ArrayList)2 GroovyObject (groovy.lang.GroovyObject)1 LinkedList (java.util.LinkedList)1 ProxyFactory (org.springframework.aop.framework.ProxyFactory)1 TypedStringValue (org.springframework.beans.factory.config.TypedStringValue)1 ManagedMap (org.springframework.beans.factory.support.ManagedMap)1 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)1 Element (org.w3c.dom.Element)1