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
Commits
a77f58e4
Commit
a77f58e4
authored
3 years ago
by
florian
Browse files
Options
Downloads
Patches
Plain Diff
DRAFT: Test inertion of a record with a property
parent
9f454df6
No related branches found
No related tags found
1 merge request
!3
TST: Add Tests for insert and delete
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
test/test_transaction.cpp
+109
-5
109 additions, 5 deletions
test/test_transaction.cpp
with
109 additions
and
5 deletions
test/test_transaction.cpp
+
109
−
5
View file @
a77f58e4
...
@@ -35,6 +35,7 @@ namespace caosdb::transaction {
...
@@ -35,6 +35,7 @@ namespace caosdb::transaction {
using
caosdb
::
entity
::
Entity
;
using
caosdb
::
entity
::
Entity
;
using
caosdb
::
entity
::
MessageCode
;
using
caosdb
::
entity
::
MessageCode
;
using
caosdb
::
entity
::
Parent
;
using
caosdb
::
entity
::
Parent
;
using
caosdb
::
entity
::
Property
;
class
test_transaction
:
public
::
testing
::
Test
{
class
test_transaction
:
public
::
testing
::
Test
{
protected:
protected:
...
@@ -95,8 +96,7 @@ TEST(test_transaction, retrieve_non_existing) {
...
@@ -95,8 +96,7 @@ TEST(test_transaction, retrieve_non_existing) {
MessageCode
::
ENTITY_DOES_NOT_EXIST
);
MessageCode
::
ENTITY_DOES_NOT_EXIST
);
}
}
// TODO(fspreck) cognitive complexity > 25 (threshold)
TEST
(
test_transaction
,
insert_delete
)
{
TEST
(
test_transaction
,
insert_delete
)
{
// NOLINT
const
auto
&
connection
=
const
auto
&
connection
=
caosdb
::
connection
::
ConnectionManager
::
GetDefaultConnection
();
caosdb
::
connection
::
ConnectionManager
::
GetDefaultConnection
();
...
@@ -143,9 +143,7 @@ TEST(test_transaction, insert_delete) { // NOLINT
...
@@ -143,9 +143,7 @@ TEST(test_transaction, insert_delete) { // NOLINT
EXPECT_FALSE
(
deleted_entity
.
HasErrors
());
EXPECT_FALSE
(
deleted_entity
.
HasErrors
());
}
}
// TODO(fspreck) Simplify inserts and deletes once we have
TEST
(
test_transaction
,
insert_delete_with_parent
)
{
// multi-entity operations, also cognitive complexity > threshold
TEST
(
test_transaction
,
insert_delete_with_parent
)
{
// NOLINT
const
auto
&
connection
=
const
auto
&
connection
=
caosdb
::
connection
::
ConnectionManager
::
GetDefaultConnection
();
caosdb
::
connection
::
ConnectionManager
::
GetDefaultConnection
();
...
@@ -235,5 +233,111 @@ TEST(test_transaction, insert_delete_with_parent) { // NOLINT
...
@@ -235,5 +233,111 @@ TEST(test_transaction, insert_delete_with_parent) { // NOLINT
// TODO(fspreck) Insert a Record with a parent and a Property. Check
// TODO(fspreck) Insert a Record with a parent and a Property. Check
// for success and delete everything.
// for success and delete everything.
TEST
(
test_transaction
,
insert_delete_with_property
)
{
const
auto
&
connection
=
caosdb
::
connection
::
ConnectionManager
::
GetDefaultConnection
();
// Create and insert property
Entity
prop_ent
;
prop_ent
.
SetRole
(
"Property"
);
prop_ent
.
SetName
(
"TestProperty"
);
prop_ent
.
SetDatatype
(
"TEXT"
);
auto
prop_insertion
(
connection
->
CreateTransaction
());
prop_insertion
->
InsertEntity
(
&
prop_ent
);
prop_insertion
->
ExecuteAsynchronously
();
auto
prop_insert_status
=
prop_insertion
->
WaitForIt
();
ASSERT_TRUE
(
prop_insert_status
.
IsTerminated
());
ASSERT_FALSE
(
prop_insert_status
.
IsError
());
const
auto
&
prop_result_set
=
dynamic_cast
<
const
UniqueResult
&>
(
prop_insertion
->
GetResultSet
());
const
auto
&
inserted_prop
=
prop_result_set
.
GetEntity
();
EXPECT_FALSE
(
inserted_prop
.
GetId
().
empty
());
// create and insert record type with the above property
Property
prop_rt
;
prop_rt
.
SetName
(
prop_ent
.
GetName
());
prop_rt
.
SetId
(
inserted_prop
.
GetId
());
prop_rt
.
SetImportance
(
"SUGGESTED"
);
Entity
rt
;
rt
.
SetRole
(
"RecordType"
);
rt
.
SetName
(
"TestRT"
);
rt
.
AppendProperty
(
prop_rt
);
auto
rt_insertion
(
connection
->
CreateTransaction
());
rt_insertion
->
InsertEntity
(
&
rt
);
rt_insertion
->
ExecuteAsynchronously
();
auto
rt_insert_status
=
rt_insertion
->
WaitForIt
();
ASSERT_TRUE
(
rt_insert_status
.
IsTerminated
());
ASSERT_FALSE
(
rt_insert_status
.
IsError
());
const
auto
&
rt_result_set
=
dynamic_cast
<
const
UniqueResult
&>
(
rt_insertion
->
GetResultSet
());
const
auto
&
inserted_rt
=
rt_result_set
.
GetEntity
();
EXPECT_FALSE
(
inserted_rt
.
GetId
().
empty
());
// retrieve inserted rt for testing
auto
rt_retrieval
(
connection
->
CreateTransaction
());
rt_retrieval
->
RetrieveById
(
inserted_rt
.
GetId
());
rt_retrieval
->
ExecuteAsynchronously
();
auto
rt_retrieve_status
=
rt_retrieval
->
WaitForIt
();
ASSERT_TRUE
(
rt_retrieve_status
.
IsTerminated
());
ASSERT_FALSE
(
rt_retrieve_status
.
IsError
());
const
auto
&
rt_retrieve_results
=
dynamic_cast
<
const
UniqueResult
&>
(
rt_retrieval
->
GetResultSet
());
const
auto
&
retrieved_rt
=
rt_retrieve_results
.
GetEntity
();
EXPECT_EQ
(
inserted_rt
.
GetId
(),
retrieved_rt
.
GetId
());
EXPECT_EQ
(
rt
.
GetName
(),
retrieved_rt
.
GetName
());
EXPECT_EQ
(
retrieved_rt
.
GetProperties
().
Size
(),
1
);
const
auto
&
retrieved_prop_rt
=
retrieved_rt
.
GetProperties
().
At
(
0
);
EXPECT_EQ
(
retrieved_prop_rt
.
GetName
(),
prop_ent
.
GetName
());
EXPECT_EQ
(
retrieved_prop_rt
.
GetId
(),
inserted_prop
.
GetId
());
EXPECT_EQ
(
retrieved_prop_rt
.
GetDatatype
(),
prop_ent
.
GetDatatype
());
EXPECT_EQ
(
retrieved_prop_rt
.
GetImportance
(),
prop_rt
.
GetImportance
());
// create and insert record of the above record type with a property
// with a value.
Parent
parent
;
parent
.
SetName
(
rt
.
GetName
());
parent
.
SetId
(
inserted_rt
.
GetId
());
Property
prop_rec
;
prop_rec
.
SetName
(
prop_ent
.
GetName
());
prop_rec
.
SetId
(
inserted_prop
.
GetId
());
prop_rec
.
SetValue
(
"Test"
);
Entity
rec
;
rec
.
SetName
(
"TestRec"
);
rec
.
SetRole
(
"Record"
);
rec
.
AppendParent
(
parent
);
rec
.
AppendProperty
(
prop_rec
);
auto
rec_insertion
(
connection
->
CreateTransaction
());
rec_insertion
->
InsertEntity
(
&
rec
);
rec_insertion
->
ExecuteAsynchronously
();
auto
rec_insert_status
=
rec_insertion
->
WaitForIt
();
ASSERT_TRUE
(
rec_insert_status
.
IsTerminated
());
ASSERT_FALSE
(
rec_insert_status
.
IsError
());
const
auto
&
rec_result_set
=
dynamic_cast
<
const
UniqueResult
&>
(
rec_insertion
->
GetResultSet
());
const
auto
&
inserted_rec
=
rec_result_set
.
GetEntity
();
EXPECT_FALSE
(
inserted_rec
.
GetId
().
empty
());
}
}
// namespace caosdb::transaction
}
// namespace caosdb::transaction
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment