Browse files

Merge branch 'master' of github.com:robfletcher/betamax into httpclient

Conflicts:
	src/main/groovy/co/freeside/betamax/proxy/jetty/BetamaxProxy.groovy
  • Loading branch information...
2 parents 5238fad + 76e2e14 commit 8cf3fd9c785c09651277b696fbf3d1d9bb313c74 Rob Fletcher committed Oct 1, 2012
Showing with 181 additions and 153 deletions.
  1. +1 −1 examples/grails-betamax/grails-app/conf/BetamaxConfig.groovy
  2. +16 −16 examples/grails-betamax/test/functional/betamax/examples/TwitterPageSpec.groovy
  3. +11 −12 examples/grails-betamax/test/unit/betamax/examples/TwitterControllerSpec.groovy
  4. +22 −23 examples/grails-betamax/test/unit/betamax/examples/TwitterServiceSpec.groovy
  5. +4 −0 src/docs/index.md
  6. +4 −6 src/main/groovy/co/freeside/betamax/handler/TapeReader.groovy
  7. +4 −6 src/main/groovy/co/freeside/betamax/handler/TapeWriter.groovy
  8. +4 −5 src/main/groovy/co/freeside/betamax/proxy/jetty/BetamaxProxy.groovy
  9. +5 −9 src/main/groovy/co/freeside/betamax/tape/MemoryTape.groovy
  10. +6 −8 src/test/groovy/co/freeside/betamax/AnnotationSpec.groovy
  11. +3 −3 src/test/groovy/co/freeside/betamax/AnnotationTest.groovy
  12. +44 −0 src/test/groovy/co/freeside/betamax/LocalhostSpec.groovy
  13. +2 −1 src/test/groovy/co/freeside/betamax/proxy/HttpsSpec.groovy
  14. +3 −4 src/test/groovy/co/freeside/betamax/proxy/IgnoreHostsSpec.groovy
  15. +3 −4 src/test/groovy/co/freeside/betamax/proxy/PreExistingProxySpec.groovy
  16. +5 −8 src/test/groovy/co/freeside/betamax/proxy/ProxyNetworkCommsSpec.groovy
  17. +3 −4 src/test/groovy/co/freeside/betamax/proxy/ProxyRecordAndPlaybackSpec.groovy
  18. +5 −10 src/test/groovy/co/freeside/betamax/proxy/ProxyTimeoutSpec.groovy
  19. +1 −1 src/test/groovy/co/freeside/betamax/proxy/jetty/BetamaxProxySpec.groovy
  20. +2 −2 src/test/groovy/co/freeside/betamax/recorder/RequestMatchingSpec.groovy
  21. +7 −13 src/test/groovy/co/freeside/betamax/recorder/TapeModeSpec.groovy
  22. +3 −5 src/test/groovy/co/freeside/betamax/tape/FilenameNormalizationSpec.groovy
  23. +2 −1 src/test/groovy/co/freeside/betamax/tape/MultiThreadedTapeWritingSpec.groovy
  24. +3 −6 src/test/groovy/co/freeside/betamax/tape/PostBodySpec.groovy
  25. +3 −5 src/test/groovy/co/freeside/betamax/tape/YamlTapeLoaderSpec.groovy
  26. +15 −0 src/test/groovy/co/freeside/betamax/util/FileUtils.groovy
View
2 examples/grails-betamax/grails-app/conf/BetamaxConfig.groovy
@@ -1,4 +1,4 @@
betamax {
- tapeRoot = new File("test/resources/tapes")
+ tapeRoot = new File('test/resources/tapes')
ignoreLocalhost = true
}
View
32 examples/grails-betamax/test/functional/betamax/examples/TwitterPageSpec.groovy
@@ -12,47 +12,47 @@ import org.openqa.selenium.htmlunit.HtmlUnitDriver
class TwitterPageSpec extends GebSpec {
- File baseDir = BuildSettingsHolder.settings?.baseDir ?: new File("examples/grails-betamax")
- @Rule Recorder recorder = new Recorder(tapeRoot: new File(baseDir, "test/resources/tapes"), ignoreLocalhost: true)
+ File baseDir = BuildSettingsHolder.settings?.baseDir ?: new File('examples/grails-betamax')
+ @Rule Recorder recorder = new Recorder(tapeRoot: new File(baseDir, 'test/resources/tapes'), ignoreLocalhost: true)
- def setupSpec() {
+ void setupSpec() {
def restClient = ApplicationHolder.application.mainContext.restClient
BetamaxRoutePlanner.configure(restClient.client)
}
- def setup() {
- browser.baseUrl = "http://localhost:8080/grails-betamax/"
+ void setup() {
+ browser.baseUrl = 'http://localhost:8080/grails-betamax/'
HtmlUnitDriver driver = browser.driver
- def proxyConfig = new ProxyConfig("localhost", 5555)
- proxyConfig.addHostsToProxyBypass("localhost")
+ 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")
- def "displays list of tweets based on query"() {
+ @Betamax(tape = 'twitter success')
+ void 'displays list of tweets based on query'() {
given:
- go "twitter"
+ go 'twitter'
expect:
- title == "Twitter Search Results"
+ 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"
+ $('#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")
- def "can follow a link to a twitter user"() {
+ @Betamax(tape = 'twitter success')
+ void 'can follow a link to a twitter user'() {
given:
- go "twitter"
+ go 'twitter'
when:
$('#tweets li').eq(0).find('small a').click()
then:
- $('.user-info .username').text() == "@zanthrash"
+ $('.user-info .username').text() == '@zanthrash'
}
}
View
23 examples/grails-betamax/test/unit/betamax/examples/TwitterControllerSpec.groovy
@@ -2,42 +2,41 @@ package betamax.examples
import grails.test.mixin.TestFor
import spock.lang.Specification
-
import static javax.servlet.http.HttpServletResponse.SC_SERVICE_UNAVAILABLE
@TestFor(TwitterController)
class TwitterControllerSpec extends Specification {
TwitterService twitterService = Mock(TwitterService)
- def setup() {
+ void setup() {
controller.twitterService = twitterService
}
-
- def "default query is '#gr8conf'"() {
+
+ void 'default query is "#gr8conf"'() {
when:
controller.clients()
then:
- 1 * twitterService.tweetsByClient("#gr8conf")
+ 1 * twitterService.tweetsByClient('#gr8conf')
}
-
- def "passes query and results to view"() {
+
+ void 'passes query and results to view'() {
given:
def results = [web: 2, iPhone: 4, android: 1]
- twitterService.tweetsByClient("#gr8conf") >> results
+ twitterService.tweetsByClient('#gr8conf') >> results
when:
def model = controller.clients()
then:
- model.q == "#gr8conf"
+ model.q == '#gr8conf'
model.clients == results
}
-
- def "handles twitter error"() {
+
+ void 'handles twitter error'() {
given:
- twitterService.tweetsByClient("#gr8conf") >> { throw new TwitterException('Fail Whale!') }
+ twitterService.tweetsByClient('#gr8conf') >> { throw new TwitterException('Fail Whale!') }
when:
controller.clients()
View
45 examples/grails-betamax/test/unit/betamax/examples/TwitterServiceSpec.groovy
@@ -1,5 +1,7 @@
package betamax.examples
+import java.util.logging.ConsoleHandler
+import java.util.logging.Logger
import co.freeside.betamax.Betamax
import co.freeside.betamax.Recorder
import co.freeside.betamax.httpclient.BetamaxRoutePlanner
@@ -9,57 +11,54 @@ import groovyx.net.http.RESTClient
import org.junit.Rule
import spock.lang.Specification
-import java.util.logging.ConsoleHandler
-import java.util.logging.Logger
-
@TestFor(TwitterService)
class TwitterServiceSpec extends Specification {
- File baseDir = BuildSettingsHolder.settings?.baseDir ?: new File("examples/grails-betamax")
- @Rule Recorder recorder = new Recorder(tapeRoot: new File(baseDir, "test/resources/tapes"))
+ File baseDir = BuildSettingsHolder.settings?.baseDir ?: new File('examples/grails-betamax')
+ @Rule Recorder recorder = new Recorder(tapeRoot: new File(baseDir, 'test/resources/tapes'))
TwitterService service = new TwitterService()
- def setupSpec() {
- def log = Logger.getLogger("betamax")
+ void setupSpec() {
+ def log = Logger.getLogger('betamax')
log.addHandler(new ConsoleHandler())
}
- def setup() {
+ void setup() {
def restClient = new RESTClient()
BetamaxRoutePlanner.configure(restClient.client)
service.restClient = restClient
}
- @Betamax(tape = "twitter success")
- def "returns aggregated twitter client stats when a successful response is received"() {
+ @Betamax(tape = 'twitter success')
+ void 'returns aggregated twitter client stats when a successful response is received'() {
when:
- def clients = service.tweetsByClient("#gr8conf")
+ 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
+ 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")
- def "only retrieves tweets containing the search term"() {
+ @Betamax(tape = 'twitter success')
+ void 'only retrieves tweets containing the search term'() {
when:
- def tweets = service.tweets("#gr8conf")
+ def tweets = service.tweets('#gr8conf')
then:
tweets.size() == 10
tweets.every { it.text =~ /(?i)#gr8conf/ }
}
- @Betamax(tape = "twitter rate limit")
- def "sets an error status when twitter rate limit is exceeded"() {
+ @Betamax(tape = 'twitter rate limit')
+ void 'sets an error status when twitter rate limit is exceeded'() {
when:
- service.tweetsByClient("#gr8conf")
+ service.tweetsByClient('#gr8conf')
then:
thrown TwitterException
View
4 src/docs/index.md
@@ -198,6 +198,10 @@ Tape files are stored as _YAML_ so that they should be reasonably easy to edit b
## Proxy compatibility
+### Java 6
+
+Under Java 6 it is not possible to proxy connections to URLs whose host is `localhost` or `127.0.0.1`. The workaround is to use the hostname or public IP address of the machine instead. This is a [known issue](http://bugs.sun.com/view_bug.do?bug_id=6737819) that is fixed in Java 7.
+
### Apache HttpClient
By default [Apache _HttpClient_][httpclient] takes no notice of Java's HTTP proxy settings. The Betamax proxy can only intercept traffic from HttpClient if the client instance is set up to use a [`ProxySelectorRoutePlanner`][proxyselector]. When Betamax is not active this will mean HttpClient traffic will be routed via the default proxy configured in Java (if any).
View
10 src/main/groovy/co/freeside/betamax/handler/TapeReader.groovy
@@ -1,11 +1,9 @@
package co.freeside.betamax.handler
-import co.freeside.betamax.Recorder
-import co.freeside.betamax.message.Request
-import co.freeside.betamax.message.Response
-
import java.util.logging.Logger
-
+import co.freeside.betamax.Recorder
+import co.freeside.betamax.message.*
+import static co.freeside.betamax.proxy.jetty.BetamaxProxy.X_BETAMAX
import static java.net.HttpURLConnection.HTTP_FORBIDDEN
import static java.util.logging.Level.INFO
/**
@@ -29,7 +27,7 @@ class TapeReader extends ChainedHttpHandler {
} else if (tape.readable && tape.seek(request)) {
log.log INFO, "Playing back from '$tape.name'"
def response = tape.play(request)
- response.addHeader('X-Betamax', 'PLAY')
+ response.addHeader(X_BETAMAX, 'PLAY')
response
} else if (tape.writable) {
chain(request)
View
10 src/main/groovy/co/freeside/betamax/handler/TapeWriter.groovy
@@ -1,11 +1,9 @@
package co.freeside.betamax.handler
-import co.freeside.betamax.Recorder
-import co.freeside.betamax.message.Request
-import co.freeside.betamax.message.Response
-
import java.util.logging.Logger
-
+import co.freeside.betamax.Recorder
+import co.freeside.betamax.message.*
+import static co.freeside.betamax.proxy.jetty.BetamaxProxy.X_BETAMAX
import static java.net.HttpURLConnection.HTTP_FORBIDDEN
import static java.util.logging.Level.INFO
@@ -31,7 +29,7 @@ class TapeWriter extends ChainedHttpHandler {
log.log INFO, "Recording to '$tape.name'"
tape.record(request, response)
- response.addHeader('X-Betamax', 'REC')
+ response.addHeader(X_BETAMAX, 'REC')
response
}
View
9 src/main/groovy/co/freeside/betamax/proxy/jetty/BetamaxProxy.groovy
@@ -1,22 +1,21 @@
package co.freeside.betamax.proxy.jetty
+import java.util.logging.Logger
+import javax.servlet.http.*
import co.freeside.betamax.message.Response
import co.freeside.betamax.message.servlet.ServletRequestAdapter
import co.freeside.betamax.handler.HttpHandler
import co.freeside.betamax.handler.HandlerException
+import co.freeside.betamax.proxy.handler.*
import org.eclipse.jetty.server.Request
import org.eclipse.jetty.server.handler.AbstractHandler
-
-import javax.servlet.http.HttpServletRequest
-import javax.servlet.http.HttpServletResponse
-import java.util.logging.Logger
-
import static java.net.HttpURLConnection.HTTP_INTERNAL_ERROR
import static java.util.logging.Level.SEVERE
import static org.apache.http.HttpHeaders.VIA
class BetamaxProxy extends AbstractHandler {
+ public static final String X_BETAMAX = 'X-Betamax'
public static final String VIA_HEADER = 'Betamax'
private HttpHandler handlerChain
View
14 src/main/groovy/co/freeside/betamax/tape/MemoryTape.groovy
@@ -17,17 +17,13 @@
package co.freeside.betamax.tape
import co.freeside.betamax.TapeMode
-import co.freeside.betamax.message.Request
-import co.freeside.betamax.message.Response
-import co.freeside.betamax.message.tape.RecordedRequest
-import co.freeside.betamax.message.tape.RecordedResponse
+import co.freeside.betamax.message.*
+import co.freeside.betamax.message.tape.*
import org.yaml.snakeyaml.reader.StreamReader
-
import static TapeMode.READ_WRITE
-import static co.freeside.betamax.MatchRule.method
-import static co.freeside.betamax.MatchRule.uri
+import static co.freeside.betamax.MatchRule.*
+import static co.freeside.betamax.proxy.jetty.BetamaxProxy.X_BETAMAX
import static org.apache.http.HttpHeaders.VIA
-
/**
* Represents a set of recorded HTTP interactions that can be played back or appended to.
*/
@@ -124,7 +120,7 @@ class MemoryTape implements Tape {
def clone = new RecordedResponse()
clone.status = response.status
response.headers.each {
- if (!(it.key in [VIA, 'X-Betamax'])) {
+ if (!(it.key in [VIA, X_BETAMAX])) {
clone.headers[it.key] = it.value
}
}
View
14 src/test/groovy/co/freeside/betamax/AnnotationSpec.groovy
@@ -5,18 +5,16 @@ import co.freeside.betamax.proxy.jetty.SimpleServer
import co.freeside.betamax.util.server.EchoHandler
import groovyx.net.http.RESTClient
import org.junit.Rule
-import spock.lang.AutoCleanup
-import spock.lang.Shared
-import spock.lang.Specification
-import spock.lang.Stepwise
-
+import spock.lang.*
+import static co.freeside.betamax.proxy.jetty.BetamaxProxy.X_BETAMAX
+import static co.freeside.betamax.util.FileUtils.newTempDir
import static java.net.HttpURLConnection.HTTP_OK
import static org.apache.http.HttpHeaders.VIA
@Stepwise
class AnnotationSpec extends Specification {
- @Shared @AutoCleanup('deleteDir') File tapeRoot = new File(System.properties.'java.io.tmpdir', 'tapes')
+ @Shared @AutoCleanup('deleteDir') File tapeRoot = newTempDir('tapes')
@Rule Recorder recorder = new Recorder(tapeRoot: tapeRoot)
@AutoCleanup('stop') SimpleServer endpoint = new SimpleServer()
RESTClient http
@@ -53,7 +51,7 @@ class AnnotationSpec extends Specification {
then:
response.status == HTTP_OK
response.getFirstHeader(VIA)?.value == 'Betamax'
- response.getFirstHeader('X-Betamax')?.value == 'REC'
+ response.getFirstHeader(X_BETAMAX)?.value == 'REC'
}
@Betamax(tape = 'annotation_spec')
@@ -64,7 +62,7 @@ class AnnotationSpec extends Specification {
then:
response.status == HTTP_OK
response.getFirstHeader(VIA)?.value == 'Betamax'
- response.getFirstHeader('X-Betamax')?.value == 'PLAY'
+ response.getFirstHeader(X_BETAMAX)?.value == 'PLAY'
}
void 'can make unproxied request after using annotation'() {
View
6 src/test/groovy/co/freeside/betamax/AnnotationTest.groovy
@@ -5,7 +5,7 @@ import co.freeside.betamax.proxy.jetty.SimpleServer
import co.freeside.betamax.util.server.EchoHandler
import groovyx.net.http.RESTClient
import org.junit.*
-
+import static co.freeside.betamax.proxy.jetty.BetamaxProxy.X_BETAMAX
import static java.net.HttpURLConnection.HTTP_OK
import static org.apache.http.HttpHeaders.VIA
@@ -57,7 +57,7 @@ class AnnotationTest {
assert response.status == HTTP_OK
assert response.getFirstHeader(VIA)?.value == 'Betamax'
- assert response.getFirstHeader('X-Betamax')?.value == 'REC'
+ assert response.getFirstHeader(X_BETAMAX)?.value == 'REC'
}
@Test
@@ -67,7 +67,7 @@ class AnnotationTest {
assert response.status == HTTP_OK
assert response.getFirstHeader(VIA)?.value == 'Betamax'
- assert response.getFirstHeader('X-Betamax')?.value == 'PLAY'
+ assert response.getFirstHeader(X_BETAMAX)?.value == 'PLAY'
}
@Test
View
44 src/test/groovy/co/freeside/betamax/LocalhostSpec.groovy
@@ -0,0 +1,44 @@
+package co.freeside.betamax
+
+import co.freeside.betamax.httpclient.BetamaxRoutePlanner
+import co.freeside.betamax.proxy.jetty.SimpleServer
+import co.freeside.betamax.util.server.EchoHandler
+import groovyx.net.http.*
+import org.junit.Rule
+import spock.lang.*
+import static co.freeside.betamax.TapeMode.WRITE_ONLY
+import static co.freeside.betamax.util.FileUtils.newTempDir
+import static java.net.HttpURLConnection.HTTP_OK
+import static org.apache.http.HttpHeaders.VIA
+
+@Issue('https://github.com/robfletcher/betamax/issues/62')
+@Issue('http://bugs.sun.com/view_bug.do?bug_id=6737819')
+@Unroll
+class LocalhostSpec extends Specification {
+
+ @Shared @AutoCleanup('deleteDir') File tapeRoot = newTempDir('tapes')
+ @Rule Recorder recorder = new Recorder(tapeRoot: tapeRoot)
+
+ @Shared @AutoCleanup('stop') SimpleServer endpoint = new SimpleServer()
+
+ @Shared RESTClient http = new RESTClient()
+
+ void setupSpec() {
+ BetamaxRoutePlanner.configure(http.client)
+ endpoint.start(EchoHandler)
+ }
+
+ @Betamax(tape = 'localhost', mode = WRITE_ONLY)
+ void 'can proxy requests to local endpoint at #uri'() {
+ when:
+ HttpResponseDecorator response = http.get(uri: uri)
+
+ then:
+ response.status == HTTP_OK
+ response.getFirstHeader(VIA)?.value == 'Betamax'
+
+ where:
+ uri << [endpoint.url, "http://localhost:$endpoint.port/", "http://127.0.0.1:$endpoint.port/"]
+ }
+
+}
View
3 src/test/groovy/co/freeside/betamax/proxy/HttpsSpec.groovy
@@ -9,14 +9,15 @@ import org.apache.http.client.methods.HttpGet
import org.apache.http.impl.client.DefaultHttpClient
import org.junit.Rule
import spock.lang.*
+import static co.freeside.betamax.util.FileUtils.newTempDir
import static org.apache.http.HttpHeaders.VIA
import static org.apache.http.HttpStatus.SC_OK
@Issue('https://github.com/robfletcher/betamax/issues/34')
@Unroll
class HttpsSpec extends Specification {
- @Shared @AutoCleanup('deleteDir') File tapeRoot = new File(System.properties.'java.io.tmpdir', 'tapes')
+ @Shared @AutoCleanup('deleteDir') File tapeRoot = newTempDir('tapes')
@Rule @AutoCleanup('ejectTape') Recorder recorder = new Recorder(tapeRoot: tapeRoot, sslSupport: true)
@Shared @AutoCleanup('stop') SimpleServer httpsEndpoint = new SimpleSecureServer(5001)
@Shared @AutoCleanup('stop') SimpleServer httpEndpoint = new SimpleServer()
View
7 src/test/groovy/co/freeside/betamax/proxy/IgnoreHostsSpec.groovy
@@ -2,19 +2,18 @@ package co.freeside.betamax.proxy
import co.freeside.betamax.Recorder
import co.freeside.betamax.httpclient.BetamaxRoutePlanner
-import co.freeside.betamax.proxy.jetty.ProxyServer
-import co.freeside.betamax.proxy.jetty.SimpleServer
+import co.freeside.betamax.proxy.jetty.*
import co.freeside.betamax.util.server.EchoHandler
import groovyx.net.http.RESTClient
import spock.lang.*
-
+import static co.freeside.betamax.util.FileUtils.newTempDir
import static org.apache.http.HttpHeaders.VIA
@Issue('https://github.com/robfletcher/betamax/issues/16')
@Unroll
class IgnoreHostsSpec extends Specification {
- @Shared @AutoCleanup('deleteDir') File tapeRoot = new File(System.properties.'java.io.tmpdir', 'tapes')
+ @Shared @AutoCleanup('deleteDir') File tapeRoot = newTempDir('tapes')
@Shared @AutoCleanup('stop') SimpleServer endpoint = new SimpleServer()
@AutoCleanup('ejectTape') Recorder recorder = new Recorder(tapeRoot: tapeRoot)
@AutoCleanup('stop') ProxyServer proxy = new ProxyServer(recorder)
View
7 src/test/groovy/co/freeside/betamax/proxy/PreExistingProxySpec.groovy
@@ -1,20 +1,19 @@
package co.freeside.betamax.proxy
-import co.freeside.betamax.Betamax
-import co.freeside.betamax.Recorder
+import co.freeside.betamax.*
import co.freeside.betamax.proxy.jetty.SimpleServer
import co.freeside.betamax.util.server.HelloHandler
import org.junit.Rule
import spock.lang.*
-
+import static co.freeside.betamax.util.FileUtils.newTempDir
import static co.freeside.betamax.util.server.HelloHandler.HELLO_WORLD
import static java.net.HttpURLConnection.HTTP_OK
import static org.apache.http.HttpHeaders.VIA
@Issue('https://github.com/robfletcher/betamax/issues/54')
class PreExistingProxySpec extends Specification {
- @AutoCleanup('deleteDir') File tapeRoot = new File(System.properties.'java.io.tmpdir', 'tapes')
+ @AutoCleanup('deleteDir') File tapeRoot = newTempDir('tapes')
@Rule Recorder recorder = new Recorder(tapeRoot: tapeRoot)
@Shared @AutoCleanup('stop') SimpleServer proxyServer = new SimpleServer()
View
13 src/test/groovy/co/freeside/betamax/proxy/ProxyNetworkCommsSpec.groovy
@@ -1,27 +1,24 @@
package co.freeside.betamax.proxy
-import co.freeside.betamax.Betamax
-import co.freeside.betamax.Recorder
+import co.freeside.betamax.*
import co.freeside.betamax.httpclient.BetamaxRoutePlanner
import co.freeside.betamax.proxy.jetty.SimpleServer
import co.freeside.betamax.util.server.EchoHandler
-import groovyx.net.http.HttpURLClient
-import groovyx.net.http.RESTClient
-import org.apache.commons.httpclient.HttpClient
-import org.apache.commons.httpclient.ProxyHost
+import groovyx.net.http.*
+import org.apache.commons.httpclient.*
import org.apache.commons.httpclient.methods.GetMethod
import org.apache.http.HttpHost
import org.junit.Rule
import spock.lang.*
-
+import static co.freeside.betamax.util.FileUtils.newTempDir
import static java.net.HttpURLConnection.HTTP_OK
import static org.apache.http.HttpHeaders.VIA
import static org.apache.http.conn.params.ConnRoutePNames.DEFAULT_PROXY
@Unroll
class ProxyNetworkCommsSpec extends Specification {
- @AutoCleanup('deleteDir') File tapeRoot = new File(System.properties.'java.io.tmpdir', 'tapes')
+ @AutoCleanup('deleteDir') File tapeRoot = newTempDir('tapes')
@Rule Recorder recorder = new Recorder(tapeRoot: tapeRoot)
@Shared @AutoCleanup('stop') SimpleServer endpoint = new SimpleServer()
View
7 src/test/groovy/co/freeside/betamax/proxy/ProxyRecordAndPlaybackSpec.groovy
@@ -2,19 +2,18 @@ package co.freeside.betamax.proxy
import co.freeside.betamax.Recorder
import co.freeside.betamax.httpclient.BetamaxRoutePlanner
-import co.freeside.betamax.proxy.jetty.ProxyServer
-import co.freeside.betamax.proxy.jetty.SimpleServer
+import co.freeside.betamax.proxy.jetty.*
import co.freeside.betamax.util.server.EchoHandler
import groovyx.net.http.RESTClient
import org.yaml.snakeyaml.Yaml
import spock.lang.*
-
+import static co.freeside.betamax.util.FileUtils.newTempDir
import static java.net.HttpURLConnection.HTTP_OK
@Stepwise
class ProxyRecordAndPlaybackSpec extends Specification {
- @Shared @AutoCleanup('deleteDir') File tapeRoot = new File(System.properties.'java.io.tmpdir', 'tapes')
+ @Shared @AutoCleanup('deleteDir') File tapeRoot = newTempDir('tapes')
@Shared @AutoCleanup('ejectTape') Recorder recorder = new Recorder(tapeRoot: tapeRoot)
@Shared @AutoCleanup('stop') ProxyServer proxy = new ProxyServer(recorder)
@AutoCleanup('stop') SimpleServer endpoint = new SimpleServer()
View
15 src/test/groovy/co/freeside/betamax/proxy/ProxyTimeoutSpec.groovy
@@ -1,27 +1,22 @@
package co.freeside.betamax.proxy
-import co.freeside.betamax.Betamax
-import co.freeside.betamax.Recorder
+import co.freeside.betamax.*
import co.freeside.betamax.httpclient.BetamaxRoutePlanner
import co.freeside.betamax.proxy.jetty.SimpleServer
import co.freeside.betamax.util.server.SlowHandler
-import groovyx.net.http.HttpResponseException
-import groovyx.net.http.RESTClient
+import groovyx.net.http.*
import org.apache.http.impl.client.DefaultHttpRequestRetryHandler
import org.junit.Rule
-import spock.lang.AutoCleanup
-import spock.lang.Issue
-import spock.lang.Shared
-import spock.lang.Specification
-
+import spock.lang.*
+import static co.freeside.betamax.util.FileUtils.newTempDir
import static java.net.HttpURLConnection.HTTP_GATEWAY_TIMEOUT
@Issue('https://github.com/robfletcher/betamax/issues/20')
class ProxyTimeoutSpec extends Specification {
@Rule Recorder recorder = new Recorder(tapeRoot: tapeRoot, proxyTimeout: 100)
- @Shared @AutoCleanup('deleteDir') File tapeRoot = new File(System.properties.'java.io.tmpdir', 'tapes')
+ @Shared @AutoCleanup('deleteDir') File tapeRoot = newTempDir('tapes')
@AutoCleanup('stop') SimpleServer endpoint = new SimpleServer()
RESTClient http
View
2 src/test/groovy/co/freeside/betamax/proxy/jetty/BetamaxProxySpec.groovy
@@ -31,7 +31,7 @@ class BetamaxProxySpec extends Specification {
betamaxResponse.body = 'O HAI'.bytes
}
- void 'passes the request to is handler chain'() {
+ void 'passes the request to its handler chain'() {
given:
def handler = Mock(HttpHandler)
proxy << handler
View
4 src/test/groovy/co/freeside/betamax/recorder/RequestMatchingSpec.groovy
@@ -4,14 +4,14 @@ import co.freeside.betamax.Recorder
import co.freeside.betamax.httpclient.BetamaxRoutePlanner
import groovyx.net.http.RESTClient
import spock.lang.*
-
import static co.freeside.betamax.MatchRule.host
+import static co.freeside.betamax.util.FileUtils.newTempDir
import static org.apache.http.HttpHeaders.VIA
@Issue('https://github.com/robfletcher/betamax/issues/9')
class RequestMatchingSpec extends Specification {
- @Shared @AutoCleanup('deleteDir') File tapeRoot = new File(System.properties.'java.io.tmpdir', 'tapes')
+ @Shared @AutoCleanup('deleteDir') File tapeRoot = newTempDir('tapes')
@Shared Recorder recorder = new Recorder(tapeRoot: tapeRoot)
@Shared RESTClient http = new RESTClient()
View
20 src/test/groovy/co/freeside/betamax/recorder/TapeModeSpec.groovy
@@ -2,23 +2,17 @@ package co.freeside.betamax.recorder
import co.freeside.betamax.Recorder
import co.freeside.betamax.httpclient.BetamaxRoutePlanner
-import co.freeside.betamax.proxy.jetty.ProxyServer
-import co.freeside.betamax.proxy.jetty.SimpleServer
+import co.freeside.betamax.proxy.jetty.*
import co.freeside.betamax.util.server.EchoHandler
-import groovyx.net.http.HttpResponseException
-import groovyx.net.http.RESTClient
-import spock.lang.AutoCleanup
-import spock.lang.Shared
-import spock.lang.Specification
-
-import static co.freeside.betamax.TapeMode.READ_ONLY
-import static co.freeside.betamax.TapeMode.WRITE_ONLY
-import static java.net.HttpURLConnection.HTTP_FORBIDDEN
-import static java.net.HttpURLConnection.HTTP_OK
+import groovyx.net.http.*
+import spock.lang.*
+import static co.freeside.betamax.TapeMode.*
+import static co.freeside.betamax.util.FileUtils.newTempDir
+import static java.net.HttpURLConnection.*
class TapeModeSpec extends Specification {
- @Shared @AutoCleanup('deleteDir') File tapeRoot = new File(System.properties.'java.io.tmpdir', 'tapes')
+ @Shared @AutoCleanup('deleteDir') File tapeRoot = newTempDir('tapes')
@Shared Recorder recorder = new Recorder(tapeRoot: tapeRoot)
@Shared @AutoCleanup('stop') ProxyServer proxy = new ProxyServer(recorder)
@Shared @AutoCleanup('stop') SimpleServer endpoint = new SimpleServer()
View
8 src/test/groovy/co/freeside/betamax/tape/FilenameNormalizationSpec.groovy
@@ -1,15 +1,13 @@
package co.freeside.betamax.tape
import co.freeside.betamax.tape.yaml.YamlTapeLoader
-import spock.lang.AutoCleanup
-import spock.lang.Shared
-import spock.lang.Specification
-import spock.lang.Unroll
+import spock.lang.*
+import static co.freeside.betamax.util.FileUtils.newTempDir
@Unroll
class FilenameNormalizationSpec extends Specification {
- @Shared @AutoCleanup('deleteDir') File tapeRoot = new File(System.properties.'java.io.tmpdir', 'tapes')
+ @Shared @AutoCleanup('deleteDir') File tapeRoot = newTempDir('tapes')
void "a tape named '#tapeName' is written to a file called '#filename'"() {
given:
View
3 src/test/groovy/co/freeside/betamax/tape/MultiThreadedTapeWritingSpec.groovy
@@ -6,12 +6,13 @@ import co.freeside.betamax.proxy.jetty.SimpleServer
import co.freeside.betamax.util.server.HelloHandler
import org.junit.Rule
import spock.lang.*
+import static co.freeside.betamax.util.FileUtils.newTempDir
import static co.freeside.betamax.util.server.HelloHandler.HELLO_WORLD
import static java.util.concurrent.TimeUnit.SECONDS
class MultiThreadedTapeWritingSpec extends Specification {
- @Shared @AutoCleanup('deleteDir') File tapeRoot = new File(System.properties.'java.io.tmpdir', 'tapes')
+ @Shared @AutoCleanup('deleteDir') File tapeRoot = newTempDir('tapes')
@Rule Recorder recorder = new Recorder(tapeRoot: tapeRoot)
@Shared @AutoCleanup('stop') SimpleServer endpoint = new SimpleServer()
View
9 src/test/groovy/co/freeside/betamax/tape/PostBodySpec.groovy
@@ -7,17 +7,14 @@ import org.apache.http.entity.StringEntity
import org.apache.http.impl.client.DefaultHttpClient
import org.junit.Rule
import org.yaml.snakeyaml.Yaml
-import spock.lang.AutoCleanup
-import spock.lang.Issue
-import spock.lang.Shared
-import spock.lang.Specification
-
+import spock.lang.*
import static co.freeside.betamax.TapeMode.WRITE_ONLY
+import static co.freeside.betamax.util.FileUtils.newTempDir
@Issue('https://github.com/robfletcher/betamax/issues/50')
class PostBodySpec extends Specification {
- @Shared @AutoCleanup('deleteDir') File tapeRoot = new File(System.properties.'java.io.tmpdir', 'tapes')
+ @Shared @AutoCleanup('deleteDir') File tapeRoot = newTempDir('tapes')
@Rule Recorder recorder = new Recorder(tapeRoot: tapeRoot)
private DefaultHttpClient httpClient = new DefaultHttpClient()
View
8 src/test/groovy/co/freeside/betamax/tape/YamlTapeLoaderSpec.groovy
@@ -1,14 +1,12 @@
package co.freeside.betamax.tape
import co.freeside.betamax.tape.yaml.YamlTapeLoader
-import spock.lang.AutoCleanup
-import spock.lang.Issue
-import spock.lang.Shared
-import spock.lang.Specification
+import spock.lang.*
+import static co.freeside.betamax.util.FileUtils.newTempDir
class YamlTapeLoaderSpec extends Specification {
- @Shared @AutoCleanup('deleteDir') File tapeRoot = new File(System.properties.'java.io.tmpdir', 'tapes')
+ @Shared @AutoCleanup('deleteDir') File tapeRoot = newTempDir('tapes')
void setupSpec() {
tapeRoot.mkdirs()
View
15 src/test/groovy/co/freeside/betamax/util/FileUtils.groovy
@@ -0,0 +1,15 @@
+package co.freeside.betamax.util
+
+class FileUtils {
+
+ private static final File TMP = new File(System.properties.'java.io.tmpdir')
+
+ static File newTempDir(String name) {
+ def dir = new File(TMP, name)
+ dir.mkdirs()
+ dir
+ }
+
+ private FileUtils() {}
+
+}

0 comments on commit 8cf3fd9

Please sign in to comment.