Skip to content

Commit

Permalink
separate bus and coach API
Browse files Browse the repository at this point in the history
  • Loading branch information
miklcct committed Oct 17, 2024
1 parent f4244a5 commit 5cee140
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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),
Expand Down Expand Up @@ -40,6 +42,10 @@ public enum ApiRequestMode {
}

public Collection<TransitMode> getTransitModes() {
if (this == BUS && OTPFeature.GtfsCoach.isOff()) {
return List.of(TransitMode.BUS, TransitMode.COACH);
}

return transitModes;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -144,9 +145,36 @@ static Stream<Arguments> transportModesCases() {
);
}

static Stream<Arguments> 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<Map<String, Object>> modes, String expectedFilters) {
OTPFeature.GtfsCoach.testOff(() -> testModes(modes, expectedFilters));
}

@ParameterizedTest
@MethodSource("transportModesCasesWithCoach")
void modesWithCoach(List<Map<String, Object>> modes, String expectedFilters) {
OTPFeature.GtfsCoach.testOn(() -> testModes(modes, expectedFilters));
}

private void testModes(List<Map<String, Object>> modes, String expectedFilters) {
Map<String, Object> arguments = Map.of("transportModes", modes);

var routeRequest = LegacyRouteRequestMapper.toRouteRequest(
Expand Down

0 comments on commit 5cee140

Please sign in to comment.