多租户时如何使用 DomainUnitTest 进行测试
How to test with DomainUnitTest when 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 中工作正常
如何在使用多租户时测试域 类?
我看到我需要使用 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 中工作正常