From 03af50060bfa7fa7b4a2dc4e2e7b2c050ce1cd2f Mon Sep 17 00:00:00 2001 From: lgrd Date: Wed, 11 Jan 2023 14:27:03 +0100 Subject: [PATCH] Update of integration tests (#13) * [test] apisManager ok * [test] baseManager ok * [test] line ok * [test] resourceParameter ok * [test] serviceAdministered ok * [test] *Request ok * [test] serverManager ok * [test] serviceProcess en cours * [test] resourceOperation ok * [test] *parameter ok * [test] apisManager ok * [test] baseManager ok * [test] line ok * [test] resourceParameter ok * [test] serviceAdministered ok * [test] *Request ok * [test] serverManager ok * [test] serviceProcess en cours * [test] resourceOperation ok * [test] *parameter ok * [sub] update r2gg commit * fix(test) update json for pgr and valhalla source description * [doc] fix test/functional/readme.md Co-authored-by: jmkerloch <53606373+jmkerloch@users.noreply.github.com> Co-authored-by: jmkerloch Co-authored-by: jmkerloch <53606373+jmkerloch@users.noreply.github.com> --- docker/route-graph-generator | 2 +- src/js/apis/apisManager.js | 158 +----------------- src/js/base/baseManager.js | 22 --- src/js/geometry/line.js | 2 +- src/js/parameters/boolParameter.js | 2 +- src/js/parameters/constraintParameter.js | 2 +- src/js/parameters/enumParameter.js | 2 +- src/js/parameters/floatParameter.js | 2 +- src/js/parameters/intParameter.js | 2 +- src/js/parameters/pointParameter.js | 2 +- src/js/parameters/resourceParameter.js | 22 +-- src/js/requests/isochroneRequest.js | 26 +-- src/js/requests/nearestRequest.js | 10 +- src/js/requests/request.js | 17 +- src/js/requests/routeRequest.js | 13 +- src/js/server/serverManager.js | 11 +- src/js/service/serviceAdministered.js | 4 +- src/js/service/serviceProcess.js | 27 +-- test/functional/readme.md | 22 +-- .../mocha/apis/integrationApiManager.js | 55 +++--- .../mocha/base/integrationBaseManager.js | 42 +++-- test/integration/mocha/config/log4js.json | 4 +- test/integration/mocha/config/road2.json | 27 +++ .../mocha/config/service.json} | 40 +++-- .../mocha/geometry/integrationLine.js | 4 +- .../mocha/operations/integrationOperation.js | 2 +- .../integrationResourceOperation.js | 33 ++-- .../parameters/integrationBoolParameter.js | 82 +++++++++ .../integrationConstraintParameter.js | 76 +++++++++ .../parameters/integrationEnumParameter.js | 82 +++++++++ .../parameters/integrationFloatParameter.js | 110 ++++++++++++ .../parameters/integrationIntParameter.js | 110 ++++++++++++ .../parameters/integrationPointParameter.js | 92 ++++++++++ .../integrationResourceParameter.js | 57 +++++-- .../requests/integrationIsochroneRequest.js | 29 ++-- .../requests/integrationNearestRequest.js | 70 ++++++++ .../mocha/requests/integrationRouteRequest.js | 71 +++++++- .../resources/integrationOsrmResource.js | 2 +- .../resources/integrationResourceManager.js | 5 +- .../resources/integrationValhallaResource.js | 2 +- .../mocha/responses/integrationPortion.js | 2 +- .../mocha/server/integrationServerManager.js | 87 ++++++++++ .../mocha/service/integrationService.js | 4 +- .../service/integrationServiceProcess.js | 44 +++++ .../mocha/sources/integrationPgrSource.js | 20 ++- .../mocha/sources/integrationSourceManager.js | 2 +- .../sources/integrationValhallaSource.js | 3 +- .../topology/integrationTopologyManager.js | 87 ---------- test/integration/readme.md | 22 ++- .../resources/topology/correctDBTopology.json | 25 --- .../topology/correctOSMTopology.json | 10 -- .../topology/incorrectDBTopology.json | 24 --- .../topology/incorrectOSMTopology.json | 9 - .../mocha/config/resources/corse.resource | 130 -------------- test/unit/mocha/requests/testsRequest.js | 5 +- .../mocha/service/testsServiceAdministered.js | 26 +++ test/unit/readme.md | 5 +- 57 files changed, 1170 insertions(+), 678 deletions(-) create mode 100644 test/integration/mocha/config/road2.json rename test/{unit/mocha/config/road2.json => integration/mocha/config/service.json} (50%) create mode 100644 test/integration/mocha/parameters/integrationBoolParameter.js create mode 100644 test/integration/mocha/parameters/integrationConstraintParameter.js create mode 100644 test/integration/mocha/parameters/integrationEnumParameter.js create mode 100644 test/integration/mocha/parameters/integrationFloatParameter.js create mode 100644 test/integration/mocha/parameters/integrationIntParameter.js create mode 100644 test/integration/mocha/parameters/integrationPointParameter.js create mode 100644 test/integration/mocha/requests/integrationNearestRequest.js create mode 100644 test/integration/mocha/server/integrationServerManager.js create mode 100644 test/integration/mocha/service/integrationServiceProcess.js delete mode 100644 test/integration/mocha/topology/integrationTopologyManager.js delete mode 100644 test/integration/resources/topology/correctDBTopology.json delete mode 100644 test/integration/resources/topology/correctOSMTopology.json delete mode 100644 test/integration/resources/topology/incorrectDBTopology.json delete mode 100644 test/integration/resources/topology/incorrectOSMTopology.json delete mode 100644 test/unit/mocha/config/resources/corse.resource create mode 100644 test/unit/mocha/service/testsServiceAdministered.js diff --git a/docker/route-graph-generator b/docker/route-graph-generator index c9b526a1..d1974112 160000 --- a/docker/route-graph-generator +++ b/docker/route-graph-generator @@ -1 +1 @@ -Subproject commit c9b526a1cb4d3972ecbdafac292c8e0c4cc0b242 +Subproject commit d19741120b915d1cf034e099fe5ccad1cbb63e0c diff --git a/src/js/apis/apisManager.js b/src/js/apis/apisManager.js index 5cbf799e..dee9b318 100644 --- a/src/js/apis/apisManager.js +++ b/src/js/apis/apisManager.js @@ -14,16 +14,14 @@ module.exports = class apisManager { * * @function * @name constructor - * @description Constructeur de la classe resourceManager + * @description Constructeur de la classe apisManager + * @param {string} apisDirectory - Dossier qui contient les APIs. Par défaut, il s'agit du dossier de ce projet contenant des APIs * */ - constructor() { + constructor(apisDirectory = "../apis/") { // Dossier contenant les APIs du projet - this._apisDirectory = "../apis/"; - - // Prefix utilisé pour chaque route des APIS - this._prefix = ""; + this._apisDirectory = apisDirectory; // Liste des routes chargées par l'app Express this._listOfRoutes = new Array(); @@ -33,50 +31,6 @@ module.exports = class apisManager { } - /** - * - * @function - * @name get apisDirectory - * @description Récupérer le chemin du dossier qui contient les APIs - * - */ - get apisDirectory () { - return this._apisDirectory; - } - - /** - * - * @function - * @name get prefix - * @description Récupérer le prefix utilisé par ce manager - * - */ - get prefix () { - return this._prefix; - } - - /** - * - * @function - * @name get listOfRoutes - * @description Récupérer la liste des routes disponibles via ce manager - * - */ - get listOfRoutes () { - return this._listOfRoutes; - } - - /** - * - * @function - * @name get apisCatalog - * @description Récupérer la liste des apis disponibles via ce manager - * - */ - get apisCatalog () { - return this._apisCatalog; - } - /** * * @function @@ -121,6 +75,7 @@ module.exports = class apisManager { availableAPI= fs.statSync(tmpPathName).isDirectory() } catch(error) { LOGGER.error("Mauvaise configuration: 'name' ne peut être évalué."); + LOGGER.error(error); return false; } @@ -180,95 +135,6 @@ module.exports = class apisManager { } - /** - * - * @function - * @name loadApiDirectory - * @description Fonction utilisée pour charger l'ensemble des APIs disponibles dans un dossier. - * @param {express} app - Objet créé par ExpressJS représentant l'application - * - */ - - loadApiDirectory (app) { - - LOGGER.info("Chargement des APIS..."); - - // Soit _apisDirectory est un chemin absolu qui pointe vers un autre repo d'APIs, soit c'est celui du repo officiel de Road2 (usage de __dirname) - let APIsDirectory = path.resolve(__dirname, this._apisDirectory); - - // on lit le contenu du dossier - let APIsDirectoryTable = new Array(); - - try { - APIsDirectoryTable = fs.readdirSync(APIsDirectory); - } catch (error) { - LOGGER.error("Le dossier n'est pas lisible: " + APIsDirectory); - LOGGER.error(error); - return false; - } - - // S'il est vide ce n'est pas normal - if (APIsDirectoryTable.length === 0) { - LOGGER.error("Le dossier des apis est vide."); - return false; - } - - // Pour chaque sous-dossier on a potentiellement une api - for (let i = 0; i < APIsDirectoryTable.length; i++) { - - let apiName = APIsDirectoryTable[i]; - - let APIDirectory = APIsDirectory + "/" + apiName; - - if (fs.statSync(APIDirectory).isDirectory()) { - // c'est un dossier qui contient potentiellement une API - - LOGGER.info("Nouvelle API: " + apiName); - - let APIDirectoryTable = fs.readdirSync(APIDirectory); - - if (APIDirectoryTable.length === 0) { - LOGGER.error("Le dossier de l'api est vide."); - return false; - } - - for (let j = 0; j < APIDirectoryTable.length; j++) { - - let apiVersion = APIDirectoryTable[j]; - - let APIDirectoryVersion = APIDirectory + "/" + apiVersion; - - if (fs.statSync(APIDirectoryVersion).isDirectory()) { - // c'est un dossier qui contient potentiellement une version de l'API - - LOGGER.info("Nouvelle version: " + apiVersion); - - let configuration = { - name: apiName, - version: apiVersion - }; - - if (!this.loadApiConfiguration(app, configuration)) { - LOGGER.error("Impossible de charger l'API " + apiName + "/" + apiVersion); - } - - } else { - // Si ce n'est pas un dossier, on ne fait rien - } - - } - - } else { - // Si ce n'est pas un dossier, on ne fait rien - } - - } - - LOGGER.info("APIS chargees."); - return true; - - } - /** * * @function @@ -293,16 +159,10 @@ module.exports = class apisManager { // Gestion du router // ------------------ - let route; - - if (this._prefix !== "") { - route = "/" + this._prefix + "/" + apiName + "/" + apiVersion; - } else { - route = "/"+ apiName + "/" + apiVersion; - } + let route = "/"+ apiName + "/" + apiVersion; // On vérifie que la route n'existe pas déjà - if (this.verifyRouteExistanceById(route)) { + if (this._verifyRouteExistanceById(route)) { // Si elle existe c'est un vrai problème donc on arrête le chargement LOGGER.error("La route " + route + " existe deja. L'api n'est donc pas chargee."); return false; @@ -361,14 +221,14 @@ module.exports = class apisManager { /** * * @function - * @name verifyRouteExistanceById + * @name _verifyRouteExistanceById * @description Fonction utilisée pour vérifier que la route n'est pas déjà chargée * @param {string} route - Route à tester * @return {boolean} true si la route est déjà présente et false sinon * */ - verifyRouteExistanceById (route) { + _verifyRouteExistanceById (route) { for (let i = 0; i < this._listOfRoutes.length; i++) { if (this._listOfRoutes[i] === route) { diff --git a/src/js/base/baseManager.js b/src/js/base/baseManager.js index 0866f49d..bbe82012 100644 --- a/src/js/base/baseManager.js +++ b/src/js/base/baseManager.js @@ -37,28 +37,6 @@ module.exports = class baseManager { } - /** - * - * @function - * @name get loadedBaseConfiguration - * @description Récupérer la liste des configurations déjà chargées par ce manager - * - */ - get loadedBaseConfiguration() { - return this._loadedBaseConfiguration; - } - - /** - * - * @function - * @name get baseCatalog - * @description Récupérer le catalogue des bases - * - */ - get baseCatalog() { - return this._baseCatalog; - } - /** * * @function diff --git a/src/js/geometry/line.js b/src/js/geometry/line.js index 024154bd..8fe498cb 100644 --- a/src/js/geometry/line.js +++ b/src/js/geometry/line.js @@ -33,7 +33,7 @@ module.exports = class Line extends Geometry { super("line", projection); - // Géométrie de la polyline + // Géométrie de la Line this._geom = geom; // Format de géométrie (geojson, polyline...) diff --git a/src/js/parameters/boolParameter.js b/src/js/parameters/boolParameter.js index a1a710bf..d8b5acef 100644 --- a/src/js/parameters/boolParameter.js +++ b/src/js/parameters/boolParameter.js @@ -29,7 +29,7 @@ module.exports = class BoolParameter extends ResourceParameter { */ constructor(parameter) { - // id + // Paramètre de service super(parameter); // defaultValueContent diff --git a/src/js/parameters/constraintParameter.js b/src/js/parameters/constraintParameter.js index f31070c0..dd959a2d 100644 --- a/src/js/parameters/constraintParameter.js +++ b/src/js/parameters/constraintParameter.js @@ -31,7 +31,7 @@ module.exports = class ConstraintParameter extends ResourceParameter { */ constructor(parameter) { - // id + // Paramètre de service super(parameter); // defaultValueContent diff --git a/src/js/parameters/enumParameter.js b/src/js/parameters/enumParameter.js index 2228da3a..756f789e 100644 --- a/src/js/parameters/enumParameter.js +++ b/src/js/parameters/enumParameter.js @@ -29,7 +29,7 @@ module.exports = class EnumParameter extends ResourceParameter { */ constructor(parameter) { - // id + // Paramètre de service super(parameter); // defaultValueContent diff --git a/src/js/parameters/floatParameter.js b/src/js/parameters/floatParameter.js index 26ec6f6d..93dc5ad3 100644 --- a/src/js/parameters/floatParameter.js +++ b/src/js/parameters/floatParameter.js @@ -30,7 +30,7 @@ module.exports = class FloatParameter extends ResourceParameter { */ constructor(parameter) { - // id + // Paramètre de service super(parameter); // defaultValueContent diff --git a/src/js/parameters/intParameter.js b/src/js/parameters/intParameter.js index a9f42835..271038ae 100644 --- a/src/js/parameters/intParameter.js +++ b/src/js/parameters/intParameter.js @@ -29,7 +29,7 @@ module.exports = class IntParameter extends ResourceParameter { */ constructor(parameter) { - // id + // Paramètre de service super(parameter); // defaultValueContent diff --git a/src/js/parameters/pointParameter.js b/src/js/parameters/pointParameter.js index de1f7cd2..57be1fd7 100644 --- a/src/js/parameters/pointParameter.js +++ b/src/js/parameters/pointParameter.js @@ -30,7 +30,7 @@ module.exports = class PointParameter extends ResourceParameter { */ constructor(parameter) { - // id + // Paramètre de service super(parameter); // Bbox diff --git a/src/js/parameters/resourceParameter.js b/src/js/parameters/resourceParameter.js index c961febc..09334e32 100644 --- a/src/js/parameters/resourceParameter.js +++ b/src/js/parameters/resourceParameter.js @@ -23,12 +23,12 @@ module.exports = class ResourceParameter { * @function * @name constructor * @description Constructeur de la classe ResourceParameter - * @param {object} parameter - Référence au paramètre de service + * @param {Parameter} parameter - Référence au paramètre de service, instance de la classe Parameter * */ constructor(parameter) { - // id + // paramètre du service this._serviceParameter = parameter; } @@ -49,7 +49,7 @@ module.exports = class ResourceParameter { * @function * @name load * @description Charger la configuration - * @param {string} parameterConf - Configuration d'un paramètre + * @param {object} parameterConf - Configuration d'un paramètre * @return {boolean} * */ @@ -115,16 +115,12 @@ module.exports = class ResourceParameter { userTable = userValue.split("|"); } else { - //TODO: ce n'est pas censé arriver, que fait-on ? - return errorManager.createErrorMessage(""); + return errorManager.createErrorMessage("style non reconnu"); } } else { - // on peut avoir simplement un float - // TODO: vérification du float ? - LOGGER.debug("user parameter is NOT a string"); - userTable = userValue; + return errorManager.createErrorMessage("user parameter is NOT a string"); } @@ -167,7 +163,9 @@ module.exports = class ResourceParameter { LOGGER.debug("specificCheck()"); LOGGER.debug("user value : " + userValue); - LOGGER.debug("options: " + options.toString()); + if (options) { + LOGGER.debug("options: " + options.toString()); + } return errorManager.createErrorMessage(""); } @@ -230,7 +228,9 @@ module.exports = class ResourceParameter { LOGGER.debug("specificConversion()"); LOGGER.debug("user value : " + userValue); - LOGGER.debug("options: " + options.toString()); + if (options) { + LOGGER.debug("options: " + options.toString()); + } return null; } diff --git a/src/js/requests/isochroneRequest.js b/src/js/requests/isochroneRequest.js index 343ef21b..62e248b6 100644 --- a/src/js/requests/isochroneRequest.js +++ b/src/js/requests/isochroneRequest.js @@ -9,9 +9,11 @@ const Request = require('./request'); * @description Classe modélisant une requête d'isochrone. * Chaque requête reçue par le service doit être transformée en requête de cette forme * pour le proxy +* */ module.exports = class isochroneRequest extends Request { + /** * * @function @@ -29,31 +31,29 @@ module.exports = class isochroneRequest extends Request { * @param {string} distanceUnit - Unité de distance utilisée pour le calcul. * */ - constructor( - resource, - point, - costType, - costValue, - profile, - direction, - askedProjection, - geometryFormat, - timeUnit, - distanceUnit - ) { + + constructor(resource, point, costType, costValue, profile, direction, askedProjection, geometryFormat, timeUnit, distanceUnit) { // Constructeur parent super("isochrone", resource, "isochroneRequest"); - /* Initialisation du reste des paramètres. */ + // Initialisation du reste des paramètres this._point = point; + this._costType = costType; + this._costValue = costValue; + this._profile = profile; + this._direction = direction; + this._askedProjection = askedProjection; + this._geometryFormat = geometryFormat; + this._timeUnit = timeUnit; + this._distanceUnit = distanceUnit; // Gestion des contraintes diff --git a/src/js/requests/nearestRequest.js b/src/js/requests/nearestRequest.js index 63bcc008..b640d838 100644 --- a/src/js/requests/nearestRequest.js +++ b/src/js/requests/nearestRequest.js @@ -24,16 +24,16 @@ module.exports = class nearestRequest extends Request { * @param {integer} number - Type du coût. * */ - constructor( - resource, - coordinates - ) { + + constructor(resource, coordinates) { // Constructeur parent super("nearest", resource, "nearestRequest"); - // Initialisation du reste des paramètres. + // Coordonnées du point fourni this._coordinates = coordinates; + + // Nombre de points attendus en retour this._number = 1; } diff --git a/src/js/requests/request.js b/src/js/requests/request.js index 75f63607..107952f4 100644 --- a/src/js/requests/request.js +++ b/src/js/requests/request.js @@ -30,7 +30,7 @@ module.exports = class Request { // Ressource concernée this._resource = resource; - // Type de la requête + // Type de la requête (ne doit pas être modifié) this._type = type; } @@ -92,19 +92,4 @@ module.exports = class Request { return this._type; } - /** - * - * @function - * @name set type - * @description Attribuer le type de la requête - * @param {string} ty - Type de la requête - * - */ - set type (ty) { - this._type = ty; - } - - - - } diff --git a/src/js/requests/routeRequest.js b/src/js/requests/routeRequest.js index b38372ac..c651ff94 100644 --- a/src/js/requests/routeRequest.js +++ b/src/js/requests/routeRequest.js @@ -56,7 +56,7 @@ module.exports = class routeRequest extends Request { // geometryFormat // type des géométries demandé - this._geometryFormat = "geojson" + this._geometryFormat = "geojson"; // bbox this._bbox = true; @@ -268,6 +268,17 @@ module.exports = class routeRequest extends Request { return this._waysAttributes; } + /** + * + * @function + * @name set waysAttributes + * @description Attribuer la liste des attributs disponibles pour les voies empruntées. + * + */ + set waysAttributes (wa) { + this._waysAttributes = wa; + } + /** * * @function diff --git a/src/js/server/serverManager.js b/src/js/server/serverManager.js index 964d9b0f..7139a760 100644 --- a/src/js/server/serverManager.js +++ b/src/js/server/serverManager.js @@ -12,7 +12,7 @@ const LOGGER = log4js.getLogger("SERVERMANAGER"); * * @class * @name serverManager -* @description Gestionnaire des serveurs disponible sur un service +* @description Gestionnaire des serveurs disponibles sur un service ou un administrateur * */ @@ -53,7 +53,7 @@ module.exports = class serverManager { * @param {object} config - Configuration à vérifier * */ - checkServerConfiguration(config) { + checkServerConfiguration(config) { if (!config) { LOGGER.error("Aucune configuration n'a ete fournie"); @@ -316,15 +316,16 @@ module.exports = class serverManager { LOGGER.info("Arret de l'ensemble des serveurs."); if (this._loadedServerId.length === 0) { - LOGGER.warn("Aucun serveur n'est disponible."); + LOGGER.warn("Aucun serveur n'est disponible (id)."); return true; } try { assert.deepStrictEqual(this._serverCatalog, {}); - } catch (err) { - LOGGER.warn("Aucun serveur n'est disponible."); + LOGGER.warn("Aucun serveur n'est disponible (catalog)."); return true; + } catch (err) { + // On continue } for (let serverId in this._serverCatalog) { diff --git a/src/js/service/serviceAdministered.js b/src/js/service/serviceAdministered.js index fdeac440..4fea566b 100644 --- a/src/js/service/serviceAdministered.js +++ b/src/js/service/serviceAdministered.js @@ -4,7 +4,7 @@ * * @class * @name ServiceAdministered -* @description Classe modélisant une service administré par l'administrateur. +* @description Classe modélisant une service administré par l'administrateur. C'est une classe mère dérivée par serviceProcess * @param {string} id - Identifiant du service administré * @param {string} type - Type de service administré * @@ -18,6 +18,8 @@ module.exports = class ServiceAdministered { * @function * @name constructor * @description Constructeur de la classe ServiceAdministered + * @param {string} id - id du service + * @param {string} type - Type du service, parmi 'newProcess' pour le moment * */ constructor(id, type) { diff --git a/src/js/service/serviceProcess.js b/src/js/service/serviceProcess.js index 64d4e792..369bc20f 100644 --- a/src/js/service/serviceProcess.js +++ b/src/js/service/serviceProcess.js @@ -36,34 +36,9 @@ module.exports = class ServiceProcess extends ServiceAdministered { // Emplacement de la configuration this._configurationLocation = location; - // Stockage de la configuration - this._configuration = {}; - // Instance de childProcess quand le processus est lancé - this._serviceAdministered; - - } + this._serviceAdministered = {}; - /** - * - * @function - * @name get configurationLocation - * @description Récupérer la configurationLocation du service - * - */ - get configurationLocation () { - return this._configurationLocation; - } - - /** - * - * @function - * @name get configuration - * @description Récupérer la configuration du service - * - */ - get configuration () { - return this._configuration; } /** diff --git a/test/functional/readme.md b/test/functional/readme.md index 7cbed9a8..9f47973a 100644 --- a/test/functional/readme.md +++ b/test/functional/readme.md @@ -4,30 +4,24 @@ Cucumber sera utilisé afin de tester les APIs de Road2, et cela, dans leurs asp ## Utilisation de Cucumber -Il y a plusieurs features cucumber pour effectuer les tests fonctionnels. On retrouve des features pour tester les requêtes qui peuvent être envoyées sur le serveur. Et on retrouve une feature pour tester les différentes configuration que l'on peut fournir au serveur afin de diffuser les services. +Il y a plusieurs features cucumber pour effectuer les tests fonctionnels. On retrouve des features pour tester les requêtes qui peuvent être envoyées sur le serveur. Et on retrouve des features pour tester les différentes configurations que l'on peut fournir au serveur afin de diffuser les services. ### Request -La feature `requestTest.feature` permet de tester les fonctionnalités principales. Elle a l'avantage d'être accessible dès que l'image docker a été construite. La seconde `requestComplementTest.feature` permet de tester plus de fonctionnalités. Pour que cette feature soit testable, il est nécessaire de construire une ressource OSRM et une ressource PGR sur l'île-de-France. C'est pour cette raison que ces features sont séparées. -Enfin, la troisième `requestDataTest.feature` se concentre sur les tests qui impliquent d'avoir une connaissance plus fine de la donnée. Les résultats dépendront des points de départ, d'arrivée et de la présence de pont par exemple. +Les features `request/cucumber/features/req*.feature` permettent de tester les fonctionnalités accessibles via des requêtes. Pour fonctionner, il est nécessaire d'avoir généré des données pour chaque moteur sur l'île-de-France. -Afin de lancer les tests Cucumber, on suivra la procédure suivante: +Afin de lancer ces tests, on suivra la procédure suivante: +- générer des données pour chaque moteur sur l'île-de-France - lancer le serveur Road2 via docker-compose -- exécuter la commande `npm run rtest` via docker-compose (pour tester les fonctionnalités principales de l'api simple 1.0.0) -- exécuter la commande `npm run artest` via docker-compose (pour tester l'api admin 1.0.0) -- générer une ressource OSRM et une ressource PGR sur l'île-de-France via docker-compose -- exécuter la commande `npm run crtest` via docker-compose -- exécuter la commande `npm run drtest` via docker-compose +- exécuter la commande `npm run rtest` via docker-compose. ### Configuration -La feature `configurationTest.feature` permet de tester différentes configuration. Elle a l'avantage d'être accessible dès que l'image docker a été construite. La seconde `configurationComplementTest.feature` permet de tester plus de fonctionnalités. Pour que cette feature soit testable, il est nécessaire de construire une ressource PGR sur l'île-de-France. C'est pour cette raison que ces features sont séparées. +Les features `configuration/cucumber/features/conf*.feature` permettent de tester les fonctionnalités liées au chargement d'une configuration de Road2. -Afin de lancer les tests Cucumber, on suivra la procédure suivante: +Afin de lancer ces tests, on suivra la procédure suivante: - lancer le serveur Road2 via docker-compose -- exécuter la commande `npm run ctest` via docker-compose -- générer une ressource PGR sur l'île-de-France via docker-compose -- exécuter la commande `npm run ccftest` via docker-compose +- exécuter la commande `npm run ctest` via docker-compose. diff --git a/test/integration/mocha/apis/integrationApiManager.js b/test/integration/mocha/apis/integrationApiManager.js index 3df128fd..ed318c0a 100644 --- a/test/integration/mocha/apis/integrationApiManager.js +++ b/test/integration/mocha/apis/integrationApiManager.js @@ -11,48 +11,65 @@ describe('Test de la classe ApisManager', function() { logManager.manageLogs(); }); - let apisManager = new ApisManager(); - let referenceApp = express(); - let app = express(); - let referenceApi = new Api("simple","1.0.0","/home/docker/app/test/integration/mocha/config/apis/simple/1.0.0/index.js"); - referenceApi.initFile = "/home/docker/app/test/integration/mocha/config/apis/simple/1.0.0/init.js"; - referenceApi.updateFile = "/home/docker/app/test/integration/mocha/config/apis/simple/1.0.0/update.js"; - referenceApi.initialize("/simple/1.0.0", referenceApp); + describe('Test du constructeur et des attributs', function() { - describe('Test du constructeur et des getters', function() { + let apisManager = new ApisManager(); + + it('Get apisDirectory', function() { + assert.deepEqual(apisManager._apisDirectory, "../apis/"); + }); it('Get listOfRoutes', function() { - assert.deepEqual(apisManager.listOfRoutes, new Array()); + assert.deepEqual(apisManager._listOfRoutes, new Array()); }); it('Get apisCatalog', function() { - assert.deepEqual(apisManager.apisCatalog, {}); + assert.deepEqual(apisManager._apisCatalog, {}); }); }); - describe('Test de la fonction loadApiDirectory()', function() { + describe('Test de la fonction checkApiConfiguration()', function() { - it('loadApiDirectory() avec les bons parametres', function() { - assert.equal(apisManager.loadApiDirectory(app, "../../../test/integration/mocha/config/apis/", ""), true); + let apisManager = new ApisManager("../../../test/integration/mocha/config/apis/"); + + it('checkApiConfiguration() avec les bons parametres', function() { + let configuration = {"name" : "simple","version" : "1.0.0"}; + assert.equal(apisManager.checkApiConfiguration(configuration), true); + }); + + it('checkApiConfiguration() avec des mauvais parametres', function() { + let configuration = {"nam" : "todo","versio" : "2.0.0"}; + assert.equal(apisManager.checkApiConfiguration(configuration), false); }); }); - describe('Test de la fonction verifyRouteExistanceById()', function() { + describe('Test de la fonction loadApiConfiguration()', function() { - it('verifyRouteExistanceById() avec une route qui existe', function() { - assert.equal(apisManager.verifyRouteExistanceById("/simple/1.0.0"), true); - }); + let apisManager = new ApisManager("../../../test/integration/mocha/config/apis/"); + let app = express(); + let configuration = {"name" : "simple","version" : "1.0.0"}; - it('verifyRouteExistanceById() avec une route qui n\'existe pas', function() { - assert.equal(apisManager.verifyRouteExistanceById("/test/1.0.3"), false); + it('loadApiConfiguration() avec les bons parametres', function() { + assert.equal(apisManager.loadApiConfiguration(app, configuration), true); }); }); describe('Test de la fonction getApi()', function() { + let apisManager = new ApisManager("../../../test/integration/mocha/config/apis/"); + let app = express(); + let configuration = {"name" : "simple","version" : "1.0.0"}; + apisManager.loadApiConfiguration(app, configuration); + let referenceApp = express(); + let referenceApi = new Api("simple","1.0.0","/home/docker/app/test/integration/mocha/config/apis/simple/1.0.0/index.js"); + referenceApi.initFile = "/home/docker/app/test/integration/mocha/config/apis/simple/1.0.0/init.js"; + referenceApi.updateFile = "/home/docker/app/test/integration/mocha/config/apis/simple/1.0.0/update.js"; + referenceApi.initialize("/simple/1.0.0", referenceApp); + + it('getApi()', function() { assert.deepEqual(apisManager.getApi("simple", "1.0.0"), referenceApi); }); diff --git a/test/integration/mocha/base/integrationBaseManager.js b/test/integration/mocha/base/integrationBaseManager.js index 53fcd015..fd341347 100644 --- a/test/integration/mocha/base/integrationBaseManager.js +++ b/test/integration/mocha/base/integrationBaseManager.js @@ -1,8 +1,7 @@ const assert = require('assert'); -const Base = require('../../../../src/js/base/base'); const BaseManager = require('../../../../src/js/base/baseManager'); -const logManager = require('../../../unit/mocha/logManager'); -const fs = require('fs'); +const logManager = require('../logManager'); +const path = require('path'); describe('Test de la classe BaseManager', function() { @@ -11,24 +10,27 @@ describe('Test de la classe BaseManager', function() { logManager.manageLogs(); }); - let configuration = "/home/docker/app/test/integration/mocha/config/dbs/db_config_test.json"; - let referenceBase = new Base(JSON.parse(fs.readFileSync(configuration))); + let configuration = path.resolve(__dirname, "../config/dbs/db_config_test.json"); let baseManager = new BaseManager(); - describe('Test du constructeur et des getters/setters', function() { + describe('Test du constructeur et des attributs', function() { it('Get loadedBaseConfiguration', function() { - assert.deepEqual(baseManager.loadedBaseConfiguration, new Array()); + assert.deepEqual(baseManager._loadedBaseConfiguration, new Array()); + }); + + it('Get checkedBaseConfiguration', function() { + assert.deepEqual(baseManager._checkedBaseConfiguration, new Array()); }); it('Get baseCatalog', function() { - assert.deepEqual(baseManager.baseCatalog, {}); + assert.deepEqual(baseManager._baseCatalog, {}); }); }); - describe('Verifications des configurations', function() { + describe('Cycle de vérification des configurations', function() { it('checkBaseConfiguration()', async function() { let response = await baseManager.checkBaseConfiguration(configuration); @@ -40,15 +42,27 @@ describe('Test de la classe BaseManager', function() { assert.deepEqual(baseManager._checkedBaseConfiguration, [configuration]); }); + it('flushCheckedBaseConfiguration()', function() { + baseManager.saveCheckedBaseConfiguration(configuration); + baseManager.flushCheckedBaseConfiguration(); + assert.deepEqual(baseManager._checkedBaseConfiguration, new Array()); + }); + }); - describe('Creation d\'une base', function() { + describe('Chargement des configurations', function() { it('loadBaseConfiguration()', function() { - let newBase = baseManager.loadBaseConfiguration(configuration); - // TODO: comprendre pourquoi le assert qui suit ne marche pas - // assert.deepEqual(baseManager.baseCatalog[configuration], referenceBase); - assert.equal(newBase.connected, false); + assert.equal(baseManager.loadBaseConfiguration(configuration), true); + }); + + }); + + describe('Récupération d\'une base', function() { + + it('getBase()', function() { + let base = baseManager.getBase(configuration); + assert.deepEqual(base.connected, false); }); }); diff --git a/test/integration/mocha/config/log4js.json b/test/integration/mocha/config/log4js.json index c8dae0dd..2bfbcf15 100644 --- a/test/integration/mocha/config/log4js.json +++ b/test/integration/mocha/config/log4js.json @@ -4,11 +4,11 @@ "console": { "type": "console", "layout": {"type": "pattern", "pattern": "%[[%d] [%p] %c %z -%] %m"} } }, "categories": { - "default": { "appenders": ["console"], "level": "info" } + "default": { "appenders": ["console"], "level": "debug" } } }, "httpConf": { - "level": "info", + "level": "debug", "format": ":remote-addr - :method :url HTTP/:http-version :status :content-length :referrer :user-agent" } } diff --git a/test/integration/mocha/config/road2.json b/test/integration/mocha/config/road2.json new file mode 100644 index 00000000..147ad962 --- /dev/null +++ b/test/integration/mocha/config/road2.json @@ -0,0 +1,27 @@ +{ + "administration":{ + "api" : { + "name" : "admin", + "version" : "1.0.0" + }, + "services": [ + { + "id": "main", + "configuration": "./service.json", + "onStart": "true", + "creationType": "newProcess" + } + ], + "network" : { + "server" : { + "id": "administrator", + "https": "false", + "host": "0.0.0.0", + "port": "8078" + } + }, + "logs": { + "configuration": "./log4js.json" + } + } +} diff --git a/test/unit/mocha/config/road2.json b/test/integration/mocha/config/service.json similarity index 50% rename from test/unit/mocha/config/road2.json rename to test/integration/mocha/config/service.json index 9cfa5574..fb56ec3f 100644 --- a/test/unit/mocha/config/road2.json +++ b/test/integration/mocha/config/service.json @@ -1,16 +1,16 @@ { "application": { - "name": "Road2-test", - "title": "Tests sur le service de calcul d'itinéraire", - "description": "Ce service permet de calculer des itinéraires sur les données du Géoportail.", - "url": "https://wxs.ign.fr/#KEY/geoportail/itineraire", + "name": "Road2", + "title": "Service de calcul d'itinéraire", + "description": "Ce service permet de calculer des itinéraires", + "url": "https://localhost/", "provider": { "name": "IGN", "site": "www.ign.fr", "mail": "sav@ign.fr" }, "logs": { - "configuration": "/home/docker/app/test/unit/mocha/config/log4js.json" + "configuration": "./log4js-service.json" }, "operations":{ "directory": "/home/docker/app/src/resources/operations", @@ -20,21 +20,35 @@ }, "resources": { "directories": [ - "/home/docker/app/test/unit/mocha/config/resources/" + "/home/docker/data/resources/" + ] + }, + "sources": { + "directories": [ + "/home/docker/data/sources/" ] }, "network": { "servers": [ { - "id": "test", + "id": "internalServer", "https": "false", - "host": "0.0.0.1", - "port": "8080" + "host": "0.0.0.0", + "port": "8091" } - ] - }, + ], + "cors": { + "configuration": "./cors.json" + } + }, "projections": { - "directory": "/home/docker/app/test/unit/mocha/config/projections/" - } + "directory": "./projections/" + }, + "apis": [ + { + "name" : "simple", + "version" : "1.0.0" + } + ] } } diff --git a/test/integration/mocha/geometry/integrationLine.js b/test/integration/mocha/geometry/integrationLine.js index 45bf2d9f..8724b655 100644 --- a/test/integration/mocha/geometry/integrationLine.js +++ b/test/integration/mocha/geometry/integrationLine.js @@ -1,7 +1,7 @@ const assert = require('assert'); const Line = require('../../../../src/js/geometry/line'); const proj4 = require('proj4'); -const logManager = require('../../../unit/mocha/logManager'); +const logManager = require('../logManager'); describe('Test de la classe Line', function() { @@ -40,7 +40,7 @@ describe('Test de la classe Line', function() { describe('Test du constructeur et des getters/setters', function() { it('Get type', function() { - assert.equal(line.type, "polyline"); + assert.equal(line.type, "line"); }); it('Get projection', function() { diff --git a/test/integration/mocha/operations/integrationOperation.js b/test/integration/mocha/operations/integrationOperation.js index fdf3a10a..616a6262 100644 --- a/test/integration/mocha/operations/integrationOperation.js +++ b/test/integration/mocha/operations/integrationOperation.js @@ -1,7 +1,7 @@ const assert = require('assert'); const Operation = require('../../../../src/js/operations/operation'); const Parameter = require('../../../../src/js/parameters/parameter'); -const logManager = require('../../../unit/mocha/logManager'); +const logManager = require('../logManager'); describe('Test de la classe Operation', function() { diff --git a/test/integration/mocha/operations/integrationResourceOperation.js b/test/integration/mocha/operations/integrationResourceOperation.js index a6decad8..736463c4 100644 --- a/test/integration/mocha/operations/integrationResourceOperation.js +++ b/test/integration/mocha/operations/integrationResourceOperation.js @@ -1,9 +1,8 @@ const assert = require('assert'); const ResourceOperation = require('../../../../src/js/operations/resourceOperation'); -const Parameter = require('../../../../src/js/parameters/parameter'); const ResourceParameter = require('../../../../src/js/parameters/resourceParameter'); const logManager = require('../logManager'); -const sinon = require('sinon'); +const Parameter = require('../../../../src/js/parameters/parameter'); describe('Test de la classe ResourceOperation', function() { @@ -12,17 +11,11 @@ describe('Test de la classe ResourceOperation', function() { logManager.manageLogs(); }); - // Pour ne pas dépendre de la classe Parameter et resourceParameter - let serviceParameter = sinon.mock(Parameter); - serviceParameter.id = "start"; - - let resourceParameter = sinon.mock(ResourceParameter); - resourceParameter.serviceParameter = serviceParameter; - - let parameters = {}; - parameters["start"] = serviceParameter; - - let resourceOperation = new ResourceOperation("route", parameters); + let serviceParameter = new Parameter("start","point","start","Points de départ","true","false") + let resourceParameter = new ResourceParameter(serviceParameter); + let parameterHash = {}; + parameterHash["start"] = resourceParameter; + let resourceOperation = new ResourceOperation("route", parameterHash); describe('Test du constructeur et des getters', function() { @@ -31,11 +24,19 @@ describe('Test de la classe ResourceOperation', function() { }); it('Get resourceParameters', function() { - assert.deepEqual(resourceOperation.resourceParameters, parameters); + assert.deepEqual(resourceOperation.resourceParameters, parameterHash); + }); + + }); + + describe('Test du constructeur et des getters', function() { + + it('getParameterById() d\'un paramètre existant', function() { + assert.deepEqual(resourceOperation.getParameterById("start"), parameterHash["start"]); }); - it('getParameterById()', function() { - assert.deepEqual(resourceOperation.getParameterById("start"), parameters["start"]); + it('getParameterById() d\'un paramètre non existant', function() { + assert.deepEqual(resourceOperation.getParameterById("end"), {}); }); }); diff --git a/test/integration/mocha/parameters/integrationBoolParameter.js b/test/integration/mocha/parameters/integrationBoolParameter.js new file mode 100644 index 00000000..f60c391d --- /dev/null +++ b/test/integration/mocha/parameters/integrationBoolParameter.js @@ -0,0 +1,82 @@ +const assert = require('assert'); +const Parameter = require('../../../../src/js/parameters/parameter'); +const BoolParameter = require('../../../../src/js/parameters/boolParameter'); +const logManager = require('../logManager'); + +describe('Test de la classe BoolParameter', function() { + + before(function() { + // runs before all tests in this block + logManager.manageLogs(); + }); + + let parameterConf = {"id": "bbox", "defaultValueContent": "true"}; + let parameter = new Parameter("bbox","boolean","bbox","bbox","false","true"); + let boolParameter = new BoolParameter(parameter); + + describe('Test du constructeur et des getters', function() { + + it('Get serviceParameter', function() { + assert.equal(boolParameter.serviceParameter.style, "pipeDelimited"); + }); + + it('Get defaultValueContent', function() { + assert.equal(boolParameter.defaultValueContent, null); + }); + + it('Get values', function() { + assert.deepEqual(boolParameter.values, [true, false]); + }); + + }); + + describe('Test du chargement', function() { + + it('load()', function() { + assert.equal(boolParameter.load(parameterConf), true); + }); + + }); + + describe('Test des vérifications', function() { + + it('check() avec bonne valeur', function() { + assert.equal(boolParameter.check("true").code, "ok"); + }); + + it('check() avec mauvaise valeur', function() { + assert.equal(boolParameter.check("toto").code, "error"); + }); + + it('specificCheck() avec bonne valeur', function() { + assert.equal(boolParameter.specificCheck("true").code, "ok"); + }); + + it('specificCheck() avec mauvaise valeur', function() { + assert.equal(boolParameter.specificCheck("toto").code, "error"); + }); + + }); + + describe('Test des conversions', function() { + + it('convertIntoTable() avec des paramètres bons', function() { + assert.equal(boolParameter.convertIntoTable("true|false", [], {}), true); + }); + + it('specificConvertion() avec des bons paramètres', function() { + assert.equal(boolParameter.specificConvertion("true"), true); + }); + + it('specificConvertion() avec des bons paramètres', function() { + assert.equal(boolParameter.specificConvertion("false"), false); + }); + + it('specificConvertion() avec des mauvais paramètres', function() { + assert.equal(boolParameter.specificConvertion("test"), null); + }); + + }); + + +}); diff --git a/test/integration/mocha/parameters/integrationConstraintParameter.js b/test/integration/mocha/parameters/integrationConstraintParameter.js new file mode 100644 index 00000000..a8f044a6 --- /dev/null +++ b/test/integration/mocha/parameters/integrationConstraintParameter.js @@ -0,0 +1,76 @@ +const assert = require('assert'); +const Parameter = require('../../../../src/js/parameters/parameter'); +const ConstraintParameter = require('../../../../src/js/parameters/constraintParameter'); +const logManager = require('../logManager'); +const Constraint = require('../../../../src/js/constraint/constraint'); + +describe('Test de la classe ConstraintParameter', function() { + + before(function() { + // runs before all tests in this block + logManager.manageLogs(); + }); + + let refContraint = new Constraint("banned","waytype","toll","=","autoroute"); + let parameterConf = {"id":"constraints","values":[{"keyType":"name-osrm","key":"waytype","availableConstraintType":["banned"],"availableValues":[{"value":"autoroute","field":"toll"},{"value":"tunnel","field":"tunnel"},{"value":"pont","field":"bridge"}]}]}; + let parameter = new Parameter("resource","enumeration","resource","resource","true","false"); + let constraintParameter = new ConstraintParameter(parameter); + + describe('Test du constructeur et des getters', function() { + + it('Get serviceParameter', function() { + assert.equal(constraintParameter.serviceParameter.style, "pipeDelimited"); + }); + + it('Get defaultValueContent', function() { + assert.deepEqual(constraintParameter.defaultValueContent, {}); + }); + + it('Get values', function() { + assert.deepEqual(constraintParameter.values, new Array()); + }); + + }); + + describe('Test du chargement', function() { + + it('load()', function() { + assert.equal(constraintParameter.load(parameterConf), true); + }); + + }); + + describe('Test des vérifications', function() { + + it('check() avec bonne valeur', function() { + assert.equal(constraintParameter.check("{\"constraintType\":\"banned\",\"key\":\"waytype\",\"operator\":\"=\",\"value\":\"autoroute\"}").code, "ok"); + }); + + it('check() avec mauvaise valeur', function() { + assert.equal(constraintParameter.check("test").code, "error"); + }); + + it('specificCheck() avec bonne valeur', function() { + assert.equal(constraintParameter.specificCheck("{\"constraintType\":\"banned\",\"key\":\"waytype\",\"operator\":\"=\",\"value\":\"autoroute\"}").code, "ok"); + }); + + it('specificCheck() avec mauvaise valeur', function() { + assert.equal(constraintParameter.specificCheck("test").code, "error"); + }); + + }); + + describe('Test des conversions', function() { + + it('convertIntoTable()', function() { + assert.equal(constraintParameter.convertIntoTable("{\"constraintType\":\"banned\",\"key\":\"waytype\",\"operator\":\"=\",\"value\":\"autoroute\"}\|{\"constraintType\":\"banned\",\"key\":\"waytype\",\"operator\":\"=\",\"value\":\"tunnel\"}", [], {}), true); + }); + + it('specificConvertion()', function() { + assert.deepEqual(constraintParameter.specificConvertion("{\"constraintType\":\"banned\",\"key\":\"waytype\",\"operator\":\"=\",\"value\":\"autoroute\"}"), refContraint); + }); + + }); + + +}); diff --git a/test/integration/mocha/parameters/integrationEnumParameter.js b/test/integration/mocha/parameters/integrationEnumParameter.js new file mode 100644 index 00000000..f6dbb7ef --- /dev/null +++ b/test/integration/mocha/parameters/integrationEnumParameter.js @@ -0,0 +1,82 @@ +const assert = require('assert'); +const Parameter = require('../../../../src/js/parameters/parameter'); +const EnumParameter = require('../../../../src/js/parameters/enumParameter'); +const logManager = require('../logManager'); + +describe('Test de la classe EnumParameter', function() { + + before(function() { + // runs before all tests in this block + logManager.manageLogs(); + }); + + let parameterConf = {"id": "resource","values": ["data","data2"]}; + let parameter = new Parameter("resource","enumeration","resource","resource","true","false"); + let enumParameter = new EnumParameter(parameter); + + describe('Test du constructeur et des getters', function() { + + it('Get serviceParameter', function() { + assert.equal(enumParameter.serviceParameter.style, "pipeDelimited"); + }); + + it('Get defaultValueContent', function() { + assert.equal(enumParameter.defaultValueContent, ""); + }); + + it('Get values', function() { + assert.deepEqual(enumParameter.values, new Array()); + }); + + }); + + describe('Test du chargement', function() { + + it('load()', function() { + assert.equal(enumParameter.load(parameterConf), true); + }); + + }); + + describe('Test des vérifications', function() { + + it('check() avec bonne valeur', function() { + assert.equal(enumParameter.check("data").code, "ok"); + }); + + it('check() avec autre bonne valeur', function() { + assert.equal(enumParameter.check("data2").code, "ok"); + }); + + it('check() avec mauvaise valeur', function() { + assert.equal(enumParameter.check("test").code, "error"); + }); + + it('specificCheck() avec bonne valeur', function() { + assert.equal(enumParameter.specificCheck("data").code, "ok"); + }); + + it('specificCheck() avec autre bonne valeur', function() { + assert.equal(enumParameter.specificCheck("data2").code, "ok"); + }); + + it('specificCheck() avec mauvaise valeur', function() { + assert.equal(enumParameter.specificCheck("test").code, "error"); + }); + + }); + + describe('Test des conversions', function() { + + it('convertIntoTable()', function() { + assert.equal(enumParameter.convertIntoTable("data|data2", [], {}), true); + }); + + it('specificConvertion()', function() { + assert.equal(enumParameter.specificConvertion("data"), "data"); + }); + + }); + + +}); diff --git a/test/integration/mocha/parameters/integrationFloatParameter.js b/test/integration/mocha/parameters/integrationFloatParameter.js new file mode 100644 index 00000000..922dc6a6 --- /dev/null +++ b/test/integration/mocha/parameters/integrationFloatParameter.js @@ -0,0 +1,110 @@ +const assert = require('assert'); +const Parameter = require('../../../../src/js/parameters/parameter'); +const FloatParameter = require('../../../../src/js/parameters/floatParameter'); +const logManager = require('../logManager'); + +describe('Test de la classe FloatParameter', function() { + + before(function() { + // runs before all tests in this block + logManager.manageLogs(); + }); + + let parameterConf = {"id": "costValue","values": {"min": 100,"max": 20000}}; + let parameter = new Parameter("costValue","float","costValue","costValue","true","false"); + let floatParameter = new FloatParameter(parameter); + + describe('Test du constructeur et des getters', function() { + + it('Get serviceParameter', function() { + assert.equal(floatParameter.serviceParameter.style, "pipeDelimited"); + }); + + it('Get defaultValueContent', function() { + assert.equal(floatParameter.defaultValueContent, 0); + }); + + it('Get values', function() { + assert.deepEqual(floatParameter.values, {min:null,max:null}); + }); + + }); + + describe('Test du chargement', function() { + + it('load()', function() { + assert.equal(floatParameter.load(parameterConf), true); + }); + + it('Get defaultValueContent', function() { + assert.equal(floatParameter.defaultValueContent, 0); + }); + + it('Get values', function() { + assert.deepEqual(floatParameter.values, {min:100,max:20000}); + }); + + }); + + describe('Test des vérifications', function() { + + it('check() avec bonne valeur', function() { + assert.equal(floatParameter.check("200").code, "ok"); + }); + + it('check() avec autre bonne valeur', function() { + assert.equal(floatParameter.check("10000").code, "ok"); + }); + + it('check() avec mauvaise valeur', function() { + assert.equal(floatParameter.check("test").code, "error"); + }); + + it('check() avec mauvaise valeur', function() { + assert.equal(floatParameter.check(1).code, "error"); + }); + + it('check() avec mauvaise valeur', function() { + assert.equal(floatParameter.check("1").code, "error"); + }); + + it('check() avec mauvaise valeur', function() { + assert.equal(floatParameter.check("300000").code, "error"); + }); + + it('specificCheck() avec bonne valeur', function() { + assert.equal(floatParameter.specificCheck("200").code, "ok"); + }); + + it('specificCheck() avec autre bonne valeur', function() { + assert.equal(floatParameter.specificCheck("10000").code, "ok"); + }); + + it('specificCheck() avec mauvaise valeur', function() { + assert.equal(floatParameter.specificCheck("test").code, "error"); + }); + + it('specificCheck() avec mauvaise valeur', function() { + assert.equal(floatParameter.specificCheck(1).code, "error"); + }); + + it('specificCheck() avec mauvaise valeur', function() { + assert.equal(floatParameter.specificCheck(300000).code, "error"); + }); + + }); + + describe('Test des conversions', function() { + + it('convertIntoTable()', function() { + assert.equal(floatParameter.convertIntoTable("data|data2", [], {}), true); + }); + + it('specificConvertion()', function() { + assert.equal(floatParameter.specificConvertion(1.321), 1.321); + }); + + }); + + +}); diff --git a/test/integration/mocha/parameters/integrationIntParameter.js b/test/integration/mocha/parameters/integrationIntParameter.js new file mode 100644 index 00000000..16ea6bef --- /dev/null +++ b/test/integration/mocha/parameters/integrationIntParameter.js @@ -0,0 +1,110 @@ +const assert = require('assert'); +const Parameter = require('../../../../src/js/parameters/parameter'); +const IntParameter = require('../../../../src/js/parameters/intParameter'); +const logManager = require('../logManager'); + +describe('Test de la classe IntParameter', function() { + + before(function() { + // runs before all tests in this block + logManager.manageLogs(); + }); + + let parameterConf = {"id": "number", "defaultValueContent": 1, "values": {"min": 1,"max": 10}}; + let parameter = new Parameter("number","integer","number","number","false","true"); + let intParameter = new IntParameter(parameter); + + describe('Test du constructeur et des getters', function() { + + it('Get serviceParameter', function() { + assert.equal(intParameter.serviceParameter.style, "pipeDelimited"); + }); + + it('Get defaultValueContent', function() { + assert.equal(intParameter.defaultValueContent, 0); + }); + + it('Get values', function() { + assert.deepEqual(intParameter.values, {min:null,max:null}); + }); + + }); + + describe('Test du chargement', function() { + + it('load()', function() { + assert.equal(intParameter.load(parameterConf), true); + }); + + it('Get defaultValueContent', function() { + assert.equal(intParameter.defaultValueContent, 1); + }); + + it('Get values', function() { + assert.deepEqual(intParameter.values, {min:1,max:10}); + }); + + }); + + describe('Test des vérifications', function() { + + it('check() avec bonne valeur', function() { + assert.equal(intParameter.check("2").code, "ok"); + }); + + it('check() avec autre bonne valeur', function() { + assert.equal(intParameter.check("10").code, "ok"); + }); + + it('check() avec mauvaise valeur', function() { + assert.equal(intParameter.check("test").code, "error"); + }); + + it('check() avec mauvaise valeur', function() { + assert.equal(intParameter.check(1).code, "error"); + }); + + it('check() avec mauvaise valeur', function() { + assert.equal(intParameter.check("0").code, "error"); + }); + + it('check() avec mauvaise valeur', function() { + assert.equal(intParameter.check("2000").code, "error"); + }); + + it('specificCheck() avec bonne valeur', function() { + assert.equal(intParameter.specificCheck("2").code, "ok"); + }); + + it('specificCheck() avec autre bonne valeur', function() { + assert.equal(intParameter.specificCheck("10").code, "ok"); + }); + + it('specificCheck() avec mauvaise valeur', function() { + assert.equal(intParameter.specificCheck("test").code, "error"); + }); + + it('specificCheck() avec mauvaise valeur', function() { + assert.equal(intParameter.specificCheck(0).code, "error"); + }); + + it('specificCheck() avec mauvaise valeur', function() { + assert.equal(intParameter.specificCheck(2000).code, "error"); + }); + + }); + + describe('Test des conversions', function() { + + it('convertIntoTable()', function() { + assert.equal(intParameter.convertIntoTable("data|data2", [], {}), true); + }); + + it('specificConvertion()', function() { + assert.equal(intParameter.specificConvertion(1), 1); + }); + + }); + + +}); diff --git a/test/integration/mocha/parameters/integrationPointParameter.js b/test/integration/mocha/parameters/integrationPointParameter.js new file mode 100644 index 00000000..a39f49d4 --- /dev/null +++ b/test/integration/mocha/parameters/integrationPointParameter.js @@ -0,0 +1,92 @@ +const assert = require('assert'); +const Point = require('../../../../src/js/geometry/point'); +const Parameter = require('../../../../src/js/parameters/parameter'); +const PointParameter = require('../../../../src/js/parameters/pointParameter'); +const logManager = require('../logManager'); + +describe('Test de la classe PointParameter', function() { + + before(function() { + // runs before all tests in this block + logManager.manageLogs(); + }); + + let refPoint = new Point(2,48.5,"EPSG:4326"); + let parameterConf = {"id": "point","values": {"bbox": "1.7,48.4,3.3,49.1","projection": "EPSG:4326"}}; + let parameter = new Parameter("start","point","start","start","true","false"); + let pointParameter = new PointParameter(parameter); + + describe('Test du constructeur et des getters', function() { + + it('Get serviceParameter', function() { + assert.equal(pointParameter.serviceParameter.style, "pipeDelimited"); + }); + + it('Get defaultValueContent', function() { + assert.equal(pointParameter.defaultValueContent, ""); + }); + + it('Get values', function() { + assert.deepEqual(pointParameter.values, {bbox:""}); + }); + + }); + + describe('Test du chargement', function() { + + it('load()', function() { + assert.equal(pointParameter.load(parameterConf), true); + }); + + it('Get defaultValueContent', function() { + assert.equal(pointParameter.defaultValueContent, ""); + }); + + it('Get values', function() { + assert.deepEqual(pointParameter.values, {bbox:"1.7,48.4,3.3,49.1"}); + }); + + }); + + describe('Test des vérifications', function() { + + it('check() avec bonne valeur', function() { + assert.equal(pointParameter.check("2.1,48.6","EPSG:4326").code, "ok"); + }); + + it('check() avec mauvaise valeur', function() { + assert.equal(pointParameter.check("2.1,48","EPSG:4326").code, "error"); + }); + + it('check() avec mauvaise valeur', function() { + assert.equal(pointParameter.check("1.5,48.5","EPSG:4326").code, "error"); + }); + + it('specificCheck() avec bonne valeur', function() { + assert.equal(pointParameter.specificCheck("2.1,48.6","EPSG:4326").code, "ok"); + }); + + it('specificCheck() avec mauvaise valeur', function() { + assert.equal(pointParameter.specificCheck("2.1,48","EPSG:4326").code, "error"); + }); + + it('specificCheck() avec mauvaise valeur', function() { + assert.equal(pointParameter.specificCheck("1.5,48.5","EPSG:4326").code, "error"); + }); + + }); + + describe('Test des conversions', function() { + + it('convertIntoTable()', function() { + assert.equal(pointParameter.convertIntoTable("2,48.5|2,48.6", [], "EPSG:4326"), true); + }); + + it('specificConvertion()', function() { + assert.deepEqual(pointParameter.specificConvertion("2,48.5","EPSG:4326"), refPoint); + }); + + }); + + +}); diff --git a/test/integration/mocha/parameters/integrationResourceParameter.js b/test/integration/mocha/parameters/integrationResourceParameter.js index 0133a60d..19cf381a 100644 --- a/test/integration/mocha/parameters/integrationResourceParameter.js +++ b/test/integration/mocha/parameters/integrationResourceParameter.js @@ -1,58 +1,85 @@ const assert = require('assert'); +const Parameter = require('../../../../src/js/parameters/parameter'); const ResourceParameter = require('../../../../src/js/parameters/resourceParameter'); -const logManager = require('../../../unit/mocha/logManager'); +const logManager = require('../logManager'); -describe('Test de la classe RouteRequest', function() { +describe('Test de la classe ResourceParameter', function() { before(function() { // runs before all tests in this block logManager.manageLogs(); }); - let resourceParameter = new ResourceParameter({explode: true, min: 0, max: 5, style: "pipeDelimited"}); + let parameter = new Parameter("intermediates","point","intermediates","Points intermédiaires","true","false"); + let resourceParameter = new ResourceParameter(parameter); describe('Test du constructeur et des getters', function() { - it('Get Parameter', function() { + it('Get serviceParameter', function() { assert.equal(resourceParameter.serviceParameter.style, "pipeDelimited"); }); }); - describe('Test de load', function() { + describe('Test du chargement', function() { - it('Load', function() { - assert.equal(resourceParameter.load("toto"), false); + // Dans cette classe, cette fonction renvoit toujours false car elle est réellement implémentée dans les classes filles + it('load()', function() { + assert.equal(resourceParameter.load({"id":"test"}), false); }); }); - describe('Test des check', function() { + describe('Test des vérifications', function() { - it('Check', function() { + // Dans cette classe, cette fonction renvoit toujours une erreur car elle fait appel à specificCheck() qui est réellement implémentée dans les classes filles + it('check() avec options', function() { + assert.equal(resourceParameter.check("toto", {"test":true}).code, "error"); + }); + + it('check() avec options vides', function() { assert.equal(resourceParameter.check("toto", {}).code, "error"); }); - it('Specific check', function() { + it('check() sans options', function() { + assert.equal(resourceParameter.check("toto").code, "error"); + }); + + // Dans cette classe, cette fonction renvoit toujours une erreur car elle est réellement implémentée dans les classes filles + it('specificCheck() avec options', function() { + assert.equal(resourceParameter.specificCheck("toto", {"test":true}).code, "error"); + }); + + it('specificCheck() avec options vides', function() { assert.equal(resourceParameter.specificCheck("toto", {}).code, "error"); }); + it('specificCheck() sans options', function() { + assert.equal(resourceParameter.specificCheck("toto").code, "error"); + }); + }); describe('Test des conversions', function() { - it('Convert into table OK', function() { - assert.equal(resourceParameter.convertIntoTable(["toto", "tata"], [], {}), false); + // Dans cette classe, cette fonction renvoit toujours une erreur car elle fait appel à specificConversion() qui est réellement implémentée dans les classes filles + it('convertIntoTable() avec des paramètres bons', function() { + assert.equal(resourceParameter.convertIntoTable("test", [], {}), false); }); - it('Convert into table OK not exploded', function() { - assert.equal(resourceParameterNotExplode.convertIntoTable("toto|tata", [], {}), true); + // Dans cette classe, cette fonction renvoit toujours une erreur car elle est réellement implémentée dans les classes filles + it('specificConvertion() avec options', function() { + assert.equal(resourceParameter.specificConvertion("toto", {"test":true}), null); }); - it('Specific Convertion', function() { + it('specificConvertion() avec options vides', function() { assert.equal(resourceParameter.specificConvertion("toto", {}), null); }); + it('specificConvertion() sans options', function() { + assert.equal(resourceParameter.specificConvertion("toto"), null); + }); + }); diff --git a/test/integration/mocha/requests/integrationIsochroneRequest.js b/test/integration/mocha/requests/integrationIsochroneRequest.js index 1c004a64..6034fed5 100644 --- a/test/integration/mocha/requests/integrationIsochroneRequest.js +++ b/test/integration/mocha/requests/integrationIsochroneRequest.js @@ -1,6 +1,6 @@ const assert = require('assert'); const IsochroneRequest = require('../../../../src/js/requests/isochroneRequest'); -const logManager = require('../../../unit/mocha/logManager'); +const logManager = require('../logManager'); describe('Test de la classe IsochroneRequest', function() { @@ -9,7 +9,7 @@ describe('Test de la classe IsochroneRequest', function() { logManager.manageLogs(); }); - let request = new IsochroneRequest("corse-osm", {lon: 8.732901, lat: 41.928821}, "time", 100, "car", "departure", "EPSG:4326", "geojson", "s", "m"); + let request = new IsochroneRequest("corse-osm", {lon: 8.732901, lat: 41.928821}, "time", 100, "car", "departure", "EPSG:4326", "geojson", "minute", "meter"); describe('Test du constructeur et des getters', function() { @@ -54,11 +54,15 @@ describe('Test de la classe IsochroneRequest', function() { }); it('Get timeUnit', function() { - assert.deepEqual(request.timeUnit, "s"); + assert.deepEqual(request.timeUnit, "minute"); }); it('Get distanceUnit', function() { - assert.deepEqual(request.distanceUnit, "m"); + assert.deepEqual(request.distanceUnit, "meter"); + }); + + it('Get constraints', function() { + assert.deepEqual(request.constraints, new Array()); }); }); @@ -75,9 +79,9 @@ describe('Test de la classe IsochroneRequest', function() { assert.equal(request.resource, "corse-osm-2"); }); - it('Set Type', function() { + it('Set Type ne change rien', function() { request.type = "otherRequest"; - assert.equal(request.type, "otherRequest"); + assert.equal(request.type, "isochroneRequest"); }); it('Set point', function() { @@ -116,13 +120,18 @@ describe('Test de la classe IsochroneRequest', function() { }); it('Set timeUnit', function() { - request.timeUnit = "min"; - assert.deepEqual(request.timeUnit, "min"); + request.timeUnit = "second"; + assert.deepEqual(request.timeUnit, "second"); }); it('Set distanceUnit', function() { - request.distanceUnit = "km"; - assert.deepEqual(request.distanceUnit, "km"); + request.distanceUnit = "kilometer"; + assert.deepEqual(request.distanceUnit, "kilometer"); + }); + + it('Set constraints', function() { + request.constraints = [{"test":true}]; + assert.deepEqual(request.constraints, [{"test":true}]); }); diff --git a/test/integration/mocha/requests/integrationNearestRequest.js b/test/integration/mocha/requests/integrationNearestRequest.js new file mode 100644 index 00000000..d0a69516 --- /dev/null +++ b/test/integration/mocha/requests/integrationNearestRequest.js @@ -0,0 +1,70 @@ +const assert = require('assert'); +const NearestRequest = require('../../../../src/js/requests/nearestRequest'); +const Point = require('../../../../src/js/geometry/point'); +const logManager = require('../logManager'); + +describe('Test de la classe NearestRequest', function() { + + before(function() { + // runs before all tests in this block + logManager.manageLogs(); + }); + + let point = new Point(2,48,"EPSG:4326"); + let request = new NearestRequest("data", point); + + describe('Test du constructeur et des getters', function() { + + it('Get Operation', function() { + assert.equal(request.operation, "nearest"); + }); + + it('Get Resource', function() { + assert.equal(request.resource, "data"); + }); + + it('Get Type', function() { + assert.equal(request.type, "nearestRequest"); + }); + + it('Get coordinates', function() { + assert.deepEqual(request.coordinates, point); + }); + + it('Get number', function() { + assert.equal(request.number, 1); + }); + + }); + + describe('Test des setters', function() { + + it('Set Operation', function() { + request.operation = "nearest"; + assert.equal(request.operation, "nearest"); + }); + + it('Set Resource', function() { + request.resource = "data"; + assert.equal(request.resource, "data"); + }); + + it('Set Type ne change rien', function() { + request.type = "otherRequest"; + assert.equal(request.type, "nearestRequest"); + }); + + it('Set Start', function() { + let newPoint = new Point(2.1,48.2,"EPSG:4326"); + request.coordinates = newPoint; + assert.deepEqual(request.coordinates, newPoint); + }); + + it('Set number', function() { + request.number = 2; + assert.deepEqual(request.number, 2); + }); + + }); + +}); diff --git a/test/integration/mocha/requests/integrationRouteRequest.js b/test/integration/mocha/requests/integrationRouteRequest.js index 1de841a4..404859d8 100644 --- a/test/integration/mocha/requests/integrationRouteRequest.js +++ b/test/integration/mocha/requests/integrationRouteRequest.js @@ -1,6 +1,6 @@ const assert = require('assert'); const RouteRequest = require('../../../../src/js/requests/routeRequest'); -const logManager = require('../../../unit/mocha/logManager'); +const logManager = require('../logManager'); describe('Test de la classe RouteRequest', function() { @@ -49,6 +49,30 @@ describe('Test de la classe RouteRequest', function() { assert.deepEqual(request.intermediates, new Array()); }); + it('Get waysAttributes', function() { + assert.deepEqual(request.waysAttributes, new Array()); + }); + + it('Get geometryFormat', function() { + assert.deepEqual(request.geometryFormat, "geojson"); + }); + + it('Get bbox', function() { + assert.deepEqual(request.bbox, true); + }); + + it('Get timeUnit', function() { + assert.deepEqual(request.timeUnit, "minute"); + }); + + it('Get distanceUnit', function() { + assert.deepEqual(request.distanceUnit, "meter"); + }); + + it('Get constraints', function() { + assert.deepEqual(request.constraints, new Array()); + }); + }); describe('Test des setters', function() { @@ -63,9 +87,9 @@ describe('Test de la classe RouteRequest', function() { assert.equal(request.resource, "corse-osm-2"); }); - it('Set Type', function() { + it('Set Type ne change rien', function() { request.type = "otherRequest"; - assert.equal(request.type, "otherRequest"); + assert.equal(request.type, "routeRequest"); }); it('Set Start', function() { @@ -98,7 +122,48 @@ describe('Test de la classe RouteRequest', function() { assert.deepEqual(request.intermediates, [{lon: 8.732902, lat: 41.953932},{lon: 8.732801, lat: 41.953835}]); }); + it('Set waysAttributes', function() { + request.waysAttributes = ["name"]; + assert.deepEqual(request.waysAttributes, ["name"]); + }); + + it('Set geometryFormat', function() { + request.geometryFormat = "wkt"; + assert.deepEqual(request.geometryFormat, "wkt"); + }); + + it('Set bbox', function() { + request.bbox = false; + assert.deepEqual(request.bbox, false); + }); + + it('Set timeUnit', function() { + request.timeUnit = "second"; + assert.deepEqual(request.timeUnit, "second"); + }); + + it('Set distanceUnit', function() { + request.distanceUnit = "kilometer"; + assert.deepEqual(request.distanceUnit, "kilometer"); + }); + + it('Set constraints', function() { + request.constraints = [{"test":true}] + assert.deepEqual(request.constraints, [{"test":true}]); + }); + }); + describe('Test de isAttributeRequested()', function() { + + it('isAttributeRequested() d\'un attribut demandé', function() { + assert.equal(request.isAttributeRequested("name"), true); + }); + + it('isAttributeRequested() d\'un attribut non demandé', function() { + assert.equal(request.isAttributeRequested("test"), false); + }); + + }); }); diff --git a/test/integration/mocha/resources/integrationOsrmResource.js b/test/integration/mocha/resources/integrationOsrmResource.js index ba8123d9..ff9a4efc 100644 --- a/test/integration/mocha/resources/integrationOsrmResource.js +++ b/test/integration/mocha/resources/integrationOsrmResource.js @@ -1,7 +1,7 @@ const assert = require('assert'); const OsrmResource = require('../../../../src/js/resources/osrmResource'); const RouteRequest = require('../../../../src/js/requests/routeRequest'); -const logManager = require('../../../unit/mocha/logManager'); +const logManager = require('../logManager'); const sinon = require('sinon'); diff --git a/test/integration/mocha/resources/integrationResourceManager.js b/test/integration/mocha/resources/integrationResourceManager.js index 6c0f930f..d825b7f7 100644 --- a/test/integration/mocha/resources/integrationResourceManager.js +++ b/test/integration/mocha/resources/integrationResourceManager.js @@ -1,7 +1,6 @@ const assert = require('assert'); const ResourceManager = require('../../../../src/js/resources/resourceManager'); const SourceManager = require('../../../../src/js/sources/sourceManager'); -const TopologyManager = require('../../../../src/js/topology/topologyManager'); const OperationManager = require('../../../../src/js/operations/operationManager'); const logManager = require('../logManager'); @@ -163,13 +162,11 @@ describe('Test de la classe ResourceManager', function() { let resourceManager = new ResourceManager(); let sourceManager = sinon.mock(SourceManager); - let topologyManager = sinon.mock(TopologyManager); let operationManager = sinon.mock(OperationManager); // Comportements attendus sourceManager.checkSource = sinon.stub().withArgs(resourceConfiguration).returns(true); sourceManager.sourceTopology = new Array(); - topologyManager.checkTopology = sinon.stub().returns(true); operationManager.checkResourceOperationConf = sinon.stub().returns(true); operationManager.getResourceOperationConf = sinon.stub().returns(true); operationManager.createResourceOperation = sinon.stub().returns(true); @@ -185,7 +182,7 @@ describe('Test de la classe ResourceManager', function() { describe('Test de checkResource() et checkResourceOsrm()', function() { it('Avec les bons parametres', function() { - assert.equal(resourceManager.checkResource(resourceConfiguration, sourceManager, operationManager, topologyManager), true); + assert.equal(resourceManager.checkResource(resourceConfiguration, sourceManager, operationManager), true); }); it('checkResource() avec un mauvais id', function() { diff --git a/test/integration/mocha/resources/integrationValhallaResource.js b/test/integration/mocha/resources/integrationValhallaResource.js index b248a59c..36852841 100644 --- a/test/integration/mocha/resources/integrationValhallaResource.js +++ b/test/integration/mocha/resources/integrationValhallaResource.js @@ -1,7 +1,7 @@ const assert = require('assert'); const ValhallaResource = require('../../../../src/js/resources/valhallaResource'); const RouteRequest = require('../../../../src/js/requests/routeRequest'); -const logManager = require('../../../unit/mocha/logManager'); +const logManager = require('../logManager'); const sinon = require('sinon'); diff --git a/test/integration/mocha/responses/integrationPortion.js b/test/integration/mocha/responses/integrationPortion.js index 8d9766b6..ffd17dad 100644 --- a/test/integration/mocha/responses/integrationPortion.js +++ b/test/integration/mocha/responses/integrationPortion.js @@ -1,7 +1,7 @@ const assert = require('assert'); const Portion = require('../../../../src/js/responses/portion'); const Step = require('../../../../src/js/responses/step'); -const logManager = require('../../../unit/mocha/logManager'); +const logManager = require('../logManager'); describe('Test de la classe Portion', function() { diff --git a/test/integration/mocha/server/integrationServerManager.js b/test/integration/mocha/server/integrationServerManager.js new file mode 100644 index 00000000..93963b21 --- /dev/null +++ b/test/integration/mocha/server/integrationServerManager.js @@ -0,0 +1,87 @@ +const assert = require('assert'); +const ServerManager = require('../../../../src/js/server/serverManager'); +const logManager = require('../logManager'); +const path = require('path'); +const fs = require('fs'); +const express = require('express'); + +describe('Test de la classe ServerManager', function() { + + before(function() { + // runs before all tests in this block + logManager.manageLogs(); + }); + + let file = path.resolve(__dirname, "../config/road2.json"); + let configuration = JSON.parse(fs.readFileSync(file)); + configuration = configuration.administration.network.server; + + let app = express(); + + let serverManager = new ServerManager(); + + describe('Test du constructeur et des attributs', function() { + + it('Get _loadedServerId', function() { + assert.deepEqual(serverManager._loadedServerId, new Array()); + }); + + it('Get _checkedServerId', function() { + assert.deepEqual(serverManager._checkedServerId, new Array()); + }); + + it('Get _serverCatalog', function() { + assert.deepEqual(serverManager._serverCatalog, {}); + }); + + it('Get _loadedServerDescription', function() { + assert.deepEqual(serverManager._loadedServerDescription, {}); + }); + + it('Get _checkedServerDescription', function() { + assert.deepEqual(serverManager._checkedServerDescription, {}); + }); + + }); + + describe('Cycle de vérification des configurations', function() { + + it('checkServerConfiguration()', function() { + assert.equal(serverManager.checkServerConfiguration(configuration), true); + }); + + it('saveServerConfiguration()', function() { + serverManager.saveServerConfiguration(configuration); + let refObject = {}; + refObject[configuration.id] = configuration; + assert.deepEqual(serverManager._checkedServerDescription, refObject); + }); + + it('flushCheckedServer()', function() { + serverManager.flushCheckedServer(); + assert.deepEqual(serverManager._checkedServerDescription, {}); + }); + + }); + + describe('Chargement des configurations', function() { + + it('loadServerConfiguration()', function() { + assert.equal(serverManager.loadServerConfiguration(app, configuration), true); + }); + + }); + + describe('Cycle de vie des serveurs gérés', function() { + + it('startAllServers()', function() { + assert.equal(serverManager.startAllServers(), true); + }); + + it('stopAllServer()', function() { + assert.equal(serverManager.stopAllServer(), true); + }); + + }); + +}); diff --git a/test/integration/mocha/service/integrationService.js b/test/integration/mocha/service/integrationService.js index bd4a7e3b..885e740f 100644 --- a/test/integration/mocha/service/integrationService.js +++ b/test/integration/mocha/service/integrationService.js @@ -4,11 +4,10 @@ const RouteRequest = require('../../../../src/js/requests/routeRequest'); const ApisManager = require('../../../../src/js/apis/apisManager'); const ResourceManager = require('../../../../src/js/resources/resourceManager'); const SourceManager = require('../../../../src/js/sources/sourceManager'); -const TopologyManager = require('../../../../src/js/topology/topologyManager'); const ServerManager = require('../../../../src/js/server/serverManager'); const Resource = require('../../../../src/js/resources/resource'); const Source = require('../../../../src/js/sources/source'); -const logManager = require('../../../unit/mocha/logManager'); +const logManager = require('../logManager'); const path = require('path'); const fs = require('fs'); @@ -70,7 +69,6 @@ describe('Test de la classe Service', function() { sourceManager.getSourceTopology = sinon.stub().returns("toto"); service._sourceManager = sourceManager; - const topologyManager = sinon.mock(TopologyManager); topologyManager.getTopologyById = sinon.stub().returns("toto"); service._topologyManager = topologyManager; diff --git a/test/integration/mocha/service/integrationServiceProcess.js b/test/integration/mocha/service/integrationServiceProcess.js new file mode 100644 index 00000000..ff0b749c --- /dev/null +++ b/test/integration/mocha/service/integrationServiceProcess.js @@ -0,0 +1,44 @@ +const assert = require('assert'); +const ServiceProcess = require('../../../../src/js/service/serviceProcess'); +const logManager = require('../logManager'); +const path = require('path'); + +describe('Test de la classe ServiceProcess', function() { + + before(function() { + // runs before all tests in this block + logManager.manageLogs(); + }); + + let configuration = path.resolve(__dirname, "../config/service.json"); + let serviceProcess = new ServiceProcess("test", configuration); + + describe('Test du constructeur et des attributs', function() { + + it('Get id', function() { + assert.equal(serviceProcess.id, "test"); + }); + + it('Get type', function() { + assert.equal(serviceProcess.type, "newProcess"); + }); + + it('Get _configurationLocation', function() { + assert.equal(serviceProcess._configurationLocation, configuration); + }); + + it('Get _serviceAdministered', function() { + assert.deepEqual(serviceProcess._serviceAdministered, {}); + }); + + }); + + describe('Test du chargement d\'un service', function() { + + xit('loadService()', function() { + assert.equal(serviceProcess.loadService(), true); + }); + + }); + +}); diff --git a/test/integration/mocha/sources/integrationPgrSource.js b/test/integration/mocha/sources/integrationPgrSource.js index b72f9e76..cbe498f3 100644 --- a/test/integration/mocha/sources/integrationPgrSource.js +++ b/test/integration/mocha/sources/integrationPgrSource.js @@ -19,9 +19,13 @@ describe('Test de la classe pgrSource', function() { "storage": { "dbConfig": "/home/docker/app/test/unit/mocha/config/dbs/db_config_test.json", "costColumn": "cost_s_car", - "rcostColumn": "reverse_cost_s_car" + "rcostColumn": "reverse_cost_s_car", + "base": { + "schema" : "public", + "attributes" : {length: 0} + } }, - "cost": { + "costs": [{ "profile": "car", "optimization": "fastest", "compute": { @@ -30,6 +34,7 @@ describe('Test de la classe pgrSource', function() { } } } + ] }; let topology = { @@ -51,9 +56,13 @@ describe('Test de la classe pgrSource', function() { "type": "pgr", "storage": { "costColumn": "cost_m_car", - "rcostColumn": "reverse_cost_m_car" + "rcostColumn": "reverse_cost_m_car", + "base": { + "schema" : "public", + "attributes" : {length: 0} + } }, - "cost": { + "costs": [{ "profile": "car", "optimization": "shortest", "compute": { @@ -62,6 +71,7 @@ describe('Test de la classe pgrSource', function() { } } } + ] }; let source = new pgrSource(sourceDescription, topology); @@ -73,7 +83,7 @@ describe('Test de la classe pgrSource', function() { describe('Test du constructeur et des getters', function() { - it('Get Source id', function() { + xit('Get Source id', function() { assert.equal(source.id, "test-car-fastest"); }); diff --git a/test/integration/mocha/sources/integrationSourceManager.js b/test/integration/mocha/sources/integrationSourceManager.js index a3dde9c2..29d1b1e0 100644 --- a/test/integration/mocha/sources/integrationSourceManager.js +++ b/test/integration/mocha/sources/integrationSourceManager.js @@ -1,7 +1,7 @@ const assert = require('assert'); const SourceManager = require('../../../../src/js/sources/sourceManager'); const OperationManager = require('../../../../src/js/operations/operationManager'); -const logManager = require('../../../unit/mocha/logManager'); +const logManager = require('../logManager'); const Source = require('../../../../src/js/sources/source'); const sinon = require('sinon'); diff --git a/test/integration/mocha/sources/integrationValhallaSource.js b/test/integration/mocha/sources/integrationValhallaSource.js index fffb9d4b..37ab5b9f 100644 --- a/test/integration/mocha/sources/integrationValhallaSource.js +++ b/test/integration/mocha/sources/integrationValhallaSource.js @@ -39,7 +39,7 @@ describe('Test de la classe valhallaSource', function() { "dir": "/home/docker/data/corse-latest-valhalla-tiles/", "config": "/home/docker/data/valhalla.json" }, - "cost": { + "costs": [{ "profile": "car", "optimization": "fastest", "compute": { @@ -54,6 +54,7 @@ describe('Test de la classe valhallaSource', function() { } } } + ] }; let topology = { diff --git a/test/integration/mocha/topology/integrationTopologyManager.js b/test/integration/mocha/topology/integrationTopologyManager.js deleted file mode 100644 index 712b79a9..00000000 --- a/test/integration/mocha/topology/integrationTopologyManager.js +++ /dev/null @@ -1,87 +0,0 @@ -const assert = require('assert'); -const TopologyManager = require('../../../../src/js/topology/topologyManager'); -const BaseManager = require('../../../../src/js/base/baseManager'); -const ProjectionManager = require('../../../../src/js/geography/projectionManager'); -const OsmTopology = require('../../../../src/js/topology/osmTopology'); -const logManager = require('../logManager'); -const fs = require('fs'); - -describe('Test de la classe TopologyManager', function() { - - before(function() { - // runs before all tests in this block - logManager.manageLogs(); - }); - - let baseManager = new BaseManager(); - let projectionManager = new ProjectionManager(); - projectionManager.loadProjectionDirectory("/home/docker/app/test/integration/mocha/config/projections"); - - let topologyManager = new TopologyManager(baseManager, projectionManager); - - describe('Test du checkTopology()', function() { - - it('checkTopology() avec une topologie OSM correcte', function() { - let correctOSMTopology = JSON.parse(fs.readFileSync("/home/docker/app/test/integration/resources/topology/correctOSMTopology.json")); - assert.equal(topologyManager.checkTopology(correctOSMTopology), true); - }); - - it('checkTopology() avec une topologie OSM incorrecte', function() { - let incorrectOSMTopology = JSON.parse(fs.readFileSync("/home/docker/app/test/integration/resources/topology/incorrectOSMTopology.json")); - assert.equal(topologyManager.checkTopology(incorrectOSMTopology), false); - }); - - it('checkTopology() avec une topologie DB correcte', function() { - let correctDBTopology = JSON.parse(fs.readFileSync("/home/docker/app/test/integration/resources/topology/correctDBTopology.json")); - assert.equal(topologyManager.checkTopology(correctDBTopology), true); - }); - - it('checkTopology() avec une topologie DB incorrecte', function() { - let incorrectDBTopology = JSON.parse(fs.readFileSync("/home/docker/app/test/integration/resources/topology/incorrectDBTopology.json")); - assert.equal(topologyManager.checkTopology(incorrectDBTopology), false); - }); - - }); - - describe('Test du checkDuplicationTopology()', function() { - - let correctOSMTopology = JSON.parse(fs.readFileSync("/home/docker/app/test/integration/resources/topology/correctOSMTopology.json")); - - it('checkDuplicationTopology() avec une topologie deja verifiee et identique', function() { - assert.equal(topologyManager.checkDuplicationTopology(correctOSMTopology), true); - }); - - it('checkDuplicationTopology() avec une topologie deja verifiee mais non identique', function() { - correctOSMTopology.description = "test"; - assert.equal(topologyManager.checkDuplicationTopology(correctOSMTopology), false); - }); - - }); - - describe('Test du createTopology()', function() { - - let correctOSMTopology = JSON.parse(fs.readFileSync("/home/docker/app/test/integration/resources/topology/correctOSMTopology.json")); - let referenceTopology = new OsmTopology(correctOSMTopology.id, correctOSMTopology.description, - correctOSMTopology.projection, correctOSMTopology.bbox, correctOSMTopology.storage.file); - - it('createTopology() avec une topologie deja verifiee', function() { - assert.deepEqual(topologyManager.createTopology(correctOSMTopology), referenceTopology); - }); - - }); - - describe('Test du loadAllTopologies()', function() { - - it('loadAllTopologies()', function() { - assert.deepEqual(topologyManager.loadAllTopologies(), true); - }); - - it('loadAllTopologies() pour un manager vide', function() { - let emptyTopologyManager = new TopologyManager(baseManager, projectionManager); - assert.deepEqual(emptyTopologyManager.loadAllTopologies(), false); - }); - - - }); - -}) \ No newline at end of file diff --git a/test/integration/readme.md b/test/integration/readme.md index 3bc24f36..011fd25a 100644 --- a/test/integration/readme.md +++ b/test/integration/readme.md @@ -18,19 +18,22 @@ C'est l'approche bottom-up qui a été choisie pour ces tests. On va tester les - point (geometry, proj4) - polygon (geoemtry, turf, proj4, polyline) - operation (parameter) - - resourceParameter (parameter)* - - routeRequest (request) - - isochroneRequest (request) - - serverManager (server, ExpressJS, log4js) + - resourceParameter (parameter) + - serverManager (server, ExpressJS, log4js, fs, assert) - Deuxième niveau: + - routeRequest (request, point) + - isochroneRequest (request, point) + - nearestRequest (request, point) - resourceOperation (resourceParameter) - boolParameter (resourceParameter) - enumParameter (resourceParameter) - floatParameter (resourceParameter) - pointParameter (resourceParameter, point, log4js) - constraintParameter (resourceParameter, constraint, looseConstraint) - - isochroneResponse (response, point, geometry) + - intParameter (resourceParameter) + - isochroneResponse (response, point, geometry)* + - nearestResponse (response, point, geometry) - step (line, duration, distance) - source (baseManager, projectionManager) @@ -49,7 +52,7 @@ Cinquième niveau: - routeResponse (response, point, route) Sixième niveau: - - osrmSource (source, osrm, routeResponse, route, portion, line, point, step, distance, duration, errorManager, log4js) + - osrmSource (source, osrm, routeResponse, nearestResponse, route, portion, line, point, step, distance, duration, errorManager, log4js) - pgrSource (source, routeResponse, isochroneResponse, route, portion, line, point, polygon, step, distance, duration, errorManager, gisManager, copyManager, simplify, turf, looseConstraint, log4js) Septième niveau: @@ -61,6 +64,13 @@ Huitième niveau: Neuvième niveau: - service (apisManager, resourceManager, sourceManager, operationManager, baseManager, projectionManager, serverManager, errorManager, ExpressJS, log4js) +Dixième niveau: + - serviceManager (service, serviceProcess, log4js) + - serviceProcess (serviceAdministered, service, log4js, fork) + +Onzième niveau: + - administrator (express, log4js, helmet, path, fs, assert, serverManager, serviceManager, apisManager) + Autres: - road2.js - controller.js de l'api simple 1.0.0 diff --git a/test/integration/resources/topology/correctDBTopology.json b/test/integration/resources/topology/correctDBTopology.json deleted file mode 100644 index b3fdead5..00000000 --- a/test/integration/resources/topology/correctDBTopology.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "id": "base-bduni", - "type": "db", - "description": "Donn\u00e9es issues de la BDUNI de l'IGN.", - "storage": { - "base": { - "dbConfig": "/home/docker/data/output_base.json", - "schema": "public", - "attributes": [ - { - "key": "name", - "column": "way_names", - "default": "false" - }, - { - "key": "id", - "column": "id", - "default": "false" - } - ] - } - }, - "projection": "EPSG:4326", - "bbox": "1.7,48.4,3.3,49.1" -} \ No newline at end of file diff --git a/test/integration/resources/topology/correctOSMTopology.json b/test/integration/resources/topology/correctOSMTopology.json deleted file mode 100644 index 133bdfac..00000000 --- a/test/integration/resources/topology/correctOSMTopology.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "id": "corse-osm", - "type": "osm", - "description": "Données OSM sur la Corse.", - "storage": { - "file": "/home/docker/internal/corse-latest.osm.pbf" - }, - "projection": "EPSG:4326", - "bbox": "-180,-90,180,90" -} \ No newline at end of file diff --git a/test/integration/resources/topology/incorrectDBTopology.json b/test/integration/resources/topology/incorrectDBTopology.json deleted file mode 100644 index a62074b0..00000000 --- a/test/integration/resources/topology/incorrectDBTopology.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "type": "db", - "description": "Donn\u00e9es issues de la BDUNI de l'IGN.", - "storage": { - "base": { - "dbConfig": "/home/docker/data/output_base.json", - "schema": "public", - "attributes": [ - { - "key": "name", - "column": "way_names", - "default": "false" - }, - { - "key": "id", - "column": "id", - "default": "false" - } - ] - } - }, - "projection": "EPSG:4326", - "bbox": "1.7,48.4,3.3,49.1" -} \ No newline at end of file diff --git a/test/integration/resources/topology/incorrectOSMTopology.json b/test/integration/resources/topology/incorrectOSMTopology.json deleted file mode 100644 index 8597726e..00000000 --- a/test/integration/resources/topology/incorrectOSMTopology.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "type": "osm", - "description": "Données OSM sur la Corse.", - "storage": { - "file": "/home/docker/internal/corse-latest.osm.pbf" - }, - "projection": "EPSG:4326", - "bbox": "-180,-90,180,90" -} \ No newline at end of file diff --git a/test/unit/mocha/config/resources/corse.resource b/test/unit/mocha/config/resources/corse.resource deleted file mode 100644 index f6e6da5f..00000000 --- a/test/unit/mocha/config/resources/corse.resource +++ /dev/null @@ -1,130 +0,0 @@ -{ - "resource": { - "id": "corse-osm", - "type": "osrm", - "description": "Exemple d'une ressource sur la Corse avec les données OSM.", - "topology": { - "id": "corse-osm", - "type": "osm", - "description": "Données OSM sur la Corse.", - "storage": { - "file": "/home/docker/internal/corse-latest.osm.pbf" - }, - "projection": "EPSG:4326", - "bbox": "-180,-90,180,90" - }, - "sources": [ - { - "id": "corse-car-fastest", - "type": "osrm", - "storage": { - "file": "/home/docker/internal/corse-latest.osrm" - }, - "cost": { - "profile": "car", - "optimization": "fastest", - "compute": { - "storage": { - "file": "/usr/local/share/osrm/profiles/car.lua" - } - } - } - } - ], - "availableOperations":[ - { - "id": "route", - "parameters": [ - { - "id": "resource", - "values": [ - "corse-osm" - ] - }, - { - "id": "start", - "values": { - "bbox": "-180,-90,180,90", - "projection": "EPSG:4326" - } - }, - { - "id": "end", - "values": { - "bbox": "-180,-90,180,90", - "projection": "EPSG:4326" - } - }, - { - "id": "profile", - "defaultValueContent": "car", - "values": [ - "car" - ] - }, - { - "id": "optimization", - "defaultValueContent": "fastest", - "values": [ - "fastest" - ] - }, - { - "id": "intermediates", - "values": { - "bbox": "-180,-90,180,90", - "projection": "EPSG:4326" - } - }, - { - "id": "getSteps", - "defaultValueContent": "true" - }, - { - "id": "waysAttributes", - "values": [ - "name" - ] - }, - { - "id": "geometryFormat", - "defaultValueContent": "geojson", - "values": [ - "geojson", - "polyline" - ] - }, - { - "id": "bbox", - "defaultValueContent": "true" - }, - { - "id": "projection", - "defaultValueContent": "EPSG:4326", - "values": [ - "EPSG:4326", - "EPSG:2154" - ] - }, - { - "id": "timeUnit", - "defaultValueContent": "minute", - "values": [ - "hour", - "minute", - "second" - ] - }, - { - "id": "distanceUnit", - "defaultValueContent": "meter", - "values": [ - "meter", - "kilometer" - ] - } - ] - } - ] - } -} diff --git a/test/unit/mocha/requests/testsRequest.js b/test/unit/mocha/requests/testsRequest.js index c46f0bb0..60a7f48e 100644 --- a/test/unit/mocha/requests/testsRequest.js +++ b/test/unit/mocha/requests/testsRequest.js @@ -39,9 +39,10 @@ describe('Test de la classe Request', function() { assert.equal(request.resource, "corse-osm-2"); }); - it('Set Type', function() { + // Le type ne devrait pas changer car il dépend de la classe fille appelée + it('Set Type ne change rien', function() { request.type = "otherRequest"; - assert.equal(request.type, "otherRequest"); + assert.equal(request.type, "routeRequest"); }); }); diff --git a/test/unit/mocha/service/testsServiceAdministered.js b/test/unit/mocha/service/testsServiceAdministered.js new file mode 100644 index 00000000..2f79fb53 --- /dev/null +++ b/test/unit/mocha/service/testsServiceAdministered.js @@ -0,0 +1,26 @@ +const assert = require('assert'); +const ServiceAdministered = require('../../../../src/js/service/serviceAdministered'); +const logManager = require('../logManager'); + +describe('Test de la classe ServiceAdministered', function() { + + before(function() { + // runs before all tests in this block + logManager.manageLogs(); + }); + + describe('Test du constructeur et des getters', function() { + + let serviceAdm = new ServiceAdministered("test", "newProcess"); + + it('Get Id', function() { + assert.equal(serviceAdm.id, "test"); + }); + + it('Get Type', function() { + assert.equal(serviceAdm.type, "newProcess"); + }); + + }); + +}); diff --git a/test/unit/readme.md b/test/unit/readme.md index 9cd4908f..f8dc2702 100644 --- a/test/unit/readme.md +++ b/test/unit/readme.md @@ -9,7 +9,7 @@ docker-compose exec road2 npm run utest Mais cela devrait fonctionner uniquement avec `mocha`. Lancer la commande suivante depuis la racine du projet: ``` mocha --recursive './test/unit/mocha/**/*.js' -```  +``` Les tests unitaires concernent les classes qui ne dépendent pas d'une autre classe du projet pour fonctionner. Les autres classes sont testées dans les tests d'intégration [ici](./integration/readme.md). @@ -33,4 +33,5 @@ On trouvera donc les classes ou les fichiers suivants: - simplify.js //TODO - storageManager (log4js) - validationManager -- wkt \ No newline at end of file +- wkt +- serviceAdministered