From 9a3edc14362465b75b1f792718808a07f9c27f6c Mon Sep 17 00:00:00 2001 From: Joel Lappalainen Date: Thu, 4 Jul 2024 14:53:45 +0300 Subject: [PATCH] Add place finder tests for rental --- .../PlaceFinderTraverseVisitor.java | 2 +- .../PlaceFinderTraverseVisitorTest.java | 71 +++++++++++++++++++ .../street/search/state/TestStateBuilder.java | 14 ++++ 3 files changed, 86 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/opentripplanner/routing/graphfinder/PlaceFinderTraverseVisitor.java b/src/main/java/org/opentripplanner/routing/graphfinder/PlaceFinderTraverseVisitor.java index 41b8ea6cbc4..16420a0d9eb 100644 --- a/src/main/java/org/opentripplanner/routing/graphfinder/PlaceFinderTraverseVisitor.java +++ b/src/main/java/org/opentripplanner/routing/graphfinder/PlaceFinderTraverseVisitor.java @@ -31,6 +31,7 @@ public class PlaceFinderTraverseVisitor implements TraverseVisitor private final Set filterByStops; private final Set filterByStations; private final Set filterByRoutes; + private final Set filterByNetwork; private final Set filterByVehicleRental; private final Set seenPatternAtStops = new HashSet<>(); private final Set seenStops = new HashSet<>(); @@ -44,7 +45,6 @@ public class PlaceFinderTraverseVisitor implements TraverseVisitor private final boolean includeStations; private final int maxResults; private final double radiusMeters; - private final Set filterByNetwork; /** * @param transitService A TransitService used in finding information about the diff --git a/src/test/java/org/opentripplanner/routing/graphfinder/PlaceFinderTraverseVisitorTest.java b/src/test/java/org/opentripplanner/routing/graphfinder/PlaceFinderTraverseVisitorTest.java index 0796176d9bb..b69a6533334 100644 --- a/src/test/java/org/opentripplanner/routing/graphfinder/PlaceFinderTraverseVisitorTest.java +++ b/src/test/java/org/opentripplanner/routing/graphfinder/PlaceFinderTraverseVisitorTest.java @@ -13,6 +13,7 @@ import org.opentripplanner.framework.geometry.WgsCoordinate; import org.opentripplanner.framework.i18n.NonLocalizedString; import org.opentripplanner.model.StopTime; +import org.opentripplanner.service.vehiclerental.model.TestVehicleRentalStationBuilder; import org.opentripplanner.street.search.state.TestStateBuilder; import org.opentripplanner.transit.model._data.TransitModelForTest; import org.opentripplanner.transit.model.basic.TransitMode; @@ -280,4 +281,74 @@ void stopsAndStationsWithStopAndStationFilter() { visitor.visitVertex(state1); } + + @Test + void rentalStation() { + var visitor = new PlaceFinderTraverseVisitor( + transitService, + null, + List.of(PlaceType.VEHICLE_RENT), + null, + null, + null, + null, + null, + 1, + 500 + ); + var station = new TestVehicleRentalStationBuilder().build(); + assertEquals(List.of(), visitor.placesFound); + var state1 = TestStateBuilder.ofWalking().rentalStation(station).build(); + visitor.visitVertex(state1); + + var res = visitor.placesFound.stream().map(PlaceAtDistance::place).toList(); + + assertEquals(List.of(station), res); + } + + @Test + void rentalStationWithNetworksFilter() { + var visitor = new PlaceFinderTraverseVisitor( + transitService, + null, + List.of(PlaceType.VEHICLE_RENT), + null, + null, + null, + null, + List.of("Network-1"), + 1, + 500 + ); + var station = new TestVehicleRentalStationBuilder().build(); + assertEquals(List.of(), visitor.placesFound); + var state1 = TestStateBuilder.ofWalking().rentalStation(station).build(); + visitor.visitVertex(state1); + + var res = visitor.placesFound.stream().map(PlaceAtDistance::place).toList(); + + assertEquals(List.of(station), res); + + visitor = + new PlaceFinderTraverseVisitor( + transitService, + null, + List.of(PlaceType.VEHICLE_RENT), + null, + null, + null, + null, + List.of("Network-2"), + 1, + 500 + ); + + assertEquals(List.of(), visitor.placesFound); + state1 = TestStateBuilder.ofWalking().rentalStation(station).build(); + visitor.visitVertex(state1); + + res = visitor.placesFound.stream().map(PlaceAtDistance::place).toList(); + + assertEquals(List.of(), res); + } } diff --git a/src/test/java/org/opentripplanner/street/search/state/TestStateBuilder.java b/src/test/java/org/opentripplanner/street/search/state/TestStateBuilder.java index e43c5a769d0..3750c4619b9 100644 --- a/src/test/java/org/opentripplanner/street/search/state/TestStateBuilder.java +++ b/src/test/java/org/opentripplanner/street/search/state/TestStateBuilder.java @@ -16,6 +16,7 @@ import org.opentripplanner.service.vehiclerental.model.TestFreeFloatingRentalVehicleBuilder; import org.opentripplanner.service.vehiclerental.model.TestVehicleRentalStationBuilder; import org.opentripplanner.service.vehiclerental.model.VehicleRentalPlace; +import org.opentripplanner.service.vehiclerental.model.VehicleRentalStation; import org.opentripplanner.service.vehiclerental.street.StreetVehicleRentalLink; import org.opentripplanner.service.vehiclerental.street.VehicleRentalEdge; import org.opentripplanner.service.vehiclerental.street.VehicleRentalPlaceVertex; @@ -219,6 +220,19 @@ public TestStateBuilder stop() { return arriveAtStop(testModel.stop("stop", count, count).build()); } + /** + * Add a state that arrives at a rental station. + */ + public TestStateBuilder rentalStation(VehicleRentalStation station) { + count++; + var from = (StreetVertex) currentState.vertex; + var to = new VehicleRentalPlaceVertex(station); + + var link = StreetVehicleRentalLink.createStreetVehicleRentalLink(from, to); + currentState = link.traverse(currentState)[0]; + return this; + } + public TestStateBuilder enterStation(String id) { count++; var from = (StreetVertex) currentState.vertex;