1111import org .opentripplanner .transit .model ._data .TransitTestEnvironment ;
1212import org .opentripplanner .transit .model ._data .TransitTestEnvironmentBuilder ;
1313import org .opentripplanner .transit .model ._data .TripInput ;
14+ import org .opentripplanner .transit .model .basic .SubMode ;
15+ import org .opentripplanner .transit .model .basic .TransitMode ;
1416import org .opentripplanner .transit .model .network .Route ;
1517import org .opentripplanner .transit .model .organization .Operator ;
1618import org .opentripplanner .transit .model .site .RegularStop ;
2224import org .opentripplanner .updater .trip .RealtimeTestConstants ;
2325import org .opentripplanner .updater .trip .SiriTestHelper ;
2426import org .opentripplanner .updater .trip .siri .SiriEtBuilder ;
27+ import uk .org .siri .siri21 .VehicleModesEnumeration ;
2528
2629class ExtraJourneyTest implements RealtimeTestConstants {
2730
2831 private static final String ADDED_TRIP_ID = "newJourney" ;
2932 private static final String OPERATOR_ID = "operatorId" ;
3033 private static final String ROUTE_ID = "routeId" ;
34+ private static final String RAIL_ROUTE_ID = "railRouteId" ;
3135
3236 private final TransitTestEnvironmentBuilder ENV_BUILDER = TransitTestEnvironment .of ();
3337 private final RegularStop STOP_A = ENV_BUILDER .stop (STOP_A_ID );
@@ -43,6 +47,15 @@ class ExtraJourneyTest implements RealtimeTestConstants {
4347 .addStop (STOP_A , "0:00:10" , "0:00:11" )
4448 .addStop (STOP_B , "0:00:20" , "0:00:21" );
4549
50+ private final Route RAIL_ROUTE = ENV_BUILDER .route (RAIL_ROUTE_ID , r ->
51+ r .withMode (TransitMode .RAIL )
52+ );
53+
54+ private final TripInput RAIL_TRIP_INPUT = TripInput .of ("railTrip1" )
55+ .withRoute (RAIL_ROUTE )
56+ .addStop (STOP_A , "0:00:10" , "0:00:11" )
57+ .addStop (STOP_B , "0:00:20" , "0:00:21" );
58+
4659 @ Test
4760 void testAddJourneyWithExistingRoute () {
4861 var env = ENV_BUILDER .addTrip (TRIP_1_INPUT ).build ();
@@ -242,6 +255,123 @@ void testReplaceJourneyWithoutEstimatedVehicleJourneyCode() {
242255 assertFailure (UpdateError .UpdateErrorType .UNKNOWN , result );
243256 }
244257
258+ @ Test
259+ void testAddJourneyWithNewRouteAndShortName () {
260+ var env = ENV_BUILDER .addTrip (TRIP_1_INPUT ).build ();
261+ var siri = SiriTestHelper .of (env );
262+
263+ String newRouteRef = "newRouteForShortName" ;
264+ var updates = createValidAddedJourney (siri )
265+ .withLineRef (newRouteRef )
266+ .withPublishedLineName ("L1" )
267+ .buildEstimatedTimetableDeliveries ();
268+
269+ var result = siri .applyEstimatedTimetable (updates );
270+ assertEquals (1 , result .successful ());
271+
272+ Route newRoute = env .transitService ().getRoute (id (newRouteRef ));
273+ assertNotNull (newRoute );
274+ assertEquals (
275+ "L1" ,
276+ newRoute .getShortName (),
277+ "PublishedLineName should be mapped to the new route short name"
278+ );
279+ }
280+
281+ @ Test
282+ void testAddJourneyWithNewRouteAndOperator () {
283+ var env = ENV_BUILDER .addTrip (TRIP_1_INPUT ).build ();
284+ var siri = SiriTestHelper .of (env );
285+
286+ String newRouteRef = "newRouteForOperator" ;
287+ var updates = createValidAddedJourney (siri )
288+ .withLineRef (newRouteRef )
289+ .buildEstimatedTimetableDeliveries ();
290+
291+ var result = siri .applyEstimatedTimetable (updates );
292+ assertEquals (1 , result .successful ());
293+
294+ Trip trip = env .transitService ().getTrip (id (ADDED_TRIP_ID ));
295+ assertNotNull (trip );
296+ assertEquals (
297+ OPERATOR ,
298+ trip .getOperator (),
299+ "The new trip is assigned to the operator specified in OperatorRef"
300+ );
301+ }
302+
303+ @ Test
304+ void testAddJourneyWithNewRouteResolvesAgencyFromOperator () {
305+ var env = ENV_BUILDER .addTrip (TRIP_1_INPUT ).build ();
306+ var siri = SiriTestHelper .of (env );
307+
308+ String newRouteRef = "newRouteForAgency" ;
309+ var updates = createValidAddedJourney (siri )
310+ .withLineRef (newRouteRef )
311+ .buildEstimatedTimetableDeliveries ();
312+
313+ var result = siri .applyEstimatedTimetable (updates );
314+ assertEquals (1 , result .successful ());
315+
316+ Route newRoute = env .transitService ().getRoute (id (newRouteRef ));
317+ assertNotNull (newRoute );
318+ assertEquals (
319+ ROUTE .getAgency (),
320+ newRoute .getAgency (),
321+ "The new route agency should be mapped to the agency of any existing route that has the same operator"
322+ );
323+ }
324+
325+ @ Test
326+ void testAddJourneyBusReplacingRailHasRailReplacementSubmode () {
327+ var env = ENV_BUILDER .addTrip (TRIP_1_INPUT ).addTrip (RAIL_TRIP_INPUT ).build ();
328+ var siri = SiriTestHelper .of (env );
329+
330+ String newRouteRef = "busReplacementRoute" ;
331+ var updates = createValidAddedJourney (siri )
332+ .withLineRef (newRouteRef )
333+ .withExternalLineRef (RAIL_ROUTE_ID )
334+ .withVehicleMode (VehicleModesEnumeration .BUS )
335+ .buildEstimatedTimetableDeliveries ();
336+
337+ var result = siri .applyEstimatedTimetable (updates );
338+ assertEquals (1 , result .successful ());
339+
340+ Route newRoute = env .transitService ().getRoute (id (newRouteRef ));
341+ assertNotNull (newRoute );
342+ assertEquals (TransitMode .BUS , newRoute .getMode ());
343+ assertEquals (
344+ SubMode .of ("railReplacementBus" ),
345+ newRoute .getNetexSubmode (),
346+ "When an added bus trip is assigned to an existing rail route, the submode should be 'railReplacementBus'"
347+ );
348+ }
349+
350+ @ Test
351+ void testAddJourneyRailReplacingRailHasReplacementRailSubmode () {
352+ var env = ENV_BUILDER .addTrip (TRIP_1_INPUT ).addTrip (RAIL_TRIP_INPUT ).build ();
353+ var siri = SiriTestHelper .of (env );
354+
355+ String newRouteRef = "railReplacementRoute" ;
356+ var updates = createValidAddedJourney (siri )
357+ .withLineRef (newRouteRef )
358+ .withExternalLineRef (RAIL_ROUTE_ID )
359+ .withVehicleMode (VehicleModesEnumeration .RAIL )
360+ .buildEstimatedTimetableDeliveries ();
361+
362+ var result = siri .applyEstimatedTimetable (updates );
363+ assertEquals (1 , result .successful ());
364+
365+ Route newRoute = env .transitService ().getRoute (id (newRouteRef ));
366+ assertNotNull (newRoute );
367+ assertEquals (TransitMode .RAIL , newRoute .getMode ());
368+ assertEquals (
369+ SubMode .of ("replacementRailService" ),
370+ newRoute .getNetexSubmode (),
371+ "When an added rail trip is assigned to an existing rail route, the submode should be 'replacementRailService'"
372+ );
373+ }
374+
245375 private SiriEtBuilder createValidAddedJourney (SiriTestHelper siri ) {
246376 return siri
247377 .etBuilder ()
0 commit comments