From 40d8b14e4d460e8e1c03e5f2d672b4f621fd34bd Mon Sep 17 00:00:00 2001 From: dan-du-car <62157949+dan-du-car@users.noreply.github.com> Date: Thu, 7 Dec 2023 15:02:12 -0500 Subject: [PATCH] Telematic bridge: Fix available topic return null value in topics field when there is no topic available (#569) # PR Details ## Description Telematic bridge sends null topics when there is no topic available. The idea value for this topics is empty array value [] rather than a null value. This PR is to initialize the topics value with empty array ## Related Issue https://github.com/usdot-fhwa-OPS/V2X-Hub/issues/570 ## Motivation and Context telematic testing ## How Has This Been Tested? Integration test ## Types of changes - [x] Defect fix (non-breaking change that fixes an issue) - [ ] New feature (non-breaking change that adds functionality) - [ ] Breaking change (fix or feature that cause existing functionality to change) ## Checklist: - [ ] I have added any new packages to the sonar-scanner.properties file - [ ] My change requires a change to the documentation. - [ ] I have updated the documentation accordingly. - [x] I have read the **CONTRIBUTING** document. [V2XHUB Contributing Guide](https://github.com/usdot-fhwa-OPS/V2X-Hub/blob/develop/Contributing.md) - [ ] I have added tests to cover my changes. - [ ] All new and existing tests passed. --- src/v2i-hub/TelematicBridgePlugin/src/TelematicUnit.cpp | 2 +- src/v2i-hub/TelematicBridgePlugin/test/test_TelematicUnit.cpp | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/v2i-hub/TelematicBridgePlugin/src/TelematicUnit.cpp b/src/v2i-hub/TelematicBridgePlugin/src/TelematicUnit.cpp index e99029b53..948b9f017 100644 --- a/src/v2i-hub/TelematicBridgePlugin/src/TelematicUnit.cpp +++ b/src/v2i-hub/TelematicBridgePlugin/src/TelematicUnit.cpp @@ -219,7 +219,7 @@ namespace TelematicBridge message[TESTING_TYPE_KEY] = testingType; message[EVENT_NAME_KEY] = eventName; message[TIMESTAMP_KEY] = duration_cast(system_clock::now().time_since_epoch()).count(); - Json::Value topics; + Json::Value topics = Json::arrayValue; for (const auto &topic : availableTopicList) { if (!boost::icontains(excludedTopics, topic)) diff --git a/src/v2i-hub/TelematicBridgePlugin/test/test_TelematicUnit.cpp b/src/v2i-hub/TelematicBridgePlugin/test/test_TelematicUnit.cpp index 9a81427b4..c1fbdae50 100644 --- a/src/v2i-hub/TelematicBridgePlugin/test/test_TelematicUnit.cpp +++ b/src/v2i-hub/TelematicBridgePlugin/test/test_TelematicUnit.cpp @@ -43,6 +43,10 @@ namespace TelematicBridge auto reply = TelematicUnit::constructAvailableTopicsReplyString(unit, eventLocation, testingType, eventName, topics, excluded_topic); auto json = TelematicUnit::parseJson(reply); ASSERT_EQ("test_topic", json["topics"][0]["name"].asString()); + + reply = TelematicUnit::constructAvailableTopicsReplyString(unit, eventLocation, testingType, eventName, {}, excluded_topic); + json = TelematicUnit::parseJson(reply); + ASSERT_EQ(1, json["topics"].isArray()); } TEST_F(test_TelematicUnit, constructPublishedDataString)