Google APIs Client Library for C++
|
A fake transport that plays back from a JSON scribed transcript. More...
#include "client/transport/json_playback_transport.h"
Public Member Functions | |
JsonPlaybackTransport (const HttpTransportOptions &options) | |
Constructor with standard transport options. | |
virtual | ~JsonPlaybackTransport () |
Standard destructor. | |
virtual HttpRequest * | NewHttpRequest (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. | |
HttpScribeCensor * | censor () const |
Returns the censor, if any. | |
Static Public Attributes | |
static const StringPiece | kTransportIdentifier |
The default id() attribute value identifying curl transport instances. |
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.
JsonPlaybackTransport | ( | const HttpTransportOptions & | options | ) | [explicit] |
Constructor with standard transport options.
[in] | options | The standard options to configure the transport with. |
virtual ~JsonPlaybackTransport | ( | ) | [virtual] |
Standard destructor.
HttpScribeCensor* censor | ( | ) | const [inline] |
Returns the censor, if any.
util::Status LoadTranscript | ( | DataReader * | reader | ) |
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.
[in] | reader | The reader to load the transcript from. |
virtual HttpRequest* NewHttpRequest | ( | const HttpRequest::HttpMethod & | method | ) | [virtual] |
Implements the request factory method required by HttpTransport.
[in] | method | The HTTP method to use for the request. |
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.
[in] | censor | The 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.
[in] | t | The caller maintains ownership of the transport. |
JsonPlaybackTranscript* transcript | ( | ) | const [inline] |
Returns the current transcript.
const StringPiece kTransportIdentifier [static] |
The default id() attribute value identifying curl transport instances.