Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
caosdb-cppinttest
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
caosdb-cppinttest
Merge requests
!8
F files
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
F files
f-files
into
main
Overview
0
Commits
20
Pipelines
15
Changes
1
Merged
Henrik tom Wörden
requested to merge
f-files
into
main
3 years ago
Overview
0
Commits
20
Pipelines
15
Changes
1
Expand
0
0
Merge request reports
Viewing commit
0d72ee86
Prev
Next
Show latest version
1 file
+
102
−
2
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Verified
0d72ee86
WIP: file download
· 0d72ee86
Timm Fitschen
authored
3 years ago
test/test_file_transmission.cpp
0 → 100644
+
164
−
0
Options
/*
* 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
Loading