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
27fc8af1
Verified
Commit
27fc8af1
authored
2 years ago
by
Timm Fitschen
Browse files
Options
Downloads
Patches
Plain Diff
WIP: SELECT for GRPC API
parent
ef5b60b0
No related branches found
Branches containing commit
No related tags found
2 merge requests
!28
Release 0.2.2
,
!27
F grpc select
Pipeline
#29524
failed
2 years ago
Stage: info
Stage: setup
Stage: build
Stage: test
Changes
1
Pipelines
3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
test/test_select.cpp
+82
-3
82 additions, 3 deletions
test/test_select.cpp
with
82 additions
and
3 deletions
test/test_select.cpp
+
82
−
3
View file @
27fc8af1
...
...
@@ -20,28 +20,107 @@
*
*/
#include
"caosdb/connection.h"
// for Connection, ConnectionManager
#include
"caosdb/data_type.h"
// for AtomicDataType
#include
"caosdb/transaction.h"
// for Transaction, ResultTable
#include
"caosdb/value.h"
// for Value
#include
<gtest/gtest-message.h>
// for Message
#include
<gtest/gtest-test-part.h>
// for SuiteApiResolver, TestFactoryImpl
#include
<gtest/gtest_pred_impl.h>
// for Test, TestInfo, EXPECT_EQ, TEST
#include
<memory>
// for allocator, unique_ptr, __shared_p...
//
namespace
caosdb
::
transaction
{
using
caosdb
::
entity
::
AtomicDataType
;
using
caosdb
::
entity
::
Role
;
using
caosdb
::
entity
::
Property
;
using
caosdb
::
entity
::
Parent
;
using
caosdb
::
entity
::
Entity
;
using
caosdb
::
entity
::
Value
;
class
test_select
:
public
::
testing
::
Test
{
public:
static
void
DeleteEntities
()
{
// delete all entities
const
auto
&
connection
=
caosdb
::
connection
::
ConnectionManager
::
GetDefaultConnection
();
auto
query_transaction
(
connection
->
CreateTransaction
());
query_transaction
->
Query
(
"FIND Test*"
);
query_transaction
->
Execute
();
if
(
query_transaction
->
GetResultSet
().
size
()
>
0
)
{
std
::
cout
<<
"Cleanup: Deleting "
<<
query_transaction
->
GetResultSet
().
size
()
<<
" entities."
<<
std
::
endl
;
auto
delete_transaction
(
connection
->
CreateTransaction
());
for
(
const
Entity
&
entity
:
query_transaction
->
GetResultSet
())
{
delete_transaction
->
DeleteById
(
entity
.
GetId
());
}
delete_transaction
->
Execute
();
}
}
static
auto
CreateTestProp
()
->
Entity
{
Entity
entity
;
entity
.
SetRole
(
Role
::
PROPERTY
);
entity
.
SetName
(
"TestProp"
);
entity
.
SetDataType
(
AtomicDataType
::
TEXT
);
return
entity
;
}
static
auto
CreateTestRT
()
->
Entity
{
Entity
entity
;
entity
.
SetRole
(
Role
::
RECORD_TYPE
);
entity
.
SetName
(
"TestRT"
);
return
entity
;
}
static
auto
CreateRecord
(
const
std
::
string
&
property_name
,
Value
value
)
->
Entity
{
Entity
entity
;
entity
.
SetRole
(
Role
::
RECORD
);
Parent
parent
;
parent
.
SetName
(
"TestRT"
);
entity
.
AppendParent
(
parent
);
Property
property
;
property
.
SetName
(
property_name
);
property
.
SetValue
(
value
);
entity
.
AppendProperty
(
property
);
return
entity
;
}
protected
:
// Fixture methods //////////////////////////////////////////////////////////
void
SetUp
()
override
{
DeleteEntities
();
const
auto
&
connection
=
caosdb
::
connection
::
ConnectionManager
::
GetDefaultConnection
();
auto
insert_transaction
(
connection
->
CreateTransaction
());
insert_transaction
->
InsertEntity
(
CreateTestRT
());
insert_transaction
->
InsertEntity
(
CreateTestProp
());
insert_transaction
->
Execute
();
}
void
TearDown
()
override
{
DeleteEntities
();
}
};
/*
* Test select query on empty database.
*/
TEST
(
test_
transaction
,
test_select
)
{
TEST
_F
(
test_
select
,
test_select
_name
)
{
const
auto
&
connection
=
caosdb
::
connection
::
ConnectionManager
::
GetDefaultConnection
();
auto
query_transaction
(
connection
->
CreateTransaction
());
query_transaction
->
Query
(
"SELECT name FROM
ENTITY WITH id > 99
"
);
query_transaction
->
Query
(
"SELECT name FROM
RecordType TestRT
"
);
query_transaction
->
Execute
();
EXPECT_EQ
(
query_transaction
->
GetResultTable
().
size
(),
0
);
EXPECT_EQ
(
query_transaction
->
GetResultTable
().
GetHeader
().
size
(),
1
);
for
(
const
auto
&
column
:
query_transaction
->
GetResultTable
().
GetHeader
())
{
EXPECT_EQ
(
column
.
GetName
(),
"name"
);
}
EXPECT_EQ
(
query_transaction
->
GetResultTable
().
size
(),
1
);
for
(
const
auto
&
row
:
query_transaction
->
GetResultTable
().
GetRows
())
{
EXPECT_EQ
(
row
.
GetValue
(
"name"
).
GetAsString
(),
"bla"
);
}
}
}
// 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