From 9785bdb4e304d135cd127ffd164612846bb4980c Mon Sep 17 00:00:00 2001 From: Timm Fitschen <t.fitschen@indiscale.com> Date: Tue, 10 Aug 2021 17:11:11 +0200 Subject: [PATCH] WIP: files --- conanfile.txt | 2 +- test/CMakeLists.txt | 4 +-- test/test_transaction.cpp | 74 +++++++++++++++++++++++++++++++++++---- 3 files changed, 71 insertions(+), 9 deletions(-) diff --git a/conanfile.txt b/conanfile.txt index a5a7c5f..ccd05f4 100644 --- a/conanfile.txt +++ b/conanfile.txt @@ -1,5 +1,5 @@ [requires] -caosdb/0.0.10 +caosdb/0.0.11 gtest/1.11.0 [generators] diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 9f430b9..1bba969 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -23,7 +23,6 @@ ####################################################################### set(test_cases test_connection - test_file_transmission test_transaction test_ccaosdb ) @@ -106,7 +105,8 @@ foreach (i RANGE "${len_test_cases}") target_link_libraries(${test_case_name} PRIVATE ${CONAN_LIBS_CAOSDB} ${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}) + ${CONAN_LIBS_PROTOBUF} ${CONAN_LIBS_ZLIB} ${CONAN_LIBS_RE2} + ${CONAN_LIBS_BOOST}) target_include_directories(${test_case_name} PUBLIC ${CONAN_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR}) if(LINTING) diff --git a/test/test_transaction.cpp b/test/test_transaction.cpp index 79cdb12..be750d9 100644 --- a/test/test_transaction.cpp +++ b/test/test_transaction.cpp @@ -24,12 +24,14 @@ #include "caosdb/status_code.h" // for SUCCESS, StatusCode #include "caosdb/transaction.h" // for Entity, Transaction, UniqueRe... #include "caosdb/transaction_status.h" // for TransactionStatus, StatusCode -#include "gtest/gtest-message.h" // for Message -#include "gtest/gtest-test-part.h" // for TestPartResult, SuiteApiResolver -#include "gtest/gtest_pred_impl.h" // for Test, EXPECT_EQ, AssertionResult -#include <memory> // for unique_ptr, allocator, __shar... -#include <string> // for string -#include <vector> // for vector +#include <boost/filesystem/path.hpp> +#include "gtest/gtest-message.h" // for Message +#include "gtest/gtest-test-part.h" // for TestPartResult, SuiteApiResolver +#include "gtest/gtest_pred_impl.h" // for Test, EXPECT_EQ, AssertionResult +#include <iostream> +#include <memory> // for unique_ptr, allocator, __shar... +#include <string> // for string +#include <vector> // for vector namespace caosdb::transaction { using caosdb::entity::Entity; using caosdb::entity::MessageCode; @@ -656,4 +658,64 @@ TEST_F(test_transaction, test_query_with_retrieve) { EXPECT_EQ(count_and_retrieve->GetCountResult(), 3); } +TEST_F(test_transaction, test_file_upload) { + const auto &connection = + caosdb::connection::ConnectionManager::GetDefaultConnection(); + + Entity file; + file.SetRole("File"); + file.SetFilePath("test.txt"); + file.SetLocalPath("test.txt"); + + auto insert_transaction(connection->CreateTransaction()); + insert_transaction->InsertEntity(&file); + insert_transaction->ExecuteAsynchronously(); + + auto insert_status = insert_transaction->WaitForIt(); + + ASSERT_TRUE(insert_status.IsTerminated()); + EXPECT_EQ(insert_status.GetCode(), StatusCode::SUCCESS); + + const auto &insert_results = + dynamic_cast<const UniqueResult &>(insert_transaction->GetResultSet()); + + const auto &inserted_file = insert_results.GetEntity(); + EXPECT_FALSE(inserted_file.GetId().empty()); + EXPECT_FALSE(inserted_file.HasErrors()); +} + +TEST_F(test_transaction, test_file_download) { + const auto &connection = + caosdb::connection::ConnectionManager::GetDefaultConnection(); + + Entity file; + file.SetRole("File"); + file.SetFilePath("test.txt"); + file.SetLocalPath("test.txt"); + + auto insert_transaction(connection->CreateTransaction()); + insert_transaction->InsertEntity(&file); + insert_transaction->Execute(); + + const auto &insert_results = insert_transaction->GetResultSet(); + + const auto &inserted_file = insert_results.At(0); + ASSERT_FALSE(inserted_file.GetId().empty()); + ASSERT_FALSE(inserted_file.HasErrors()); + + auto download_transaction(connection->CreateTransaction()); + download_transaction->RetrieveAndDownloadFilesById(inserted_file.GetId(), + "downloaded.txt"); + download_transaction->ExecuteAsynchronously(); + download_transaction->WaitForIt(); + + const auto &download_results = download_transaction->GetResultSet(); + ASSERT_EQ(download_results.Size(), 1); + + const auto &downloaded_file = download_results.At(0); + ASSERT_FALSE(downloaded_file.GetId().empty()); + ASSERT_FALSE(downloaded_file.HasErrors()); + EXPECT_EQ(downloaded_file.GetLocalPath().string(), "downloaded.txt"); +} + } // namespace caosdb::transaction -- GitLab