2016-02-11 3 views
0

У меня есть класс домена, который расширяет класс без домена. Когда мой проект был на Grails 2.5.3, тест работал нормально.Grails 3.x - тесты от grails 2.5.x не работают

@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 и все работает отлично, за исключением всех моих тестов. Результат теста на Граалей 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" из домена, проверка проходит успешно. Я не могу удалить его из всех моих классов домена, это очень важно для логики программы. Я могу это исправить? Thanx!

ответ

Смежные вопросы