From 5cee1405fe49b3bf2cf80c71d7039896452e84a7 Mon Sep 17 00:00:00 2001 From: Michael Tsang Date: Thu, 17 Oct 2024 13:04:39 +0100 Subject: [PATCH] separate bus and coach API --- .../api/parameter/ApiRequestMode.java | 8 +++++- .../LegacyRouteRequestMapperTest.java | 28 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/application/src/main/java/org/opentripplanner/api/parameter/ApiRequestMode.java b/application/src/main/java/org/opentripplanner/api/parameter/ApiRequestMode.java index 6e19b106033..c78e5dfb66f 100644 --- a/application/src/main/java/org/opentripplanner/api/parameter/ApiRequestMode.java +++ b/application/src/main/java/org/opentripplanner/api/parameter/ApiRequestMode.java @@ -2,6 +2,7 @@ import java.util.Collection; import java.util.List; +import org.opentripplanner.framework.application.OTPFeature; import org.opentripplanner.transit.model.basic.TransitMode; public enum ApiRequestMode { @@ -12,7 +13,8 @@ public enum ApiRequestMode { TRAM(TransitMode.TRAM), SUBWAY(TransitMode.SUBWAY), RAIL(TransitMode.RAIL), - BUS(TransitMode.BUS, TransitMode.COACH), + BUS(TransitMode.BUS), + COACH(TransitMode.COACH), FERRY(TransitMode.FERRY), CABLE_CAR(TransitMode.CABLE_CAR), GONDOLA(TransitMode.GONDOLA), @@ -40,6 +42,10 @@ public enum ApiRequestMode { } public Collection getTransitModes() { + if (this == BUS && OTPFeature.GtfsCoach.isOff()) { + return List.of(TransitMode.BUS, TransitMode.COACH); + } + return transitModes; } } diff --git a/application/src/test/java/org/opentripplanner/apis/gtfs/mapping/routerequest/LegacyRouteRequestMapperTest.java b/application/src/test/java/org/opentripplanner/apis/gtfs/mapping/routerequest/LegacyRouteRequestMapperTest.java index 3ca29f7c531..b42ea828462 100644 --- a/application/src/test/java/org/opentripplanner/apis/gtfs/mapping/routerequest/LegacyRouteRequestMapperTest.java +++ b/application/src/test/java/org/opentripplanner/apis/gtfs/mapping/routerequest/LegacyRouteRequestMapperTest.java @@ -27,6 +27,7 @@ import org.opentripplanner.apis.gtfs.TestRoutingService; import org.opentripplanner.apis.gtfs.generated.GraphQLTypes; import org.opentripplanner.ext.fares.impl.DefaultFareService; +import org.opentripplanner.framework.application.OTPFeature; import org.opentripplanner.model.plan.PlanTestConstants; import org.opentripplanner.routing.api.request.RouteRequest; import org.opentripplanner.routing.api.request.preference.TimeSlopeSafetyTriangle; @@ -144,9 +145,36 @@ static Stream transportModesCases() { ); } + static Stream transportModesCasesWithCoach() { + return Stream.of( + of( + List.of(mode("BUS")), + "[TransitFilterRequest{select: [SelectRequest{transportModes: [BUS]}]}]" + ), + of( + List.of(mode("BUS"), mode("COACH")), + "[TransitFilterRequest{select: [SelectRequest{transportModes: [BUS, COACH]}]}]" + ), + of( + List.of(mode("BUS"), mode("MONORAIL")), + "[TransitFilterRequest{select: [SelectRequest{transportModes: [BUS, MONORAIL]}]}]" + ) + ); + } + @ParameterizedTest @MethodSource("transportModesCases") void modes(List> modes, String expectedFilters) { + OTPFeature.GtfsCoach.testOff(() -> testModes(modes, expectedFilters)); + } + + @ParameterizedTest + @MethodSource("transportModesCasesWithCoach") + void modesWithCoach(List> modes, String expectedFilters) { + OTPFeature.GtfsCoach.testOn(() -> testModes(modes, expectedFilters)); + } + + private void testModes(List> modes, String expectedFilters) { Map arguments = Map.of("transportModes", modes); var routeRequest = LegacyRouteRequestMapper.toRouteRequest(