In a lot of real life implementations of applications we face the requirement to import some kind of (text) files. Usually we would implement some (hardcoded?) logic to validate the file (eg. proper header, proper number of delimiters, proper date/time value,etc.). Eventually also need to check for the existence of related data in a tabl...
I have a controller method like such:
def search = {
def query = params.query
...
render results as JSON
}
How do I unit test this? Specifically, how do I call search to set params.query, and how do I test the results of the method render? Is there a way to mock the render method, perhaps?
...
I want to use some parts of code in different area of bootstrap.groovy. How do I "include" these parts and reuse it?
def init = {
environments {
production {
include("bla.groovy)
include("blaFoo.groovy)
}
test {
include("blaFoo.groovy)
}
development {
...
How can you do a batch insert using groovy Sql while simulating prepared statements? All the examples I've found are similar to the following and don't use prepared statements.
withBatch { stmt ->
stmt.addBatch("insert into table (field1,field2) values('value1','value2')")
stmt.addBatch("insert into table (field1,field2) values('value3...
Hi guys,
I have to implement map values in my Grails app.
I have a class that can contain 0..N OsmTags, and the key is unique.
In Java I would model this with a Map in each object, but I don't know how to map classes in Grails.
So I defined this class:
class OsmTag {
/** OSM tag name, e.g. natural */
String key
/** OSM tag...
I need to call a number of methods in parallel and wait for results. Each relies on different resources, so they may return at different times. I need to wait until I receive all results or time out after a certain amount of time.
I could just spawn threads with a reference to a shared object via a method call, but is there a better, mo...
I am trying to export a standalone RCP app using Eclipse 3.5.2.
The app has a main pure Java plug-in, and a Java / Groovy plug-in that is used by the main plug-in.
When I export the main RCP plug-in using the "Export Wizard", I get compiler errors saying that the Groovy classes cannot be found, e.g
ERROR in C:\mysrc\src\ch\calcs\provi...
Hi,
I recently have a problem using the antbuilder mail task in groovy. It always throws the following exception:
[mail] Sending email: null
[mail] Failed to send email: 0
Caught: : java.lang.ArrayIndexOutOfBoundsException: 0
I think the problem just occurred with the release of the new 1.7.2 version, but I cannot ensure it.
Here is...
In the following Groovy snippet, I attempt to replace both the hashCode and toString methods
String.metaClass.toString = {-> "override" }
String.metaClass.hashCode = {-> 22 }
But when I test it out, only the replacement of hashCode works
String s = "foo"
println s.hashCode() // prints 22
println s.toString() // prints "foo"
Is to...
I am writing a Groovlet and would like to delegate part of the HTML builder to a method but am having trouble getting it to work. Below is what I have:
def pages = [page1: html.p("page1")]
html.html {
p("p")
pages[page1]
}
I am expecting the following output:
<html>
<p>p</p>
<p>page1</p>
</html>
Instead what I get is the fo...
I have two domains :
class CodeSetDetail {
String id
String codeSummaryId
static hasMany = [codes:CodeSummary]
static constraints = {
id(unique:true,blank:false)
}
static mapping = {
version false
id column:'code_set_detail_id', generator: 'assigned'
}
}
and :
class CodeSummary {
String i...
y is it so hard to extract the date from the view via the params in a grails controller?
i don't want to extract the date by hand like this:
instance.dateX = parseDate(params["dateX_value"])//parseDate is from my helper class
i just want to use instance.properties = params you know :)
in the model the type is java.util.Date and in th...
Grails is great. Yet, sometimes, we just need a quick, lightweight web framework. Is there such a thing out there?
...
In Groovy Console I have this:
import groovy.util.*
import org.codehaus.groovy.runtime.*
def gse = new GroovyScriptEngine("c:\\temp")
def script = gse.loadScriptByName("say.groovy")
this.metaClass.mixin script
say("bye")
say.groovy contains
def say(String msg) {
println(msg)
}
Edit: I filed a bug report: https://svn.dentaku.c...
Hi,
I want one folder to be copied from my plugin's base directory (pluginBasedir) to the target project when someone installs my plugin. If I keep that folder within web-app, it gets copied. But I want to keep that folder under base directory.
Do I have to ovverride _GrailsPluginDev.groovy script?
Regards,
Paras
...
Hi,
I'm new to Java and Groovy and am running into trouble with the following Groovy script. I created this whittled down version of a larger script to facilitate debugging.
The script is iterating through a list trying to calc a running total of the values of all objects in the list. Some or all of these objects' values may be null.
...
Hi,
Given an instance of java.util.Date which is a Sunday. If there are 4 Sundays in the month in question, I need to figure out whether the chosen date is
1st Sunday of month
2nd Sunday of month
2nd last Sunday of month
Last Sunday of month
If there are 5 Sundays in the month in question, then I need to figure out whether the chose...
I am trying to take advantage of the convenience of groovy's scripting syntax to assign properties, but having trouble with a specific case. I must be missing something simple here. I define class A, B, C as so:
class A {
A() {
println "Constructed class A!"
}
}
class B {
B() {
println "Constructed class...
I am trying to dynamically display an image that I am storing in the google datastore as a Blob. I am not getting any errors but I am getting a broken image on the page that I view.
Any help would be awesome!
I have the following code in my grails app
domain class has the following
@PrimaryKey
@Persistent(valueStrategy = IdGenerator...
Hello,
I'd like to test a "withCriteria" closure and am not sure how to go about it. I see how to mock out the withCriteria call, but not test the code within the closure. When running the test that executes the "withCriteria", I keep getting a MissingMethodException, even though the code runs fine under the normal flow of execution. Any...