Grails 3.x — тесты из Grails 2.5.x не работают

У меня есть класс домена, который расширяет класс, не относящийся к домену. Когда мой проект был на 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)

Если удалить «extends DomainRestResource» из домена, тест завершится успешно. Я не могу удалить его из всех своих доменных классов, это очень важно для логики программы. Как я могу это исправить? Спасибо!


person Sergey Linnik    schedule 11.02.2016    source источник


Ответы (1)


Решение — просто обновить Grails до версии 3.1.2.

person Sergey Linnik    schedule 02.03.2016