242 lines
8.1 KiB
C++
Executable File
242 lines
8.1 KiB
C++
Executable File
/**
|
|
* AES Function Topic Client test executable
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
*/
|
|
|
|
#include "aes_test_charge_administration.h"
|
|
#include <QCoreApplication>
|
|
#include <QTest>
|
|
#include <QTimer>
|
|
|
|
namespace AreaEffectSimulation
|
|
{
|
|
static const int s_ChargeAmount = 600;
|
|
|
|
TestChargeAdministration::TestChargeAdministration(QObject *parent)
|
|
: TestBase("Test.ChargeAdministration", parent)
|
|
{
|
|
}
|
|
|
|
bool TestChargeAdministration::init(int domainId, int exerciseId, int testId)
|
|
{
|
|
if (!TestBase::init(domainId, exerciseId, testId))
|
|
return false;
|
|
|
|
m_testId = testId;
|
|
m_caData.id(-1);
|
|
DEBUG_LOG(m_logger) << "Test Id = " << m_testId;
|
|
|
|
m_dtc->waitForHistoricalDataChargeAdministration();
|
|
|
|
connect(m_dtc.get(), &AreaEffectSimulation::Interface::Dtc::chargeAdministrationChanged, this, &TestChargeAdministration::chargeAdministrationChanged);
|
|
return true;
|
|
}
|
|
|
|
bool TestChargeAdministration::checkBaseData(const AreaEffectSimulation::ChargeAdministration &a, const AreaEffectSimulation::ChargeAdministration &b) const
|
|
{
|
|
|
|
if (a.amount() != b.amount())
|
|
{
|
|
WARNING_LOG(m_logger) << "Amount does not match: " << a.amount() << " - " << b.amount();
|
|
return false;
|
|
}
|
|
|
|
if (a.planned() != b.planned())
|
|
{
|
|
WARNING_LOG(m_logger) << "Planned does not match: " << a.planned() << " - " << b.planned();
|
|
return false;
|
|
}
|
|
|
|
if (a.chargeTypeId() != b.chargeTypeId())
|
|
{
|
|
WARNING_LOG(m_logger) << "ChargeTypeId does not match: " << a.chargeTypeId() << " - " << b.chargeTypeId();
|
|
return false;
|
|
}
|
|
|
|
if (a.partyId() != b.partyId())
|
|
{
|
|
WARNING_LOG(m_logger) << "PartyId does not match: " << a.partyId() << " - " << b.partyId();
|
|
return false;
|
|
}
|
|
|
|
if (a.used() != b.used())
|
|
{
|
|
WARNING_LOG(m_logger) << "Used does not match: " << a.used() << " - " << b.used();
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
//
|
|
// ChargeAdministration
|
|
//
|
|
void TestChargeAdministration::tryCreateChargeAdministration()
|
|
{
|
|
m_caData = AreaEffectSimulation::ChargeAdministration();
|
|
m_expectedAesId = -1;
|
|
AreaEffectSimulation::ChargeAdministration esData;
|
|
|
|
esData.chargeTypeId(471);
|
|
esData.partyId(2);
|
|
esData.amount(450);
|
|
esData.effectSourceId(ProjectDataManagement::EffectSource::ES_Internal);
|
|
|
|
INFO_LOG(m_logger) << "trying to send ChargeAdministrationCreateRequest()";
|
|
m_replyError = false;
|
|
m_bIsCreatedRequest = true;
|
|
|
|
// amountChangedByOperator=true
|
|
if (!m_ftc->chargeAdministrationModifyRequest(ChargeAdministrationModifyRequest(0,
|
|
esData.chargeTypeId(),
|
|
esData.partyId(),
|
|
esData.effectSourceId(),
|
|
esData.amount(),
|
|
true),
|
|
this))
|
|
{
|
|
ERROR_LOG(m_logger) << "Error during ChargeAdministrationCreateRequest()";
|
|
failExit();
|
|
return;
|
|
}
|
|
|
|
if (!waitForData([this]() { return m_caData.id() == m_expectedAesId; }))
|
|
{
|
|
ERROR_LOG(m_logger) << "Error creating charge admin object";
|
|
failExit();
|
|
return;
|
|
}
|
|
if (!checkBaseData(m_caData, esData))
|
|
{
|
|
ERROR_LOG(m_logger) << "Creation data does not match published data";
|
|
failExit();
|
|
return;
|
|
}
|
|
QTimer::singleShot(0, this, &TestChargeAdministration::tryModifyChargeAdministration);
|
|
INFO_LOG(m_logger) << "tryCreateChargeAdministration successful";
|
|
}
|
|
|
|
void TestChargeAdministration::tryModifyChargeAdministration()
|
|
{
|
|
INFO_LOG(m_logger) << "trying to send modify request";
|
|
m_caData.chargeTypeId(471);
|
|
m_caData.partyId(2);
|
|
m_caData.amount(600);
|
|
|
|
const AreaEffectSimulation::ChargeAdministration esData(m_caData);
|
|
m_caData = AreaEffectSimulation::ChargeAdministration();
|
|
m_caData.id(esData.id());
|
|
m_bIsCreatedRequest = false;
|
|
|
|
// amountChangedByOperator=true
|
|
if (!m_ftc->chargeAdministrationModifyRequest(ChargeAdministrationModifyRequest(esData.id(),
|
|
esData.chargeTypeId(),
|
|
esData.partyId(),
|
|
esData.effectSourceId(),
|
|
esData.amount(),
|
|
true),
|
|
this))
|
|
{
|
|
ERROR_LOG(m_logger) << "Error requesting modify data";
|
|
failExit();
|
|
return;
|
|
}
|
|
|
|
if (!waitForData([this]() { return m_caData.amount() == s_ChargeAmount; }))
|
|
{
|
|
ERROR_LOG(m_logger) << "Error updating charge admin object";
|
|
failExit();
|
|
return;
|
|
}
|
|
|
|
QTimer::singleShot(0, qApp, &QCoreApplication::quit);
|
|
INFO_LOG(m_logger) << "tryModifyChargeAdministration successful";
|
|
}
|
|
|
|
//
|
|
// ChargeAdministration
|
|
//
|
|
void TestChargeAdministration::chargeAdministrationChanged(const AreaEffectSimulation::ChargeAdministration &data, DataModification modType)
|
|
{
|
|
if (m_caData.id() < 0)
|
|
return;
|
|
INFO_LOG(m_logger) << "Got ChargeAdministrationData with mod type " << (int)modType << ", id: " << data.id() << ", name: " << data.chargeTypeId()
|
|
<< ", amount: " << data.amount();
|
|
if ((modType == DataModification::eAdded && m_caData.id() == 0) || (modType == DataModification::eModified && m_caData.id() == data.id()))
|
|
{
|
|
DEBUG_LOG(m_logger) << "** Updating m_caData";
|
|
m_caData = data;
|
|
}
|
|
}
|
|
|
|
void TestChargeAdministration::onChargeAdministrationModifyReply(const Core::FunctionReplyObject &replyObject)
|
|
{
|
|
if (m_bIsCreatedRequest)
|
|
onAesCreateReply(replyObject);
|
|
else
|
|
onAesModifyReply(replyObject);
|
|
}
|
|
|
|
void TestChargeAdministration::tryCreateCA()
|
|
{
|
|
tryCreateChargeAdministration(371, 3, 1383);
|
|
tryCreateChargeAdministration(371, 2, 1382);
|
|
tryCreateChargeAdministration(372, 3, 1393);
|
|
tryCreateChargeAdministration(372, 2, 1392);
|
|
tryCreateChargeAdministration(381, 3, 9999);
|
|
tryCreateChargeAdministration(382, 3, 9999);
|
|
QTimer::singleShot(0, qApp, &QCoreApplication::quit);
|
|
}
|
|
|
|
void TestChargeAdministration::tryCreateChargeAdministration(int chargeTypeId, int partyId, int amount)
|
|
{
|
|
m_caData = AreaEffectSimulation::ChargeAdministration();
|
|
AreaEffectSimulation::ChargeAdministration esData;
|
|
|
|
esData.chargeTypeId(chargeTypeId);
|
|
esData.partyId(partyId);
|
|
esData.amount(amount);
|
|
esData.amountChangedByOperator(true);
|
|
|
|
INFO_LOG(m_logger) << "trying to send ChargeAdministrationCreateRequest(int,int,int)";
|
|
m_replyError = false;
|
|
m_bIsCreatedRequest = true;
|
|
// amountChangedByOperator=true
|
|
if (!m_ftc->chargeAdministrationModifyRequest(ChargeAdministrationModifyRequest(0,
|
|
esData.chargeTypeId(),
|
|
esData.partyId(),
|
|
esData.effectSourceId(),
|
|
esData.amount(),
|
|
true),
|
|
this))
|
|
{
|
|
ERROR_LOG(m_logger) << "Error during ChargeAdministrationCreateRequest()";
|
|
failExit();
|
|
return;
|
|
}
|
|
|
|
if (!waitForData([this]() { return m_caData.id() == m_expectedAesId; }))
|
|
{
|
|
ERROR_LOG(m_logger) << "Error creating charge admin object";
|
|
failExit();
|
|
return;
|
|
}
|
|
if (!checkBaseData(m_caData, esData))
|
|
{
|
|
ERROR_LOG(m_logger) << "Creation data does not match published data";
|
|
failExit();
|
|
return;
|
|
}
|
|
INFO_LOG(m_logger) << "tryCreateChargeAdministration successful";
|
|
QTimer::singleShot(0, qApp, &QCoreApplication::quit);
|
|
}
|
|
|
|
} // namespace AreaEffectSimulation
|
|
|
|
// ------------------------------------------------------------------
|
|
int main(int argc, char **argv)
|
|
{
|
|
return AreaEffectSimulation::mainBase(argc, argv, []() { return new AreaEffectSimulation::TestChargeAdministration; });
|
|
}
|