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

Native Router #4791

Merged
merged 3 commits into from
Oct 27, 2021
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
12 changes: 12 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,18 @@ License: [The Apache License, Version 2.0](http://www.apache.org/licenses/LICENS

===========================================================================

Mapbox Navigation uses portions of the kotlinx-coroutines-android (Coroutines support libraries for Kotlin).
URL: [https://github.com/Kotlin/kotlinx.coroutines](https://github.com/Kotlin/kotlinx.coroutines)
License: [The Apache Software License, Version 2.0](https://www.apache.org/licenses/LICENSE-2.0.txt)

===========================================================================

Mapbox Navigation uses portions of the kotlinx-coroutines-core (Coroutines support libraries for Kotlin).
URL: [https://github.com/Kotlin/kotlinx.coroutines](https://github.com/Kotlin/kotlinx.coroutines)
License: [The Apache Software License, Version 2.0](https://www.apache.org/licenses/LICENSE-2.0.txt)

===========================================================================

Mapbox Navigation uses portions of the Mapbox Android Commmon OkHttp SDK.
URL: [https://github.com/mapbox/mapbox-sdk](https://github.com/mapbox/mapbox-sdk)
License: [BSD](https://opensource.org/licenses/BSD-2-Clause)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ 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.options.NavigationOptions
import com.mapbox.navigation.base.options.RoutingTilesOptions
import com.mapbox.navigation.base.route.RouteRefreshOptions
import com.mapbox.navigation.core.MapboxNavigation
import com.mapbox.navigation.core.MapboxNavigationProvider
import com.mapbox.navigation.instrumentation_tests.R
import com.mapbox.navigation.instrumentation_tests.activity.EmptyTestActivity
import com.mapbox.navigation.instrumentation_tests.utils.MapboxNavigationRule
import com.mapbox.navigation.instrumentation_tests.utils.http.MockAvailableTilesVersionsRequestHandler
import com.mapbox.navigation.instrumentation_tests.utils.http.MockDirectionsRefreshHandler
import com.mapbox.navigation.instrumentation_tests.utils.http.MockDirectionsRequestHandler
import com.mapbox.navigation.instrumentation_tests.utils.idling.IdlingPolicyTimeoutRule
Expand All @@ -27,6 +29,7 @@ import org.junit.Assert.assertEquals
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import java.net.URI
import java.util.concurrent.TimeUnit

class RouteRefreshTest : BaseTest<EmptyTestActivity>(EmptyTestActivity::class.java) {
Expand All @@ -53,6 +56,8 @@ class RouteRefreshTest : BaseTest<EmptyTestActivity>(EmptyTestActivity::class.ja

@Before
fun setup() {
setupMockRequestHandlers(coordinates)

mapboxNavigation = MapboxNavigationProvider.create(
NavigationOptions.Builder(activity)
.accessToken(getMapboxAccessTokenFromResources(activity))
Expand All @@ -61,14 +66,18 @@ class RouteRefreshTest : BaseTest<EmptyTestActivity>(EmptyTestActivity::class.ja
.intervalMillis(TimeUnit.SECONDS.toMillis(30))
.build()
)
.routingTilesOptions(
RoutingTilesOptions.Builder()
.tilesBaseUri(URI(mockWebServerRule.baseUrl))
.build()
)
.build()
)
}

@Test
fun expect_route_refresh_to_update_traffic_annotations() {
// Request a route.
setupMockRequestHandlers(coordinates)
val routes = requestDirectionsRouteSync(coordinates).reversed()

// Create an observer resource that captures the routes.
Expand Down Expand Up @@ -116,6 +125,11 @@ class RouteRefreshTest : BaseTest<EmptyTestActivity>(EmptyTestActivity::class.ja
readRawFileText(activity, R.raw.route_response_route_refresh_annotations)
)
)
mockWebServerRule.requestHandlers.add(
MockAvailableTilesVersionsRequestHandler(
readRawFileText(activity, R.raw.nn_response_available_versions)
)
)
}

private fun requestDirectionsRouteSync(coordinates: List<Point>): List<DirectionsRoute> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.mapbox.navigation.instrumentation_tests.utils.http

import com.mapbox.navigation.testing.ui.http.MockRequestHandler
import okhttp3.mockwebserver.MockResponse
import okhttp3.mockwebserver.RecordedRequest

/**
* Mocks NN available tiles versions request.
*
* @param jsonResponse the full JSON response
*/
class MockAvailableTilesVersionsRequestHandler(
private val jsonResponse: String
) : MockRequestHandler {
override fun handle(request: RecordedRequest): MockResponse? {
val prefix = """/route-tiles/v2/mapbox/driving-traffic/versions"""
return if (request.path!!.startsWith(prefix)) {
MockResponse().setBody(jsonResponse)
} else {
null
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"availableVersions":["2021_10_15-03_00_00","2021_10_09-03_00_00","2021_10_03-03_00_00","2021_09_17-03_00_00","2021_09_12-03_00_00","2021_09_05-03_00_00","2021_09_04-03_00_00","2021_08_23-14_04_46","2021_08_23-03_00_00","2021_08_21-03_00_00","2021_08_16-03_00_00","2021_08_08-03_00_00","2021_07_31-03_00_00","2021_07_25-03_00_00","2021_07_17-03_00_00","2021_07_10-03_00_00","2021_07_04-03_00_00","2021_06_27-03_00_00","2021_06_20-03_00_00","2021_06_13-03_00_00","2021_06_06-03_00_00","2021_06_05-03_00_00","2021_05_30-03_00_00","2021_05_23-03_00_00","2021_05_16-03_00_00","2021_05_09-03_00_00","2021_05_01-03_00_00","2021_04_26-03_00_00","2021_04_25-03_00_00","2021_04_18-03_00_00"],"metadata":{"2021_10_15-03_00_00":{"map":{"tileset_version":"2021_10_15-03_00_00"}},"2021_10_09-03_00_00":{"map":{"tileset_version":"2021_10_09-03_00_00"}},"2021_10_03-03_00_00":{"map":{"tileset_version":"2021_10_03-03_00_00"}},"2021_09_17-03_00_00":{"map":{"tileset_version":"2021_09_17-03_00_00"}},"2021_09_12-03_00_00":{"map":{"tileset_version":"2021_09_12-03_00_00"}},"2021_09_05-03_00_00":{"map":{"tileset_version":"2021_09_05-03_00_00"}},"2021_09_04-03_00_00":{"map":{"tileset_version":"2021_09_04-03_00_00"}},"2021_08_23-14_04_46":{"map":{}},"2021_08_23-03_00_00":{"map":{}},"2021_08_21-03_00_00":{"map":{}},"2021_08_16-03_00_00":{"map":{}},"2021_08_08-03_00_00":{"map":{}},"2021_07_31-03_00_00":{"map":{}},"2021_07_25-03_00_00":{"map":{}},"2021_07_17-03_00_00":{"map":{}},"2021_07_10-03_00_00":{"map":{}},"2021_07_04-03_00_00":{"map":{}},"2021_06_27-03_00_00":{"map":{}},"2021_06_20-03_00_00":{"map":{}},"2021_06_13-03_00_00":{"map":{}},"2021_06_06-03_00_00":{"map":{}},"2021_06_05-03_00_00":{"map":{}},"2021_05_30-03_00_00":{"map":{}},"2021_05_23-03_00_00":{"map":{}},"2021_05_16-03_00_00":{"map":{}},"2021_05_09-03_00_00":{"map":{}},"2021_05_01-03_00_00":{"map":{}},"2021_04_26-03_00_00":{"map":{}},"2021_04_25-03_00_00":{"map":{}},"2021_04_18-03_00_00":{"map":{}}}}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will we need to keep updating this file? Do we need to mock it in general? We are not mocking routing tiles request (yet), so why do we need to mock the routing tiles version requests?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't need to update it, we mock it to prevent mockWebServer exception

throw Error(
                    """Request url:
                      |${request.path}
                      |is not handled.
                      |
                      |Available handlers:
                      |$formattedHandlersBuilder
                    """.trimMargin()
                )

We are not mocking routing tiles request (yet), so why do we need to mock the routing tiles version requests?

not 100% sure, looks like because version request made by NN and tiles request by common (Tilestore).
I mocked it because of the mockWebServer exception.

Copy link

@LukasPaczos LukasPaczos Oct 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, since we redirect everything localhost, the onboard router will probably always fail because it has no tiles. This shouldn't impact the test as long as the device doesn't go offline.

Loading