OpenTripPlanner/application/src/test/java/org/opentripplanner/routing/graphfinder/PlaceFinderTraverseVisitorTest.java
Leonard Ehrenfried ab17160b38
Fix all package names and imports
# Conflicts:
#	application/src/test-fixtures/java/org/opentripplanner/transit/model/site/TestStopLocation.java
#	application/src/test/java/org/opentripplanner/transit/service/DefaultTransitServiceTest.java

# Conflicts:
#	application/src/ext-test/java/org/opentripplanner/ext/flex/FlexIntegrationTest.java
#	application/src/ext/java/org/opentripplanner/ext/carpooling/model/CarpoolLeg.java
#	application/src/ext/java/org/opentripplanner/ext/flex/FlexTransferIndex.java
#	application/src/ext/java/org/opentripplanner/ext/reportapi/model/TransfersReport.java
#	application/src/main/java/org/opentripplanner/apis/transmodel/model/EnumTypes.java
#	application/src/main/java/org/opentripplanner/graph_builder/GraphBuilder.java
#	application/src/main/java/org/opentripplanner/gtfs/interlining/InterlineProcessor.java
#	application/src/main/java/org/opentripplanner/model/plan/Leg.java
#	application/src/main/java/org/opentripplanner/model/plan/leg/ScheduledTransitLeg.java
#	application/src/main/java/org/opentripplanner/routing/algorithm/mapping/RaptorPathToItineraryMapper.java
#	application/src/main/java/org/opentripplanner/routing/algorithm/raptoradapter/transit/request/RaptorRequestTransferCache.java
#	application/src/main/java/org/opentripplanner/transfer/regular/TransferRepository.java
#	application/src/main/java/org/opentripplanner/transfer/regular/internal/DefaultTransferRepository.java
#	application/src/main/java/org/opentripplanner/transfer/regular/model/PathTransfer.java
#	application/src/test/java/org/opentripplanner/apis/transmodel/mapping/TripRequestMapperTest.java
#	application/src/test/java/org/opentripplanner/routing/algorithm/GraphRoutingTest.java

# Conflicts:
#	application/src/ext-test/java/org/opentripplanner/ext/vectortiles/layers/stops/StopsLayerTest.java
#	application/src/main/java/org/opentripplanner/updater/configure/UpdaterConfigurator.java
#	application/src/test/java/org/opentripplanner/service/vehicleparking/VehicleParkingTestGraphData.java

# Conflicts:
#	application/src/main/java/org/opentripplanner/updater/trip/gtfs/TripTimesUpdater.java

# Conflicts:
#	application/src/test/java/org/opentripplanner/graph_builder/module/islandpruning/SubgraphOnlyFerryTest.java

# Conflicts:
#	application/src/test/java/org/opentripplanner/apis/gtfs/mapping/routerequest/LegacyRouteRequestMapperTest.java
2026-02-16 10:58:51 +01:00

352 lines
10 KiB
Java

package org.opentripplanner.routing.graphfinder;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.opentripplanner.model.plan.PlanTestConstants.T11_00;
import static org.opentripplanner.model.plan.PlanTestConstants.T11_05;
import static org.opentripplanner.model.plan.PlanTestConstants.T11_10;
import static org.opentripplanner.transit.model._data.TimetableRepositoryForTest.id;
import static org.opentripplanner.transit.model._data.TimetableRepositoryForTest.route;
import static org.opentripplanner.transit.model._data.TimetableRepositoryForTest.tripPattern;
import java.util.List;
import org.junit.jupiter.api.Test;
import org.opentripplanner.core.model.i18n.NonLocalizedString;
import org.opentripplanner.model.StopTime;
import org.opentripplanner.service.vehiclerental.model.TestVehicleRentalStationBuilder;
import org.opentripplanner.street.geometry.WgsCoordinate;
import org.opentripplanner.street.search.state.TestStateBuilder;
import org.opentripplanner.transit.model._data.TimetableRepositoryForTest;
import org.opentripplanner.transit.model.basic.TransitMode;
import org.opentripplanner.transit.model.network.Route;
import org.opentripplanner.transit.model.network.StopPattern;
import org.opentripplanner.transit.model.network.TripPatternBuilder;
import org.opentripplanner.transit.model.site.RegularStop;
import org.opentripplanner.transit.model.site.Station;
import org.opentripplanner.transit.service.DefaultTransitService;
import org.opentripplanner.transit.service.TimetableRepository;
public class PlaceFinderTraverseVisitorTest {
static TimetableRepositoryForTest model = TimetableRepositoryForTest.of();
static final Station STATION1 = Station.of(id("S1"))
.withName(new NonLocalizedString("Station 1"))
.withCoordinate(1.1, 1.1)
.build();
static final Station STATION2 = Station.of(id("S2"))
.withName(new NonLocalizedString("Station 2"))
.withCoordinate(1.1, 1.1)
.build();
static final RegularStop STOP1 = model
.stop("stop-1")
.withCoordinate(new WgsCoordinate(1, 1))
.withParentStation(STATION1)
.build();
static final RegularStop STOP2 = model
.stop("stop-2")
.withCoordinate(1.001, 1.001)
.withParentStation(STATION2)
.build();
static final RegularStop STOP3 = model.stop("stop-3").withCoordinate(1.002, 1.002).build();
static final RegularStop STOP4 = model.stop("stop-4").withCoordinate(1.003, 1.003).build();
static final Route R = route("r").build();
static final TimetableRepository TIMETABLE_REPO = new TimetableRepository(
model.siteRepositoryBuilder().withRegularStops(List.of(STOP1, STOP2, STOP3, STOP4)).build()
);
static {
TripPatternBuilder t = tripPattern("trip", R);
var st1 = new StopTime();
st1.setStop(STOP1);
st1.setArrivalTime(T11_00);
var st2 = new StopTime();
st2.setStop(STOP2);
st2.setArrivalTime(T11_05);
t.withStopPattern(new StopPattern(List.of(st1, st2)));
TIMETABLE_REPO.addTripPattern(id("tp1"), t.build());
var st3 = new StopTime();
st3.setStop(STOP3);
st3.setArrivalTime(T11_10);
t.withStopPattern(new StopPattern(List.of(st3)));
TIMETABLE_REPO.addTripPattern(id("tp2"), t.build());
var st4 = new StopTime();
st4.setStop(STOP4);
st4.setArrivalTime(T11_10);
t.withStopPattern(new StopPattern(List.of(st4)));
TIMETABLE_REPO.addTripPattern(id("tp3"), t.build());
TIMETABLE_REPO.index();
}
static DefaultTransitService transitService = new DefaultTransitService(TIMETABLE_REPO);
@Test
void stopsOnly() {
var visitor = new PlaceFinderTraverseVisitor(
transitService,
List.of(TransitMode.BUS),
List.of(PlaceType.STOP),
null,
null,
null,
null,
null,
1,
500
);
assertEquals(List.of(), visitor.placesFound);
var state1 = TestStateBuilder.ofWalking().streetEdge().stop(STOP1).build();
visitor.visitVertex(state1);
var state2 = TestStateBuilder.ofWalking().streetEdge().streetEdge().stop(STOP2).build();
visitor.visitVertex(state2);
var res = visitor.placesFound.stream().map(PlaceAtDistance::place).toList();
assertEquals(List.of(STOP1, STOP2), res);
visitor.visitVertex(state1);
}
@Test
void stationsOnly() {
var visitor = new PlaceFinderTraverseVisitor(
transitService,
List.of(TransitMode.BUS),
List.of(PlaceType.STATION),
null,
null,
null,
null,
null,
1,
500
);
assertEquals(List.of(), visitor.placesFound);
var state1 = TestStateBuilder.ofWalking().streetEdge().stop(STOP1).build();
visitor.visitVertex(state1);
var state2 = TestStateBuilder.ofWalking().streetEdge().streetEdge().stop(STOP2).build();
visitor.visitVertex(state2);
var res = visitor.placesFound.stream().map(PlaceAtDistance::place).toList();
assertEquals(List.of(STATION1, STATION2), res);
visitor.visitVertex(state1);
}
@Test
void stopsAndStations() {
var visitor = new PlaceFinderTraverseVisitor(
transitService,
List.of(TransitMode.BUS),
List.of(PlaceType.STOP, PlaceType.STATION),
null,
null,
null,
null,
null,
1,
500
);
assertEquals(List.of(), visitor.placesFound);
var state1 = TestStateBuilder.ofWalking().streetEdge().stop(STOP1).build();
visitor.visitVertex(state1);
var state2 = TestStateBuilder.ofWalking().streetEdge().streetEdge().stop(STOP3).build();
visitor.visitVertex(state2);
// Revisited stop should not be added to found places
visitor.visitVertex(state1);
var res = visitor.placesFound.stream().map(PlaceAtDistance::place).toList();
assertEquals(List.of(STATION1, STOP3), res);
visitor.visitVertex(state1);
}
@Test
void stopsAndStationsWithStationFilter() {
var visitor = new PlaceFinderTraverseVisitor(
transitService,
List.of(TransitMode.BUS),
List.of(PlaceType.STOP, PlaceType.STATION),
List.of(STOP2.getId(), STOP3.getId()),
List.of(STATION1.getId()),
null,
null,
null,
1,
500
);
assertEquals(List.of(), visitor.placesFound);
var state1 = TestStateBuilder.ofWalking().streetEdge().stop(STOP1).build();
visitor.visitVertex(state1);
var state2 = TestStateBuilder.ofWalking().streetEdge().streetEdge().stop(STOP2).build();
visitor.visitVertex(state2);
var state3 = TestStateBuilder.ofWalking().streetEdge().streetEdge().stop(STOP3).build();
visitor.visitVertex(state3);
var res = visitor.placesFound.stream().map(PlaceAtDistance::place).toList();
// Stop 3 should be included as it is not part of a station.
// Stop 2 should not be included as its parent station is not included in the station filter.
assertEquals(List.of(STATION1, STOP3), res);
visitor.visitVertex(state1);
}
@Test
void stopsAndStationsWithStopFilter() {
var visitor = new PlaceFinderTraverseVisitor(
transitService,
List.of(TransitMode.BUS),
List.of(PlaceType.STOP, PlaceType.STATION),
List.of(STOP2.getId()),
null,
null,
null,
null,
1,
500
);
assertEquals(List.of(), visitor.placesFound);
var state1 = TestStateBuilder.ofWalking().streetEdge().stop(STOP1).build();
visitor.visitVertex(state1);
var state2 = TestStateBuilder.ofWalking().streetEdge().streetEdge().stop(STOP2).build();
visitor.visitVertex(state2);
var state3 = TestStateBuilder.ofWalking().streetEdge().streetEdge().stop(STOP3).build();
visitor.visitVertex(state3);
var res = visitor.placesFound.stream().map(PlaceAtDistance::place).toList();
// Stop 3 should not be included as it is included in the stop filter
assertEquals(List.of(STATION1, STATION2), res);
visitor.visitVertex(state1);
}
@Test
void stopsAndStationsWithStopAndStationFilter() {
var visitor = new PlaceFinderTraverseVisitor(
transitService,
List.of(TransitMode.BUS),
List.of(PlaceType.STOP, PlaceType.STATION),
List.of(STOP4.getId()),
List.of(STATION1.getId()),
null,
null,
null,
1,
500
);
assertEquals(List.of(), visitor.placesFound);
var state1 = TestStateBuilder.ofWalking().streetEdge().stop(STOP1).build();
visitor.visitVertex(state1);
var state2 = TestStateBuilder.ofWalking().streetEdge().streetEdge().stop(STOP2).build();
visitor.visitVertex(state2);
var state3 = TestStateBuilder.ofWalking().streetEdge().streetEdge().stop(STOP3).build();
visitor.visitVertex(state3);
var state4 = TestStateBuilder.ofWalking().streetEdge().streetEdge().stop(STOP4).build();
visitor.visitVertex(state4);
var res = visitor.placesFound.stream().map(PlaceAtDistance::place).toList();
assertEquals(List.of(STATION1, STOP4), res);
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);
}
}