Skip to content
Snippets Groups Projects
Commit fc4969d3 authored by florian's avatar florian
Browse files

TST: Add unit tests for properties and CopyTo

parent 249dce56
No related branches found
No related tags found
1 merge request!4ENH: Allow insertion and deletion of single entities
Pipeline #11192 passed
Pipeline: caosdb-cppinttest

#11194

    This commit is part of merge request !4. Comments created here will be created in the context of that merge request.
    ......@@ -3,6 +3,7 @@
    * This file is a part of the CaosDB Project.
    *
    * Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com>
    * Copyright (C) 2021 Florian Spreckelsen <f.spreckelsen@indiscale.com>
    * Copyright (C) 2021 IndiScale GmbH <info@indiscale.com>
    *
    * This program is free software: you can redistribute it and/or modify
    ......@@ -23,7 +24,9 @@
    #include "caosdb/entity/v1alpha1/main.grpc.pb.h" // for EntityTransactionSe...
    #include "caosdb/entity/v1alpha1/main.pb.h" // for IdResponse, Message
    #include "caosdb/message_code.h" // for MessageCode
    #include "caosdb/protobuf_helper.h" // for get_arena
    #include "caosdb/transaction.h" // for Transaction
    #include "google/protobuf/arena.h" // for Arena
    #include "gtest/gtest-message.h" // for Message
    #include "gtest/gtest-test-part.h" // for TestPartResult, Sui...
    #include "gtest/gtest_pred_impl.h" // for Test, EXPECT_EQ
    ......@@ -33,6 +36,8 @@
    namespace caosdb::entity {
    using caosdb::entity::v1alpha1::IdResponse;
    using ProtoEntity = caosdb::entity::v1alpha1::Entity;
    using caosdb::utility::get_arena;
    TEST(test_entity, test_parent_setters) {
    auto parent = Parent();
    ......@@ -56,6 +61,79 @@ TEST(test_entity, test_append_parent) {
    EXPECT_EQ(same_parent.GetId(), "some-id");
    }
    TEST(test_entity, test_property_setters) {
    auto prop = Property();
    prop.SetName("prop_name");
    prop.SetId("prop_id");
    prop.SetImportance("prop_importance");
    prop.SetValue("prop_value");
    prop.SetUnit("prop_unit");
    prop.SetDatatype("prop_dtype");
    EXPECT_EQ(prop.GetName(), "prop_name");
    EXPECT_EQ(prop.GetId(), "prop_id");
    EXPECT_EQ(prop.GetImportance(), "prop_importance");
    EXPECT_EQ(prop.GetValue(), "prop_value");
    EXPECT_EQ(prop.GetUnit(), "prop_unit");
    EXPECT_EQ(prop.GetDatatype(), "prop_dtype");
    }
    // TODO(fspreck) cognitive complexity > 25 (threshold)
    TEST(test_entity, test_append_property) { // NOLINT
    auto entity = Entity();
    auto prop = Property();
    prop.SetName("prop_name");
    prop.SetId("prop_id");
    prop.SetImportance("prop_importance");
    prop.SetValue("prop_value");
    prop.SetUnit("prop_unit");
    prop.SetDatatype("prop_dtype");
    EXPECT_EQ(entity.GetProperties().Size(), 0);
    entity.AppendProperty(prop);
    EXPECT_EQ(entity.GetProperties().Size(), 1);
    auto same_prop = entity.GetProperties().At(0);
    EXPECT_EQ(prop.GetName(), same_prop.GetName());
    EXPECT_EQ(prop.GetId(), same_prop.GetId());
    EXPECT_EQ(prop.GetImportance(), same_prop.GetImportance());
    EXPECT_EQ(prop.GetValue(), same_prop.GetValue());
    EXPECT_EQ(prop.GetUnit(), same_prop.GetUnit());
    EXPECT_EQ(prop.GetDatatype(), same_prop.GetDatatype());
    }
    TEST(test_entity, test_copy_to) {
    auto entity = Entity();
    entity.SetId("original_id");
    entity.SetName("orignial_name");
    auto parent = Parent();
    parent.SetId("parent_id");
    parent.SetName("parent_name");
    entity.AppendParent(parent);
    auto prop = Property();
    prop.SetId("prop_id");
    prop.SetName("prop_name");
    entity.AppendProperty(prop);
    // create protobuf entity to which all fields ae copied and then a
    // CaoosDB entity from that protobuf entity.
    auto *proto_copy =
    google::protobuf::Arena::CreateMessage<ProtoEntity>(get_arena());
    entity.CopyTo(proto_copy);
    auto copied = Entity(proto_copy);
    EXPECT_EQ(entity.GetId(), copied.GetId());
    EXPECT_EQ(entity.GetName(), copied.GetName());
    EXPECT_EQ(copied.GetParents().At(0).GetId(), parent.GetId());
    EXPECT_EQ(copied.GetParents().At(0).GetName(), parent.GetName());
    EXPECT_EQ(copied.GetProperties().At(0).GetId(), prop.GetId());
    EXPECT_EQ(copied.GetProperties().At(0).GetName(), prop.GetName());
    }
    TEST(test_entity, test_insert_entity) {
    auto transaction = caosdb::transaction::Transaction(
    std::shared_ptr<transaction::EntityTransactionService::Stub>(nullptr));
    ......
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Finish editing this message first!
    Please register or to comment