Grails 3.x - 来自Grails 2.5.x的测试不起作用

时间:2016-02-11 15:34:51

标签: grails gorm spock

我有一个域类,它扩展了非域类。当我的项目在Grails 2.5.3上时,测试工作正常。

@Mock(Activity)
class ActivitySpec extends Specification {
    def "test"(){
        expect:
        new Activity(name: 'dfd').save()
    }
}

域名

class Activity extends DomainRestResource {
    String name
    String code
    String description
    static hasMany = [....]
    static belongsTo = [... ]

    static constraints = {
        name maxSize: 50
       ....
    }

    static mapping = {
        table name: 'tt_activity'
    }
}

DomainRestResourcesrc/main/groovy/com/...

中定义

DomainRestResource.groovy

抽象类DomainRestResource扩展了UniversalRestResource {

@Autowired
def connectionManager
@Autowired
def userActivityService
@Autowired
def dataSource

protected transient int limit
protected transient int offset
private transient String tableName

/*
many static methods and fields
and some logic
*/

}

UniversalRestResource.groovy

abstract class UniversalRestResource {

    /*
    some logic
    */

    abstract List<Object> findObjectsByQuery(String query, int limit, int offset)
   /*and any others abstract methods*/
}

现在我将项目升级到Grails 3.1.1,除了我的所有测试之外,一切正常。 关于grails的测试结果3.1.1:

org.grails.datastore.mapping.model.IllegalMappingException: Mapped identifier [id] for class [com.astaprime.rest.DomainRestResource] is not a valid property

    at org.grails.datastore.mapping.model.config.GormMappingConfigurationStrategy.getIdentity(GormMappingConfigurationStrategy.java:887)
    at org.grails.datastore.mapping.model.AbstractPersistentEntity.resolveIdentifier(AbstractPersistentEntity.java:196)
    at org.grails.datastore.mapping.model.AbstractPersistentEntity.initialize(AbstractPersistentEntity.java:117)
    at org.grails.datastore.mapping.model.AbstractPersistentEntity.getRootEntity(AbstractPersistentEntity.java:221)
    at org.grails.datastore.mapping.model.AbstractMappingContext.initializePersistentEntity(AbstractMappingContext.java:271)
    at org.grails.datastore.mapping.model.AbstractMappingContext.initialize(AbstractMappingContext.java:250)
    at grails.test.mixin.domain.DomainClassUnitTestMixin.initializeMappingContext(DomainClassUnitTestMixin.groovy:93)
    at grails.test.mixin.domain.DomainClassUnitTestMixin.mockDomains(DomainClassUnitTestMixin.groovy:87)
    at org.spockframework.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:153)
    at org.spockframework.runtime.model.MethodInfo.invoke(MethodInfo.java:84)
    at org.spockframework.runtime.extension.MethodInvocation.proceed(MethodInvocation.java:88)
    at org.spockframework.runtime.extension.builtin.AbstractRuleInterceptor$1.evaluate(AbstractRuleInterceptor.java:37)
    at grails.test.runtime.TestRuntimeJunitAdapter$1$2.evaluate(TestRuntimeJunitAdapter.groovy:46)
    at org.spockframework.runtime.extension.builtin.TestRuleInterceptor.intercept(TestRuleInterceptor.java:38)
    at org.spockframework.runtime.extension.MethodInvocation.proceed(MethodInvocation.java:87)
    at org.spockframework.runtime.extension.MethodInvocation.proceed(MethodInvocation.java:88)
    at org.spockframework.runtime.extension.builtin.AbstractRuleInterceptor$1.evaluate(AbstractRuleInterceptor.java:37)
    at grails.test.runtime.TestRuntimeJunitAdapter$3$4.evaluate(TestRuntimeJunitAdapter.groovy:73)
    at org.spockframework.runtime.extension.builtin.ClassRuleInterceptor.intercept(ClassRuleInterceptor.java:38)
    at org.spockframework.runtime.extension.MethodInvocation.proceed(MethodInvocation.java:87)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)

如果删除&#34;扩展DomainRestResource&#34;从域,测试成功。 我不能从我的所有域类中删除它,它对程序逻辑非常重要。 我能解决这个问题吗?感谢名单!

1 个答案:

答案 0 :(得分:0)

解决方案只是将Grails升级到版本3.1.2 The issue on Github