Skip to content
Snippets Groups Projects
Select Git revision
  • 8f115afb21ffc5d8cfc6ba38a94ad8a7a58afb30
  • main default protected
  • f-sss4grpc
  • dev
  • 108-implement-rpc-call-for-server-side-scripting
  • f-windows-conan-create
  • f-to-string
  • f-update-requirements
  • f-related-projects
  • f-role
  • f-remote-path
  • f-rel-path
  • f-consol-message
  • v0.3.0
  • v0.2.2
  • v0.2.1
  • v0.2.0
  • v0.1.2
  • v0.1.1
  • v0.1
  • v0.0.19
  • v0.0.18
  • v0.0.16
  • v0.0.15
  • v0.0.10
  • v0.0.9
  • v0.0.8
  • v0.0.7
  • v0.0.6
  • v0.0.5
  • v0.0.4
  • v0.0.3
  • v0.0.2
33 results

test_configuration.cpp

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    test_configuration.cpp 4.14 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(); }
    };
    
    // TODO(tf) cogintive complexity > 25 (threshold)
    TEST_F(test_configuration, load_json) { // NOLINT
      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();
    }
    
    // TODO(tf) cognitive complexity again
    TEST_F(test_configuration,                           // NOLINT
           get_default_connection_configuration_error) { // NOLINT
      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