diff --git a/include/caosdb/entity.h b/include/caosdb/entity.h index 254c39555e012f6b3823492c66cda30743e7c6d4..b3eb9e1428f97a3835de5180428091fc746a580f 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 57935d1cb7bd7565a2d64d8b22b2f761246f600a..8c7359b609855905fa7b9a8a3600896c974b440a 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 4a505b3488f5ec644c615a104d480f0b69c572c0..66423eb49300422439a75ec20f35e63d703053c1 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;