[from now] 2013/09/27 13:15:55

diff --git a/grails-plugin-datasource/src/test/groovy/grails/transaction/TransactionalTransformSpec.groovy b/grails-plugin-datasource/src/test/groovy/grails/transaction/TransactionalTransformSpec.groovy
index f9ce725..f4b07a9 100644
--- a/grails-plugin-datasource/src/test/groovy/grails/transaction/TransactionalTransformSpec.groovy
+++ b/grails-plugin-datasource/src/test/groovy/grails/transaction/TransactionalTransformSpec.groovy
@@ -224,6 +224,65 @@ new BookService()

     }

+    void "Test rollback with @Transactional annotation"() {
+        when:"A new instance of a class with a @Transactional method is created"
+            def bookService = new GroovyShell().evaluate('''
+import grails.transaction.*
+import org.codehaus.groovy.grails.orm.support.TransactionManagerAware
+import org.springframework.transaction.PlatformTransactionManager
+import org.springframework.transaction.TransactionStatus
+import org.springframework.transaction.annotation.Isolation
+import org.springframework.transaction.annotation.Propagation
+
+class BookService {
+
+    @Transactional
+    void throwRuntimeException() {
+        throw new TestTransactionRuntimeException(transactionStatus)
+    }
+
+    @Transactional
+    void throwException() {
+         throw new TestTransactionException(transactionStatus)
+    }
+
+}
+
+new BookService()
+''')
+
+        then:"It implements TransactionManagerAware"
+            bookService instanceof TransactionManagerAware
+
+        when:"A transactionManager is set"
+            def transactionManager = getPlatformTransactionManager()
+            bookService.transactionManager = transactionManager
+
+        then:"It is not null"
+            bookService.transactionManager != null
+
+        when:"A transactional method is called"
+            bookService.throwRuntimeException()
+
+        then:"The transaction was started"
+            thrown(TestTransactionRuntimeException)
+
+            transactionManager.transactoinRollbacked == true
+
+        when:"A transactionManager is set"
+        transactionManager = getPlatformTransactionManager()
+        bookService.transactionManager = transactionManager
+
+        then:"It is not null"
+        bookService.transactionManager != null
+
+        when:"A transactional method is called"
+        bookService.throwException()
+
+        then:"The transaction was started"
+        thrown(TestTransactionException)
+        transactionManager.transactoinRollbacked == false
+    }

     TestTransactionManager getPlatformTransactionManager() {
         def dataSource = new DriverManagerDataSource("org.h2.Driver", "jdbc:h2:mem:${TransactionalTransformSpec.name};MVCC=TRUE;LOCK_TIMEOUT=10000", "sa", "")
@@ -233,6 +292,7 @@ new BookService()
 }
 class TestTransactionManager extends DataSourceTransactionManager {
     boolean transactionStarted = false
+    boolean transactoinRollbacked = false
     TestTransactionManager(DataSource dataSource) {
         super(dataSource)
     }
@@ -242,7 +302,27 @@ class TestTransactionManager extends DataSourceTransactionManager {
         transactionStarted = true
         return super.doGetTransaction()
     }
+
+    @Override
+    protected void doRollback(DefaultTransactionStatus status) {
+        transactoinRollbacked = true
+        super.doRollback(status)
+    }
+
 }

+class TestTransactionRuntimeException extends RuntimeException {
+    DefaultTransactionStatus status
+
+    TestTransactionRuntimeException(DefaultTransactionStatus status) {
+        this.status = status
+    }
+}

+class TestTransactionException extends Exception {
+    DefaultTransactionStatus status

+    TestTransactionException(DefaultTransactionStatus status) {
+        this.status = status
+    }
+}