-
Notifications
You must be signed in to change notification settings - Fork 319
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e15369b
commit 9d49c13
Showing
16 changed files
with
638 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
- Introduced `RouterFailure#isRetryable` which indicates if that makes sense to retry with this type of failure. | ||
For convenience, you can use an extension property `isRetryable` for the list of `RouterFailure` in `NavigationRouterCallback.onFailure`. | ||
In case of reroute use `RerouteState.Failed.isRetryable`. |
137 changes: 105 additions & 32 deletions
137
.../src/androidTest/java/com/mapbox/navigation/instrumentation_tests/core/CoreRerouteTest.kt
Large diffs are not rendered by default.
Oops, something went wrong.
224 changes: 224 additions & 0 deletions
224
...rc/androidTest/java/com/mapbox/navigation/instrumentation_tests/core/RouteRequestTests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,224 @@ | ||
package com.mapbox.navigation.instrumentation_tests.core | ||
|
||
import android.location.Location | ||
import com.mapbox.api.directions.v5.models.RouteOptions | ||
import com.mapbox.geojson.Point | ||
import com.mapbox.navigation.base.extensions.applyDefaultNavigationOptions | ||
import com.mapbox.navigation.base.route.isRetryable | ||
import com.mapbox.navigation.instrumentation_tests.R | ||
import com.mapbox.navigation.instrumentation_tests.utils.history.MapboxHistoryTestRule | ||
import com.mapbox.navigation.instrumentation_tests.utils.readRawFileText | ||
import com.mapbox.navigation.instrumentation_tests.utils.withMapboxNavigation | ||
import com.mapbox.navigation.instrumentation_tests.utils.withoutInternet | ||
import com.mapbox.navigation.testing.ui.BaseCoreNoCleanUpTest | ||
import com.mapbox.navigation.testing.ui.http.MockRequestHandler | ||
import com.mapbox.navigation.testing.ui.utils.coroutines.RouteRequestResult | ||
import com.mapbox.navigation.testing.ui.utils.coroutines.requestRoutes | ||
import com.mapbox.navigation.testing.ui.utils.coroutines.sdkTest | ||
import okhttp3.mockwebserver.MockResponse | ||
import org.junit.Assert.assertFalse | ||
import org.junit.Assert.assertTrue | ||
import org.junit.Rule | ||
import org.junit.Test | ||
|
||
/** | ||
* See https://docs.mapbox.com/api/navigation/directions/#directions-api-errors for info | ||
* about different Directions API failures | ||
*/ | ||
class RouteRequestTests : BaseCoreNoCleanUpTest() { | ||
|
||
@get:Rule | ||
val mapboxHistoryTestRule = MapboxHistoryTestRule() | ||
|
||
private val origin = Point.fromLngLat( | ||
13.361378213031003, | ||
52.49813341962201 | ||
) | ||
|
||
override fun setupMockLocation(): Location { | ||
return mockLocationUpdatesRule.generateLocationUpdate { | ||
longitude = origin.longitude() | ||
latitude = origin.latitude() | ||
} | ||
} | ||
|
||
@Test | ||
fun requestRouteWithoutInternetAndTiles() = sdkTest { | ||
withMapboxNavigation( | ||
historyRecorderRule = mapboxHistoryTestRule | ||
) { navigation -> | ||
withoutInternet { | ||
val routes = navigation.requestRoutes(createTestRouteOptions()) | ||
assertTrue(routes is RouteRequestResult.Failure) | ||
val isRetryable = (routes as RouteRequestResult.Failure).reasons.isRetryable | ||
assertTrue(isRetryable) | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
fun error500Unknown() = sdkTest { | ||
mockWebServerRule.requestHandlers.add( | ||
MockRequestHandler { | ||
MockResponse().setBody("unexpected server error").setResponseCode(500) | ||
} | ||
) | ||
withMapboxNavigation( | ||
historyRecorderRule = mapboxHistoryTestRule | ||
) { navigation -> | ||
val routes = navigation.requestRoutes(createTestRouteOptions()) | ||
assertTrue(routes is RouteRequestResult.Failure) | ||
val isRetryable = (routes as RouteRequestResult.Failure).reasons.isRetryable | ||
assertFalse(isRetryable) | ||
} | ||
} | ||
|
||
@Test | ||
fun invalidInput() = sdkTest { | ||
mockWebServerRule.requestHandlers.add( | ||
MockRequestHandler { | ||
MockResponse() | ||
.setBody(readRawFileText(context, R.raw.invalid_alternative_response_body)) | ||
.setResponseCode(422) | ||
} | ||
) | ||
withMapboxNavigation( | ||
historyRecorderRule = mapboxHistoryTestRule | ||
) { navigation -> | ||
val routes = navigation.requestRoutes(createTestRouteOptions()) | ||
assertTrue(routes is RouteRequestResult.Failure) | ||
val isRetryable = (routes as RouteRequestResult.Failure).reasons.isRetryable | ||
assertFalse(isRetryable) | ||
} | ||
} | ||
|
||
@Test | ||
fun wrongSegment() = sdkTest { | ||
mockWebServerRule.requestHandlers.add( | ||
MockRequestHandler { | ||
MockResponse() | ||
.setBody(readRawFileText(context, R.raw.wrong_segment_response_body)) | ||
.setResponseCode(200) | ||
} | ||
) | ||
withMapboxNavigation( | ||
historyRecorderRule = mapboxHistoryTestRule | ||
) { navigation -> | ||
val routes = navigation.requestRoutes(createTestRouteOptions()) | ||
assertTrue(routes is RouteRequestResult.Failure) | ||
val isRetryable = (routes as RouteRequestResult.Failure).reasons.isRetryable | ||
assertFalse(isRetryable) | ||
} | ||
} | ||
|
||
@Test | ||
fun noRouteFound() = sdkTest { | ||
mockWebServerRule.requestHandlers.add( | ||
MockRequestHandler { | ||
MockResponse() | ||
.setBody("{\"code\":\"NoRoute\",\"message\":\"No route found\",\"routes\":[]}") | ||
.setResponseCode(200) | ||
} | ||
) | ||
withMapboxNavigation( | ||
historyRecorderRule = mapboxHistoryTestRule | ||
) { navigation -> | ||
val routes = navigation.requestRoutes(createTestRouteOptions()) | ||
assertTrue(routes is RouteRequestResult.Failure) | ||
val isRetryable = (routes as RouteRequestResult.Failure).reasons.isRetryable | ||
assertFalse(isRetryable) | ||
} | ||
} | ||
|
||
@Test | ||
fun invalidAccessToken() = sdkTest { | ||
mockWebServerRule.requestHandlers.add( | ||
MockRequestHandler { | ||
MockResponse() | ||
.setBody("{\"message\":\"Not Authorized - Invalid Token\"}") | ||
.setResponseCode(401) | ||
} | ||
) | ||
withMapboxNavigation( | ||
historyRecorderRule = mapboxHistoryTestRule | ||
) { navigation -> | ||
val routes = navigation.requestRoutes(createTestRouteOptions()) | ||
assertTrue(routes is RouteRequestResult.Failure) | ||
val isRetryable = (routes as RouteRequestResult.Failure).reasons.isRetryable | ||
assertFalse(isRetryable) | ||
} | ||
} | ||
|
||
@Test | ||
fun noAccessToken() = sdkTest { | ||
mockWebServerRule.requestHandlers.add( | ||
MockRequestHandler { | ||
MockResponse() | ||
.setBody(readRawFileText(context, R.raw.no_access_token_response_body)) | ||
.setResponseCode(401) | ||
} | ||
) | ||
withMapboxNavigation( | ||
historyRecorderRule = mapboxHistoryTestRule | ||
) { navigation -> | ||
val routes = navigation.requestRoutes(createTestRouteOptions()) | ||
assertTrue(routes is RouteRequestResult.Failure) | ||
val isRetryable = (routes as RouteRequestResult.Failure).reasons.isRetryable | ||
assertFalse(isRetryable) | ||
} | ||
} | ||
|
||
@Test | ||
fun forbidden() = sdkTest { | ||
mockWebServerRule.requestHandlers.add( | ||
MockRequestHandler { | ||
MockResponse() | ||
.setBody("{\"message\":\"Forbidden\"}") | ||
.setResponseCode(403) | ||
} | ||
) | ||
withMapboxNavigation( | ||
historyRecorderRule = mapboxHistoryTestRule | ||
) { navigation -> | ||
val routes = navigation.requestRoutes(createTestRouteOptions()) | ||
assertTrue(routes is RouteRequestResult.Failure) | ||
val isRetryable = (routes as RouteRequestResult.Failure).reasons.isRetryable | ||
assertFalse(isRetryable) | ||
} | ||
} | ||
|
||
@Test | ||
fun profileNotFound() = sdkTest { | ||
mockWebServerRule.requestHandlers.add( | ||
MockRequestHandler { | ||
MockResponse() | ||
.setBody("{\"message\":\"Profile not found\"}") | ||
.setResponseCode(401) | ||
} | ||
) | ||
withMapboxNavigation( | ||
historyRecorderRule = mapboxHistoryTestRule | ||
) { navigation -> | ||
val routes = navigation.requestRoutes(createTestRouteOptions()) | ||
assertTrue(routes is RouteRequestResult.Failure) | ||
val isRetryable = (routes as RouteRequestResult.Failure).reasons.isRetryable | ||
assertFalse(isRetryable) | ||
} | ||
} | ||
|
||
private fun createTestRouteOptions(): RouteOptions { | ||
return RouteOptions.builder() | ||
.baseUrl(mockWebServerRule.baseUrl) | ||
.applyDefaultNavigationOptions() | ||
.coordinatesList( | ||
listOf( | ||
origin, | ||
Point.fromLngLat( | ||
13.361478213031003, | ||
52.49823341962201 | ||
) | ||
) | ||
) | ||
.build() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
instrumentation-tests/src/main/res/raw/invalid_alternative_response_body.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"message": "annotations value must be one of duration, distance, speed, congestion, congestion_numeric, closure, state_of_charge, maxspeed", | ||
"code": "InvalidInput" | ||
} |
4 changes: 4 additions & 0 deletions
4
instrumentation-tests/src/main/res/raw/no_access_token_response_body.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"message": "Not Authorized - Invalid Token", | ||
"error_detail": "No valid token prefix found in access_token parameter" | ||
} |
5 changes: 5 additions & 0 deletions
5
instrumentation-tests/src/main/res/raw/wrong_segment_response_body
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"code": "NoSegment", | ||
"message": "Could not find a matching segment for input coordinates", | ||
"routes": [] | ||
} |
10 changes: 10 additions & 0 deletions
10
...gation-base/src/main/java/com/mapbox/navigation/base/internal/route/RetryableThrowable.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.mapbox.navigation.base.internal.route | ||
|
||
import com.mapbox.navigation.base.route.RouterFailure | ||
|
||
/** | ||
* It exists in order not to break API of data class [RouterFailure] by adding boolean field, | ||
* instead existing fields are used to transfer more data. | ||
*/ | ||
@Deprecated("replace by a boolean filed in RouterFailure") | ||
class RetryableThrowable : Throwable(message = "It makes sense to retry in case of that error") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
libnavigation-base/src/main/java/com/mapbox/navigation/base/route/RouterEx.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.mapbox.navigation.base.route | ||
|
||
/** | ||
* Indicates if it makes sense to retry for this type of failures. | ||
* If false, it doesn't make sense to retry route request | ||
*/ | ||
val List<RouterFailure>?.isRetryable: Boolean | ||
get() = this?.any { it.isRetryable } ?: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.