diff --git a/gradle/dependencies.gradle b/gradle/dependencies.gradle index 64188b242ab..959e857033e 100644 --- a/gradle/dependencies.gradle +++ b/gradle/dependencies.gradle @@ -13,7 +13,7 @@ ext { // version which we should use in this build def mapboxNavigatorVersion = System.getenv("FORCE_MAPBOX_NAVIGATION_NATIVE_VERSION") if (mapboxNavigatorVersion == null || mapboxNavigatorVersion == '') { - mapboxNavigatorVersion = '161.1.0' + mapboxNavigatorVersion = 'master-SNAPSHOT' } println("Navigation Native version: " + mapboxNavigatorVersion) diff --git a/instrumentation-tests/src/androidTest/java/com/mapbox/navigation/instrumentation_tests/core/RouteAlternativesTest.kt b/instrumentation-tests/src/androidTest/java/com/mapbox/navigation/instrumentation_tests/core/RouteAlternativesTest.kt index 0b16734c6da..32bc6e0ec2b 100644 --- a/instrumentation-tests/src/androidTest/java/com/mapbox/navigation/instrumentation_tests/core/RouteAlternativesTest.kt +++ b/instrumentation-tests/src/androidTest/java/com/mapbox/navigation/instrumentation_tests/core/RouteAlternativesTest.kt @@ -25,6 +25,9 @@ import com.mapbox.navigation.instrumentation_tests.utils.location.MockLocationRe import com.mapbox.navigation.instrumentation_tests.utils.location.stayOnPosition import com.mapbox.navigation.instrumentation_tests.utils.openRawResource import com.mapbox.navigation.instrumentation_tests.utils.readRawFileText +import com.mapbox.navigation.instrumentation_tests.utils.routes.EvRoutesProvider +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.testing.ui.BaseCoreNoCleanUpTest import com.mapbox.navigation.testing.ui.http.MockRequestHandler @@ -44,6 +47,7 @@ import kotlinx.coroutines.flow.filterIsInstance import kotlinx.coroutines.flow.filterNot import kotlinx.coroutines.flow.first import okhttp3.mockwebserver.MockResponse +import okhttp3.mockwebserver.RecordedRequest import org.junit.Assert.assertEquals import org.junit.Assert.assertNotNull import org.junit.Assert.assertTrue @@ -51,6 +55,7 @@ import org.junit.Rule import org.junit.Test import java.io.InputStreamReader import java.net.URL +import java.util.concurrent.CountDownLatch /** * This test ensures that alternative route recommendations @@ -449,6 +454,57 @@ class RouteAlternativesTest : BaseCoreNoCleanUpTest() { } } + @Test + fun offlineRouteCalculatedFasterThenOnline() = sdkTest( + timeout = INCREASED_TIMEOUT_BECAUSE_OF_REAL_ROUTING_TILES_USAGE + ) { + val originalTestRoute = EvRoutesProvider.getBerlinEvRoute( + context, + mockWebServerRule.baseUrl + ) + val onlineCalculationBlocker = CountDownLatch(1) + mockWebServerRule.requestHandlers.add(object : MockRequestHandler { + override fun handle(request: RecordedRequest): MockResponse? { + val routeOptions = try { + RouteOptions.fromUrl(request.requestUrl!!.toUrl()).apply { + coordinatesList() // make sure that coordinates could be parsed + } + } catch (t: Throwable) { + return null + } + onlineCalculationBlocker.await() + return null + } + }) + mockWebServerRule.requestHandlers.add(originalTestRoute.mockWebServerHandler) + withMapboxNavigationAndOfflineTilesForRegion( + OfflineRegions.Berlin, + historyRecorderRule = mapboxHistoryTestRule + ) { navigation -> + navigation.registerRouteAlternativesObserver( + AdvancedAlternativesObserverFromDocumentation(navigation) + ) + navigation.startTripSession() + stayOnPosition( + originalTestRoute.origin.latitude(), + originalTestRoute.origin.longitude(), + 0.0f, + ) { + val requestResult = navigation.requestRoutes(originalTestRoute.routeOptions) + .getSuccessfulResultOrThrowException() + assertEquals(RouterOrigin.Onboard, requestResult.routerOrigin) + navigation.setNavigationRoutesAsync(requestResult.routes) + onlineCalculationBlocker.countDown() + mockWebServerRule.requestHandlers.clear() // don't handle other requests + } + val onlineRoutes = navigation.routesUpdates().first { + it.reason == RoutesExtra.ROUTES_UPDATE_REASON_NEW && + it.navigationRoutes.first().origin == RouterOrigin.Offboard + } + assertEquals(2, onlineRoutes.navigationRoutes.size) + } + } + private fun createExternalAlternatives(): List { return NavigationRoute.create( readRawFileText(context, R.raw.route_response_alternative_continue), diff --git a/libtesting-ui/src/main/java/com/mapbox/navigation/testing/ui/http/MockWebServerRule.kt b/libtesting-ui/src/main/java/com/mapbox/navigation/testing/ui/http/MockWebServerRule.kt index 5805a94b9aa..d83ac2f55f6 100644 --- a/libtesting-ui/src/main/java/com/mapbox/navigation/testing/ui/http/MockWebServerRule.kt +++ b/libtesting-ui/src/main/java/com/mapbox/navigation/testing/ui/http/MockWebServerRule.kt @@ -51,12 +51,13 @@ class MockWebServerRule : TestWatcher() { private fun initDispatcher() { webServer.dispatcher = object : Dispatcher() { override fun dispatch(request: RecordedRequest): MockResponse { - requestHandlers.forEach { + val currentRequestHandlers = requestHandlers.toList() + currentRequestHandlers.forEach { it.handle(request)?.run { return this } } val formattedHandlersBuilder = StringBuilder() - requestHandlers.forEach { + currentRequestHandlers.forEach { formattedHandlersBuilder.append("$it\n|") } return MockResponse().setResponseCode(500)