Skip to content

Commit

Permalink
test short routes
Browse files Browse the repository at this point in the history
  • Loading branch information
VysotskiVadim committed Oct 25, 2023
1 parent 04b729b commit a5bd6af
Showing 1 changed file with 34 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.mapbox.navigation.instrumentation_tests.R
import com.mapbox.navigation.instrumentation_tests.utils.DelayedResponseModifier
import com.mapbox.navigation.instrumentation_tests.utils.http.MockDirectionsRequestHandler
import com.mapbox.navigation.instrumentation_tests.utils.readRawFileText
import com.mapbox.navigation.instrumentation_tests.utils.routes.RoutesProvider
import com.mapbox.navigation.instrumentation_tests.utils.withMapboxNavigation
import com.mapbox.navigation.testing.ui.BaseCoreNoCleanUpTest
import com.mapbox.navigation.testing.ui.utils.coroutines.getSuccessfulResultOrThrowException
Expand Down Expand Up @@ -55,48 +56,41 @@ class LongRoutesSanityTest : BaseCoreNoCleanUpTest() {

@Test
fun requestNewRoutesWhileLongRoutesAreSet() = sdkTest {
val routeOptions = longRouteOptions()
val handler = MockDirectionsRequestHandler(
profile = DirectionsCriteria.PROFILE_DRIVING_TRAFFIC,
lazyJsonResponse = { readRawFileText(context, R.raw.long_route_7k) },
expectedCoordinates = routeOptions.coordinatesList()
)
mockWebServerRule.requestHandlers.add(handler)
val longRoutesOptions = setupLongRoutes()
val shortRoutesOptions = setupShortRoutes()
withMapboxNavigation(
longRoutesOptimisationOptions = LongRoutesOptimisationOptions.OptimiseNavigationForLongRoutes(
responseToParseSizeBytes = 5.megabytesInBytes()
)
) { navigation ->
navigation.setNavigationRoutesAsync(
navigation
.requestRoutes(routeOptions)
.requestRoutes(longRoutesOptions)
.getSuccessfulResultOrThrowException().routes
)
assertEquals(2, navigation.getNavigationRoutes().size)

val newRoutes = navigation.requestRoutes(routeOptions)
val shortRoutes = navigation.requestRoutes(shortRoutesOptions)
assertEquals(2, navigation.getNavigationRoutes().size)

val newRoutes = navigation.requestRoutes(longRoutesOptions)
.getSuccessfulResultOrThrowException()
assertEquals(1, navigation.getNavigationRoutes().size)
}
}

@Test
fun requestNewRoutesWhileLongRoutesArePreviewed() = sdkTest {
val routeOptions = longRouteOptions()
val handler = MockDirectionsRequestHandler(
profile = DirectionsCriteria.PROFILE_DRIVING_TRAFFIC,
lazyJsonResponse = { readRawFileText(context, R.raw.long_route_7k) },
expectedCoordinates = routeOptions.coordinatesList()
)
mockWebServerRule.requestHandlers.add(handler)
val longRoutesOptions = setupLongRoutes()
val shortRoutesOptions = setupShortRoutes()
withMapboxNavigation(
longRoutesOptimisationOptions = LongRoutesOptimisationOptions.OptimiseNavigationForLongRoutes(
responseToParseSizeBytes = 5.megabytesInBytes()
)
) { navigation ->
navigation.setRoutesPreview(
navigation
.requestRoutes(routeOptions)
.requestRoutes(longRoutesOptions)
.getSuccessfulResultOrThrowException().routes
)

Expand All @@ -109,12 +103,26 @@ class LongRoutesSanityTest : BaseCoreNoCleanUpTest() {
.routesList.size
)

val newRoutes = navigation.requestRoutes(routeOptions)
val shortRoutes = navigation.requestRoutes(shortRoutesOptions)
assertEquals(2, navigation.getRoutesPreview()?.routesList?.size)

val newLongRoutes = navigation.requestRoutes(longRoutesOptions)
.getSuccessfulResultOrThrowException()
assertEquals(1, navigation.getRoutesPreview()?.routesList?.size)
}
}

private fun setupLongRoutes(): RouteOptions {
val routeOptions = longRouteOptions()
val handler = MockDirectionsRequestHandler(
profile = DirectionsCriteria.PROFILE_DRIVING_TRAFFIC,
lazyJsonResponse = { readRawFileText(context, R.raw.long_route_7k) },
expectedCoordinates = routeOptions.coordinatesList()
)
mockWebServerRule.requestHandlers.add(handler)
return routeOptions
}

private fun longRouteOptions(): RouteOptions {
val routeOptions = RouteOptions.builder()
.baseUrl(mockWebServerRule.baseUrl) // comment to use real Directions API
Expand All @@ -132,6 +140,14 @@ class LongRoutesSanityTest : BaseCoreNoCleanUpTest() {
.build()
return routeOptions
}

private fun setupShortRoutes(): RouteOptions {
val shortRoute = RoutesProvider.dc_very_short(context)
mockWebServerRule.requestHandlers.addAll(shortRoute.mockRequestHandlers)
return RouteOptions.builder().applyDefaultNavigationOptions()
.coordinatesList(shortRoute.routeWaypoints)
.build()
}
}

private fun Int.megabytesInBytes() = this * 1024 * 1024

0 comments on commit a5bd6af

Please sign in to comment.