|
2 | 2 |
|
3 | 3 | import static com.google.common.truth.Truth.assertThat; |
4 | 4 | import static org.junit.jupiter.api.Assertions.assertEquals; |
| 5 | +import static org.opentripplanner.updater.spi.UpdateResultAssertions.assertSuccess; |
5 | 6 |
|
6 | 7 | import org.junit.jupiter.api.Test; |
7 | 8 | import org.opentripplanner.transit.model._data.TransitTestEnvironment; |
@@ -51,4 +52,97 @@ void testChangeQuay() { |
51 | 52 |
|
52 | 53 | assertThat(env.raptorData().summarizePatterns()).containsExactly("F:Route1::001:RT[MODIFIED]"); |
53 | 54 | } |
| 55 | + |
| 56 | + /** |
| 57 | + * Change quay (B to C) producing a MODIFIED pattern, then send a second update referencing the |
| 58 | + * original stop B, reverting the pattern back to the scheduled one. |
| 59 | + */ |
| 60 | + @Test |
| 61 | + void testChangeQuayThenRevertToOriginalStops() { |
| 62 | + var env = ENV_BUILDER.addTrip(TRIP_INPUT).build(); |
| 63 | + var siri = SiriTestHelper.of(env); |
| 64 | + |
| 65 | + // Step 1: Change quay from B to C (same station) |
| 66 | + var quayChange = siri |
| 67 | + .etBuilder() |
| 68 | + .withDatedVehicleJourneyRef(TRIP_1_ID) |
| 69 | + .withRecordedCalls(builder -> builder.call(STOP_A).departAimedActual("00:00:11", "00:00:15")) |
| 70 | + .withEstimatedCalls(builder -> |
| 71 | + builder.call(STOP_C).arriveAimedExpected("00:00:20", "00:00:33") |
| 72 | + ) |
| 73 | + .buildEstimatedTimetableDeliveries(); |
| 74 | + |
| 75 | + var result1 = siri.applyEstimatedTimetable(quayChange); |
| 76 | + assertSuccess(result1); |
| 77 | + assertEquals( |
| 78 | + "MODIFIED | A [R] 0:00:15 0:00:15 | C 0:00:33 0:00:33", |
| 79 | + env.tripData(TRIP_1_ID).showTimetable() |
| 80 | + ); |
| 81 | + |
| 82 | + // Step 2: Revert to original stop B with updated times |
| 83 | + var revert = siri |
| 84 | + .etBuilder() |
| 85 | + .withDatedVehicleJourneyRef(TRIP_1_ID) |
| 86 | + .withRecordedCalls(builder -> builder.call(STOP_A).departAimedActual("00:00:11", "00:00:16")) |
| 87 | + .withEstimatedCalls(builder -> |
| 88 | + builder.call(STOP_B).arriveAimedExpected("00:00:20", "00:00:30") |
| 89 | + ) |
| 90 | + .buildEstimatedTimetableDeliveries(); |
| 91 | + |
| 92 | + var result2 = siri.applyEstimatedTimetable(revert); |
| 93 | + assertSuccess(result2); |
| 94 | + assertEquals( |
| 95 | + "UPDATED | A [R] 0:00:16 0:00:16 | B 0:00:30 0:00:30", |
| 96 | + env.tripData(TRIP_1_ID).showTimetable() |
| 97 | + ); |
| 98 | + // Pattern reverts to the scheduled one (not an RT pattern), but trip state is UPDATED |
| 99 | + assertThat(env.raptorData().summarizePatterns()).containsExactly("F:Pattern1[UPDATED]"); |
| 100 | + } |
| 101 | + |
| 102 | + /** |
| 103 | + * Change quay (B to C), then send a second update that keeps the same quay change (C) |
| 104 | + * but with different delay. The quay change must be preserved across updates. |
| 105 | + */ |
| 106 | + @Test |
| 107 | + void testChangeQuayThenUpdateTimesKeepsQuayChange() { |
| 108 | + var env = ENV_BUILDER.addTrip(TRIP_INPUT).build(); |
| 109 | + var siri = SiriTestHelper.of(env); |
| 110 | + |
| 111 | + // Step 1: Change quay from B to C (same station) with delay |
| 112 | + var quayChange = siri |
| 113 | + .etBuilder() |
| 114 | + .withDatedVehicleJourneyRef(TRIP_1_ID) |
| 115 | + .withRecordedCalls(builder -> builder.call(STOP_A).departAimedActual("00:00:11", "00:00:15")) |
| 116 | + .withEstimatedCalls(builder -> |
| 117 | + builder.call(STOP_C).arriveAimedExpected("00:00:20", "00:00:33") |
| 118 | + ) |
| 119 | + .buildEstimatedTimetableDeliveries(); |
| 120 | + |
| 121 | + var result1 = siri.applyEstimatedTimetable(quayChange); |
| 122 | + assertSuccess(result1); |
| 123 | + assertEquals( |
| 124 | + "MODIFIED | A [R] 0:00:15 0:00:15 | C 0:00:33 0:00:33", |
| 125 | + env.tripData(TRIP_1_ID).showTimetable() |
| 126 | + ); |
| 127 | + assertThat(env.raptorData().summarizePatterns()).containsExactly("F:Route1::001:RT[MODIFIED]"); |
| 128 | + |
| 129 | + // Step 2: Keep quay change (still C) but with different delay |
| 130 | + var updatedTimes = siri |
| 131 | + .etBuilder() |
| 132 | + .withDatedVehicleJourneyRef(TRIP_1_ID) |
| 133 | + .withRecordedCalls(builder -> builder.call(STOP_A).departAimedActual("00:00:11", "00:00:16")) |
| 134 | + .withEstimatedCalls(builder -> |
| 135 | + builder.call(STOP_C).arriveAimedExpected("00:00:20", "00:00:35") |
| 136 | + ) |
| 137 | + .buildEstimatedTimetableDeliveries(); |
| 138 | + |
| 139 | + var result2 = siri.applyEstimatedTimetable(updatedTimes); |
| 140 | + assertSuccess(result2); |
| 141 | + // Quay change must be preserved - still MODIFIED on RT pattern, not reverted to scheduled |
| 142 | + assertEquals( |
| 143 | + "MODIFIED | A [R] 0:00:16 0:00:16 | C 0:00:35 0:00:35", |
| 144 | + env.tripData(TRIP_1_ID).showTimetable() |
| 145 | + ); |
| 146 | + assertThat(env.raptorData().summarizePatterns()).containsExactly("F:Route1::001:RT[MODIFIED]"); |
| 147 | + } |
54 | 148 | } |
0 commit comments