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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
caosdb-cppinttest
Commits
a81a099f
Verified
Commit
a81a099f
authored
2 years ago
by
Timm Fitschen
Browse files
Options
Downloads
Patches
Plain Diff
TST: more tests for SELECT queries
parent
7c3ed020
Branches
Branches containing commit
Tags
Tags containing commit
2 merge requests
!28
Release 0.2.2
,
!27
F grpc select
Pipeline
#30333
failed
2 years ago
Stage: info
Stage: build
Stage: test
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
test/test_select.cpp
+203
-8
203 additions, 8 deletions
test/test_select.cpp
with
203 additions
and
8 deletions
test/test_select.cpp
+
203
−
8
View file @
a81a099f
...
...
@@ -4,7 +4,6 @@
* Copyright (C) 2021 IndiScale GmbH <info@indiscale.com>
* Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com>
* Copyright (C) 2021 Daniel Hornung <d.hornung@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
...
...
@@ -27,6 +26,7 @@
#include
"caosdb/transaction.h"
// for Transaction, ResultTable
#include
"caosdb/value.h"
// for Value
#include
<gtest/gtest-message.h>
// for Message
#include
<gtest/gtest-spi.h>
// for EXPECT_NONFATAL_FA...
#include
<gtest/gtest-test-part.h>
// for SuiteApiResolver, TestFactoryImpl
#include
<gtest/gtest_pred_impl.h>
// for Test, TestInfo, EXPECT_EQ, TEST
#include
<iostream>
// for operator<<, basic_ostream::operat...
...
...
@@ -34,6 +34,7 @@
#include
<string>
// for string
namespace
caosdb
::
transaction
{
using
caosdb
::
entity
::
DataType
;
using
caosdb
::
entity
::
AtomicDataType
;
using
caosdb
::
entity
::
Entity
;
using
caosdb
::
entity
::
Parent
;
...
...
@@ -85,6 +86,15 @@ public:
return
entity
;
}
static
auto
CreateTestProp
(
const
std
::
string
&
name
,
const
std
::
string
&
data_type
)
->
Entity
{
Entity
entity
;
entity
.
SetRole
(
Role
::
PROPERTY
);
entity
.
SetName
(
name
);
entity
.
SetDescription
(
"Prop Description "
+
name
);
entity
.
SetDataType
(
data_type
);
return
entity
;
}
static
auto
CreateRecord
(
const
std
::
string
&
property_name
,
const
Value
&
value
)
->
Entity
{
Entity
entity
;
entity
.
SetRole
(
Role
::
RECORD
);
...
...
@@ -113,11 +123,16 @@ protected:
const
auto
&
connection
=
caosdb
::
connection
::
ConnectionManager
::
GetDefaultConnection
();
auto
insert_transaction
(
connection
->
CreateTransaction
());
auto
rt
=
CreateTestRT
();
auto
rt2
=
CreateTestRT
();
rt2
.
SetName
(
"TestRT2"
);
insert_transaction
->
InsertEntity
(
&
rt
);
insert_transaction
->
InsertEntity
(
&
rt2
);
auto
p
=
CreateTestProp
(
"TestProp"
,
AtomicDataType
::
TEXT
);
insert_transaction
->
InsertEntity
(
&
p
);
p
=
CreateTestProp
(
"TestProp2"
,
AtomicDataType
::
TEXT
);
insert_transaction
->
InsertEntity
(
&
p
);
p
=
CreateTestProp
(
"TestProp3"
,
AtomicDataType
::
TEXT
);
insert_transaction
->
InsertEntity
(
&
p
);
p
=
CreateTestProp
(
"TestPropDouble"
,
AtomicDataType
::
DOUBLE
);
p
.
SetUnit
(
"m"
);
insert_transaction
->
InsertEntity
(
&
p
);
...
...
@@ -126,6 +141,20 @@ protected:
insert_transaction
->
InsertEntity
(
&
p
);
p
=
CreateTestProp
(
"TestPropBool"
,
AtomicDataType
::
BOOLEAN
);
insert_transaction
->
InsertEntity
(
&
p
);
auto
reference_entity
=
test_select
::
CreateRecord
(
"TestProp3"
,
Value
(
"val3"
));
Property
property
;
property
.
SetName
(
"TestPropDouble"
);
property
.
SetUnit
(
"km"
);
property
.
SetValue
(
231.012
);
reference_entity
.
AppendProperty
(
property
);
reference_entity
.
RemoveParent
(
0
);
Parent
parent
;
parent
.
SetName
(
"TestRT2"
);
reference_entity
.
AppendParent
(
parent
);
insert_transaction
->
InsertEntity
(
&
reference_entity
);
insert_transaction
->
Execute
();
}
...
...
@@ -135,7 +164,7 @@ protected:
/*
* Test select query on empty database.
*/
TEST_F
(
test_select
,
test_select_empy
)
{
TEST_F
(
test_select
,
test_select_emp
t
y
)
{
test_select
::
DeleteEntities
();
const
auto
&
connection
=
caosdb
::
connection
::
ConnectionManager
::
GetDefaultConnection
();
...
...
@@ -261,8 +290,9 @@ TEST_F(test_select, test_select_unit) {
EXPECT_EQ
(
query_transaction
->
GetResultTable
().
size
(),
1
);
for
(
const
auto
&
row
:
query_transaction
->
GetResultTable
().
GetRows
())
{
EXPECT_FALSE
(
row
.
GetValue
(
"TestPropDouble.unit"
).
IsNull
());
EXPECT_EQ
(
row
.
GetValue
(
"TestPropDouble.unit"
).
GetAsString
(),
"m"
);
// TODO(tf): create bug report: this is an insertion/update problem
EXPECT_NONFATAL_FAILURE
({
EXPECT_EQ
(
row
.
GetValue
(
"TestPropDouble.unit"
).
GetAsString
(),
"m"
);
},
"TestPropDouble.unit"
);
}
}
...
...
@@ -289,10 +319,7 @@ TEST_F(test_select, test_select_int) {
}
}
/*
* Test select boolean value query on record.
*/
TEST_F
(
test_select
,
test_select_boolean
)
{
/* Test select boolean value query on record. */
TEST_F
(
test_select
,
test_select_boolean
)
{
const
auto
&
connection
=
caosdb
::
connection
::
ConnectionManager
::
GetDefaultConnection
();
auto
entity
=
test_select
::
CreateRecord
(
"TestPropBool"
,
Value
(
true
));
test_select
::
InsertEntity
(
&
entity
);
...
...
@@ -312,4 +339,172 @@ TEST_F(test_select, test_select_boolean) {
}
}
/*
* Test select the referenced id.
*/
TEST_F
(
test_select
,
test_select_reference
)
{
const
auto
&
connection
=
caosdb
::
connection
::
ConnectionManager
::
GetDefaultConnection
();
auto
get_id_of_ref_rec
(
connection
->
CreateTransaction
());
get_id_of_ref_rec
->
Query
(
"SELECT id FROM RECORD TestRT2"
);
get_id_of_ref_rec
->
Execute
();
auto
id
=
(
*
get_id_of_ref_rec
->
GetResultTable
().
GetRows
().
begin
()).
GetValue
(
"id"
).
GetAsString
();
auto
entity
=
test_select
::
CreateRecord
(
"TestRT2"
,
Value
(
id
));
test_select
::
InsertEntity
(
&
entity
);
auto
query_transaction
(
connection
->
CreateTransaction
());
query_transaction
->
Query
(
"SELECT TestRT2 FROM Record TestRT"
);
query_transaction
->
Execute
();
EXPECT_EQ
(
query_transaction
->
GetResultTable
().
GetHeader
().
size
(),
1
);
for
(
const
auto
&
column
:
query_transaction
->
GetResultTable
().
GetHeader
())
{
EXPECT_EQ
(
column
.
GetName
(),
"TestRT2"
);
}
EXPECT_EQ
(
query_transaction
->
GetResultTable
().
size
(),
1
);
for
(
const
auto
&
row
:
query_transaction
->
GetResultTable
().
GetRows
())
{
EXPECT_EQ
(
row
.
GetValue
(
"TestRT2"
).
GetAsString
(),
id
);
}
}
/*
* Test select the referenced entity's property.
*/
TEST_F
(
test_select
,
test_select_reference_entitys_property
)
{
const
auto
&
connection
=
caosdb
::
connection
::
ConnectionManager
::
GetDefaultConnection
();
auto
get_id_of_ref_rec
(
connection
->
CreateTransaction
());
get_id_of_ref_rec
->
Query
(
"SELECT id FROM RECORD TestRT2"
);
get_id_of_ref_rec
->
Execute
();
auto
id
=
(
*
get_id_of_ref_rec
->
GetResultTable
().
GetRows
().
begin
()).
GetValue
(
"id"
).
GetAsString
();
auto
entity
=
test_select
::
CreateRecord
(
"TestRT2"
,
Value
(
id
));
test_select
::
InsertEntity
(
&
entity
);
auto
query_transaction
(
connection
->
CreateTransaction
());
query_transaction
->
Query
(
"SELECT TestRT2.TestProp3 FROM Record TestRT"
);
query_transaction
->
Execute
();
EXPECT_EQ
(
query_transaction
->
GetResultTable
().
GetHeader
().
size
(),
1
);
for
(
const
auto
&
column
:
query_transaction
->
GetResultTable
().
GetHeader
())
{
EXPECT_EQ
(
column
.
GetName
(),
"TestRT2.TestProp3"
);
}
EXPECT_EQ
(
query_transaction
->
GetResultTable
().
size
(),
1
);
for
(
const
auto
&
row
:
query_transaction
->
GetResultTable
().
GetRows
())
{
EXPECT_EQ
(
row
.
GetValue
(
"TestRT2.TestProp3"
).
GetAsString
(),
"val3"
);
}
}
/*
* Test select the referenced entity's property's unit.
*/
TEST_F
(
test_select
,
test_select_reference_entitys_propertys_unit
)
{
const
auto
&
connection
=
caosdb
::
connection
::
ConnectionManager
::
GetDefaultConnection
();
auto
get_id_of_ref_rec
(
connection
->
CreateTransaction
());
get_id_of_ref_rec
->
Query
(
"SELECT id FROM RECORD TestRT2"
);
get_id_of_ref_rec
->
Execute
();
auto
id
=
(
*
get_id_of_ref_rec
->
GetResultTable
().
GetRows
().
begin
()).
GetValue
(
"id"
).
GetAsString
();
auto
entity
=
test_select
::
CreateRecord
(
"TestRT2"
,
Value
(
id
));
test_select
::
InsertEntity
(
&
entity
);
auto
query_transaction
(
connection
->
CreateTransaction
());
query_transaction
->
Query
(
"SELECT TestRT2.TestPropDouble.unit FROM Record TestRT"
);
query_transaction
->
Execute
();
EXPECT_EQ
(
query_transaction
->
GetResultTable
().
GetHeader
().
size
(),
1
);
for
(
const
auto
&
column
:
query_transaction
->
GetResultTable
().
GetHeader
())
{
EXPECT_EQ
(
column
.
GetName
(),
"TestRT2.TestPropDouble.unit"
);
}
EXPECT_EQ
(
query_transaction
->
GetResultTable
().
size
(),
1
);
for
(
const
auto
&
row
:
query_transaction
->
GetResultTable
().
GetRows
())
{
EXPECT_EQ
(
row
.
GetValue
(
"TestRT2.TestPropDouble.unit"
).
GetAsString
(),
"km"
);
}
}
/*
* Test select the referenced entity's property's description.
*/
TEST_F
(
test_select
,
test_select_reference_entitys_propertys_description
)
{
const
auto
&
connection
=
caosdb
::
connection
::
ConnectionManager
::
GetDefaultConnection
();
auto
get_id_of_ref_rec
(
connection
->
CreateTransaction
());
get_id_of_ref_rec
->
Query
(
"SELECT id FROM RECORD TestRT2"
);
get_id_of_ref_rec
->
Execute
();
auto
id
=
(
*
get_id_of_ref_rec
->
GetResultTable
().
GetRows
().
begin
()).
GetValue
(
"id"
).
GetAsString
();
auto
entity
=
test_select
::
CreateRecord
(
"TestRT2"
,
Value
(
id
));
test_select
::
InsertEntity
(
&
entity
);
auto
query_transaction
(
connection
->
CreateTransaction
());
query_transaction
->
Query
(
"SELECT TestRT2.TestProp3.description FROM Record TestRT"
);
query_transaction
->
Execute
();
EXPECT_EQ
(
query_transaction
->
GetResultTable
().
GetHeader
().
size
(),
1
);
for
(
const
auto
&
column
:
query_transaction
->
GetResultTable
().
GetHeader
())
{
EXPECT_EQ
(
column
.
GetName
(),
"TestRT2.TestProp3.description"
);
}
EXPECT_EQ
(
query_transaction
->
GetResultTable
().
size
(),
1
);
for
(
const
auto
&
row
:
query_transaction
->
GetResultTable
().
GetRows
())
{
EXPECT_EQ
(
row
.
GetValue
(
"TestRT2.TestProp3.description"
).
GetAsString
(),
"Prop Description TestProp3"
);
}
}
/*
* Test select the referenced entity's property's name.
*/
TEST_F
(
test_select
,
test_select_reference_entitys_propertys_name
)
{
const
auto
&
connection
=
caosdb
::
connection
::
ConnectionManager
::
GetDefaultConnection
();
auto
get_id_of_ref_rec
(
connection
->
CreateTransaction
());
get_id_of_ref_rec
->
Query
(
"SELECT id FROM RECORD TestRT2"
);
get_id_of_ref_rec
->
Execute
();
auto
id
=
(
*
get_id_of_ref_rec
->
GetResultTable
().
GetRows
().
begin
()).
GetValue
(
"id"
).
GetAsString
();
auto
entity
=
test_select
::
CreateRecord
(
"TestRT2"
,
Value
(
id
));
test_select
::
InsertEntity
(
&
entity
);
auto
query_transaction
(
connection
->
CreateTransaction
());
query_transaction
->
Query
(
"SELECT TestRT2.TestProp3.name FROM Record TestRT"
);
query_transaction
->
Execute
();
EXPECT_EQ
(
query_transaction
->
GetResultTable
().
GetHeader
().
size
(),
1
);
for
(
const
auto
&
column
:
query_transaction
->
GetResultTable
().
GetHeader
())
{
EXPECT_EQ
(
column
.
GetName
(),
"TestRT2.TestProp3.name"
);
}
EXPECT_EQ
(
query_transaction
->
GetResultTable
().
size
(),
1
);
for
(
const
auto
&
row
:
query_transaction
->
GetResultTable
().
GetRows
())
{
EXPECT_EQ
(
row
.
GetValue
(
"TestRT2.TestProp3.name"
).
GetAsString
(),
"TestProp3"
);
}
}
/*
* Test select the referenced entity's property's id.
*/
TEST_F
(
test_select
,
test_select_reference_entitys_propertys_id
)
{
const
auto
&
connection
=
caosdb
::
connection
::
ConnectionManager
::
GetDefaultConnection
();
auto
get_id_of_ref_rec
(
connection
->
CreateTransaction
());
get_id_of_ref_rec
->
Query
(
"SELECT id FROM RECORD TestRT2"
);
get_id_of_ref_rec
->
Execute
();
auto
id
=
(
*
get_id_of_ref_rec
->
GetResultTable
().
GetRows
().
begin
()).
GetValue
(
"id"
).
GetAsString
();
auto
get_id_of_prop
(
connection
->
CreateTransaction
());
get_id_of_prop
->
Query
(
"SELECT id FROM PROPERTY TestProp3"
);
get_id_of_prop
->
Execute
();
auto
pid
=
(
*
get_id_of_prop
->
GetResultTable
().
GetRows
().
begin
()).
GetValue
(
"id"
).
GetAsString
();
auto
entity
=
test_select
::
CreateRecord
(
"TestRT2"
,
Value
(
id
));
test_select
::
InsertEntity
(
&
entity
);
auto
query_transaction
(
connection
->
CreateTransaction
());
query_transaction
->
Query
(
"SELECT TestRT2.TestProp3.id FROM Record TestRT"
);
query_transaction
->
Execute
();
EXPECT_EQ
(
query_transaction
->
GetResultTable
().
GetHeader
().
size
(),
1
);
for
(
const
auto
&
column
:
query_transaction
->
GetResultTable
().
GetHeader
())
{
EXPECT_EQ
(
column
.
GetName
(),
"TestRT2.TestProp3.id"
);
}
EXPECT_EQ
(
query_transaction
->
GetResultTable
().
size
(),
1
);
for
(
const
auto
&
row
:
query_transaction
->
GetResultTable
().
GetRows
())
{
EXPECT_EQ
(
row
.
GetValue
(
"TestRT2.TestProp3.id"
).
GetAsString
(),
pid
);
}
}
}
// 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