From 1c57270ac98a05622524440df66ae453229082db Mon Sep 17 00:00:00 2001
From: Daniel <d.hornung@indiscale.com>
Date: Wed, 25 Aug 2021 11:33:35 +0200
Subject: [PATCH] WIP TEST: Wrote test which did not fail before.

Probably there should be a similar test for ccaosdb.
---
 include/caosdb/utility.h               | 11 ++++++-----
 src/caosdb/connection.cpp              |  4 ++--
 src/ccaosdb.cpp                        |  1 +
 test/test_connection.cpp               | 13 ++++++++++---
 test/test_data/test_caosdb_client.json | 10 ++++++++++
 5 files changed, 29 insertions(+), 10 deletions(-)

diff --git a/include/caosdb/utility.h b/include/caosdb/utility.h
index 763646f..568f8c9 100644
--- a/include/caosdb/utility.h
+++ b/include/caosdb/utility.h
@@ -91,12 +91,13 @@ auto getEnumValueFromName<caosdb::entity::Role>(const std::string &name) -> caos
  */
 inline auto load_string_file(const path &path) -> std::string {
   std::string result;
-  try {
+  // TODO(htw)
+  // try {
     boost::filesystem::load_string_file(path, result);
-  } catch (const std::exception &exc) {
-    throw caosdb::exceptions::Exception(StatusCode::FILE_CANNOT_BE_READ ,
-                                          "Cannot read the following file: "+ path.string());
-  }
+  // } catch (const std::exception &exc) {
+  //   throw caosdb::exceptions::Exception(StatusCode::FILE_CANNOT_BE_READ ,
+  //                                         "Cannot read the following file: "+ path.string());
+  // }
   return result;
 }
 
diff --git a/src/caosdb/connection.cpp b/src/caosdb/connection.cpp
index d6782f8..9d27c5c 100644
--- a/src/caosdb/connection.cpp
+++ b/src/caosdb/connection.cpp
@@ -109,8 +109,8 @@ auto ConnectionManager::mGetConnection(const std::string &name) const
       auto connection = ConfigurationManager::GetConnectionConfiguration(name);
       connections[name] = std::make_shared<Connection>(*connection.release());
     } catch (const caosdb::exceptions::ConfigurationError &exc) {
-      throw caosdb::exceptions::UnknownConnectionError("No connection named '" + name +
-                                                       "' present.");
+      throw caosdb::exceptions::UnknownConnectionError("Error with the connection named '" + name +
+                                                       "': " + exc.what());
     }
   }
   return this->connections.at(name);
diff --git a/src/ccaosdb.cpp b/src/ccaosdb.cpp
index d5165c9..c506e44 100644
--- a/src/ccaosdb.cpp
+++ b/src/ccaosdb.cpp
@@ -185,6 +185,7 @@ ERROR_RETURN_CODE(GENERIC_ERROR,
                     if (out->_deletable) {
                       return caosdb::StatusCode::EXTERN_C_ASSIGNMENT_ERROR;
                     }
+                    // TODO(htw) eitehr check for file existence or call CreateCertificateProvider?
                     out->wrapped_certificate_provider =
                       new caosdb::configuration::PemFileCertificateProvider(std::string(path));
                     out->_deletable = true;
diff --git a/test/test_connection.cpp b/test/test_connection.cpp
index 9939153..86eae20 100644
--- a/test/test_connection.cpp
+++ b/test/test_connection.cpp
@@ -65,9 +65,16 @@ TEST_F(test_connection, configure_ssl_localhost_8080) {
 }
 
 TEST_F(test_connection, connection_manager_unknown_connection) {
-  EXPECT_THROW_MESSAGE(ConnectionManager::GetConnection("test"),
-                       caosdb::exceptions::UnknownConnectionError,
-                       "No connection named 'test' present.");
+  EXPECT_THROW_MESSAGE(
+      ConnectionManager::GetConnection("test"), caosdb::exceptions::UnknownConnectionError,
+      "Error with the connection named 'test': The connection 'test' has not been defined.");
+}
+
+TEST_F(test_connection, connection_missing_certificate) {
+  EXPECT_THROW_MESSAGE(
+      ConnectionManager::GetConnection("missing"), caosdb::exceptions::UnknownConnectionError,
+      std::string("Error with the connection named 'missing': ")
+      + "File does not exist (server_certificate_path): /missing");
 }
 
 TEST_F(test_connection, connection_manager_get_default_connection) {
diff --git a/test/test_data/test_caosdb_client.json b/test/test_data/test_caosdb_client.json
index 2007413..276c542 100644
--- a/test/test_data/test_caosdb_client.json
+++ b/test/test_data/test_caosdb_client.json
@@ -13,6 +13,16 @@
     "local-caosdb": {
       "host": "localhost",
       "port": 8443,
+      "authentication": {
+        "type": "plain",
+        "username": "me",
+          "password": "secret!"
+      }
+    },
+    "missing": {
+      "host": "localhost",
+      "port": 8443,
+      "server_certificate_path": "/missing",
       "authentication": {
         "type": "plain",
         "username": "me",
-- 
GitLab