/** * Build a new {@link MapboxMapMatching} object with the initial values set for * {@link #baseUrl()}, {@link #profile()}, {@link #geometries()}, and {@link #user()}. * * @return a {@link Builder} object for creating this object * @since 3.0.0 */ public static Builder builder() { return new AutoValue_MapboxMapMatching.Builder() .baseUrl(Constants.BASE_API_URL) .profile(DirectionsCriteria.PROFILE_DRIVING) .geometries(DirectionsCriteria.GEOMETRY_POLYLINE6) .user(DirectionsCriteria.PROFILE_DEFAULT_USER); }
@Override protected Call<MapMatchingResponse> initializeCall() { return getService().getCall( ApiCallHelper.getHeaderUserAgent(clientAppName()), user(), profile(), coordinates(), accessToken(), geometries(), radiuses(), steps(), overview(), timestamps(), annotations(), language(), tidy(), roundaboutExits(), bannerInstructions(), voiceInstructions(), voiceUnits(), waypoints(), waypointNames(), approaches()); }
public static void main(String[] args) { MapboxMapMatching mapMatching = MapboxMapMatching.builder() .accessToken(BuildConfig.MAPBOX_ACCESS_TOKEN) .coordinate(Point.fromLngLat(-117.1728265285492,32.71204416018209)) .coordinate(Point.fromLngLat(-117.17288821935652,32.712258556224)) .coordinate(Point.fromLngLat(-117.17293113470076,32.712443613445814)) .coordinate(Point.fromLngLat(-117.17292040586472,32.71256999376694)) .coordinate(Point.fromLngLat(-117.17298477888109,32.712603845608285)) .coordinate(Point.fromLngLat(-117.17314302921294,32.71259933203019)) .coordinate(Point.fromLngLat(-117.17334151268004,32.71254065549407)) .build(); mapMatching.enqueueCall(new Callback<MapMatchingResponse>() { @Override public void onResponse(Call<MapMatchingResponse> call, Response<MapMatchingResponse> response) { System.out.println(response.body().toString()); } @Override public void onFailure(Call<MapMatchingResponse> call, Throwable throwable) { System.out.println(throwable); } }); } }
@Test public void sanityWaypoints() throws Exception { MapboxMapMatching mapMatching = MapboxMapMatching.builder() .coordinate(Point.fromLngLat(2.0, 2.0)) .coordinate(Point.fromLngLat(3.0, 3.0)) .coordinate(Point.fromLngLat(4.0, 4.0)) .waypoints(0, 1, 2) .baseUrl("https://foobar.com") .accessToken(ACCESS_TOKEN) .build(); assertNotNull(mapMatching); }
@Test public void sanity() throws Exception { MapboxMapMatching mapMatching = MapboxMapMatching.builder() .coordinates(coordinates) .baseUrl(mockUrl.toString()) .accessToken(ACCESS_TOKEN) .build(); assertNotNull(mapMatching); }
@Test public void build_exceptionThrownWhenNumApproachesDoesNotMatchCoordinates() throws Exception { thrown.expect(ServicesException.class); thrown.expectMessage( startsWith("Number of approach elements must match")); MapboxMapMatching mapMatching = MapboxMapMatching.builder() .coordinate(Point.fromLngLat(2.0, 2.0)) .coordinate(Point.fromLngLat(4.0, 4.0)) .addApproaches(APPROACH_UNRESTRICTED) .baseUrl("https://foobar.com") .accessToken(ACCESS_TOKEN) .build(); }
@Test public void build_exceptionThrownWhenLessThanTwoCoordsProvided() throws Exception { thrown.expect(ServicesException.class); thrown.expectMessage( startsWith("At least two coordinates must be provided with your API request.")); MapboxMapMatching mapMatching = MapboxMapMatching.builder() .coordinate(Point.fromLngLat(2.0, 2.0)) .baseUrl("https://foobar.com") .accessToken(ACCESS_TOKEN) .build(); mapMatching.executeCall(); }
@Test public void build_noAccessTokenExceptionThrown() throws Exception { thrown.expect(IllegalStateException.class); thrown.expectMessage("Missing required properties: accessToken"); MapboxMapMatching.builder() .coordinate(Point.fromLngLat(2.0, 2.0)) .coordinate(Point.fromLngLat(2.0, 2.0)) .build(); }
@Override protected Call<MapMatchingResponse> initializeCall() { return getService().getCall( ApiCallHelper.getHeaderUserAgent(clientAppName()), user(), profile(), coordinates(), accessToken(), geometries(), radiuses(), steps(), overview(), timestamps(), annotations(), language(), tidy(), roundaboutExits(), bannerInstructions(), voiceInstructions(), voiceUnits(), waypoints(), waypointNames(), approaches()); }
/** * Build a new {@link MapboxMapMatching} object with the initial values set for * {@link #baseUrl()}, {@link #profile()}, {@link #geometries()}, and {@link #user()}. * * @return a {@link Builder} object for creating this object * @since 3.0.0 */ public static Builder builder() { return new AutoValue_MapboxMapMatching.Builder() .baseUrl(Constants.BASE_API_URL) .profile(DirectionsCriteria.PROFILE_DRIVING) .geometries(DirectionsCriteria.GEOMETRY_POLYLINE6) .user(DirectionsCriteria.PROFILE_DEFAULT_USER); }
@Test public void build_exceptionThrownWhenLessThanTwoWayPointsProvided() throws Exception { thrown.expect(ServicesException.class); thrown.expectMessage( startsWith("Waypoints must be a list of at least two indexes separated by")); MapboxMapMatching mapMatching = MapboxMapMatching.builder() .coordinate(Point.fromLngLat(2.0, 2.0)) .coordinate(Point.fromLngLat(4.0, 4.0)) .waypoints(0) .baseUrl("https://foobar.com") .accessToken(ACCESS_TOKEN) .build(); }
@Test public void accessToken_doesGetPlacedInUrlCorrectly() throws Exception { MapboxMapMatching mapMatching = MapboxMapMatching.builder() .coordinates(coordinates) .baseUrl(mockUrl.toString()) .accessToken(ACCESS_TOKEN) .build(); assertTrue(mapMatching.cloneCall().request().url().toString().contains("access_token=pk.XXX")); }
@Test public void build_exceptionThrownWhenInvalidApproaches() throws Exception { thrown.expect(ServicesException.class); thrown.expectMessage( startsWith("All approaches values must be one of curb, unrestricted")); MapboxMapMatching mapMatching = MapboxMapMatching.builder() .coordinate(Point.fromLngLat(2.0, 2.0)) .coordinate(Point.fromLngLat(4.0, 4.0)) .addApproaches(APPROACH_UNRESTRICTED, "restricted") .baseUrl("https://foobar.com") .accessToken(ACCESS_TOKEN) .build(); }
@Test public void build_invalidAccessTokenExceptionThrown() throws Exception { thrown.expect(ServicesException.class); thrown.expectMessage("Using Mapbox Services requires setting a valid access token."); MapboxMapMatching.builder() .accessToken("") .coordinate(Point.fromLngLat(2.0, 2.0)) .coordinate(Point.fromLngLat(2.0, 2.0)) .build(); }
@Override protected Call<MapMatchingResponse> initializeCall() { return getService().getCall( ApiCallHelper.getHeaderUserAgent(clientAppName()), user(), profile(), coordinates(), accessToken(), geometries(), radiuses(), steps(), overview(), timestamps(), annotations(), language(), tidy(), roundaboutExits(), bannerInstructions(), voiceInstructions(), voiceUnits(), waypoints(), waypointNames(), approaches()); }
/** * Build a new {@link MapboxMapMatching} object with the initial values set for * {@link #baseUrl()}, {@link #profile()}, {@link #geometries()}, and {@link #user()}. * * @return a {@link Builder} object for creating this object * @since 3.0.0 */ public static Builder builder() { return new AutoValue_MapboxMapMatching.Builder() .baseUrl(Constants.BASE_API_URL) .profile(DirectionsCriteria.PROFILE_DRIVING) .geometries(DirectionsCriteria.GEOMETRY_POLYLINE6) .user(DirectionsCriteria.PROFILE_DEFAULT_USER); }
@Test public void build_exceptionThrownWhenMiddleWaypointsAreWrong() throws Exception { thrown.expect(ServicesException.class); thrown.expectMessage( startsWith("Waypoints index too large (no corresponding coordinate)")); MapboxMapMatching mapMatching = MapboxMapMatching.builder() .coordinate(Point.fromLngLat(2.0, 2.0)) .coordinate(Point.fromLngLat(3.0, 3.0)) .coordinate(Point.fromLngLat(4.0, 4.0)) .waypoints(0, 3, 2) .baseUrl("https://foobar.com") .accessToken(ACCESS_TOKEN) .build(); }
@Test public void clientAppName_doesSetInHeaderCorrectly1() throws Exception { MapboxMapMatching mapMatching = MapboxMapMatching.builder() .coordinates(coordinates) .baseUrl(mockUrl.toString()) .clientAppName("APP") .accessToken(ACCESS_TOKEN) .build(); assertTrue(mapMatching.cloneCall().request().header("User-Agent").contains("APP")); }
@Test public void build_exceptionThrownWhenWaypointDoNotEndWithLast() throws Exception { thrown.expect(ServicesException.class); thrown.expectMessage( startsWith("Waypoints must contain indices of the first and last coordinates")); MapboxMapMatching mapMatching = MapboxMapMatching.builder() .coordinate(Point.fromLngLat(2.0, 2.0)) .coordinate(Point.fromLngLat(3.0, 3.0)) .coordinate(Point.fromLngLat(4.0, 4.0)) .waypoints(0, 1) .baseUrl("https://foobar.com") .accessToken(ACCESS_TOKEN) .build(); }
@Test public void build_exceptionThrownWhenWaypointsDoNotStartWith0() throws Exception { thrown.expect(ServicesException.class); thrown.expectMessage( startsWith("Waypoints must contain indices of the first and last coordinates")); MapboxMapMatching mapMatching = MapboxMapMatching.builder() .coordinate(Point.fromLngLat(2.0, 2.0)) .coordinate(Point.fromLngLat(3.0, 3.0)) .coordinate(Point.fromLngLat(4.0, 4.0)) .waypoints(1, 2) .baseUrl("https://foobar.com") .accessToken(ACCESS_TOKEN) .build(); }