utils: Retrieval of managed objects of DBUS

This commit implements functionality to retrieve the managed object of a
specific DBUS service on a particular path.  Additionally implements a
function template for inventory objects which efficiently enables
retrieval of managed object for Inventory Manager.

Tested: Added unit test cases for checking the return value.

Change-Id: Ide652f843db1623bdacebf3e269e03895bbb7f1a
Signed-off-by: Riya Dixit <riyadixitagra@gmail.com>
diff --git a/common/test/mocked_utils.hpp b/common/test/mocked_utils.hpp
index 71bc6e7..e42677c 100644
--- a/common/test/mocked_utils.hpp
+++ b/common/test/mocked_utils.hpp
@@ -22,6 +22,35 @@
 } // namespace utils
 } // namespace pldm
 
+class GetManagedEmptyObject
+{
+  public:
+    static pldm::utils::ObjectValueTree getManagedObj(const char* /*service*/,
+                                                      const char* /*path*/)
+    {
+        return pldm::utils::ObjectValueTree{};
+    }
+};
+
+class GetManagedObject
+{
+  public:
+    static pldm::utils::ObjectValueTree getManagedObj(const char* /*service*/,
+                                                      const char* /*path*/)
+    {
+        return pldm::utils::ObjectValueTree{
+            {sdbusplus::message::object_path("/foo/bar"),
+             {{"foo.bar",
+               {{"Functional", true},
+                {"Enabled", true},
+                {"PrettyName", "System"},
+                {"Present", true},
+                {"SerialNumber", "abc123z"},
+                {"Model", "1234 - 00Z"},
+                {"SubModel", "S0"}}}}}};
+    }
+};
+
 class MockdBusHandler : public pldm::utils::DBusHandler
 {
   public:
diff --git a/common/test/pldm_utils_test.cpp b/common/test/pldm_utils_test.cpp
index 549e289..93cf335 100644
--- a/common/test/pldm_utils_test.cpp
+++ b/common/test/pldm_utils_test.cpp
@@ -1,4 +1,5 @@
 #include "common/utils.hpp"
+#include "mocked_utils.hpp"
 
 #include <libpldm/platform.h>
 
@@ -6,6 +7,28 @@
 
 using namespace pldm::utils;
 
+TEST(GetInventoryObjects, testForEmptyObject)
+{
+    ObjectValueTree result =
+        DBusHandler::getInventoryObjects<GetManagedEmptyObject>();
+    EXPECT_TRUE(result.empty());
+}
+
+TEST(GetInventoryObjects, testForObject)
+{
+    std::string path = "/foo/bar";
+    std::string service = "foo.bar";
+    auto result = DBusHandler::getInventoryObjects<GetManagedObject>();
+    EXPECT_EQ(result[path].begin()->first, service);
+    auto function =
+        std::get<bool>(result[path][service][std::string("Functional")]);
+    auto model =
+        std::get<std::string>(result[path][service][std::string("Model")]);
+    EXPECT_FALSE(result.empty());
+    EXPECT_TRUE(function);
+    EXPECT_EQ(model, std::string("1234 - 00Z"));
+}
+
 TEST(decodeDate, testGooduintToDate)
 {
     uint64_t data = 20191212115959;