Skip to content

Commit cedfcea

Browse files
koebiTheGreatRefrigerator
authored andcommitted
add tests for road speed, speed unit and skeleton for surface speed
1 parent 70cc004 commit cedfcea

File tree

1 file changed

+93
-8
lines changed
  • openrouteservice-api-tests/src/test/java/org/heigit/ors/v2/services/routing

1 file changed

+93
-8
lines changed

openrouteservice-api-tests/src/test/java/org/heigit/ors/v2/services/routing/ResultTest.java

Lines changed: 93 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3715,11 +3715,11 @@ public void testUserRoadSpeed() {
37153715
JSONObject body = new JSONObject();
37163716
JSONArray coords = new JSONArray();
37173717
JSONArray neuenheim = new JSONArray();
3718-
neuenheim.put(8.684435);
3719-
neuenheim.put(49.417367);
3718+
neuenheim.put(8.685036);
3719+
neuenheim.put(49.4201314);
37203720
JSONArray dossenheim = new JSONArray();
3721-
dossenheim.put(8.664275);
3722-
dossenheim.put(49.453557);
3721+
dossenheim.put(8.668814);
3722+
dossenheim.put(49.442794);
37233723
coords.put(neuenheim);
37243724
coords.put(dossenheim);
37253725
body.put("coordinates", coords);
@@ -3739,8 +3739,8 @@ public void testUserRoadSpeed() {
37393739
.then().log().ifValidationFails()
37403740
.assertThat()
37413741
.body("any { it.key == 'routes' }", is(true))
3742-
.body("routes[0].summary.distance", is(5492.7f))
3743-
.body("routes[0].summary.duration", is(5492.7f))
3742+
.body("routes[0].summary.distance", is(4507.5f))
3743+
.body("routes[0].summary.duration", is(469.1f))
37443744
.statusCode(200);
37453745

37463746
JSONObject userSpeedLimits = new JSONObject();
@@ -3761,19 +3761,104 @@ public void testUserRoadSpeed() {
37613761
.then().log().ifValidationFails()
37623762
.assertThat()
37633763
.body("any { it.key == 'routes' }", is(true))
3764-
.body("routes[0].summary.distance", is(6010.3f))
3765-
.body("routes[0].summary.duration", is(6010.3f))
3764+
.body("routes[0].summary.distance", is(3811.0f))
3765+
.body("routes[0].summary.duration", is(554.3f))
37663766
.statusCode(200);
37673767
}
37683768

37693769
@Test
37703770
public void testUserSurfaceSpeed() {
3771+
JSONObject body = new JSONObject();
3772+
JSONArray coords = new JSONArray();
3773+
JSONArray neuenheim = new JSONArray();
3774+
neuenheim.put(8.685036);
3775+
neuenheim.put(49.4201314);
3776+
JSONArray dossenheim = new JSONArray();
3777+
dossenheim.put(8.668814);
3778+
dossenheim.put(49.442794);
3779+
coords.put(neuenheim);
3780+
coords.put(dossenheim);
3781+
body.put("coordinates", coords);
3782+
3783+
// since we're testing on the same profile, "shortest" would not be dependent on speed settings
3784+
// and "recommended" will make too many assumptions on what route could be preferred.
3785+
body.put("preference", "fastest");
3786+
3787+
// request route without specifying user Speed
3788+
given()
3789+
.header("Accept", "application/json")
3790+
.header("Content-Type", "application/json")
3791+
.pathParam("profile", getParameter("carProfile"))
3792+
.body(body.toString())
3793+
.when().log().ifValidationFails()
3794+
.post(getEndPointPath() + "/{profile}")
3795+
.then().log().ifValidationFails()
3796+
.assertThat()
3797+
.body("any { it.key == 'routes' }", is(true))
3798+
.body("routes[0].summary.distance", is(4507.5f))
3799+
.body("routes[0].summary.duration", is(469.1f))
3800+
.statusCode(200);
3801+
3802+
JSONObject userSpeedLimits = new JSONObject();
3803+
JSONObject roadSpeedLimits = new JSONObject();
3804+
roadSpeedLimits.put("primary", 30);
3805+
roadSpeedLimits.put("secondary", 30);
3806+
userSpeedLimits.put("roadSpeeds", roadSpeedLimits);
3807+
body.put("user_speed_limits", userSpeedLimits);
3808+
3809+
// request route limiting speed on primary and secondary roads to 30
3810+
given()
3811+
.header("Accept", "application/json")
3812+
.header("Content-Type", "application/json")
3813+
.pathParam("profile", getParameter("carProfile"))
3814+
.body(body.toString())
3815+
.when().log().ifValidationFails()
3816+
.post(getEndPointPath() + "/{profile}")
3817+
.then().log().ifValidationFails()
3818+
.assertThat()
3819+
.body("any { it.key == 'routes' }", is(true))
3820+
.body("routes[0].summary.distance", is(3811.0f))
3821+
.body("routes[0].summary.duration", is(554.3f))
3822+
.statusCode(200);
37713823

37723824
}
37733825

37743826
@Test
37753827
public void testUserSpeedUnit() {
3828+
JSONObject body = new JSONObject();
3829+
JSONArray coords = new JSONArray();
3830+
JSONArray neuenheim = new JSONArray();
3831+
neuenheim.put(8.685036);
3832+
neuenheim.put(49.4201314);
3833+
JSONArray dossenheim = new JSONArray();
3834+
dossenheim.put(8.668814);
3835+
dossenheim.put(49.442794);
3836+
coords.put(neuenheim);
3837+
coords.put(dossenheim);
3838+
body.put("coordinates", coords);
37763839

3840+
// this is the same query as testUserRoadSpeed uses, but has speeds in mph
3841+
JSONObject userSpeedLimits = new JSONObject();
3842+
JSONObject roadSpeedLimits = new JSONObject();
3843+
roadSpeedLimits.put("primary", 18.6412f);
3844+
roadSpeedLimits.put("secondary", 18.6412f);
3845+
userSpeedLimits.put("roadSpeeds", roadSpeedLimits);
3846+
userSpeedLimits.put("unit", "mph");
3847+
body.put("user_speed_limits", userSpeedLimits);
3848+
3849+
given()
3850+
.header("Accept", "application/json")
3851+
.header("Content-Type", "application/json")
3852+
.pathParam("profile", getParameter("carProfile"))
3853+
.body(body.toString())
3854+
.when().log().ifValidationFails()
3855+
.post(getEndPointPath() + "/{profile}")
3856+
.then().log().ifValidationFails()
3857+
.assertThat()
3858+
.body("any { it.key == 'routes' }", is(true))
3859+
.body("routes[0].summary.distance", is(3811.0f))
3860+
.body("routes[0].summary.duration", is(554.3f))
3861+
.statusCode(200);
37773862
}
37783863

37793864
private JSONArray constructBearings(String coordString) {

0 commit comments

Comments
 (0)