No signature of method error while testing in grails - grails

I have a very simple code in my test:
expect:
String test = "test123"
myHelper.myMethod(test) == "test"
The error I'm getting is:
| groovy.lang.MissingMethodException: No signature of method: com.some.helper.MyHelper.myMethod() is applicable for argument types: (java.lang.String) values: [test123] Possible solutions: myMethod(java.lang.String)
at com.some.helper.MyHelperSpec.test (MyHelperSpec.groovy:245)
My method expects a String and I'm passing a string. What am I missing here? FWIW, I'm using grails 2.5.3

Related

Grails export plugin Throws an Error "No Signature Of Method is allowed"

Hi i am using grails export plugin and added the plugin in dependencies and mime type for excel.
I am passing the data in the below format:
FileOutputStream output = new FileOutputStream("C:/dummy/test1.xlsx")
def empDate = [[joindate:2018-01-30,desig:Instructor]]
List fields = ["joindate", "desig"]
Map labels = ["joindate": "Join Date", "desig": "Designation"]
exportService.export("xlsx", output,empDate, fields, labels, [:], [:])
//Throws an error "No Signature of method is allowed for argument types ....."
Full error is
No signature of method: com.test.ExportService.export() is appl icable for argument types: (java.lang.String, java.io.FileOutputStream, java.util.ArrayLis t, java.util.ArrayList, java.util.LinkedHashMap, java.util.LinkedHashMap, java.util.Linked HashMap) values: [xlsx, java.io.FileOutputStream#10234, [[joindate:2018-01-30, ...]], . ..] Possible solutions: every()
com.test.ExportService.export() indicates that you are using an export service implementation other than the one provided by the plugin. You probably have a locally defined ExportService class that you are using accidentally. Either rename your local class (preferred) or strongly type the injection to the one provided by the plugin.

How to fix groovy.lang.MissingMethodException: No signature of method when calculating the total

I am trying to connect to Cassandra and write a query in Grails to total the amount but I am getting a missing method exception:
groovy.lang.MissingMethodException: No signature of method: project
.sampleTest.column() is applicable for argument types: (java.lang.String) values: [amount]
Possible solutions: collect(), dump(), collect(groovy.lang.Closure)
Below is the query what I have written to sum the amount.
Select selectQuery = QueryBuilder.select().fcall("sum", column("amount")).from(tableName).allowFiltering()
Session session = cassandraTemplate.getSession();
Where selectWhere = selectQuery.where();
To use a column name inside of fcall() you need to use the static method QueryBuilder.column(). So when you use it in fcall() you need to call it like:
Select selectQuery = QueryBuilder.select().fcall("sum", QueryBuilder.column("amount")).from(tableName).allowFiltering()

grails shell and closures

Trying to run the following command in grails console:
Family.where() {password =~ "%qw%"}
A very simple query on a stored object. I'm getting back:
ERROR groovy.lang.MissingMethodException:
No signature of method: com.babyboom.Family.where() is applicable for argument types: (groovysh_evaluate$_run_closure1) values: [groovysh_evaluate$_run_closure1#34356294]
Possible solutions: where(groovy.lang.Closure), merge(), every(), grep(), merge(com.babyboom.Family), merge(java.util.Map)
I understand that the closure I created is a different than the expected one.
Couple of questions:
Why there are 2 types of closures ?
Found Why am I getting a "No signature of method"" error when running the closure recursion example in the Groovy shell? tried it and it didn't help, still getting the same error
It works well when using grails console
This is likely a classloader bug with the grails shell. To reproduce, add dependency to BuildConfig.gradle:
runtime "org.grails:grails-datastore-simple:3.1.2.RELEASE"
then run
import org.grails.datastore.mapping.simple.SimpleMapDatastore
import org.grails.datastore.gorm.GormStaticApi
class Bar {}
class Foo extends GormStaticApi<Bar> {
Foo() {
super(Bar, new SimpleMapDatastore(), [], null)
}
}
def f = new Foo()
In grails console yields:
Result: Foo#699c0395
In grails shell yields:
groovy:000> def f = new Foo()
ERROR java.lang.LinkageError:
loader constraint violation: when resolving overridden method "Foo.$getStaticMetaClass()Lgroovy/lang/MetaClass;" the class loader (instance of groovy/lang/GroovyClassLoader$InnerLoader) of the current class, Foo, and its superclass loader (instance of org/codehaus/groovy/grails/cli/support/GrailsRootLoader), have different Class objects for the type ()Lgroovy/lang/MetaClass; used in the signature

Grails: getAll throwing no signature of method exception?

According to the Grails literature
http://grails.org/doc/2.0.x/ref/Domain%20Classes/getAll.html
I should be able to do this
def biweeklyBatchRanges = BiweeklyBatchRange.getAll()
without getting this
groovy.lang.MissingMethodException: No signature of method: com.myplang.donation.BiweeklyBatchRange.getAll() is applicable for argument types: () values: []
Possible solutions: getAll(), getAt(java.lang.String), getId(), get(java.io.Serializable), getClass(), findAll()
Any ideas? TIA!
Never got an "answer" to this, except to use findAll. (Grails 2.0.3)

Grails session cannot assign java.string

I'm getting this error
Error 500: Executing action [pay] of controller [org.gamestrike.PaymentController] caused exception: groovy.lang.MissingMethodException: No signature of method: org.gamestrike.PaymentController.session() is applicable for argument types: (java.lang.String) values: [2011-09-15] Possible solutions: getSession()
Servlet: grails
URI: /GameStrike/grails/payment/pay.dispatch
Exception Message: No signature of method: org.gamestrike.PaymentController.session() is applicable for argument types: (java.lang.String) values: [2011-09-15] Possible solutions: getSession()
Caused by: No signature of method: org.gamestrike.PaymentController.session() is applicable for argument types: (java.lang.String) values: [2011-09-15] Possible solutions: getSession()
Class: PaymentController
At Line: [35]
Code Snippet:
Without your code it's hard to tell, but it looks like you're treating session like a method, but it's not. It's an object - the HttpSession instance.
You can call the standard methods on it, e.g. getAttribute and setAttribute but Grails adds convenience behavior. It acts like a Map so to set or get attributes you can do this:
def foo = session.foo // session.getAttribute('foo')
session.bar = 123 // session..setAttribute('bar', 123)

Resources