Skip to content

Commit

Permalink
fix and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lgrd committed Feb 15, 2024
1 parent f249ca2 commit 34ebdbf
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 1,049 deletions.
2 changes: 1 addition & 1 deletion src/js/apis/admin/1.0.0/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const log4js = require('log4js');

var LOGGER = log4js.getLogger("INIT");
var LOGGER = log4js.getLogger("UPDATE");

module.exports = {

Expand Down
31 changes: 2 additions & 29 deletions src/js/apis/osrm/1.0.0/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,37 +25,10 @@ let swaggerDocument = require(apiJsonPath);
router.use('/openapi', swaggerUi.serve, swaggerUi.setup(swaggerDocument));

// GetCapabilities
router.all("/resources", function(req, res) {
router.all("/resources", function(req, res, next) {

LOGGER.debug("request on /osrm/1.0.0/resources?");

// get service
let service = req.app.get("service");

// get uid
let uid = service.apisManager.getApi("osrm","1.0.0").uid;
LOGGER.debug(uid);

// get getCapabilities from init.js
let getCapabilities = req.app.get(uid + "-getcap");
LOGGER.debug(getCapabilities);

// Change base url in GetCapabilties if "Host" or "X-Forwarded-Host" is specified in request's headers
// Host is stored by expres in req.hostname
if (req.hostname) {
let regexpHost = /^https?:\/\/[\w\d:-_.]*\//;
try {
getCapabilities.info.url = getCapabilities.info.url.replace(regexpHost, req.protocol + "://" + req.hostname + "/");
} catch(error) {
// apply default service url in GetCapabilities
}

} else {
// apply default service url in GetCapabilities
}

res.set('content-type', 'application/json');
res.status(200).json(getCapabilities);
return next(errorManager.createError("Not Implemented", 501));

});

Expand Down
995 changes: 1 addition & 994 deletions src/js/apis/osrm/1.0.0/init.js

Large diffs are not rendered by default.

24 changes: 1 addition & 23 deletions src/js/apis/osrm/1.0.0/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,10 @@

const log4js = require('log4js');

let LOGGER = log4js.getLogger("INIT");
let LOGGER = log4js.getLogger("UPDATE");

module.exports = {

/**
*
* @function
* @name updateGetCapabilities
* @description Fonction utilisée pour mettre à jour le GetCapabilities
* @param {object} app - App ExpressJS
* @return {boolean} True si tout s'est bien passé et False sinon
*
*/

updateGetCapabilities: function(app) {

return true;

},

/**
*
* @function
Expand All @@ -35,12 +19,6 @@ module.exports = {

run: function(app, uid) {

// Création du GetCapabilities
if (!this.updateGetCapabilities(app)) {
LOGGER.error("Erreur lors de la creation du GetCapabilities.");
return false;
}

return true;

}
Expand Down
2 changes: 1 addition & 1 deletion src/js/apis/simple/1.0.0/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const log4js = require('log4js');

var LOGGER = log4js.getLogger("INIT");
var LOGGER = log4js.getLogger("UPDATE");

module.exports = {

Expand Down
3 changes: 2 additions & 1 deletion src/js/sources/osrmSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,8 @@ module.exports = class osrmSource extends Source {
// ---

// Récupération des paramètres de la réponse OSRM pour une éventuelle réponse avec son API native
engineExtras.code = osrmResponse.code;
// Si on est ici, pour le moment, c'est que c'est Ok, sinon une erreur aura déjà été renvoyée
engineExtras.code = "Ok";

// ---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
"nearest": "/simple/1.0.0/nearest",
"getcapabilities": "/simple/1.0.0/getcapabilities"
}
},
"osrm": {
"1.0.0": {
"<resource>/<profile>/<optimization>/route/v1/_/<coordinates>": "/osrm/1.0.0/<resource>/<profile>/<optimization>/route/v1/_/<coordinates>"
}
}
},
"defaultParameters": [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
Feature: Road2-osrm-1.0.0-common
Tests fonctionnels de Road2 via l'API osrm/1.0.0

Background:
Given I have loaded all my test configuration in "../../configurations/local-service.json"

Scenario: Route principale de l'API osrm/1.0.0
Given an "GET" request on "/osrm/1.0.0"
When I send the request
Then the server should send a response with status 200
And the response should contain "Road2 via OSRM API 1.0.0"

Scenario: GetCapabilities de l'API osrm/1.0.0
Given an "GET" request on "/osrm/1.0.0/resources"
When I send the request
Then the server should send a response with status 501
And the response should contain "Not Implemented"

Scenario: Requête sur une route inexistante
Given an "GET" request on "/osrm/1.0.0/test"
When I send the request
Then the server should send a response with status 404
And the response should contain "Not found"

Scenario: [route] Route sur l'API osrm 1.0.0 avec mauvaise resource
Given an "GET" request on operation "<resource>/<profile>/<optimization>/route/v1/_/<coordinates>" in api "osrm" "1.0.0"
And with path parameters:
| key | value |
| resource | test |
| profile | car |
| optimization | fastest |
| coordinates | 2.333865,48.881989;2.344851,48.872393 |
When I send the request
Then the server should send a response with status 400
And the response should have an header "content-type" with value "application/json"
And the response should contain "Parameter 'resourceId' is invalid: it does not exist on this service"

Scenario: [route] Route sur l'API osrm 1.0.0 avec mauvais profile
Given an "GET" request on operation "<resource>/<profile>/<optimization>/route/v1/_/<coordinates>" in api "osrm" "1.0.0"
And with path parameters:
| key | value |
| resource | bduni-idf-osrm |
| profile | test |
| optimization | fastest |
| coordinates | 2.333865,48.881989;2.344851,48.872393 |
When I send the request
Then the server should send a response with status 400
And the response should have an header "content-type" with value "application/json"
And the response should contain "Parameter 'profileId' is invalid"

Scenario: [route] Route sur l'API osrm 1.0.0 avec mauvaise optimisation
Given an "GET" request on operation "<resource>/<profile>/<optimization>/route/v1/_/<coordinates>" in api "osrm" "1.0.0"
And with path parameters:
| key | value |
| resource | bduni-idf-osrm |
| profile | car |
| optimization | test |
| coordinates | 2.333865,48.881989;2.344851,48.872393 |
When I send the request
Then the server should send a response with status 400
And the response should have an header "content-type" with value "application/json"
And the response should contain "Parameter 'optimizationId' is invalid"

Scenario: [route] Route sur l'API osrm 1.0.0 avec mauvaises coordonnées
Given an "GET" request on operation "<resource>/<profile>/<optimization>/route/v1/_/<coordinates>" in api "osrm" "1.0.0"
And with path parameters:
| key | value |
| resource | bduni-idf-osrm |
| profile | car |
| optimization | fastest |
| coordinates | 2.333865,48.881989;2.344851, |
When I send the request
Then the server should send a response with status 400
And the response should have an header "content-type" with value "application/json"
And the response should contain "Parameter 'coordinates' is invalid"



Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Feature: Road2-osrm-1.0.0-osrm
Tests fonctionnels de Road2 via l'API osrm/1.0.0 avec le moteur OSRM

Background:
Given I have loaded all my test configuration in "../../configurations/local-service.json"


Scenario: Route sur l'API osrm 1.0.0
Given an "GET" request on operation "<resource>/<profile>/<optimization>/route/v1/_/<coordinates>" in api "osrm" "1.0.0"
And with path parameters:
| key | value |
| resource | bduni-idf-osrm |
| profile | car |
| optimization | fastest |
| coordinates | 2.333865,48.881989;2.344851,48.872393 |
When I send the request
Then the server should send a response with status 200
And the response should have an header "content-type" with value "application/json"
And the response should contain an attribute "code" with value "Ok"
And the response should contain an attribute "waypoints"
And the response should contain an attribute "routes"

0 comments on commit 34ebdbf

Please sign in to comment.