|
28 | 28 | import org.opentripplanner.street.model.edge.Edge; |
29 | 29 | import org.opentripplanner.street.model.edge.StreetStationCentroidLink; |
30 | 30 | import org.opentripplanner.street.model.vertex.StationCentroidVertex; |
| 31 | +import org.opentripplanner.street.model.vertex.TemporaryStreetLocation; |
31 | 32 | import org.opentripplanner.street.model.vertex.TransitStopVertex; |
32 | 33 | import org.opentripplanner.street.model.vertex.Vertex; |
33 | 34 | import org.opentripplanner.street.search.TraverseMode; |
@@ -288,6 +289,41 @@ void walkingBetterThanTransitException() { |
288 | 289 | assertEquals(RoutingErrorCode.WALKING_BETTER_THAN_TRANSIT, fromError.code); |
289 | 290 | } |
290 | 291 |
|
| 292 | + @Test |
| 293 | + void nonExistingPlaceIdWithCoordinatesShouldFallbackToCoordinates() { |
| 294 | + var container = new TemporaryVerticesContainer(); |
| 295 | + var nonExistingStopId = new FeedScopedId("F", "NonExistingStop"); |
| 296 | + |
| 297 | + // Create locations with both a non-existing stop ID and valid coordinates |
| 298 | + var from = new GenericLocation("From", nonExistingStopId, stopA.getLat(), stopA.getLon()); |
| 299 | + var to = new GenericLocation( |
| 300 | + "To", |
| 301 | + new FeedScopedId("F", "AnotherNonExisting"), |
| 302 | + stopD.getLat(), |
| 303 | + stopD.getLon() |
| 304 | + ); |
| 305 | + |
| 306 | + var request = LinkingContextRequest.of() |
| 307 | + .withFrom(from) |
| 308 | + .withTo(to) |
| 309 | + .withDirectMode(StreetMode.WALK) |
| 310 | + .build(); |
| 311 | + |
| 312 | + // This should NOT throw an exception - it should fall back to using coordinates |
| 313 | + var linkingContext = linkingContextFactory.create(container, request); |
| 314 | + |
| 315 | + // Verify that vertices were created from the coordinates |
| 316 | + var fromVertices = linkingContext.findVertices(from); |
| 317 | + assertThat(fromVertices).hasSize(1); |
| 318 | + assertTemporaryVertexOnStop(fromVertices.stream().findFirst().get(), stopA); |
| 319 | + |
| 320 | + var toVertices = linkingContext.findVertices(to); |
| 321 | + assertThat(toVertices).hasSize(1); |
| 322 | + assertTemporaryVertexOnStop(toVertices.stream().findFirst().get(), stopD); |
| 323 | + |
| 324 | + container.close(); |
| 325 | + } |
| 326 | + |
291 | 327 | private static Graph buildGraph(Station station, RegularStop... stops) { |
292 | 328 | var graph = new Graph(); |
293 | 329 | var left = StreetModelForTest.intersectionVertex(CENTER.asJtsCoordinate()); |
@@ -323,6 +359,12 @@ private static Graph buildGraph(Station station, RegularStop... stops) { |
323 | 359 | return graph; |
324 | 360 | } |
325 | 361 |
|
| 362 | + private void assertTemporaryVertexOnStop(Vertex vertex, RegularStop stop) { |
| 363 | + assertThat(vertex).isInstanceOf(TemporaryStreetLocation.class); |
| 364 | + assertEquals(stop.getLat(), vertex.getLat(), 0.0001); |
| 365 | + assertEquals(stop.getLon(), vertex.getLon(), 0.0001); |
| 366 | + } |
| 367 | + |
326 | 368 | private RegularStop toStop(Set<? extends Vertex> fromVertices) { |
327 | 369 | assertThat(fromVertices).hasSize(1); |
328 | 370 | var id = ((TransitStopVertex) List.copyOf(fromVertices).getFirst()).getId(); |
|
0 commit comments