|
| 1 | +package com.mapbox.navigation.instrumentation_tests.core |
| 2 | + |
| 3 | +import android.location.Location |
| 4 | +import com.mapbox.navigation.base.options.NavigationOptions |
| 5 | +import com.mapbox.navigation.base.options.RoutingTilesOptions |
| 6 | +import com.mapbox.navigation.base.route.NavigationRoute |
| 7 | +import com.mapbox.navigation.base.route.RouterOrigin |
| 8 | +import com.mapbox.navigation.base.trip.model.RouteProgressState |
| 9 | +import com.mapbox.navigation.core.MapboxNavigation |
| 10 | +import com.mapbox.navigation.core.MapboxNavigationProvider |
| 11 | +import com.mapbox.navigation.instrumentation_tests.R |
| 12 | +import com.mapbox.navigation.instrumentation_tests.activity.EmptyTestActivity |
| 13 | +import com.mapbox.navigation.instrumentation_tests.utils.MapboxNavigationRule |
| 14 | +import com.mapbox.navigation.instrumentation_tests.utils.coroutines.routeProgressUpdates |
| 15 | +import com.mapbox.navigation.instrumentation_tests.utils.coroutines.sdkTest |
| 16 | +import com.mapbox.navigation.instrumentation_tests.utils.coroutines.setNavigationRoutesAndWaitForUpdate |
| 17 | +import com.mapbox.navigation.instrumentation_tests.utils.readRawFileText |
| 18 | +import com.mapbox.navigation.testing.ui.BaseTest |
| 19 | +import com.mapbox.navigation.testing.ui.utils.getMapboxAccessTokenFromResources |
| 20 | +import com.mapbox.navigation.testing.ui.utils.runOnMainSync |
| 21 | +import kotlinx.coroutines.flow.first |
| 22 | +import org.junit.Assert.assertEquals |
| 23 | +import org.junit.Before |
| 24 | +import org.junit.Ignore |
| 25 | +import org.junit.Rule |
| 26 | +import org.junit.Test |
| 27 | +import java.net.URI |
| 28 | + |
| 29 | +class UpcomingRouteObjectsTest : BaseTest<EmptyTestActivity>(EmptyTestActivity::class.java) { |
| 30 | + |
| 31 | + @get:Rule |
| 32 | + val mapboxNavigationRule = MapboxNavigationRule() |
| 33 | + |
| 34 | + private lateinit var mapboxNavigation: MapboxNavigation |
| 35 | + |
| 36 | + override fun setupMockLocation(): Location = mockLocationUpdatesRule.generateLocationUpdate { |
| 37 | + latitude = 48.143406486859135 |
| 38 | + longitude = 11.428011943347627 |
| 39 | + } |
| 40 | + |
| 41 | + @Before |
| 42 | + fun setup() { |
| 43 | + runOnMainSync { |
| 44 | + mapboxNavigation = MapboxNavigationProvider.create( |
| 45 | + NavigationOptions.Builder(activity) |
| 46 | + .accessToken(getMapboxAccessTokenFromResources(activity)) |
| 47 | + .routingTilesOptions( |
| 48 | + RoutingTilesOptions.Builder() |
| 49 | + .tilesBaseUri(URI(mockWebServerRule.baseUrl)) |
| 50 | + .build() |
| 51 | + ) |
| 52 | + .build() |
| 53 | + ) |
| 54 | + } |
| 55 | + } |
| 56 | + |
| 57 | + @Test |
| 58 | + @Ignore("waiting for the NN fix, see NN-449") |
| 59 | + fun distanceToIncidentDoesNotChangeAfterAddingNewWaypointOnTheRouteGeometry() = sdkTest { |
| 60 | + val (oneLegRoute, twoLegsRoute, incidentId) = |
| 61 | + getRoutesFromTheSameOriginButDifferentWaypointsCount() |
| 62 | + |
| 63 | + setRoutesOriginAsCurrentLocation(oneLegRoute, twoLegsRoute) |
| 64 | + |
| 65 | + mapboxNavigation.startTripSession() |
| 66 | + mapboxNavigation.setNavigationRoutesAndWaitForUpdate(oneLegRoute) |
| 67 | + val upcomingIncidentForOneLeg = mapboxNavigation.routeProgressUpdates() |
| 68 | + .first { it.currentState == RouteProgressState.TRACKING } |
| 69 | + .upcomingRoadObjects |
| 70 | + .first { it.roadObject.id == incidentId } |
| 71 | + |
| 72 | + mapboxNavigation.setNavigationRoutesAndWaitForUpdate(twoLegsRoute) |
| 73 | + val upcomingIncidentForTwoLegsRoute = mapboxNavigation.routeProgressUpdates() |
| 74 | + .first { it.currentState == RouteProgressState.TRACKING } |
| 75 | + .upcomingRoadObjects |
| 76 | + .first { it.roadObject.id == incidentId } |
| 77 | + |
| 78 | + assertEquals( |
| 79 | + upcomingIncidentForOneLeg.distanceToStart, |
| 80 | + upcomingIncidentForTwoLegsRoute.distanceToStart |
| 81 | + ) |
| 82 | + } |
| 83 | + |
| 84 | + private fun setRoutesOriginAsCurrentLocation( |
| 85 | + oneLegRoute: List<NavigationRoute>, |
| 86 | + twoLegsRoute: List<NavigationRoute> |
| 87 | + ) { |
| 88 | + val origin = oneLegRoute.first().waypoints!!.first().location() |
| 89 | + assertEquals(origin, twoLegsRoute.first().waypoints!!.first().location()) |
| 90 | + mockLocationUpdatesRule.generateLocationUpdate { |
| 91 | + latitude = origin.latitude() |
| 92 | + longitude = origin.longitude() |
| 93 | + } |
| 94 | + } |
| 95 | + |
| 96 | + private fun getRoutesFromTheSameOriginButDifferentWaypointsCount(): |
| 97 | + Triple<List<NavigationRoute>, List<NavigationRoute>, String> { |
| 98 | + val origin = "11.428011943347627,48.143406486859135" |
| 99 | + val destination = "11.443258702449555,48.14554279886465" |
| 100 | + val routeWithIncident = NavigationRoute.create( |
| 101 | + directionsResponseJson = readRawFileText( |
| 102 | + activity, |
| 103 | + R.raw.route_through_incident_6058002857835914_one_leg |
| 104 | + ), |
| 105 | + routeRequestUrl = "https://api.mapbox.com/directions/v5/mapbox/driving-traffic/" + |
| 106 | + "$origin;$destination" + |
| 107 | + "?access_token=**&alternatives=true" + |
| 108 | + "&annotations=closure,congestion_numeric,congestion,speed,duration,distance" + |
| 109 | + "&geometries=polyline6&language=en&overview=full&steps=true", |
| 110 | + routerOrigin = RouterOrigin.Offboard |
| 111 | + ) |
| 112 | + val routeWithIncidentTwoLegs = NavigationRoute.create( |
| 113 | + directionsResponseJson = readRawFileText( |
| 114 | + activity, |
| 115 | + R.raw.route_through_incident_6058002857835914_two_legs |
| 116 | + ), |
| 117 | + routeRequestUrl = "https://api.mapbox.com/directions/v5/mapbox/driving-traffic/" + |
| 118 | + "$origin;11.42945687746061,48.1436160028498" + |
| 119 | + ";$destination" + |
| 120 | + "?access_token=**&alternatives=true" + |
| 121 | + "&annotations=closure,congestion_numeric,congestion,speed,duration,distance" + |
| 122 | + "&geometries=polyline6&language=en&overview=full&steps=true", |
| 123 | + routerOrigin = RouterOrigin.Offboard |
| 124 | + ) |
| 125 | + val incident = routeWithIncident.first() |
| 126 | + .directionsRoute.legs()!!.first() |
| 127 | + .incidents()!!.first() |
| 128 | + return Triple(routeWithIncident, routeWithIncidentTwoLegs, incident.id()) |
| 129 | + } |
| 130 | +} |
0 commit comments