Search in sources :

Example 11 with NoRollbackRuleAttribute

use of org.springframework.transaction.interceptor.NoRollbackRuleAttribute 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 12 with NoRollbackRuleAttribute

use of org.springframework.transaction.interceptor.NoRollbackRuleAttribute 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)

Aggregations

NoRollbackRuleAttribute (org.springframework.transaction.interceptor.NoRollbackRuleAttribute)12 RollbackRuleAttribute (org.springframework.transaction.interceptor.RollbackRuleAttribute)12 RuleBasedTransactionAttribute (org.springframework.transaction.interceptor.RuleBasedTransactionAttribute)11 IOException (java.io.IOException)9 Method (java.lang.reflect.Method)9 Test (org.junit.Test)9 TransactionAttribute (org.springframework.transaction.interceptor.TransactionAttribute)9 ArrayList (java.util.ArrayList)2