@@ -21,6 +21,7 @@ import org.codehaus.groovy.control.MultipleCompilationErrorsException
2121import org.springframework.beans.factory.annotation.Autowired
2222import org.springframework.beans.factory.annotation.Qualifier
2323import org.springframework.transaction.PlatformTransactionManager
24+ import org.springframework.util.ReflectionUtils
2425
2526import javax.annotation.PostConstruct
2627import javax.sql.DataSource
@@ -60,6 +61,10 @@ class TransactionalTransformSpec extends Specification {
6061
6162 }
6263
64+ def cleanup() {
65+
66+ }
67+
6368 void "my test method"() {
6469 expect:
6570 1 == 1
@@ -72,10 +77,91 @@ class TransactionalTransformSpec extends Specification {
7277 TransactionManagerAware . isAssignableFrom(mySpec)
7378 mySpec. getDeclaredMethod(' setup' )
7479 mySpec. getDeclaredMethod(' $tt__setup' , TransactionStatus )
80+ mySpec. getDeclaredMethod(' cleanup' )
81+ mySpec. getDeclaredMethod(' $tt__cleanup' , TransactionStatus )
82+
7583 mySpec. getDeclaredMethod(' $spock_feature_0_0' )
7684 mySpec. getDeclaredMethod(' $tt__$spock_feature_0_0' , TransactionStatus )
7785 }
7886
87+ void " Test @Rollback when applied to Spock specifications and where blocks" () {
88+ when :" A new instance of a class with a @Transactional method is created that subclasses another transactional class"
89+ Class mySpec = new GroovyShell (). evaluate('''
90+ import grails.test.mixin.integration.Integration
91+ import grails.transaction.Rollback
92+ import spock.lang.Specification
93+
94+ @Integration
95+ @Rollback
96+ class DemoSpec extends Specification {
97+
98+ def "test toUpperCase"() {
99+ given:
100+ def result = value.toUpperCase()
101+
102+ expect:
103+ result == expectedResult
104+
105+ where:
106+ value | expectedResult
107+ 'King Crimson' | 'KING CRIMSON\'
108+ 'Riverside' | 'RIVERSIDE\'
109+ }
110+ }
111+ DemoSpec
112+ ''' )
113+
114+ then :" It implements TransactionManagerAware"
115+ TransactionManagerAware . isAssignableFrom(mySpec)
116+ mySpec. getDeclaredMethod(' $spock_feature_0_0' , Object , Object )
117+ mySpec. getDeclaredMethod(' $spock_feature_0_0proc' , Object , Object )
118+ mySpec. getDeclaredMethod(' $spock_feature_0_0prov0' )
119+
120+ ! ReflectionUtils . findMethod(mySpec, ' $tt__$spock_feature_0_0prov0' , TransactionStatus )
121+ ReflectionUtils . findMethod(mySpec, ' $tt__$spock_feature_0_0' , Object , Object , TransactionStatus )
122+ ! ReflectionUtils . findMethod(mySpec, ' $tt__$spock_feature_0_0proc' , Object , Object , TransactionStatus )
123+ }
124+
125+ void " Test @Rollback when applied to Spock specifications on a method and where blocks" () {
126+ when :" A new instance of a class with a @Transactional method is created that subclasses another transactional class"
127+ Class mySpec = new GroovyShell (). evaluate('''
128+ import grails.test.mixin.integration.Integration
129+ import grails.transaction.Rollback
130+ import spock.lang.Specification
131+
132+ @Integration
133+
134+ class DemoSpec extends Specification {
135+
136+ @Rollback
137+ def "test toUpperCase"() {
138+ given:
139+ def result = value.toUpperCase()
140+
141+ expect:
142+ result == expectedResult
143+
144+ where:
145+ value | expectedResult
146+ 'King Crimson' | 'KING CRIMSON\'
147+ 'Riverside' | 'RIVERSIDE\'
148+ }
149+ }
150+ DemoSpec
151+ ''' )
152+
153+ then :" It implements TransactionManagerAware"
154+ TransactionManagerAware . isAssignableFrom(mySpec)
155+ mySpec. getDeclaredMethod(' $spock_feature_0_0' , Object , Object )
156+ mySpec. getDeclaredMethod(' $spock_feature_0_0proc' , Object , Object )
157+ mySpec. getDeclaredMethod(' $spock_feature_0_0prov0' )
158+
159+ ! ReflectionUtils . findMethod(mySpec, ' $tt__$spock_feature_0_0prov0' , TransactionStatus )
160+ ReflectionUtils . findMethod(mySpec, ' $tt__$spock_feature_0_0' , Object , Object , TransactionStatus )
161+ ! ReflectionUtils . findMethod(mySpec, ' $tt__$spock_feature_0_0proc' , Object , Object , TransactionStatus )
162+ }
163+
164+
79165 @Issue (' #701' )
80166 void " Test @Transactional with a datasource specified isn't TransactionManager aware, but has appropriate autowired and qualifier" () {
81167 when :" A new instance of a class with a @Transactional method is created that subclasses another transactional class"
0 commit comments