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

add tests for eta_model parameter #7373

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import com.mapbox.navigation.base.trip.model.RouteProgressState
import com.mapbox.navigation.core.MapboxNavigation
import com.mapbox.navigation.core.MapboxNavigationProvider
import com.mapbox.navigation.core.directions.session.RoutesExtra
import com.mapbox.navigation.core.internal.extensions.flowLocationMatcherResult
import com.mapbox.navigation.core.reroute.NavigationRerouteController
import com.mapbox.navigation.core.reroute.RerouteController
import com.mapbox.navigation.core.reroute.RerouteState
Expand All @@ -35,6 +36,7 @@ import com.mapbox.navigation.instrumentation_tests.utils.http.MockDirectionsRefr
import com.mapbox.navigation.instrumentation_tests.utils.http.MockDirectionsRequestHandler
import com.mapbox.navigation.instrumentation_tests.utils.idling.RouteProgressStateIdlingResource
import com.mapbox.navigation.instrumentation_tests.utils.location.MockLocationReplayerRule
import com.mapbox.navigation.instrumentation_tests.utils.location.stayOnPosition
import com.mapbox.navigation.instrumentation_tests.utils.readRawFileText
import com.mapbox.navigation.instrumentation_tests.utils.routes.MockRoute
import com.mapbox.navigation.instrumentation_tests.utils.routes.RoutesProvider
Expand Down Expand Up @@ -67,6 +69,7 @@ import org.junit.Rule
import org.junit.Test
import java.net.URI
import java.util.concurrent.TimeUnit
import kotlin.math.abs

class CoreRerouteTest : BaseTest<EmptyTestActivity>(EmptyTestActivity::class.java) {

Expand Down Expand Up @@ -853,6 +856,53 @@ class CoreRerouteTest : BaseTest<EmptyTestActivity>(EmptyTestActivity::class.jav
assertEquals(routes[1], rerouteResult.navigationRoutes.first())
}

@Test
fun reroute_keeps_eta_model_parameter() = sdkTest {
val mapboxNavigation = createMapboxNavigation()
val coordinates = listOf(
Point.fromLngLat(139.828785, 36.503349),
Point.fromLngLat(139.051904, 35.982396)
)
val offRouteLocation = mockLocationUpdatesRule.generateLocationUpdate {
this.latitude = coordinates[0].latitude() + 0.002
this.longitude = coordinates[0].longitude()
}
val handler = MockDirectionsRequestHandler(
DirectionsCriteria.PROFILE_DRIVING_TRAFFIC,
readRawFileText(context, R.raw.route_response_enhanced_model),
coordinates,
relaxedExpectedCoordinates = true
)
mockWebServerRule.requestHandlers.add(handler)

mapboxNavigation.startTripSession()
stayOnPosition(coordinates[0].latitude(), coordinates[0].longitude(), 0f) {
mapboxNavigation.flowLocationMatcherResult().filter {
abs(it.enhancedLocation.latitude - coordinates[0].latitude()) < 0.001 &&
abs(it.enhancedLocation.longitude - coordinates[0].longitude()) < 0.001
}.first()
val routes = mapboxNavigation.requestRoutes(
RouteOptions.builder()
.applyDefaultNavigationOptions()
.applyLanguageAndVoiceUnitOptions(activity)
.baseUrl(mockWebServerRule.baseUrl)
.coordinatesList(coordinates)
.unrecognizedProperties(mapOf("eta_model" to "enhanced"))
.build()
).getSuccessfulResultOrThrowException().routes

mapboxNavigation.setNavigationRoutesAndWaitForUpdate(routes)
}
stayOnPosition(offRouteLocation.latitude, offRouteLocation.longitude, 0f) {
mapboxNavigation.routesUpdates()
.filter { it.reason == RoutesExtra.ROUTES_UPDATE_REASON_REROUTE }
.first()

val rerouteRequest = handler.handledRequests.last()
assertEquals("enhanced", rerouteRequest.requestUrl?.queryParameter("eta_model"))
}
}

private fun createMapboxNavigation(customRefreshInterval: Long? = null): MapboxNavigation {
var mapboxNavigation: MapboxNavigation? = null

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package com.mapbox.navigation.instrumentation_tests.core

import android.location.Location
import com.mapbox.navigation.base.route.RouterOrigin
import com.mapbox.navigation.instrumentation_tests.utils.location.stayOnPosition
import com.mapbox.navigation.instrumentation_tests.utils.routes.EvRoutesProvider
import com.mapbox.navigation.instrumentation_tests.utils.routes.MockedEvRoutes
import com.mapbox.navigation.instrumentation_tests.utils.tiles.OfflineRegions
import com.mapbox.navigation.instrumentation_tests.utils.tiles.withMapboxNavigationAndOfflineTilesForRegion
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.utils.coroutines.RouteRequestResult
import com.mapbox.navigation.testing.ui.utils.coroutines.getSuccessfulResultOrThrowException
import com.mapbox.navigation.testing.ui.utils.coroutines.requestRoutes
import com.mapbox.navigation.testing.ui.utils.coroutines.sdkTest
import com.mapbox.navigation.testing.ui.utils.coroutines.setNavigationRoutesAndWaitForUpdate
import com.mapbox.navigation.testing.ui.utils.coroutines.setNavigationRoutesAsync
import org.junit.Assert
import org.junit.Assert.assertEquals
import org.junit.Test

class RequestRoutesTest : BaseCoreNoCleanUpTest() {

override fun setupMockLocation(): Location {
return mockLocationUpdatesRule.generateLocationUpdate {
longitude = 13.361378213031003
latitude = 52.49813341962201
}
}

@Test
fun buildOfflineRouteWithUnknownParameters() = sdkTest(
timeout = INCREASED_TIMEOUT_BECAUSE_OF_REAL_ROUTING_TILES_USAGE
) {
val testRoute = setupBerlinEvRoute()
withMapboxNavigationAndOfflineTilesForRegion(
OfflineRegions.Berlin,
) { navigation ->
navigation.startTripSession()
stayOnPosition(
testRoute.origin.latitude(),
testRoute.origin.longitude(),
0.0f,
) {
withoutInternet {
val requestResult = navigation.requestRoutes(
testRoute.routeOptions.toBuilder()
.unrecognizedProperties(
mapOf(
"unknown_key1" to "unknown_value1",
"unknown_key2" to "333",
"eta_model" to "enhanced"
)
)
.build()
).getSuccessfulResultOrThrowException()
assertEquals(RouterOrigin.Onboard, requestResult.routerOrigin)
navigation.setNavigationRoutesAndWaitForUpdate(requestResult.routes)
}
}
}
}

private fun setupBerlinEvRoute(): MockedEvRoutes {
val originalTestRoute = EvRoutesProvider.getBerlinEvRoute(
context,
mockWebServerRule.baseUrl
)
mockWebServerRule.requestHandlers.add(originalTestRoute.mockWebServerHandler)
return originalTestRoute
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,43 @@ class RouteAlternativesTest : BaseCoreNoCleanUpTest() {
}
}

@Test
fun alternative_request_keeps_eta_model_parameter() = sdkTest {
setupMockRequestHandlers()
withMapboxNavigation(
historyRecorderRule = mapboxHistoryTestRule
) { mapboxNavigation ->
val routes = mapboxNavigation.requestNavigationRoutes(
startCoordinates,
unrecognized = mapOf("eta_model" to "enhanced")
)
mockWebServerRule.requestHandlers.clear()
val alternativesHandler = MockDirectionsRequestHandler(
"driving-traffic",
readRawFileText(context, R.raw.route_response_alternative_during_navigation),
startCoordinates,
relaxedExpectedCoordinates = true
)
mockWebServerRule.requestHandlers.add(alternativesHandler)
mapboxNavigation.startTripSession()
mapboxNavigation.flowLocationMatcherResult().first()
mapboxNavigation.setNavigationRoutesAsync(routes)
mockLocationReplayerRule.playRoute(routes.first().directionsRoute)

mapboxNavigation.alternativesUpdates()
.filterIsInstance<NavigationRouteAlternativesResult.OnRouteAlternatives>()
.filter {
it.alternatives.isNotEmpty() && it.alternatives.none {
it.id.startsWith("1SSd29ZxmjD7ELLqDJHRPPDP5W4wdh633IbGo41pJrL6wpJRmzNaMA==")
}
}
.first()

val alternativesRequest = alternativesHandler.handledRequests.last()
assertEquals("enhanced", alternativesRequest.requestUrl?.queryParameter("eta_model"))
}
}

private fun createExternalAlternatives(): List<NavigationRoute> {
return NavigationRoute.create(
readRawFileText(context, R.raw.route_response_alternative_continue),
Expand Down Expand Up @@ -328,12 +365,14 @@ class RouteAlternativesTest : BaseCoreNoCleanUpTest() {
}

private suspend fun MapboxNavigation.requestNavigationRoutes(
coordinates: List<Point>
coordinates: List<Point>,
unrecognized: Map<String, String>? = null
): List<NavigationRoute> {
val routeOptions = RouteOptions.builder()
.applyDefaultNavigationOptions()
.alternatives(true)
.coordinatesList(coordinates)
.unrecognizedProperties(unrecognized)
.baseUrl(mockWebServerRule.baseUrl) // Comment out to test a real server
.build()
return requestRoutes(routeOptions)
Expand Down

Large diffs are not rendered by default.