|
| 1 | +// Copyright CERN and copyright holders of ALICE O2. This software is |
| 2 | +// distributed under the terms of the GNU General Public License v3 (GPL |
| 3 | +// Version 3), copied verbatim in the file "COPYING". |
| 4 | +// |
| 5 | +// See http://alice-o2.web.cern.ch/license for full licensing information. |
| 6 | +// |
| 7 | +// In applying this license CERN does not waive the privileges and immunities |
| 8 | +// granted to it by virtue of its status as an Intergovernmental Organization |
| 9 | +// or submit itself to any jurisdiction. |
| 10 | + |
| 11 | +/// |
| 12 | +/// \file testCcdbDatabase.cxx |
| 13 | +/// \author Adam Wegrzynek |
| 14 | +/// \author Bartheley von Haller |
| 15 | +/// |
| 16 | + |
| 17 | +#include <QualityControl/DatabaseFactory.h> |
| 18 | +#include <unordered_map> |
| 19 | +#include <QualityControl/CcdbDatabase.h> |
| 20 | + |
| 21 | +#define BOOST_TEST_MODULE CcdbDatabaseExtra test |
| 22 | +#define BOOST_TEST_MAIN |
| 23 | +#define BOOST_TEST_DYN_LINK |
| 24 | + |
| 25 | +#include <boost/test/unit_test.hpp> |
| 26 | +#include <TH1F.h> |
| 27 | +#include <TFile.h> |
| 28 | +#include <boost/property_tree/ptree.hpp> |
| 29 | +#include <boost/property_tree/json_parser.hpp> |
| 30 | + |
| 31 | +namespace utf = boost::unit_test; |
| 32 | + |
| 33 | +namespace o2::quality_control::core |
| 34 | +{ |
| 35 | + |
| 36 | +namespace |
| 37 | +{ |
| 38 | + |
| 39 | +using namespace o2::quality_control::core; |
| 40 | +using namespace o2::quality_control::repository; |
| 41 | +using namespace std; |
| 42 | + |
| 43 | +const std::string CCDB_ENDPOINT = "ccdb-test.cern.ch:8080"; |
| 44 | +std::unordered_map<std::string, std::string> Objects; |
| 45 | + |
| 46 | +/** |
| 47 | + * Fixture for the tests, i.e. code is ran in every test that uses it, i.e. it is like a setup and teardown for tests. |
| 48 | + */ |
| 49 | +struct test_fixture { |
| 50 | + test_fixture() |
| 51 | + { |
| 52 | + backend = DatabaseFactory::create("CCDB"); |
| 53 | + backend->connect(CCDB_ENDPOINT, "", "", ""); |
| 54 | + std::cout << "*** " << boost::unit_test::framework::current_test_case().p_name << " ***" << std::endl; |
| 55 | + } |
| 56 | + |
| 57 | + ~test_fixture() = default; |
| 58 | + |
| 59 | + std::unique_ptr<DatabaseInterface> backend; |
| 60 | + map<string, string> metadata; |
| 61 | +}; |
| 62 | + |
| 63 | +// These tests should not be executed automatically, too much error prone. |
| 64 | +// It depends on what is in the database. |
| 65 | + |
| 66 | +BOOST_AUTO_TEST_CASE(ccdb_retrieve_all) |
| 67 | +{ |
| 68 | + test_fixture f; |
| 69 | + for (auto const& [task, object] : Objects) { |
| 70 | + std::cout << "[RETRIEVE]: " << task << object << std::endl; |
| 71 | + auto mo = f.backend->retrieve(task, object); |
| 72 | + if (mo == nullptr) { |
| 73 | + std::cout << "No object found (" << task << object << ")" << std::endl; |
| 74 | + continue; |
| 75 | + } |
| 76 | + cout << "name of encapsulated object : " << mo->getObject()->GetName() << endl; // just to test it |
| 77 | + } |
| 78 | +} |
| 79 | + |
| 80 | +// TODO this should not be executed automatically, too much error prone. |
| 81 | +// It depends on what is in the database. |
| 82 | +BOOST_AUTO_TEST_CASE(ccdb_retrieve_all_json) |
| 83 | +{ |
| 84 | + test_fixture f; |
| 85 | + for (auto const& [task, object] : Objects) { |
| 86 | + std::cout << "[JSON RETRIEVE]: " << task << "/" << object << std::endl; |
| 87 | + auto json = f.backend->retrieveJson(task, object); |
| 88 | + if (json.empty()) { |
| 89 | + std::cout << "skipping empty object..." << std::endl; |
| 90 | + continue; |
| 91 | + } |
| 92 | + std::stringstream ss; |
| 93 | + ss << json; |
| 94 | + boost::property_tree::ptree pt; |
| 95 | + boost::property_tree::read_json(ss, pt); |
| 96 | + } |
| 97 | +} |
| 98 | +} // namespace |
| 99 | +} // namespace o2::quality_control::core |
0 commit comments