Files
qt-migration-legatus/qt6-after/qt6-migrated-legatus/Lts/Services/NotificationManagement/ModuleTests/nom_tests.cpp
T
berrux-dev c3eda18234 Migrates remaining services and plugins to generated rtiddsgen API
Converts accessor calls to plain member access across the residual service set.
2026-09-21 02:47:48 +02:00

594 lines
20 KiB
C++
Executable File

/**
* MRK Function Topic test executable
* $Id$
* $HeadURL$
* $Author$
* Created by Hanna E. Rathje, ESZS, 2025-06-23
*/
#include "nom_tests.h"
#include "ngltools/ngltools_filesystem.h"
#include <nglapplication/nglcoreapplication.h>
#include <LtsCommandLineParser/LtsCommandLineParser.h>
#include <QtCore/QTimer>
#include <QtCore/QDateTime>
#include <QtCore/QString>
#include <QtCore/QVector>
#include <NotificationManagement/nom_ftc.h>
#include <NotificationManagement/nom_dtc.h>
#include <ParticipantManagement/ppm_operator_rights.h>
#include <FileManagement/flm_operator_rights.h>
#include <iostream>
#include <NotificationManagement/settings.h>
#include <LtsUtilsSettings/settings.h>
#include <nglsettings/nglsettings_settings.h>
#include <QSettings>
using namespace NotificationManagement;
//-----------------------------------------------------------------------------
NomTests::NomTests(QObject *parent)
: QObject(parent)
, m_exerciseId(0)
, m_testId(0)
, m_notificationId(0)
, m_eTestStep(eUnknown)
, m_bTestsSuccessful(true)
, m_logger(getLogger("NomTests"))
{
qRegisterMetaType<Core::FunctionReply>("Core::FunctionReply");
} // end of ctor()
//-----------------------------------------------------------------------------
NomTests::~NomTests()
{
} // end of dtor()
//-----------------------------------------------------------------------------
bool NomTests::init(int domainId, int exerciseId, int testId, int notificationId)
{
INFO_LOG(m_logger) << "MrkTests::init() "
<< " domainId:" << domainId
<< " exerciseId:" << exerciseId
<< " testId: " << testId
<< " notificationId: " << notificationId
;
m_testId = testId;
m_exerciseId = exerciseId;
m_notificationId = notificationId;
// initialize DDS
m_ddsConnector.reset(new DDSConnector::DdsConnector(domainId, IDL::PartitionType::AllExercises, exerciseId));
if (!m_ddsConnector->init())
return false;
m_ddsConnector->initPublisherSubscriber();
// Access to FTC
TRACE_LOG(m_logger) << "create ftc";
m_ftc = NotificationManagement::Interface::Ftc::create(m_ddsConnector);
TRACE_LOG(m_logger) << "init ftc";
bool bRet = m_ftc->enableAll();
TRACE_LOG(m_logger) << "init end - bRet = " << bRet;
// Access to DTC
TRACE_LOG(m_logger) << "create dtc";
m_dtc = NotificationManagement::Interface::Dtc::create(m_ddsConnector);
TRACE_LOG(m_logger) << "init dtc";
bRet &= m_dtc->enableAll();
TRACE_LOG(m_logger) << "init end - bRet = " << bRet;
// Access to OPM DTC
TRACE_LOG(m_logger) << "create opmDtc";
m_opmDtc = OperatorManagement::Interface::Dtc::create(m_ddsConnector);
m_opmDtc->enableUser();
return bRet;
} // end of init()
//-----------------------------------------------------------------------------
void NomTests::startTest()
{
INFO_LOG(m_logger) << "startTest() exerciseId:" << m_exerciseId
<< " testId:" << m_testId
<< " notificationId:" << m_notificationId
;
connect(m_dtc.get(), &Interface::Dtc::nomNotificationChanged,
this, &NomTests::onReceiveNotificationChanged);
switch(m_testId)
{
case 0:
QTimer::singleShot(0, this, &NomTests::tryCreate);//command ./nomTests -d xx -e xx -t 0
break;
case 1:
QTimer::singleShot(0, this, &NomTests::tryCreateHQ);//command ./nomTests -d xx -e xx -t 1
break;
case 2:
QTimer::singleShot(0, this, &NomTests::tryReadReceipt);
break;
case 3:
QTimer::singleShot(0, this, &NomTests::tryRemove);
break;
case 10:
QTimer::singleShot(0, this, &NomTests::tryGetAllNotifications);
break;
case 11:
QTimer::singleShot(0, this, &NomTests::tryGetNotification);
break;
}
} // end of startTest()
//-----------------------------------------------------------------------------
void NomTests::tryCreate()
{
m_eTestStep = eCreate;
CreateNotificationRequest data;
getCreateNotificationRequestData(data);
INFO_LOG(m_logger) << "trying to send CreateNotificationRequest";
if (!m_ftc->createNotificationRequest(data, this))
{
ERROR_LOG(m_logger) << "Error requesting create data";
failExit();
}
}
void NomTests::tryCreateHQ()
{
QScopedPointer<NGL::Settings> s (new NGL::Settings(NGL::findProjectConfigFile()));
qint64 currentTime = QDateTime::currentMSecsSinceEpoch();
qint64 expiryTime = currentTime + Settings::expiryIntervalMSec();
NotificationManagement::NomNotification notif;
notif.title = tr("HQ Reports ").toStdString();
// format: "[Open HQ Report Dialog](//flmHQReport/party=3&folder=51&file=12)"
// Open HQ Report Dialog : this text link will display on notification and is clickable
// url().host() to get host scheme_identifier: flmHQReport
// QString data = url().path().mid(1) to get "party=3&folder=51&file=12".
// with QUrlQuery query(data); // get each parameter: query.queryItemValue("party").toInt(); // same for the others
/// retrieve data in flm_explorer_gui_plugin.cpp
int partyId = 3; // place holder from ex_42.pppm_party PartyId BLUE
int folderId = 51; // place holder from flm_folder
int fileId = 12; // place holder from flm_file_content
QString linkName = QStringLiteral("Open HQ Report Dialog");
QString content = QStringLiteral("[%1](//flmHQReport/?party=%2&folder=%3&file=%4)");
content = content.arg(linkName).arg(partyId).arg(folderId).arg(fileId);
notif.content = content.toStdString();
notif.timeStamp = currentTime;
notif.expiryTime = expiryTime;
notif.priority = static_cast<NotificationManagement::Priority_def::type>(Settings::notificationPriority());
notif.processedPriority = NotificationManagement::Priority::Highest;
notif.exerciseId = m_exerciseId;
for (const auto &userId : m_opmDtc->getOperatorsByOperatorRight(OperatorRights::FileManagementFilesEdit))
{
NotificationManagement::Address addr;
addr.addressId = userId;
addr.isRead = false;
QString name = QStringLiteral("Operator ") + QString::number(userId);
addr.name = name.toStdString();
addr.addressType = NotificationManagement::AddressType::Operator;
addr.addressSubId = userId+10;
notif.recipientIds.push_back(addr);
}
// NotificationManagement::Address addrSender;
// addrSender.addressId(FileManagement::Offset);
// addrSender.name(tr("[FileManagement2](flmHQReport)").toStdString());
// addrSender.addressType(NotificationManagement::AddressType_def::Service);
// addrSender.addressSubId(321);
// notif.sender(addrSender);
NotificationManagement::CreateNotificationRequest notifReq;
notifReq.notification = notif;
if (!m_ftc->createNotificationRequest(notifReq, this))
ERROR_LOG(m_logger) << "Error requesting create Notification data";
} // end of tryCreate()
//-----------------------------------------------------------------------------
void NomTests::tryReadReceipt()
{
m_eTestStep = eReadReceipt;
m_dtc->waitForHistoricalDataNomNotification();
NotificationManagement::NomNotification data = m_dtc->nomNotification(m_notificationId);
NotificationManagement::Address recipientAddress = data.recipientIds.front();
//NotificationManagement::Address recipientAddress = data.recipientIds().at(2);
NotificationManagement::ReadReceiptRequest request;
request.addressId = recipientAddress.id;
request.operatorId = recipientAddress.addressId;
request.workstationId = 0;
request.notificationIds = {m_notificationId};
request.processed = true;
INFO_LOG(m_logger) << "trying to send CreateNotificationRequest";
if (!m_ftc->readReceiptRequest(request, this))
{
ERROR_LOG(m_logger) << "Error requesting readReceipt data";
failExit();
}
} // end of tryReadReceipt
//-----------------------------------------------------------------------------
void NomTests::tryRemove()
{
m_eTestStep = eRemove;
/*
NotificationRemoveRequest data;
data.id(m_notificationId);
INFO_LOG(m_logger) << "trying to send remove request for notificationId:" << data.id();
if (!m_ftc->notificationRemoveRequest(data, this))
{
ERROR_LOG(m_logger) << "Error requesting remove data for notificationId:" << data.id();
failExit();
}
*/
} // end of tryRemove()
//-----------------------------------------------------------------------------
void NomTests::tryGetAllNotifications()
{
m_eTestStep = eGetAllNotifications;
DEBUG_LOG(m_logger) << "trying to get all notifications";
m_dtc->waitForHistoricalDataNomNotification();
if (m_dtc->nomNotifications().isEmpty())
{
ERROR_LOG(m_logger) << "Error requesting all notification data";
QTimer::singleShot(0, qApp, &QCoreApplication::quit);
return;
}
for (const NomNotification &notif : m_dtc->nomNotifications())
{
// needed for Test 11 tryGetNotification
m_notificationId = notif.id;
INFO_LOG(m_logger) << "Nom(" << notif.id << ") :"
<< " title:" << notif.title
<< " content:" << notif.content
<< " timeStamp:" << notif.timeStamp
<< " priority:" << notif.priority
<< " processed: " << notif.processed
<< " processedTime: " << notif.processTime
<< " processPrio: " << notif.processedPriority
<< " recipient count:" << notif.recipientIds.size();
INFO_LOG(m_logger) << "SenderAddress(" << notif.sender.id << ") :"
<< " name: " << notif.sender.name
<< ", addressId: " << notif.sender.addressId
<< ", addressSubId: " << notif.sender.addressSubId
<< ", addressSubSubId: " << notif.sender.addressSubSubId
<< ", addressType: " << notif.sender.addressType;
}
QTimer::singleShot(0, qApp, &QCoreApplication::quit);
} // end of tryGetAllNotifications()
//-----------------------------------------------------------------------------
void NomTests::tryGetNotification()
{
DEBUG_LOG(m_logger) << "trying to get notification with id:" << m_notificationId;
if (m_testId > 1)
m_eTestStep = eGetNotification;
if (m_notificationId <= 0)
{
ERROR_LOG(m_logger) << "invalid notificationId - test aborted.";
failExit();
}
m_dtc->waitForHistoricalDataNomNotification();
NotificationManagement::NomNotification notif = m_dtc->nomNotification(m_notificationId);
if (notif.id <= 0)
{
ERROR_LOG(m_logger) << "Error receiving data for notificationId " << m_notificationId << " returnVal:" << notif.id;
failExit();
}
else
{
INFO_LOG(m_logger) << "NomNotification(" << notif.id << ") :"
<< " title:" << notif.title
<< " content:" << notif.content
<< " timeStamp:" << notif.timeStamp
<< " priority:" << notif.priority
<< " processed: " << notif.processed
<< " processedTime: " << notif.processTime
<< " processPrio: " << notif.processedPriority
<< " recipient count:" << notif.recipientIds.size();
for (const NotificationManagement::Address &addr : notif.recipientIds)
{
INFO_LOG(m_logger) << "Recipient(" << addr.id << ") :"
<< " name: " << addr.name
<< ", addressId: " << addr.addressId
<< ", addressSubId: " << addr.addressSubId
<< ", addressSubSubId: " << addr.addressSubSubId
<< ", addressType: " << addr.addressType
<< ", isRead: " << addr.isRead;
}
INFO_LOG(m_logger) << "SenderAddress(" << notif.sender.id << ") :"
<< " name: " << notif.sender.name
<< ", addressId: " << notif.sender.addressId
<< ", addressSubId: " << notif.sender.addressSubId
<< ", addressSubSubId: " << notif.sender.addressSubSubId
<< ", addressType: " << notif.sender.addressType;
}
if (m_testId == 0)
{
if (m_eTestStep == eCreate)
{
if (! onCompareCreatedData(notif))
{
ERROR_LOG(m_logger) << "Compare created data failed!";
failExit();
}
else
{
QTimer::singleShot(0, this, &NomTests::tryReadReceipt);
return;
}
}
}
QTimer::singleShot(0, qApp, &QCoreApplication::quit);
} // end of tryGetNotification()
//-----------------------------------------------------------------------------
void NomTests::onCreateNotificationReply(const Core::FunctionReplyObject &replyObject)
{
INFO_LOG(m_logger) << "Got createReply with id " << replyObject.id()
<< " and errorString " << replyObject.translated();
m_notificationId = replyObject.id();
if (replyObject.error())
{
ERROR_LOG(m_logger) << "Error requesting create data";
failExit();
return;
}
else
DEBUG_LOG(m_logger) << "Requesting create data ok. Got new id:" << replyObject.id() << " ... ok.";
if (m_testId == 0)
// QTimer::singleShot(0, this, &NomTests::tryModify()));
QTimer::singleShot(0, this, &NomTests::tryGetNotification);
else
QTimer::singleShot(0, qApp, &QCoreApplication::quit);
} // end of onNotificationCreateReply()
//-----------------------------------------------------------------------------
void NomTests::onReadReceiptReply(const Core::FunctionReplyObject &replyObject)
{
INFO_LOG(m_logger) << "Got onReadReceipt with id " << replyObject.id()
<< " and errorString " << replyObject.translated();
if (replyObject.error())
{
ERROR_LOG(m_logger) << "Error requesting ReadReceipt data for id:" << replyObject.id();
failExit();
return;
}
else
DEBUG_LOG(m_logger) << "Requesting ReadReceipt data for id:" << replyObject.id() << " ... ok.";
if (m_testId == 0)
// QTimer::singleShot(0, this, &MrkTests::tryDelete()));
QTimer::singleShot(0, this, &NomTests::tryGetNotification);
else
QTimer::singleShot(0, qApp, &QCoreApplication::quit);
} // end of onReadReceiptReply()
//-----------------------------------------------------------------------------
/*
void NomTests::onNotificationRemoveReply(const Core::FunctionReplyObject &replyObject)
{
INFO_LOG(m_logger) << "Got removeReply with id " << replyObject.id()
<< " and errorString " << replyObject.translated();
if (replyObject.error())
{
ERROR_LOG(m_logger) << "Error requesting remove data for NotificationId:" << replyObject.id();
failExit();
return;
}
else
DEBUG_LOG(m_logger) << "Requesting remove data for NotificationId:" << replyObject.id() << " ... ok.";
if (m_testId == 0)
{
QTimer::singleShot(0, this, &MrkTests::tryCreateSnapshot);
// ansonsten verheriger Ausstieg mit Errorlog.
}
QTimer::singleShot(0, qApp, &QCoreApplication::quit);
} // end of onNotificationRemoveReply()
*/
//-----------------------------------------------------------------------------
void NomTests::onReceiveNotificationChanged(const NomNotification &data, DataModification modType)
{
// INFO_LOG(m_logger) << "onReceiveNotificationChanged() notificationId:" << data.id()
// << " modificationType: = " << (int)modType<< " received";
switch (modType)
{
case DataModification::eAdded:
INFO_LOG(m_logger) << "*** NomNotification added received. notificationId:" << data.id;
break;
case DataModification::eModified:
INFO_LOG(m_logger) << "*** NomNotification modified received. notificationId:" << data.id;
break;
case DataModification::eRemoved:
INFO_LOG(m_logger) << "*** NomNotification removed received. notificationId:" << data.id;
break;
}
} // end of onReceiveNotificationChanged()
//-----------------------------------------------------------------------------
void NomTests::getCreateNotificationRequestData(CreateNotificationRequest &data)
{
qint64 currentTime = QDateTime::currentMSecsSinceEpoch();
// 100 seconds
qint64 expiryTime = currentTime + 100 * 1000;
NotificationManagement::NomNotification notif;
notif.title = "TestNotificationCreate";
notif.content = "Dies ist ein Test mit Content";
notif.timeStamp = currentTime;
notif.expiryTime = expiryTime;
notif.priority = NotificationManagement::Priority::High;
notif.processedPriority = NotificationManagement::Priority::Low;
notif.exerciseId = m_exerciseId;
for (int i=10; i< 24; i++)
{
NotificationManagement::Address addr;
addr.addressId = i;
addr.isRead = false;
QString name = QStringLiteral("Operator ") + QString::number(i);
addr.name = name.toStdString();
addr.addressType = NotificationManagement::AddressType::Operator;
addr.addressSubId = i+10;
notif.recipientIds.push_back(addr);
}
NotificationManagement::Address wsAddr;
wsAddr.addressId = 302;
wsAddr.isRead = false;
QString name = QStringLiteral("Workstation 2 ");
wsAddr.name = name.toStdString();
wsAddr.addressType = NotificationManagement::AddressType::Workstation;
notif.recipientIds.push_back(wsAddr);
NotificationManagement::Address addrSender;
addrSender.addressId = ParticipantManagement::Offset;
addrSender.name = QStringLiteral("svcParticipantManagement ").toStdString();
addrSender.addressType = NotificationManagement::AddressType::Service;
notif.sender = addrSender;
data.notification = notif;
} // end of getCreateNotificationRequestData()
//-----------------------------------------------------------------------------
bool NomTests::onCompareCreatedData(NomNotification &data)
{
DEBUG_LOG(m_logger) << "start onCompareCreatedData() for id :" << data.id;
// Vergleicht die zurueckgelesen Datan mit den statischen create Daten
CreateNotificationRequest createData;
getCreateNotificationRequestData(createData);
if (createData.notification.title != data.title)
return false;
if (createData.notification.priority != data.priority)
return false;
if (createData.notification.content != data.content)
return false;
if (createData.notification.processedPriority != data.processedPriority)
return false;
return true;
} // end of onCompareCreatedData()
//-----------------------------------------------------------------------------
void NomTests::failExit()
{
m_bTestsSuccessful = false;
QTimer::singleShot(0, qApp, &QCoreApplication::quit);
}
//-----------------------------------------------------------------------------
class CmdLineParser : public LtsCommandLineParser::LtsCommandLineParser
{
public:
CmdLineParser()
: LtsCommandLineParser()
{
addOption({ QStringList() << QStringLiteral("t") << QStringLiteral("testId")
, QStringLiteral("TestId.")
, QStringLiteral("Default: 0 (all FTC/DTC tests), 1 create, 2 readReceipt, 3 remove, 10 getAllNotification and Recipients, 11 getNotification")
, QStringLiteral("0")
});
addOption({ QStringList() << QStringLiteral("n") << QStringLiteral("notificationId")
, QStringLiteral("NotificationId.")
, QStringLiteral("Used for tests 2, 3 & 11 only to select the notification")
, QStringLiteral("0")
});
}
int testId() const { return isSet(QStringLiteral("t")) ? value(QStringLiteral("t")).toInt() : -1; }
int notificationId() const { return isSet(QStringLiteral("n")) ? value(QStringLiteral("n")).toInt() : -1; }
};
//-----------------------------------------------------------------------------
int main(int argc, char **argv)
{
NGLCoreApplication app(argc, argv);
app.createLogger("nom", "log4cxx_nom_module_tests.props");
int iRet = -1;
CmdLineParser options;
if (!options.init())
return iRet;
std::unique_ptr<NotificationManagement::NomTests> NomTests(new NotificationManagement::NomTests);
if (!NomTests->init(options.domainId(), options.exerciseId(), options.testId(), options.notificationId()))
return iRet;
QTimer::singleShot(2000, NomTests.get(), &NotificationManagement::NomTests::startTest);
STARTUP_LOG(app.baseLogger());
app.exec();
iRet = NomTests->testsSuccessful() ? 0 : 1;
fprintf(stderr, "%d\n", iRet);
DEBUG_LOG(app.baseLogger()) << "** TEST result = " << iRet;
SHUTDOWN_LOG(app.baseLogger());
return iRet;
}
//-----------------------------------------------------------------------------