我的Grails 3.1.8应用程序的所有生成的控制器测试仅在尝试删除域实例时失败。
错误是:
java.lang.NullPointerException: Cannot invoke method fire() on null object
at gov.usda.fs.forecast.traits.UpdateMetadataTrait$Trait$Helper.afterDelete(UpdateMetadataTrait.groovy:30)
at org.springframework.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:216)
at org.springframework.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:201)
at org.grails.datastore.gorm.events.DomainEventListener.invokeEvent(DomainEventListener.java:259)
at org.grails.datastore.gorm.events.DomainEventListener.afterDelete(DomainEventListener.java:176)
at org.grails.datastore.gorm.events.DomainEventListener.onPersistenceEvent(DomainEventListener.java:96)
at org.grails.datastore.mapping.engine.event.AbstractPersistenceEventListener.onApplicationEvent(AbstractPersistenceEventListener.java:47)
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:166)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:138)
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:381)
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:335)
at org.grails.datastore.mapping.engine.EntityPersister.firePostDeleteEvent(EntityPersister.java:340)
at org.grails.datastore.mapping.engine.NativeEntryEntityPersister.deleteEntity(NativeEntryEntityPersister.java:131)
at org.grails.datastore.mapping.engine.EntityPersister.delete(EntityPersister.java:262)
at org.grails.datastore.mapping.core.AbstractSession.delete(AbstractSession.java:728)
at org.grails.datastore.gorm.GormInstanceApi.delete_closure9(GormInstanceApi.groovy:268)
at groovy.lang.Closure.call(Closure.java:426)
at org.grails.datastore.mapping.core.DatastoreUtils.execute(DatastoreUtils.java:310)
at org.grails.datastore.gorm.AbstractDatastoreApi.execute(AbstractDatastoreApi.groovy:37)
at org.grails.datastore.gorm.GormInstanceApi.delete(GormInstanceApi.groovy:267)
at org.grails.datastore.gorm.GormEntity$Trait$Helper.delete(GormEntity.groovy:194)
at gov.usda.fs.forecast.InvoiceStatusController.$tt__delete(InvoiceStatusController.groovy:91)
at gov.usda.fs.forecast.InvoiceStatusController.delete_closure4(InvoiceStatusController.groovy)
at groovy.lang.Closure.call(Closure.java:426)
at groovy.lang.Closure.call(Closure.java:442)
at grails.transaction.GrailsTransactionTemplate$2.doInTransaction(GrailsTransactionTemplate.groovy:96)
at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:133)
at grails.transaction.GrailsTransactionTemplate.execute(GrailsTran
这是测试代码:
void "Test that the delete action deletes an instance if it exists"() {
when:"The delete action is called for a null instance"
request.contentType = FORM_CONTENT_TYPE
request.method = 'DELETE'
controller.delete(null)
then:"A 404 is returned"
response.redirectedUrl == '/invoiceStatus/index'
flash.message != null
when:"A domain instance is created"
response.reset()
populateValidParams(params)
def invoiceStatus = new InvoiceStatus(params).save(flush: true)
then:"It exists"
InvoiceStatus.count() == 1
// The test fails when issuing the delete
when:"The domain instance is passed to the delete action"
controller.delete(invoiceStatus)
then:"The instance is deleted"
InvoiceStatus.count() == 0
response.redirectedUrl == '/invoiceStatus/index'
flash.message != null
}
我在同一地点的每个生成的测试中得到相同的错误。任何线索都将非常感激。