MarkLogic Connect
MarkLogic Connect Client API Collection
Public Member Functions | List of all members
mlclient::internals::FakeConnection Class Reference

Implements the Fake idiom. Provides a Fake connection to MarkLogic for testing. More...

#include <FakeConnection.hpp>

Inheritance diagram for mlclient::internals::FakeConnection:
mlclient::IConnection

Public Member Functions

 FakeConnection ()
 Creates a Connection instance. More...
 
 ~FakeConnection ()
 
connection_configuration Connection configuration functions
void configure (const std::string &hostname, const std::string &port, const std::string &username, const std::string &password, const bool usessl=false) override
 
void setDatabaseName (const std::string &db) override
 Sets the name of the database to query/update. Defaults to Documents. More...
 
std::string getDatabaseName () override
 Returns the database name we're querying/updating. Defaults to Documents. More...
 
bool connect () override
 Connects or tests the authentication in the connection. May not actually connect. More...
 
void disconnect () override
 Frees up resources held by the connection, until the next call to connect. More...
 
http_raw RAW HTTP commands
ResponsedoGet (const std::string &pathAndQuerystring) override
 Performs a HTTP GET Request against MarkLogic Server. More...
 
ResponsedoPut (const std::string &pathAndQuerystring, const IDocumentContent &payload) override
 Performs a HTTP PUT Request against MarkLogic Server. More...
 
ResponsedoPost (const std::string &pathAndQuerystring, const IDocumentContent &payload) override
 Performs a HTTP POST Request against MarkLogic Server. More...
 
ResponsedoDelete (const std::string &pathAndQueryString) override
 Performs a HTTP DELETE Request against MarkLogic Server. More...
 
- Public Member Functions inherited from mlclient::IConnection
MLCLIENT_API IConnection ()=default
 Creates a Connection instance. More...
 
virtual ~IConnection ()=default
 
virtual MLCLIENT_API ResponsegetDocument (Document &inout_document)=0
 TODO add optional call parameters (E.g. fetch properties also) More...
 
virtual MLCLIENT_API ResponsegetDocumentContent (Document &inout_document)=0
 Populates the content of the specified document (MUST have a uri). More...
 
virtual MLCLIENT_API ResponsegetDocumentProperties (Document &inout_document)=0
 Populates the properties of the specified document (MUST have a uri). More...
 
virtual MLCLIENT_API ResponsegetDocumentPermissions (Document &inout_document)=0
 Populates the permissions of the specified document (MUST have a uri). More...
 
virtual MLCLIENT_API ResponsesaveDocuments (const DocumentSet &documents, const long startPosInclusive, const long endPosInclusive)=0
 Saves a set of documents as a single batch to MarkLogic Server. More...
 
virtual MLCLIENT_API ResponsesaveDocument (const Document &doc)=0
 Saves a document to MarkLogic (either as new or an update), at the given document URI (MarkLogic unique document ID) More...
 
virtual MLCLIENT_API ResponsesearchExtension (const std::string &extensionName, const SearchDescription &desc)=0
 Performs a search against a REST extension that is compatible with POST /v1/search (i.e. Connection::search) More...
 
virtual MLCLIENT_API ResponsesaveSearchOptions (const std::string &optionsName, const IDocumentContent *optionsDoc)=0
 Saves search options to the server. More...
 
virtual MLCLIENT_API Responsevalues (const std::string &valuesName, const std::string &optionsName)=0
 Performs a values lookup in MarkLogic Server, returning the top values from the lexicon as per the search options configuration used. More...
 
virtual MLCLIENT_API ResponsevaluesExtension (const std::string &extensionName, const std::string &valuesName, const std::string &optionsName, const SearchDescription &desc)=0
 Performs a values against a REST extension that is compatible with POST /v1/search (i.e. Connection::search) More...
 
virtual MLCLIENT_API ResponselistRootCollections ()=0
 Lists the top level collections. I.e. ones starting without a / or ones starting with a / but not containing a / character. More...
 
virtual MLCLIENT_API ResponselistCollections (const std::string &parentCollection)=0
 Lists the immediate child collections of the specified parent Collections. More...
 

wrap_rest Convenience wrapper function calls for common MarkLogic REST API calls.

ResponsegetDocument (const std::string &uri) override
 Retrieves a document from the server, at the given document URI (MarkLogic unique document ID) More...
 
ResponsesaveDocumentContent (const std::string &uri, const IDocumentContent &payload) override
 Saves a document to MarkLogic (either as new or an update), at the given document URI (MarkLogic unique document ID) More...
 
ResponsedeleteDocument (const std::string &uri) override
 Deletes the specified document by URI. More...
 
Responsesearch (const SearchDescription &desc) override
 Performs a search against the MarkLogic database given the provided search query, text and options. More...
 

Detailed Description

Implements the Fake idiom. Provides a Fake connection to MarkLogic for testing.

Author
Adam Fowler adam..nosp@m.fowl.nosp@m.er@ma.nosp@m.rklo.nosp@m.gic.c.nosp@m.om
Since
8.0.0
Date
2016-05-15

This class operates on documents as if it were MarkLogic Server, storing them in memory. Search methods return the first n records as requested in the SearchDescription (default: first 10).

Constructor & Destructor Documentation

mlclient::internals::FakeConnection::FakeConnection ( )

Creates a Connection instance.

Defaults connection to admin/admin, localhost, nossl, port 8002, and the Documents database.

Since
8.0.0
mlclient::internals::FakeConnection::~FakeConnection ( )

Destroys a Connection instance.

Member Function Documentation

void mlclient::internals::FakeConnection::configure ( const std::string &  hostname,
const std::string &  port,
const std::string &  username,
const std::string &  password,
const bool  usessl = false 
)
overridevirtual

Configures this connection, providing connection override information - host, port, username, password and SSL usage

Since
8.0.0
Parameters
[in]hostnameThe hostname or IP address of the MarkLogic Server (or load balancer) to connect to
[in]portA String representing the (numerical) port number of the MarkLogic Server (or load balancer) to connect to
[in]usernameThe username of the used to connect to MarkLogic Server as
[in]passwordThe plain text password used to authenticate the user to MarkLogic server with
[in]usesslA bool representation whether to use SSL (i.e. a HTTPS url) or not

Implements mlclient::IConnection.

bool mlclient::internals::FakeConnection::connect ( )
overridevirtual

Connects or tests the authentication in the connection. May not actually connect.

Note
Should be called prior to any use of functions. Is not called for the developer

Implements mlclient::IConnection.

Response* mlclient::internals::FakeConnection::deleteDocument ( const std::string &  uri)
overridevirtual

Deletes the specified document by URI.

Parameters
[in]uriThe document URI to delete
Returns
A unique_ptr for the Response object. The caller is repsonsible for deleting the pointer.
Exceptions
NoCredentialsExceptionThe credentials for the Connection were not accepted by MarkLogic Server, or permission is denied for this request.
Since
8.0.0

Implements mlclient::IConnection.

void mlclient::internals::FakeConnection::disconnect ( )
overridevirtual

Frees up resources held by the connection, until the next call to connect.

Note
Should be called by a class' destructor

Implements mlclient::IConnection.

Response* mlclient::internals::FakeConnection::doDelete ( const std::string &  pathAndQueryString)
overridevirtual

Performs a HTTP DELETE Request against MarkLogic Server.

Allows mlclient based applications to call any arbitrary REST endpoint on MarkLogic. Just in case we don't yet provide a specific convenience method to invoke it.

Performs a HTTP DELETE REST request to an arbitrary URL on MarkLogic Server

Since
8.0.0
Parameters
[in]pathAndQueryStringthe path and query string for the entire delete request. E.g. /v1/documents?uri=/my/doc.json
Returns
A unique_ptr for a Response instance. The caller is responsible for destroying the pointer.
Exceptions
NoCredentialsExceptionThe credentials for the Connection were not accepted by MarkLogic Server, or permission is denied for this request.
Note
This function is not limited to the REST API, and can be used for the management REST API or any arbitrary MarkLogic web application URL.

Implements mlclient::IConnection.

Response* mlclient::internals::FakeConnection::doGet ( const std::string &  pathAndQuerystring)
overridevirtual

Performs a HTTP GET Request against MarkLogic Server.

Allows mlclient based applications to call any arbitrary REST endpoint on MarkLogic. Just in case we don't yet provide a specific convenience method to invoke it.

Performs a RESTful HTTP GET request to an arbitrary URL on MarkLogic Server

Since
8.0.0
Parameters
[in]pathAndQueryStringthe path and query string for the entire get request. E.g. /v1/search?options=myoptions
Returns
A unique_ptr for a Response instance. The caller is responsible for destroying the pointer.
Exceptions
NoCredentialsExceptionThe credentials for the Connection were not accepted by MarkLogic Server, or permission is denied for this request.
Note
This function is not limited to the REST API, and can be used for the management REST API or any arbitrary MarkLogic web application URL.

Implements mlclient::IConnection.

Response* mlclient::internals::FakeConnection::doPost ( const std::string &  pathAndQuerystring,
const IDocumentContent payload 
)
overridevirtual

Performs a HTTP POST Request against MarkLogic Server.

Allows mlclient based applications to call any arbitrary REST endpoint on MarkLogic. Just in case we don't yet provide a specific convenience method to invoke it.

Performs a RESTful HTTP POST request to an arbitrary URL on MarkLogic Server

Since
8.0.0
Parameters
[in]pathAndQueryStringthe path and query string for the entire post request. E.g. /v1/search?options=myoptions
[in]payloadThe DocumentContent to send to MarkLogic Server
Returns
A unique_ptr for a Response instance. The caller is responsible for destroying the pointer.
Exceptions
NoCredentialsExceptionThe credentials for the Connection were not accepted by MarkLogic Server, or permission is denied for this request.
Note
This function is not limited to the REST API, and can be used for the management REST API or any arbitrary MarkLogic web application URL.

Implements mlclient::IConnection.

Response* mlclient::internals::FakeConnection::doPut ( const std::string &  pathAndQuerystring,
const IDocumentContent payload 
)
overridevirtual

Performs a HTTP PUT Request against MarkLogic Server.

Allows mlclient based applications to call any arbitrary REST endpoint on MarkLogic. Just in case we don't yet provide a specific convenience method to invoke it.

Performs a RESTful HTTP PUT request to an arbitrary URL on MarkLogic Server

Since
8.0.0
Parameters
[in]pathAndQueryStringthe path and query string for the entire put request. E.g. /v1/search?options=myoptions
[in]payloadThe DocumentContent to send to MarkLogic Server
Returns
A unique_ptr for a Response instance. The caller is responsible for destroying the pointer.
Exceptions
NoCredentialsExceptionThe credentials for the Connection were not accepted by MarkLogic Server, or permission is denied for this request.
Note
This function is not limited to the REST API, and can be used for the management REST API or any arbitrary MarkLogic web application URL.

Implements mlclient::IConnection.

std::string mlclient::internals::FakeConnection::getDatabaseName ( )
overridevirtual

Returns the database name we're querying/updating. Defaults to Documents.

Since
8.0.0
Returns
A string representation of the database name (not internal MarkLogic database numeric ID)

Implements mlclient::IConnection.

Response* mlclient::internals::FakeConnection::getDocument ( const std::string &  uri)
overridevirtual

Retrieves a document from the server, at the given document URI (MarkLogic unique document ID)

Performs a GET /v1/documents?uri HTTP call

Parameters
[in]uriThe URI of the document to fetch from MarkLogic Server
Returns
A unique_ptr for the Response object. The caller is repsonsible for deleting the pointer.
Exceptions
NoCredentialsExceptionThe credentials for the Connection were not accepted by MarkLogic Server, or permission is denied for this request.
Since
8.0.0

Implements mlclient::IConnection.

Response* mlclient::internals::FakeConnection::saveDocumentContent ( const std::string &  uri,
const IDocumentContent payload 
)
overridevirtual

Saves a document to MarkLogic (either as new or an update), at the given document URI (MarkLogic unique document ID)

Performs a call to PUT /v1/documents?ext in order to save a Document to MarkLogic Server

Parameters
[in]uriThe URI of the document to save to MarkLogic Server
[in]payloadThe DocumentContent to send to MarkLogic Server
Returns
A unique_ptr for the Response object. The caller is repsonsible for deleting the pointer.
Exceptions
NoCredentialsExceptionThe credentials for the Connection were not accepted by MarkLogic Server, or permission is denied for this request.
Since
8.0.0

Implements mlclient::IConnection.

Response* mlclient::internals::FakeConnection::search ( const SearchDescription desc)
overridevirtual

Performs a search against the MarkLogic database given the provided search query, text and options.

Uses a SearchDescription value object to wrap complex search parameters for MarkLogic Server.

Performs a POST /v1/search HTTP POST to MarkLogic Server

Parameters
[in]descThe SearchDescription defining the search, options, and query string
Returns
A unique_ptr for the Response object. The caller is repsonsible for deleting the pointer.
Exceptions
NoCredentialsExceptionThe credentials for the Connection were not accepted by MarkLogic Server, or permission is denied for this request.
Since
8.0.0

Implements mlclient::IConnection.

void mlclient::internals::FakeConnection::setDatabaseName ( const std::string &  db)
overridevirtual

Sets the name of the database to query/update. Defaults to Documents.

Since
8.0.0
Parameters
[in]Thestring name (not internal MarkLogic numeric ID) of the database to query.

Implements mlclient::IConnection.


The documentation for this class was generated from the following file: