Groovy Documentation

betamax
[Groovy] Class Recorder

java.lang.Object
  betamax.Recorder
All Implemented Interfaces:
org.junit.rules.MethodRule

class Recorder
extends java.lang.Object

This is the main interface to the Betamax proxy. It allows control of Betamax configuration and inserting and ejecting `Tape` instances. The class can also be used as a _JUnit @Rule_ allowing tests annotated with `@Betamax` to run with the Betamax HTTP proxy in the background.


Field Summary
static int DEFAULT_PROXY_PORT

static int DEFAULT_PROXY_TIMEOUT

static java.lang.String DEFAULT_TAPE_ROOT

 
Property Summary
TapeMode defaultMode

The default mode for an inserted tape.

int proxyPort

The port the Betamax proxy will listen on.

int proxyTimeout

The time the proxy will wait before aborting a request in milliseconds.

java.io.File tapeRoot

The base directory where tape files are stored.

 
Constructor Summary
Recorder()

Recorder(java.util.Properties properties)

 
Method Summary
org.junit.runners.model.Statement apply(org.junit.runners.model.Statement statement, org.junit.runners.model.FrameworkMethod method, java.lang.Object target)

void ejectTape()

'Ejects' the current _tape_, writing its content to file.

Tape getTape()

Gets the current active _tape_.

void insertTape(java.lang.String name, java.util.Map arguments = [:])

Inserts a tape either creating a new one or loading an existing file from `tapeRoot`.

void overrideProxySettings()

void restoreOriginalProxySettings()

java.lang.Object withTape(java.lang.String name, groovy.lang.Closure closure)

Runs the supplied closure after starting the Betamax proxy and inserting a _tape_.

java.lang.Object withTape(java.lang.String tapeName, java.util.Map arguments, groovy.lang.Closure closure)

Runs the supplied closure after starting the Betamax proxy and inserting a _tape_.

 
Methods inherited from class java.lang.Object
java.lang.Object#wait(), java.lang.Object#wait(long), java.lang.Object#wait(long, int), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll()
 

Field Detail

DEFAULT_PROXY_PORT

public static final int DEFAULT_PROXY_PORT


DEFAULT_PROXY_TIMEOUT

public static final int DEFAULT_PROXY_TIMEOUT


DEFAULT_TAPE_ROOT

public static final java.lang.String DEFAULT_TAPE_ROOT


 
Property Detail

defaultMode

TapeMode defaultMode
The default mode for an inserted tape.


proxyPort

int proxyPort
The port the Betamax proxy will listen on.


proxyTimeout

int proxyTimeout
The time the proxy will wait before aborting a request in milliseconds.


tapeRoot

java.io.File tapeRoot
The base directory where tape files are stored.


 
Constructor Detail

Recorder

Recorder()


Recorder

Recorder(java.util.Properties properties)


 
Method Detail

apply

org.junit.runners.model.Statement apply(org.junit.runners.model.Statement statement, org.junit.runners.model.FrameworkMethod method, java.lang.Object target)


ejectTape

void ejectTape()
'Ejects' the current _tape_, writing its content to file. If the proxy is active after calling this method it will no longer record or play back any HTTP traffic until another tape is inserted.


getTape

Tape getTape()
Gets the current active _tape_.
Returns:
the active _tape_.


insertTape

void insertTape(java.lang.String name, java.util.Map arguments = [:])
Inserts a tape either creating a new one or loading an existing file from `tapeRoot`.
Parameters:
name - the name of the _tape_.
arguments - customize the behaviour of the tape.


overrideProxySettings

void overrideProxySettings()


restoreOriginalProxySettings

void restoreOriginalProxySettings()


withTape

java.lang.Object withTape(java.lang.String name, groovy.lang.Closure closure)
Runs the supplied closure after starting the Betamax proxy and inserting a _tape_. After the closure completes the _tape_ is ejected and the proxy stopped.
Parameters:
name - the name of the _tape_.
closure - the closure to execute.
Returns:
the return value of the closure.


withTape

java.lang.Object withTape(java.lang.String tapeName, java.util.Map arguments, groovy.lang.Closure closure)
Runs the supplied closure after starting the Betamax proxy and inserting a _tape_. After the closure completes the _tape_ is ejected and the proxy stopped.
Parameters:
tapeName - the name of the _tape_.
arguments - arguments that affect the operation of the proxy.
closure - the closure to execute.
Returns:
the return value of the closure.


 

Groovy Documentation