/** * @RDE_HEADER@ * ISM Function Topic test executable * $Id$ * $HeadURL$ * $Author$ * Created by Iuliana Ojog, SLSE, 2016-11-28 */ #include "ism_tests.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include /* ---------------------------------------------------------------------------------- * HOW TO RUN THE TESTS (for example) * ---------------------------------------------------------------------------------- * 0. Preconditions: * Start with an empty database (BUILD) * make db * Start services: (SV) * ./bin/svcExerciseManagement -d 74 & * ./bin/svcInfrastructureManagement -d 74 & * Test steps: see ism_tests.csv */ // ------------------------------------------------------------------------------ using namespace InfrastructureManagement; IsmTests::IsmTests(QObject *parent) : QObject(parent) , m_testId(0) , m_assetId(0) , m_mainStructureElementId(0) , m_structureElementId(0) , m_indexNo(0) , m_bTestsSuccessful(true) , m_logger(getLogger("Test")) { qRegisterMetaType("Core::FunctionReply"); } // ------------------------------------------------------------------------------ IsmTests::~IsmTests() { } // ------------------------------------------------------------------------------ bool IsmTests::init(int domainId, int testId, int assetId, int mainStructureElementId, int structureElementId, int indexNo) { INFO_LOG(m_logger) << "init begin"; m_testId = testId; m_assetId = assetId; m_mainStructureElementId = mainStructureElementId; m_structureElementId = structureElementId; m_indexNo = indexNo; // initialize DDS, always on exercise 0 m_ddsConnector.reset(new DDSConnector::DdsConnector(domainId, IDL::PartitionType::Global)); if (!m_ddsConnector->init()) return false; m_ddsConnector->initPublisherSubscriber(); // initialize database m_dbHandler = std::make_shared(); if(!m_dbHandler->init(0, Settings::settings())) { ERROR_LOG(m_logger) << "Initialisation dbHandler failed."; return false; } DEBUG_LOG(m_logger) << "Initialisation dbHandler succesful."; m_db = m_dbHandler->db(); TRACE_LOG(m_logger) << "create dtc"; m_dtc = InfrastructureManagement::Interface::Dtc::create(m_ddsConnector); TRACE_LOG(m_logger) << "init dtc"; bool bRet = m_dtc->enableAll(); TRACE_LOG(m_logger) << "init dtc end - bRet = " << bRet; TRACE_LOG(m_logger) << "create ftc"; m_ftc = InfrastructureManagement::Interface::Ftc::create(m_ddsConnector); TRACE_LOG(m_logger) << "init ftc"; bRet &= m_ftc->enableAll(); TRACE_LOG(m_logger) << "init ftc end - bRet = " << bRet; DEBUG_LOG(m_logger) << "########### Domain Id = " << domainId; DEBUG_LOG(m_logger) << "########### Test Id = " << testId; DEBUG_LOG(m_logger) << "########### Asset Id = " << assetId; DEBUG_LOG(m_logger) << "########### Main Structure Element Id = " << mainStructureElementId; DEBUG_LOG(m_logger) << "########### Structure Element Id = " << structureElementId; DEBUG_LOG(m_logger) << "########### Index No = " << indexNo; return bRet; } // ------------------------------------------------------------------------------ void IsmTests::startTest() { INFO_LOG(m_logger) << "********* startTest **************"; // main structure elements switch (m_testId) { // main structure elements case 101: tryCreateMainStructureElement(); break; case 102: tryModifyMainStructureElement(); break; case 103: tryRemoveMainStructureElement(); break; case 104: tryCreateBridge(); break; case 105: tryChangeBridgeStatus(); break; // assets case 131: tryCreateAsset(); break; case 132: tryModifyAsset(); break; case 133: tryRemoveAsset(); break; case 134: tryUnmountAsset(); break; // mounting point asset case 141: tryCreateMountingPointAsset(); break; case 143: tryRemoveMountingPointAsset(); break; // mounting point schedule case 151: tryCreateMainSchedule(); break; case 152: tryModifyMainSchedule(); break; case 153: tryRemoveMainSchedule(); break; case 154: tryChangeStatusSchedule(); break; case 155: tryCopySchedule(); break; case 156: checkSchedule(); break; // mouting point plan case 161: tryCreateMountingPointPlan(); break; default: failExit(); break; } INFO_LOG(m_logger) << "********* endTest **************"; QTimer::singleShot(0, qApp, &QCoreApplication::quit); } // ------------------------------------------------------------------------------ static void addElementToRequest(MainStructureElementModifyRequest &request, const StructureElement &se, int parentIdx) { const size_t size = request.elements().size(); request.elements().resize(size + 1, se); request.childParentRelations().resize(size + 1, parentIdx); } // ************* MAIN STRUCTURE ELEMENT ********************************************** // ------------------------------------------------------------------------------ void IsmTests::tryCreateMainStructureElement() { INFO_LOG(m_logger) << "trying to send MainStructureElementCreateRequest"; MainStructureElementModifyRequest data; // Building 56 data.name("Test Building"); QJsonObject jsonObj; jsonObj[QStringLiteral("street")] = QStringLiteral("Brueggeweg"); jsonObj[QStringLiteral("number")] = QStringLiteral("56"); // '{"street":"Brueggeweg", "number":"56"}' QJsonDocument doc(jsonObj); data.description(doc.toJson().toStdString()); data.angle(30.5); data.modelId(1001); data.externalWlsId(1001); data.geoPosition().lon(0.1552736550); data.geoPosition().lat(0.9259746511); data.geoPosition().z(0.00); data.properties("{}"); data.structureElementTypeId(InfrastructureManagement::StructureElementType::Building); StructureElement seData; // element 1 & 2 -> see ParseBuildingXml::parseXmlInternal() // building, idx = 0 seData.name("Test Building"); seData.displayName("Building 56"); seData.structureElementTypeId(InfrastructureManagement::StructureElementType::Building); seData.relPosition().offsetX(0); seData.relPosition().offsetY(0); seData.relPosition().offsetZ(0); seData.mountingPointTypeId(InfrastructureManagement::MountingPointType::Unknown); seData.properties("{\"description\":\"Info Test Building\"}"); addElementToRequest(data, seData, -1); // root element has no parent // building mounting point, idx = 1 seData.name("Test Building - Mounting Point"); seData.displayName("Building 56 - MP"); seData.structureElementTypeId(InfrastructureManagement::StructureElementType::MountingPoint); seData.barcode("4711"); seData.relPosition().offsetX(0); seData.relPosition().offsetY(0); seData.relPosition().offsetZ(0); seData.mountingPointTypeId(InfrastructureManagement::MountingPointType::BuildingControlUnit); seData.properties("{\"description\":\"Info Test Mounting Point\"}"); addElementToRequest(data, seData, 0); // Floor 1, idx = 1 seData.name("Floor 01"); seData.displayName("Floor 1"); seData.structureElementTypeId(InfrastructureManagement::StructureElementType::Floor); // type floor seData.barcode("123xxxx"); seData.relPosition().offsetX(70000); seData.relPosition().offsetY(90000); seData.relPosition().offsetZ(10); seData.mountingPointTypeId(InfrastructureManagement::MountingPointType::Unknown); seData.orientation(Core::Orientation(0, 0, 0)); seData.properties("{\"description\":\"Info-Building-56-Floor-01\"}"); addElementToRequest(data, seData, 0); // Floor 2, idx = 2 seData.name("Floor 02"); seData.displayName("Floor 2"); seData.structureElementTypeId(InfrastructureManagement::StructureElementType::Floor); // type floor seData.barcode("123xxxx"); seData.relPosition().offsetX(70000); seData.relPosition().offsetY(90000); seData.relPosition().offsetZ(10); seData.mountingPointTypeId(InfrastructureManagement::MountingPointType::Unknown); seData.orientation(Core::Orientation(0, 0, 0)); seData.properties("{\"description\":\"Info-Building-56-Floor-02\"}"); addElementToRequest(data, seData, 0); // Room 01-01, idx = 3 seData.name("Room 01"); seData.displayName("Room 01"); seData.structureElementTypeId(InfrastructureManagement::StructureElementType::Room); // type room seData.barcode("123xxxx"); seData.relPosition().offsetX(70000); seData.relPosition().offsetY(90000); seData.relPosition().offsetZ(10); seData.mountingPointTypeId(InfrastructureManagement::MountingPointType::Unknown); seData.orientation(Core::Orientation(0, 0, 0)); seData.properties("{\"description\":\"Info-Building-56-Floor-01-Room-01\"}"); addElementToRequest(data, seData, 1); // Room 01-02, idx = 4 seData.name("Room 02"); seData.displayName("Room 02"); seData.structureElementTypeId(InfrastructureManagement::StructureElementType::Room); // type room seData.barcode("123xxxx"); seData.relPosition().offsetX(70000); seData.relPosition().offsetY(90000); seData.relPosition().offsetZ(10); seData.mountingPointTypeId(InfrastructureManagement::MountingPointType::Unknown); seData.orientation(Core::Orientation(0, 0, 0)); seData.properties("{\"description\":\"Info-Building-56-Floor-01-Room-02\"}"); addElementToRequest(data, seData, 1); // Room 02-01, idx = 5 seData.name("Room 01"); seData.displayName("Room 01"); seData.structureElementTypeId(InfrastructureManagement::StructureElementType::Room); // type room seData.barcode("123xxxx"); seData.relPosition().offsetX(70000); seData.relPosition().offsetY(90000); seData.relPosition().offsetZ(10); seData.mountingPointTypeId(InfrastructureManagement::MountingPointType::Unknown); seData.orientation(Core::Orientation(0, 0, 0)); seData.properties("{\"description\":\"Info-Building-56-Floor-02-Room-01\"}"); addElementToRequest(data, seData, 2); // Room 02-02, idx = 6 seData.name("Room 02"); seData.displayName("Room 02"); seData.structureElementTypeId(InfrastructureManagement::StructureElementType::Room); // type room seData.barcode("123xxxx"); seData.relPosition().offsetX(70000); seData.relPosition().offsetY(90000); seData.relPosition().offsetZ(10); seData.mountingPointTypeId(InfrastructureManagement::MountingPointType::Unknown); seData.orientation(Core::Orientation(0, 0, 0)); seData.properties("{\"description\":\"Info-Building-56-Floor-02-Room-02\"}"); addElementToRequest(data, seData, 2); // Mounting Point 01-01-01 seData.name("Mounting Point 56-01-01-01"); seData.displayName("MP 1"); seData.structureElementTypeId(InfrastructureManagement::StructureElementType::MountingPoint); // type mounting point seData.barcode("123xxxx"); seData.relPosition().offsetX(70000); seData.relPosition().offsetY(90000); seData.relPosition().offsetZ(10); seData.mountingPointTypeId(InfrastructureManagement::MountingPointType::IndoorCamera); seData.orientation(Core::Orientation(0, 0, 0)); seData.properties("{\"description\":\"Info-Building-56-Floor-01-Room-01-MP-01\"}"); addElementToRequest(data, seData, 3); // Mounting Point 01-01-02 seData.name("Mounting Point 56-01-01-02"); seData.displayName("MP 2"); seData.structureElementTypeId(InfrastructureManagement::StructureElementType::MountingPoint); // type mounting point seData.barcode("123xxxx"); seData.relPosition().offsetX(70000); seData.relPosition().offsetY(90000); seData.relPosition().offsetZ(10); seData.mountingPointTypeId(InfrastructureManagement::MountingPointType::IndoorCamera); seData.orientation(Core::Orientation(0, 0, 0)); seData.properties("{\"description\":\"Info-Building-56-Floor-01-Room-01-MP-02\"}"); addElementToRequest(data, seData, 3); // Mounting Point 01-02-01 seData.name("Mounting Point 56-01-02-01"); seData.displayName("MP 3"); seData.structureElementTypeId(InfrastructureManagement::StructureElementType::MountingPoint); // type mounting point seData.barcode("123xxxx"); seData.relPosition().offsetX(70000); seData.relPosition().offsetY(90000); seData.relPosition().offsetZ(10); seData.mountingPointTypeId(InfrastructureManagement::MountingPointType::IndoorCamera); seData.orientation(Core::Orientation(0, 0, 0)); seData.properties("{\"description\":\"Info-Building-56-Floor-01-Room-02-MP-01\"}"); addElementToRequest(data, seData, 4); // Mounting Point 01-02-02 seData.name("Mounting Point 56-01-02-02"); seData.displayName("MP 4"); seData.structureElementTypeId(InfrastructureManagement::StructureElementType::MountingPoint); // type mounting point seData.barcode("123xxxx"); seData.relPosition().offsetX(70000); seData.relPosition().offsetY(90000); seData.relPosition().offsetZ(10); seData.mountingPointTypeId(InfrastructureManagement::MountingPointType::IndoorCamera); seData.orientation(Core::Orientation(0, 0, 0)); seData.properties("{\"description\":\"Info-Building-56-Floor-01-Room-02-MP-02\"}"); addElementToRequest(data, seData, 4); // mounting point building central unit seData.name("Test MP Building"); seData.displayName("MP 5"); seData.structureElementTypeId(InfrastructureManagement::StructureElementType::MountingPoint); seData.barcode("4711"); seData.relPosition().offsetX(0); seData.relPosition().offsetY(0); seData.relPosition().offsetZ(0); seData.mountingPointTypeId(InfrastructureManagement::MountingPointType::BuildingControlUnit); seData.properties("{\"description\":\"Info MP Test Building\"}"); addElementToRequest(data, seData, 0); //Footprint InfrastructureManagement::FootprintElement feData; std::vector elements; elements.resize(4); // index 1 feData.id(1); feData.relPosition().offsetX(0); feData.relPosition().offsetY(0); feData.relPosition().offsetZ(0); elements[0] = feData; // index 2 feData.id(2); feData.relPosition().offsetX(9.11999988555908); feData.relPosition().offsetY(0); feData.relPosition().offsetZ(0); elements[1] = feData; // index 3 feData.id(3); feData.relPosition().offsetX(9.11999988555908); feData.relPosition().offsetY(9.02999973297119); feData.relPosition().offsetZ(0); elements[2] = feData; // index 4 feData.id(4); feData.relPosition().offsetX(0); feData.relPosition().offsetY(9.02999973297119); feData.relPosition().offsetZ(0); elements[3] = feData; data.footprint(elements); QByteArray vmTest; vmTest += "bla-bla-bla"; // data.vulnerabilityData(LtsUtils::convert>(vmTest)); // if (!m_ftc->mainStructureElementModifyRequest(data, this)) // { // ERROR_LOG(m_logger) << "Error requesting create data (building)"; // failExit(); // } QTest::qWait(1000); } // ------------------------------------------------------------------------------ void IsmTests::tryModifyMainStructureElement() { INFO_LOG(m_logger) << "trying to send MainStructureElementModifyRequest "; m_dtc->waitForHistoricalDataMainStructureElement(); InfrastructureManagement::MainStructureElement mse = m_dtc->mainStructureElement(m_mainStructureElementId); InfrastructureManagement::MainStructureElementModifyRequest data; if (mse.id() == 0) { ERROR_LOG(m_logger) << "Error requesting modify data"; failExit(); } DEBUG_LOG(m_logger) << "Modify MainStructureElement with id = " << mse.id(); // creating ModifyRequest data.id(mse.id()); data.name(mse.name()); data.description(mse.description()); data.angle(mse.angle()); data.modelId(mse.modelId()); data.externalWlsId(mse.externalWlsId()); data.geoPosition(mse.geoPosition()); data.elements(mse.elements()); data.properties(mse.properties()); data.structureElementTypeId(mse.structureElementTypeId()); // changing MSE name data.name("TestBuilding-Updated"); m_replyFinished = false; if (!m_ftc->mainStructureElementModifyRequest(data, this)) { ERROR_LOG(m_logger) << "Error requesting modify data"; failExit(); } QTRY_COMPARE(m_replyFinished, true); // updating SE barcodes InfrastructureManagement::StructureElement se; InfrastructureManagement::StructureElementModifyRequest seData; seData.mainStructureElementId(mse.id()); seData.elements().reserve(mse.elements().size()); for (size_t i = 0; i < mse.elements().size(); ++i) { se = mse.elements().at(i); DEBUG_LOG(m_logger) << "Updating barcode for element (" << i << ") with old barcode = " << se.barcode(); se.barcode("BARCODE"); seData.elements().push_back(se); } if (!m_ftc->structureElementModifyRequest(seData, this)) { ERROR_LOG(m_logger) << "Error requesting modify data"; failExit(); } QTest::qWait(1000); } // ------------------------------------------------------------------------------ void IsmTests::tryRemoveMainStructureElement() { INFO_LOG(m_logger) << "trying to send MainStructureElementRemoveRequest for mse id = " << m_mainStructureElementId; m_dtc->waitForHistoricalDataMainStructureElement(); InfrastructureManagement::MainStructureElement mse = m_dtc->mainStructureElement(m_mainStructureElementId); if (mse.id() == 0) { ERROR_LOG(m_logger) << "Cannot find main structure element with id = " << m_mainStructureElementId; failExit(); } if (!m_ftc->mainStructureElementRemoveRequest(MainStructureElementRemoveRequest(m_mainStructureElementId), this)) { ERROR_LOG(m_logger) << "Error requesting delete data"; failExit(); } QTest::qWait(1000); } // ------------------------------------------------------------------------------ void IsmTests::tryCreateBridge() { INFO_LOG(m_logger) << "trying to send MainStructureElementCreateRequest"; MainStructureElementModifyRequest data; data.name("Test Bridge"); QJsonObject jsonObj; jsonObj[QStringLiteral("bridgeStatus")] = 0; // '{"bridgeStatus":0}' QJsonDocument doc(jsonObj); data.properties(doc.toJson().toStdString()); data.angle(30.5); data.modelId(0); data.externalWlsId(0); data.geoPosition().lon(0.1552736550); data.geoPosition().lat(0.9259746511); data.geoPosition().z(0.00); data.description("{}"); data.structureElementTypeId(InfrastructureManagement::StructureElementType::Bridge); StructureElement seData; seData.name("Test Bridge"); seData.displayName("Bridge 001"); seData.structureElementTypeId(InfrastructureManagement::StructureElementType::Bridge); seData.relPosition().offsetX(0); seData.relPosition().offsetY(0); seData.relPosition().offsetZ(0); seData.mountingPointTypeId(InfrastructureManagement::MountingPointType::Unknown); seData.properties("{\"description\":\"Info Test Bridge\"}"); addElementToRequest(data, seData, -1); // root element has no parent if (!m_ftc->mainStructureElementModifyRequest(data, this)) { ERROR_LOG(m_logger) << "Error requesting create data (bridge)"; failExit(); } QTest::qWait(1000); } // ------------------------------------------------------------------------------ void IsmTests::tryChangeBridgeStatus() { INFO_LOG(m_logger) << "trying to send MainStructureElementModifyBridgeStatusRequest "; m_dtc->waitForHistoricalDataMainStructureElement(); InfrastructureManagement::MainStructureElement mse = m_dtc->mainStructureElement(m_mainStructureElementId); InfrastructureManagement::MainStructureElementModifyBridgeStatusRequest data; if (mse.id() == 0) { ERROR_LOG(m_logger) << "Error requesting modify data"; failExit(); } DEBUG_LOG(m_logger) << "Modify MainStructureElement with id = " << mse.id(); // creating ModifyRequest data.id(mse.id()); if (m_dtc->getBridgeStatus(m_mainStructureElementId) == BridgeStatus::Intact) data.status(BridgeStatus::Broken); else data.status(BridgeStatus::Intact); m_replyFinished = false; if (!m_ftc->mainStructureElementModifyBridgeStatusRequest(data, this)) { ERROR_LOG(m_logger) << "Error requesting modify bridge status"; failExit(); } QTRY_COMPARE(m_replyFinished, true); QTest::qWait(1000); } // ************* ASSET ********************************************************** // ------------------------------------------------------------------------------ void IsmTests::tryCreateAsset() { INFO_LOG(m_logger) << "trying to send AssetCreateRequest"; InstrumentationAssetModifyRequest data; data.name("Camera-01"); data.mountingPointTypeId(InfrastructureManagement::MountingPointType::IndoorCamera); data.barcode("1"); data.properties("{\"description\":\"Info-Camera-01\"}"); if (!m_ftc->instrumentationAssetModifyRequest(data, this)) { ERROR_LOG(m_logger) << "Error requesting create data"; failExit(); } QTest::qWait(1000); data.name("Camera-02"); data.barcode("2"); data.mountingPointTypeId(InfrastructureManagement::MountingPointType::IndoorCamera); data.properties("{\"description\":\"Info-Camera-02\"}"); if (!m_ftc->instrumentationAssetModifyRequest(data, this)) { ERROR_LOG(m_logger) << "Error requesting create data"; failExit(); } QTest::qWait(1000); data.name("Camera-03"); data.barcode("3"); data.mountingPointTypeId(InfrastructureManagement::MountingPointType::MeteoDataUnit); data.properties("{\"description\":\"Info-Camera-03\"}"); if (!m_ftc->instrumentationAssetModifyRequest(data, this)) { ERROR_LOG(m_logger) << "Error requesting create data"; failExit(); } QTest::qWait(1000); data.name("Camera-04"); data.barcode("4"); data.mountingPointTypeId(InfrastructureManagement::MountingPointType::MeteoDataUnit); data.properties("{\"description\":\"Info-Camera-03\"}"); if (!m_ftc->instrumentationAssetModifyRequest(data, this)) { ERROR_LOG(m_logger) << "Error requesting create data"; failExit(); } QTest::qWait(1000); } // ------------------------------------------------------------------------------ void IsmTests::tryModifyAsset() { INFO_LOG(m_logger) << "trying to send asset modify request "; DEBUG_LOG(m_logger) << "m_assetId = " << m_assetId; m_dtc->waitForHistoricalDataInstrumentationAsset(); const InfrastructureManagement::InstrumentationAsset &ast = m_dtc->instrumentationAsset(m_assetId); // const InfrastructureManagement::InstrumentationAsset &ast1 = m_dtc->instrumentationAssets()[m_assetId]; InfrastructureManagement::InstrumentationAssetModifyRequest data; DEBUG_LOG(m_logger) << "ast.id() = " << ast.id(); // DEBUG_LOG(m_logger) << "ast1.id() = " << ast1.id(); if (ast.id() == 0) { ERROR_LOG(m_logger) << "Cannot find Asset Id = " << m_assetId; failExit(); } else { data.id(ast.id()); data.name(ast.name()); data.barcode(ast.barcode()); data.mountingPointTypeId(ast.mountingPointTypeId()); data.instrumentationAssetStateId(ast.assetStateId()); data.properties(ast.properties()); // changing only name data.name("Asset-Updated"); if (!m_ftc->instrumentationAssetModifyRequest(InstrumentationAssetModifyRequest(data), this)) { ERROR_LOG(m_logger) << "Error requesting modify data"; failExit(); } QTest::qWait(1000); } } // ------------------------------------------------------------------------------ void IsmTests::tryRemoveAsset() { INFO_LOG(m_logger) << "trying to send AssetRemoveRequest for id = " << m_assetId; m_dtc->waitForHistoricalDataInstrumentationAsset(); const InfrastructureManagement::InstrumentationAsset &ast = m_dtc->instrumentationAsset(m_assetId); if (ast.id() == 0) { ERROR_LOG(m_logger) << "Cannot find Asset Id = " << m_assetId; failExit(); } if (!m_ftc->instrumentationAssetRemoveRequest(InstrumentationAssetRemoveRequest(m_assetId), this)) { ERROR_LOG(m_logger) << "Error requesting delete data"; failExit(); } QTest::qWait(1000); } // ------------------------------------------------------------------------------ void IsmTests::tryUnmountAsset() { INFO_LOG(m_logger) << "trying to send asset state modify request "; DEBUG_LOG(m_logger) << "m_assetId = " << m_assetId; m_dtc->waitForHistoricalDataInstrumentationAsset(); const InfrastructureManagement::InstrumentationAsset &ast = m_dtc->instrumentationAsset(m_assetId); // const InfrastructureManagement::InstrumentationAsset &ast1 = m_dtc->instrumentationAssets()[m_assetId]; InfrastructureManagement::InstrumentationAssetSetStateRequest data; DEBUG_LOG(m_logger) << "ast.id() = " << ast.id(); // DEBUG_LOG(m_logger) << "ast1.id() = " << ast1.id(); if (ast.id() == 0) { ERROR_LOG(m_logger) << "Cannot find Asset Id = " << m_assetId; failExit(); } else { data.id(ast.id()); data.instrumentationAssetStateId(InstrumentationAssetState::Unmounted); if (!m_ftc->instrumentationAssetSetStateRequest(InstrumentationAssetSetStateRequest(data), this)) { ERROR_LOG(m_logger) << "Error requesting set asset state"; failExit(); } QTest::qWait(1000); } } // ************* MOUNTING POINT ASSETS ******************************************* // ------------------------------------------------------------------------------ void IsmTests::tryCreateMountingPointAsset() { INFO_LOG(m_logger) << "trying to send AssetCreateRequest"; MountingPointAssetModifyRequest data; data.assetId(m_assetId); data.structureElementId(m_structureElementId); data.lastUpdated(QDateTime::currentMSecsSinceEpoch()); if (!m_ftc->mountingPointAssetModifyRequest(data, this)) { ERROR_LOG(m_logger) << "Error requesting create data"; failExit(); } QTest::qWait(1000); } // ------------------------------------------------------------------------------ void IsmTests::tryRemoveMountingPointAsset() { INFO_LOG(m_logger) << "trying to send MountingPointAssetRemoveRequest "; m_dtc->waitForHistoricalDataMountingPointAsset(); if (!m_dtc->getMountingPointAssetId(m_structureElementId, m_assetId, m_mountingPointAssetId)) { ERROR_LOG(m_logger) << "Cannot find requested mounting point asset"; failExit(); } DEBUG_LOG(m_logger) << "MountingPointAsset Id = " << m_mountingPointAssetId; if (!m_ftc->mountingPointAssetRemoveRequest(MountingPointAssetRemoveRequest(m_mountingPointAssetId), this)) { ERROR_LOG(m_logger) << "Error requesting delete data"; failExit(); } QTest::qWait(1000); } // ************* MOUNTING POINT SCHEDULE ********************************************************** // ------------------------------------------------------------------------------ void IsmTests::tryCreateMainSchedule() { INFO_LOG(m_logger) << "trying to send MainScheduleCreateRequest"; MainScheduleModifyRequest data0, data1, data2; data1.id(0); // to be inserted data1.name("Instrumentation Plan 1 (ex 42)"); data1.exerciseId(42); data1.statusId(InfrastructureManagement::ScheduleStatus::Inactive); data1.timeCreated(10000000); data1.timeStart(12000000); data1.timeEnd( 13000000); data1.description("Info-Main-Schedule-01"); if (!m_ftc->mainScheduleModifyRequest(data1, this)) { ERROR_LOG(m_logger) << "Error requesting create data"; failExit(); } QTest::qWait(1000); data2.id(0); // to be inserted data2.name("Instrumentation Plan 2 (ex 42)"); data2.exerciseId(42); data2.statusId(InfrastructureManagement::ScheduleStatus::Inactive); data2.timeCreated(14000000); data2.timeStart(16000000); data2.timeEnd( 17000000); data2.description("Info-Main-Schedule-02"); if (!m_ftc->mainScheduleModifyRequest(data2, this)) { ERROR_LOG(m_logger) << "Error requesting create data"; failExit(); } QTest::qWait(1000); data0.id(0); // to be inserted data0.name("No exercise"); data0.statusId(InfrastructureManagement::ScheduleStatus::Active); data0.timeCreated(14000000); data0.timeStart(15000000); data0.timeEnd( 19000000); data0.description("Info-Main-Schedule-03"); if (!m_ftc->mainScheduleModifyRequest(data0, this)) { ERROR_LOG(m_logger) << "Error requesting create data"; failExit(); } QTest::qWait(1000); } // ------------------------------------------------------------------------------ void IsmTests::tryModifyMainSchedule() { INFO_LOG(m_logger) << "trying to send mounting point schedule modify request "; m_dtc->waitForHistoricalDataMainSchedule(); // using m_assetId as main schedule id InfrastructureManagement::MainSchedule ast = m_dtc->mainSchedule(m_assetId); InfrastructureManagement::MainScheduleModifyRequest data; DEBUG_LOG(m_logger) << "m_assetId = " << m_assetId; DEBUG_LOG(m_logger) << "ast.id() = " << ast.id(); // creating ModifyRequest if (ast.id() > 0) { data.id(ast.id()); data.name(ast.name()); data.statusId(ast.statusId()); data.exerciseId(ast.exerciseId()); data.timeCreated(ast.timeCreated()); data.timeStart(ast.timeStart()); data.timeEnd(ast.timeEnd()); data.description(ast.description()); // changing name data.name("MPS-Updated"); if (!m_ftc->mainScheduleModifyRequest(MainScheduleModifyRequest(data), this)) { ERROR_LOG(m_logger) << "Error requesting modify data"; failExit(); } } else { ERROR_LOG(m_logger) << "Cannot find main schedule id = " << m_assetId; failExit(); } QTest::qWait(1000); } // ------------------------------------------------------------------------------ void IsmTests::tryChangeStatusSchedule() { INFO_LOG(m_logger) << "trying to send mounting point schedule modify request "; m_dtc->waitForHistoricalDataMainSchedule(); // using m_assetId as main schedule id InfrastructureManagement::MainSchedule ast = m_dtc->mainSchedule(m_assetId); InfrastructureManagement::MainScheduleModifyRequest data; DEBUG_LOG(m_logger) << "m_assetId = " << m_assetId; DEBUG_LOG(m_logger) << "ast.id() = " << ast.id(); // creating ModifyRequest if (ast.id() > 0) { data.id(ast.id()); data.name(ast.name()); data.statusId(ast.statusId()); data.exerciseId(ast.exerciseId()); data.timeCreated(ast.timeCreated()); data.timeStart(ast.timeStart()); data.timeEnd(ast.timeEnd()); data.description(ast.description()); // changing name and status switch (data.statusId().underlying()) { case InfrastructureManagement::ScheduleStatus::Inactive: { data.name("MPS-UpdatedStatus-Activated"); data.statusId(InfrastructureManagement::ScheduleStatus::Active); data.timeStart(QDateTime::currentMSecsSinceEpoch()); break; } case InfrastructureManagement::ScheduleStatus::Active: { data.name("MPS-UpdatedStatus-Inactivated"); data.statusId(InfrastructureManagement::ScheduleStatus::Inactive); data.timeEnd(QDateTime::currentMSecsSinceEpoch()); break; } default: break; } if (!m_ftc->mainScheduleModifyRequest(MainScheduleModifyRequest(data), this)) { ERROR_LOG(m_logger) << "Error requesting modify data"; failExit(); } } else { ERROR_LOG(m_logger) << "Cannot find main schedule id = " << m_assetId; failExit(); } QTest::qWait(1000); } // ------------------------------------------------------------------------------ void IsmTests::tryRemoveMainSchedule() { INFO_LOG(m_logger) << "trying to send MainScheduleRemoveRequest for id = " << m_assetId; m_dtc->waitForHistoricalDataMainSchedule(); InfrastructureManagement::MainSchedule ast = m_dtc->mainSchedule(m_assetId); if (ast.id() == 0) { ERROR_LOG(m_logger) << "Cannot find main schedule id = " << m_assetId; failExit(); } if (!m_ftc->mainScheduleRemoveRequest(MainScheduleRemoveRequest(m_assetId), this)) { ERROR_LOG(m_logger) << "Error requesting delete data"; failExit(); } QTest::qWait(1000); } // ------------------------------------------------------------------------------ void IsmTests::tryCopySchedule() { INFO_LOG(m_logger) << "trying to copy schedule"; m_dtc->waitForHistoricalDataMainSchedule(); // using m_assetId as main schedule id InfrastructureManagement::MainSchedule ms = m_dtc->mainSchedule(m_assetId); DEBUG_LOG(m_logger) << "scheduleId = " << m_assetId; DEBUG_LOG(m_logger) << "ms.id() = " << ms.id(); int newId = m_db->copySchedule(ms.id()); if (newId <= 0) { ERROR_LOG(m_logger) << "Error copy schedule, code = " << newId; failExit(); } QTest::qWait(1000); } // ------------------------------------------------------------------------------ void IsmTests::checkSchedule() { ERROR_LOG(m_logger) << "check instrumentation plan"; m_dtc->waitForHistoricalDataMainSchedule(); // using m_assetId as main schedule id InfrastructureManagement::MainSchedule ms = m_dtc->mainSchedule(m_assetId); DEBUG_LOG(m_logger) << "scheduleId = " << m_assetId; DEBUG_LOG(m_logger) << "ms.id() = " << ms.id(); QList diff; bool ok = m_dtc->getScheduleDifferences(m_assetId, diff); if (ok) ERROR_LOG(m_logger) << "Instrumentation plan complete!"; else { ERROR_LOG(m_logger) << "Instrumentation plan not complete !!!"; for (const MountingPointPlan &mpp : qAsConst(diff)) ERROR_LOG(m_logger) << "Diff - # mpp.structureElementId() = " << mpp.structureElementId(); } QTest::qWait(1000); } // ************* MOUNTING POINT PLAN ********************************************************** // ------------------------------------------------------------------------------ void IsmTests::tryCreateMountingPointPlan() { INFO_LOG(m_logger) << "trying to send MountingPointPlanCreateRequest"; MountingPointPlanModifyRequest data; data.mountingPointScheduleId(m_assetId); // data.structureElementId(m_structureElementId); // data.mountingPointState(InfrastructureManagement::MountingPointState::Equipped); if (!m_ftc->mountingPointPlanModifyRequest(data, this)) { ERROR_LOG(m_logger) << "Error requesting create data"; failExit(); } QTest::qWait(1000); data.mountingPointScheduleId(m_assetId); // data.structureElementId(m_mainStructureElementId); // data.mountingPointState(InfrastructureManagement::MountingPointState::Idle); if (!m_ftc->mountingPointPlanModifyRequest(data, this)) { ERROR_LOG(m_logger) << "Error requesting create data"; failExit(); } QTest::qWait(1000); } //********************* GENERAL ************************************************* // ------------------------------------------------------------------------------ void IsmTests::onError(const QString &reason) { ERROR_LOG(m_logger) << "Got Reply error: " << reason; failExit(); } // ------------------------------------------------------------------------------ void IsmTests::onCreateReply(const Core::FunctionReplyObject &replyObject) { if (replyObject.error()) { onError(replyObject.translated()); return; } INFO_LOG(m_logger) << "Got createReply with id " << replyObject.id() << " and errorString " << replyObject.translated(); QTimer::singleShot(0, qApp, &QCoreApplication::quit); } // ------------------------------------------------------------------------------ void IsmTests::onModifyReply(const Core::FunctionReplyObject &replyObject) { m_replyFinished = true; if (replyObject.error()) { onError(replyObject.translated()); return; } INFO_LOG(m_logger) << "Got modifyRequest with id " << replyObject.id() << " and errorString " << replyObject.translated(); QTimer::singleShot(0, qApp, &QCoreApplication::quit); } // ------------------------------------------------------------------------------ void IsmTests::onRemoveReply(const Core::FunctionReplyObject &replyObject) { if (replyObject.error()) { onError(replyObject.translated()); return; } INFO_LOG(m_logger) << "Got removeReply with id " << replyObject.id() << " and errorString " << replyObject.translated(); QTimer::singleShot(0, qApp, &QCoreApplication::quit); } // ------------------------------------------------------------------------------ void IsmTests::failExit() { ERROR_LOG(m_logger) << "FAIL EXIT !"; m_bTestsSuccessful = false; QTimer::singleShot(0, qApp, &QCoreApplication::quit); } // ------------------------------------------------------------------ class CmdLineParser : public LtsCommandLineParser::LtsCommandLineParser { public: CmdLineParser() : LtsCommandLineParser() { addOption( { QStringList() << QLatin1String("t") << QLatin1String("testId") , QLatin1String("TestId.") , QLatin1String("Default: 0") , QLatin1String("0") } ); addOption( { QStringList() << QLatin1String("a") << QLatin1String("assetId") , QLatin1String("AssetId.MainScheduleId.") , QLatin1String("Default: 0") , QLatin1String("0") } ); addOption( { QStringList() << QLatin1String("m") << QLatin1String("mainStructureElementId") , QLatin1String("MainStructureElementId.") , QLatin1String("Default: 0") , QLatin1String("0") } ); addOption( { QStringList() << QLatin1String("s") << QLatin1String("structureElementId") , QLatin1String("StructureElementId.") , QLatin1String("Default: 0") , QLatin1String("0") } ); addOption( { QStringList() << QLatin1String("i") << QLatin1String("indexNo") , QLatin1String("IndexNo.") , QLatin1String("Default: 0") , QLatin1String("0") } ); } int testId() const { return isSet(QLatin1String("t")) ? value(QLatin1String("t")).toInt() : -1; } int assetId() const { return isSet(QLatin1String("a")) ? value(QLatin1String("a")).toInt() : -1; } int mainStructureElementId() const { return isSet(QLatin1String("m")) ? value(QLatin1String("m")).toInt() : -1; } int structureElementId() const { return isSet(QLatin1String("s")) ? value(QLatin1String("s")).toInt() : -1; } int indexNo() const { return isSet(QLatin1String("i")) ? value(QLatin1String("i")).toInt() : -1; } }; // ------------------------------------------------------------------ int main(int argc, char **argv) { int iRet = -1; NGLCoreApplication app(argc, argv); app.createLogger("ISM", 0 ); CmdLineParser options; if (!options.init()) return iRet; std::unique_ptr IsmTests(new InfrastructureManagement::IsmTests); if(!IsmTests->init(options.domainId(), options.testId(), options.assetId(), options.mainStructureElementId(), options.structureElementId(), options.indexNo())) return iRet; QTimer::singleShot(0, IsmTests.get(), &InfrastructureManagement::IsmTests::startTest); STARTUP_LOG(app.baseLogger()); app.exec(); iRet = IsmTests->testsSuccessful() ? 0 : 1; fprintf(stderr, "\n%d\n\n", iRet); INFO_LOG(app.baseLogger()) << "** TEST result = " << iRet; SHUTDOWN_LOG(app.baseLogger()); return iRet; }