Skip to content

Commit

Permalink
Add validation for scheduled data in SIRI update
Browse files Browse the repository at this point in the history
  • Loading branch information
vpaturet committed May 29, 2024
1 parent bf34653 commit e7e38e4
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,31 @@ void testAddJourney() {
assertEquals(4 * 60, tripTimes.getDepartureTime(1));
}

@Test
void testAddedJourneyWithInvalidScheduledData() {
var env = new RealtimeTestEnvironment();

// Create an extra journey with invalid planned data (travel back in time)
// and valid real time data
var createExtraJourney = new SiriEtBuilder(env.getDateTimeHelper())
.withEstimatedVehicleJourneyCode("newJourney")
.withIsExtraJourney(true)
.withOperatorRef(env.operator1Id.getId())
.withLineRef(env.route1Id.getId())
.withEstimatedCalls(builder ->
builder
.call(env.stopA1)
.departAimedExpected("10:58", "10:48")
.call(env.stopB1)
.arriveAimedExpected("10:08", "10:58")
)
.buildEstimatedTimetableDeliveries();

var result = env.applyEstimatedTimetable(createExtraJourney);
assertEquals(0, result.successful());
assertFailure(result, UpdateError.UpdateErrorType.NEGATIVE_HOP_TIME);
}

@Test
void testReplaceJourney() {
var env = new RealtimeTestEnvironment();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,11 @@ Result<TripUpdate, UpdateError> build() {
aimedStopTimes,
transitModel.getDeduplicator()
);
// validate the scheduled trip times
// they are in general superseded by real-time trip times
// but in case of trip cancellation, OTP will fall back to scheduled trip times
// therefore they must be valid
tripTimes.validateNonIncreasingTimes();
tripTimes.setServiceCode(transitModel.getServiceCodes().get(trip.getServiceId()));
pattern.add(tripTimes);
RealTimeTripTimes updatedTripTimes = tripTimes.copyScheduledTimes();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,9 @@ public void setRealTimeState(final RealTimeState realTimeState) {
* found.
*/
public void validateNonIncreasingTimes() {
final int nStops = arrivalTimes.length;
final int nStops = arrivalTimes != null
? arrivalTimes.length
: scheduledTripTimes.getNumStops();
int prevDep = -9_999_999;
for (int s = 0; s < nStops; s++) {
final int arr = getArrivalTime(s);
Expand Down

0 comments on commit e7e38e4

Please sign in to comment.