Skip to content

Commit

Permalink
code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-du-car committed Nov 22, 2023
1 parent 4370816 commit 2d6364a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 12 deletions.
29 changes: 17 additions & 12 deletions src/v2i-hub/TelematicBridgePlugin/src/TelematicUnit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,9 @@ namespace TelematicBridge
auto s = natsConnection_RequestString(&reply, _conn, REGISTER_UNIT_TOPIC, payload.c_str(), TIME_OUT);
if (s == NATS_OK)
{
auto responseStr = natsMsg_GetData(reply);
PLOG(logINFO) << "Received registered reply: " << responseStr;
auto root = parseJson(responseStr);
if (root.isMember(LOCATION) && root.isMember(TESTING_TYPE) && root.isMember(EVENT_NAME))
{
_eventLocation = root[LOCATION].asString();
_testingType = root[TESTING_TYPE].asString();
_eventName = root[EVENT_NAME].asString();

// Unit is registered when server responds with event information (location, testing_type, event_name)
_isRegistered = true;
}
auto replyStr = natsMsg_GetData(reply);
PLOG(logINFO) << "Received registered reply: " << replyStr;
updateRegisterStatus(replyStr);
natsMsg_Destroy(reply);
}
else
Expand All @@ -59,6 +50,20 @@ namespace TelematicBridge
}
}

void TelematicUnit::updateRegisterStatus(const string &registerReply)
{
auto root = parseJson(registerReply);
if (root.isMember(LOCATION) && root.isMember(TESTING_TYPE) && root.isMember(EVENT_NAME))
{
_eventLocation = root[LOCATION].asString();
_testingType = root[TESTING_TYPE].asString();
_eventName = root[EVENT_NAME].asString();

// Unit is registered when server responds with event information (location, testing_type, event_name)
_isRegistered = true;
}
}

void TelematicUnit::availableTopicsReplier()
{
if (!_subAvailableTopic)
Expand Down
6 changes: 6 additions & 0 deletions src/v2i-hub/TelematicBridgePlugin/src/TelematicUnit.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ namespace TelematicBridge
*/
void updateAvailableTopics(const string &newTopic);

/**
* @brief Update telematic unit registration status with the registration reply from NATS server
* @param string Register reply in Json format
*/
void updateRegisterStatus(const string& registerReply);

/**
* @brief construct Json data string that will be streamed into the cloud by a publisher
* @param unit_st struct that contains unit related information
Expand Down
9 changes: 9 additions & 0 deletions src/v2i-hub/TelematicBridgePlugin/test/test_TelematicUnit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,13 @@ namespace TelematicBridge
_telematicUnitPtr->clearSelectedTopics();
ASSERT_FALSE(_telematicUnitPtr->inSelectedTopics(selectedTopic));
}
TEST_F(test_TelematicUnit, updateRegisterStatus)
{
string replyStr = "{\"event_name\":\"Test\",\"location\":\"Local\",\"testing_type\":\"Integration\"}";
_telematicUnitPtr->updateRegisterStatus(replyStr);
ASSERT_EQ("Local", _telematicUnitPtr->getEventLocation());
ASSERT_EQ("Test", _telematicUnitPtr->getEventName());
ASSERT_EQ("Integration", _telematicUnitPtr->getTestingType());
}

}

0 comments on commit 2d6364a

Please sign in to comment.