diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 2a1612d3106959c2e5534a60fef64816c070b764..c388869d9b0df41f78f478145c61f653bde21c51 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -25,7 +25,6 @@ set(test_cases test_connection test_transaction test_list_properties - test_file_transmission test_ccaosdb ) diff --git a/test/test_file_transmission.cpp b/test/test_file_transmission.cpp deleted file mode 100644 index 0f6eeb8f4f7bc0cd0e811e8a814f1c67812feba5..0000000000000000000000000000000000000000 --- a/test/test_file_transmission.cpp +++ /dev/null @@ -1,163 +0,0 @@ -/* - * 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/connection.h" // for Connection, ConnectionManager -#include "caosdb/entity.h" -#include "caosdb/entity/v1alpha1/main.pb.h" -#include "caosdb/transaction.h" // for Transaction, UniqueRe... -#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 -namespace caosdb::transaction { -using caosdb::entity::Entity; -using caosdb::entity::v1alpha1::FileDownloadResponse; -using caosdb::entity::v1alpha1::FileUploadResponse; -using caosdb::entity::v1alpha1::RegisterFileDownloadResponse; -using caosdb::entity::v1alpha1::RegisterFileUploadResponse; -using caosdb::entity::v1alpha1::RegistrationStatus; -using caosdb::entity::v1alpha1::TransmissionStatus; - -// TODO(tf) this file is currently not used (see CMakeLists.txt) -// Is it still necessary or is it obsolete due to test_transaction.cpp? -// RegisterFileDownloadResponse is currently not defined by proto or the h -// file. - -class test_file_transmission : public ::testing::Test { -protected: - void SetUp() override {} - - void TearDown() override { - // TODO(tf): delete all created entities - } -}; - -TEST_F(test_file_transmission, register_file_upload) { - const auto &connection = - caosdb::connection::ConnectionManager::GetDefaultConnection(); - - auto transaction(connection->CreateTransaction()); - RegisterFileUploadResponse response; - EXPECT_EQ(response.status(), - RegistrationStatus::REGISTRATION_STATUS_UNSPECIFIED); - - transaction->RegisterUploadFile(&response); - - EXPECT_EQ(response.status(), - RegistrationStatus::REGISTRATION_STATUS_ACCEPTED); - EXPECT_FALSE(response.registration_id().empty()); -} - -TEST_F(test_file_transmission, file_upload) { - const auto &connection = - caosdb::connection::ConnectionManager::GetDefaultConnection(); - - auto transaction(connection->CreateTransaction()); - RegisterFileUploadResponse registration_response; - - transaction->RegisterUploadFile(®istration_response); - ASSERT_EQ(registration_response.status(), - RegistrationStatus::REGISTRATION_STATUS_ACCEPTED); - auto registration_id = registration_response.registration_id(); - - FileUploadResponse upload_response; - transaction->UploadFile(&upload_response, registration_id); - - EXPECT_EQ(upload_response.status(), - TransmissionStatus::TRANSMISSION_STATUS_GO_ON); -} - -TEST_F(test_file_transmission, file_insertion) { - const auto &connection = - caosdb::connection::ConnectionManager::GetDefaultConnection(); - - auto transaction(connection->CreateTransaction()); - RegisterFileUploadResponse registration_response; - - transaction->RegisterUploadFile(®istration_response); - ASSERT_EQ(registration_response.status(), - RegistrationStatus::REGISTRATION_STATUS_ACCEPTED); - auto registration_id = registration_response.registration_id(); - - FileUploadResponse upload_response; - transaction->UploadFile(&upload_response, registration_id); - - Entity file_entity; - file_entity.SetRole("File"); - file_entity.SetFileTransmissionId(registration_id, "test.txt"); - file_entity.SetFilePath("test.txt"); - - transaction->InsertEntity(&file_entity); - transaction->Execute(); - - auto cleanup_transaction(connection->CreateTransaction()); - cleanup_transaction->DeleteById(transaction->GetResultSet().At(0).GetId()); - cleanup_transaction->Execute(); -} - -TEST_F(test_file_transmission, file_download) { - const auto &connection = - caosdb::connection::ConnectionManager::GetDefaultConnection(); - - auto upload_transaction(connection->CreateTransaction()); - RegisterFileUploadResponse upload_registration_response; - - upload_transaction->RegisterUploadFile(&upload_registration_response); - ASSERT_EQ(upload_registration_response.status(), - RegistrationStatus::REGISTRATION_STATUS_ACCEPTED); - auto registration_id = upload_registration_response.registration_id(); - - FileUploadResponse upload_response; - upload_transaction->UploadFile(&upload_response, registration_id); - - Entity file_entity; - file_entity.SetRole("File"); - file_entity.SetFileTransmissionId(registration_id, "test.txt"); - file_entity.SetFilePath("test.txt"); - - upload_transaction->InsertEntity(&file_entity); - upload_transaction->Execute(); - - // Download by entity_id - auto download_transaction(connection->CreateTransaction()); - RegisterFileDownloadResponse download_registration_response; - RegisterFileDownloadRequest download_registration_request; - download_registration_request.add_files()->set_entity_id( - upload_transaction->GetResultSet().At(0).GetId()); - download_transaction->RegisterDownloadFile(download_registration_request, - &download_registration_response); - ASSERT_EQ(download_registration_response.status(), - RegistrationStatus::REGISTRATION_STATUS_ACCEPTED); - - FileDownloadResponse download_response; - download_transaction->DownloadFile(&download_response, - download_registration_response); - - EXPECT_EQ(download_response.chunk().data(), "this is some data"); - - // CLEANUP - auto cleanup_transaction(connection->CreateTransaction()); - cleanup_transaction->DeleteById( - upload_transaction->GetResultSet().At(0).GetId()); - cleanup_transaction->Execute(); -} - -} // namespace caosdb::transaction