-
Notifications
You must be signed in to change notification settings - Fork 198
Description
Original Reporter: erdi
Environment: Not Specified
Version: Not Specified
Migrated From: http://jira.grails.org/browse/GPMONGODB-40
I've recently started using DatastoreUnitTestMixin to unit test my code using criteria queries. If I run my unit tests or integration test separately everything works fine, but if I run them both using grails test-app I get a following stack trace:
java.lang.UnsupportedOperationException
at $Proxy35.doWebDescriptor(Unknown Source)
at _GrailsPackage_groovy$_run_closure5_closure19.doCall(_GrailsPackage_groovy:232)
at _GrailsPackage_groovy$_run_closure5_closure19.doCall(_GrailsPackage_groovy)
at _GrailsSettings_groovy$_run_closure10.doCall(_GrailsSettings_groovy:282)
at _GrailsSettings_groovy$_run_closure10.call(_GrailsSettings_groovy)
at _GrailsPackage_groovy$_run_closure5.doCall(_GrailsPackage_groovy:230)
at _GrailsPackage_groovy$_run_closure2.doCall(_GrailsPackage_groovy:168)
at _GrailsBootstrap_groovy$_run_closure6.doCall(_GrailsBootstrap_groovy:134)
at _GrailsTest_groovy$_run_closure9.doCall(_GrailsTest_groovy:301)
at _GrailsTest_groovy$_run_closure9.doCall(_GrailsTest_groovy)
at _GrailsTest_groovy$_run_closure1_closure21.doCall(_GrailsTest_groovy:178)
at _GrailsTest_groovy$_run_closure1.doCall(_GrailsTest_groovy:168)
at TestApp$_run_closure1.doCall(TestApp.groovy:102)
at gant.Gant$_dispatch_closure5.doCall(Gant.groovy:381)
at gant.Gant$_dispatch_closure7.doCall(Gant.groovy:415)
at gant.Gant$_dispatch_closure7.doCall(Gant.groovy)
at gant.Gant.withBuildListeners(Gant.groovy:427)
at gant.Gant.this$2$withBuildListeners(Gant.groovy)
at gant.Gant$this$2$withBuildListeners.callCurrent(Unknown Source)
at gant.Gant.dispatch(Gant.groovy:415)
at gant.Gant.this$2$dispatch(Gant.groovy)
at gant.Gant.invokeMethod(Gant.groovy)
at gant.Gant.executeTargets(Gant.groovy:590)
at gant.Gant.executeTargets(Gant.groovy:589)
Error generating web.xml file: null
I checked out the code of DatastoreUnitTestMixin and tracked down the reason to be in mocking GrailsPluginManager and assigning it to PluginManagerHolder.pluginManager - the mocked object doesn't implement doWebDescriptor method.
The following is a workaround class I'm using at the moment with success:
class DatastoreUnitTestMixinWithFix extends DatastoreUnitTestMixin {
private GrailsPluginManager originalManager
private boolean shouldRestorePluginManager = false
def mockDomain(Class domainClass, List instances = []) {
if (!shouldRestorePluginManager) {
originalManager = PluginManagerHolder.pluginManager
shouldRestorePluginManager = true
}
super.mockDomain(domainClass, instances)
}
def disconnect() {
super.disconnect()
if (shouldRestorePluginManager) {
PluginManagerHolder.pluginManager = originalManager
shouldRestorePluginManager = false
}
}
}