From f91e5a0f0a03e321e6fdba73bfbe0f659d33be51 Mon Sep 17 00:00:00 2001 From: florian <f.spreckelsen@inidscale.com> Date: Mon, 2 Aug 2021 16:47:04 +0200 Subject: [PATCH] ENH: Add more setters for entities --- include/caosdb/entity.h | 4 +++- src/caosdb/entity.cpp | 12 ++++++++++++ test/test_entity.cpp | 25 +++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/include/caosdb/entity.h b/include/caosdb/entity.h index 254c395..b3eb9e1 100644 --- a/include/caosdb/entity.h +++ b/include/caosdb/entity.h @@ -314,6 +314,9 @@ public: [[nodiscard]] inline auto GetUnit() const -> const std::string & { return wrapped->unit(); }; + [[nodiscard]] inline auto GetValue() const -> const std::string & { + return wrapped->value(); + }; [[nodiscard]] auto GetParents() const -> const Parents &; [[nodiscard]] auto GetProperties() const -> const Properties &; @@ -344,7 +347,6 @@ public: auto SetName(const std::string &name) -> void; auto SetVersionId(const std::string &id) -> void; - // TODO(fspreck) ... and also these auto SetValue(const std::string &value) -> void; auto SetUnit(const std::string &unit) -> void; // Currently no references or lists. diff --git a/src/caosdb/entity.cpp b/src/caosdb/entity.cpp index 57935d1..8c7359b 100644 --- a/src/caosdb/entity.cpp +++ b/src/caosdb/entity.cpp @@ -107,4 +107,16 @@ auto Entity::SetName(const std::string &name) -> void { this->wrapped->set_name(name); } +auto Entity::SetValue(const std::string &value) -> void { + this->wrapped->set_value(value); +} + +auto Entity::SetUnit(const std::string &unit) -> void { + this->wrapped->set_unit(unit); +} + +auto Entity::SetDatatype(const std::string &datatype) -> void { + this->wrapped->set_datatype(datatype); +} + } // namespace caosdb::entity diff --git a/test/test_entity.cpp b/test/test_entity.cpp index 4a505b3..66423eb 100644 --- a/test/test_entity.cpp +++ b/test/test_entity.cpp @@ -73,6 +73,31 @@ TEST(test_entity, test_insert_entity) { EXPECT_EQ(entity.GetVersionId(), "version_id"); } +// TODO(fspreck) cognitive complexity > 25 (threshold) +TEST(test_entity, test_insert_with_role) { // NOLINT + auto transaction = caosdb::transaction::Transaction( + std::shared_ptr<transaction::EntityTransactionService::Stub>(nullptr)); + + auto entity = Entity(); + entity.SetId("entity_id"); + entity.SetVersionId("version_id"); + entity.SetRole("Property"); + entity.SetDatatype("DOUBLE"); + entity.SetName("Length"); + entity.SetUnit("m"); + entity.SetValue("5.5"); + + transaction.InsertEntity(&entity); + + EXPECT_EQ(entity.GetId(), "entity_id"); + EXPECT_EQ(entity.GetVersionId(), "version_id"); + EXPECT_EQ(entity.GetRole(), "Property"); + EXPECT_EQ(entity.GetDatatype(), "DOUBLE"); + EXPECT_EQ(entity.GetName(), "Length"); + EXPECT_EQ(entity.GetUnit(), "m"); + EXPECT_EQ(entity.GetValue(), "5.5"); +} + // TODO(tf) cognitive complexity > 25 (threshold) TEST(test_entity, test_from_id_response) { // NOLINT IdResponse idResponse; -- GitLab