libpldmresponder: create PDR when the D-Bus object path exists

On a system where this D-Bus object path does not exist, it should
not create a PDR when the D-Bus object specified here is not found.

Tested: In the PDR config files, the PDR is successfully created when
the objectPath of the D-Bus exists, otherwise, skipped the current
config and the PDR is not created.

Signed-off-by: George Liu <liuxiwei@inspur.com>
Change-Id: Ib59fa79cc28d5712161bfb971c37c86c363bafb0
diff --git a/common/utils.hpp b/common/utils.hpp
index e84ed7b..8c5c4f5 100644
--- a/common/utils.hpp
+++ b/common/utils.hpp
@@ -144,6 +144,9 @@
   public:
     virtual ~DBusHandlerInterface() = default;
 
+    virtual std::string getService(const char* path,
+                                   const char* interface) const = 0;
+
     virtual void setDbusProperty(const DBusMapping& dBusMap,
                                  const PropertyValue& value) const = 0;
 
@@ -181,7 +184,8 @@
      *
      *  @throw sdbusplus::exception::SdBusError when it fails
      */
-    std::string getService(const char* path, const char* interface) const;
+    std::string getService(const char* path,
+                           const char* interface) const override;
 
     /** @brief Get property(type: variant) from the requested dbus
      *
diff --git a/libpldmresponder/pdr_numeric_effecter.hpp b/libpldmresponder/pdr_numeric_effecter.hpp
index 1aa525b..402a426 100644
--- a/libpldmresponder/pdr_numeric_effecter.hpp
+++ b/libpldmresponder/pdr_numeric_effecter.hpp
@@ -24,8 +24,9 @@
  *  @param[out] repo - pdr::RepoInterface
  *
  */
-template <class Handler>
-void generateNumericEffecterPDR(const Json& json, Handler& handler,
+template <class DBusInterface, class Handler>
+void generateNumericEffecterPDR(const DBusInterface& dBusIntf, const Json& json,
+                                Handler& handler,
                                 pdr_utils::RepoInterface& repo)
 {
     static const std::vector<Json> emptyList{};
@@ -164,6 +165,17 @@
         auto interface = dbusEntry.value("interface", "");
         auto propertyName = dbusEntry.value("property_name", "");
         auto propertyType = dbusEntry.value("property_type", "");
+
+        try
+        {
+            auto service =
+                dBusIntf.getService(objectPath.c_str(), interface.c_str());
+        }
+        catch (const std::exception& e)
+        {
+            continue;
+        }
+
         pldm::utils::DBusMapping dbusMapping{objectPath, interface,
                                              propertyName, propertyType};
         DbusMappings dbusMappings{};
diff --git a/libpldmresponder/pdr_state_effecter.hpp b/libpldmresponder/pdr_state_effecter.hpp
index 5b49a46..1391def 100644
--- a/libpldmresponder/pdr_state_effecter.hpp
+++ b/libpldmresponder/pdr_state_effecter.hpp
@@ -24,9 +24,9 @@
  *  @param[out] repo - pdr::RepoInterface
  *
  */
-template <class Handler>
-void generateStateEffecterPDR(const Json& json, Handler& handler,
-                              pdr_utils::RepoInterface& repo)
+template <class DBusInterface, class Handler>
+void generateStateEffecterPDR(const DBusInterface& dBusIntf, const Json& json,
+                              Handler& handler, pdr_utils::RepoInterface& repo)
 {
     static const std::vector<Json> emptyList{};
     auto entries = json.value("entries", emptyList);
@@ -104,6 +104,17 @@
             auto interface = dbusEntry.value("interface", "");
             auto propertyName = dbusEntry.value("property_name", "");
             auto propertyType = dbusEntry.value("property_type", "");
+
+            try
+            {
+                auto service =
+                    dBusIntf.getService(objectPath.c_str(), interface.c_str());
+            }
+            catch (const std::exception& e)
+            {
+                continue;
+            }
+
             pldm::utils::DBusMapping dbusMapping{objectPath, interface,
                                                  propertyName, propertyType};
             dbusMappings.emplace_back(std::move(dbusMapping));
diff --git a/libpldmresponder/platform.cpp b/libpldmresponder/platform.cpp
index 88ddcf8..affe52e 100644
--- a/libpldmresponder/platform.cpp
+++ b/libpldmresponder/platform.cpp
@@ -65,7 +65,8 @@
     return dbusObjMaps.at(effecterId);
 }
 
-void Handler::generate(const std::string& dir, Repo& repo)
+void Handler::generate(const pldm::utils::DBusHandler& dBusIntf,
+                       const std::string& dir, Repo& repo)
 {
     if (!fs::exists(dir))
     {
@@ -79,14 +80,18 @@
 
     const std::map<Type, generatePDR> generateHandlers = {
         {PLDM_STATE_EFFECTER_PDR,
-         [this](const auto& json, RepoInterface& repo) {
-             pdr_state_effecter::generateStateEffecterPDR<Handler>(json, *this,
-                                                                   repo);
+         [this](const DBusHandler& dBusIntf, const auto& json,
+                RepoInterface& repo) {
+             pdr_state_effecter::generateStateEffecterPDR<
+                 pldm::utils::DBusHandler, Handler>(dBusIntf, json, *this,
+                                                    repo);
          }},
         {PLDM_NUMERIC_EFFECTER_PDR,
-         [this](const auto& json, RepoInterface& repo) {
-             pdr_numeric_effecter::generateNumericEffecterPDR<Handler>(
-                 json, *this, repo);
+         [this](const DBusHandler& dBusIntf, const auto& json,
+                RepoInterface& repo) {
+             pdr_numeric_effecter::generateNumericEffecterPDR<
+                 pldm::utils::DBusHandler, Handler>(dBusIntf, json, *this,
+                                                    repo);
          }}};
 
     Type pdrType{};
@@ -101,7 +106,7 @@
                 for (const auto& effecter : effecterPDRs)
                 {
                     pdrType = effecter.value("pdrType", 0);
-                    generateHandlers.at(pdrType)(effecter, repo);
+                    generateHandlers.at(pdrType)(dBusIntf, effecter, repo);
                 }
             }
         }
diff --git a/libpldmresponder/platform.hpp b/libpldmresponder/platform.hpp
index ad635bd..c79a2ed 100644
--- a/libpldmresponder/platform.hpp
+++ b/libpldmresponder/platform.hpp
@@ -28,7 +28,8 @@
 using namespace pldm::responder::pdr_utils;
 
 using generatePDR =
-    std::function<void(const Json& json, pdr_utils::RepoInterface& repo)>;
+    std::function<void(const pldm::utils::DBusHandler& dBusIntf,
+                       const Json& json, pdr_utils::RepoInterface& repo)>;
 
 using EffecterId = uint16_t;
 using DbusObjMaps =
@@ -55,7 +56,8 @@
 class Handler : public CmdHandler
 {
   public:
-    Handler(const std::string& pdrJsonsDir, const std::string& eventsJsonsDir,
+    Handler(const pldm::utils::DBusHandler& dBusIntf,
+            const std::string& pdrJsonsDir, const std::string& eventsJsonsDir,
             pldm_pdr* repo, HostPDRHandler* hostPDRHandler,
             fru::Handler* fruHandler,
             const std::optional<EventMap>& addOnHandlersMap = std::nullopt) :
@@ -63,7 +65,7 @@
         hostPDRHandler(hostPDRHandler), stateSensorHandler(eventsJsonsDir),
         fruHandler(fruHandler)
     {
-        generate(pdrJsonsDir, pdrRepo);
+        generate(dBusIntf, pdrJsonsDir, pdrRepo);
 
         handlers.emplace(PLDM_GET_PDR,
                          [this](const pldm_msg* request, size_t payloadLength) {
@@ -158,10 +160,12 @@
 
     /** @brief Parse PDR JSONs and build PDR repository
      *
+     *  @param[in] dBusIntf - The interface object
      *  @param[in] dir - directory housing platform specific PDR JSON files
      *  @param[in] repo - instance of concrete implementation of Repo
      */
-    void generate(const std::string& dir, Repo& repo);
+    void generate(const pldm::utils::DBusHandler& dBusIntf,
+                  const std::string& dir, Repo& repo);
 
     /** @brief Parse PDR JSONs and build state effecter PDR repository
      *
diff --git a/pldmd/pldmd.cpp b/pldmd/pldmd.cpp
index a688b86..71f1cfb 100644
--- a/pldmd/pldmd.cpp
+++ b/pldmd/pldmd.cpp
@@ -196,8 +196,9 @@
     // Platform handler.
     invoker.registerHandler(PLDM_PLATFORM,
                             std::make_unique<platform::Handler>(
-                                PDR_JSONS_DIR, EVENTS_JSONS_DIR, pdrRepo.get(),
-                                hostPDRHandler.get(), fruHandler.get()));
+                                dbusHandler, PDR_JSONS_DIR, EVENTS_JSONS_DIR,
+                                pdrRepo.get(), hostPDRHandler.get(),
+                                fruHandler.get()));
     invoker.registerHandler(PLDM_FRU, std::move(fruHandler));
 
 #ifdef OEM_IBM
diff --git a/test/libpldmresponder_pdr_effecter_test.cpp b/test/libpldmresponder_pdr_effecter_test.cpp
index a9afc6b..e0a54bf 100644
--- a/test/libpldmresponder_pdr_effecter_test.cpp
+++ b/test/libpldmresponder_pdr_effecter_test.cpp
@@ -2,6 +2,9 @@
 
 #include "libpldmresponder/pdr_utils.hpp"
 #include "libpldmresponder/platform.hpp"
+#include "mocked_utils.hpp"
+
+#include <sdbusplus/test/sdbus_mock.hpp>
 
 #include <gtest/gtest.h>
 
@@ -10,13 +13,22 @@
 using namespace pldm::responder::pdr;
 using namespace pldm::responder::pdr_utils;
 
+using ::testing::_;
+using ::testing::Return;
+using ::testing::StrEq;
+
 TEST(GeneratePDRByStateEffecter, testGoodJson)
 {
+    MockdBusHandler mockedUtils;
+    EXPECT_CALL(mockedUtils, getService(StrEq("/foo/bar"), _))
+        .Times(5)
+        .WillRepeatedly(Return("foo.bar"));
+
     auto inPDRRepo = pldm_pdr_init();
     auto outPDRRepo = pldm_pdr_init();
     Repo outRepo(outPDRRepo);
-    Handler handler("./pdr_jsons/state_effecter/good", "./event_jsons/good",
-                    inPDRRepo, nullptr, nullptr);
+    Handler handler(mockedUtils, "./pdr_jsons/state_effecter/good",
+                    "./event_jsons/good", inPDRRepo, nullptr, nullptr);
     Repo inRepo(inPDRRepo);
     getRepoByType(inRepo, outRepo, PLDM_STATE_EFFECTER_PDR);
 
@@ -96,7 +108,7 @@
     const auto& [dbusMappings2, dbusValMaps2] =
         handler.getDbusObjMaps(pdr->effecter_id);
     ASSERT_EQ(dbusMappings2[0].objectPath, "/foo/bar");
-    ASSERT_EQ(dbusMappings2[1].objectPath, "/foo/bar/baz");
+    ASSERT_EQ(dbusMappings2[1].objectPath, "/foo/bar");
 
     ASSERT_THROW(handler.getDbusObjMaps(0xDEAD), std::exception);
 
@@ -106,11 +118,16 @@
 
 TEST(GeneratePDRByNumericEffecter, testGoodJson)
 {
+    MockdBusHandler mockedUtils;
+    EXPECT_CALL(mockedUtils, getService(StrEq("/foo/bar"), _))
+        .Times(5)
+        .WillRepeatedly(Return("foo.bar"));
+
     auto inPDRRepo = pldm_pdr_init();
     auto outPDRRepo = pldm_pdr_init();
     Repo outRepo(outPDRRepo);
-    Handler handler("./pdr_jsons/state_effecter/good", "", inPDRRepo, nullptr,
-                    nullptr);
+    Handler handler(mockedUtils, "./pdr_jsons/state_effecter/good", "",
+                    inPDRRepo, nullptr, nullptr);
     Repo inRepo(inPDRRepo);
     getRepoByType(inRepo, outRepo, PLDM_NUMERIC_EFFECTER_PDR);
 
@@ -147,11 +164,16 @@
 
 TEST(GeneratePDR, testMalformedJson)
 {
+    MockdBusHandler mockedUtils;
+    EXPECT_CALL(mockedUtils, getService(StrEq("/foo/bar"), _))
+        .Times(5)
+        .WillRepeatedly(Return("foo.bar"));
+
     auto inPDRRepo = pldm_pdr_init();
     auto outPDRRepo = pldm_pdr_init();
     Repo outRepo(outPDRRepo);
-    Handler handler("./pdr_jsons/state_effecter/good", "./event_jsons/good",
-                    inPDRRepo, nullptr, nullptr);
+    Handler handler(mockedUtils, "./pdr_jsons/state_effecter/good",
+                    "./event_jsons/good", inPDRRepo, nullptr, nullptr);
     Repo inRepo(inPDRRepo);
     getRepoByType(inRepo, outRepo, PLDM_STATE_EFFECTER_PDR);
 
@@ -165,9 +187,14 @@
 
 TEST(findStateEffecterId, goodJson)
 {
+    MockdBusHandler mockedUtils;
+    EXPECT_CALL(mockedUtils, getService(StrEq("/foo/bar"), _))
+        .Times(5)
+        .WillRepeatedly(Return("foo.bar"));
+
     auto inPDRRepo = pldm_pdr_init();
-    Handler handler("./pdr_jsons/state_effecter/good", "", inPDRRepo, nullptr,
-                    nullptr);
+    Handler handler(mockedUtils, "./pdr_jsons/state_effecter/good", "",
+                    inPDRRepo, nullptr, nullptr);
     uint16_t entityType = 33;
     uint16_t entityInstance = 0;
     uint16_t containerId = 0;
diff --git a/test/libpldmresponder_platform_test.cpp b/test/libpldmresponder_platform_test.cpp
index 60df7bf..22ededa 100644
--- a/test/libpldmresponder_platform_test.cpp
+++ b/test/libpldmresponder_platform_test.cpp
@@ -7,6 +7,8 @@
 #include "libpldmresponder/platform_state_effecter.hpp"
 #include "mocked_utils.hpp"
 
+#include <sdbusplus/test/sdbus_mock.hpp>
+
 #include <iostream>
 
 using namespace pldm::utils;
@@ -15,6 +17,10 @@
 using namespace pldm::responder::pdr;
 using namespace pldm::responder::pdr_utils;
 
+using ::testing::_;
+using ::testing::Return;
+using ::testing::StrEq;
+
 TEST(getPDR, testGoodPath)
 {
     std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_GET_PDR_REQ_BYTES>
@@ -26,9 +32,14 @@
         reinterpret_cast<struct pldm_get_pdr_req*>(req->payload);
     request->request_count = 100;
 
+    MockdBusHandler mockedUtils;
+    EXPECT_CALL(mockedUtils, getService(StrEq("/foo/bar"), _))
+        .Times(5)
+        .WillRepeatedly(Return("foo.bar"));
+
     auto pdrRepo = pldm_pdr_init();
-    Handler handler("./pdr_jsons/state_effecter/good", "./event_jsons/good",
-                    pdrRepo, nullptr, nullptr);
+    Handler handler(mockedUtils, "./pdr_jsons/state_effecter/good",
+                    "./event_jsons/good", pdrRepo, nullptr, nullptr);
     Repo repo(pdrRepo);
     ASSERT_EQ(repo.empty(), false);
     auto response = handler.getPDR(req, requestPayloadLength);
@@ -58,9 +69,14 @@
         reinterpret_cast<struct pldm_get_pdr_req*>(req->payload);
     request->request_count = 1;
 
+    MockdBusHandler mockedUtils;
+    EXPECT_CALL(mockedUtils, getService(StrEq("/foo/bar"), _))
+        .Times(5)
+        .WillRepeatedly(Return("foo.bar"));
+
     auto pdrRepo = pldm_pdr_init();
-    Handler handler("./pdr_jsons/state_effecter/good", "./event_jsons/good",
-                    pdrRepo, nullptr, nullptr);
+    Handler handler(mockedUtils, "./pdr_jsons/state_effecter/good",
+                    "./event_jsons/good", pdrRepo, nullptr, nullptr);
     Repo repo(pdrRepo);
     ASSERT_EQ(repo.empty(), false);
     auto response = handler.getPDR(req, requestPayloadLength);
@@ -84,9 +100,14 @@
     request->record_handle = 100000;
     request->request_count = 1;
 
+    MockdBusHandler mockedUtils;
+    EXPECT_CALL(mockedUtils, getService(StrEq("/foo/bar"), _))
+        .Times(5)
+        .WillRepeatedly(Return("foo.bar"));
+
     auto pdrRepo = pldm_pdr_init();
-    Handler handler("./pdr_jsons/state_effecter/good", "./event_jsons/good",
-                    pdrRepo, nullptr, nullptr);
+    Handler handler(mockedUtils, "./pdr_jsons/state_effecter/good",
+                    "./event_jsons/good", pdrRepo, nullptr, nullptr);
     Repo repo(pdrRepo);
     ASSERT_EQ(repo.empty(), false);
     auto response = handler.getPDR(req, requestPayloadLength);
@@ -108,9 +129,14 @@
         reinterpret_cast<struct pldm_get_pdr_req*>(req->payload);
     request->record_handle = 1;
 
+    MockdBusHandler mockedUtils;
+    EXPECT_CALL(mockedUtils, getService(StrEq("/foo/bar"), _))
+        .Times(5)
+        .WillRepeatedly(Return("foo.bar"));
+
     auto pdrRepo = pldm_pdr_init();
-    Handler handler("./pdr_jsons/state_effecter/good", "./event_jsons/good",
-                    pdrRepo, nullptr, nullptr);
+    Handler handler(mockedUtils, "./pdr_jsons/state_effecter/good",
+                    "./event_jsons/good", pdrRepo, nullptr, nullptr);
     Repo repo(pdrRepo);
     ASSERT_EQ(repo.empty(), false);
     auto response = handler.getPDR(req, requestPayloadLength);
@@ -134,9 +160,14 @@
         reinterpret_cast<struct pldm_get_pdr_req*>(req->payload);
     request->request_count = 100;
 
+    MockdBusHandler mockedUtils;
+    EXPECT_CALL(mockedUtils, getService(StrEq("/foo/bar"), _))
+        .Times(5)
+        .WillRepeatedly(Return("foo.bar"));
+
     auto pdrRepo = pldm_pdr_init();
-    Handler handler("./pdr_jsons/state_effecter/good", "./event_jsons/good",
-                    pdrRepo, nullptr, nullptr);
+    Handler handler(mockedUtils, "./pdr_jsons/state_effecter/good",
+                    "./event_jsons/good", pdrRepo, nullptr, nullptr);
     Repo repo(pdrRepo);
     ASSERT_EQ(repo.empty(), false);
     auto response = handler.getPDR(req, requestPayloadLength);
@@ -184,11 +215,16 @@
 
 TEST(setStateEffecterStatesHandler, testGoodRequest)
 {
+    MockdBusHandler mockedUtils;
+    EXPECT_CALL(mockedUtils, getService(StrEq("/foo/bar"), _))
+        .Times(5)
+        .WillRepeatedly(Return("foo.bar"));
+
     auto inPDRRepo = pldm_pdr_init();
     auto outPDRRepo = pldm_pdr_init();
     Repo outRepo(outPDRRepo);
-    Handler handler("./pdr_jsons/state_effecter/good", "./event_jsons/good",
-                    inPDRRepo, nullptr, nullptr);
+    Handler handler(mockedUtils, "./pdr_jsons/state_effecter/good",
+                    "./event_jsons/good", inPDRRepo, nullptr, nullptr);
     Repo inRepo(inPDRRepo);
     getRepoByType(inRepo, outRepo, PLDM_STATE_EFFECTER_PDR);
     pdr_utils::PdrEntry e;
@@ -204,14 +240,13 @@
     std::string value = "xyz.openbmc_project.Foo.Bar.V1";
     PropertyValue propertyValue = value;
 
-    MockdBusHandler handlerObj;
     DBusMapping dbusMapping{"/foo/bar", "xyz.openbmc_project.Foo.Bar",
                             "propertyName", "string"};
 
-    EXPECT_CALL(handlerObj, setDbusProperty(dbusMapping, propertyValue))
+    EXPECT_CALL(mockedUtils, setDbusProperty(dbusMapping, propertyValue))
         .Times(2);
     auto rc = platform_state_effecter::setStateEffecterStatesHandler<
-        MockdBusHandler, Handler>(handlerObj, handler, 0x1, stateField);
+        MockdBusHandler, Handler>(mockedUtils, handler, 0x1, stateField);
     ASSERT_EQ(rc, 0);
 
     pldm_pdr_destroy(inPDRRepo);
@@ -220,11 +255,16 @@
 
 TEST(setStateEffecterStatesHandler, testBadRequest)
 {
+    MockdBusHandler mockedUtils;
+    EXPECT_CALL(mockedUtils, getService(StrEq("/foo/bar"), _))
+        .Times(5)
+        .WillRepeatedly(Return("foo.bar"));
+
     auto inPDRRepo = pldm_pdr_init();
     auto outPDRRepo = pldm_pdr_init();
     Repo outRepo(outPDRRepo);
-    Handler handler("./pdr_jsons/state_effecter/good", "./event_jsons/good",
-                    inPDRRepo, nullptr, nullptr);
+    Handler handler(mockedUtils, "./pdr_jsons/state_effecter/good",
+                    "./event_jsons/good", inPDRRepo, nullptr, nullptr);
     Repo inRepo(inPDRRepo);
     getRepoByType(inRepo, outRepo, PLDM_STATE_EFFECTER_PDR);
     pdr_utils::PdrEntry e;
@@ -238,20 +278,19 @@
     stateField.push_back({PLDM_REQUEST_SET, 3});
     stateField.push_back({PLDM_REQUEST_SET, 4});
 
-    MockdBusHandler handlerObj;
     auto rc = platform_state_effecter::setStateEffecterStatesHandler<
-        MockdBusHandler, Handler>(handlerObj, handler, 0x1, stateField);
+        MockdBusHandler, Handler>(mockedUtils, handler, 0x1, stateField);
     ASSERT_EQ(rc, PLDM_PLATFORM_SET_EFFECTER_UNSUPPORTED_SENSORSTATE);
 
     rc = platform_state_effecter::setStateEffecterStatesHandler<MockdBusHandler,
                                                                 Handler>(
-        handlerObj, handler, 0x9, stateField);
+        mockedUtils, handler, 0x9, stateField);
     ASSERT_EQ(rc, PLDM_PLATFORM_INVALID_EFFECTER_ID);
 
     stateField.push_back({PLDM_REQUEST_SET, 4});
     rc = platform_state_effecter::setStateEffecterStatesHandler<MockdBusHandler,
                                                                 Handler>(
-        handlerObj, handler, 0x1, stateField);
+        mockedUtils, handler, 0x1, stateField);
     ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
 
     pldm_pdr_destroy(inPDRRepo);
@@ -260,11 +299,16 @@
 
 TEST(setNumericEffecterValueHandler, testGoodRequest)
 {
+    MockdBusHandler mockedUtils;
+    EXPECT_CALL(mockedUtils, getService(StrEq("/foo/bar"), _))
+        .Times(5)
+        .WillRepeatedly(Return("foo.bar"));
+
     auto inPDRRepo = pldm_pdr_init();
     auto numericEffecterPdrRepo = pldm_pdr_init();
     Repo numericEffecterPDRs(numericEffecterPdrRepo);
-    Handler handler("./pdr_jsons/state_effecter/good", "", inPDRRepo, nullptr,
-                    nullptr);
+    Handler handler(mockedUtils, "./pdr_jsons/state_effecter/good", "",
+                    inPDRRepo, nullptr, nullptr);
     Repo inRepo(inPDRRepo);
     getRepoByType(inRepo, numericEffecterPDRs, PLDM_NUMERIC_EFFECTER_PDR);
 
@@ -280,15 +324,14 @@
     uint32_t effecterValue = 2100000000; // 2036-07-18 21:20:00
     PropertyValue propertyValue = static_cast<uint32_t>(effecterValue);
 
-    MockdBusHandler handlerObj;
     DBusMapping dbusMapping{"/foo/bar", "xyz.openbmc_project.Foo.Bar",
                             "propertyName", "uint64_t"};
-    EXPECT_CALL(handlerObj, setDbusProperty(dbusMapping, propertyValue))
+    EXPECT_CALL(mockedUtils, setDbusProperty(dbusMapping, propertyValue))
         .Times(1);
 
     auto rc = platform_numeric_effecter::setNumericEffecterValueHandler<
         MockdBusHandler, Handler>(
-        handlerObj, handler, effecterId, PLDM_EFFECTER_DATA_SIZE_UINT32,
+        mockedUtils, handler, effecterId, PLDM_EFFECTER_DATA_SIZE_UINT32,
         reinterpret_cast<uint8_t*>(&effecterValue), 4);
     ASSERT_EQ(rc, 0);
 
@@ -298,11 +341,16 @@
 
 TEST(setNumericEffecterValueHandler, testBadRequest)
 {
+    MockdBusHandler mockedUtils;
+    EXPECT_CALL(mockedUtils, getService(StrEq("/foo/bar"), _))
+        .Times(5)
+        .WillRepeatedly(Return("foo.bar"));
+
     auto inPDRRepo = pldm_pdr_init();
     auto numericEffecterPdrRepo = pldm_pdr_init();
     Repo numericEffecterPDRs(numericEffecterPdrRepo);
-    Handler handler("./pdr_jsons/state_effecter/good", "", inPDRRepo, nullptr,
-                    nullptr);
+    Handler handler(mockedUtils, "./pdr_jsons/state_effecter/good", "",
+                    inPDRRepo, nullptr, nullptr);
     Repo inRepo(inPDRRepo);
     getRepoByType(inRepo, numericEffecterPDRs, PLDM_NUMERIC_EFFECTER_PDR);
 
@@ -316,10 +364,9 @@
 
     uint16_t effecterId = 3;
     uint64_t effecterValue = 9876543210;
-    MockdBusHandler handlerObj;
     auto rc = platform_numeric_effecter::setNumericEffecterValueHandler<
         MockdBusHandler, Handler>(
-        handlerObj, handler, effecterId, PLDM_EFFECTER_DATA_SIZE_SINT32,
+        mockedUtils, handler, effecterId, PLDM_EFFECTER_DATA_SIZE_SINT32,
         reinterpret_cast<uint8_t*>(&effecterValue), 3);
     ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
 
diff --git a/test/mocked_utils.hpp b/test/mocked_utils.hpp
index 838e542..9a1c87e 100644
--- a/test/mocked_utils.hpp
+++ b/test/mocked_utils.hpp
@@ -28,6 +28,9 @@
 class MockdBusHandler : public DBusHandler
 {
   public:
+    MOCK_METHOD(std::string, getService, (const char*, const char*),
+                (const override));
+
     MOCK_METHOD(void, setDbusProperty,
                 (const DBusMapping&, const PropertyValue&), (const override));
 
diff --git a/test/pdr_jsons/state_effecter/good/effecter_pdr.json b/test/pdr_jsons/state_effecter/good/effecter_pdr.json
index e5230c6..ec77f6e 100644
--- a/test/pdr_jsons/state_effecter/good/effecter_pdr.json
+++ b/test/pdr_jsons/state_effecter/good/effecter_pdr.json
@@ -83,7 +83,7 @@
                                 ]
                             },
                             "dbus": {
-                                "path": "/foo/bar/baz",
+                                "path": "/foo/bar",
                                 "interface": "xyz.openbmc_project.Foo.Bar.Baz",
                                 "property_name": "propertyName",
                                 "property_type": "string",
diff --git a/test/pdr_jsons/state_effecter/malformed/effecter_pdr.json b/test/pdr_jsons/state_effecter/malformed/effecter_pdr.json
index afa9987..d6b0213 100644
--- a/test/pdr_jsons/state_effecter/malformed/effecter_pdr.json
+++ b/test/pdr_jsons/state_effecter/malformed/effecter_pdr.json
@@ -83,7 +83,7 @@
                                 ]
                             },
                             "dbus": {
-                                "path": "/foo/bar/baz",
+                                "path": "/foo/bar",
                                 "interface": "xyz.openbmc_project.Foo.Bar.Baz",
                                 "property_name": "propertyName",
                                 "property_type": "string",