From 49ac4b7acf477733f7556a0c03b825535d89eacf Mon Sep 17 00:00:00 2001 From: Leonard Ehrenfried Date: Mon, 17 Jun 2024 13:27:05 +0200 Subject: [PATCH 01/21] Move invalid trip id test --- .../trip/TimetableSnapshotSourceTest.java | 36 ----------------- .../rejection/InvalidTripIdTest.java | 40 +++++++++++++++++++ 2 files changed, 40 insertions(+), 36 deletions(-) create mode 100644 src/test/java/org/opentripplanner/updater/trip/moduletests/rejection/InvalidTripIdTest.java diff --git a/src/test/java/org/opentripplanner/updater/trip/TimetableSnapshotSourceTest.java b/src/test/java/org/opentripplanner/updater/trip/TimetableSnapshotSourceTest.java index 1dad90b416b..ef45c442f0a 100644 --- a/src/test/java/org/opentripplanner/updater/trip/TimetableSnapshotSourceTest.java +++ b/src/test/java/org/opentripplanner/updater/trip/TimetableSnapshotSourceTest.java @@ -22,7 +22,6 @@ import java.time.Duration; import java.time.LocalDate; import java.util.List; -import java.util.stream.Stream; import javax.annotation.Nonnull; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Nested; @@ -109,41 +108,6 @@ public void testGetSnapshotWithMaxSnapshotFrequencyCleared() { assertNotSame(snapshot, newSnapshot); } - /** - * This test just asserts that invalid trip ids don't throw an exception and are ignored instead - */ - @Test - public void invalidTripId() { - var updater = new TimetableSnapshotSource( - TimetableSnapshotSourceParameters.DEFAULT, - transitModel - ); - - Stream - .of("", null) - .forEach(id -> { - var tripDescriptorBuilder = TripDescriptor.newBuilder(); - tripDescriptorBuilder.setTripId(""); - tripDescriptorBuilder.setScheduleRelationship( - TripDescriptor.ScheduleRelationship.SCHEDULED - ); - var tripUpdateBuilder = TripUpdate.newBuilder(); - - tripUpdateBuilder.setTrip(tripDescriptorBuilder); - var tripUpdate = tripUpdateBuilder.build(); - - var result = updater.applyTripUpdates( - TRIP_MATCHER_NOOP, - REQUIRED_NO_DATA, - DIFFERENTIAL, - List.of(tripUpdate), - feedId - ); - - assertEquals(0, result.successful()); - }); - } - @Test public void testHandleModifiedTrip() { // GIVEN diff --git a/src/test/java/org/opentripplanner/updater/trip/moduletests/rejection/InvalidTripIdTest.java b/src/test/java/org/opentripplanner/updater/trip/moduletests/rejection/InvalidTripIdTest.java new file mode 100644 index 00000000000..58f9fb2ff55 --- /dev/null +++ b/src/test/java/org/opentripplanner/updater/trip/moduletests/rejection/InvalidTripIdTest.java @@ -0,0 +1,40 @@ +package org.opentripplanner.updater.trip.moduletests.rejection; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import com.google.transit.realtime.GtfsRealtime; +import java.util.stream.Stream; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +import org.opentripplanner.updater.trip.RealtimeTestEnvironment; + +public class InvalidTripIdTest { + + static Stream invalidCases() { + return Stream.of(null, "", " "); + } + + /** + * This test just asserts that invalid trip ids don't throw an exception and are ignored instead + */ + @ParameterizedTest(name = "tripId=\"{0}\"") + @MethodSource("invalidCases") + void invalidTripId(String tripId) { + var env = RealtimeTestEnvironment.gtfs(); + var tripDescriptorBuilder = GtfsRealtime.TripDescriptor.newBuilder(); + if (tripId != null) { + tripDescriptorBuilder.setTripId(tripId); + } + tripDescriptorBuilder.setScheduleRelationship( + GtfsRealtime.TripDescriptor.ScheduleRelationship.SCHEDULED + ); + var tripUpdateBuilder = GtfsRealtime.TripUpdate.newBuilder(); + + tripUpdateBuilder.setTrip(tripDescriptorBuilder); + var tripUpdate = tripUpdateBuilder.build(); + + var result = env.applyTripUpdate(tripUpdate); + + assertEquals(0, result.successful()); + } +} From 3f79d0e357b3c8b0ff444d35efbcbcd5a4fdefc7 Mon Sep 17 00:00:00 2001 From: Leonard Ehrenfried Date: Mon, 17 Jun 2024 13:31:03 +0200 Subject: [PATCH 02/21] Move assertions into separate class --- .../siri/SiriTimetableSnapshotSourceTest.java | 18 +----------------- .../test/support/UpdateResultAssertions.java | 13 +++++++++++++ 2 files changed, 14 insertions(+), 17 deletions(-) create mode 100644 src/test/java/org/opentripplanner/test/support/UpdateResultAssertions.java diff --git a/src/ext-test/java/org/opentripplanner/ext/siri/SiriTimetableSnapshotSourceTest.java b/src/ext-test/java/org/opentripplanner/ext/siri/SiriTimetableSnapshotSourceTest.java index a069f5c6656..73f6b92ffe7 100644 --- a/src/ext-test/java/org/opentripplanner/ext/siri/SiriTimetableSnapshotSourceTest.java +++ b/src/ext-test/java/org/opentripplanner/ext/siri/SiriTimetableSnapshotSourceTest.java @@ -1,24 +1,12 @@ package org.opentripplanner.ext.siri; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.opentripplanner.test.support.UpdateResultAssertions.assertFailure; -import java.util.List; -import java.util.Set; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; -import org.opentripplanner.model.PickDrop; import org.opentripplanner.transit.model.timetable.RealTimeState; -import org.opentripplanner.transit.model.timetable.Trip; -import org.opentripplanner.transit.model.timetable.TripOnServiceDate; -import org.opentripplanner.transit.model.timetable.TripTimes; -import org.opentripplanner.transit.model.timetable.TripTimesFactory; -import org.opentripplanner.transit.service.DefaultTransitService; -import org.opentripplanner.transit.service.StopModel; -import org.opentripplanner.transit.service.TransitModel; -import org.opentripplanner.transit.service.TransitService; -import org.opentripplanner.updater.TimetableSnapshotSourceParameters; import org.opentripplanner.updater.spi.UpdateError; -import org.opentripplanner.updater.spi.UpdateResult; import org.opentripplanner.updater.trip.RealtimeTestEnvironment; class SiriTimetableSnapshotSourceTest { @@ -402,10 +390,6 @@ void testExtraUnknownStop() { assertFailure(UpdateError.UpdateErrorType.INVALID_STOP_SEQUENCE, result); } - private void assertFailure(UpdateError.UpdateErrorType expectedError, UpdateResult result) { - assertEquals(Set.of(expectedError), result.failures().keySet()); - } - private static SiriEtBuilder updatedJourneyBuilder(RealtimeTestEnvironment env) { return new SiriEtBuilder(env.getDateTimeHelper()) .withEstimatedCalls(builder -> diff --git a/src/test/java/org/opentripplanner/test/support/UpdateResultAssertions.java b/src/test/java/org/opentripplanner/test/support/UpdateResultAssertions.java new file mode 100644 index 00000000000..e41660b0443 --- /dev/null +++ b/src/test/java/org/opentripplanner/test/support/UpdateResultAssertions.java @@ -0,0 +1,13 @@ +package org.opentripplanner.test.support; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.Set; +import org.opentripplanner.updater.spi.UpdateError; +import org.opentripplanner.updater.spi.UpdateResult; + +public class UpdateResultAssertions { + public static void assertFailure(UpdateError.UpdateErrorType expectedError, UpdateResult result) { + assertEquals(Set.of(expectedError), result.failures().keySet()); + } +} From c442d17a6392e51eb06b1d5c9283910234327595 Mon Sep 17 00:00:00 2001 From: Leonard Ehrenfried Date: Mon, 17 Jun 2024 14:06:47 +0200 Subject: [PATCH 03/21] Move skipped tests --- .../test/support/UpdateResultAssertions.java | 13 ++ .../updater/trip/RealtimeTestEnvironment.java | 8 +- .../trip/TimetableSnapshotSourceTest.java | 215 ------------------ .../trip/moduletests/delay/DelayedTest.java | 71 +++++- .../trip/moduletests/delay/SkippedTest.java | 128 ++++++++++- .../rejection/InvalidInputTest.java | 5 +- 6 files changed, 213 insertions(+), 227 deletions(-) diff --git a/src/test/java/org/opentripplanner/test/support/UpdateResultAssertions.java b/src/test/java/org/opentripplanner/test/support/UpdateResultAssertions.java index e41660b0443..c6be0406ae3 100644 --- a/src/test/java/org/opentripplanner/test/support/UpdateResultAssertions.java +++ b/src/test/java/org/opentripplanner/test/support/UpdateResultAssertions.java @@ -1,13 +1,26 @@ package org.opentripplanner.test.support; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.Set; import org.opentripplanner.updater.spi.UpdateError; import org.opentripplanner.updater.spi.UpdateResult; public class UpdateResultAssertions { + public static void assertFailure(UpdateError.UpdateErrorType expectedError, UpdateResult result) { assertEquals(Set.of(expectedError), result.failures().keySet()); } + + public static UpdateResult assertSuccess(UpdateResult updateResult) { + var errorCodes = updateResult.failures().keySet(); + assertEquals( + Set.of(), + errorCodes, + "Update result should have no error codes but had %s".formatted(errorCodes) + ); + assertTrue(updateResult.successful() > 0); + return updateResult; + } } diff --git a/src/test/java/org/opentripplanner/updater/trip/RealtimeTestEnvironment.java b/src/test/java/org/opentripplanner/updater/trip/RealtimeTestEnvironment.java index c2fb31e2dfb..fdd726eb624 100644 --- a/src/test/java/org/opentripplanner/updater/trip/RealtimeTestEnvironment.java +++ b/src/test/java/org/opentripplanner/updater/trip/RealtimeTestEnvironment.java @@ -15,6 +15,7 @@ import org.opentripplanner.ext.siri.EntityResolver; import org.opentripplanner.ext.siri.SiriFuzzyTripMatcher; import org.opentripplanner.ext.siri.SiriTimetableSnapshotSource; +import org.opentripplanner.framework.i18n.I18NString; import org.opentripplanner.graph_builder.issue.api.DataImportIssueStore; import org.opentripplanner.model.StopTime; import org.opentripplanner.model.TimetableSnapshot; @@ -300,7 +301,12 @@ private UpdateResult applyEstimatedTimetable( } private Trip createTrip(String id, Route route, List stops) { - var trip = Trip.of(id(id)).withRoute(route).withServiceId(SERVICE_ID).build(); + var trip = Trip + .of(id(id)) + .withRoute(route) + .withHeadsign(I18NString.of("Headsign of %s".formatted(id))) + .withServiceId(SERVICE_ID) + .build(); var tripOnServiceDate = TripOnServiceDate .of(trip.getId()) diff --git a/src/test/java/org/opentripplanner/updater/trip/TimetableSnapshotSourceTest.java b/src/test/java/org/opentripplanner/updater/trip/TimetableSnapshotSourceTest.java index ef45c442f0a..9cf69821aff 100644 --- a/src/test/java/org/opentripplanner/updater/trip/TimetableSnapshotSourceTest.java +++ b/src/test/java/org/opentripplanner/updater/trip/TimetableSnapshotSourceTest.java @@ -2,7 +2,6 @@ import static com.google.transit.realtime.GtfsRealtime.TripDescriptor.ScheduleRelationship.ADDED; import static com.google.transit.realtime.GtfsRealtime.TripDescriptor.ScheduleRelationship.CANCELED; -import static com.google.transit.realtime.GtfsRealtime.TripDescriptor.ScheduleRelationship.SCHEDULED; import static com.google.transit.realtime.GtfsRealtime.TripUpdate.StopTimeUpdate.ScheduleRelationship.SKIPPED; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -29,7 +28,6 @@ import org.opentripplanner.ConstantsForTests; import org.opentripplanner.TestOtpModel; import org.opentripplanner._support.time.ZoneIds; -import org.opentripplanner.framework.i18n.NonLocalizedString; import org.opentripplanner.framework.time.ServiceDateUtils; import org.opentripplanner.model.PickDrop; import org.opentripplanner.model.Timetable; @@ -310,219 +308,6 @@ public void testHandleModifiedTrip() { } } - @Nested - class Scheduled { - - @Test - public void scheduled() { - // GIVEN - - String scheduledTripId = "1.1"; - - var builder = new TripUpdateBuilder( - scheduledTripId, - SERVICE_DATE, - SCHEDULED, - transitModel.getTimeZone() - ) - .addDelayedStopTime(1, 0) - .addDelayedStopTime(2, 60, 80) - .addDelayedStopTime(3, 90, 90); - - var tripUpdate = builder.build(); - - var updater = defaultUpdater(); - - // WHEN - updater.applyTripUpdates( - TRIP_MATCHER_NOOP, - REQUIRED_NO_DATA, - DIFFERENTIAL, - List.of(tripUpdate), - feedId - ); - - // THEN - final TimetableSnapshot snapshot = updater.getTimetableSnapshot(); - - final FeedScopedId tripId = new FeedScopedId(feedId, scheduledTripId); - final Trip trip = transitModel.getTransitModelIndex().getTripForId().get(tripId); - final TripPattern originalTripPattern = transitModel - .getTransitModelIndex() - .getPatternForTrip() - .get(trip); - - final Timetable originalTimetableForToday = snapshot.resolve( - originalTripPattern, - SERVICE_DATE - ); - final Timetable originalTimetableScheduled = snapshot.resolve(originalTripPattern, null); - - assertNotSame(originalTimetableForToday, originalTimetableScheduled); - - final int originalTripIndexScheduled = originalTimetableScheduled.getTripIndex(tripId); - assertTrue( - originalTripIndexScheduled > -1, - "Original trip should be found in scheduled time table" - ); - final TripTimes originalTripTimesScheduled = originalTimetableScheduled.getTripTimes( - originalTripIndexScheduled - ); - assertFalse( - originalTripTimesScheduled.isCanceledOrDeleted(), - "Original trip times should not be canceled in scheduled time table" - ); - assertEquals(RealTimeState.SCHEDULED, originalTripTimesScheduled.getRealTimeState()); - - final int originalTripIndexForToday = originalTimetableForToday.getTripIndex(tripId); - assertTrue( - originalTripIndexForToday > -1, - "Original trip should be found in time table for service date" - ); - final TripTimes originalTripTimesForToday = originalTimetableForToday.getTripTimes( - originalTripIndexForToday - ); - assertEquals(RealTimeState.UPDATED, originalTripTimesForToday.getRealTimeState()); - assertEquals(0, originalTripTimesForToday.getArrivalDelay(0)); - assertEquals(0, originalTripTimesForToday.getDepartureDelay(0)); - assertEquals(60, originalTripTimesForToday.getArrivalDelay(1)); - assertEquals(80, originalTripTimesForToday.getDepartureDelay(1)); - assertEquals(90, originalTripTimesForToday.getArrivalDelay(2)); - assertEquals(90, originalTripTimesForToday.getDepartureDelay(2)); - } - - @Test - public void scheduledTripWithSkippedAndNoData() { - // GIVEN - - String scheduledTripId = "1.1"; - - var builder = new TripUpdateBuilder( - scheduledTripId, - SERVICE_DATE, - SCHEDULED, - transitModel.getTimeZone() - ) - .addNoDataStop(1) - .addSkippedStop(2) - .addNoDataStop(3); - - var tripUpdate = builder.build(); - - var updater = defaultUpdater(); - - // WHEN - updater.applyTripUpdates( - TRIP_MATCHER_NOOP, - REQUIRED_NO_DATA, - DIFFERENTIAL, - List.of(tripUpdate), - feedId - ); - - // THEN - final TimetableSnapshot snapshot = updater.getTimetableSnapshot(); - - // Original trip pattern - { - final FeedScopedId tripId = new FeedScopedId(feedId, scheduledTripId); - final Trip trip = transitModel.getTransitModelIndex().getTripForId().get(tripId); - final TripPattern originalTripPattern = transitModel - .getTransitModelIndex() - .getPatternForTrip() - .get(trip); - - final Timetable originalTimetableForToday = snapshot.resolve( - originalTripPattern, - SERVICE_DATE - ); - final Timetable originalTimetableScheduled = snapshot.resolve(originalTripPattern, null); - - assertNotSame(originalTimetableForToday, originalTimetableScheduled); - - final int originalTripIndexScheduled = originalTimetableScheduled.getTripIndex(tripId); - assertTrue( - originalTripIndexScheduled > -1, - "Original trip should be found in scheduled time table" - ); - final TripTimes originalTripTimesScheduled = originalTimetableScheduled.getTripTimes( - originalTripIndexScheduled - ); - assertFalse( - originalTripTimesScheduled.isCanceledOrDeleted(), - "Original trip times should not be canceled in scheduled time table" - ); - assertEquals(RealTimeState.SCHEDULED, originalTripTimesScheduled.getRealTimeState()); - - final int originalTripIndexForToday = originalTimetableForToday.getTripIndex(tripId); - assertTrue( - originalTripIndexForToday > -1, - "Original trip should be found in time table for service date" - ); - final TripTimes originalTripTimesForToday = originalTimetableForToday.getTripTimes( - originalTripIndexForToday - ); - assertTrue( - originalTripTimesForToday.isDeleted(), - "Original trip times should be deleted in time table for service date" - ); - // original trip should be deleted - assertEquals(RealTimeState.DELETED, originalTripTimesForToday.getRealTimeState()); - } - - // New trip pattern - { - final TripPattern newTripPattern = snapshot.getRealtimeAddedTripPattern( - new FeedScopedId(feedId, scheduledTripId), - SERVICE_DATE - ); - assertNotNull(newTripPattern, "New trip pattern should be found"); - - final Timetable newTimetableForToday = snapshot.resolve(newTripPattern, SERVICE_DATE); - final Timetable newTimetableScheduled = snapshot.resolve(newTripPattern, null); - - assertNotSame(newTimetableForToday, newTimetableScheduled); - - assertTrue(newTripPattern.canBoard(0)); - assertFalse(newTripPattern.canBoard(1)); - assertTrue(newTripPattern.canBoard(2)); - - assertEquals(new NonLocalizedString("foo"), newTripPattern.getTripHeadsign()); - assertEquals( - newTripPattern.getOriginalTripPattern().getTripHeadsign(), - newTripPattern.getTripHeadsign() - ); - - final int newTimetableForTodayModifiedTripIndex = newTimetableForToday.getTripIndex( - scheduledTripId - ); - assertTrue( - newTimetableForTodayModifiedTripIndex > -1, - "New trip should be found in time table for service date" - ); - - var newTripTimes = newTimetableForToday.getTripTimes(newTimetableForTodayModifiedTripIndex); - assertEquals(RealTimeState.UPDATED, newTripTimes.getRealTimeState()); - - assertEquals( - -1, - newTimetableScheduled.getTripIndex(scheduledTripId), - "New trip should not be found in scheduled time table" - ); - - assertEquals(0, newTripTimes.getArrivalDelay(0)); - assertEquals(0, newTripTimes.getDepartureDelay(0)); - assertEquals(0, newTripTimes.getArrivalDelay(1)); - assertEquals(0, newTripTimes.getDepartureDelay(1)); - assertEquals(0, newTripTimes.getArrivalDelay(2)); - assertEquals(0, newTripTimes.getDepartureDelay(2)); - assertTrue(newTripTimes.isNoDataStop(0)); - assertTrue(newTripTimes.isCancelledStop(1)); - assertTrue(newTripTimes.isNoDataStop(2)); - } - } - } - @Nested class Added { diff --git a/src/test/java/org/opentripplanner/updater/trip/moduletests/delay/DelayedTest.java b/src/test/java/org/opentripplanner/updater/trip/moduletests/delay/DelayedTest.java index 4cfe1e5500d..5752e4941be 100644 --- a/src/test/java/org/opentripplanner/updater/trip/moduletests/delay/DelayedTest.java +++ b/src/test/java/org/opentripplanner/updater/trip/moduletests/delay/DelayedTest.java @@ -2,26 +2,32 @@ import static com.google.transit.realtime.GtfsRealtime.TripDescriptor.ScheduleRelationship.SCHEDULED; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotSame; import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.opentripplanner.test.support.UpdateResultAssertions.assertSuccess; +import static org.opentripplanner.updater.trip.RealtimeTestEnvironment.SERVICE_DATE; import org.junit.jupiter.api.Test; import org.opentripplanner.model.Timetable; import org.opentripplanner.model.TimetableSnapshot; +import org.opentripplanner.transit.model.network.TripPattern; import org.opentripplanner.transit.model.timetable.RealTimeState; +import org.opentripplanner.transit.model.timetable.TripTimes; import org.opentripplanner.updater.trip.RealtimeTestEnvironment; import org.opentripplanner.updater.trip.TripUpdateBuilder; /** * Delays should be applied to the first trip but should leave the second trip untouched. */ -public class DelayedTest { +class DelayedTest { private static final int DELAY = 1; private static final int STOP_SEQUENCE = 1; @Test - public void delayed() { + void singleStopDelay() { var env = RealtimeTestEnvironment.gtfs(); var tripUpdate = new TripUpdateBuilder( @@ -85,4 +91,65 @@ public void delayed() { assertEquals(RealTimeState.SCHEDULED, realtime.getTripTimes(tripIndex).getRealTimeState()); } } + + /** + * Tests delays to multiple stop times, where arrival and departure do not have the same delay. + */ + @Test + void complexDelay() { + var env = RealtimeTestEnvironment.gtfs(); + + String tripId = env.trip2.getId().getId(); + + var builder = new TripUpdateBuilder(tripId, SERVICE_DATE, SCHEDULED, env.timeZone) + .addDelayedStopTime(0, 0) + .addDelayedStopTime(1, 60, 80) + .addDelayedStopTime(2, 90, 90); + + var tripUpdate = builder.build(); + + assertSuccess(env.applyTripUpdate(tripUpdate)); + + // THEN + final TimetableSnapshot snapshot = env.getTimetableSnapshot(); + + final TripPattern originalTripPattern = env.transitModel + .getTransitModelIndex() + .getPatternForTrip() + .get(env.trip2); + + final Timetable originalTimetableForToday = snapshot.resolve(originalTripPattern, SERVICE_DATE); + final Timetable originalTimetableScheduled = snapshot.resolve(originalTripPattern, null); + + assertNotSame(originalTimetableForToday, originalTimetableScheduled); + + final int originalTripIndexScheduled = originalTimetableScheduled.getTripIndex(tripId); + assertTrue( + originalTripIndexScheduled > -1, + "Original trip should be found in scheduled time table" + ); + final TripTimes originalTripTimesScheduled = originalTimetableScheduled.getTripTimes( + originalTripIndexScheduled + ); + assertFalse( + originalTripTimesScheduled.isCanceledOrDeleted(), + "Original trip times should not be canceled in scheduled time table" + ); + assertEquals(RealTimeState.SCHEDULED, originalTripTimesScheduled.getRealTimeState()); + + final int originalTripIndexForToday = originalTimetableForToday.getTripIndex(tripId); + assertTrue( + originalTripIndexForToday > -1, + "Original trip should be found in time table for service date" + ); + + assertEquals( + "SCHEDULED | A1 0:01 0:01:01 | B1 0:01:10 0:01:11 | C1 0:01:20 0:01:21", + env.getScheduledTimetable(env.trip2.getId()) + ); + assertEquals( + "UPDATED | A1 0:01 0:01:01 | B1 0:02:10 0:02:31 | C1 0:02:50 0:02:51", + env.getRealtimeTimetable(env.trip2) + ); + } } diff --git a/src/test/java/org/opentripplanner/updater/trip/moduletests/delay/SkippedTest.java b/src/test/java/org/opentripplanner/updater/trip/moduletests/delay/SkippedTest.java index 9afb7e76261..4424d47495b 100644 --- a/src/test/java/org/opentripplanner/updater/trip/moduletests/delay/SkippedTest.java +++ b/src/test/java/org/opentripplanner/updater/trip/moduletests/delay/SkippedTest.java @@ -3,12 +3,16 @@ import static com.google.transit.realtime.GtfsRealtime.TripDescriptor.ScheduleRelationship.SCHEDULED; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNotSame; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.opentripplanner.test.support.UpdateResultAssertions.assertSuccess; +import static org.opentripplanner.updater.trip.RealtimeTestEnvironment.SERVICE_DATE; import static org.opentripplanner.updater.trip.UpdateIncrementality.DIFFERENTIAL; import org.junit.jupiter.api.Test; +import org.opentripplanner.framework.i18n.NonLocalizedString; import org.opentripplanner.model.Timetable; import org.opentripplanner.model.TimetableSnapshot; import org.opentripplanner.transit.model.framework.FeedScopedId; @@ -40,9 +44,8 @@ public void scheduledTripWithSkippedAndScheduled() { .addDelayedStopTime(2, 90) .build(); - var result = env.applyTripUpdate(tripUpdate); + assertSuccess(env.applyTripUpdate(tripUpdate)); - assertEquals(1, result.successful()); final TimetableSnapshot snapshot = env.getTimetableSnapshot(); @@ -144,9 +147,7 @@ public void scheduledTripWithPreviouslySkipped() { .addDelayedStopTime(2, 90) .build(); - var result = env.applyTripUpdate(tripUpdate, DIFFERENTIAL); - - assertEquals(1, result.successful()); + var result = assertSuccess(env.applyTripUpdate(tripUpdate, DIFFERENTIAL)); // Create update to the same trip but now the skipped stop is no longer skipped var scheduledBuilder = new TripUpdateBuilder( @@ -162,7 +163,7 @@ public void scheduledTripWithPreviouslySkipped() { tripUpdate = scheduledBuilder.build(); // apply the update with the previously skipped stop now scheduled - result = env.applyTripUpdate(tripUpdate, DIFFERENTIAL); + result = assertSuccess(env.applyTripUpdate(tripUpdate, DIFFERENTIAL)); assertEquals(1, result.successful()); // Check that the there is no longer a realtime added trip pattern for the trip and that the @@ -222,4 +223,119 @@ public void scheduledTripWithPreviouslySkipped() { assertEquals(90, originalTripTimesForToday.getDepartureDelay(2)); } } + + /** + * Tests a mixture of SKIPPED and NO_DATA. + */ + @Test + public void skippedNoData() { + var env = RealtimeTestEnvironment.gtfs(); + + final FeedScopedId tripId = env.trip2.getId(); + var builder = new TripUpdateBuilder(tripId.getId(), SERVICE_DATE, SCHEDULED, env.timeZone) + .addNoDataStop(0) + .addSkippedStop(1) + .addNoDataStop(2); + + var tripUpdate = builder.build(); + + assertSuccess(env.applyTripUpdate(tripUpdate)); + + // THEN + var snapshot = env.getTimetableSnapshot(); + + // Original trip pattern + { + final TripPattern originalTripPattern = env.transitModel + .getTransitModelIndex() + .getPatternForTrip() + .get(env.trip2); + + final Timetable originalTimetableForToday = snapshot.resolve( + originalTripPattern, + SERVICE_DATE + ); + final Timetable originalTimetableScheduled = snapshot.resolve(originalTripPattern, null); + + assertNotSame(originalTimetableForToday, originalTimetableScheduled); + + final int originalTripIndexScheduled = originalTimetableScheduled.getTripIndex(tripId); + assertTrue( + originalTripIndexScheduled > -1, + "Original trip should be found in scheduled time table" + ); + final TripTimes originalTripTimesScheduled = originalTimetableScheduled.getTripTimes( + originalTripIndexScheduled + ); + assertFalse( + originalTripTimesScheduled.isCanceledOrDeleted(), + "Original trip times should not be canceled in scheduled time table" + ); + assertEquals(RealTimeState.SCHEDULED, originalTripTimesScheduled.getRealTimeState()); + + final int originalTripIndexForToday = originalTimetableForToday.getTripIndex(tripId); + assertTrue( + originalTripIndexForToday > -1, + "Original trip should be found in time table for service date" + ); + final TripTimes originalTripTimesForToday = originalTimetableForToday.getTripTimes( + originalTripIndexForToday + ); + assertTrue( + originalTripTimesForToday.isDeleted(), + "Original trip times should be deleted in time table for service date" + ); + // original trip should be deleted + assertEquals(RealTimeState.DELETED, originalTripTimesForToday.getRealTimeState()); + } + + // New trip pattern + { + final TripPattern newTripPattern = snapshot.getRealtimeAddedTripPattern(tripId, SERVICE_DATE); + assertNotNull(newTripPattern, "New trip pattern should be found"); + + final Timetable newTimetableForToday = snapshot.resolve(newTripPattern, SERVICE_DATE); + final Timetable newTimetableScheduled = snapshot.resolve(newTripPattern, null); + + assertNotSame(newTimetableForToday, newTimetableScheduled); + + assertTrue(newTripPattern.canBoard(0)); + assertFalse(newTripPattern.canBoard(1)); + assertTrue(newTripPattern.canBoard(2)); + + assertEquals( + new NonLocalizedString("Headsign of TestTrip2"), + newTripPattern.getTripHeadsign() + ); + assertEquals( + newTripPattern.getOriginalTripPattern().getTripHeadsign(), + newTripPattern.getTripHeadsign() + ); + + final int newTimetableForTodayModifiedTripIndex = newTimetableForToday.getTripIndex(tripId); + assertTrue( + newTimetableForTodayModifiedTripIndex > -1, + "New trip should be found in time table for service date" + ); + + var newTripTimes = newTimetableForToday.getTripTimes(newTimetableForTodayModifiedTripIndex); + assertEquals(RealTimeState.UPDATED, newTripTimes.getRealTimeState()); + + assertEquals( + -1, + newTimetableScheduled.getTripIndex(tripId), + "New trip should not be found in scheduled time table" + ); + + assertEquals(0, newTripTimes.getArrivalDelay(0)); + assertEquals(0, newTripTimes.getDepartureDelay(0)); + assertEquals(0, newTripTimes.getArrivalDelay(1)); + assertEquals(0, newTripTimes.getDepartureDelay(1)); + assertEquals(0, newTripTimes.getArrivalDelay(2)); + assertEquals(0, newTripTimes.getDepartureDelay(2)); + assertTrue(newTripTimes.isNoDataStop(0)); + assertTrue(newTripTimes.isCancelledStop(1)); + assertTrue(newTripTimes.isNoDataStop(2)); + } + } } diff --git a/src/test/java/org/opentripplanner/updater/trip/moduletests/rejection/InvalidInputTest.java b/src/test/java/org/opentripplanner/updater/trip/moduletests/rejection/InvalidInputTest.java index 00831333943..d0b3ad5dc31 100644 --- a/src/test/java/org/opentripplanner/updater/trip/moduletests/rejection/InvalidInputTest.java +++ b/src/test/java/org/opentripplanner/updater/trip/moduletests/rejection/InvalidInputTest.java @@ -3,12 +3,12 @@ import static com.google.transit.realtime.GtfsRealtime.TripDescriptor.ScheduleRelationship.SCHEDULED; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.opentripplanner.test.support.UpdateResultAssertions.assertFailure; import static org.opentripplanner.updater.spi.UpdateError.UpdateErrorType.NO_SERVICE_ON_DATE; import static org.opentripplanner.updater.trip.RealtimeTestEnvironment.SERVICE_DATE; import java.time.LocalDate; import java.util.List; -import java.util.Set; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; import org.opentripplanner.updater.trip.RealtimeTestEnvironment; @@ -40,7 +40,6 @@ public void invalidTripDate(LocalDate date) { var snapshot = env.getTimetableSnapshot(); assertTrue(snapshot.isEmpty()); assertEquals(1, result.failed()); - var errors = result.failures().keySet(); - assertEquals(Set.of(NO_SERVICE_ON_DATE), errors); + assertFailure(NO_SERVICE_ON_DATE, result); } } From 7cb284b43b936ecd40ed37931e82c4c697fe185b Mon Sep 17 00:00:00 2001 From: Leonard Ehrenfried Date: Mon, 17 Jun 2024 14:30:35 +0200 Subject: [PATCH 04/21] Move ADDED tests --- .../updater/trip/RealtimeTestEnvironment.java | 9 +- .../trip/TimetableSnapshotSourceTest.java | 217 ------------------ .../trip/moduletests/addition/AddedTest.java | 207 +++++++++++++++++ .../trip/moduletests/delay/SkippedTest.java | 1 - .../rejection/InvalidInputTest.java | 2 - 5 files changed, 213 insertions(+), 223 deletions(-) create mode 100644 src/test/java/org/opentripplanner/updater/trip/moduletests/addition/AddedTest.java diff --git a/src/test/java/org/opentripplanner/updater/trip/RealtimeTestEnvironment.java b/src/test/java/org/opentripplanner/updater/trip/RealtimeTestEnvironment.java index fdd726eb624..98f339a4cc7 100644 --- a/src/test/java/org/opentripplanner/updater/trip/RealtimeTestEnvironment.java +++ b/src/test/java/org/opentripplanner/updater/trip/RealtimeTestEnvironment.java @@ -56,16 +56,19 @@ public final class RealtimeTestEnvironment { ); public static final LocalDate SERVICE_DATE = LocalDate.of(2024, 5, 8); public static final FeedScopedId SERVICE_ID = TransitModelForTest.id("CAL_1"); + public static final String STOP_A1_ID = "A1"; + public static final String STOP_B1_ID = "B1"; + public static final String STOP_C1_ID = "C1"; private final TransitModelForTest testModel = TransitModelForTest.of(); public final ZoneId timeZone = ZoneId.of(TransitModelForTest.TIME_ZONE_ID); public final Station stationA = testModel.station("A").build(); public final Station stationB = testModel.station("B").build(); public final Station stationC = testModel.station("C").build(); public final Station stationD = testModel.station("D").build(); - public final RegularStop stopA1 = testModel.stop("A1").withParentStation(stationA).build(); - public final RegularStop stopB1 = testModel.stop("B1").withParentStation(stationB).build(); + public final RegularStop stopA1 = testModel.stop(STOP_A1_ID).withParentStation(stationA).build(); + public final RegularStop stopB1 = testModel.stop(STOP_B1_ID).withParentStation(stationB).build(); public final RegularStop stopB2 = testModel.stop("B2").withParentStation(stationB).build(); - public final RegularStop stopC1 = testModel.stop("C1").withParentStation(stationC).build(); + public final RegularStop stopC1 = testModel.stop(STOP_C1_ID).withParentStation(stationC).build(); public final RegularStop stopD1 = testModel.stop("D1").withParentStation(stationD).build(); public final StopModel stopModel = testModel .stopModelBuilder() diff --git a/src/test/java/org/opentripplanner/updater/trip/TimetableSnapshotSourceTest.java b/src/test/java/org/opentripplanner/updater/trip/TimetableSnapshotSourceTest.java index 9cf69821aff..7ae7b7386f3 100644 --- a/src/test/java/org/opentripplanner/updater/trip/TimetableSnapshotSourceTest.java +++ b/src/test/java/org/opentripplanner/updater/trip/TimetableSnapshotSourceTest.java @@ -1,6 +1,5 @@ package org.opentripplanner.updater.trip; -import static com.google.transit.realtime.GtfsRealtime.TripDescriptor.ScheduleRelationship.ADDED; import static com.google.transit.realtime.GtfsRealtime.TripDescriptor.ScheduleRelationship.CANCELED; import static com.google.transit.realtime.GtfsRealtime.TripUpdate.StopTimeUpdate.ScheduleRelationship.SKIPPED; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -17,22 +16,18 @@ import com.google.transit.realtime.GtfsRealtime.TripUpdate; import com.google.transit.realtime.GtfsRealtime.TripUpdate.StopTimeEvent; import com.google.transit.realtime.GtfsRealtime.TripUpdate.StopTimeUpdate; -import de.mfdz.MfdzRealtimeExtensions.StopTimePropertiesExtension.DropOffPickupType; import java.time.Duration; import java.time.LocalDate; import java.util.List; import javax.annotation.Nonnull; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.opentripplanner.ConstantsForTests; import org.opentripplanner.TestOtpModel; import org.opentripplanner._support.time.ZoneIds; import org.opentripplanner.framework.time.ServiceDateUtils; -import org.opentripplanner.model.PickDrop; import org.opentripplanner.model.Timetable; import org.opentripplanner.model.TimetableSnapshot; -import org.opentripplanner.transit.model.basic.TransitMode; import org.opentripplanner.transit.model.framework.FeedScopedId; import org.opentripplanner.transit.model.network.TripPattern; import org.opentripplanner.transit.model.timetable.RealTimeState; @@ -41,7 +36,6 @@ import org.opentripplanner.transit.service.TransitModel; import org.opentripplanner.updater.GtfsRealtimeFuzzyTripMatcher; import org.opentripplanner.updater.TimetableSnapshotSourceParameters; -import org.opentripplanner.updater.spi.UpdateSuccess.WarningType; public class TimetableSnapshotSourceTest { @@ -308,217 +302,6 @@ public void testHandleModifiedTrip() { } } - @Nested - class Added { - - final String addedTripId = "added_trip"; - - @Test - public void addedTrip() { - var builder = new TripUpdateBuilder( - addedTripId, - SERVICE_DATE, - ADDED, - transitModel.getTimeZone() - ); - - builder.addStopTime("A", 30).addStopTime("C", 40).addStopTime("E", 55); - - var tripUpdate = builder.build(); - - var updater = defaultUpdater(); - - // WHEN - updater.applyTripUpdates( - TRIP_MATCHER_NOOP, - REQUIRED_NO_DATA, - DIFFERENTIAL, - List.of(tripUpdate), - feedId - ); - - // THEN - assertAddedTrip(SERVICE_DATE, this.addedTripId, updater); - } - - private TripPattern assertAddedTrip( - LocalDate serviceDate, - String tripId, - TimetableSnapshotSource updater - ) { - var stopA = transitModel.getStopModel().getRegularStop(new FeedScopedId(feedId, "A")); - // Get the trip pattern of the added trip which goes through stopA - var snapshot = updater.getTimetableSnapshot(); - var patternsAtA = snapshot.getPatternsForStop(stopA); - - assertNotNull(patternsAtA, "Added trip pattern should be found"); - assertEquals(1, patternsAtA.size()); - var tripPattern = patternsAtA.stream().findFirst().get(); - - final Timetable forToday = snapshot.resolve(tripPattern, serviceDate); - final Timetable schedule = snapshot.resolve(tripPattern, null); - - assertNotSame(forToday, schedule); - - final int forTodayAddedTripIndex = forToday.getTripIndex(tripId); - assertTrue( - forTodayAddedTripIndex > -1, - "Added trip should be found in time table for service date" - ); - assertEquals( - RealTimeState.ADDED, - forToday.getTripTimes(forTodayAddedTripIndex).getRealTimeState() - ); - - final int scheduleTripIndex = schedule.getTripIndex(tripId); - assertEquals(-1, scheduleTripIndex, "Added trip should not be found in scheduled time table"); - return tripPattern; - } - - @Test - public void addedTripWithNewRoute() { - // GIVEN - - final var builder = new TripUpdateBuilder( - addedTripId, - SERVICE_DATE, - ADDED, - transitModel.getTimeZone() - ); - // add extension to set route name, url, mode - builder.addTripExtension(); - - builder - .addStopTime("A", 30, DropOffPickupType.PHONE_AGENCY) - .addStopTime("C", 40, DropOffPickupType.COORDINATE_WITH_DRIVER) - .addStopTime("E", 55, DropOffPickupType.NONE); - - var tripUpdate = builder.build(); - - var updater = defaultUpdater(); - - // WHEN - var result = updater.applyTripUpdates( - TRIP_MATCHER_NOOP, - REQUIRED_NO_DATA, - DIFFERENTIAL, - List.of(tripUpdate), - feedId - ); - - // THEN - - assertTrue(result.warnings().isEmpty()); - - var pattern = assertAddedTrip(SERVICE_DATE, addedTripId, updater); - - var route = pattern.getRoute(); - assertEquals(TripUpdateBuilder.ROUTE_URL, route.getUrl()); - assertEquals(TripUpdateBuilder.ROUTE_NAME, route.getName()); - assertEquals(TransitMode.RAIL, route.getMode()); - - var fromTransitModel = transitModel.getTransitModelIndex().getRouteForId(route.getId()); - assertEquals(fromTransitModel, route); - - assertEquals(PickDrop.CALL_AGENCY, pattern.getBoardType(0)); - assertEquals(PickDrop.CALL_AGENCY, pattern.getAlightType(0)); - - assertEquals(PickDrop.COORDINATE_WITH_DRIVER, pattern.getBoardType(1)); - assertEquals(PickDrop.COORDINATE_WITH_DRIVER, pattern.getAlightType(1)); - } - - @Test - public void addedWithUnknownStop() { - // GIVEN - final var builder = new TripUpdateBuilder( - addedTripId, - SERVICE_DATE, - ADDED, - transitModel.getTimeZone() - ); - // add extension to set route name, url, mode - builder.addTripExtension(); - - builder - .addStopTime("A", 30, DropOffPickupType.PHONE_AGENCY) - .addStopTime("UNKNOWN_STOP_ID", 40, DropOffPickupType.COORDINATE_WITH_DRIVER) - .addStopTime("E", 55, DropOffPickupType.NONE); - - var tripUpdate = builder.build(); - - var updater = defaultUpdater(); - - // WHEN - var result = updater.applyTripUpdates( - TRIP_MATCHER_NOOP, - REQUIRED_NO_DATA, - DIFFERENTIAL, - List.of(tripUpdate), - feedId - ); - - // THEN - - assertFalse(result.warnings().isEmpty()); - - assertEquals(List.of(WarningType.UNKNOWN_STOPS_REMOVED_FROM_ADDED_TRIP), result.warnings()); - - var pattern = assertAddedTrip(SERVICE_DATE, addedTripId, updater); - - assertEquals(2, pattern.getStops().size()); - } - - @Test - public void repeatedlyAddedTripWithNewRoute() { - // GIVEN - - final var builder = new TripUpdateBuilder( - addedTripId, - SERVICE_DATE, - ADDED, - transitModel.getTimeZone() - ); - // add extension to set route name, url, mode - builder.addTripExtension(); - - builder - .addStopTime("A", 30, DropOffPickupType.PHONE_AGENCY) - .addStopTime("C", 40, DropOffPickupType.COORDINATE_WITH_DRIVER) - .addStopTime("E", 55, DropOffPickupType.NONE); - - var tripUpdate = builder.build(); - - var updater = defaultUpdater(); - - // WHEN - updater.applyTripUpdates( - TRIP_MATCHER_NOOP, - REQUIRED_NO_DATA, - DIFFERENTIAL, - List.of(tripUpdate), - feedId - ); - var pattern = assertAddedTrip(SERVICE_DATE, addedTripId, updater); - var firstRoute = pattern.getRoute(); - - // apply the update a second time to check that no new route instance is created but the old one is reused - updater.applyTripUpdates( - TRIP_MATCHER_NOOP, - REQUIRED_NO_DATA, - DIFFERENTIAL, - List.of(tripUpdate), - feedId - ); - var secondPattern = assertAddedTrip(SERVICE_DATE, addedTripId, updater); - var secondRoute = secondPattern.getRoute(); - - // THEN - - assertSame(firstRoute, secondRoute); - assertNotNull(transitModel.getTransitModelIndex().getRouteForId(firstRoute.getId())); - } - } - @Nonnull private TimetableSnapshotSource defaultUpdater() { return new TimetableSnapshotSource( diff --git a/src/test/java/org/opentripplanner/updater/trip/moduletests/addition/AddedTest.java b/src/test/java/org/opentripplanner/updater/trip/moduletests/addition/AddedTest.java new file mode 100644 index 00000000000..2cce94117b3 --- /dev/null +++ b/src/test/java/org/opentripplanner/updater/trip/moduletests/addition/AddedTest.java @@ -0,0 +1,207 @@ +package org.opentripplanner.updater.trip.moduletests.addition; + +import static com.google.transit.realtime.GtfsRealtime.TripDescriptor.ScheduleRelationship.ADDED; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNotSame; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.opentripplanner.test.support.UpdateResultAssertions.assertSuccess; +import static org.opentripplanner.updater.trip.RealtimeTestEnvironment.SERVICE_DATE; +import static org.opentripplanner.updater.trip.RealtimeTestEnvironment.STOP_A1_ID; +import static org.opentripplanner.updater.trip.RealtimeTestEnvironment.STOP_B1_ID; +import static org.opentripplanner.updater.trip.RealtimeTestEnvironment.STOP_C1_ID; + +import de.mfdz.MfdzRealtimeExtensions; +import java.util.List; +import org.junit.jupiter.api.Test; +import org.opentripplanner.model.PickDrop; +import org.opentripplanner.model.Timetable; +import org.opentripplanner.transit.model.basic.TransitMode; +import org.opentripplanner.transit.model.network.TripPattern; +import org.opentripplanner.transit.model.timetable.RealTimeState; +import org.opentripplanner.updater.spi.UpdateSuccess; +import org.opentripplanner.updater.trip.RealtimeTestEnvironment; +import org.opentripplanner.updater.trip.TripUpdateBuilder; + +public class AddedTest { + + final String ADDED_TRIP_ID = "added_trip"; + + @Test + public void addedTrip() { + var env = RealtimeTestEnvironment.gtfs(); + + var tripUpdate = new TripUpdateBuilder(ADDED_TRIP_ID, SERVICE_DATE, ADDED, env.timeZone) + .addStopTime(STOP_A1_ID, 30) + .addStopTime(STOP_B1_ID, 40) + .addStopTime(STOP_C1_ID, 55) + .build(); + + assertSuccess(env.applyTripUpdate(tripUpdate)); + assertAddedTrip(this.ADDED_TRIP_ID, env); + } + + + @Test + public void addedTripWithNewRoute() { + var env = RealtimeTestEnvironment.gtfs(); + final var builder = new TripUpdateBuilder(ADDED_TRIP_ID, SERVICE_DATE, ADDED, env.timeZone); + // add extension to set route name, url, mode + builder.addTripExtension(); + + builder + .addStopTime( + STOP_A1_ID, + 30, + MfdzRealtimeExtensions.StopTimePropertiesExtension.DropOffPickupType.PHONE_AGENCY + ) + .addStopTime( + STOP_B1_ID, + 40, + MfdzRealtimeExtensions.StopTimePropertiesExtension.DropOffPickupType.COORDINATE_WITH_DRIVER + ) + .addStopTime( + STOP_B1_ID, + 55, + MfdzRealtimeExtensions.StopTimePropertiesExtension.DropOffPickupType.NONE + ); + + var tripUpdate = builder.build(); + + // WHEN + var result = assertSuccess(env.applyTripUpdate(tripUpdate)); + + // THEN + + assertTrue(result.warnings().isEmpty()); + + var pattern = assertAddedTrip(ADDED_TRIP_ID, env); + + var route = pattern.getRoute(); + assertEquals(TripUpdateBuilder.ROUTE_URL, route.getUrl()); + assertEquals(TripUpdateBuilder.ROUTE_NAME, route.getName()); + assertEquals(TransitMode.RAIL, route.getMode()); + + var fromTransitModel = env.transitModel.getTransitModelIndex().getRouteForId(route.getId()); + assertEquals(fromTransitModel, route); + + assertEquals(PickDrop.CALL_AGENCY, pattern.getBoardType(0)); + assertEquals(PickDrop.CALL_AGENCY, pattern.getAlightType(0)); + + assertEquals(PickDrop.COORDINATE_WITH_DRIVER, pattern.getBoardType(1)); + assertEquals(PickDrop.COORDINATE_WITH_DRIVER, pattern.getAlightType(1)); + } + + @Test + public void addedWithUnknownStop() { + var env = RealtimeTestEnvironment.gtfs(); + final var builder = new TripUpdateBuilder(ADDED_TRIP_ID, SERVICE_DATE, ADDED, env.timeZone); + // add extension to set route name, url, mode + builder.addTripExtension(); + + builder + .addStopTime( + STOP_A1_ID, + 30, + MfdzRealtimeExtensions.StopTimePropertiesExtension.DropOffPickupType.PHONE_AGENCY + ) + .addStopTime( + "UNKNOWN_STOP_ID", + 40, + MfdzRealtimeExtensions.StopTimePropertiesExtension.DropOffPickupType.COORDINATE_WITH_DRIVER + ) + .addStopTime( + STOP_C1_ID, + 55, + MfdzRealtimeExtensions.StopTimePropertiesExtension.DropOffPickupType.NONE + ); + + var tripUpdate = builder.build(); + + var result = assertSuccess(env.applyTripUpdate(tripUpdate)); + + assertFalse(result.warnings().isEmpty()); + + assertEquals( + List.of(UpdateSuccess.WarningType.UNKNOWN_STOPS_REMOVED_FROM_ADDED_TRIP), + result.warnings() + ); + + var pattern = assertAddedTrip(ADDED_TRIP_ID, env); + + assertEquals(2, pattern.getStops().size()); + } + + @Test + public void repeatedlyAddedTripWithNewRoute() { + var env = RealtimeTestEnvironment.gtfs(); + final var builder = new TripUpdateBuilder(ADDED_TRIP_ID, SERVICE_DATE, ADDED, env.timeZone); + // add extension to set route name, url, mode + builder.addTripExtension(); + + builder + .addStopTime( + STOP_A1_ID, + 30, + MfdzRealtimeExtensions.StopTimePropertiesExtension.DropOffPickupType.PHONE_AGENCY + ) + .addStopTime( + STOP_B1_ID, + 40, + MfdzRealtimeExtensions.StopTimePropertiesExtension.DropOffPickupType.COORDINATE_WITH_DRIVER + ) + .addStopTime( + STOP_C1_ID, + 55, + MfdzRealtimeExtensions.StopTimePropertiesExtension.DropOffPickupType.NONE + ); + + var tripUpdate = builder.build(); + + assertSuccess(env.applyTripUpdate(tripUpdate)); + var pattern = assertAddedTrip(ADDED_TRIP_ID, env); + var firstRoute = pattern.getRoute(); + + // apply the update a second time to check that no new route instance is created but the old one is reused + env.applyTripUpdate(tripUpdate); + var secondPattern = assertAddedTrip(ADDED_TRIP_ID, env); + var secondRoute = secondPattern.getRoute(); + + // THEN + + assertSame(firstRoute, secondRoute); + assertNotNull(env.transitModel.getTransitModelIndex().getRouteForId(firstRoute.getId())); + } + private TripPattern assertAddedTrip(String tripId, RealtimeTestEnvironment env) { + var snapshot = env.getTimetableSnapshot(); + var stopA = env.transitModel.getStopModel().getRegularStop(env.stopA1.getId()); + // Get the trip pattern of the added trip which goes through stopA + var patternsAtA = env.getTimetableSnapshot().getPatternsForStop(stopA); + + assertNotNull(patternsAtA, "Added trip pattern should be found"); + assertEquals(1, patternsAtA.size()); + var tripPattern = patternsAtA.stream().findFirst().get(); + + final Timetable forToday = snapshot.resolve(tripPattern, SERVICE_DATE); + final Timetable schedule = snapshot.resolve(tripPattern, null); + + assertNotSame(forToday, schedule); + + final int forTodayAddedTripIndex = forToday.getTripIndex(tripId); + assertTrue( + forTodayAddedTripIndex > -1, + "Added trip should be found in time table for service date" + ); + assertEquals( + RealTimeState.ADDED, + forToday.getTripTimes(forTodayAddedTripIndex).getRealTimeState() + ); + + final int scheduleTripIndex = schedule.getTripIndex(tripId); + assertEquals(-1, scheduleTripIndex, "Added trip should not be found in scheduled time table"); + return tripPattern; + } + +} diff --git a/src/test/java/org/opentripplanner/updater/trip/moduletests/delay/SkippedTest.java b/src/test/java/org/opentripplanner/updater/trip/moduletests/delay/SkippedTest.java index 4424d47495b..fb3ae2fd3bb 100644 --- a/src/test/java/org/opentripplanner/updater/trip/moduletests/delay/SkippedTest.java +++ b/src/test/java/org/opentripplanner/updater/trip/moduletests/delay/SkippedTest.java @@ -46,7 +46,6 @@ public void scheduledTripWithSkippedAndScheduled() { assertSuccess(env.applyTripUpdate(tripUpdate)); - final TimetableSnapshot snapshot = env.getTimetableSnapshot(); // Original trip pattern diff --git a/src/test/java/org/opentripplanner/updater/trip/moduletests/rejection/InvalidInputTest.java b/src/test/java/org/opentripplanner/updater/trip/moduletests/rejection/InvalidInputTest.java index d0b3ad5dc31..8084f3e64d3 100644 --- a/src/test/java/org/opentripplanner/updater/trip/moduletests/rejection/InvalidInputTest.java +++ b/src/test/java/org/opentripplanner/updater/trip/moduletests/rejection/InvalidInputTest.java @@ -1,7 +1,6 @@ package org.opentripplanner.updater.trip.moduletests.rejection; import static com.google.transit.realtime.GtfsRealtime.TripDescriptor.ScheduleRelationship.SCHEDULED; -import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.opentripplanner.test.support.UpdateResultAssertions.assertFailure; import static org.opentripplanner.updater.spi.UpdateError.UpdateErrorType.NO_SERVICE_ON_DATE; @@ -39,7 +38,6 @@ public void invalidTripDate(LocalDate date) { var snapshot = env.getTimetableSnapshot(); assertTrue(snapshot.isEmpty()); - assertEquals(1, result.failed()); assertFailure(NO_SERVICE_ON_DATE, result); } } From 50701c175474168cfad3fb8ff838a014ac61e267 Mon Sep 17 00:00:00 2001 From: Leonard Ehrenfried Date: Mon, 17 Jun 2024 14:39:43 +0200 Subject: [PATCH 05/21] Move ADDED tests --- .../trip/moduletests/addition/AddedTest.java | 3 +- .../trip/moduletests/delay/SkippedTest.java | 50 +++++++------------ 2 files changed, 19 insertions(+), 34 deletions(-) diff --git a/src/test/java/org/opentripplanner/updater/trip/moduletests/addition/AddedTest.java b/src/test/java/org/opentripplanner/updater/trip/moduletests/addition/AddedTest.java index 2cce94117b3..4d3da180f49 100644 --- a/src/test/java/org/opentripplanner/updater/trip/moduletests/addition/AddedTest.java +++ b/src/test/java/org/opentripplanner/updater/trip/moduletests/addition/AddedTest.java @@ -43,7 +43,6 @@ public void addedTrip() { assertAddedTrip(this.ADDED_TRIP_ID, env); } - @Test public void addedTripWithNewRoute() { var env = RealtimeTestEnvironment.gtfs(); @@ -174,6 +173,7 @@ public void repeatedlyAddedTripWithNewRoute() { assertSame(firstRoute, secondRoute); assertNotNull(env.transitModel.getTransitModelIndex().getRouteForId(firstRoute.getId())); } + private TripPattern assertAddedTrip(String tripId, RealtimeTestEnvironment env) { var snapshot = env.getTimetableSnapshot(); var stopA = env.transitModel.getStopModel().getRegularStop(env.stopA1.getId()); @@ -203,5 +203,4 @@ private TripPattern assertAddedTrip(String tripId, RealtimeTestEnvironment env) assertEquals(-1, scheduleTripIndex, "Added trip should not be found in scheduled time table"); return tripPattern; } - } diff --git a/src/test/java/org/opentripplanner/updater/trip/moduletests/delay/SkippedTest.java b/src/test/java/org/opentripplanner/updater/trip/moduletests/delay/SkippedTest.java index fb3ae2fd3bb..20ca8d20b30 100644 --- a/src/test/java/org/opentripplanner/updater/trip/moduletests/delay/SkippedTest.java +++ b/src/test/java/org/opentripplanner/updater/trip/moduletests/delay/SkippedTest.java @@ -33,12 +33,7 @@ public void scheduledTripWithSkippedAndScheduled() { var env = RealtimeTestEnvironment.gtfs(); String scheduledTripId = env.trip2.getId().getId(); - var tripUpdate = new TripUpdateBuilder( - scheduledTripId, - RealtimeTestEnvironment.SERVICE_DATE, - SCHEDULED, - env.timeZone - ) + var tripUpdate = new TripUpdateBuilder(scheduledTripId, SERVICE_DATE, SCHEDULED, env.timeZone) .addDelayedStopTime(0, 0) .addSkippedStop(1) .addDelayedStopTime(2, 90) @@ -59,7 +54,7 @@ public void scheduledTripWithSkippedAndScheduled() { final Timetable originalTimetableForToday = snapshot.resolve( originalTripPattern, - RealtimeTestEnvironment.SERVICE_DATE + SERVICE_DATE ); final Timetable originalTimetableScheduled = snapshot.resolve(originalTripPattern, null); @@ -81,13 +76,10 @@ public void scheduledTripWithSkippedAndScheduled() { { final TripPattern newTripPattern = snapshot.getRealtimeAddedTripPattern( env.trip2.getId(), - RealtimeTestEnvironment.SERVICE_DATE + SERVICE_DATE ); - final Timetable newTimetableForToday = snapshot.resolve( - newTripPattern, - RealtimeTestEnvironment.SERVICE_DATE - ); + final Timetable newTimetableForToday = snapshot.resolve(newTripPattern, SERVICE_DATE); final Timetable newTimetableScheduled = snapshot.resolve(newTripPattern, null); assertNotSame(newTimetableForToday, newTimetableScheduled); @@ -135,12 +127,7 @@ public void scheduledTripWithPreviouslySkipped() { var env = RealtimeTestEnvironment.gtfs(); var tripId = env.trip2.getId(); - var tripUpdate = new TripUpdateBuilder( - tripId.getId(), - RealtimeTestEnvironment.SERVICE_DATE, - SCHEDULED, - env.timeZone - ) + var tripUpdate = new TripUpdateBuilder(tripId.getId(), SERVICE_DATE, SCHEDULED, env.timeZone) .addDelayedStopTime(0, 0) .addSkippedStop(1) .addDelayedStopTime(2, 90) @@ -151,7 +138,7 @@ public void scheduledTripWithPreviouslySkipped() { // Create update to the same trip but now the skipped stop is no longer skipped var scheduledBuilder = new TripUpdateBuilder( tripId.getId(), - RealtimeTestEnvironment.SERVICE_DATE, + SERVICE_DATE, SCHEDULED, env.timeZone ) @@ -170,10 +157,7 @@ public void scheduledTripWithPreviouslySkipped() { var snapshot = env.getTimetableSnapshot(); { - final TripPattern newTripPattern = snapshot.getRealtimeAddedTripPattern( - env.trip2.getId(), - RealtimeTestEnvironment.SERVICE_DATE - ); + final TripPattern newTripPattern = snapshot.getRealtimeAddedTripPattern(tripId, SERVICE_DATE); assertNull(newTripPattern); final Trip trip = env.transitModel.getTransitModelIndex().getTripForId().get(tripId); @@ -183,7 +167,7 @@ public void scheduledTripWithPreviouslySkipped() { .get(trip); final Timetable originalTimetableForToday = snapshot.resolve( originalTripPattern, - RealtimeTestEnvironment.SERVICE_DATE + SERVICE_DATE ); final Timetable originalTimetableScheduled = snapshot.resolve(originalTripPattern, null); @@ -213,13 +197,15 @@ public void scheduledTripWithPreviouslySkipped() { final TripTimes originalTripTimesForToday = originalTimetableForToday.getTripTimes( originalTripIndexForToday ); - assertEquals(RealTimeState.UPDATED, originalTripTimesForToday.getRealTimeState()); - assertEquals(0, originalTripTimesForToday.getArrivalDelay(0)); - assertEquals(0, originalTripTimesForToday.getDepartureDelay(0)); - assertEquals(50, originalTripTimesForToday.getArrivalDelay(1)); - assertEquals(50, originalTripTimesForToday.getDepartureDelay(1)); - assertEquals(90, originalTripTimesForToday.getArrivalDelay(2)); - assertEquals(90, originalTripTimesForToday.getDepartureDelay(2)); + + assertEquals( + "SCHEDULED | A1 0:01 0:01:01 | B1 0:01:10 0:01:11 | C1 0:01:20 0:01:21", + env.getScheduledTimetable(tripId) + ); + assertEquals( + "UPDATED | A1 0:01 0:01:01 | B1 0:02 0:02:01 | C1 0:02:50 0:02:51", + env.getRealtimeTimetable(tripId, SERVICE_DATE) + ); } } @@ -317,7 +303,7 @@ public void skippedNoData() { "New trip should be found in time table for service date" ); - var newTripTimes = newTimetableForToday.getTripTimes(newTimetableForTodayModifiedTripIndex); + var newTripTimes = newTimetableForToday.getTripTimes(tripId); assertEquals(RealTimeState.UPDATED, newTripTimes.getRealTimeState()); assertEquals( From d85c67a5a741d82e17a597b4ffd15787d6f98724 Mon Sep 17 00:00:00 2001 From: Leonard Ehrenfried Date: Mon, 17 Jun 2024 14:53:50 +0200 Subject: [PATCH 06/21] Refactor handling of schedule relationships --- .../updater/trip/TimetableSnapshotSource.java | 50 ++++++------------- .../trip/moduletests/delay/SkippedTest.java | 3 -- 2 files changed, 16 insertions(+), 37 deletions(-) diff --git a/src/main/java/org/opentripplanner/updater/trip/TimetableSnapshotSource.java b/src/main/java/org/opentripplanner/updater/trip/TimetableSnapshotSource.java index cc39d82369b..ba4ffe211b4 100644 --- a/src/main/java/org/opentripplanner/updater/trip/TimetableSnapshotSource.java +++ b/src/main/java/org/opentripplanner/updater/trip/TimetableSnapshotSource.java @@ -1,5 +1,6 @@ package org.opentripplanner.updater.trip; +import static com.google.transit.realtime.GtfsRealtime.TripDescriptor.ScheduleRelationship.SCHEDULED; import static org.opentripplanner.updater.spi.UpdateError.UpdateErrorType.INVALID_ARRIVAL_TIME; import static org.opentripplanner.updater.spi.UpdateError.UpdateErrorType.INVALID_DEPARTURE_TIME; import static org.opentripplanner.updater.spi.UpdateError.UpdateErrorType.NOT_IMPLEMENTED_DUPLICATED; @@ -19,6 +20,7 @@ import com.google.common.collect.Multimaps; import com.google.transit.realtime.GtfsRealtime; import com.google.transit.realtime.GtfsRealtime.TripDescriptor; +import com.google.transit.realtime.GtfsRealtime.TripDescriptor.ScheduleRelationship; import com.google.transit.realtime.GtfsRealtime.TripUpdate; import com.google.transit.realtime.GtfsRealtime.TripUpdate.StopTimeUpdate; import de.mfdz.MfdzRealtimeExtensions; @@ -150,7 +152,7 @@ public UpdateResult applyTripUpdates( return UpdateResult.empty(); } - Map failuresByRelationship = new HashMap<>(); + Map failuresByRelationship = new HashMap<>(); List> results = new ArrayList<>(); snapshotManager.withLock(() -> { @@ -199,11 +201,12 @@ public UpdateResult applyTripUpdates( serviceDate = localDateNow.get(); } // Determine what kind of trip update this is - final TripDescriptor.ScheduleRelationship tripScheduleRelationship = determineTripScheduleRelationship( - tripDescriptor + var scheduleRelationship = Objects.requireNonNullElse( + tripDescriptor.getScheduleRelationship(), + SCHEDULED ); if (updateIncrementality == DIFFERENTIAL) { - purgePatternModifications(tripScheduleRelationship, tripId, serviceDate); + purgePatternModifications(scheduleRelationship, tripId, serviceDate); } uIndex += 1; @@ -213,7 +216,7 @@ public UpdateResult applyTripUpdates( Result result; try { result = - switch (tripScheduleRelationship) { + switch (scheduleRelationship) { case SCHEDULED -> handleScheduledTrip( tripUpdate, tripId, @@ -255,11 +258,11 @@ public UpdateResult applyTripUpdates( if (result.isFailure()) { debug(tripId, "Failed to apply TripUpdate."); LOG.trace(" Contents: {}", tripUpdate); - if (failuresByRelationship.containsKey(tripScheduleRelationship)) { - var c = failuresByRelationship.get(tripScheduleRelationship); - failuresByRelationship.put(tripScheduleRelationship, ++c); + if (failuresByRelationship.containsKey(scheduleRelationship)) { + var c = failuresByRelationship.get(scheduleRelationship); + failuresByRelationship.put(scheduleRelationship, ++c); } else { - failuresByRelationship.put(tripScheduleRelationship, 1); + failuresByRelationship.put(scheduleRelationship, 1); } } } @@ -282,7 +285,7 @@ public UpdateResult applyTripUpdates( * added trip pattern. */ private void purgePatternModifications( - TripDescriptor.ScheduleRelationship tripScheduleRelationship, + ScheduleRelationship tripScheduleRelationship, FeedScopedId tripId, LocalDate serviceDate ) { @@ -290,8 +293,8 @@ private void purgePatternModifications( if ( !isPreviouslyAddedTrip(tripId, pattern, serviceDate) || ( - tripScheduleRelationship != TripDescriptor.ScheduleRelationship.CANCELED && - tripScheduleRelationship != TripDescriptor.ScheduleRelationship.DELETED + tripScheduleRelationship != ScheduleRelationship.CANCELED && + tripScheduleRelationship != ScheduleRelationship.DELETED ) ) { // Remove previous realtime updates for this trip. This is necessary to avoid previous @@ -327,7 +330,7 @@ public TimetableSnapshot getTimetableSnapshot() { private static void logUpdateResult( String feedId, - Map failuresByRelationship, + Map failuresByRelationship, UpdateResult updateResult ) { ResultLogger.logUpdateResult(feedId, "gtfs-rt-trip-updates", updateResult); @@ -345,27 +348,6 @@ private static void logUpdateResult( }); } - /** - * Determine how the trip update should be handled. - * - * @param tripDescriptor trip descriptor - * @return TripDescriptor.ScheduleRelationship indicating how the trip update should be handled - */ - private TripDescriptor.ScheduleRelationship determineTripScheduleRelationship( - final TripDescriptor tripDescriptor - ) { - // Assume default value - TripDescriptor.ScheduleRelationship tripScheduleRelationship = - TripDescriptor.ScheduleRelationship.SCHEDULED; - - // If trip update contains schedule relationship, use it - if (tripDescriptor.hasScheduleRelationship()) { - tripScheduleRelationship = tripDescriptor.getScheduleRelationship(); - } - - return tripScheduleRelationship; - } - private Result handleScheduledTrip( TripUpdate tripUpdate, FeedScopedId tripId, diff --git a/src/test/java/org/opentripplanner/updater/trip/moduletests/delay/SkippedTest.java b/src/test/java/org/opentripplanner/updater/trip/moduletests/delay/SkippedTest.java index 20ca8d20b30..78770e6f6b7 100644 --- a/src/test/java/org/opentripplanner/updater/trip/moduletests/delay/SkippedTest.java +++ b/src/test/java/org/opentripplanner/updater/trip/moduletests/delay/SkippedTest.java @@ -194,9 +194,6 @@ public void scheduledTripWithPreviouslySkipped() { originalTripIndexForToday > -1, "Original trip should be found in time table for service date" ); - final TripTimes originalTripTimesForToday = originalTimetableForToday.getTripTimes( - originalTripIndexForToday - ); assertEquals( "SCHEDULED | A1 0:01 0:01:01 | B1 0:01:10 0:01:11 | C1 0:01:20 0:01:21", From 58005ac84917998876a0203a7f02d110908ca17b Mon Sep 17 00:00:00 2001 From: Leonard Ehrenfried Date: Mon, 17 Jun 2024 15:04:49 +0200 Subject: [PATCH 07/21] Simplify access --- .../updater/trip/moduletests/addition/AddedTest.java | 10 +++++----- .../cancellation/CancellationDeletionTest.java | 4 ++-- .../updater/trip/moduletests/delay/SkippedTest.java | 6 +++--- .../trip/moduletests/rejection/InvalidInputTest.java | 4 ++-- .../trip/moduletests/rejection/InvalidTripIdTest.java | 2 +- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/test/java/org/opentripplanner/updater/trip/moduletests/addition/AddedTest.java b/src/test/java/org/opentripplanner/updater/trip/moduletests/addition/AddedTest.java index 4d3da180f49..ff03362cbdd 100644 --- a/src/test/java/org/opentripplanner/updater/trip/moduletests/addition/AddedTest.java +++ b/src/test/java/org/opentripplanner/updater/trip/moduletests/addition/AddedTest.java @@ -25,12 +25,12 @@ import org.opentripplanner.updater.trip.RealtimeTestEnvironment; import org.opentripplanner.updater.trip.TripUpdateBuilder; -public class AddedTest { +class AddedTest { final String ADDED_TRIP_ID = "added_trip"; @Test - public void addedTrip() { + void addedTrip() { var env = RealtimeTestEnvironment.gtfs(); var tripUpdate = new TripUpdateBuilder(ADDED_TRIP_ID, SERVICE_DATE, ADDED, env.timeZone) @@ -44,7 +44,7 @@ public void addedTrip() { } @Test - public void addedTripWithNewRoute() { + void addedTripWithNewRoute() { var env = RealtimeTestEnvironment.gtfs(); final var builder = new TripUpdateBuilder(ADDED_TRIP_ID, SERVICE_DATE, ADDED, env.timeZone); // add extension to set route name, url, mode @@ -94,7 +94,7 @@ public void addedTripWithNewRoute() { } @Test - public void addedWithUnknownStop() { + void addedWithUnknownStop() { var env = RealtimeTestEnvironment.gtfs(); final var builder = new TripUpdateBuilder(ADDED_TRIP_ID, SERVICE_DATE, ADDED, env.timeZone); // add extension to set route name, url, mode @@ -134,7 +134,7 @@ public void addedWithUnknownStop() { } @Test - public void repeatedlyAddedTripWithNewRoute() { + void repeatedlyAddedTripWithNewRoute() { var env = RealtimeTestEnvironment.gtfs(); final var builder = new TripUpdateBuilder(ADDED_TRIP_ID, SERVICE_DATE, ADDED, env.timeZone); // add extension to set route name, url, mode diff --git a/src/test/java/org/opentripplanner/updater/trip/moduletests/cancellation/CancellationDeletionTest.java b/src/test/java/org/opentripplanner/updater/trip/moduletests/cancellation/CancellationDeletionTest.java index b2c31e2254e..b0bb999f350 100644 --- a/src/test/java/org/opentripplanner/updater/trip/moduletests/cancellation/CancellationDeletionTest.java +++ b/src/test/java/org/opentripplanner/updater/trip/moduletests/cancellation/CancellationDeletionTest.java @@ -32,7 +32,7 @@ static List cases() { @ParameterizedTest @MethodSource("cases") - public void cancelledTrip(ScheduleRelationship relationship, RealTimeState state) { + void cancelledTrip(ScheduleRelationship relationship, RealTimeState state) { var env = RealtimeTestEnvironment.gtfs(); var pattern1 = env.getPatternForTrip(env.trip1); @@ -73,7 +73,7 @@ public void cancelledTrip(ScheduleRelationship relationship, RealTimeState state */ @ParameterizedTest @MethodSource("cases") - public void cancelingAddedTrip(ScheduleRelationship relationship, RealTimeState state) { + void cancelingAddedTrip(ScheduleRelationship relationship, RealTimeState state) { var env = RealtimeTestEnvironment.gtfs(); var addedTripId = "added-trip"; // First add ADDED trip diff --git a/src/test/java/org/opentripplanner/updater/trip/moduletests/delay/SkippedTest.java b/src/test/java/org/opentripplanner/updater/trip/moduletests/delay/SkippedTest.java index 78770e6f6b7..4d91eefd390 100644 --- a/src/test/java/org/opentripplanner/updater/trip/moduletests/delay/SkippedTest.java +++ b/src/test/java/org/opentripplanner/updater/trip/moduletests/delay/SkippedTest.java @@ -29,7 +29,7 @@ public class SkippedTest { @Test - public void scheduledTripWithSkippedAndScheduled() { + void scheduledTripWithSkippedAndScheduled() { var env = RealtimeTestEnvironment.gtfs(); String scheduledTripId = env.trip2.getId().getId(); @@ -123,7 +123,7 @@ public void scheduledTripWithSkippedAndScheduled() { * the new stop-skipping trip pattern should also be removed. */ @Test - public void scheduledTripWithPreviouslySkipped() { + void scheduledTripWithPreviouslySkipped() { var env = RealtimeTestEnvironment.gtfs(); var tripId = env.trip2.getId(); @@ -210,7 +210,7 @@ public void scheduledTripWithPreviouslySkipped() { * Tests a mixture of SKIPPED and NO_DATA. */ @Test - public void skippedNoData() { + void skippedNoData() { var env = RealtimeTestEnvironment.gtfs(); final FeedScopedId tripId = env.trip2.getId(); diff --git a/src/test/java/org/opentripplanner/updater/trip/moduletests/rejection/InvalidInputTest.java b/src/test/java/org/opentripplanner/updater/trip/moduletests/rejection/InvalidInputTest.java index 8084f3e64d3..4d28c60eeb5 100644 --- a/src/test/java/org/opentripplanner/updater/trip/moduletests/rejection/InvalidInputTest.java +++ b/src/test/java/org/opentripplanner/updater/trip/moduletests/rejection/InvalidInputTest.java @@ -17,7 +17,7 @@ * A trip with start date that is outside the service period shouldn't throw an exception and is * ignored instead. */ -public class InvalidInputTest { +class InvalidInputTest { public static List cases() { return List.of(SERVICE_DATE.minusYears(10), SERVICE_DATE.plusYears(10)); @@ -25,7 +25,7 @@ public static List cases() { @ParameterizedTest @MethodSource("cases") - public void invalidTripDate(LocalDate date) { + void invalidTripDate(LocalDate date) { var env = RealtimeTestEnvironment.gtfs(); var update = new TripUpdateBuilder(env.trip1.getId().getId(), date, SCHEDULED, env.timeZone) diff --git a/src/test/java/org/opentripplanner/updater/trip/moduletests/rejection/InvalidTripIdTest.java b/src/test/java/org/opentripplanner/updater/trip/moduletests/rejection/InvalidTripIdTest.java index 58f9fb2ff55..8d7f7629575 100644 --- a/src/test/java/org/opentripplanner/updater/trip/moduletests/rejection/InvalidTripIdTest.java +++ b/src/test/java/org/opentripplanner/updater/trip/moduletests/rejection/InvalidTripIdTest.java @@ -8,7 +8,7 @@ import org.junit.jupiter.params.provider.MethodSource; import org.opentripplanner.updater.trip.RealtimeTestEnvironment; -public class InvalidTripIdTest { +class InvalidTripIdTest { static Stream invalidCases() { return Stream.of(null, "", " "); From 3e346d438192d19143dd7da0e9ffbb522c2d7e3d Mon Sep 17 00:00:00 2001 From: Leonard Ehrenfried Date: Mon, 17 Jun 2024 15:38:33 +0200 Subject: [PATCH 08/21] Remove unused method --- .../opentripplanner/transit/model/network/TripPattern.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/main/java/org/opentripplanner/transit/model/network/TripPattern.java b/src/main/java/org/opentripplanner/transit/model/network/TripPattern.java index f9734c1cb1a..deab7ee79f4 100644 --- a/src/main/java/org/opentripplanner/transit/model/network/TripPattern.java +++ b/src/main/java/org/opentripplanner/transit/model/network/TripPattern.java @@ -334,10 +334,6 @@ public boolean isBoardAndAlightAt(int stopIndex, PickDrop value) { // TODO: These should probably be deprecated. That would require grabbing the scheduled timetable, // and would avoid mistakes where real-time updates are accidentally not taken into account. - public boolean stopPatternIsEqual(TripPattern other) { - return stopPattern.equals(other.stopPattern); - } - public Trip getTrip(int tripIndex) { return scheduledTimetable.getTripTimes(tripIndex).getTrip(); } From 6412eeabe0f94aae12407f7514965021374d00a6 Mon Sep 17 00:00:00 2001 From: Leonard Ehrenfried Date: Mon, 17 Jun 2024 15:43:48 +0200 Subject: [PATCH 09/21] Remove method that is only used in test --- .../opentripplanner/transit/model/network/TripPattern.java | 7 ------- .../gtfs/interlining/InterlineProcessorTest.java | 5 ++--- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/opentripplanner/transit/model/network/TripPattern.java b/src/main/java/org/opentripplanner/transit/model/network/TripPattern.java index deab7ee79f4..57c71d06113 100644 --- a/src/main/java/org/opentripplanner/transit/model/network/TripPattern.java +++ b/src/main/java/org/opentripplanner/transit/model/network/TripPattern.java @@ -331,13 +331,6 @@ public boolean isBoardAndAlightAt(int stopIndex, PickDrop value) { /* METHODS THAT DELEGATE TO THE SCHEDULED TIMETABLE */ - // TODO: These should probably be deprecated. That would require grabbing the scheduled timetable, - // and would avoid mistakes where real-time updates are accidentally not taken into account. - - public Trip getTrip(int tripIndex) { - return scheduledTimetable.getTripTimes(tripIndex).getTrip(); - } - // TODO OTP2 this method modifies the state, it will be refactored in a subsequent step /** * Add the given tripTimes to this pattern's scheduled timetable, recording the corresponding trip diff --git a/src/test/java/org/opentripplanner/gtfs/interlining/InterlineProcessorTest.java b/src/test/java/org/opentripplanner/gtfs/interlining/InterlineProcessorTest.java index 67ca61f0403..a1aa4f9d753 100644 --- a/src/test/java/org/opentripplanner/gtfs/interlining/InterlineProcessorTest.java +++ b/src/test/java/org/opentripplanner/gtfs/interlining/InterlineProcessorTest.java @@ -125,9 +125,8 @@ void testInterline( void staySeatedNotAllowed() { var transferService = new DefaultTransferService(); - var fromTrip = patterns.get(0).getTrip(0); - var toTrip = patterns.get(1).getTrip(0); - + var fromTrip = patterns.get(0).getScheduledTimetable().getTripTimes().get(0).getTrip(); + var toTrip = patterns.get(1).getScheduledTimetable().getTripTimes().get(0).getTrip(); var notAllowed = new StaySeatedNotAllowed(fromTrip, toTrip); var calendarService = new CalendarServiceData(); From 6844979453abbeaf213e4c6063574a19ae6b420a Mon Sep 17 00:00:00 2001 From: Leonard Ehrenfried Date: Tue, 18 Jun 2024 12:43:26 +0200 Subject: [PATCH 10/21] Return error code for invalid trip IDs --- .../updater/trip/TimetableSnapshotSource.java | 2 ++ .../trip/moduletests/rejection/InvalidTripIdTest.java | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/opentripplanner/updater/trip/TimetableSnapshotSource.java b/src/main/java/org/opentripplanner/updater/trip/TimetableSnapshotSource.java index ba4ffe211b4..c452d5f58f8 100644 --- a/src/main/java/org/opentripplanner/updater/trip/TimetableSnapshotSource.java +++ b/src/main/java/org/opentripplanner/updater/trip/TimetableSnapshotSource.java @@ -3,6 +3,7 @@ import static com.google.transit.realtime.GtfsRealtime.TripDescriptor.ScheduleRelationship.SCHEDULED; import static org.opentripplanner.updater.spi.UpdateError.UpdateErrorType.INVALID_ARRIVAL_TIME; import static org.opentripplanner.updater.spi.UpdateError.UpdateErrorType.INVALID_DEPARTURE_TIME; +import static org.opentripplanner.updater.spi.UpdateError.UpdateErrorType.INVALID_INPUT_STRUCTURE; import static org.opentripplanner.updater.spi.UpdateError.UpdateErrorType.NOT_IMPLEMENTED_DUPLICATED; import static org.opentripplanner.updater.spi.UpdateError.UpdateErrorType.NOT_IMPLEMENTED_UNSCHEDULED; import static org.opentripplanner.updater.spi.UpdateError.UpdateErrorType.NO_SERVICE_ON_DATE; @@ -178,6 +179,7 @@ public UpdateResult applyTripUpdates( if (!tripDescriptor.hasTripId() || tripDescriptor.getTripId().isBlank()) { debug(feedId, "", "No trip id found for gtfs-rt trip update: \n{}", tripUpdate); + results.add(Result.failure(UpdateError.noTripId(INVALID_INPUT_STRUCTURE))); continue; } diff --git a/src/test/java/org/opentripplanner/updater/trip/moduletests/rejection/InvalidTripIdTest.java b/src/test/java/org/opentripplanner/updater/trip/moduletests/rejection/InvalidTripIdTest.java index 8d7f7629575..6cacaeb6ca9 100644 --- a/src/test/java/org/opentripplanner/updater/trip/moduletests/rejection/InvalidTripIdTest.java +++ b/src/test/java/org/opentripplanner/updater/trip/moduletests/rejection/InvalidTripIdTest.java @@ -1,6 +1,7 @@ package org.opentripplanner.updater.trip.moduletests.rejection; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.opentripplanner.test.support.UpdateResultAssertions.assertFailure; +import static org.opentripplanner.updater.spi.UpdateError.UpdateErrorType.INVALID_INPUT_STRUCTURE; import com.google.transit.realtime.GtfsRealtime; import java.util.stream.Stream; @@ -35,6 +36,6 @@ void invalidTripId(String tripId) { var result = env.applyTripUpdate(tripUpdate); - assertEquals(0, result.successful()); + assertFailure(INVALID_INPUT_STRUCTURE, result); } } From 17858f56899971370b9200f16dc35ab619052862 Mon Sep 17 00:00:00 2001 From: Leonard Ehrenfried Date: Tue, 18 Jun 2024 13:24:50 +0200 Subject: [PATCH 11/21] Make module tests a lot more compact --- .../trip/moduletests/addition/AddedTest.java | 56 ++------ .../CancellationDeletionTest.java | 15 +-- .../trip/moduletests/delay/DelayedTest.java | 77 ++++------- .../trip/moduletests/delay/SkippedTest.java | 123 +++++++----------- .../rejection/InvalidInputTest.java | 2 - 5 files changed, 93 insertions(+), 180 deletions(-) diff --git a/src/test/java/org/opentripplanner/updater/trip/moduletests/addition/AddedTest.java b/src/test/java/org/opentripplanner/updater/trip/moduletests/addition/AddedTest.java index ff03362cbdd..6a7d076923f 100644 --- a/src/test/java/org/opentripplanner/updater/trip/moduletests/addition/AddedTest.java +++ b/src/test/java/org/opentripplanner/updater/trip/moduletests/addition/AddedTest.java @@ -13,7 +13,7 @@ import static org.opentripplanner.updater.trip.RealtimeTestEnvironment.STOP_B1_ID; import static org.opentripplanner.updater.trip.RealtimeTestEnvironment.STOP_C1_ID; -import de.mfdz.MfdzRealtimeExtensions; +import de.mfdz.MfdzRealtimeExtensions.StopTimePropertiesExtension.DropOffPickupType; import java.util.List; import org.junit.jupiter.api.Test; import org.opentripplanner.model.PickDrop; @@ -51,21 +51,9 @@ void addedTripWithNewRoute() { builder.addTripExtension(); builder - .addStopTime( - STOP_A1_ID, - 30, - MfdzRealtimeExtensions.StopTimePropertiesExtension.DropOffPickupType.PHONE_AGENCY - ) - .addStopTime( - STOP_B1_ID, - 40, - MfdzRealtimeExtensions.StopTimePropertiesExtension.DropOffPickupType.COORDINATE_WITH_DRIVER - ) - .addStopTime( - STOP_B1_ID, - 55, - MfdzRealtimeExtensions.StopTimePropertiesExtension.DropOffPickupType.NONE - ); + .addStopTime(STOP_A1_ID, 30, DropOffPickupType.PHONE_AGENCY) + .addStopTime(STOP_B1_ID, 40, DropOffPickupType.COORDINATE_WITH_DRIVER) + .addStopTime(STOP_B1_ID, 55, DropOffPickupType.NONE); var tripUpdate = builder.build(); @@ -101,21 +89,9 @@ void addedWithUnknownStop() { builder.addTripExtension(); builder - .addStopTime( - STOP_A1_ID, - 30, - MfdzRealtimeExtensions.StopTimePropertiesExtension.DropOffPickupType.PHONE_AGENCY - ) - .addStopTime( - "UNKNOWN_STOP_ID", - 40, - MfdzRealtimeExtensions.StopTimePropertiesExtension.DropOffPickupType.COORDINATE_WITH_DRIVER - ) - .addStopTime( - STOP_C1_ID, - 55, - MfdzRealtimeExtensions.StopTimePropertiesExtension.DropOffPickupType.NONE - ); + .addStopTime(STOP_A1_ID, 30, DropOffPickupType.PHONE_AGENCY) + .addStopTime("UNKNOWN_STOP_ID", 40, DropOffPickupType.COORDINATE_WITH_DRIVER) + .addStopTime(STOP_C1_ID, 55, DropOffPickupType.NONE); var tripUpdate = builder.build(); @@ -141,21 +117,9 @@ void repeatedlyAddedTripWithNewRoute() { builder.addTripExtension(); builder - .addStopTime( - STOP_A1_ID, - 30, - MfdzRealtimeExtensions.StopTimePropertiesExtension.DropOffPickupType.PHONE_AGENCY - ) - .addStopTime( - STOP_B1_ID, - 40, - MfdzRealtimeExtensions.StopTimePropertiesExtension.DropOffPickupType.COORDINATE_WITH_DRIVER - ) - .addStopTime( - STOP_C1_ID, - 55, - MfdzRealtimeExtensions.StopTimePropertiesExtension.DropOffPickupType.NONE - ); + .addStopTime(STOP_A1_ID, 30, DropOffPickupType.PHONE_AGENCY) + .addStopTime(STOP_B1_ID, 40, DropOffPickupType.COORDINATE_WITH_DRIVER) + .addStopTime(STOP_C1_ID, 55, DropOffPickupType.NONE); var tripUpdate = builder.build(); diff --git a/src/test/java/org/opentripplanner/updater/trip/moduletests/cancellation/CancellationDeletionTest.java b/src/test/java/org/opentripplanner/updater/trip/moduletests/cancellation/CancellationDeletionTest.java index b0bb999f350..41e42bf00db 100644 --- a/src/test/java/org/opentripplanner/updater/trip/moduletests/cancellation/CancellationDeletionTest.java +++ b/src/test/java/org/opentripplanner/updater/trip/moduletests/cancellation/CancellationDeletionTest.java @@ -4,6 +4,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNotSame; import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.opentripplanner.test.support.UpdateResultAssertions.assertSuccess; import static org.opentripplanner.updater.trip.UpdateIncrementality.DIFFERENTIAL; import com.google.transit.realtime.GtfsRealtime.TripDescriptor.ScheduleRelationship; @@ -45,11 +46,9 @@ void cancelledTrip(ScheduleRelationship relationship, RealTimeState state) { env.timeZone ) .build(); - var result = env.applyTripUpdate(update); + assertSuccess(env.applyTripUpdate(update)); - assertEquals(1, result.successful()); - - final TimetableSnapshot snapshot = env.getTimetableSnapshot(); + var snapshot = env.getTimetableSnapshot(); final Timetable forToday = snapshot.resolve(pattern1, RealtimeTestEnvironment.SERVICE_DATE); final Timetable schedule = snapshot.resolve(pattern1, null); assertNotSame(forToday, schedule); @@ -88,9 +87,7 @@ void cancelingAddedTrip(ScheduleRelationship relationship, RealTimeState state) .addStopTime(env.stopC1.getId().getId(), 55) .build(); - var result = env.applyTripUpdate(update, DIFFERENTIAL); - - assertEquals(1, result.successful()); + assertSuccess(env.applyTripUpdate(update, DIFFERENTIAL)); // Cancel or delete the added trip update = @@ -101,9 +98,7 @@ void cancelingAddedTrip(ScheduleRelationship relationship, RealTimeState state) env.timeZone ) .build(); - result = env.applyTripUpdate(update, DIFFERENTIAL); - - assertEquals(1, result.successful()); + assertSuccess(env.applyTripUpdate(update, DIFFERENTIAL)); final TimetableSnapshot snapshot = env.getTimetableSnapshot(); // Get the trip pattern of the added trip which goes through stopA diff --git a/src/test/java/org/opentripplanner/updater/trip/moduletests/delay/DelayedTest.java b/src/test/java/org/opentripplanner/updater/trip/moduletests/delay/DelayedTest.java index 5752e4941be..7440a189846 100644 --- a/src/test/java/org/opentripplanner/updater/trip/moduletests/delay/DelayedTest.java +++ b/src/test/java/org/opentripplanner/updater/trip/moduletests/delay/DelayedTest.java @@ -4,7 +4,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotSame; -import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.opentripplanner.test.support.UpdateResultAssertions.assertSuccess; import static org.opentripplanner.updater.trip.RealtimeTestEnvironment.SERVICE_DATE; @@ -43,53 +42,34 @@ void singleStopDelay() { assertEquals(1, result.successful()); - // trip1 should be modified - { - var pattern1 = env.getPatternForTrip(env.trip1); - final int trip1Index = pattern1.getScheduledTimetable().getTripIndex(env.trip1.getId()); - - final TimetableSnapshot snapshot = env.getTimetableSnapshot(); - final Timetable trip1Realtime = snapshot.resolve( - pattern1, - RealtimeTestEnvironment.SERVICE_DATE - ); - final Timetable trip1Scheduled = snapshot.resolve(pattern1, null); - - assertNotSame(trip1Realtime, trip1Scheduled); - assertNotSame( - trip1Realtime.getTripTimes(trip1Index), - trip1Scheduled.getTripTimes(trip1Index) - ); - assertEquals(1, trip1Realtime.getTripTimes(trip1Index).getArrivalDelay(STOP_SEQUENCE)); - assertEquals(1, trip1Realtime.getTripTimes(trip1Index).getDepartureDelay(STOP_SEQUENCE)); - - assertEquals( - RealTimeState.SCHEDULED, - trip1Scheduled.getTripTimes(trip1Index).getRealTimeState() - ); - assertEquals( - RealTimeState.UPDATED, - trip1Realtime.getTripTimes(trip1Index).getRealTimeState() - ); - } - - // trip2 should keep the scheduled information - { - var pattern = env.getPatternForTrip(env.trip2); - final int tripIndex = pattern.getScheduledTimetable().getTripIndex(env.trip2.getId()); - - final TimetableSnapshot snapshot = env.getTimetableSnapshot(); - final Timetable realtime = snapshot.resolve(pattern, RealtimeTestEnvironment.SERVICE_DATE); - final Timetable scheduled = snapshot.resolve(pattern, null); - - assertSame(realtime, scheduled); - assertSame(realtime.getTripTimes(tripIndex), scheduled.getTripTimes(tripIndex)); - assertEquals(0, realtime.getTripTimes(tripIndex).getArrivalDelay(STOP_SEQUENCE)); - assertEquals(0, realtime.getTripTimes(tripIndex).getDepartureDelay(STOP_SEQUENCE)); - - assertEquals(RealTimeState.SCHEDULED, scheduled.getTripTimes(tripIndex).getRealTimeState()); - assertEquals(RealTimeState.SCHEDULED, realtime.getTripTimes(tripIndex).getRealTimeState()); - } + var pattern1 = env.getPatternForTrip(env.trip1); + int trip1Index = pattern1.getScheduledTimetable().getTripIndex(env.trip1.getId()); + + final TimetableSnapshot snapshot = env.getTimetableSnapshot(); + final Timetable trip1Realtime = snapshot.resolve( + pattern1, + RealtimeTestEnvironment.SERVICE_DATE + ); + final Timetable trip1Scheduled = snapshot.resolve(pattern1, null); + + assertNotSame(trip1Realtime, trip1Scheduled); + assertNotSame(trip1Realtime.getTripTimes(trip1Index), trip1Scheduled.getTripTimes(trip1Index)); + assertEquals(DELAY, trip1Realtime.getTripTimes(trip1Index).getArrivalDelay(STOP_SEQUENCE)); + assertEquals(DELAY, trip1Realtime.getTripTimes(trip1Index).getDepartureDelay(STOP_SEQUENCE)); + + assertEquals( + RealTimeState.SCHEDULED, + trip1Scheduled.getTripTimes(trip1Index).getRealTimeState() + ); + + assertEquals( + "SCHEDULED | A1 0:00:10 0:00:11 | B1 0:00:20 0:00:21", + env.getScheduledTimetable(env.trip1.getId()) + ); + assertEquals( + "UPDATED | A1 [ND] 0:00:10 0:00:11 | B1 0:00:21 0:00:22", + env.getRealtimeTimetable(env.trip1.getId().getId()) + ); } /** @@ -110,7 +90,6 @@ void complexDelay() { assertSuccess(env.applyTripUpdate(tripUpdate)); - // THEN final TimetableSnapshot snapshot = env.getTimetableSnapshot(); final TripPattern originalTripPattern = env.transitModel diff --git a/src/test/java/org/opentripplanner/updater/trip/moduletests/delay/SkippedTest.java b/src/test/java/org/opentripplanner/updater/trip/moduletests/delay/SkippedTest.java index 4d91eefd390..c70dd380602 100644 --- a/src/test/java/org/opentripplanner/updater/trip/moduletests/delay/SkippedTest.java +++ b/src/test/java/org/opentripplanner/updater/trip/moduletests/delay/SkippedTest.java @@ -13,13 +13,10 @@ import org.junit.jupiter.api.Test; import org.opentripplanner.framework.i18n.NonLocalizedString; -import org.opentripplanner.model.Timetable; -import org.opentripplanner.model.TimetableSnapshot; import org.opentripplanner.transit.model.framework.FeedScopedId; -import org.opentripplanner.transit.model.network.TripPattern; import org.opentripplanner.transit.model.timetable.RealTimeState; import org.opentripplanner.transit.model.timetable.Trip; -import org.opentripplanner.transit.model.timetable.TripTimes; +import org.opentripplanner.transit.model.timetable.TripTimesStringBuilder; import org.opentripplanner.updater.trip.RealtimeTestEnvironment; import org.opentripplanner.updater.trip.TripUpdateBuilder; @@ -41,27 +38,24 @@ void scheduledTripWithSkippedAndScheduled() { assertSuccess(env.applyTripUpdate(tripUpdate)); - final TimetableSnapshot snapshot = env.getTimetableSnapshot(); + var snapshot = env.getTimetableSnapshot(); // Original trip pattern { - final FeedScopedId tripId = env.trip2.getId(); - final Trip trip = env.transitModel.getTransitModelIndex().getTripForId().get(tripId); - final TripPattern originalTripPattern = env.transitModel + var tripId = env.trip2.getId(); + var trip = env.transitModel.getTransitModelIndex().getTripForId().get(tripId); + var originalTripPattern = env.transitModel .getTransitModelIndex() .getPatternForTrip() .get(trip); - final Timetable originalTimetableForToday = snapshot.resolve( - originalTripPattern, - SERVICE_DATE - ); - final Timetable originalTimetableScheduled = snapshot.resolve(originalTripPattern, null); + var originalTimetableForToday = snapshot.resolve(originalTripPattern, SERVICE_DATE); + var originalTimetableScheduled = snapshot.resolve(originalTripPattern, null); assertNotSame(originalTimetableForToday, originalTimetableScheduled); - final int originalTripIndexForToday = originalTimetableForToday.getTripIndex(tripId); - final TripTimes originalTripTimesForToday = originalTimetableForToday.getTripTimes( + int originalTripIndexForToday = originalTimetableForToday.getTripIndex(tripId); + var originalTripTimesForToday = originalTimetableForToday.getTripTimes( originalTripIndexForToday ); assertTrue( @@ -74,13 +68,10 @@ void scheduledTripWithSkippedAndScheduled() { // New trip pattern { - final TripPattern newTripPattern = snapshot.getRealtimeAddedTripPattern( - env.trip2.getId(), - SERVICE_DATE - ); + var newTripPattern = snapshot.getRealtimeAddedTripPattern(env.trip2.getId(), SERVICE_DATE); - final Timetable newTimetableForToday = snapshot.resolve(newTripPattern, SERVICE_DATE); - final Timetable newTimetableScheduled = snapshot.resolve(newTripPattern, null); + var newTimetableForToday = snapshot.resolve(newTripPattern, SERVICE_DATE); + var newTimetableScheduled = snapshot.resolve(newTripPattern, null); assertNotSame(newTimetableForToday, newTimetableScheduled); @@ -88,7 +79,7 @@ void scheduledTripWithSkippedAndScheduled() { assertFalse(newTripPattern.canBoard(1)); assertTrue(newTripPattern.canBoard(2)); - final int newTimetableForTodayModifiedTripIndex = newTimetableForToday.getTripIndex( + int newTimetableForTodayModifiedTripIndex = newTimetableForToday.getTripIndex( scheduledTripId ); @@ -101,15 +92,10 @@ void scheduledTripWithSkippedAndScheduled() { "New trip should not be found in scheduled time table" ); - assertEquals(0, newTripTimes.getArrivalDelay(0)); - assertEquals(0, newTripTimes.getDepartureDelay(0)); - assertEquals(42, newTripTimes.getArrivalDelay(1)); - assertEquals(47, newTripTimes.getDepartureDelay(1)); - assertEquals(90, newTripTimes.getArrivalDelay(2)); - assertEquals(90, newTripTimes.getDepartureDelay(2)); - assertFalse(newTripTimes.isCancelledStop(0)); - assertTrue(newTripTimes.isCancelledStop(1)); - assertFalse(newTripTimes.isNoDataStop(2)); + assertEquals( + "UPDATED | A1 0:01 0:01:01 | B1 [C] 0:01:52 0:01:58 | C1 0:02:50 0:02:51", + env.getRealtimeTimetable(scheduledTripId) + ); } } @@ -133,7 +119,7 @@ void scheduledTripWithPreviouslySkipped() { .addDelayedStopTime(2, 90) .build(); - var result = assertSuccess(env.applyTripUpdate(tripUpdate, DIFFERENTIAL)); + assertSuccess(env.applyTripUpdate(tripUpdate, DIFFERENTIAL)); // Create update to the same trip but now the skipped stop is no longer skipped var scheduledBuilder = new TripUpdateBuilder( @@ -149,38 +135,34 @@ void scheduledTripWithPreviouslySkipped() { tripUpdate = scheduledBuilder.build(); // apply the update with the previously skipped stop now scheduled - result = assertSuccess(env.applyTripUpdate(tripUpdate, DIFFERENTIAL)); + assertSuccess(env.applyTripUpdate(tripUpdate, DIFFERENTIAL)); - assertEquals(1, result.successful()); // Check that the there is no longer a realtime added trip pattern for the trip and that the // stoptime updates have gone through var snapshot = env.getTimetableSnapshot(); { - final TripPattern newTripPattern = snapshot.getRealtimeAddedTripPattern(tripId, SERVICE_DATE); + var newTripPattern = snapshot.getRealtimeAddedTripPattern(tripId, SERVICE_DATE); assertNull(newTripPattern); final Trip trip = env.transitModel.getTransitModelIndex().getTripForId().get(tripId); - final TripPattern originalTripPattern = env.transitModel + var originalTripPattern = env.transitModel .getTransitModelIndex() .getPatternForTrip() .get(trip); - final Timetable originalTimetableForToday = snapshot.resolve( - originalTripPattern, - SERVICE_DATE - ); + var originalTimetableForToday = snapshot.resolve(originalTripPattern, SERVICE_DATE); - final Timetable originalTimetableScheduled = snapshot.resolve(originalTripPattern, null); + var originalTimetableScheduled = snapshot.resolve(originalTripPattern, null); assertNotSame(originalTimetableForToday, originalTimetableScheduled); - final int originalTripIndexScheduled = originalTimetableScheduled.getTripIndex(tripId); + int originalTripIndexScheduled = originalTimetableScheduled.getTripIndex(tripId); assertTrue( originalTripIndexScheduled > -1, "Original trip should be found in scheduled time table" ); - final TripTimes originalTripTimesScheduled = originalTimetableScheduled.getTripTimes( + var originalTripTimesScheduled = originalTimetableScheduled.getTripTimes( originalTripIndexScheduled ); assertFalse( @@ -188,7 +170,7 @@ void scheduledTripWithPreviouslySkipped() { "Original trip times should not be canceled in scheduled time table" ); assertEquals(RealTimeState.SCHEDULED, originalTripTimesScheduled.getRealTimeState()); - final int originalTripIndexForToday = originalTimetableForToday.getTripIndex(tripId); + int originalTripIndexForToday = originalTimetableForToday.getTripIndex(tripId); assertTrue( originalTripIndexForToday > -1, @@ -214,12 +196,12 @@ void skippedNoData() { var env = RealtimeTestEnvironment.gtfs(); final FeedScopedId tripId = env.trip2.getId(); - var builder = new TripUpdateBuilder(tripId.getId(), SERVICE_DATE, SCHEDULED, env.timeZone) + + var tripUpdate = new TripUpdateBuilder(tripId.getId(), SERVICE_DATE, SCHEDULED, env.timeZone) .addNoDataStop(0) .addSkippedStop(1) - .addNoDataStop(2); - - var tripUpdate = builder.build(); + .addNoDataStop(2) + .build(); assertSuccess(env.applyTripUpdate(tripUpdate)); @@ -228,39 +210,40 @@ void skippedNoData() { // Original trip pattern { - final TripPattern originalTripPattern = env.transitModel + var originalTripPattern = env.transitModel .getTransitModelIndex() .getPatternForTrip() .get(env.trip2); - final Timetable originalTimetableForToday = snapshot.resolve( - originalTripPattern, - SERVICE_DATE - ); - final Timetable originalTimetableScheduled = snapshot.resolve(originalTripPattern, null); + var originalTimetableForToday = snapshot.resolve(originalTripPattern, SERVICE_DATE); + var originalTimetableScheduled = snapshot.resolve(originalTripPattern, null); assertNotSame(originalTimetableForToday, originalTimetableScheduled); - final int originalTripIndexScheduled = originalTimetableScheduled.getTripIndex(tripId); + int originalTripIndexScheduled = originalTimetableScheduled.getTripIndex(tripId); assertTrue( originalTripIndexScheduled > -1, "Original trip should be found in scheduled time table" ); - final TripTimes originalTripTimesScheduled = originalTimetableScheduled.getTripTimes( + var originalTripTimesScheduled = originalTimetableScheduled.getTripTimes( originalTripIndexScheduled ); assertFalse( originalTripTimesScheduled.isCanceledOrDeleted(), "Original trip times should not be canceled in scheduled time table" ); - assertEquals(RealTimeState.SCHEDULED, originalTripTimesScheduled.getRealTimeState()); - final int originalTripIndexForToday = originalTimetableForToday.getTripIndex(tripId); + assertEquals( + "SCHEDULED | A1 0:01 0:01:01 | B1 0:01:10 0:01:11 | C1 0:01:20 0:01:21", + TripTimesStringBuilder.encodeTripTimes(originalTripTimesScheduled, originalTripPattern) + ); + + int originalTripIndexForToday = originalTimetableForToday.getTripIndex(tripId); assertTrue( originalTripIndexForToday > -1, "Original trip should be found in time table for service date" ); - final TripTimes originalTripTimesForToday = originalTimetableForToday.getTripTimes( + var originalTripTimesForToday = originalTimetableForToday.getTripTimes( originalTripIndexForToday ); assertTrue( @@ -273,11 +256,11 @@ void skippedNoData() { // New trip pattern { - final TripPattern newTripPattern = snapshot.getRealtimeAddedTripPattern(tripId, SERVICE_DATE); + var newTripPattern = snapshot.getRealtimeAddedTripPattern(tripId, SERVICE_DATE); assertNotNull(newTripPattern, "New trip pattern should be found"); - final Timetable newTimetableForToday = snapshot.resolve(newTripPattern, SERVICE_DATE); - final Timetable newTimetableScheduled = snapshot.resolve(newTripPattern, null); + var newTimetableForToday = snapshot.resolve(newTripPattern, SERVICE_DATE); + var newTimetableScheduled = snapshot.resolve(newTripPattern, null); assertNotSame(newTimetableForToday, newTimetableScheduled); @@ -294,14 +277,13 @@ void skippedNoData() { newTripPattern.getTripHeadsign() ); - final int newTimetableForTodayModifiedTripIndex = newTimetableForToday.getTripIndex(tripId); + int newTimetableForTodayModifiedTripIndex = newTimetableForToday.getTripIndex(tripId); assertTrue( newTimetableForTodayModifiedTripIndex > -1, "New trip should be found in time table for service date" ); var newTripTimes = newTimetableForToday.getTripTimes(tripId); - assertEquals(RealTimeState.UPDATED, newTripTimes.getRealTimeState()); assertEquals( -1, @@ -309,15 +291,10 @@ void skippedNoData() { "New trip should not be found in scheduled time table" ); - assertEquals(0, newTripTimes.getArrivalDelay(0)); - assertEquals(0, newTripTimes.getDepartureDelay(0)); - assertEquals(0, newTripTimes.getArrivalDelay(1)); - assertEquals(0, newTripTimes.getDepartureDelay(1)); - assertEquals(0, newTripTimes.getArrivalDelay(2)); - assertEquals(0, newTripTimes.getDepartureDelay(2)); - assertTrue(newTripTimes.isNoDataStop(0)); - assertTrue(newTripTimes.isCancelledStop(1)); - assertTrue(newTripTimes.isNoDataStop(2)); + assertEquals( + "UPDATED | A1 [ND] 0:01 0:01:01 | B1 [C] 0:01:10 0:01:11 | C1 [ND] 0:01:20 0:01:21", + TripTimesStringBuilder.encodeTripTimes(newTripTimes, newTripPattern) + ); } } } diff --git a/src/test/java/org/opentripplanner/updater/trip/moduletests/rejection/InvalidInputTest.java b/src/test/java/org/opentripplanner/updater/trip/moduletests/rejection/InvalidInputTest.java index 4d28c60eeb5..4815d7180c4 100644 --- a/src/test/java/org/opentripplanner/updater/trip/moduletests/rejection/InvalidInputTest.java +++ b/src/test/java/org/opentripplanner/updater/trip/moduletests/rejection/InvalidInputTest.java @@ -29,9 +29,7 @@ void invalidTripDate(LocalDate date) { var env = RealtimeTestEnvironment.gtfs(); var update = new TripUpdateBuilder(env.trip1.getId().getId(), date, SCHEDULED, env.timeZone) - .addDelayedStopTime(1, 0) .addDelayedStopTime(2, 60, 80) - .addDelayedStopTime(3, 90, 90) .build(); var result = env.applyTripUpdate(update); From 02cb8f752a32a580daad6e7409b361761528c53f Mon Sep 17 00:00:00 2001 From: Leonard Ehrenfried Date: Tue, 18 Jun 2024 14:02:32 +0200 Subject: [PATCH 12/21] Increase code reuse in SkippedTest --- .../trip/moduletests/addition/AddedTest.java | 5 +- .../CancellationDeletionTest.java | 12 +- .../trip/moduletests/delay/DelayedTest.java | 26 +- .../trip/moduletests/delay/SkippedTest.java | 303 +++++++----------- .../rejection/InvalidTripIdTest.java | 9 +- 5 files changed, 128 insertions(+), 227 deletions(-) diff --git a/src/test/java/org/opentripplanner/updater/trip/moduletests/addition/AddedTest.java b/src/test/java/org/opentripplanner/updater/trip/moduletests/addition/AddedTest.java index 6a7d076923f..8a2d6e96407 100644 --- a/src/test/java/org/opentripplanner/updater/trip/moduletests/addition/AddedTest.java +++ b/src/test/java/org/opentripplanner/updater/trip/moduletests/addition/AddedTest.java @@ -17,7 +17,6 @@ import java.util.List; import org.junit.jupiter.api.Test; import org.opentripplanner.model.PickDrop; -import org.opentripplanner.model.Timetable; import org.opentripplanner.transit.model.basic.TransitMode; import org.opentripplanner.transit.model.network.TripPattern; import org.opentripplanner.transit.model.timetable.RealTimeState; @@ -148,8 +147,8 @@ private TripPattern assertAddedTrip(String tripId, RealtimeTestEnvironment env) assertEquals(1, patternsAtA.size()); var tripPattern = patternsAtA.stream().findFirst().get(); - final Timetable forToday = snapshot.resolve(tripPattern, SERVICE_DATE); - final Timetable schedule = snapshot.resolve(tripPattern, null); + var forToday = snapshot.resolve(tripPattern, SERVICE_DATE); + var schedule = snapshot.resolve(tripPattern, null); assertNotSame(forToday, schedule); diff --git a/src/test/java/org/opentripplanner/updater/trip/moduletests/cancellation/CancellationDeletionTest.java b/src/test/java/org/opentripplanner/updater/trip/moduletests/cancellation/CancellationDeletionTest.java index 41e42bf00db..3b527b64e5d 100644 --- a/src/test/java/org/opentripplanner/updater/trip/moduletests/cancellation/CancellationDeletionTest.java +++ b/src/test/java/org/opentripplanner/updater/trip/moduletests/cancellation/CancellationDeletionTest.java @@ -12,8 +12,6 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; -import org.opentripplanner.model.Timetable; -import org.opentripplanner.model.TimetableSnapshot; import org.opentripplanner.transit.model.timetable.RealTimeState; import org.opentripplanner.updater.trip.RealtimeTestEnvironment; import org.opentripplanner.updater.trip.TripUpdateBuilder; @@ -49,8 +47,8 @@ void cancelledTrip(ScheduleRelationship relationship, RealTimeState state) { assertSuccess(env.applyTripUpdate(update)); var snapshot = env.getTimetableSnapshot(); - final Timetable forToday = snapshot.resolve(pattern1, RealtimeTestEnvironment.SERVICE_DATE); - final Timetable schedule = snapshot.resolve(pattern1, null); + var forToday = snapshot.resolve(pattern1, RealtimeTestEnvironment.SERVICE_DATE); + var schedule = snapshot.resolve(pattern1, null); assertNotSame(forToday, schedule); assertNotSame(forToday.getTripTimes(tripIndex1), schedule.getTripTimes(tripIndex1)); @@ -100,15 +98,15 @@ void cancelingAddedTrip(ScheduleRelationship relationship, RealTimeState state) .build(); assertSuccess(env.applyTripUpdate(update, DIFFERENTIAL)); - final TimetableSnapshot snapshot = env.getTimetableSnapshot(); + var snapshot = env.getTimetableSnapshot(); // Get the trip pattern of the added trip which goes through stopA var patternsAtA = snapshot.getPatternsForStop(env.stopA1); assertNotNull(patternsAtA, "Added trip pattern should be found"); var tripPattern = patternsAtA.stream().findFirst().get(); - final Timetable forToday = snapshot.resolve(tripPattern, RealtimeTestEnvironment.SERVICE_DATE); - final Timetable schedule = snapshot.resolve(tripPattern, null); + var forToday = snapshot.resolve(tripPattern, RealtimeTestEnvironment.SERVICE_DATE); + var schedule = snapshot.resolve(tripPattern, null); assertNotSame(forToday, schedule); diff --git a/src/test/java/org/opentripplanner/updater/trip/moduletests/delay/DelayedTest.java b/src/test/java/org/opentripplanner/updater/trip/moduletests/delay/DelayedTest.java index 7440a189846..d9282e1b155 100644 --- a/src/test/java/org/opentripplanner/updater/trip/moduletests/delay/DelayedTest.java +++ b/src/test/java/org/opentripplanner/updater/trip/moduletests/delay/DelayedTest.java @@ -9,8 +9,6 @@ import static org.opentripplanner.updater.trip.RealtimeTestEnvironment.SERVICE_DATE; import org.junit.jupiter.api.Test; -import org.opentripplanner.model.Timetable; -import org.opentripplanner.model.TimetableSnapshot; import org.opentripplanner.transit.model.network.TripPattern; import org.opentripplanner.transit.model.timetable.RealTimeState; import org.opentripplanner.transit.model.timetable.TripTimes; @@ -45,12 +43,9 @@ void singleStopDelay() { var pattern1 = env.getPatternForTrip(env.trip1); int trip1Index = pattern1.getScheduledTimetable().getTripIndex(env.trip1.getId()); - final TimetableSnapshot snapshot = env.getTimetableSnapshot(); - final Timetable trip1Realtime = snapshot.resolve( - pattern1, - RealtimeTestEnvironment.SERVICE_DATE - ); - final Timetable trip1Scheduled = snapshot.resolve(pattern1, null); + var snapshot = env.getTimetableSnapshot(); + var trip1Realtime = snapshot.resolve(pattern1, RealtimeTestEnvironment.SERVICE_DATE); + var trip1Scheduled = snapshot.resolve(pattern1, null); assertNotSame(trip1Realtime, trip1Scheduled); assertNotSame(trip1Realtime.getTripTimes(trip1Index), trip1Scheduled.getTripTimes(trip1Index)); @@ -79,26 +74,25 @@ void singleStopDelay() { void complexDelay() { var env = RealtimeTestEnvironment.gtfs(); - String tripId = env.trip2.getId().getId(); + var tripId = env.trip2.getId().getId(); - var builder = new TripUpdateBuilder(tripId, SERVICE_DATE, SCHEDULED, env.timeZone) + var tripUpdate = new TripUpdateBuilder(tripId, SERVICE_DATE, SCHEDULED, env.timeZone) .addDelayedStopTime(0, 0) .addDelayedStopTime(1, 60, 80) - .addDelayedStopTime(2, 90, 90); - - var tripUpdate = builder.build(); + .addDelayedStopTime(2, 90, 90) + .build(); assertSuccess(env.applyTripUpdate(tripUpdate)); - final TimetableSnapshot snapshot = env.getTimetableSnapshot(); + var snapshot = env.getTimetableSnapshot(); final TripPattern originalTripPattern = env.transitModel .getTransitModelIndex() .getPatternForTrip() .get(env.trip2); - final Timetable originalTimetableForToday = snapshot.resolve(originalTripPattern, SERVICE_DATE); - final Timetable originalTimetableScheduled = snapshot.resolve(originalTripPattern, null); + var originalTimetableForToday = snapshot.resolve(originalTripPattern, SERVICE_DATE); + var originalTimetableScheduled = snapshot.resolve(originalTripPattern, null); assertNotSame(originalTimetableForToday, originalTimetableScheduled); diff --git a/src/test/java/org/opentripplanner/updater/trip/moduletests/delay/SkippedTest.java b/src/test/java/org/opentripplanner/updater/trip/moduletests/delay/SkippedTest.java index c70dd380602..349e472036d 100644 --- a/src/test/java/org/opentripplanner/updater/trip/moduletests/delay/SkippedTest.java +++ b/src/test/java/org/opentripplanner/updater/trip/moduletests/delay/SkippedTest.java @@ -3,7 +3,6 @@ import static com.google.transit.realtime.GtfsRealtime.TripDescriptor.ScheduleRelationship.SCHEDULED; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNotSame; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -12,10 +11,8 @@ import static org.opentripplanner.updater.trip.UpdateIncrementality.DIFFERENTIAL; import org.junit.jupiter.api.Test; -import org.opentripplanner.framework.i18n.NonLocalizedString; import org.opentripplanner.transit.model.framework.FeedScopedId; import org.opentripplanner.transit.model.timetable.RealTimeState; -import org.opentripplanner.transit.model.timetable.Trip; import org.opentripplanner.transit.model.timetable.TripTimesStringBuilder; import org.opentripplanner.updater.trip.RealtimeTestEnvironment; import org.opentripplanner.updater.trip.TripUpdateBuilder; @@ -38,65 +35,14 @@ void scheduledTripWithSkippedAndScheduled() { assertSuccess(env.applyTripUpdate(tripUpdate)); - var snapshot = env.getTimetableSnapshot(); + assertOriginalTripPatternIsDeleted(env, env.trip2.getId()); + + assertNewTripTimesIsUpdated(env, env.trip2.getId()); - // Original trip pattern - { - var tripId = env.trip2.getId(); - var trip = env.transitModel.getTransitModelIndex().getTripForId().get(tripId); - var originalTripPattern = env.transitModel - .getTransitModelIndex() - .getPatternForTrip() - .get(trip); - - var originalTimetableForToday = snapshot.resolve(originalTripPattern, SERVICE_DATE); - var originalTimetableScheduled = snapshot.resolve(originalTripPattern, null); - - assertNotSame(originalTimetableForToday, originalTimetableScheduled); - - int originalTripIndexForToday = originalTimetableForToday.getTripIndex(tripId); - var originalTripTimesForToday = originalTimetableForToday.getTripTimes( - originalTripIndexForToday - ); - assertTrue( - originalTripTimesForToday.isDeleted(), - "Original trip times should be deleted in time table for service date" - ); - // original trip should be canceled - assertEquals(RealTimeState.DELETED, originalTripTimesForToday.getRealTimeState()); - } - - // New trip pattern - { - var newTripPattern = snapshot.getRealtimeAddedTripPattern(env.trip2.getId(), SERVICE_DATE); - - var newTimetableForToday = snapshot.resolve(newTripPattern, SERVICE_DATE); - var newTimetableScheduled = snapshot.resolve(newTripPattern, null); - - assertNotSame(newTimetableForToday, newTimetableScheduled); - - assertTrue(newTripPattern.canBoard(0)); - assertFalse(newTripPattern.canBoard(1)); - assertTrue(newTripPattern.canBoard(2)); - - int newTimetableForTodayModifiedTripIndex = newTimetableForToday.getTripIndex( - scheduledTripId - ); - - var newTripTimes = newTimetableForToday.getTripTimes(newTimetableForTodayModifiedTripIndex); - assertEquals(RealTimeState.UPDATED, newTripTimes.getRealTimeState()); - - assertEquals( - -1, - newTimetableScheduled.getTripIndex(scheduledTripId), - "New trip should not be found in scheduled time table" - ); - - assertEquals( - "UPDATED | A1 0:01 0:01:01 | B1 [C] 0:01:52 0:01:58 | C1 0:02:50 0:02:51", - env.getRealtimeTimetable(scheduledTripId) - ); - } + assertEquals( + "UPDATED | A1 0:01 0:01:01 | B1 [C] 0:01:52 0:01:58 | C1 0:02:50 0:02:51", + env.getRealtimeTimetable(scheduledTripId) + ); } /** @@ -141,51 +87,18 @@ void scheduledTripWithPreviouslySkipped() { // stoptime updates have gone through var snapshot = env.getTimetableSnapshot(); - { - var newTripPattern = snapshot.getRealtimeAddedTripPattern(tripId, SERVICE_DATE); - assertNull(newTripPattern); - final Trip trip = env.transitModel.getTransitModelIndex().getTripForId().get(tripId); - - var originalTripPattern = env.transitModel - .getTransitModelIndex() - .getPatternForTrip() - .get(trip); - var originalTimetableForToday = snapshot.resolve(originalTripPattern, SERVICE_DATE); - - var originalTimetableScheduled = snapshot.resolve(originalTripPattern, null); - - assertNotSame(originalTimetableForToday, originalTimetableScheduled); - - int originalTripIndexScheduled = originalTimetableScheduled.getTripIndex(tripId); - - assertTrue( - originalTripIndexScheduled > -1, - "Original trip should be found in scheduled time table" - ); - var originalTripTimesScheduled = originalTimetableScheduled.getTripTimes( - originalTripIndexScheduled - ); - assertFalse( - originalTripTimesScheduled.isCanceledOrDeleted(), - "Original trip times should not be canceled in scheduled time table" - ); - assertEquals(RealTimeState.SCHEDULED, originalTripTimesScheduled.getRealTimeState()); - int originalTripIndexForToday = originalTimetableForToday.getTripIndex(tripId); - - assertTrue( - originalTripIndexForToday > -1, - "Original trip should be found in time table for service date" - ); - - assertEquals( - "SCHEDULED | A1 0:01 0:01:01 | B1 0:01:10 0:01:11 | C1 0:01:20 0:01:21", - env.getScheduledTimetable(tripId) - ); - assertEquals( - "UPDATED | A1 0:01 0:01:01 | B1 0:02 0:02:01 | C1 0:02:50 0:02:51", - env.getRealtimeTimetable(tripId, SERVICE_DATE) - ); - } + assertNull(snapshot.getRealtimeAddedTripPattern(tripId, SERVICE_DATE)); + + assertNewTripTimesIsUpdated(env, tripId); + + assertEquals( + "SCHEDULED | A1 0:01 0:01:01 | B1 0:01:10 0:01:11 | C1 0:01:20 0:01:21", + env.getScheduledTimetable(tripId) + ); + assertEquals( + "UPDATED | A1 0:01 0:01:01 | B1 0:02 0:02:01 | C1 0:02:50 0:02:51", + env.getRealtimeTimetable(tripId, SERVICE_DATE) + ); } /** @@ -205,96 +118,96 @@ void skippedNoData() { assertSuccess(env.applyTripUpdate(tripUpdate)); - // THEN + assertOriginalTripPatternIsDeleted(env, tripId); + + assertNewTripTimesIsUpdated(env, tripId); + + assertEquals( + "UPDATED | A1 [ND] 0:01 0:01:01 | B1 [C] 0:01:10 0:01:11 | C1 [ND] 0:01:20 0:01:21", + env.getRealtimeTimetable(env.trip2) + ); + } + + private static void assertOriginalTripPatternIsDeleted( + RealtimeTestEnvironment env, + FeedScopedId tripId + ) { + var trip = env.transitModel.getTransitModelIndex().getTripForId().get(tripId); + var originalTripPattern = env.transitModel.getTransitModelIndex().getPatternForTrip().get(trip); var snapshot = env.getTimetableSnapshot(); + var originalTimetableForToday = snapshot.resolve(originalTripPattern, SERVICE_DATE); + var originalTimetableScheduled = snapshot.resolve(originalTripPattern, null); + + assertNotSame(originalTimetableForToday, originalTimetableScheduled); + + int originalTripIndexScheduled = originalTimetableScheduled.getTripIndex(tripId); + assertTrue( + originalTripIndexScheduled > -1, + "Original trip should be found in scheduled time table" + ); + var originalTripTimesScheduled = originalTimetableScheduled.getTripTimes( + originalTripIndexScheduled + ); + assertFalse( + originalTripTimesScheduled.isCanceledOrDeleted(), + "Original trip times should not be canceled in scheduled time table" + ); + + assertEquals( + "SCHEDULED | A1 0:01 0:01:01 | B1 0:01:10 0:01:11 | C1 0:01:20 0:01:21", + TripTimesStringBuilder.encodeTripTimes(originalTripTimesScheduled, originalTripPattern) + ); + + int originalTripIndexForToday = originalTimetableForToday.getTripIndex(tripId); + assertTrue( + originalTripIndexForToday > -1, + "Original trip should be found in time table for service date" + ); + var originalTripTimesForToday = originalTimetableForToday.getTripTimes( + originalTripIndexForToday + ); + assertTrue( + originalTripTimesForToday.isDeleted(), + "Original trip times should be deleted in time table for service date" + ); + // original trip should be deleted + assertEquals(RealTimeState.DELETED, originalTripTimesForToday.getRealTimeState()); + } - // Original trip pattern - { - var originalTripPattern = env.transitModel - .getTransitModelIndex() - .getPatternForTrip() - .get(env.trip2); - - var originalTimetableForToday = snapshot.resolve(originalTripPattern, SERVICE_DATE); - var originalTimetableScheduled = snapshot.resolve(originalTripPattern, null); - - assertNotSame(originalTimetableForToday, originalTimetableScheduled); - - int originalTripIndexScheduled = originalTimetableScheduled.getTripIndex(tripId); - assertTrue( - originalTripIndexScheduled > -1, - "Original trip should be found in scheduled time table" - ); - var originalTripTimesScheduled = originalTimetableScheduled.getTripTimes( - originalTripIndexScheduled - ); - assertFalse( - originalTripTimesScheduled.isCanceledOrDeleted(), - "Original trip times should not be canceled in scheduled time table" - ); - - assertEquals( - "SCHEDULED | A1 0:01 0:01:01 | B1 0:01:10 0:01:11 | C1 0:01:20 0:01:21", - TripTimesStringBuilder.encodeTripTimes(originalTripTimesScheduled, originalTripPattern) - ); - - int originalTripIndexForToday = originalTimetableForToday.getTripIndex(tripId); - assertTrue( - originalTripIndexForToday > -1, - "Original trip should be found in time table for service date" - ); - var originalTripTimesForToday = originalTimetableForToday.getTripTimes( - originalTripIndexForToday - ); - assertTrue( - originalTripTimesForToday.isDeleted(), - "Original trip times should be deleted in time table for service date" - ); - // original trip should be deleted - assertEquals(RealTimeState.DELETED, originalTripTimesForToday.getRealTimeState()); - } - - // New trip pattern - { - var newTripPattern = snapshot.getRealtimeAddedTripPattern(tripId, SERVICE_DATE); - assertNotNull(newTripPattern, "New trip pattern should be found"); - - var newTimetableForToday = snapshot.resolve(newTripPattern, SERVICE_DATE); - var newTimetableScheduled = snapshot.resolve(newTripPattern, null); - - assertNotSame(newTimetableForToday, newTimetableScheduled); - - assertTrue(newTripPattern.canBoard(0)); - assertFalse(newTripPattern.canBoard(1)); - assertTrue(newTripPattern.canBoard(2)); - - assertEquals( - new NonLocalizedString("Headsign of TestTrip2"), - newTripPattern.getTripHeadsign() - ); - assertEquals( - newTripPattern.getOriginalTripPattern().getTripHeadsign(), - newTripPattern.getTripHeadsign() - ); - - int newTimetableForTodayModifiedTripIndex = newTimetableForToday.getTripIndex(tripId); - assertTrue( - newTimetableForTodayModifiedTripIndex > -1, - "New trip should be found in time table for service date" - ); - - var newTripTimes = newTimetableForToday.getTripTimes(tripId); - - assertEquals( - -1, - newTimetableScheduled.getTripIndex(tripId), - "New trip should not be found in scheduled time table" - ); - - assertEquals( - "UPDATED | A1 [ND] 0:01 0:01:01 | B1 [C] 0:01:10 0:01:11 | C1 [ND] 0:01:20 0:01:21", - TripTimesStringBuilder.encodeTripTimes(newTripTimes, newTripPattern) - ); - } + private static void assertNewTripTimesIsUpdated( + RealtimeTestEnvironment env, + FeedScopedId tripId + ) { + var originalTripPattern = env.transitModel + .getTransitModelIndex() + .getPatternForTrip() + .get(env.trip2); + var snapshot = env.getTimetableSnapshot(); + var originalTimetableForToday = snapshot.resolve(originalTripPattern, SERVICE_DATE); + + var originalTimetableScheduled = snapshot.resolve(originalTripPattern, null); + + assertNotSame(originalTimetableForToday, originalTimetableScheduled); + + int originalTripIndexScheduled = originalTimetableScheduled.getTripIndex(tripId); + + assertTrue( + originalTripIndexScheduled > -1, + "Original trip should be found in scheduled time table" + ); + var originalTripTimesScheduled = originalTimetableScheduled.getTripTimes( + originalTripIndexScheduled + ); + assertFalse( + originalTripTimesScheduled.isCanceledOrDeleted(), + "Original trip times should not be canceled in scheduled time table" + ); + assertEquals(RealTimeState.SCHEDULED, originalTripTimesScheduled.getRealTimeState()); + int originalTripIndexForToday = originalTimetableForToday.getTripIndex(tripId); + + assertTrue( + originalTripIndexForToday > -1, + "Original trip should be found in time table for service date" + ); } } diff --git a/src/test/java/org/opentripplanner/updater/trip/moduletests/rejection/InvalidTripIdTest.java b/src/test/java/org/opentripplanner/updater/trip/moduletests/rejection/InvalidTripIdTest.java index 6cacaeb6ca9..e6e7a4737f7 100644 --- a/src/test/java/org/opentripplanner/updater/trip/moduletests/rejection/InvalidTripIdTest.java +++ b/src/test/java/org/opentripplanner/updater/trip/moduletests/rejection/InvalidTripIdTest.java @@ -1,5 +1,6 @@ package org.opentripplanner.updater.trip.moduletests.rejection; +import static com.google.transit.realtime.GtfsRealtime.TripDescriptor.ScheduleRelationship.SCHEDULED; import static org.opentripplanner.test.support.UpdateResultAssertions.assertFailure; import static org.opentripplanner.updater.spi.UpdateError.UpdateErrorType.INVALID_INPUT_STRUCTURE; @@ -26,16 +27,12 @@ void invalidTripId(String tripId) { if (tripId != null) { tripDescriptorBuilder.setTripId(tripId); } - tripDescriptorBuilder.setScheduleRelationship( - GtfsRealtime.TripDescriptor.ScheduleRelationship.SCHEDULED - ); + tripDescriptorBuilder.setScheduleRelationship(SCHEDULED); var tripUpdateBuilder = GtfsRealtime.TripUpdate.newBuilder(); tripUpdateBuilder.setTrip(tripDescriptorBuilder); var tripUpdate = tripUpdateBuilder.build(); - var result = env.applyTripUpdate(tripUpdate); - - assertFailure(INVALID_INPUT_STRUCTURE, result); + assertFailure(INVALID_INPUT_STRUCTURE, env.applyTripUpdate(tripUpdate)); } } From 21e745f4651d9f0c5b5b9112d0b209904fb4b9ab Mon Sep 17 00:00:00 2001 From: Leonard Ehrenfried Date: Wed, 19 Jun 2024 09:44:31 +0200 Subject: [PATCH 13/21] Simplify AddedTest --- .../trip/moduletests/addition/AddedTest.java | 46 ++++++------------- 1 file changed, 14 insertions(+), 32 deletions(-) diff --git a/src/test/java/org/opentripplanner/updater/trip/moduletests/addition/AddedTest.java b/src/test/java/org/opentripplanner/updater/trip/moduletests/addition/AddedTest.java index 8a2d6e96407..1e75f558510 100644 --- a/src/test/java/org/opentripplanner/updater/trip/moduletests/addition/AddedTest.java +++ b/src/test/java/org/opentripplanner/updater/trip/moduletests/addition/AddedTest.java @@ -2,7 +2,6 @@ import static com.google.transit.realtime.GtfsRealtime.TripDescriptor.ScheduleRelationship.ADDED; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNotSame; import static org.junit.jupiter.api.Assertions.assertSame; @@ -45,22 +44,15 @@ void addedTrip() { @Test void addedTripWithNewRoute() { var env = RealtimeTestEnvironment.gtfs(); - final var builder = new TripUpdateBuilder(ADDED_TRIP_ID, SERVICE_DATE, ADDED, env.timeZone); - // add extension to set route name, url, mode - builder.addTripExtension(); - - builder + var tripUpdate = new TripUpdateBuilder(ADDED_TRIP_ID, SERVICE_DATE, ADDED, env.timeZone) + .addTripExtension() .addStopTime(STOP_A1_ID, 30, DropOffPickupType.PHONE_AGENCY) .addStopTime(STOP_B1_ID, 40, DropOffPickupType.COORDINATE_WITH_DRIVER) - .addStopTime(STOP_B1_ID, 55, DropOffPickupType.NONE); - - var tripUpdate = builder.build(); + .addStopTime(STOP_B1_ID, 55, DropOffPickupType.NONE) + .build(); - // WHEN var result = assertSuccess(env.applyTripUpdate(tripUpdate)); - // THEN - assertTrue(result.warnings().isEmpty()); var pattern = assertAddedTrip(ADDED_TRIP_ID, env); @@ -83,21 +75,16 @@ void addedTripWithNewRoute() { @Test void addedWithUnknownStop() { var env = RealtimeTestEnvironment.gtfs(); - final var builder = new TripUpdateBuilder(ADDED_TRIP_ID, SERVICE_DATE, ADDED, env.timeZone); - // add extension to set route name, url, mode - builder.addTripExtension(); - - builder + var tripUpdate = new TripUpdateBuilder(ADDED_TRIP_ID, SERVICE_DATE, ADDED, env.timeZone) + // add extension to set route name, url, mode + .addTripExtension() .addStopTime(STOP_A1_ID, 30, DropOffPickupType.PHONE_AGENCY) .addStopTime("UNKNOWN_STOP_ID", 40, DropOffPickupType.COORDINATE_WITH_DRIVER) - .addStopTime(STOP_C1_ID, 55, DropOffPickupType.NONE); - - var tripUpdate = builder.build(); + .addStopTime(STOP_C1_ID, 55, DropOffPickupType.NONE) + .build(); var result = assertSuccess(env.applyTripUpdate(tripUpdate)); - assertFalse(result.warnings().isEmpty()); - assertEquals( List.of(UpdateSuccess.WarningType.UNKNOWN_STOPS_REMOVED_FROM_ADDED_TRIP), result.warnings() @@ -111,16 +98,13 @@ void addedWithUnknownStop() { @Test void repeatedlyAddedTripWithNewRoute() { var env = RealtimeTestEnvironment.gtfs(); - final var builder = new TripUpdateBuilder(ADDED_TRIP_ID, SERVICE_DATE, ADDED, env.timeZone); - // add extension to set route name, url, mode - builder.addTripExtension(); - - builder + var tripUpdate = new TripUpdateBuilder(ADDED_TRIP_ID, SERVICE_DATE, ADDED, env.timeZone) + // add extension to set route name, url, mode + .addTripExtension() .addStopTime(STOP_A1_ID, 30, DropOffPickupType.PHONE_AGENCY) .addStopTime(STOP_B1_ID, 40, DropOffPickupType.COORDINATE_WITH_DRIVER) - .addStopTime(STOP_C1_ID, 55, DropOffPickupType.NONE); - - var tripUpdate = builder.build(); + .addStopTime(STOP_C1_ID, 55, DropOffPickupType.NONE) + .build(); assertSuccess(env.applyTripUpdate(tripUpdate)); var pattern = assertAddedTrip(ADDED_TRIP_ID, env); @@ -131,8 +115,6 @@ void repeatedlyAddedTripWithNewRoute() { var secondPattern = assertAddedTrip(ADDED_TRIP_ID, env); var secondRoute = secondPattern.getRoute(); - // THEN - assertSame(firstRoute, secondRoute); assertNotNull(env.transitModel.getTransitModelIndex().getRouteForId(firstRoute.getId())); } From 85d513a1ed29e3bba87acd11f26657b20bbeef83 Mon Sep 17 00:00:00 2001 From: Leonard Ehrenfried Date: Mon, 1 Jul 2024 17:59:18 +0200 Subject: [PATCH 14/21] Move assertion class to another package --- .../ext/siri/SiriTimetableSnapshotSourceTest.java | 2 +- .../{test/support => updater/spi}/UpdateResultAssertions.java | 4 +--- .../updater/trip/moduletests/addition/AddedTest.java | 2 +- .../moduletests/cancellation/CancellationDeletionTest.java | 2 +- .../updater/trip/moduletests/delay/DelayedTest.java | 2 +- .../updater/trip/moduletests/delay/SkippedTest.java | 2 +- .../updater/trip/moduletests/rejection/InvalidInputTest.java | 2 +- .../updater/trip/moduletests/rejection/InvalidTripIdTest.java | 2 +- 8 files changed, 8 insertions(+), 10 deletions(-) rename src/test/java/org/opentripplanner/{test/support => updater/spi}/UpdateResultAssertions.java (82%) diff --git a/src/ext-test/java/org/opentripplanner/ext/siri/SiriTimetableSnapshotSourceTest.java b/src/ext-test/java/org/opentripplanner/ext/siri/SiriTimetableSnapshotSourceTest.java index 73f6b92ffe7..3c5d3acf1cb 100644 --- a/src/ext-test/java/org/opentripplanner/ext/siri/SiriTimetableSnapshotSourceTest.java +++ b/src/ext-test/java/org/opentripplanner/ext/siri/SiriTimetableSnapshotSourceTest.java @@ -1,7 +1,7 @@ package org.opentripplanner.ext.siri; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.opentripplanner.test.support.UpdateResultAssertions.assertFailure; +import static org.opentripplanner.updater.spi.UpdateResultAssertions.assertFailure; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; diff --git a/src/test/java/org/opentripplanner/test/support/UpdateResultAssertions.java b/src/test/java/org/opentripplanner/updater/spi/UpdateResultAssertions.java similarity index 82% rename from src/test/java/org/opentripplanner/test/support/UpdateResultAssertions.java rename to src/test/java/org/opentripplanner/updater/spi/UpdateResultAssertions.java index c6be0406ae3..13806cde4c3 100644 --- a/src/test/java/org/opentripplanner/test/support/UpdateResultAssertions.java +++ b/src/test/java/org/opentripplanner/updater/spi/UpdateResultAssertions.java @@ -1,11 +1,9 @@ -package org.opentripplanner.test.support; +package org.opentripplanner.updater.spi; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.Set; -import org.opentripplanner.updater.spi.UpdateError; -import org.opentripplanner.updater.spi.UpdateResult; public class UpdateResultAssertions { diff --git a/src/test/java/org/opentripplanner/updater/trip/moduletests/addition/AddedTest.java b/src/test/java/org/opentripplanner/updater/trip/moduletests/addition/AddedTest.java index 1e75f558510..7f5d976e737 100644 --- a/src/test/java/org/opentripplanner/updater/trip/moduletests/addition/AddedTest.java +++ b/src/test/java/org/opentripplanner/updater/trip/moduletests/addition/AddedTest.java @@ -6,7 +6,7 @@ import static org.junit.jupiter.api.Assertions.assertNotSame; import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.opentripplanner.test.support.UpdateResultAssertions.assertSuccess; +import static org.opentripplanner.updater.spi.UpdateResultAssertions.assertSuccess; import static org.opentripplanner.updater.trip.RealtimeTestEnvironment.SERVICE_DATE; import static org.opentripplanner.updater.trip.RealtimeTestEnvironment.STOP_A1_ID; import static org.opentripplanner.updater.trip.RealtimeTestEnvironment.STOP_B1_ID; diff --git a/src/test/java/org/opentripplanner/updater/trip/moduletests/cancellation/CancellationDeletionTest.java b/src/test/java/org/opentripplanner/updater/trip/moduletests/cancellation/CancellationDeletionTest.java index 3b527b64e5d..c85225b7828 100644 --- a/src/test/java/org/opentripplanner/updater/trip/moduletests/cancellation/CancellationDeletionTest.java +++ b/src/test/java/org/opentripplanner/updater/trip/moduletests/cancellation/CancellationDeletionTest.java @@ -4,7 +4,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNotSame; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.opentripplanner.test.support.UpdateResultAssertions.assertSuccess; +import static org.opentripplanner.updater.spi.UpdateResultAssertions.assertSuccess; import static org.opentripplanner.updater.trip.UpdateIncrementality.DIFFERENTIAL; import com.google.transit.realtime.GtfsRealtime.TripDescriptor.ScheduleRelationship; diff --git a/src/test/java/org/opentripplanner/updater/trip/moduletests/delay/DelayedTest.java b/src/test/java/org/opentripplanner/updater/trip/moduletests/delay/DelayedTest.java index d9282e1b155..53805939e40 100644 --- a/src/test/java/org/opentripplanner/updater/trip/moduletests/delay/DelayedTest.java +++ b/src/test/java/org/opentripplanner/updater/trip/moduletests/delay/DelayedTest.java @@ -5,7 +5,7 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotSame; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.opentripplanner.test.support.UpdateResultAssertions.assertSuccess; +import static org.opentripplanner.updater.spi.UpdateResultAssertions.assertSuccess; import static org.opentripplanner.updater.trip.RealtimeTestEnvironment.SERVICE_DATE; import org.junit.jupiter.api.Test; diff --git a/src/test/java/org/opentripplanner/updater/trip/moduletests/delay/SkippedTest.java b/src/test/java/org/opentripplanner/updater/trip/moduletests/delay/SkippedTest.java index 349e472036d..c17130fbda6 100644 --- a/src/test/java/org/opentripplanner/updater/trip/moduletests/delay/SkippedTest.java +++ b/src/test/java/org/opentripplanner/updater/trip/moduletests/delay/SkippedTest.java @@ -6,7 +6,7 @@ import static org.junit.jupiter.api.Assertions.assertNotSame; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.opentripplanner.test.support.UpdateResultAssertions.assertSuccess; +import static org.opentripplanner.updater.spi.UpdateResultAssertions.assertSuccess; import static org.opentripplanner.updater.trip.RealtimeTestEnvironment.SERVICE_DATE; import static org.opentripplanner.updater.trip.UpdateIncrementality.DIFFERENTIAL; diff --git a/src/test/java/org/opentripplanner/updater/trip/moduletests/rejection/InvalidInputTest.java b/src/test/java/org/opentripplanner/updater/trip/moduletests/rejection/InvalidInputTest.java index 4815d7180c4..da362451753 100644 --- a/src/test/java/org/opentripplanner/updater/trip/moduletests/rejection/InvalidInputTest.java +++ b/src/test/java/org/opentripplanner/updater/trip/moduletests/rejection/InvalidInputTest.java @@ -2,8 +2,8 @@ import static com.google.transit.realtime.GtfsRealtime.TripDescriptor.ScheduleRelationship.SCHEDULED; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.opentripplanner.test.support.UpdateResultAssertions.assertFailure; import static org.opentripplanner.updater.spi.UpdateError.UpdateErrorType.NO_SERVICE_ON_DATE; +import static org.opentripplanner.updater.spi.UpdateResultAssertions.assertFailure; import static org.opentripplanner.updater.trip.RealtimeTestEnvironment.SERVICE_DATE; import java.time.LocalDate; diff --git a/src/test/java/org/opentripplanner/updater/trip/moduletests/rejection/InvalidTripIdTest.java b/src/test/java/org/opentripplanner/updater/trip/moduletests/rejection/InvalidTripIdTest.java index e6e7a4737f7..83c2547dbc7 100644 --- a/src/test/java/org/opentripplanner/updater/trip/moduletests/rejection/InvalidTripIdTest.java +++ b/src/test/java/org/opentripplanner/updater/trip/moduletests/rejection/InvalidTripIdTest.java @@ -1,8 +1,8 @@ package org.opentripplanner.updater.trip.moduletests.rejection; import static com.google.transit.realtime.GtfsRealtime.TripDescriptor.ScheduleRelationship.SCHEDULED; -import static org.opentripplanner.test.support.UpdateResultAssertions.assertFailure; import static org.opentripplanner.updater.spi.UpdateError.UpdateErrorType.INVALID_INPUT_STRUCTURE; +import static org.opentripplanner.updater.spi.UpdateResultAssertions.assertFailure; import com.google.transit.realtime.GtfsRealtime; import java.util.stream.Stream; From 8c3364e9830682b8ab8dab1bf321fe57933cb90e Mon Sep 17 00:00:00 2001 From: Leonard Ehrenfried Date: Mon, 1 Jul 2024 18:09:04 +0200 Subject: [PATCH 15/21] Rename Stop to StopCall --- .../updater/trip/RealtimeTestEnvironment.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/test/java/org/opentripplanner/updater/trip/RealtimeTestEnvironment.java b/src/test/java/org/opentripplanner/updater/trip/RealtimeTestEnvironment.java index e9aa783833f..57aba0b19bb 100644 --- a/src/test/java/org/opentripplanner/updater/trip/RealtimeTestEnvironment.java +++ b/src/test/java/org/opentripplanner/updater/trip/RealtimeTestEnvironment.java @@ -114,12 +114,20 @@ private RealtimeTestEnvironment(SourceType sourceType) { Route route1 = TransitModelForTest.route(route1Id).build(); trip1 = - createTrip("TestTrip1", route1, List.of(new Stop(stopA1, 10, 11), new Stop(stopB1, 20, 21))); + createTrip( + "TestTrip1", + route1, + List.of(new StopCall(stopA1, 10, 11), new StopCall(stopB1, 20, 21)) + ); trip2 = createTrip( "TestTrip2", route1, - List.of(new Stop(stopA1, 60, 61), new Stop(stopB1, 70, 71), new Stop(stopC1, 80, 81)) + List.of( + new StopCall(stopA1, 60, 61), + new StopCall(stopB1, 70, 71), + new StopCall(stopC1, 80, 81) + ) ); CalendarServiceData calendarServiceData = new CalendarServiceData(); @@ -295,7 +303,7 @@ private UpdateResult applyEstimatedTimetable( return getEstimatedTimetableHandler(fuzzyMatching).applyUpdate(updates, DIFFERENTIAL); } - private Trip createTrip(String id, Route route, List stops) { + private Trip createTrip(String id, Route route, List stops) { var trip = Trip .of(id(id)) .withRoute(route) @@ -323,7 +331,7 @@ private Trip createTrip(String id, Route route, List stops) { final TripPattern pattern = TransitModelForTest .tripPattern(id + "Pattern", route) - .withStopPattern(TransitModelForTest.stopPattern(stops.stream().map(Stop::stop).toList())) + .withStopPattern(TransitModelForTest.stopPattern(stops.stream().map(StopCall::stop).toList())) .build(); pattern.add(tripTimes); @@ -348,5 +356,5 @@ private StopTime createStopTime( return st; } - protected record Stop(RegularStop stop, int arrivalTime, int departureTime) {} + protected record StopCall(RegularStop stop, int arrivalTime, int departureTime) {} } From 1301e96ac7224728a7be8ff36cfdaeaa2cb3b57d Mon Sep 17 00:00:00 2001 From: Leonard Ehrenfried Date: Tue, 2 Jul 2024 11:41:03 +0200 Subject: [PATCH 16/21] Make assertion return void --- .../updater/spi/UpdateResultAssertions.java | 3 +-- .../updater/trip/moduletests/addition/AddedTest.java | 7 ++++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/test/java/org/opentripplanner/updater/spi/UpdateResultAssertions.java b/src/test/java/org/opentripplanner/updater/spi/UpdateResultAssertions.java index 13806cde4c3..38468744886 100644 --- a/src/test/java/org/opentripplanner/updater/spi/UpdateResultAssertions.java +++ b/src/test/java/org/opentripplanner/updater/spi/UpdateResultAssertions.java @@ -11,7 +11,7 @@ public static void assertFailure(UpdateError.UpdateErrorType expectedError, Upda assertEquals(Set.of(expectedError), result.failures().keySet()); } - public static UpdateResult assertSuccess(UpdateResult updateResult) { + public static void assertSuccess(UpdateResult updateResult) { var errorCodes = updateResult.failures().keySet(); assertEquals( Set.of(), @@ -19,6 +19,5 @@ public static UpdateResult assertSuccess(UpdateResult updateResult) { "Update result should have no error codes but had %s".formatted(errorCodes) ); assertTrue(updateResult.successful() > 0); - return updateResult; } } diff --git a/src/test/java/org/opentripplanner/updater/trip/moduletests/addition/AddedTest.java b/src/test/java/org/opentripplanner/updater/trip/moduletests/addition/AddedTest.java index 7f5d976e737..8d3984cc546 100644 --- a/src/test/java/org/opentripplanner/updater/trip/moduletests/addition/AddedTest.java +++ b/src/test/java/org/opentripplanner/updater/trip/moduletests/addition/AddedTest.java @@ -51,8 +51,8 @@ void addedTripWithNewRoute() { .addStopTime(STOP_B1_ID, 55, DropOffPickupType.NONE) .build(); - var result = assertSuccess(env.applyTripUpdate(tripUpdate)); - + var result = env.applyTripUpdate(tripUpdate); + assertSuccess(result); assertTrue(result.warnings().isEmpty()); var pattern = assertAddedTrip(ADDED_TRIP_ID, env); @@ -83,7 +83,8 @@ void addedWithUnknownStop() { .addStopTime(STOP_C1_ID, 55, DropOffPickupType.NONE) .build(); - var result = assertSuccess(env.applyTripUpdate(tripUpdate)); + var result = env.applyTripUpdate(tripUpdate); + assertSuccess(result); assertEquals( List.of(UpdateSuccess.WarningType.UNKNOWN_STOPS_REMOVED_FROM_ADDED_TRIP), From 3d138afb0404b84a694128d4e9470071f910bcf8 Mon Sep 17 00:00:00 2001 From: Leonard Ehrenfried Date: Wed, 3 Jul 2024 17:29:55 +0200 Subject: [PATCH 17/21] Make record private --- .../opentripplanner/updater/trip/RealtimeTestEnvironment.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/opentripplanner/updater/trip/RealtimeTestEnvironment.java b/src/test/java/org/opentripplanner/updater/trip/RealtimeTestEnvironment.java index 57aba0b19bb..34923fed9e4 100644 --- a/src/test/java/org/opentripplanner/updater/trip/RealtimeTestEnvironment.java +++ b/src/test/java/org/opentripplanner/updater/trip/RealtimeTestEnvironment.java @@ -356,5 +356,5 @@ private StopTime createStopTime( return st; } - protected record StopCall(RegularStop stop, int arrivalTime, int departureTime) {} + private record StopCall(RegularStop stop, int arrivalTime, int departureTime) {} } From 3dda63ccbffb67727f95d96e6921b5e46f5aa02c Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 16 Jul 2024 02:00:58 +0000 Subject: [PATCH 18/21] fix(deps): update dependency edu.ucar:netcdf4 to v5.6.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index cb331acccd5..b7f26812e99 100644 --- a/pom.xml +++ b/pom.xml @@ -64,7 +64,7 @@ 3.1.7 5.10.3 1.13.2 - 5.5.3 + 5.6.0 1.5.6 9.11.1 2.0.13 From 01266a83cd049cdb9ee973ee9e6ab3dcdfca2a74 Mon Sep 17 00:00:00 2001 From: Leonard Ehrenfried Date: Thu, 18 Jul 2024 22:57:44 +0200 Subject: [PATCH 19/21] Auto-merge test reporter [ci skip] --- renovate.json5 | 1 + 1 file changed, 1 insertion(+) diff --git a/renovate.json5 b/renovate.json5 index 7b957c577e3..d8ba10984e5 100644 --- a/renovate.json5 +++ b/renovate.json5 @@ -113,6 +113,7 @@ "org.mockito:mockito-core", "com.tngtech.archunit:archunit", "org.apache.maven.plugins:maven-surefire-plugin", + "me.fabriciorby:maven-surefire-junit5-tree-reporter", "org.jacoco:jacoco-maven-plugin", // coverage plugin "org.apache.commons:commons-compress", // only used by tests // maven plugins From 4198402425875fad1d139d28ca4aecbdd40f61b5 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 18 Jul 2024 09:56:02 +0000 Subject: [PATCH 20/21] chore(deps): update dependency me.fabriciorby:maven-surefire-junit5-tree-reporter to v1.3.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index b7f26812e99..02f87de47d6 100644 --- a/pom.xml +++ b/pom.xml @@ -247,7 +247,7 @@ me.fabriciorby maven-surefire-junit5-tree-reporter - 1.2.1 + 1.3.0 From c3c1ea08a9da9711315a961a49633ed7b85e993c Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 18 Jul 2024 22:34:33 +0000 Subject: [PATCH 21/21] chore(deps): update dependency io.github.git-commit-id:git-commit-id-maven-plugin to v9.0.1 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 02f87de47d6..00165487fb3 100644 --- a/pom.xml +++ b/pom.xml @@ -321,7 +321,7 @@ but we need the Maven project version as well, so we perform substitution. --> io.github.git-commit-id git-commit-id-maven-plugin - 9.0.0 + 9.0.1