Skip to content

Instantly share code, notes, and snippets.

@jurberg
jurberg / expose-jmx.groovy
Created October 30, 2012 02:38
Exposing a few methods using the Grails JMX plugin
class MyService {
static expose = ['jmx']
static jmxmethods = ['getTimeout', 'setTimeout']
static jmxexpose = ['excludeMethods':
MyService.metaClass.methods*.name.findAll{
!jmxmethods.contains(it)
}.join(',')]
int timeout
@jurberg
jurberg / CleanTestApp.groovy
Created October 18, 2012 00:46
Grails clean-test-app script
includeTargets << grailsScript("_GrailsClean")
includeTargets << grailsScript("RefreshDependencies")
includeTargets << grailsScript("TestApp")
target(cleanTestApp: "Clean, refresh dependencies, then test app") {
depends(cleanAll, refreshDependencies, 'default')
}
setDefaultTarget("cleanTestApp")
@TestFor(MyController)
@TestMixin(OneTimeDataUnitTestMixin)
class MyControllerSpec extends Specification {
def setup() {
mockOneTimeData(this, controller)
}
def "should fail"() {
given:
class OneTimeDataUnitTestMixin extends GrailsUnitTestMixin {
def mockOneTimeData(spec, controller) {
spec.metaClass.otdData = [:]
spec.metaClass.otdId = 1
controller.metaClass.oneTimeData << { Closure dataSetup ->
dataSetup.delegate = spec.otdData
dataSetup()
spec.otdId
}