Skip to content

Instantly share code, notes, and snippets.

@aaronzirbes
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aaronzirbes/1e9dffc5459c61eb7839 to your computer and use it in GitHub Desktop.
Save aaronzirbes/1e9dffc5459c61eb7839 to your computer and use it in GitHub Desktop.
package org.zirbes.grails.functional.remote
import grails.util.BuildSettingsHolder
import groovyx.remote.transport.http.HttpTransport
/**
* Adds null safe grails specific convenient no arg constructor.
* https://jira.grails.org/browse/GRAILS-10661
*/
class RemoteControl extends groovyx.remote.client.RemoteControl {
static public final RECEIVER_PATH = 'grails-remote-control'
RemoteControl() {
super(
new HttpTransport(
getNullSafeFunctionalTestReceiverAddress(),
Thread.currentThread().contextClassLoader
),
Thread.currentThread().contextClassLoader
)
}
private static String getNullSafeFunctionalTestReceiverAddress() {
String base = getNullSafeFunctionalTestBaseUrl()
if (!base) {
throw new IllegalStateException('Cannot get receiver address for functional testing as functional test ' +
'base URL is not set. Are you calling this from a functional test?')
}
return base.endsWith('/') ? base + RECEIVER_PATH : base + '/' + RECEIVER_PATH
}
private static String getNullSafeFunctionalTestBaseUrl() {
String base = BuildSettingsHolder.settings?.functionalTestBaseUrl
if (!base || base == 'null') { base = '' }
return base
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment