Open bdbogjoe opened 6 years ago
i wonder why on https://github.com/grails/grails-testing-support/blob/master/grails-gorm-testing-support/src/main/groovy/org/grails/testing/gorm/spock/DataTestSetupSpecInterceptor.groovy#L49 it is using deprecated constructor of SimpleMapDatastore
@jeffbrown do you have any idea on this issue ?
thanks to @jameskleeh, and https://github.com/bdbogjoe/unit-test-multiple-datasource/pull/3
i'm now able to able to pass my previous tests, but now i'm facing issue while trying to validate my domain
Condition failed with Exception:
bean.validate()
| |
| java.lang.IllegalStateException: No Datastore Session bound to thread, and configuration does not allow creation of non-transactional one here
joe.Test : (unsaved)
If i add annotation @Transactional(connection = 'myDataSource')
I got error :
No datastore found for connection named [myDataSource]
org.grails.datastore.mapping.core.exceptions.ConfigurationException: No datastore found for connection named [myDataSource]
at org.grails.datastore.mapping.simple.SimpleMapDatastore.getDatastoreForConnection(SimpleMapDatastore.java:344)
at joe.TestSpec.testValidateWithTransactional(TestSpec.groovy)
i updated my repo : https://github.com/bdbogjoe/unit-test-multiple-datasource
just run gradle test to have these errors
@bdbogjoe In general my advice for situations like this is to use a real datastore.
thanks @jameskleeh , i'm now back on this issue, i'm still blocked with it.
What do you mean by using real datastore ?
Seems we don't have choice : https://github.com/grails/grails-testing-support/blob/f1a61e4f4834d9faedc57d8f8882d06d79e22f7a/grails-gorm-testing-support/src/main/groovy/org/grails/testing/gorm/spock/DataTestSetupSpecInterceptor.groovy#L59
SimpleDatastore is used, and we cannot change it, and using deprecated constructor I try to override the bean grailsDatastore, but our code (doWithSpring) from tests is evaluated before, and so not possible to override the bean
I spent days already on this issue, i'm the only one testing domain which is not using default datasource ?
I updated my repo to illustrate another issue, maybe same, don't know
https://github.com/bdbogjoe/unit-test-multiple-datasource
if you run test you have now :
i have constraint defined : https://github.com/bdbogjoe/unit-test-multiple-datasource/blob/a0e35a37a698862884b5285127e7fbe7a1298ab1/grails-app/domain/joe/Test.groovy#L12
Same tests for other domain using default datasource works fine
I think we need better solution than overriding dataStore in test, because in some other places we need to get datastore from application context
i found one solution : https://github.com/bdbogjoe/unit-test-multiple-datasource/commit/9fe96259b35b79accb26c9699a8b3f576f1d9e15
but don't think it is nice solution, any other proposal ?
@jameskleeh In general my advice for situations like this is to use a real datastore. Can you elaborate ? I'm interested in your advice as I'm also currently stuck. I can't seem to find a way to have the same mocking with Domains using a different datasource than the default one.
DataTest doesn't support enhancing Domain that comes from a different datastore than default one. The only way seem to hack the connections sources to make the default datastore create children datastore...
@anthonyMoreira For example if you are using Hibernate, use the https://github.com/grails/gorm-hibernate5/blob/master/grails-plugin/src/main/groovy/grails/test/hibernate/HibernateSpec.groovy instead of this unit testing framework.
i initially created issue but in wrong place https://github.com/grails/grails-core/issues/10888
while doing test i have error :
I spent already days on this, cannot find correct solution. One idea was to overwrite method getDatastore https://github.com/bdbogjoe/unit-test-multiple-datasource/pull/2 but in some case does not work and don't think it is correct way to do this.
Do you have any idea how to fix this ? Was working fine in grails 3.1.x