rad 6.2.0
Loading...
Searching...
No Matches
oldbAdapter.hpp
Go to the documentation of this file.
1
9#ifndef RAD_UTEST_OLDB_ADAPTER_HPP
10#define RAD_UTEST_OLDB_ADAPTER_HPP
11
13
14namespace rad {
15namespace utest {
16
23public:
27 virtual ~OldbAdapter();
28
32 virtual void Connect() override;
33};
34
41std::shared_ptr<::elt::oldb::CiiOldb> GetInMemoryOldbInstance();
42
51void CreateMetadataString(const std::string& name, const std::string& uri,
52 std::shared_ptr<::elt::oldb::CiiOldb> instance);
53
60template <typename T>
61void CreateMetadataAndAttribute(const std::string& metadata_instance_name,
62 const std::string& attribute_name,
63 std::shared_ptr<elt::oldb::CiiOldb> oldb_client) {
64
65 elt::config::classes::meta::MdOldb<T> metadata;
66 metadata.setInstanceName(metadata_instance_name);
67 elt::oldb::CiiOldbUtil::SaveOrUpdateMetadata(metadata);
68 if (oldb_client->DataPointExists(elt::mal::Uri(attribute_name)) == false) {
69 auto data_point = oldb_client->CreateDataPoint<T>(elt::mal::Uri(attribute_name),
70 metadata_instance_name);
71 }
72}
73
74template <typename T>
75bool CompareAttribute(const std::string& attribute_name,
76 const T exp_value,
77 rad::cii::OldbAdapter& oldb_adapter) {
78 T act_value;
79 bool has_value = oldb_adapter.TryGet<T>(attribute_name, act_value);
80 if (!has_value) {
81 return false;
82 }
83 return exp_value == act_value;
84}
85
86template <typename T>
87bool CompareVector(const std::string& attribute_name,
88 const std::vector<T> exp_values,
89 rad::cii::OldbAdapter& oldb_adapter) {
90
91 std::vector<T> act_values;
92 bool has_value = oldb_adapter.TryGet<T>(attribute_name, act_values);
93 if (!has_value) {
94 return false;
95 }
96
97 if (exp_values.size() != act_values.size()) {
98 return false;
99 }
100
101 for (int i = 0; i < static_cast<int>(exp_values.size()); i++) {
102 if (exp_values[i] != act_values[i]) {
103 return false;
104 }
105 }
106
107 return true;
108}
109
110} // utest namespace
111} // rad namespace
112
113#endif // RAD_UTEST_OLDB_ADAPTER_HPP
OldbAdapter interface file.
Definition oldbAdapter.hpp:44
bool TryGet(const std::string &key, T &value) noexcept
Definition oldbAdapter.hpp:418
Definition oldbAdapter.hpp:22
virtual void Connect() override
Definition oldbAdapter.cpp:33
virtual ~OldbAdapter()
Definition oldbAdapter.cpp:30
void CreateMetadataString(const std::string &name, const std::string &uri, std::shared_ptr<::elt::oldb::CiiOldb > instance)
Definition oldbAdapter.cpp:78
void CreateMetadataAndAttribute(const std::string &metadata_instance_name, const std::string &attribute_name, std::shared_ptr< elt::oldb::CiiOldb > oldb_client)
Definition oldbAdapter.hpp:61
bool CompareAttribute(const std::string &attribute_name, const T exp_value, rad::cii::OldbAdapter &oldb_adapter)
Definition oldbAdapter.hpp:75
std::shared_ptr<::elt::oldb::CiiOldb > GetInMemoryOldbInstance()
Definition oldbAdapter.cpp:37
bool CompareVector(const std::string &attribute_name, const std::vector< T > exp_values, rad::cii::OldbAdapter &oldb_adapter)
Definition oldbAdapter.hpp:87
Definition actionsApp.cpp:23