1 #define BOOST_TEST_MODULE (databaseinterface test)
3 #include "boost/test/auto_unit_test.hpp"
12 #include "otsdaq/ConfigurationInterface/DatabaseConfigurationInterface.h"
14 #include "artdaq-database/JsonDocument/JSONDocument.h"
16 #include "artdaq-database/ConfigurationDB/configuration_common.h"
17 #include "artdaq-database/ConfigurationDB/dispatch_common.h"
19 #include "artdaq-database/JsonDocument/JSONDocument.h"
20 #include "artdaq-database/JsonDocument/JSONDocumentBuilder.h"
21 #include "artdaq-database/StorageProviders/FileSystemDB/provider_filedb.h"
22 #include "artdaq-database/StorageProviders/MongoDB/provider_mongodb.h"
24 #include "artdaq-database/DataFormats/Json/json_reader.h"
32 void printJSON(std::stringstream& ss)
const { ss << _json; }
33 int fillFromJSON(std::string
const& newjson)
38 std::string _json =
"{ \"testJSON\" : 123 }";
80 std::cout <<
"setup fixture\n";
83 ~
TestData() { std::cout <<
"setup fixture\n"; }
85 void updateConfigCount(
int count) { _oldConfigCount = count; }
87 int version() {
return _version; }
88 int oldConfigCount() {
return _oldConfigCount; }
90 const int _version = (srand(time(NULL)), rand() % 99999 + 100000);
92 int _oldConfigCount = 0;
99 BOOST_AUTO_TEST_SUITE(databaseinterface_test)
103 std::cout <<
"TestData::version=" << fixture.version() <<
"\n";
109 std::shared_ptr<TableBase> cfg1 = std::make_shared<TestConfiguration001>();
112 cfg1->getViewP()->setVersion(fixture.version());
114 BOOST_CHECK_EQUAL(cfg1->getViewP()->getVersion(), fixture.version());
119 ifc.saveActiveVersion(cfg1.get());
126 std::shared_ptr<TableBase> cfg1 = std::make_shared<TestConfiguration001>();
136 std::shared_ptr<TableBase> cfg1 = std::make_shared<TestConfiguration001>();
137 std::shared_ptr<TableBase> cfg2 = std::make_shared<TestConfiguration002>();
141 cfg1->getViewP()->setVersion(fixture.version() + 1);
142 cfg2->getViewP()->setVersion(fixture.version() + 2);
144 ifc.saveActiveVersion(cfg1.get());
146 ifc.saveActiveVersion(cfg2.get());
148 auto map = DatabaseConfigurationInterface::config_version_map_t{};
149 map[cfg1->getTableName()] = cfg1->getView().getVersion();
150 map[cfg2->getTableName()] = cfg2->getView().getVersion();
152 auto tableName = std::string{
"config"} + std::to_string(fixture.version());
154 auto list = ifc.getAllTableGroupNames();
156 fixture.updateConfigCount(list.size());
158 ifc.saveTableGroup(map, tableName);
167 auto tableName = std::string{
"config"} + std::to_string(fixture.version());
169 auto map = ifc.getTableGroupMembers(tableName);
171 BOOST_CHECK_EQUAL(map.size(), 2);
173 std::shared_ptr<TableBase> cfg1 = std::make_shared<TestConfiguration001>();
174 std::shared_ptr<TableBase> cfg2 = std::make_shared<TestConfiguration002>();
176 BOOST_CHECK_EQUAL(map.at(cfg1->getTableName()), fixture.version() + 1);
177 BOOST_CHECK_EQUAL(map.at(cfg2->getTableName()), fixture.version() + 2);
186 auto list = ifc.getAllTableGroupNames();
188 BOOST_CHECK_EQUAL(list.size(), fixture.oldConfigCount() + 1);
190 auto tableName = std::string{
"config"} + std::to_string(fixture.version());
192 auto found = (std::find(list.begin(), list.end(), tableName) != list.end());
194 BOOST_CHECK_EQUAL(found,
true);
203 auto list = ifc.getAllTableNames();
205 BOOST_CHECK_EQUAL(list.size(), 2);
207 std::shared_ptr<TableBase> cfg1 = std::make_shared<TestConfiguration001>();
208 std::shared_ptr<TableBase> cfg2 = std::make_shared<TestConfiguration002>();
210 auto found1 = (std::find(list.begin(), list.end(), cfg1->getTableName()) != list.end());
212 BOOST_CHECK_EQUAL(found1,
true);
214 auto found2 = (std::find(list.begin(), list.end(), cfg2->getTableName()) != list.end());
216 BOOST_CHECK_EQUAL(found2,
true);
225 std::shared_ptr<TableBase> cfg1 = std::make_shared<TestConfiguration001>();
227 auto list = ifc.getVersions(cfg1.get());
229 auto found1 = (std::find(list.begin(), list.end(), fixture.version()) != list.end());
231 BOOST_CHECK_EQUAL(found1,
true);
233 auto found2 = (std::find(list.begin(), list.end(), fixture.version() + 1) != list.end());
235 BOOST_CHECK_EQUAL(found2,
true);
244 std::shared_ptr<TableBase> cfg1 = std::make_shared<TestConfiguration001>();
246 auto version = ifc.findLatestVersion(cfg1.get());
248 auto list = ifc.getVersions(cfg1.get());
250 std::cout <<
"Found versions\n";
252 for(
auto version : list)
254 std::cout << version <<
", ";
257 std::cout <<
"\nGot latest version: " << version <<
"\n";
262 BOOST_AUTO_TEST_SUITE_END()