Skip to content

Commit

Permalink
Add freehand route segments to a route request
Browse files Browse the repository at this point in the history
Feature #167 freehand route
  • Loading branch information
Adam Rousell authored Feb 25, 2019
2 parents dcebba7 + 3e90ed5 commit 8b55d64
Show file tree
Hide file tree
Showing 16 changed files with 1,032 additions and 234 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
## [Unreleased]
### Added
- Added support for ISO 3166-1 Alpha-2 / Alpha-3 codes for routing directions option avoid_countries (Issue #195)
- Added support for free hand route option/ skip segments (Issue #167)
### Fixed
- Fixed `geometry_simplify` parameter, which had no effect before. `geometry_simplify` is incompatible with `extra_info` (#381)
### Changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.*;
Expand Down Expand Up @@ -1103,9 +1104,31 @@ public void expectWarningsAndExtraInfo() {
.assertThat()
.body("any { it.key == 'routes' }", is(true))
.body("routes[0].containsKey('warnings')", is(true))
.body("routes[0].warnings[0].containsKey('code')", is(true))
.body("routes[0].warnings[0].containsKey('message')", is(true))
.body("routes[0].containsKey('extras')", is(true))
.body("routes[0].extras.containsKey('roadaccessrestrictions')", is(true))
.statusCode(200);

given()
.header("Accept", "application/geo+json")
.header("Content-Type", "application/json")
.pathParam("profile", getParameter("carProfile"))
.body(body.toString())
.when()
.post(getEndPointPath() + "/{profile}/geojson")
.then().log().all()
.assertThat()
.body("any { it.key == 'features' }", is(true))
.body("any { it.key == 'bbox' }", is(true))
.body("any { it.key == 'type' }", is(true))
.body("features[0].containsKey('properties')", is(true))
.body("features[0].properties.containsKey('extras')", is(true))
.body("features[0].properties.containsKey('warnings')", is(true))
.body("features[0].properties.warnings[0].containsKey('code')", is(true))
.body("features[0].properties.warnings[0].containsKey('message')", is(true))
.body("features[0].properties.extras.containsKey('roadaccessrestrictions')", is(true))
.statusCode(200);
}

@Test
Expand Down Expand Up @@ -1158,4 +1181,161 @@ public void expectSimplifyIncompatibleWithExtraInfo() {
.body("error.code", is(RoutingErrorCodes.INCOMPATIBLE_PARAMETERS))
.statusCode(400);
}

@Test
public void expectSkipSegmentsErrors() {
List<Integer> skipSegmentsEmpty = new ArrayList<>(1);
List<Integer> skipSegmentsTooHigh = new ArrayList<>(1);
List<Integer> skipSegmentsTooSmall = new ArrayList<>(1);
List<Integer> skipSegmentsTooMany = new ArrayList<>(3);
skipSegmentsEmpty.add(0, 0);
skipSegmentsTooHigh.add(0, 99);
skipSegmentsTooSmall.add(0, -99);
skipSegmentsTooMany.add(0, 1);
skipSegmentsTooMany.add(1, 1);
skipSegmentsTooMany.add(2, 1);

JSONObject body = new JSONObject();
body.put("coordinates", getParameter("coordinatesShort"));

body.put("skip_segments", skipSegmentsEmpty);
given()
.header("Accept", "application/geo+json")
.header("Content-Type", "application/json")
.pathParam("profile", getParameter("carProfile"))
.body(body.toString())
.when()
.post(getEndPointPath() + "/{profile}/geojson")
.then().log().all()
.assertThat()
.body("error.code", is(RoutingErrorCodes.INVALID_PARAMETER_VALUE))
.statusCode(400);
given()
.header("Accept", "application/json")
.header("Content-Type", "application/json")
.pathParam("profile", getParameter("carProfile"))
.body(body.toString())
.when()
.post(getEndPointPath() + "/{profile}/json")
.then().log().all()
.assertThat()
.body("error.code", is(RoutingErrorCodes.INVALID_PARAMETER_VALUE))
.statusCode(400);

body.put("skip_segments", skipSegmentsTooHigh);
given()
.header("Accept", "application/geo+json")
.header("Content-Type", "application/json")
.pathParam("profile", getParameter("carProfile"))
.body(body.toString())
.when()
.post(getEndPointPath() + "/{profile}/geojson")
.then().log().all()
.assertThat()
.body("error.code", is(RoutingErrorCodes.INVALID_PARAMETER_VALUE))
.statusCode(400);
given()
.header("Accept", "application/json")
.header("Content-Type", "application/json")
.pathParam("profile", getParameter("carProfile"))
.body(body.toString())
.when()
.post(getEndPointPath() + "/{profile}/json")
.then().log().all()
.assertThat()
.body("error.code", is(RoutingErrorCodes.INVALID_PARAMETER_VALUE))
.statusCode(400);

body.put("skip_segments", skipSegmentsTooSmall);
given()
.header("Accept", "application/geo+json")
.header("Content-Type", "application/json")
.pathParam("profile", getParameter("carProfile"))
.body(body.toString())
.when()
.post(getEndPointPath() + "/{profile}/geojson")
.then().log().all()
.assertThat()
.body("error.code", is(RoutingErrorCodes.INVALID_PARAMETER_VALUE))
.statusCode(400);
given()
.header("Accept", "application/json")
.header("Content-Type", "application/json")
.pathParam("profile", getParameter("carProfile"))
.body(body.toString())
.when()
.post(getEndPointPath() + "/{profile}/json")
.then().log().all()
.assertThat()
.body("error.code", is(RoutingErrorCodes.INVALID_PARAMETER_VALUE))
.statusCode(400);

body.put("skip_segments", skipSegmentsTooMany);
given()
.header("Accept", "application/geo+json")
.header("Content-Type", "application/json")
.pathParam("profile", getParameter("carProfile"))
.body(body.toString())
.when()
.post(getEndPointPath() + "/{profile}/geojson")
.then().log().all()
.assertThat()
.body("error.code", is(RoutingErrorCodes.INVALID_PARAMETER_VALUE))
.statusCode(400);
given()
.header("Accept", "application/json")
.header("Content-Type", "application/json")
.pathParam("profile", getParameter("carProfile"))
.body(body.toString())
.when()
.post(getEndPointPath() + "/{profile}/json")
.then().log().all()
.assertThat()
.body("error.code", is(RoutingErrorCodes.INVALID_PARAMETER_VALUE))
.statusCode(400);
}

@Test
public void expectSkipSegmentsWarnings() {
List<Integer> skipSegments = new ArrayList<>(1);
skipSegments.add(1);

JSONObject body = new JSONObject();
body.put("coordinates", getParameter("coordinatesShort"));


body.put("skip_segments", skipSegments);
given()
.header("Accept", "application/json")
.header("Content-Type", "application/json")
.pathParam("profile", getParameter("carProfile"))
.body(body.toString())
.when().log().all()
.post(getEndPointPath() + "/{profile}/json")
.then().log().all()
.assertThat()
.body("any { it.key == 'routes' }", is(true))
.body("routes[0].containsKey('warnings')", is(true))
.body("routes[0].warnings[0].containsKey('code')", is(true))
.body("routes[0].warnings[0].containsKey('message')", is(true))
.statusCode(200);

given()
.header("Accept", "application/geo+json")
.header("Content-Type", "application/json")
.pathParam("profile", getParameter("carProfile"))
.body(body.toString())
.when()
.post(getEndPointPath() + "/{profile}/geojson")
.then().log().all()
.assertThat()
.body("any { it.key == 'features' }", is(true))
.body("any { it.key == 'bbox' }", is(true))
.body("any { it.key == 'type' }", is(true))
.body("features[0].containsKey('properties')", is(true))
.body("features[0].properties.containsKey('warnings')", is(true))
.body("features[0].properties.warnings[0].containsKey('code')", is(true))
.body("features[0].properties.warnings[0].containsKey('message')", is(true))
.statusCode(200);
}
}
Loading

0 comments on commit 8b55d64

Please sign in to comment.