Ich habe ein neues Grails 3.1.4 eckiges Projekt zusammen mit einigen Domänenobjekten und Controllern erstellt, die RestfulController
erweitern. Ich habe den Integrationstest unten erstellt. Als ich grails test-app -integration
laufen erhalte ich die FehlerKein transactionManager Fehler in Grails 3 Integrationstest
java.lang.IllegalStateException: No transactionManager was specified. Using @Transactional or @Rollback requires a valid configured transaction manager. If you are running in a unit test ensure the test has been properly configured and that you run the test suite not an individual test method.
at grails.transaction.GrailsTransactionTemplate.<init>(GrailsTransactionTemplate.groovy:60)
at com.waldoware.invoicer.BillingEntityRestControllerIntegrationSpec.$tt__$spock_feature_0_0(BillingEntityRestControllerIntegrationSpec.groovy:29)
at com.waldoware.invoicer.BillingEntityRestControllerIntegrationSpec.test all entities_closure2(BillingEntityRestControllerIntegrationSpec.groovy)
at groovy.lang.Closure.call(Closure.java:426)
at groovy.lang.Closure.call(Closure.java:442)
at grails.transaction.GrailsTransactionTemplate$1.doInTransaction(GrailsTransactionTemplate.groovy:70)
at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:133)
at grails.transaction.GrailsTransactionTemplate.executeAndRollback(GrailsTransactionTemplate.groovy:67)
at com.waldoware.invoicer.BillingEntityRestControllerIntegrationSpec.test all entities(BillingEntityRestControllerIntegrationSpec.groovy)
Prüfklasse:
package com.waldoware.invoicer
import grails.test.mixin.integration.Integration
import grails.transaction.*
import spock.lang.*
@Integration
@Rollback
class BillingEntityRestControllerIntegrationSpec extends Specification {
def setupData() {
def biller = new BillingEntity()
biller.with {
companyName = "Acme, Inc."
}
def ledger = new Ledger(name: "My Ledger", billingEntity: biller).save(failOnError: true, flush: true)
}
void 'test all entities'() {
when:
setupData()
new BillingEntityRestController().index()
then:
response.contentType == 'application/json;charset=UTF-8'
response.status == HttpServletResponse.SC_OK
response.text == "[{}]"
}
}
Ich habe eine Datenquelle in application.yml
einzurichten:
environments:
development:
dataSource:
dbCreate: none
url: jdbc:h2:./devDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
test:
dataSource:
dbCreate: update
url: jdbc:h2:mem:testDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
production:
dataSource:
dbCreate: update
url: jdbc:h2:./prodDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
properties:
jmxEnabled: true
initialSize: 5
maxActive: 50
minIdle: 5
maxIdle: 25
maxWait: 10000
maxAge: 600000
timeBetweenEvictionRunsMillis: 5000
minEvictableIdleTimeMillis: 60000
validationQuery: SELECT 1
validationQueryTimeout: 3
validationInterval: 15000
testOnBorrow: true
testWhileIdle: true
testOnReturn: false
jdbcInterceptors: ConnectionState
defaultTransactionIsolation: 2 # TRANSACTION_READ_COMMITTED
Der einzige Grund für einen Integrationstest ist, dass ich einen benutzerdefinierten JSON Marshaller habe, der nicht unter einem Komponententest aufgerufen wird. –
Haben Sie das jemals herausgefunden? Ich migriere eine Grails-2-Anwendung und sehe das gleiche Problem mit einigen unserer Integrationstests. – Rado
@rado Ich habe nur die benutzerdefinierten Marshaller zugunsten von Gson entfernt. Das ist der Grails 3 Weg :-) –