Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust maxspeed annotation #777

Merged
merged 2 commits into from
Mar 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ directions-fixtures:
curl "https://api.mapbox.com/directions/v5/mapbox/driving/-122.03067988107114,37.331808179989494;-122.03178702099605,37.3302383113533?voice_units=imperial&roundabout_exits=true&geometries=polyline&overview=full&steps=true&voice_instructions=true&banner_instructions=true&access_token=$(MAPBOX_ACCESS_TOKEN)" \
-o services-directions/src/test/resources/directions_v5_banner_text.json

# Directions: route with maxspeed
curl "https://api.mapbox.com/directions/v5/mapbox/driving-traffic/9.950072,52.150015;7.569915,52.916751?alternatives=true&geometries=polyline6&overview=full&steps=true&bearings=%3B&continue_straight=true&annotations=maxspeed&language=en&access_token=$(MAPBOX_ACCESS_TOKEN)" \
-o services-directions/src/test/resources/directions_v5_max_speed_annotation.json

mapmatching-fixtures:
curl "https://api.mapbox.com/matching/v5/mapbox/driving/$(MAP_MATCHING_COORDINATES)?geometries=polyline&language=sv&steps=true&access_token=$(MAPBOX_ACCESS_TOKEN)" \
-o services-matching/src/test/resources/map_matching_v5_polyline.json
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public static Builder builder() {
* @since 3.0.0
*/
@Nullable
public abstract List<MaxSpeed> maxSpeed();
public abstract List<MaxSpeed> maxspeed();

/**
* The congestion between each pair of coordinates.
Expand Down Expand Up @@ -134,11 +134,11 @@ public abstract static class Builder {
* Maxspeed is only available for the `mapbox/driving` and `mapbox/driving-traffic`
* profiles, other profiles will return `unknown`s only.
*
* @param maxSpeed list of speeds between each pair of coordinates
* @param maxspeed list of speeds between each pair of coordinates
* @return this builder for chaining options together
* @since 3.0.0
*/
public abstract Builder maxSpeed(@Nullable List<MaxSpeed> maxSpeed);
public abstract Builder maxspeed(@Nullable List<MaxSpeed> maxspeed);

/**
* The congestion between each pair of coordinates.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,37 @@
package com.mapbox.api.directions.v5;

import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.junit.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.mapbox.api.directions.v5.models.DirectionsResponse;
import com.mapbox.api.directions.v5.models.DirectionsRoute;
import com.mapbox.api.directions.v5.models.LegAnnotation;
import com.mapbox.core.TestUtils;
import com.mapbox.core.exceptions.ServicesException;
import com.mapbox.geojson.Point;
import okhttp3.HttpUrl;
import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.MockWebServer;
import okhttp3.mockwebserver.RecordedRequest;

import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import retrofit2.Response;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

import javax.swing.plaf.basic.BasicInternalFrameTitlePane;
import okhttp3.HttpUrl;
import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.MockWebServer;
import okhttp3.mockwebserver.RecordedRequest;
import retrofit2.Response;

import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.junit.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

public class MapboxDirectionsTest extends TestUtils {

Expand All @@ -36,6 +41,7 @@ public class MapboxDirectionsTest extends TestUtils {
private static final String DIRECTIONS_ROTARY_FIXTURE = "directions_v5_fixtures_rotary.json";
private static final String DIRECTIONS_V5_ANNOTATIONS_FIXTURE = "directions_annotations_v5.json";
private static final String DIRECTIONS_V5_NO_ROUTE = "directions_v5_no_route.json";
private static final String DIRECTIONS_V5_MAX_SPEED_ANNOTATION = "directions_v5_max_speed_annotation.json";

private MockWebServer server;
private HttpUrl mockUrl;
Expand Down Expand Up @@ -468,4 +474,31 @@ public void setCoordinates_localeShouldNotMatter() {
assertThat(directions.cloneCall().request().url().toString(),
containsString("1.234,2.345;13.493,9.958;5.29838,4.42189"));
}

@Test
public void maxSpeedAnnotation_doesGetFormattedInUrlCorrectly() {
Locale.setDefault(Locale.GERMANY);
MapboxDirections directions = MapboxDirections.builder()
.accessToken(ACCESS_TOKEN)
.origin(Point.fromLngLat(1.234,2.345))
.addWaypoint(Point.fromLngLat(13.493,9.958))
.destination(Point.fromLngLat(5.29838,4.42189))
.annotations(DirectionsCriteria.ANNOTATION_MAXSPEED)
.build();

assertThat(directions.cloneCall().request().url().toString(),
containsString("annotations=maxspeed"));
}

@Test
public void maxSpeedAnnotation_doesGetCreatedInResponse() throws IOException {
Gson gson = new GsonBuilder()
.registerTypeAdapterFactory(DirectionsAdapterFactory.create()).create();
String body = loadJsonFixture(DIRECTIONS_V5_MAX_SPEED_ANNOTATION);
DirectionsResponse response = gson.fromJson(body, DirectionsResponse.class);
DirectionsRoute maxSpeedRoute = response.routes().get(0);
LegAnnotation maxSpeedAnnotation = maxSpeedRoute.legs().get(0).annotation();

assertNotNull(maxSpeedAnnotation.maxspeed());
}
}

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion services-directions/src/test/resources/directions_v5.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"routes":[{"geometry":"yjzbFfcygVV?vA?P@NAzAa@VGX`BRbAF\\@`@?P","legs":[{"summary":"Infinite Loop, Mariani Avenue","weight":74.9,"duration":64.1,"steps":[{"intersections":[{"out":0,"entry":[true],"bearings":[180],"location":[-122.03076,37.331808]},{"out":1,"in":0,"entry":[false,true,true],"bearings":[0,180,270],"location":[-122.03076,37.331686]},{"out":1,"in":0,"entry":[false,true,true],"bearings":[0,165,270],"location":[-122.030765,37.331157]}],"driving_side":"right","geometry":"yjzbFfcygVV?vA?P@NAzAa@VG","mode":"driving","maneuver":{"bearing_after":180,"bearing_before":0,"location":[-122.03076,37.331808],"modifier":"left","type":"depart","instruction":"Head south on Infinite Loop"},"weight":50,"duration":39.3,"name":"Infinite Loop","distance":148,"voiceInstructions":[{"distanceAlongGeometry":148,"announcement":"Head south on Infinite Loop, then turn right onto Mariani Avenue","ssmlAnnouncement":"<speak><amazon:effect name=\"drc\"><prosody rate=\"1.08\">Head south on Infinite Loop, then turn right onto Mariani Avenue</prosody></amazon:effect></speak>"},{"distanceAlongGeometry":56.5,"announcement":"Turn right onto Mariani Avenue, then you will arrive at your destination","ssmlAnnouncement":"<speak><amazon:effect name=\"drc\"><prosody rate=\"1.08\">Turn right onto Mariani Avenue, then you will arrive at your destination</prosody></amazon:effect></speak>"}],"bannerInstructions":[{"distanceAlongGeometry":148,"primary":{"type":"turn","modifier":"right","components":[{"text":"Mariani Avenue","type":"text","abbr":"Mariani Ave","abbr_priority":0}],"text":"Mariani Avenue"},"secondary":null}]},{"intersections":[{"out":1,"in":2,"entry":[true,true,false],"bearings":[90,255,345],"location":[-122.03055,37.3305]}],"driving_side":"right","geometry":"sbzbF|aygVX`BRbAF\\@`@?P","mode":"driving","maneuver":{"bearing_after":250,"bearing_before":163,"location":[-122.03055,37.3305],"modifier":"right","type":"end of road","instruction":"Turn right onto Mariani Avenue"},"weight":24.9,"duration":24.8,"name":"Mariani Avenue","distance":114.5,"voiceInstructions":[{"distanceAlongGeometry":13.9,"announcement":"You have arrived at your destination","ssmlAnnouncement":"<speak><amazon:effect name=\"drc\"><prosody rate=\"1.08\">You have arrived at your destination</prosody></amazon:effect></speak>"}],"bannerInstructions":[{"distanceAlongGeometry":114.5,"primary":{"type":"arrive","modifier":"straight","components":[{"text":"You will arrive","type":"text"}],"text":"You will arrive"},"secondary":{"type":"arrive","modifier":"straight","components":[{"text":"Mariani Avenue","type":"text","abbr":"Mariani Ave","abbr_priority":0}],"text":"Mariani Avenue"}},{"distanceAlongGeometry":15,"primary":{"type":"arrive","modifier":"straight","components":[{"text":"You have arrived","type":"text"}],"text":"You have arrived"},"secondary":{"type":"arrive","modifier":"straight","components":[{"text":"Mariani Avenue","type":"text","abbr":"Mariani Ave","abbr_priority":0}],"text":"Mariani Avenue"}}]},{"intersections":[{"in":0,"entry":[true],"bearings":[90],"location":[-122.031787,37.330217]}],"driving_side":"right","geometry":"{`zbFtiygV","mode":"driving","maneuver":{"bearing_after":0,"bearing_before":270,"location":[-122.031787,37.330217],"type":"arrive","instruction":"You have arrived at your destination"},"weight":0,"duration":0,"name":"Mariani Avenue","distance":0,"voiceInstructions":[],"bannerInstructions":[]}],"distance":262.5}],"weight_name":"routability","weight":74.9,"duration":64.1,"distance":262.5,"voiceLocale":"en-US"}],"waypoints":[{"name":"Infinite Loop","location":[-122.03076,37.331808]},{"name":"Mariani Avenue","location":[-122.031787,37.330217]}],"code":"Ok","uuid":"cjeahg7sj3of747lgc2f0p3pp"}
{"routes":[{"geometry":"yjzbFfcygVV?vA?P@NAzAa@VGX`BRbAF\\@`@?P","legs":[{"summary":"Infinite Loop, Mariani Avenue","weight":77.2,"duration":66.4,"steps":[{"intersections":[{"out":0,"entry":[true],"bearings":[180],"location":[-122.03076,37.331808]},{"out":1,"in":0,"entry":[false,true,true],"bearings":[0,180,270],"location":[-122.03076,37.331686]},{"out":1,"in":0,"entry":[false,true,true],"bearings":[0,165,270],"location":[-122.030765,37.331157]}],"driving_side":"right","geometry":"yjzbFfcygVV?vA?P@NAzAa@VG","mode":"driving","maneuver":{"bearing_after":180,"bearing_before":0,"location":[-122.03076,37.331808],"modifier":"left","type":"depart","instruction":"Head south on Infinite Loop"},"weight":52.8,"duration":42.1,"name":"Infinite Loop","distance":148,"voiceInstructions":[{"distanceAlongGeometry":148,"announcement":"Head south on Infinite Loop, then turn right onto Mariani Avenue","ssmlAnnouncement":"<speak><amazon:effect name=\"drc\"><prosody rate=\"1.08\">Head south on Infinite Loop, then turn right onto Mariani Avenue</prosody></amazon:effect></speak>"},{"distanceAlongGeometry":52.7,"announcement":"Turn right onto Mariani Avenue, then you will arrive at your destination","ssmlAnnouncement":"<speak><amazon:effect name=\"drc\"><prosody rate=\"1.08\">Turn right onto Mariani Avenue, then you will arrive at your destination</prosody></amazon:effect></speak>"}],"bannerInstructions":[{"distanceAlongGeometry":148,"primary":{"type":"turn","modifier":"right","components":[{"text":"Mariani Avenue","type":"text","abbr":"Mariani Ave","abbr_priority":0}],"text":"Mariani Avenue"},"secondary":null}]},{"intersections":[{"out":1,"in":2,"entry":[true,true,false],"bearings":[90,255,345],"location":[-122.03055,37.3305]}],"driving_side":"right","geometry":"sbzbF|aygVX`BRbAF\\@`@?P","mode":"driving","maneuver":{"bearing_after":250,"bearing_before":163,"location":[-122.03055,37.3305],"modifier":"right","type":"end of road","instruction":"Turn right onto Mariani Avenue"},"weight":24.4,"duration":24.3,"name":"Mariani Avenue","distance":114.5,"voiceInstructions":[{"distanceAlongGeometry":14.1,"announcement":"You have arrived at your destination","ssmlAnnouncement":"<speak><amazon:effect name=\"drc\"><prosody rate=\"1.08\">You have arrived at your destination</prosody></amazon:effect></speak>"}],"bannerInstructions":[{"distanceAlongGeometry":114.5,"primary":{"type":"arrive","modifier":"straight","components":[{"text":"You will arrive","type":"text"}],"text":"You will arrive"},"secondary":{"type":"arrive","modifier":"straight","components":[{"text":"Mariani Avenue","type":"text","abbr":"Mariani Ave","abbr_priority":0}],"text":"Mariani Avenue"}},{"distanceAlongGeometry":15,"primary":{"type":"arrive","modifier":"straight","components":[{"text":"You have arrived","type":"text"}],"text":"You have arrived"},"secondary":{"type":"arrive","modifier":"straight","components":[{"text":"Mariani Avenue","type":"text","abbr":"Mariani Ave","abbr_priority":0}],"text":"Mariani Avenue"}}]},{"intersections":[{"in":0,"entry":[true],"bearings":[90],"location":[-122.031787,37.330217]}],"driving_side":"right","geometry":"{`zbFtiygV","mode":"driving","maneuver":{"bearing_after":0,"bearing_before":270,"location":[-122.031787,37.330217],"type":"arrive","instruction":"You have arrived at your destination"},"weight":0,"duration":0,"name":"Mariani Avenue","distance":0,"voiceInstructions":[],"bannerInstructions":[]}],"distance":262.5}],"weight_name":"routability","weight":77.2,"duration":66.4,"distance":262.5,"voiceLocale":"en-US"}],"waypoints":[{"name":"Infinite Loop","location":[-122.03076,37.331808]},{"name":"Mariani Avenue","location":[-122.031787,37.330217]}],"code":"Ok","uuid":"cjfe60xo206wx42pbqmyydvfy"}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"routes":[{"geometry":"ejnlFdvfuMeAeAIg@FgAGw@]{@YU]OU]G[?yA","legs":[{"summary":"Dupont Circle NW, P Street Northwest","weight":107.4,"duration":93.3,"steps":[{"intersections":[{"out":0,"entry":[true],"bearings":[36],"location":[-77.044347,38.908673]},{"out":1,"in":2,"entry":[false,true,false],"bearings":[15,60,210],"location":[-77.044059,38.908982]}],"driving_side":"right","geometry":"ejnlFdvfuM}@y@GKEOCK?KAG","mode":"driving","maneuver":{"bearing_after":36,"bearing_before":0,"location":[-77.044347,38.908673],"type":"depart","instruction":"Head northeast on New Hampshire Avenue Northwest"},"weight":22.9,"duration":18.9,"name":"New Hampshire Avenue Northwest","distance":71.5},{"intersections":[{"out":0,"in":1,"entry":[true,false,false],"bearings":[105,270,300],"location":[-77.043755,38.909076]},{"out":0,"in":3,"entry":[true,true,true,false],"bearings":[105,120,135,285],"location":[-77.043591,38.909037]},{"out":0,"in":2,"entry":[true,false,false],"bearings":[45,195,225],"location":[-77.042939,38.909165]},{"out":0,"in":2,"entry":[true,true,false,false],"bearings":[30,75,210,255],"location":[-77.042775,38.909307]},{"out":1,"in":3,"entry":[true,true,false,false,true],"bearings":[15,45,135,195,345],"location":[-77.042669,38.909502]},{"out":0,"in":1,"entry":[true,false,false],"bearings":[90,255,300],"location":[-77.042382,38.909646]}],"driving_side":"right","geometry":"wlnlFnrfuMBK@I@K@I?I?I?I?GAI?ICIAGAICICGCGEGAECCCECCCCECCCGEGEGCECGAKKEGCICICQ?yA","mode":"driving","maneuver":{"exit":3,"bearing_after":111,"bearing_before":84,"location":[-77.043755,38.909076],"modifier":"slight right","type":"roundabout","instruction":"Enter the traffic circle and take the 3rd exit onto P Street Northwest"},"weight":84.5,"duration":74.4,"name":"P Street Northwest","distance":189.9},{"intersections":[{"in":0,"entry":[true],"bearings":[270],"location":[-77.041926,38.909646]}],"driving_side":"right","geometry":"ipnlF`gfuM","mode":"driving","maneuver":{"bearing_after":0,"bearing_before":90,"location":[-77.041926,38.909646],"type":"arrive","instruction":"You have arrived at your destination"},"weight":0,"duration":0,"name":"P Street Northwest","distance":0}],"distance":261.4}],"weight_name":"routability","weight":107.4,"duration":93.3,"distance":261.4}],"waypoints":[{"name":"New Hampshire Avenue Northwest","location":[-77.044347,38.908673]},{"name":"P Street Northwest","location":[-77.041926,38.909646]}],"code":"Ok","uuid":"cjatu1k2o05ph5bp8eg0qhaoy"}
{"routes":[{"geometry":"ejnlFdvfuMeAeAIg@FgAGw@]{@YU]OU]G[?yA","legs":[{"summary":"New Hampshire Avenue Northwest, Dupont Circle NW","weight":129.6,"duration":104.4,"steps":[{"intersections":[{"out":0,"entry":[true],"bearings":[36],"location":[-77.044347,38.908673]},{"out":1,"in":2,"entry":[false,true,false],"bearings":[15,60,210],"location":[-77.044059,38.908982]}],"driving_side":"right","geometry":"ejnlFdvfuM}@y@GKEOCK?KAG","mode":"driving","maneuver":{"bearing_after":36,"bearing_before":0,"location":[-77.044347,38.908673],"type":"depart","instruction":"Head northeast on New Hampshire Avenue Northwest"},"weight":35.2,"duration":34.7,"name":"New Hampshire Avenue Northwest","distance":71.5},{"intersections":[{"out":0,"in":1,"entry":[true,false,false],"bearings":[105,270,300],"location":[-77.043755,38.909076]},{"out":0,"in":3,"entry":[true,true,true,false],"bearings":[105,120,135,285],"location":[-77.043591,38.909037]},{"out":0,"in":2,"entry":[true,false,false],"bearings":[45,195,225],"location":[-77.042939,38.909165]},{"out":0,"in":2,"entry":[true,true,false,false],"bearings":[30,75,210,255],"location":[-77.042775,38.909307]},{"out":1,"in":3,"entry":[true,true,false,false,true],"bearings":[15,45,135,195,345],"location":[-77.042669,38.909502]},{"out":0,"in":1,"entry":[true,false,false],"bearings":[90,255,300],"location":[-77.042382,38.909646]}],"driving_side":"right","geometry":"wlnlFnrfuMBK@I@K@I?I?I?I?GAI?ICIAGAICICGCGEGAECCCECCCCECCCGEGEGCECGAKKEGCICICQ?yA","mode":"driving","maneuver":{"exit":3,"bearing_after":111,"bearing_before":84,"location":[-77.043755,38.909076],"modifier":"slight right","type":"roundabout","instruction":"Enter the traffic circle and take the 3rd exit onto P Street Northwest"},"weight":94.4,"duration":69.7,"name":"P Street Northwest","distance":189.9},{"intersections":[{"in":0,"entry":[true],"bearings":[270],"location":[-77.041926,38.909646]}],"driving_side":"right","geometry":"ipnlF`gfuM","mode":"driving","maneuver":{"bearing_after":0,"bearing_before":90,"location":[-77.041926,38.909646],"type":"arrive","instruction":"You have arrived at your destination"},"weight":0,"duration":0,"name":"P Street Northwest","distance":0}],"distance":261.4}],"weight_name":"routability","weight":129.6,"duration":104.4,"distance":261.4}],"waypoints":[{"name":"New Hampshire Avenue Northwest","location":[-77.044347,38.908673]},{"name":"P Street Northwest","location":[-77.041926,38.909646]}],"code":"Ok","uuid":"cjfe60wqh055u4epbgoj7irfc"}

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Loading