Skip to content

Commit 5eda265

Browse files
Extended Data Unit Tests
1 parent 154e561 commit 5eda265

8 files changed

Lines changed: 2143 additions & 0 deletions

Implementation/UnitTest/amc_unittests_libmcdata_alerts.hpp

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ namespace AMCUnitTest {
5656
registerTest("Acknowledgement", "Test alert acknowledgement", eUnitTestCategory::utMandatoryPass, std::bind(&CUnitTestGroup_LibMCData_Alerts::testAcknowledgement, this));
5757
registerTest("RetrieveAlerts", "Test retrieving multiple alerts", eUnitTestCategory::utMandatoryPass, std::bind(&CUnitTestGroup_LibMCData_Alerts::testRetrieveAlerts, this));
5858
registerTest("AlertProperties", "Test alert properties", eUnitTestCategory::utMandatoryPass, std::bind(&CUnitTestGroup_LibMCData_Alerts::testAlertProperties, this));
59+
60+
// Additional AlertSession tests for coverage
61+
registerTest("RetrieveByType", "Retrieve alerts by type", eUnitTestCategory::utMandatoryPass, std::bind(&CUnitTestGroup_LibMCData_Alerts::testRetrieveByType, this));
62+
registerTest("RetrieveActiveByType", "Retrieve active alerts by type", eUnitTestCategory::utMandatoryPass, std::bind(&CUnitTestGroup_LibMCData_Alerts::testRetrieveActiveByType, this));
5963
}
6064

6165
void initializeTests() override {
@@ -316,6 +320,97 @@ namespace AMCUnitTest {
316320
std::string sLevelString = pAlert->GetLevelString();
317321
assertFalse(sLevelString.empty(), "Level string should not be empty");
318322
}
323+
324+
// ============= Additional AlertSession Tests =============
325+
326+
void testRetrieveByType()
327+
{
328+
auto fixture = createFixture("by_type");
329+
330+
// Use the same identifier for all alerts we want to retrieve together
331+
std::string sTypeIdentifier = "typealert";
332+
333+
// Create 3 alerts with the SAME identifier (this is the key for RetrieveAlertsByType)
334+
for (int i = 0; i < 3; i++) {
335+
std::string sUUID = AMCCommon::CUtils::createUUID();
336+
fixture.m_pAlertSession->AddAlert(
337+
sUUID,
338+
sTypeIdentifier, // Same identifier for all
339+
LibMCData::eAlertLevel::Warning,
340+
"Type test " + std::to_string(i),
341+
"",
342+
"",
343+
false,
344+
"2025-01-01T12:00:0" + std::to_string(i) + "Z"
345+
);
346+
}
347+
348+
// Create alerts with different identifier
349+
for (int i = 0; i < 2; i++) {
350+
std::string sUUID = AMCCommon::CUtils::createUUID();
351+
fixture.m_pAlertSession->AddAlert(
352+
sUUID,
353+
"othertype", // Different identifier
354+
LibMCData::eAlertLevel::Message,
355+
"Other type " + std::to_string(i),
356+
"",
357+
"",
358+
false,
359+
"2025-01-01T13:00:0" + std::to_string(i) + "Z"
360+
);
361+
}
362+
363+
// Retrieve by type (bOnlyActive = false)
364+
auto pIterator = fixture.m_pAlertSession->RetrieveAlertsByType(sTypeIdentifier, false);
365+
366+
uint64_t nCount = pIterator->Count();
367+
assertTrue(nCount >= 3, "Should have at least 3 alerts of type");
368+
}
369+
370+
void testRetrieveActiveByType()
371+
{
372+
auto fixture = createFixture("active_by_type");
373+
374+
// Use the same identifier for both alerts
375+
std::string sTypeIdentifier = "activetyp";
376+
377+
// Create active alert
378+
std::string sActiveUUID = AMCCommon::CUtils::createUUID();
379+
auto pActiveAlert = fixture.m_pAlertSession->AddAlert(
380+
sActiveUUID,
381+
sTypeIdentifier, // Same identifier
382+
LibMCData::eAlertLevel::Warning,
383+
"Active type test",
384+
"",
385+
"",
386+
false,
387+
"2025-01-01T12:00:00Z"
388+
);
389+
390+
// Create another alert with same identifier, then deactivate
391+
std::string sInactiveUUID = AMCCommon::CUtils::createUUID();
392+
auto pInactiveAlert = fixture.m_pAlertSession->AddAlert(
393+
sInactiveUUID,
394+
sTypeIdentifier, // Same identifier
395+
LibMCData::eAlertLevel::Warning,
396+
"Inactive type test",
397+
"",
398+
"",
399+
false,
400+
"2025-01-01T12:00:01Z"
401+
);
402+
pInactiveAlert->DeactivateAlert();
403+
404+
// Retrieve only active by type
405+
auto pActiveIterator = fixture.m_pAlertSession->RetrieveAlertsByType(sTypeIdentifier, true);
406+
uint64_t nActiveCount = pActiveIterator->Count();
407+
assertTrue(nActiveCount >= 1, "Should have at least 1 active alert of type");
408+
409+
// Retrieve all by type
410+
auto pAllIterator = fixture.m_pAlertSession->RetrieveAlertsByType(sTypeIdentifier, false);
411+
uint64_t nAllCount = pAllIterator->Count();
412+
assertTrue(nAllCount >= 2, "Should have at least 2 total alerts of type");
413+
}
319414
};
320415

321416
}

0 commit comments

Comments
 (0)