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

Removed test_file_transmission.cpp

parent ff0558ec
No related branches found
No related tags found
1 merge request!9F consolidation
Pipeline #12226 passed
......@@ -25,7 +25,6 @@ set(test_cases
test_connection
test_transaction
test_list_properties
test_file_transmission
test_ccaosdb
)
......
/*
* 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(&registration_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(&registration_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
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