Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce module tests for GTFS-RT #5871

Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package org.opentripplanner.ext.siri;

import java.time.Duration;
import java.time.LocalDate;
import java.util.List;
import org.opentripplanner.DateTimeHelper;
import org.opentripplanner.transit.model.framework.FeedScopedId;
import org.opentripplanner.transit.model.network.TripPattern;
import org.opentripplanner.transit.model.timetable.Trip;
import org.opentripplanner.transit.model.timetable.TripTimes;
import org.opentripplanner.updater.TimetableSnapshotSourceParameters;
import org.opentripplanner.updater.spi.UpdateResult;
import org.opentripplanner.updater.trip.RealtimeTestData;
import uk.org.siri.siri20.EstimatedTimetableDeliveryStructure;

public class SiriRealtimeTestEnvironment {

public final RealtimeTestData testData = new RealtimeTestData();

private static final TimetableSnapshotSourceParameters PARAMETERS = new TimetableSnapshotSourceParameters(
Duration.ZERO,
false
);
private final SiriTimetableSnapshotSource snapshotSource;
private final DateTimeHelper dateTimeHelper;

public SiriRealtimeTestEnvironment() {
snapshotSource = new SiriTimetableSnapshotSource(PARAMETERS, testData.transitModel);
dateTimeHelper = new DateTimeHelper(testData.timeZone, RealtimeTestData.SERVICE_DATE);
}

public EntityResolver getEntityResolver() {
return new EntityResolver(testData.getTransitService(), testData.getFeedId());
}

public TripPattern getPatternForTrip(FeedScopedId tripId) {
return getPatternForTrip(tripId, RealtimeTestData.SERVICE_DATE);
}

public TripPattern getPatternForTrip(FeedScopedId tripId, LocalDate serviceDate) {
var transitService = testData.getTransitService();
var trip = transitService.getTripOnServiceDateById(tripId);
return transitService.getPatternForTrip(trip.getTrip(), serviceDate);
}

/**
* Find the current TripTimes for a trip id on the default serviceDate
*/
public TripTimes getTripTimesForTrip(Trip trip) {
return testData.getTripTimesForTrip(trip.getId(), RealtimeTestData.SERVICE_DATE);
}

/**
* Find the current TripTimes for a trip id on the default serviceDate
*/
public TripTimes getTripTimesForTrip(String id) {
leonardehrenfried marked this conversation as resolved.
Show resolved Hide resolved
return testData.getTripTimesForTrip(testData.id(id), RealtimeTestData.SERVICE_DATE);
}
leonardehrenfried marked this conversation as resolved.
Show resolved Hide resolved

public UpdateResult applyEstimatedTimetable(List<EstimatedTimetableDeliveryStructure> updates) {
return snapshotSource.applyEstimatedTimetable(
null,
getEntityResolver(),
testData.getFeedId(),
false,
updates
);
}

public UpdateResult applyEstimatedTimetableWithFuzzyMatcher(
List<EstimatedTimetableDeliveryStructure> updates
) {
SiriFuzzyTripMatcher siriFuzzyTripMatcher = new SiriFuzzyTripMatcher(
testData.getTransitService()
);
return applyEstimatedTimetable(updates, siriFuzzyTripMatcher);
}

public DateTimeHelper getDateTimeHelper() {
return dateTimeHelper;
}

private UpdateResult applyEstimatedTimetable(
List<EstimatedTimetableDeliveryStructure> updates,
SiriFuzzyTripMatcher siriFuzzyTripMatcher
) {
return this.snapshotSource.applyEstimatedTimetable(
siriFuzzyTripMatcher,
getEntityResolver(),
testData.getFeedId(),
false,
updates
);
}
}
Loading
Loading