Fix SubTreePathsById when given ID is invalid
The commit 7a93d51 makes `getAssociatedSubTreePathsById()` to return
empty paths if there are no associated subtrees. However, it also
returns empty paths as a success, even if the given id is not valid.
This is to check the invalid case and to return NotFound.
For example, currently, this gives the success
- GET /redfish/v1/Chassis/INVALID/PowerSubsystem/PowerSupplies
Tested:
- GET with the invalid id and check the return condition.
```
busctl call -j "xyz.openbmc_project.ObjectMapper" "/xyz/openbmc_project/object_mapper" \
"xyz.openbmc_project.ObjectMapper" "GetAssociatedSubTreePathsById" ssassas \
"InvalidChassis" \
"/xyz/openbmc_project/inventory" \
1 "xyz.openbmc_project.Inventory.Item.Chassis" \
"powered_by" \
1 "xyz.openbmc_project.Inventory.Item.PowerSupply"
-->
Call failed: The resource is not found.
```
Change-Id: If4f621e105bc1a5c443c1ec8b7762f57748e1d10
Signed-off-by: Myung Bae <myungbae@us.ibm.com>
diff --git a/src/test/handler.cpp b/src/test/handler.cpp
index 46d998c..a295fbc 100644
--- a/src/test/handler.cpp
+++ b/src/test/handler.cpp
@@ -449,10 +449,11 @@
std::vector<std::string> endpointvalidInterfaces = {"test_interface_1",
"test_interface_2"};
// invalid id
- ASSERT_TRUE(getAssociatedSubTreeById(interfaceMap, associationMap, "childx",
- path, subtreeInterfaces, "descendent",
- endpointvalidInterfaces)
- .empty());
+ EXPECT_THROW(
+ getAssociatedSubTreeById(interfaceMap, associationMap, "childx", path,
+ subtreeInterfaces, "descendent",
+ endpointvalidInterfaces),
+ sdbusplus::xyz::openbmc_project::Common::Error::ResourceNotFound);
// invalid subtreeInterfaces
ASSERT_TRUE(getAssociatedSubTreeById(interfaceMap, associationMap, "child",
@@ -521,10 +522,11 @@
std::vector<std::string> endpointvalidInterfaces = {"test_interface_1",
"test_interface_2"};
// invalid id
- ASSERT_TRUE(getAssociatedSubTreePathsById(
- interfaceMap, associationMap, "childx", path,
- subtreeInterfaces, "descendent", endpointvalidInterfaces)
- .empty());
+ EXPECT_THROW(
+ getAssociatedSubTreePathsById(interfaceMap, associationMap, "childx",
+ path, subtreeInterfaces, "descendent",
+ endpointvalidInterfaces),
+ sdbusplus::xyz::openbmc_project::Common::Error::ResourceNotFound);
// invalid subtreeInterfaces
ASSERT_TRUE(getAssociatedSubTreePathsById(