Skip to content
Snippets Groups Projects
Select Git revision
  • 19982cfad3f998ccb1d931d4b42022a5b33aeb08
  • main default protected
  • dev
  • f-docs-pylib
  • f-parse-value
  • f-compare
  • f-string-ids
  • f-217-set-special-property
  • f-filesystem-import
  • f-filesystem-link
  • f-filesystem-directory
  • f-filesystem-core
  • f-filesystem-cleanup
  • f-check-merge-entities
  • f-compare-enid
  • f-select-subproperties
  • v0.18.0
  • v0.17.0
  • v0.16.0
  • v0.15.1
  • v0.15.0
  • v0.14.0
  • v0.13.2
  • v0.13.1
  • v0.13.0
  • linkahead-rename-step-2
  • linkahead-rename-step-1
  • v0.12.0
  • v0.11.2
  • v0.11.1
  • v0.11.0
  • v0.10.0
  • v0.9.0
  • v0.8.0
  • v0.7.4
  • v0.7.3
36 results

test_query.py

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    test_configuration.cpp 3.87 KiB
    /*
     *
     * This file is a part of the CaosDB Project.
     *
     * Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com>
     * Copyright (C) 2021 IndiScale GmbH <info@indiscale.com>
     *
     * This program is free software: you can redistribute it and/or modify
     * it under the terms of the GNU Affero General Public License as
     * published by the Free Software Foundation, either version 3 of the
     * License, or (at your option) any later version.
     *
     * This program is distributed in the hope that it will be useful,
     * but WITHOUT ANY WARRANTY; without even the implied warranty of
     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     * GNU Affero General Public License for more details.
     *
     * You should have received a copy of the GNU Affero General Public License
     * along with this program. If not, see <https://www.gnu.org/licenses/>.
     *
     */
    #include "caosdb/configuration.h"  // for ConfigurationError, Configuration...
    #include "caosdb/exceptions.h"     // for ConfigurationError
    #include "caosdb/log_level.h"      // for CAOSDB_DEFAULT_LOG_LEVEL, CAOSDB_...
    #include "caosdb/logging.h"        // for ConsoleSinkConfiguration, Logging...
    #include "caosdb_test_utility.h"   // for EXPECT_THROW_MESSAGE, TEST_DATA_DIR
    #include <gtest/gtest-message.h>   // for Message
    #include <gtest/gtest-test-part.h> // for TestPartResult, SuiteApiResolver
    #include <gtest/gtest_pred_impl.h> // for TestInfo, TEST_F, Test
    #include <memory>                  // for make_shared
    #include <string>                  // for operator+, allocator, string
    
    namespace caosdb::configuration {
    
    class test_configuration : public ::testing::Test {
    protected:
      void SetUp() override { ConfigurationManager::Clear(); }
      void TearDown() override { ConfigurationManager::Clear(); }
    };
    
    TEST_F(test_configuration, load_json) {
      ConfigurationManager::LoadSingleJSONConfiguration(TEST_DATA_DIR + "/test_caosdb_client.json");
      EXPECT_THROW_MESSAGE(ConfigurationManager::LoadSingleJSONConfiguration("anything"),
                           ConfigurationError, "This CaosDB client has already been configured.");
    
      ConfigurationManager::Clear();
      EXPECT_THROW_MESSAGE(ConfigurationManager::LoadSingleJSONConfiguration("anything"),
                           ConfigurationError, "Configuration file does not exist.");
      ConfigurationManager::Clear();
    }
    
    TEST_F(test_configuration, get_default_connection_configuration_error) {
      EXPECT_THROW_MESSAGE(ConfigurationManager::GetDefaultConnectionName(), ConfigurationError,
                           "This CaosDB client has not been configured.");
    
      ConfigurationManager::LoadSingleJSONConfiguration(
        TEST_DATA_DIR + "/test_broken_caosdb_client_no_connections1.json");
      EXPECT_THROW_MESSAGE(ConfigurationManager::GetDefaultConnectionName(), ConfigurationError,
                           "This CaosDB client hasn't any configured connections.");
      ConfigurationManager::Clear();
    
      ConfigurationManager::LoadSingleJSONConfiguration(
        TEST_DATA_DIR + "/test_broken_caosdb_client_no_connections2.json");
      EXPECT_THROW_MESSAGE(ConfigurationManager::GetDefaultConnectionName(), ConfigurationError,
                           "This CaosDB client hasn't any configured connections.");
      ConfigurationManager::Clear();
    
      ConfigurationManager::LoadSingleJSONConfiguration(
        TEST_DATA_DIR + "/test_broken_caosdb_client_no_connections3.json");
      EXPECT_THROW_MESSAGE(ConfigurationManager::GetDefaultConnectionName(), ConfigurationError,
                           "This CaosDB client hasn't any configured connections.");
      ConfigurationManager::Clear();
    }
    
    TEST_F(test_configuration, initialize_logging) {
      auto logging_configuration = caosdb::logging::LoggingConfiguration(CAOSDB_LOG_LEVEL_ALL);
      auto console_sink = std::make_shared<caosdb::logging::ConsoleSinkConfiguration>(
        "console", CAOSDB_DEFAULT_LOG_LEVEL);
      logging_configuration.AddSink(console_sink);
    
      initialize_logging(logging_configuration);
    }
    
    } // namespace caosdb::configuration