Skip to content
Snippets Groups Projects
Verified Commit 20f979b4 authored by Timm Fitschen's avatar Timm Fitschen
Browse files

WIP: retrieve single entity

parent 49903b45
No related branches found
No related tags found
Loading
Pipeline #9990 failed
......@@ -76,7 +76,8 @@ foreach (i RANGE "${len_test_cases}")
${CONAN_LIBS_GTEST} ${CONAN_LIBS_GRPC} ${CONAN_LIBS_ABSEIL}
${CONAN_LIBS_OPENSSL} ${CONAN_LIBS_C-ARES} ${CONAN_LIBS_BZIP2}
${CONAN_LIBS_PROTOBUF} ${CONAN_LIBS_ZLIB} ${CONAN_LIBS_RE2})
target_include_directories(${test_case_name} PUBLIC ${CONAN_INCLUDE_DIRS})
target_include_directories(${test_case_name}
PUBLIC ${CONAN_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR})
set_target_properties(${test_case_name}
PROPERTIES
CXX_CLANG_TIDY "${_CMAKE_CXX_CLANG_TIDY};${_CMAKE_CXX_CLANG_TIDY_CHECKS}"
......
/*
*
* 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/>.
*
*/
#ifndef CAOSDB_TEST_UTILITY_H
#define CAOSDB_TEST_UTILITY_H
/**
* WARNING: THIS FILE IS MAINTAINED AS PART OF THE caosdb-cpplib. Please commit
* changes there and keep these files in sync!
*
* @file caosdb_test_utility.h
* @brief Utility for the unit tests
* @author Timm Fitschen
* @date 2021-07-07
*/
#define EXPECT_THROW_MESSAGE(statement, exeption_type, message) EXPECT_THROW( \
try { \
statement; \
} catch (const exeption_type& e) { \
EXPECT_EQ(std::string(e.what()), message); \
throw; \
}, exeption_type)
#define ASSERT_THROW_MESSAGE(statement, exeption_type, message) ASSERT_THROW( \
try { \
statement; \
} catch (const exeption_type& e) { \
ASSERT_EQ(std::string(e.what()), message); \
throw; \
}, exeption_type)
#endif
......@@ -50,7 +50,7 @@ TEST(test_connection, connect_somehost_42347_fails) {
auto config = std::make_shared<InsecureCaosDBConnectionConfig>(pHost, port);
CaosDBConnection connection(config);
EXPECT_THROW(connection.getVersionInfo(), ConnectionError);
EXPECT_THROW(connection.GetVersionInfo(), ConnectionError);
}
TEST(test_connection, connection_insecure_authentication_error_wrong_credentials) {
......@@ -65,7 +65,7 @@ TEST(test_connection, connection_insecure_authentication_error_wrong_credentials
auto config = std::make_shared<InsecureCaosDBConnectionConfig>(host, port, auth);
auto connection = CaosDBConnection(config);
EXPECT_THROW(connection.getVersionInfo(), AuthenticationError);
EXPECT_THROW(connection.GetVersionInfo(), AuthenticationError);
}
......@@ -77,7 +77,7 @@ TEST(test_connection, connection_insecure_authentication_error_anonymous) {
auto config = std::make_shared<InsecureCaosDBConnectionConfig>(host, port);
auto connection = CaosDBConnection(config);
EXPECT_THROW(connection.getVersionInfo(), AuthenticationError);
EXPECT_THROW(connection.GetVersionInfo(), AuthenticationError);
}
TEST(test_connection, connection_ssl_authentication_error_anonymous) {
......@@ -90,7 +90,7 @@ TEST(test_connection, connection_ssl_authentication_error_anonymous) {
auto config = std::make_shared<SslCaosDBConnectionConfig>(host, port, ssloptions);
auto connection = CaosDBConnection(config);
EXPECT_THROW(connection.getVersionInfo(), AuthenticationError);
EXPECT_THROW(connection.GetVersionInfo(), AuthenticationError);
}
TEST(test_connection, connection_ssl_authentication_error_wrong_credentials) {
......@@ -106,7 +106,7 @@ TEST(test_connection, connection_ssl_authentication_error_wrong_credentials) {
auto config = std::make_shared<SslCaosDBConnectionConfig>(host, port, ssloptions, auth);
auto connection = CaosDBConnection(config);
EXPECT_THROW(connection.getVersionInfo(), AuthenticationError);
EXPECT_THROW(connection.GetVersionInfo(), AuthenticationError);
}
TEST(test_connection, connection_ssl_authentication_success) {
......
/*
* 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/transaction.h"
#include <gtest/gtest-message.h> // for Message
#include <gtest/gtest-test-part.h> // for SuiteApiResolver, TestPartResult
#include <memory> // for make_shared, allocator, shared_ptr
#include <string> // for string
#include "caosdb/authentication.h" // for PlainPasswordAuthenticator
#include "caosdb/connection.h" // for InsecureCaosDBConnectionConfig
#include "caosdb/exceptions.h" // for AuthenticationError, ConnectionError
#include "caosdb/utils.h" // for get_env_var
#include "gtest/gtest_pred_impl.h" // for Test, TEST, EXPECT_EQ, EXPECT_THROW
namespace caosdb::transaction {
TEST(test_transaction, first_test) {
auto port_str = caosdb::utils::get_env_var("CAOSDB_SERVER_GRPC_PORT_HTTP", "8080");
auto port = std::stoi(port_str);
const auto host = caosdb::utils::get_env_var("CAOSDB_SERVER_HOST", "localhost");
const auto user = caosdb::utils::get_env_var("CAOSDB_USER", "admin");
const auto password = caosdb::utils::get_env_var("CAOSDB_PASSWORD", "caosdb");
const auto *const description = "This is an entity";
auto auth = std::make_shared<PlainPasswordAuthenticator>(user, password);
auto config = std::make_shared<SslCaosDBConnectionConfig>(host, port, auth);
auto connection = CaosDBConnection(config);
auto transaction(connection.CreateTransaction());
transaction->Retrieve(caosdb::entity::EntityID("someid"));
transaction->Execute();
auto result_set(std::static_pointer_cast<caosdb::transaction::UniqueResult>(
transaction->GetResultSet()));
EXPECT_EQ(description, result_set->GetEntity().GetDescription());
}
} //namespace caosdb::connection
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment