Skip to content

Commit

Permalink
Merge branch 'septa-fares' into upstream-merge-2023-10-09
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardehrenfried committed Oct 9, 2023
2 parents a642678 + 33c8c9c commit df1962e
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 61 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/smoke-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
sleep: 15
- name: portland
# have to sleep longer since computing geofencing zones takes a while
sleep: 80
sleep: 125

steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -987,7 +987,7 @@
<dependency>
<groupId>org.opentripplanner</groupId>
<artifactId>otp-client</artifactId>
<version>0.0.10</version>
<version>0.0.14</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
3 changes: 1 addition & 2 deletions smoke-tests/denver/router-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
{
"type": "vehicle-positions",
"url": "https://www.rtd-denver.com/files/gtfs-rt/VehiclePosition.pb",
"feedId": "denver",
"frequencySec": 60
"feedId": "denver"
}
]
}
1 change: 0 additions & 1 deletion smoke-tests/portland/otp-config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"otpFeatures" : {
"SandboxAPILegacyGraphQLApi": true
}
}
12 changes: 9 additions & 3 deletions smoke-tests/portland/router-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,29 @@
"updaters": [
{
"type": "real-time-alerts",
"frequencySec": 60,
"earlyStartSec": 864000,
"url": "https://trimet.org/transweb/ws/V1/FeedSpecAlerts/includeFuture/true/suppressSystemWideAlerts/true/",
"feedId": "TriMet"
},
{
"type": "stop-time-updater",
"frequencySec": 30,
"frequency": "30s",
"url": "https://trimet.org/transweb/ws/V1/TripUpdate",
"feedId": "TriMet"
},
{
"type": "vehicle-rental",
"frequencySec": 90,
"frequency": "90s",
"sourceType": "gbfs",
"url": "https://mds.bird.co/gbfs/v2/public/portland/gbfs.json",
"geofencingZones": "true"
},
{
"type": "vehicle-rental",
"frequency": "90s",
"sourceType": "gbfs",
"url": "https://gbfs.spin.pm/api/gbfs/v2_3/portland/gbfs",
"geofencingZones": "true"
}
]
}
1 change: 0 additions & 1 deletion smoke-tests/septa/otp-config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"otpFeatures" : {
"SandboxAPILegacyGraphQLApi": true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ public class HoustonSmokeTest {
@Test
public void routeFromSouthToNorth() {
var modes = Set.of(TRANSIT, WALK);
SmokeTest.basicRouteTest(
var plan = SmokeTest.basicRouteTest(
new SmokeTestRequest(galvestonRoad, northLindale, modes),
List.of("WALK", "BUS", "BUS", "WALK", "TRAM", "WALK")
);

SmokeTest.assertThatAllTransitLegsHaveFareProducts(plan);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ public class PortlandSmokeTest {
public void railTrip() {
// this used to be across the city by since the train is interrupted in April '23 this is a
// much shorter trip
SmokeTest.basicRouteTest(
var plan = SmokeTest.basicRouteTest(
new SmokeTestRequest(cennentenial, hazelwood, Set.of(TRAM, WALK)),
List.of("WALK", "TRAM", "WALK")
);

SmokeTest.assertThatAllTransitLegsHaveFareProducts(plan);
}

/**
Expand Down
28 changes: 27 additions & 1 deletion src/test/java/org/opentripplanner/smoketest/SeptaSmokeTest.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
package org.opentripplanner.smoketest;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.opentripplanner.client.model.RequestMode.BICYCLE_RENT;
import static org.opentripplanner.client.model.RequestMode.TRANSIT;
import static org.opentripplanner.client.model.RequestMode.WALK;

import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.opentripplanner.client.model.Coordinate;
import org.opentripplanner.client.model.TripPlan.FareProductUse;
import org.opentripplanner.smoketest.util.SmokeTestRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* This smoke test expects an OTP installation running at localhost:8080
Expand All @@ -18,6 +24,8 @@
@Tag("septa")
public class SeptaSmokeTest {

private static final Logger LOG = LoggerFactory.getLogger(SeptaSmokeTest.class);

Coordinate airport = new Coordinate(39.876151, -75.245189);
Coordinate stPetersCemetary = new Coordinate(39.98974, -75.09515);

Expand All @@ -27,10 +35,28 @@ public class SeptaSmokeTest {
@Test
public void routeFromAirportToNorthPhiladelphia() {
var modes = Set.of(TRANSIT, WALK);
SmokeTest.basicRouteTest(
var plan = SmokeTest.basicRouteTest(
new SmokeTestRequest(airport, stPetersCemetary, modes),
List.of("WALK", "RAIL", "RAIL", "WALK", "SUBWAY", "WALK")
);
var products = plan
.itineraries()
.stream()
.flatMap(i -> i.legs().stream())
.flatMap(leg -> leg.fareProducts().stream())
.map(FareProductUse::product)
.toList();

assertFalse(products.isEmpty());

var prices = products
.stream()
.map(p -> p.price().amount().doubleValue())
.collect(Collectors.toSet());

LOG.info("Received fare products {}", products);

assertTrue(prices.contains(2.5d));
}

@Test
Expand Down
52 changes: 3 additions & 49 deletions src/test/java/org/opentripplanner/smoketest/SmokeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,18 @@
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.module.paramnames.ParameterNamesModule;
import java.io.IOException;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.LocalTime;
import java.time.ZoneId;
import java.time.temporal.TemporalAdjusters;
import java.util.List;
import org.opentripplanner.api.json.JSONObjectMapperProvider;
import org.opentripplanner.api.resource.DebugOutput;
import org.opentripplanner.client.OtpApiClient;
import org.opentripplanner.client.model.TripPlan;
import org.opentripplanner.client.model.TripPlan.Itinerary;
import org.opentripplanner.client.model.VehicleRentalStation;
import org.opentripplanner.client.parameters.TripPlanParameters;
import org.opentripplanner.model.fare.ItineraryFares;
import org.opentripplanner.smoketest.util.SmokeTestRequest;

/**
Expand All @@ -38,25 +27,11 @@
*/
public class SmokeTest {

public static final ObjectMapper mapper;
public static final OtpApiClient API_CLIENT = new OtpApiClient(
ZoneId.of("America/New_York"),
"http://localhost:8080"
);

static {
var provider = new JSONObjectMapperProvider();

SimpleModule module = new SimpleModule("SmokeTests");
module.addDeserializer(ItineraryFares.class, new FareDeserializer());
module.addDeserializer(DebugOutput.class, new DebugOutputDeserializer());

mapper = provider.getContext(null);
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
mapper.registerModule(new ParameterNamesModule(JsonCreator.Mode.PROPERTIES));
mapper.registerModule(module);
}

/**
* In order to have somewhat predictable results we get the route for the next Monday.
* <p>
Expand Down Expand Up @@ -135,29 +110,8 @@ static void assertThereArePatternsWithVehiclePositions() {
}
}

/**
* The Fare class is a little hard to deserialize, so we have a custom deserializer as we don't
* run any assertions against the fares. (That is done during unit tests.)
*/
static class FareDeserializer extends JsonDeserializer<ItineraryFares> {

@Override
public ItineraryFares deserialize(
JsonParser jsonParser,
DeserializationContext deserializationContext
) {
return null;
}
}

static class DebugOutputDeserializer extends JsonDeserializer<DebugOutput> {

@Override
public DebugOutput deserialize(
JsonParser jsonParser,
DeserializationContext deserializationContext
) {
return null;
}
static void assertThatAllTransitLegsHaveFareProducts(TripPlan plan) {
var transitLegs = plan.transitItineraries().stream().flatMap(i -> i.transitLegs().stream());
transitLegs.forEach(leg -> assertFalse(leg.fareProducts().isEmpty()));
}
}

0 comments on commit df1962e

Please sign in to comment.