grails-data-mapping icon indicating copy to clipboard operation
grails-data-mapping copied to clipboard

GRAILS-8841: Implement case-insensitive eq() Criteria in Unit Tests

Open graemerocher opened this issue 13 years ago • 11 comments

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}

graemerocher avatar Feb 24 '12 10:02 graemerocher

aveltens said: Still an issue in Grails 2.2.2

graemerocher avatar May 27 '14 03:05 graemerocher

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)

snimavat avatar Jul 20 '16 07:07 snimavat

Was there any news about this? I'm getting this error in 2.4.5. :angry:

rodriguezkatarina avatar Sep 12 '16 16:09 rodriguezkatarina

FYI... I think one way to make this work is to use HibernateTestMixin.

jeffscottbrown avatar Sep 12 '16 16:09 jeffscottbrown

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?

michaelkanis avatar Mar 03 '17 14:03 michaelkanis

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.

deflomu avatar Mar 30 '17 07:03 deflomu

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.

pauldubois777 avatar May 19 '17 16:05 pauldubois777

Facing the same issue. As a workaround used -

MyDomainObj.withCriteria() {
    Environment.current = Environment.TEST ? ilike("value", value) : eq("value", value, [ignoreCase: 
            true])
}

ankit-agrawal11 avatar Feb 09 '18 06:02 ankit-agrawal11

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)
	...

antoineroux avatar Feb 22 '18 11:02 antoineroux

Still the issue with grails 3.3.x

snimavat avatar Mar 27 '18 12:03 snimavat

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)

ajayshah1992 avatar May 25 '21 13:05 ajayshah1992