9
9
import static org .mockito .Mockito .verify ;
10
10
import static org .mockito .Mockito .when ;
11
11
12
+ import java .util .ArrayList ;
12
13
import java .util .Date ;
13
14
import java .util .List ;
14
15
import java .util .Set ;
15
16
import java .util .concurrent .TimeUnit ;
16
17
import org .entur .lamassu .cache .EntityCache ;
17
18
import org .entur .lamassu .cache .StationSpatialIndex ;
18
- import org .entur .lamassu .cache .StationSpatialIndexId ;
19
19
import org .entur .lamassu .delta .DeltaType ;
20
20
import org .entur .lamassu .delta .GBFSEntityDelta ;
21
21
import org .entur .lamassu .delta .GBFSFileDelta ;
@@ -285,38 +285,60 @@ void shouldHandleStationUpdateWithSpatialIndexChange() {
285
285
286
286
var stationId = "station-1" ;
287
287
var bikeTypeId = "bike" ;
288
+ var scooterTypeId = "scooter" ;
288
289
289
290
var bikeType = new VehicleType ();
290
291
bikeType .setId (bikeTypeId );
291
292
bikeType .setFormFactor (FormFactor .BICYCLE );
292
293
bikeType .setPropulsionType (PropulsionType .HUMAN );
293
294
295
+ var scooterType = new VehicleType ();
296
+ scooterType .setId (scooterTypeId );
297
+ scooterType .setFormFactor (FormFactor .SCOOTER );
298
+ scooterType .setPropulsionType (PropulsionType .ELECTRIC );
299
+
294
300
var currentStation = new Station ();
295
301
currentStation .setId (stationId );
296
302
currentStation .setLat (59.9 );
297
303
currentStation .setLon (10.7 );
298
304
var oldAvailability = new VehicleTypeAvailability ();
299
305
oldAvailability .setVehicleTypeId (bikeTypeId );
300
306
oldAvailability .setCount (5 );
301
- currentStation .setVehicleTypesAvailable (List .of (oldAvailability ));
307
+ currentStation .setVehicleTypesAvailable (new ArrayList <>( List .of (oldAvailability ) ));
302
308
303
309
var stationInfo = new GBFSStation ();
304
310
stationInfo .setStationId (stationId );
305
- stationInfo .setName (
306
- List .of (new GBFSName ().withLanguage ("en" ).withText ("Test Station" ))
307
- );
308
311
stationInfo .setLat (59.9 );
309
312
stationInfo .setLon (10.7 );
313
+ stationInfo .setName (
314
+ new ArrayList <>(List .of (new GBFSName ().withLanguage ("en" ).withText ("Test Station" )))
315
+ );
316
+ stationInfo .setVehicleTypesCapacity (
317
+ new ArrayList <>(
318
+ List .of (
319
+ new org .mobilitydata .gbfs .v3_0 .station_information .GBFSVehicleTypesCapacity ()
320
+ .withVehicleTypeIds (new ArrayList <>(List .of (scooterTypeId )))
321
+ .withCount (3 )
322
+ )
323
+ )
324
+ );
310
325
311
326
var stationStatus = new org .mobilitydata .gbfs .v3_0 .station_status .GBFSStation ();
312
327
stationStatus .setStationId (stationId );
313
- // No vehicles available anymore
314
- stationStatus .setNumVehiclesAvailable (0 );
315
328
stationStatus .setNumDocksAvailable (10 );
316
329
stationStatus .setIsInstalled (true );
317
330
stationStatus .setIsRenting (true );
318
331
stationStatus .setIsReturning (true );
319
332
stationStatus .setLastReported (new Date ());
333
+ stationStatus .setVehicleTypesAvailable (
334
+ new ArrayList <>(
335
+ List .of (
336
+ new org .mobilitydata .gbfs .v3_0 .station_status .GBFSVehicleTypesAvailable ()
337
+ .withVehicleTypeId (scooterTypeId )
338
+ .withCount (3 )
339
+ )
340
+ )
341
+ );
320
342
321
343
var stationInformationFeed = new GBFSStationInformation ();
322
344
var data = new GBFSData ();
@@ -326,6 +348,7 @@ void shouldHandleStationUpdateWithSpatialIndexChange() {
326
348
// Mock behavior
327
349
when (stationCache .get (stationId )).thenReturn (currentStation );
328
350
when (vehicleTypeCache .getAll (Set .of (bikeTypeId ))).thenReturn (List .of (bikeType ));
351
+ when (vehicleTypeCache .getAll (Set .of (scooterTypeId ))).thenReturn (List .of (scooterType ));
329
352
330
353
var delta = new GBFSFileDelta <>(
331
354
1000L ,
@@ -399,19 +422,84 @@ void shouldRemoveExistingStationsWhenBaseIsNull() {
399
422
if (spatialIds .size () != 2 ) return false ;
400
423
return spatialIds
401
424
.stream ()
402
- .allMatch (id -> {
403
- var spatialId = (StationSpatialIndexId ) id ;
404
- return (
405
- (
406
- spatialId .getId ().equals ("station-1" ) ||
407
- spatialId .getId ().equals ("station-2" )
408
- ) &&
409
- spatialId .getSystemId ().equals ("system-1" ) &&
410
- spatialId .getCodespace ().equals ("codespace-1" )
411
- );
412
- });
425
+ .allMatch (id ->
426
+ (
427
+ (id .getId ().equals ("station-1" ) || id .getId ().equals ("station-2" )) &&
428
+ id .getSystemId ().equals ("system-1" ) &&
429
+ id .getCodespace ().equals ("codespace-1" )
430
+ )
431
+ );
413
432
})
414
433
);
415
434
verify (stationCache , never ()).removeAll (Set .of ("station-3" )); // Should not remove stations from other systems
416
435
}
436
+
437
+ @ Test
438
+ void shouldPreservePropertiesWhenGeneratingSpatialIndexId () {
439
+ // Given
440
+ var feedProvider = new FeedProvider ();
441
+ feedProvider .setSystemId ("test-system" );
442
+ feedProvider .setCodespace ("test" );
443
+ feedProvider .setOperatorId ("test-operator" );
444
+ feedProvider .setLanguage ("en" );
445
+
446
+ var stationId = "station-1" ;
447
+ var bikeTypeId = "bike" ;
448
+
449
+ var bikeType = new VehicleType ();
450
+ bikeType .setId (bikeTypeId );
451
+ bikeType .setFormFactor (FormFactor .BICYCLE );
452
+ bikeType .setPropulsionType (PropulsionType .HUMAN );
453
+
454
+ var currentStation = new Station ();
455
+ currentStation .setId (stationId );
456
+ currentStation .setLat (59.9 );
457
+ currentStation .setLon (10.7 );
458
+ var availability = new VehicleTypeAvailability ();
459
+ availability .setVehicleTypeId (bikeTypeId );
460
+ availability .setCount (5 );
461
+ currentStation .setVehicleTypesAvailable (new ArrayList <>(List .of (availability )));
462
+
463
+ var stationInfo = new GBFSStation ();
464
+ stationInfo .setStationId (stationId );
465
+ stationInfo .setLat (59.9 );
466
+ stationInfo .setLon (10.7 );
467
+ stationInfo .setName (
468
+ new ArrayList <>(List .of (new GBFSName ().withLanguage ("en" ).withText ("Test Station" )))
469
+ );
470
+ // Note: not setting vehicle types in GBFS station
471
+
472
+ var stationStatus = new org .mobilitydata .gbfs .v3_0 .station_status .GBFSStation ();
473
+ stationStatus .setStationId (stationId );
474
+ stationStatus .setNumDocksAvailable (10 );
475
+ stationStatus .setIsInstalled (true );
476
+ stationStatus .setIsRenting (true );
477
+ stationStatus .setIsReturning (true );
478
+ stationStatus .setLastReported (new Date ());
479
+
480
+ var stationInformationFeed = new GBFSStationInformation ();
481
+ var data = new GBFSData ();
482
+ data .setStations (List .of (stationInfo ));
483
+ stationInformationFeed .setData (data );
484
+
485
+ // Mock behavior
486
+ when (stationCache .get (stationId )).thenReturn (currentStation );
487
+ when (vehicleTypeCache .getAll (Set .of (bikeTypeId ))).thenReturn (List .of (bikeType ));
488
+
489
+ var delta = new GBFSFileDelta <org .mobilitydata .gbfs .v3_0 .station_status .GBFSStation >(
490
+ 1000L ,
491
+ 2000L ,
492
+ "station_status" ,
493
+ List .of (new GBFSEntityDelta <>(stationId , DeltaType .UPDATE , stationStatus ))
494
+ );
495
+
496
+ // When
497
+ stationsUpdater .update (feedProvider , delta , stationInformationFeed );
498
+
499
+ // Then
500
+ verify (spatialIndex ).addAll (any ());
501
+ verify (stationCache ).updateAll (any ());
502
+ verify (spatialIndex , never ()).removeAll (anySet ());
503
+ verify (stationCache , never ()).removeAll (anySet ());
504
+ }
417
505
}
0 commit comments