【问题标题】:Grails 3.x - tests from grails 2.5.x don't workGrails 3.x - 来自 grails 2.5.x 的测试不起作用
【发布时间】:2016-05-22 11:28:12
【问题描述】:

我有一个域类,它扩展了非域类。当我的项目在 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'
    }
}

DomainRestResource 定义在src/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)

如果从域中删除“扩展 DomainRestResource”,则测试成功。 我不能从我所有的域类中删除它,它对程序逻辑非常重要。 我该如何解决这个问题?谢谢!

【问题讨论】:

    标签: grails grails-orm spock


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-07-01
      • 2014-02-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-18
      • 1970-01-01
      相关资源
      最近更新 更多