Skip to content
Merged
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
@@ -0,0 +1,130 @@
package com.mapbox.navigation.instrumentation_tests.core

import android.location.Location
import com.mapbox.navigation.base.options.NavigationOptions
import com.mapbox.navigation.base.options.RoutingTilesOptions
import com.mapbox.navigation.base.route.NavigationRoute
import com.mapbox.navigation.base.route.RouterOrigin
import com.mapbox.navigation.base.trip.model.RouteProgressState
import com.mapbox.navigation.core.MapboxNavigation
import com.mapbox.navigation.core.MapboxNavigationProvider
import com.mapbox.navigation.instrumentation_tests.R
import com.mapbox.navigation.instrumentation_tests.activity.EmptyTestActivity
import com.mapbox.navigation.instrumentation_tests.utils.MapboxNavigationRule
import com.mapbox.navigation.instrumentation_tests.utils.coroutines.routeProgressUpdates
import com.mapbox.navigation.instrumentation_tests.utils.coroutines.sdkTest
import com.mapbox.navigation.instrumentation_tests.utils.coroutines.setNavigationRoutesAndWaitForUpdate
import com.mapbox.navigation.instrumentation_tests.utils.readRawFileText
import com.mapbox.navigation.testing.ui.BaseTest
import com.mapbox.navigation.testing.ui.utils.getMapboxAccessTokenFromResources
import com.mapbox.navigation.testing.ui.utils.runOnMainSync
import kotlinx.coroutines.flow.first
import org.junit.Assert.assertEquals
import org.junit.Before
import org.junit.Ignore
import org.junit.Rule
import org.junit.Test
import java.net.URI

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

@get:Rule
val mapboxNavigationRule = MapboxNavigationRule()

private lateinit var mapboxNavigation: MapboxNavigation

override fun setupMockLocation(): Location = mockLocationUpdatesRule.generateLocationUpdate {
latitude = 48.143406486859135
longitude = 11.428011943347627
}

@Before
fun setup() {
runOnMainSync {
mapboxNavigation = MapboxNavigationProvider.create(
NavigationOptions.Builder(activity)
.accessToken(getMapboxAccessTokenFromResources(activity))
.routingTilesOptions(
RoutingTilesOptions.Builder()
.tilesBaseUri(URI(mockWebServerRule.baseUrl))
.build()
)
.build()
)
}
}

@Test
@Ignore("waiting for the NN fix, see NN-449")
fun distanceToIncidentDoesNotChangeAfterAddingNewWaypointOnTheRouteGeometry() = sdkTest {
val (oneLegRoute, twoLegsRoute, incidentId) =
getRoutesFromTheSameOriginButDifferentWaypointsCount()

setRoutesOriginAsCurrentLocation(oneLegRoute, twoLegsRoute)

mapboxNavigation.startTripSession()
mapboxNavigation.setNavigationRoutesAndWaitForUpdate(oneLegRoute)
val upcomingIncidentForOneLeg = mapboxNavigation.routeProgressUpdates()
.first { it.currentState == RouteProgressState.TRACKING }
.upcomingRoadObjects
.first { it.roadObject.id == incidentId }

mapboxNavigation.setNavigationRoutesAndWaitForUpdate(twoLegsRoute)
val upcomingIncidentForTwoLegsRoute = mapboxNavigation.routeProgressUpdates()
.first { it.currentState == RouteProgressState.TRACKING }
.upcomingRoadObjects
.first { it.roadObject.id == incidentId }

assertEquals(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we expect them to be equal?
The routes are different, do they have the same geometry (at least until the incident)? If yes, it should be specified in the comments. If the geometry is different, distanceToStart may be different (it's distance along the route, not direct distance, right?).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we expect them to be equal?

Current location doesn't change and both routers heads to the same direction thought the same incident.

Copy link
Contributor Author

@VysotskiVadim VysotskiVadim Jan 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If yes, it should be specified in the comments.

Thank you for the feedback. I will try to improve readability of the test

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dzinad , I updated the test. Do you understand what and why it checks now?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My point is that if we have the same origin and the same incident location, when we add a waypoint, distances may still differ. See the drawing.
And it's still not clear that the geometries from the origin until the incident are exactly the same.
Or am I missing something?
telegram-cloud-photo-size-2-5375224774822839390-y

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see your point, thank you. The routes I test follow the same roads. Like
image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the waypoint is strictly on the route's geometry? Could you mention it somewhere in the comment?

upcomingIncidentForOneLeg.distanceToStart,
upcomingIncidentForTwoLegsRoute.distanceToStart
)
}

private fun setRoutesOriginAsCurrentLocation(
oneLegRoute: List<NavigationRoute>,
twoLegsRoute: List<NavigationRoute>
) {
val origin = oneLegRoute.first().waypoints!!.first().location()
assertEquals(origin, twoLegsRoute.first().waypoints!!.first().location())
mockLocationUpdatesRule.generateLocationUpdate {
latitude = origin.latitude()
longitude = origin.longitude()
}
}

private fun getRoutesFromTheSameOriginButDifferentWaypointsCount():
Triple<List<NavigationRoute>, List<NavigationRoute>, String> {
val origin = "11.428011943347627,48.143406486859135"
val destination = "11.443258702449555,48.14554279886465"
val routeWithIncident = NavigationRoute.create(
directionsResponseJson = readRawFileText(
activity,
R.raw.route_through_incident_6058002857835914_one_leg
),
routeRequestUrl = "https://api.mapbox.com/directions/v5/mapbox/driving-traffic/" +
"$origin;$destination" +
"?access_token=**&alternatives=true" +
"&annotations=closure,congestion_numeric,congestion,speed,duration,distance" +
"&geometries=polyline6&language=en&overview=full&steps=true",
routerOrigin = RouterOrigin.Offboard
)
val routeWithIncidentTwoLegs = NavigationRoute.create(
directionsResponseJson = readRawFileText(
activity,
R.raw.route_through_incident_6058002857835914_two_legs
),
routeRequestUrl = "https://api.mapbox.com/directions/v5/mapbox/driving-traffic/" +
"$origin;11.42945687746061,48.1436160028498" +
";$destination" +
"?access_token=**&alternatives=true" +
"&annotations=closure,congestion_numeric,congestion,speed,duration,distance" +
"&geometries=polyline6&language=en&overview=full&steps=true",
routerOrigin = RouterOrigin.Offboard
)
val incident = routeWithIncident.first()
.directionsRoute.legs()!!.first()
.incidents()!!.first()
return Triple(routeWithIncident, routeWithIncidentTwoLegs, incident.id())
}
}
Loading