Google APIs Client Library for C++
JsonPlaybackTransport Class Reference

A fake transport that plays back from a JSON scribed transcript. More...

#include "client/transport/json_playback_transport.h"

+ Inheritance diagram for JsonPlaybackTransport:

List of all members.

Public Member Functions

 JsonPlaybackTransport (const HttpTransportOptions &options)
 Constructor with standard transport options.
virtual ~JsonPlaybackTransport ()
 Standard destructor.
virtual HttpRequestNewHttpRequest (const HttpRequest::HttpMethod &method)
 Implements the request factory method required by HttpTransport.
util::Status LoadTranscript (DataReader *reader)
 Loads the transcript from the reader.
void set_transcript (JsonPlaybackTranscript *t)
 Sets the current transcript to the one provdied.
JsonPlaybackTranscript * transcript () const
 Returns the current transcript.
void set_censor (HttpScribeCensor *censor)
 Sets the censor to use when resolving requests.
HttpScribeCensorcensor () const
 Returns the censor, if any.

Static Public Attributes

static const StringPiece kTransportIdentifier
 The default id() attribute value identifying curl transport instances.

Detailed Description

A fake transport that plays back from a JSON scribed transcript.

This transport implementation can be used like any other, but it does not connect to a real backend. Instead it acts as a _fake_ and will attempt to pair requests with those in JSON transcript and use the transcript to complete the request with a response or transport error.

This is primarily intended to facilitate testing the application layer without requiring the overhead, latency, and potential nondeterminissim of using real-world servers. Plus you can hand code the transcript in whole or part to inject errors or certain scenarios that might be difficult to produce on demand for a test.

To produce the transcript, you can inject a JsonScript into another transport (such as CurlHttpTransport) and make the requests you wish to playback later using this transport.

To playback the transport use an instance of this class, or the JsonPlaybackTransportFactory. For example if can set the default global transport factory to a JsonPlaybackTransportFactory. Or you can give a particular object (such as a ClientService instance) a JsonPlaybackTransport. Load the JSON transcript into the trasnport (or factory) then proceed as normal.

Warning:
For best recall and fidelity, you should set the HttpCensor on this transport to one configured the same way as the JsonScribe when you recorded the transcript. Otherwise the uncensored requests you are making will not match the censored data in the transcript.
See also:
JsonScribe

Constructor & Destructor Documentation

JsonPlaybackTransport ( const HttpTransportOptions options) [explicit]

Constructor with standard transport options.

Parameters:
[in]optionsThe standard options to configure the transport with.
virtual ~JsonPlaybackTransport ( ) [virtual]

Standard destructor.


Member Function Documentation

HttpScribeCensor* censor ( ) const [inline]

Returns the censor, if any.

Returns:
NULL if there is no censor.

Loads the transcript from the reader.

Alternatively you could use set_transport if you are sharing a transcript across multiple transport instances.

This method is not thread-safe, but you should only be performing it once before you start executing messages.

The transport instance will keep ownership of this transport instance util another is loaded or the instance is deleted.

Parameters:
[in]readerThe reader to load the transcript from.
Returns:
Whether the transcript could be loaded successfully.
See also:
set_transport
virtual HttpRequest* NewHttpRequest ( const HttpRequest::HttpMethod method) [virtual]

Implements the request factory method required by HttpTransport.

Parameters:
[in]methodThe HTTP method to use for the request.
Returns:
A new empty request that will use this fake transport when executing. Use this request as if it were real.

Implements HttpTransport.

void set_censor ( HttpScribeCensor censor) [inline]

Sets the censor to use when resolving requests.

It is important that this censors requests consistent to how they were censored in the transcript or else the requests will not resolve properly.

Parameters:
[in]censorThe caller retains ownership.
void set_transcript ( JsonPlaybackTranscript *  t) [inline]

Sets the current transcript to the one provdied.

This will override the transcript that was loaded and owned by this instance.

The transcript is thread-safe so can be shared across multiple instaneces acting as a global transcript from a message stream aggregated across all the transports sharing it.

Parameters:
[in]tThe caller maintains ownership of the transport.
JsonPlaybackTranscript* transcript ( ) const [inline]

Returns the current transcript.

Returns:
The transcript may be the private one loaded into this instance or might be a shared one that was explicitly set. NULL is returned if there is no transcript bound yet.

Member Data Documentation

const StringPiece kTransportIdentifier [static]

The default id() attribute value identifying curl transport instances.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines