@ -16,14 +16,10 @@
@@ -16,14 +16,10 @@
package org.springframework.transaction.aspectj ;
import java.lang.reflect.Method ;
import org.junit.Before ;
import org.junit.Test ;
import org.springframework.tests.transaction.CallCountingTransactionManager ;
import org.springframework.transaction.annotation.AnnotationTransactionAttributeSource ;
import org.springframework.transaction.interceptor.TransactionAttribute ;
import static org.junit.Assert.* ;
@ -65,7 +61,7 @@ public class TransactionAspectTests {
@@ -65,7 +61,7 @@ public class TransactionAspectTests {
}
@Test
public void testC ommitOnAnnotatedProtectedMethod( ) throws Throwable {
public void c ommitOnAnnotatedProtectedMethod( ) throws Throwable {
txManager . clear ( ) ;
assertEquals ( 0 , txManager . begun ) ;
beanWithAnnotatedProtectedMethod . doInTransaction ( ) ;
@ -73,7 +69,7 @@ public class TransactionAspectTests {
@@ -73,7 +69,7 @@ public class TransactionAspectTests {
}
@Test
public void testC ommitOnAnnotatedPrivateMethod( ) throws Throwable {
public void c ommitOnAnnotatedPrivateMethod( ) throws Throwable {
txManager . clear ( ) ;
assertEquals ( 0 , txManager . begun ) ;
beanWithAnnotatedPrivateMethod . doSomething ( ) ;
@ -81,15 +77,15 @@ public class TransactionAspectTests {
@@ -81,15 +77,15 @@ public class TransactionAspectTests {
}
@Test
public void testNoC ommitOnNonAnnotatedNonPublicMethodInTransactionalType( ) throws Throwable {
public void c ommitOnNonAnnotatedNonPublicMethodInTransactionalType( ) throws Throwable {
txManager . clear ( ) ;
assertEquals ( 0 , txManager . begun ) ;
assertEquals ( 0 , txManager . begun ) ;
annotationOnlyOnClassWithNoInterface . nonTransactionalMethod ( ) ;
assertEquals ( 0 , txManager . begun ) ;
assertEquals ( 0 , txManager . begun ) ;
}
@Test
public void testC ommitOnAnnotatedMethod( ) throws Throwable {
public void c ommitOnAnnotatedMethod( ) throws Throwable {
txManager . clear ( ) ;
assertEquals ( 0 , txManager . begun ) ;
methodAnnotationOnly . echo ( null ) ;
@ -97,7 +93,7 @@ public class TransactionAspectTests {
@@ -97,7 +93,7 @@ public class TransactionAspectTests {
}
@Test
public void testN otTransactional( ) throws Throwable {
public void n otTransactional( ) throws Throwable {
txManager . clear ( ) ;
assertEquals ( 0 , txManager . begun ) ;
new NotTransactional ( ) . noop ( ) ;
@ -105,15 +101,10 @@ public class TransactionAspectTests {
@@ -105,15 +101,10 @@ public class TransactionAspectTests {
}
@Test
public void testD efaultCommitOnAnnotatedClass( ) throws Throwable {
public void d efaultCommitOnAnnotatedClass( ) throws Throwable {
final Exception ex = new Exception ( ) ;
try {
testRollback ( new TransactionOperationCallback ( ) {
@Override
public Object performTransactionalOperation ( ) throws Throwable {
return annotationOnlyOnClassWithNoInterface . echo ( ex ) ;
}
} , false ) ;
testRollback ( ( ) - > annotationOnlyOnClassWithNoInterface . echo ( ex ) , false ) ;
fail ( "Should have thrown Exception" ) ;
}
catch ( Exception ex2 ) {
@ -122,15 +113,10 @@ public class TransactionAspectTests {
@@ -122,15 +113,10 @@ public class TransactionAspectTests {
}
@Test
public void testD efaultRollbackOnAnnotatedClass( ) throws Throwable {
public void d efaultRollbackOnAnnotatedClass( ) throws Throwable {
final RuntimeException ex = new RuntimeException ( ) ;
try {
testRollback ( new TransactionOperationCallback ( ) {
@Override
public Object performTransactionalOperation ( ) throws Throwable {
return annotationOnlyOnClassWithNoInterface . echo ( ex ) ;
}
} , true ) ;
testRollback ( ( ) - > annotationOnlyOnClassWithNoInterface . echo ( ex ) , true ) ;
fail ( "Should have thrown RuntimeException" ) ;
}
catch ( RuntimeException ex2 ) {
@ -139,15 +125,10 @@ public class TransactionAspectTests {
@@ -139,15 +125,10 @@ public class TransactionAspectTests {
}
@Test
public void testD efaultCommitOnSubclassOfAnnotatedClass( ) throws Throwable {
public void d efaultCommitOnSubclassOfAnnotatedClass( ) throws Throwable {
final Exception ex = new Exception ( ) ;
try {
testRollback ( new TransactionOperationCallback ( ) {
@Override
public Object performTransactionalOperation ( ) throws Throwable {
return new SubclassOfClassWithTransactionalAnnotation ( ) . echo ( ex ) ;
}
} , false ) ;
testRollback ( ( ) - > new SubclassOfClassWithTransactionalAnnotation ( ) . echo ( ex ) , false ) ;
fail ( "Should have thrown Exception" ) ;
}
catch ( Exception ex2 ) {
@ -156,15 +137,10 @@ public class TransactionAspectTests {
@@ -156,15 +137,10 @@ public class TransactionAspectTests {
}
@Test
public void testD efaultCommitOnSubclassOfClassWithTransactionalMethodAnnotated( ) throws Throwable {
public void d efaultCommitOnSubclassOfClassWithTransactionalMethodAnnotated( ) throws Throwable {
final Exception ex = new Exception ( ) ;
try {
testRollback ( new TransactionOperationCallback ( ) {
@Override
public Object performTransactionalOperation ( ) throws Throwable {
return new SubclassOfClassWithTransactionalMethodAnnotation ( ) . echo ( ex ) ;
}
} , false ) ;
testRollback ( ( ) - > new SubclassOfClassWithTransactionalMethodAnnotation ( ) . echo ( ex ) , false ) ;
fail ( "Should have thrown Exception" ) ;
}
catch ( Exception ex2 ) {
@ -173,41 +149,19 @@ public class TransactionAspectTests {
@@ -173,41 +149,19 @@ public class TransactionAspectTests {
}
@Test
public void testDefault CommitOnImplementationOfAnnotatedInterface( ) throws Throwable {
public void no CommitOnImplementationOfAnnotatedInterface( ) throws Throwable {
final Exception ex = new Exception ( ) ;
testNotTransactional ( new TransactionOperationCallback ( ) {
@Override
public Object performTransactionalOperation ( ) throws Throwable {
return new ImplementsAnnotatedInterface ( ) . echo ( ex ) ;
}
} , ex ) ;
testNotTransactional ( ( ) - > new ImplementsAnnotatedInterface ( ) . echo ( ex ) , ex ) ;
}
/ * *
* Note : resolution does not occur . Thus we can ' t make a class transactional if
* it implements a transactionally annotated interface . This behavior could only
* be changed in AbstractFallbackTransactionAttributeSource in Spring proper .
* See SPR - 14322 .
* /
@Test
public void testDoesNotResolveTxAnnotationOnMethodFromClassImplementingAnnotatedInterface ( ) throws Exception {
AnnotationTransactionAttributeSource atas = new AnnotationTransactionAttributeSource ( ) ;
Method method = ImplementsAnnotatedInterface . class . getMethod ( "echo" , Throwable . class ) ;
TransactionAttribute ta = atas . getTransactionAttribute ( method , ImplementsAnnotatedInterface . class ) ;
assertNull ( ta ) ;
}
@Test
public void testDefaultRollbackOnImplementationOfAnnotatedInterface ( ) throws Throwable {
public void noRollbackOnImplementationOfAnnotatedInterface ( ) throws Throwable {
final Exception rollbackProvokingException = new RuntimeException ( ) ;
testNotTransactional ( new TransactionOperationCallback ( ) {
@Override
public Object performTransactionalOperation ( ) throws Throwable {
return new ImplementsAnnotatedInterface ( ) . echo ( rollbackProvokingException ) ;
}
} , rollbackProvokingException ) ;
testNotTransactional ( ( ) - > new ImplementsAnnotatedInterface ( ) . echo ( rollbackProvokingException ) ,
rollbackProvokingException ) ;
}
protected void testRollback ( TransactionOperationCallback toc , boolean rollback ) throws Throwable {
txManager . clear ( ) ;
assertEquals ( 0 , txManager . begun ) ;