GRAILS-8841: Implement case-insensitive eq() Criteria in Unit Tests
Original Reporter: keithrz Environment: Not Specified Version: 2.0.1 Migrated From: http://jira.grails.org/browse/GRAILS-8841
My service unit test worked until I added the [ignoreCase: true] parameter to an eq() method. The service works as expected outside of unit tests. The service code is below. I did not include the code for the test Spec (Version: Spock 0.6-SNAPSHOT), but it doesn't seem to matter what is in the test Spec, as long as it calls the service.
Service Code: {code} package myPackage
class myService {
def getDomainObjs(value) {
def bundleList = MyDomainObj.withCriteria() {
eq("value", value, [ignoreCase: true])
}
}
}
{code}
Stack Trace: {code} groovy.lang.MissingMethodException: No signature of method: myPackage.myService.eq() is applicable for argument types: (java.lang.String, java.lang.String, java.util.LinkedHashMap) values: [value, value, [ignoreCase:true]] Possible solutions: grep(), any(), wait(), every(), dump(), find() at myPackage.myService.getDomainObjs_closure1(myService.groovy:6) at myPackage.myService.getDomainObjs_closure1(myService.groovy) at groovy.lang.Closure.call(Closure.java:412) at groovy.lang.Closure.call(Closure.java:406) at grails.gorm.CriteriaBuilder.invokeClosureNode(CriteriaBuilder.java:990) at grails.gorm.CriteriaBuilder.invokeMethod(CriteriaBuilder.java:312) at org.grails.datastore.gorm.GormStaticApi.withCriteria(GormStaticApi.groovy:261) at myPackage.myService.getDomainObjs(ContentBundleService.groovy:5) at myPackage.myServiceSpec.The getDomainObjs service must match by value(myServiceSpec.groovy:27) {code}
aveltens said: Still an issue in Grails 2.2.2
The issue still exist in 2.5.5,
I get the error
No signature of method: grails.gorm.TestCriteriaBuilder.eq() is applicable for argument types: (java.lang.String, java.lang.String, java.util.LinkedHashMap)
Was there any news about this? I'm getting this error in 2.4.5. :angry:
FYI... I think one way to make this work is to use HibernateTestMixin.
This behavior is still there in 3.2.5.
We are migrating a client application from 1.3.7 to current Grails and need to port old controller integration tests. HibernateTestMixin is deprecated and using HibernateSpec as suggested by the deprecation notice doesn't help either.
In our case the problem seems to be triggered in a domain class that has a validator using eq() with ignoreCase.
What can I do to workaround this?
Maybe using ilike() in the query instead of eq() could be a workaround. I don't know if this has any impact on the query performance.
Has anyone figured this out? You can use ilike(), but if you are using this on an API, you need to remove any % from your search value, since ilike() supports the % wildcard, whereas eq with ignoreCase doesn't.
Facing the same issue. As a workaround used -
MyDomainObj.withCriteria() {
Environment.current = Environment.TEST ? ilike("value", value) : eq("value", value, [ignoreCase:
true])
}
I have the same issue while migrating from 1.3.6 to 3.2.X. It seems this is because the tests use the AbstractCriteriaBuilder instead of the AsbractHibernateCriteriaBuilder, as the stack trace shows:
groovy.lang.MissingMethodException: No signature of method: grails.gorm.CriteriaBuilder.eq() is applicable for argument types: (java.lang.String, java.lang.String, java.util.LinkedHashMap) values: [hostName, host, [ignoreCase:true]]
Possible solutions: eq(java.lang.String, java.lang.Object), id(), grep(), any(), ge(java.lang.String, java.lang.Object), gt(java.lang.String, java.lang.Object)
at org.grails.datastore.gorm.query.criteria.AbstractCriteriaBuilder.invokeMethod(AbstractCriteriaBuilder.java:302)
at org.codehaus.groovy.runtime.InvokerHelper.invokePogoMethod(InvokerHelper.java:929)
at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:906)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodN(ScriptBytecodeAdapter.java:168)
at org.grails.datastore.gorm.query.NamedCriteriaProxy.methodMissing(NamedCriteriaProxy.groovy:255)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
at groovy.lang.MetaClassImpl.invokeMissingMethod(MetaClassImpl.java:941)
at groovy.lang.MetaClassImpl.invokePropertyOrMissing(MetaClassImpl.java:1264)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1217)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1024)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:812)
at org.grails.datastore.gorm.query.NamedCriteriaProxy.invokeMethod(NamedCriteriaProxy.groovy)
at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeOnDelegationObjects(ClosureMetaClass.java:430)
at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:371)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1024)
at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:69)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:182)
at com.mycompany.MyDomain$__clinit__closure1$_closure4.doCall(MyDomain.groovy:69)
...
Still the issue with grails 3.3.x
Does Anyone has solved this issue? aused by: groovy.lang.MissingMethodException: No signature of method: io.sparkwork.api.UserAPIController.eq() is applicable for argument types: (String, String, LinkedHashMap) values: [email, [email protected], [ignoreCase:true]] Possible solutions: edit(), user(), grep(), any(), wait(), index() at grails.artefact.gsp.TagLibraryInvoker$Trait$Helper.methodMissing(TagLibraryInvoker.groovy:94) at grails.artefact.gsp.TagLibraryInvoker$Trait$Helper$methodMissing$0.call(Unknown Source) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:115) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:143) at io.sparkwork.api.UserAPIController.methodMissing(UserAPIController.groovy) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:101) at groovy.lang.MetaClassImpl.invokeMissingMethod(MetaClassImpl.java:954) at groovy.lang.MetaClassImpl.invokePropertyOrMissing(MetaClassImpl.java:1286) at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1219) at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:1128)