40 #include <gmock/gmock.h> 41 #include <gtest/gtest.h> 57 MOCK_METHOD1(setConnectionInfo,
void (
const std::map<std::string, std::string>& connInfo));
77 MOCK_METHOD3(
renameProperty,
void (
const std::string& datasetName,
const std::string& propertyName,
const std::string& newPropertyName));
107 MOCK_METHOD3(
cloneDataSet,
void (
const std::string& name,
const std::string& cloneName,
const std::map<std::string, std::string>& options));
114 MOCK_METHOD4(
update,
void (
const std::string& datasetName,
te::da::DataSet* dataset,
const std::vector< std::set<int> >& properties,
const std::vector<size_t>& ids));
119 MOCK_METHOD1(getEncodings, std::vector<te::core::EncodingType>(
const std::map<std::string, std::string>& dsInfo));
124 virtual std::auto_ptr<te::da::DataSourceTransactor>
getTransactor()
override {
125 return std::auto_ptr<te::da::DataSourceTransactor>(getTransactorOfMock());
129 return std::auto_ptr<te::da::DataSet>(getDataSetOfMock(name, travType, accessPolicy));
133 return std::auto_ptr<te::da::DataSet>(getDataSetOfMock1(name, propertyName, e, r, travType, accessPolicy));
137 return std::auto_ptr<te::da::DataSet>(getDataSetOfMock2(name, propertyName, g, r, travType, accessPolicy));
141 return std::auto_ptr<te::da::DataSet>(queryOfMock(q, travType, accessPolicy));
145 return std::auto_ptr<te::da::DataSet>(queryOfMock1(query, travType, accessPolicy));
148 virtual std::auto_ptr<te::da::DataSetType>
getDataSetType(
const std::string& name)
override {
149 return std::auto_ptr<te::da::DataSetType>(getDataSetTypeOfMock(name));
152 virtual std::auto_ptr<te::dt::Property>
getProperty(
const std::string& datasetName,
const std::string& name)
override {
153 return std::auto_ptr<te::dt::Property>(getPropertyOfMock(datasetName, name));
156 virtual std::auto_ptr<te::dt::Property>
getProperty(
const std::string& datasetName, std::size_t propertyPos)
override {
157 return std::auto_ptr<te::dt::Property>(getPropertyOfMock1(datasetName, propertyPos));
160 virtual std::auto_ptr<te::da::PrimaryKey>
getPrimaryKey(
const std::string& datasetName)
override {
161 return std::auto_ptr<te::da::PrimaryKey> (getPrimaryKeyOfMock(datasetName));
164 virtual std::auto_ptr<te::da::ForeignKey>
getForeignKey(
const std::string& datasetName,
const std::string& name)
override {
165 return std::auto_ptr<te::da::ForeignKey> (getForeignKeyOfMock(datasetName, name));
168 virtual std::auto_ptr<te::da::UniqueKey>
getUniqueKey(
const std::string& datasetName,
const std::string& name)
override {
169 return std::auto_ptr<te::da::UniqueKey> (getUniqueKeyOfMock(datasetName, name));
172 virtual std::auto_ptr<te::da::CheckConstraint>
getCheckConstraint(
const std::string& datasetName,
const std::string& name)
override {
173 return std::auto_ptr<te::da::CheckConstraint> (getCheckConstraintOfMock(datasetName, name));
176 virtual std::auto_ptr<te::da::Index>
getIndex(
const std::string& datasetName,
const std::string& name)
override {
177 return std::auto_ptr<te::da::Index> (getIndexOfMock(datasetName, name));
180 virtual std::auto_ptr<te::da::Sequence>
getSequence(
const std::string& name)
override {
181 return std::auto_ptr<te::da::Sequence> (getSequenceOfMock(name));
184 virtual std::auto_ptr<te::gm::Envelope>
getExtent(
const std::string& datasetName,
const std::string& propertyName)
override {
185 return std::auto_ptr<te::gm::Envelope> (getExtentOfMock(datasetName, propertyName));
188 virtual std::auto_ptr<te::gm::Envelope>
getExtent(
const std::string& datasetName, std::size_t propertyPos)
override {
189 return std::auto_ptr<te::gm::Envelope> (getExtentOfMock1(datasetName, propertyPos));
204 ds.reset(datasource);
206 std::map<std::string, std::string> connInfo;
207 std::string data_dir = TERRALIB_DATA_DIR;
208 connInfo[
"URI"] = data_dir +
"/DadosEric/Municipios.shp";
210 ds->setConnectionInfo(connInfo);
220 isOpened = ds->isOpened();
224 using ::testing::AtLeast;
226 using ::testing::Return;
227 using ::testing::InSequence;
229 TEST(DataSourceTest, CanCreateDataSource) {
242 EXPECT_CALL(*mockDS.get(), setConnectionInfo(_))
246 EXPECT_CALL(*mockDS.get(),
open())
251 EXPECT_CALL(*mockDS.get(),
isOpened())
253 .WillOnce(Return(
true));
256 EXPECT_CALL(*mockDS.get(),
close())
261 EXPECT_CALL(*mockDS.get(),
isOpened())
263 .WillOnce(Return(
false));
virtual std::auto_ptr< te::da::Index > getIndex(const std::string &datasetName, const std::string &name) override
It gets the index with the given name from the dataset.
virtual void cloneDataSet(const std::string &name, const std::string &cloneName, const std::map< std::string, std::string > &options)
It clones the dataset in the data source.
virtual std::auto_ptr< te::da::DataSetType > getDataSetType(const std::string &name) override
It gets information about the given dataset.
virtual bool isValid() const =0
It checks if the data source is valid (available for using).
static std::unique_ptr< DataSource > create(const std::string &dsType, const std::string &connInfo)
It creates a new repository for a data source.
virtual bool isPropertyNameValid(const std::string &propertyName)
It checks if the given property name is valid.
virtual void dropProperty(const std::string &datasetName, const std::string &name)
It removes a property from the given dataset.
static std::unique_ptr< DataSource > make(const std::string &driver, const te::core::URI &connInfo)
virtual void execute(const Query &command)
It executes the specified command using a generic query representation.
Include files for Core Plugin Library.
virtual std::size_t getNumberOfDataSets()
It retrieves the number of data sets available in the data source.
MOCK_METHOD2(propertyExists, bool(const std::string &datasetName, const std::string &name))
MOCK_METHOD1(setConnectionInfo, void(const std::map< std::string, std::string > &connInfo))
virtual std::auto_ptr< te::dt::Property > getProperty(const std::string &datasetName, std::size_t propertyPos) override
It retrieves the property lying in the given position from the dataset.
virtual void open()=0
It opens the data source and makes it ready for using.
virtual bool uniqueKeyExists(const std::string &datasetName, const std::string &name)
It checks if a unique key with the given name exists in the dataset.
MOCK_METHOD6(update, void(const std::string &datasetName, te::da::DataSet *dataset, const std::vector< std::size_t > &properties, const te::da::ObjectIdSet *oids, const std::map< std::string, std::string > &options, std::size_t limit))
virtual std::auto_ptr< te::gm::Envelope > getExtent(const std::string &datasetName, std::size_t propertyPos) override
It retrieves the bounding rectangle for the spatial property lying in the given position in the datas...
virtual boost::ptr_vector< te::dt::Property > getProperties(const std::string &datasetName)
It retrieves the properties of the dataset.
MOCK_CONST_METHOD0(getType, std::string())
virtual void changePropertyDefinition(const std::string &datasetName, const std::string &propName, te::dt::Property *newProp)
MOCK_METHOD3(renameProperty, void(const std::string &datasetName, const std::string &propertyName, const std::string &newPropertyName))
virtual ~MockDataSource()=default
void insert(const PluginInfo &pinfo)
Adds plugin with its plugin information to the list of unloaded plugins.
A class that models the description of a dataset.
virtual bool propertyExists(const std::string &datasetName, const std::string &name)
It checks if a property with the given name exists in the dataset.
virtual std::auto_ptr< te::da::UniqueKey > getUniqueKey(const std::string &datasetName, const std::string &name) override
It gets the unique key in the dataset with the given name.
virtual bool primaryKeyExists(const std::string &datasetName, const std::string &name)
It checks if a primary key exists in the dataset.
virtual void createDataSet(DataSetType *dt, const std::map< std::string, std::string > &options)
It creates the dataset schema definition in the target data source.
virtual std::auto_ptr< te::da::DataSet > query(const te::da::Select &q, te::common::TraverseType travType, const te::common::AccessPolicy accessPolicy) override
It executes a query that may return some data using a generic query. This method always returns a dis...
virtual std::auto_ptr< te::da::Sequence > getSequence(const std::string &name) override
It gets the sequence with the given name in the data source.
It represents the SQL query dialect accepted by a given data source.
virtual void add(const std::string &datasetName, DataSet *d, const std::map< std::string, std::string > &options, std::size_t limit=0)
It adds data items to the dataset in the data source.
MOCK_METHOD0(open, void())
virtual bool isOpened() const =0
It returns true if the data source is opened, otherwise it returns false.
Basic information about a plugin.
SpatialRelation
Spatial relations between geometric objects.
It describes a sequence (a number generator).
A class that represents the known capabilities of a specific data source, i.e. this class informs all...
virtual void renameDataSet(const std::string &name, const std::string &newName)
It renames a dataset.
static te::dt::Date ds(2010, 01, 01)
static void drop(const std::string &dsType, const std::string &connInfo)
It removes a data source identified by its connection information and the driver type.
A class that describes a check constraint.
virtual void addForeignKey(const std::string &datasetName, ForeignKey *fk)
It adds a foreign key constraint to a dataset.
An abstract class for data providers like a DBMS, Web Services or a regular file. ...
virtual void dropUniqueKey(const std::string &datasetName, const std::string &name)
It removes the unique key constraint from the dataset.
virtual void addSequence(Sequence *sequence)
It adds a new sequence in the data source.
void load(const std::string &plugin_name, const bool start=true)
It tries to load the informed plugin.
It models a property definition.
void CreateDataSource(te::da::DataSource *datasource)
virtual te::core::EncodingType getEncoding()
It return the DataSource current encoding.
virtual std::string getType() const =0
It returns the data source type name (in UPPER CASE). Ex: POSTGIS, SQLITE, WFS, WMS, or MYSQL.
EncodingType
Supported character encodings.
static std::vector< std::string > getDataSourceNames(const std::string &dsType, const std::string &connInfo)
It returns the data source names available in the driver.
virtual void dropCheckConstraint(const std::string &datasetName, const std::string &name)
It removes the check constraint from the dataset.
virtual void dropPrimaryKey(const std::string &datasetName)
It removes the primary key constraint from the dataset schema.
std::string name
The plugin name: an internal value used to identify the plugin in the system. Must be a unique value...
AccessPolicy
Supported data access policies (can be used as bitfield).
TraverseType
A dataset can be traversed in two ways:
virtual std::vector< std::string > getForeignKeyNames(const std::string &datasetName)
It gets the foreign key names of the given dataset.
static PluginManager & instance()
Access the singleton.
virtual const DataSourceCapabilities & getCapabilities() const =0
It returns the known capabilities of the data source.
virtual void addCheckConstraint(const std::string &datasetName, CheckConstraint *cc)
It adds a check constraint to the dataset.
void finalize()
It finalizes the TerraLib Platform.
static TerraLib & getInstance()
It returns a reference to the singleton instance.
An Envelope defines a 2D rectangular region.
virtual void addUniqueKey(const std::string &datasetName, UniqueKey *uk)
It adds a unique key constraint to the dataset.
This class represents a set of unique ids created in the same context. i.e. from the same data set...
virtual void dropIndex(const std::string &datasetName, const std::string &idxName)
It removes the index from the given dataset.
virtual std::auto_ptr< te::da::CheckConstraint > getCheckConstraint(const std::string &datasetName, const std::string &name) override
It gets the check constraint of the dataset with the given name.
static te::dt::DateTime d(2010, 8, 9, 15, 58, 39)
static te::dt::TimeDuration dt(20, 30, 50, 11)
virtual void dropForeignKey(const std::string &datasetName, const std::string &fkName)
It removes the foreign key constraint from the dataset schema.
virtual std::string escape(const std::string &value)
It escapes a string for using in commands and queries.
It models a foreign key constraint for a DataSetType.
virtual std::size_t getNumberOfProperties(const std::string &datasetName)
It gets the number of properties of the given dataset.
TEST(DataSourceTest, CanCreateDataSource)
virtual std::vector< std::string > getDataSetNames()
It gets the dataset names available in the data source.
virtual std::vector< std::string > getIndexNames(const std::string &datasetName)
It gets the index names of the given dataset.
virtual std::auto_ptr< te::da::DataSourceTransactor > getTransactor() override
It returns the set of parameters used to set up the access channel to the underlying repository...
virtual void addPrimaryKey(const std::string &datasetName, PrimaryKey *pk)
It adds a primary key constraint to the dataset schema.
It describes a unique key (uk) constraint.
A DataSourceTransactor can be viewed as a connection to the data source for reading/writing things in...
virtual std::auto_ptr< te::gm::Envelope > getExtent(const std::string &datasetName, const std::string &propertyName) override
It retrieves the bounding rectangle of the spatial property for the given dataset.
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
A Select models a query to be used when retrieving data from a DataSource.
virtual std::auto_ptr< te::da::DataSet > query(const std::string &query, te::common::TraverseType travType, const te::common::AccessPolicy accessPolicy) override
It executes a query that may return some data using the data source native language. This method always returns a disconnected dataset, that is, a dataset that is no more dependent of the data source that provided the connection for its creation. Therefore, the disconnected dataset continues to live after the connection given by the data source has been released.
virtual bool isDataSetNameValid(const std::string &datasetName)
It checks if the given dataset name is valid.
void initialize()
It initializes the TerraLib Platform.
virtual bool dataSetExists(const std::string &name)
It checks if a dataset with the given name exists in the data source.
A dataset is the unit of information manipulated by the data access module of TerraLib.
virtual bool hasDataSets()
It checks if the data source has any dataset.
virtual std::vector< std::string > getCheckConstraintNames(const std::string &datasetName)
It gets the check constraint names of the given dataset.
virtual void dropSequence(const std::string &name)
It removes the sequence from the data source.
virtual bool indexExists(const std::string &datasetName, const std::string &name)
It checks if an index with the given name exists in the dataset.
virtual std::auto_ptr< te::da::PrimaryKey > getPrimaryKey(const std::string &datasetName) override
It retrieves the primary key of the dataset.
virtual void dropDataSet(const std::string &name)
It removes the dataset schema from the data source.
TECOREEXPORT PluginInfo JSONPluginInfoSerializer(const std::string &file_name)
A plugin finder that search for plugins in some special directories defined by compile time macros...
virtual void renameProperty(const std::string &datasetName, const std::string &propertyName, const std::string &newPropertyName)
It renames a property of the given dataset.
It describes a primary key (pk) constraint.
const te::core::URI & getConnectionInfo() const
An Uniform Resource Identifier used to describe the datasource connection.
virtual void close()=0
It closes the data source and clears all the resources used by its internal communication channel...
virtual const SQLDialect * getDialect() const =0
It returns the data source SQL dialect, if there is one.
TECOREEXPORT std::string FindInTerraLibPath(const std::string &path)
Returns the path relative to a directory or file in the context of TerraLib.
virtual std::size_t getNumberOfItems(const std::string &datasetName)
It retrieves the number of items of the given dataset.
virtual void addIndex(const std::string &datasetName, Index *idx, const std::map< std::string, std::string > &options)
It adds an index to the dataset.
virtual void changePropertiesDefinitions(const std::string &datasetName, const std::vector< std::string > &propsNames, const std::vector< te::dt::Property * > newProps)
virtual std::auto_ptr< te::da::DataSet > getDataSet(const std::string &name, te::common::TraverseType travType, const te::common::AccessPolicy accessPolicy) override
It gets the dataset identified by the given name. This method always returns a disconnected dataset...
virtual std::auto_ptr< te::da::ForeignKey > getForeignKey(const std::string &datasetName, const std::string &name) override
It retrieves the foreign key from the given dataset.
This file contains include headers for the TerraLib Common Runtime module.
virtual std::auto_ptr< te::da::DataSet > getDataSet(const std::string &name, const std::string &propertyName, const te::gm::Envelope *e, te::gm::SpatialRelation r, te::common::TraverseType travType, const te::common::AccessPolicy accessPolicy) override
It gets the dataset identified by the given name using a spatial filter over the specified property...
virtual bool sequenceExists(const std::string &name)
It checks if a sequence with the given name exists in the data source.
static bool exists(const std::string &dsType, const std::string &connInfo)
It checks if the data source exists with the connection information and the driver type...
virtual std::vector< std::string > getSequenceNames()
It gets the sequence names available in the data source.
virtual std::vector< std::string > getUniqueKeyNames(const std::string &datasetName)
It gets the unique key names of the given dataset.
This file contains include headers for the Data Access module of TerraLib.
virtual std::auto_ptr< te::dt::Property > getProperty(const std::string &datasetName, const std::string &name) override
It retrieves the property with the given name from the dataset.
virtual void update(const std::string &datasetName, DataSet *dataset, const std::vector< std::size_t > &properties, const te::da::ObjectIdSet *oids, const std::map< std::string, std::string > &options, std::size_t limit=0)
It updates the contents of a dataset for the set of data items.
virtual bool checkConstraintExists(const std::string &datasetName, const std::string &name)
It checks if a check-constraint with the given name exists in the data source.
virtual bool foreignKeyExists(const std::string &datasetName, const std::string &name)
It checks if a foreign key with the given name exists in the data source.
virtual std::vector< std::string > getPropertyNames(const std::string &datasetName)
It gets the property names of the given dataset.
A Query is independent from the data source language/dialect.
It describes an index associated to a DataSetType.
virtual std::auto_ptr< te::da::DataSet > getDataSet(const std::string &name, const std::string &propertyName, const te::gm::Geometry *g, te::gm::SpatialRelation r, te::common::TraverseType travType, const te::common::AccessPolicy accessPolicy) override
It gets the dataset identified by the given name using a spatial filter over the given geometric prop...
MOCK_METHOD4(add, void(const std::string &datasetName, te::da::DataSet *d, const std::map< std::string, std::string > &options, std::size_t limit))
virtual void addProperty(const std::string &datasetName, te::dt::Property *p)
It adds a new property to the dataset schema.