grails - Multi-Tenancy 时如何使用DomainUnitTest进行测试

标签 grails gorm spock

使用multiTenancy时如何测试域类?

我可以看到我需要扩展HibernateSpec并覆盖getConfiguration。

当我使用ServiceUnitTest而不是DomainUnitTest时,这没关系

简单的例子:
用以下命令设置application.yml:

grails:
    gorm:
        multiTenancy:
            mode: DISCRIMINATOR
            tenantResolverClass: security.CompanyTenantResolver

我的测试:
class TestSpec extends HibernateSpec implements DomainUnitTest<Test>{
    void "expect ok test"() {
        expect:
        true
    }
    def setup() {
        System.setProperty(SystemPropertyTenantResolver.PROPERTY_NAME, 'unit-test')
    }

    def cleanup() {
        System.setProperty(SystemPropertyTenantResolver.PROPERTY_NAME, '')
    }


    @Override
    Map getConfiguration() {
        [(Settings.SETTING_MULTI_TENANT_RESOLVER_CLASS): SystemPropertyTenantResolver]
    }

}

无论我尝试什么,我都会得到:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.grails.beans.ConstraintsEvaluator': Cannot resolve reference to bean 'grailsDomainClassMappingContext' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'grailsDatastore': Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.grails.datastore.mapping.simple.SimpleMapDatastore]: Constructor threw exception; nested exception is org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.lang.String] to type [java.lang.Class<?>]

是grails错误还是忘记了某些东西?

最佳答案

这是grails 3.3.2版本中的错误,在3.3.0版本中可以正常工作

关于grails - Multi-Tenancy 时如何使用DomainUnitTest进行测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48978398/

相关文章:

Grails 2.2.0 应用程序的 Maven 构建失败,JDK 1.7 : Could not find artifact com. sun :tools:jar:1. 6

hibernate - grails/GORM/hibernate -hasMany map 未在父级的save()上同步

grails - Grails域类可以在每个查询中包含自定义条件吗?

unit-testing - Spock:从 CSV 文件读取测试数据

grails - 无法在 Grails 3 中填充 java.util.getTimeZone 以进行 Taglib 中的 spock 测试

grails - 如何在 grails 域类中设置默认值

grails - Grails对象不是声明类的实例

grails - Active Record和GORM休眠

unit-testing - 带有继承的单元测试方法 Controller 调用

grails - 如何测试具有 Basecontroller 的 @Mixin 的 Controller