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

NAVAND-1599: Android Nav SDK tests #7625

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion gradle/dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -44,13 +47,15 @@ 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
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
Expand Down Expand Up @@ -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<NavigationRoute> {
return NavigationRoute.create(
readRawFileText(context, R.raw.route_response_alternative_continue),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading