Permalink
Browse files

upgrade Grails app to Grails 2.1.5 and update Betamax usage

  • Loading branch information...
1 parent d362379 commit 3daa739dc751cc44a4362b932dd1e010d67b2678 Rob Fletcher committed Nov 26, 2013
@@ -1,6 +1,6 @@
#Grails Metadata file
#Thu Sep 20 11:13:53 BST 2012
-app.grails.version=2.1.1
+app.grails.version=2.1.5
app.name=grails-betamax
app.servlet.version=3.0
app.version=0.1
@@ -6,23 +6,24 @@ grails.project.dependency.resolution = {
inherits "global"
log "warn"
- def gebVersion = "0.7.2"
- def seleniumVersion = "2.25.0"
+ def gebVersion = "0.9.2"
+ def seleniumVersion = "2.37.1"
repositories {
grailsPlugins()
grailsHome()
grailsCentral()
mavenLocal()
mavenCentral()
- mavenRepo "http://oss.sonatype.org/content/groups/public/"
+ mavenRepo "http://oss.jfrog.org/oss-snapshot-local/"
}
dependencies {
- compile("org.codehaus.groovy.modules.http-builder:http-builder:0.5.1") {
+ compile("org.codehaus.groovy.modules.http-builder:http-builder:0.6") {
excludes "groovy", "xml-apis"
}
- test 'co.freeside:betamax-proxy:1.2-SNAPSHOT'
- test "org.codehaus.geb:geb-spock:$gebVersion"
+ test "co.freeside.betamax:betamax-proxy:2.0-SNAPSHOT"
+ test "co.freeside.betamax:betamax-junit:2.0-SNAPSHOT"
+ test "org.gebish:geb-spock:$gebVersion"
test("org.seleniumhq.selenium:selenium-htmlunit-driver:$seleniumVersion") {
exclude "xml-apis"
}
@@ -51,5 +51,8 @@ class TwitterService {
}
-@InheritConstructors
-class TwitterException extends RuntimeException {}
+class TwitterException extends RuntimeException {
+ TwitterException(String message) {
+ super(message)
+ }
+}
@@ -1,58 +1,61 @@
package betamax.examples
-import co.freeside.betamax.*
-import co.freeside.betamax.httpclient.BetamaxRoutePlanner
+import co.freeside.betamax.ProxyConfiguration
+import co.freeside.betamax.junit.*
import com.gargoylesoftware.htmlunit.ProxyConfig
import geb.spock.GebSpec
import grails.util.BuildSettingsHolder
+import org.apache.http.HttpHost
import org.codehaus.groovy.grails.commons.ApplicationHolder
import org.junit.Rule
import org.openqa.selenium.htmlunit.HtmlUnitDriver
-import static co.freeside.betamax.TapeMode.READ_ONLY
+import spock.lang.Shared
+import static org.apache.http.conn.params.ConnRoutePNames.DEFAULT_PROXY
class TwitterPageSpec extends GebSpec {
- File baseDir = BuildSettingsHolder.settings?.baseDir ?: new File('examples/grails-betamax')
- @Rule Recorder recorder = new ProxyRecorder(tapeRoot: new File(baseDir, 'test/resources/tapes'), ignoreLocalhost: true, defaultMode: READ_ONLY)
-
- void setupSpec() {
- def restClient = ApplicationHolder.application.mainContext.restClient
- BetamaxRoutePlanner.configure(restClient.client)
- }
-
- void setup() {
- browser.baseUrl = 'http://localhost:8080/grails-betamax/'
- HtmlUnitDriver driver = browser.driver
- def proxyConfig = new ProxyConfig('localhost', 5555)
- proxyConfig.addHostsToProxyBypass('localhost')
- driver.webClient.proxyConfig = proxyConfig
- //driver.setJavascriptEnabled(true) //not work. see http://groups.google.com/group/webdriver/browse_thread/thread/6bbb18dca79c4e92?pli=1
- }
-
- @Betamax(tape = 'twitter success')
- void 'displays list of tweets based on query'() {
- given:
- go 'twitter'
-
- expect:
- title == 'Twitter Search Results'
-
- and:
- $('#tweets li').size() == 10
- $('#tweets li p')*.text().every { it =~ /(?i)#gr8conf/ }
- $('#tweets li').eq(0).find('p').text() == 'Slides for my #gr8conf talk: \u2018Spock Soup to Nuts\u2019. Thanks to everyone who showed up! http://t.co/CNA9ertp'
- }
-
- @Betamax(tape = 'twitter success')
- void 'can follow a link to a twitter user'() {
- given:
- go 'twitter'
-
- when:
- $('#tweets li').eq(0).find('small a').click()
-
- then:
- $('.user-info .username').text() == '@zanthrash'
- }
+ File baseDir = BuildSettingsHolder.settings?.baseDir ?: new File('examples/grails-betamax')
+ @Shared def configuration = ProxyConfiguration.builder().tapeRoot(new File(baseDir, 'test/resources/tapes')).ignoreLocalhost(true)
+ @Rule RecorderRule recorder = new RecorderRule(configuration)
+
+ void setupSpec() {
+ def restClient = ApplicationHolder.application.mainContext.restClient
+ restClient.client.params.setParameter(DEFAULT_PROXY, new HttpHost(configuration.proxyHost, configuration.proxyPort, "http"))
+ }
+
+ void setup() {
+ browser.baseUrl = 'http://localhost:8080/grails-betamax/'
+ HtmlUnitDriver driver = browser.driver
+ def proxyConfig = new ProxyConfig('localhost', 5555)
+ proxyConfig.addHostsToProxyBypass('localhost')
+ driver.webClient.proxyConfig = proxyConfig
+ //driver.setJavascriptEnabled(true) //not work. see http://groups.google.com/group/webdriver/browse_thread/thread/6bbb18dca79c4e92?pli=1
+ }
+
+ @Betamax(tape = 'twitter success')
+ void 'displays list of tweets based on query'() {
+ given:
+ go 'twitter'
+
+ expect:
+ title == 'Twitter Search Results'
+
+ and:
+ $('#tweets li').size() == 10
+ $('#tweets li p')*.text().every { it=~/(?i)#gr8conf/ }
+ $('#tweets li').eq(0).find('p').text() == 'Slides for my #gr8conf talk: \u2018Spock Soup to Nuts\u2019. Thanks to everyone who showed up! http://t.co/CNA9ertp'
+ }
+
+ @Betamax(tape = 'twitter success')
+ void 'can follow a link to a twitter user'() {
+ given:
+ go 'twitter'
+
+ when:
+ $('#tweets li').eq(0).find('small a').click()
+
+ then:
+ $('.user-info .username').text() == '@zanthrash'
+ }
}
@@ -1,65 +1,67 @@
package betamax.examples
import java.util.logging.*
-import co.freeside.betamax.*
-import co.freeside.betamax.httpclient.BetamaxRoutePlanner
+import co.freeside.betamax.ProxyConfiguration
+import co.freeside.betamax.junit.*
import grails.test.mixin.TestFor
import grails.util.BuildSettingsHolder
import groovyx.net.http.RESTClient
+import org.apache.http.HttpHost
import org.junit.Rule
import spock.lang.Specification
-import static co.freeside.betamax.TapeMode.READ_ONLY
+import static org.apache.http.conn.params.ConnRoutePNames.DEFAULT_PROXY
@TestFor(TwitterService)
class TwitterServiceSpec extends Specification {
- File baseDir = BuildSettingsHolder.settings?.baseDir ?: new File('examples/grails-betamax')
- @Rule Recorder recorder = new ProxyRecorder(tapeRoot: new File(baseDir, 'test/resources/tapes'), defaultMode: READ_ONLY)
+ File baseDir = BuildSettingsHolder.settings?.baseDir ?: new File('examples/grails-betamax')
+ def configuration = ProxyConfiguration.builder().tapeRoot(new File(baseDir, 'test/resources/tapes')).build()
+ @Rule RecorderRule recorder = new RecorderRule(configuration)
- TwitterService service = new TwitterService()
+ TwitterService service = new TwitterService()
- void setupSpec() {
- def log = Logger.getLogger('betamax')
- log.addHandler(new ConsoleHandler())
- }
+ void setupSpec() {
+ def log = Logger.getLogger('betamax')
+ log.addHandler(new ConsoleHandler())
+ }
- void setup() {
- def restClient = new RESTClient()
- BetamaxRoutePlanner.configure(restClient.client)
- service.restClient = restClient
- }
+ void setup() {
+ def restClient = new RESTClient()
+ restClient.client.params.setParameter(DEFAULT_PROXY, new HttpHost(configuration.proxyHost, configuration.proxyPort, "http"))
+ service.restClient = restClient
+ }
- @Betamax(tape = 'twitter success')
- void 'returns aggregated twitter client stats when a successful response is received'() {
- when:
- def clients = service.tweetsByClient('#gr8conf')
+ @Betamax(tape = 'twitter success')
+ void 'returns aggregated twitter client stats when a successful response is received'() {
+ when:
+ def clients = service.tweetsByClient('#gr8conf')
- then:
- clients.size() == 6
- clients['Twitterrific'] == 1
- clients['Echofon'] == 1
- clients['Tweetbot for Mac'] == 1
- clients['Twitter for Mac'] == 5
- clients['Twitter for iPhone'] == 1
- clients['Twitter for Android'] == 1
- }
+ then:
+ clients.size() == 6
+ clients['Twitterrific'] == 1
+ clients['Echofon'] == 1
+ clients['Tweetbot for Mac'] == 1
+ clients['Twitter for Mac'] == 5
+ clients['Twitter for iPhone'] == 1
+ clients['Twitter for Android'] == 1
+ }
- @Betamax(tape = 'twitter success')
- void 'only retrieves tweets containing the search term'() {
- when:
- def tweets = service.tweets('#gr8conf')
+ @Betamax(tape = 'twitter success')
+ void 'only retrieves tweets containing the search term'() {
+ when:
+ def tweets = service.tweets('#gr8conf')
- then:
- tweets.size() == 10
- tweets.every { it.text =~ /(?i)#gr8conf/ }
- }
+ then:
+ tweets.size() == 10
+ tweets.every { it.text=~/(?i)#gr8conf/ }
+ }
- @Betamax(tape = 'twitter rate limit')
- void 'sets an error status when twitter rate limit is exceeded'() {
- when:
- service.tweetsByClient('#gr8conf')
+ @Betamax(tape = 'twitter rate limit')
+ void 'sets an error status when twitter rate limit is exceeded'() {
+ when:
+ service.tweetsByClient('#gr8conf')
- then:
- thrown TwitterException
- }
+ then:
+ thrown TwitterException
+ }
}

0 comments on commit 3daa739

Please sign in to comment.