Search in sources :

Example 6 with BlockEntryImpl

use of org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl in project onebusaway-application-modules by camsys.

the class ServiceAlertsServiceImplTest method testGetServiceAlertsForVehicleJourney.

@Test
public void testGetServiceAlertsForVehicleJourney() {
    /**
     * These alerts should match
     */
    ServiceAlertRecord alert2 = new ServiceAlertRecord();
    alert2.setAgencyId("1");
    alert2.setServiceAlertId("B");
    ServiceAlertsSituationAffectsClause affectsClause2 = new ServiceAlertsSituationAffectsClause();
    affectsClause2.setAgencyId("1");
    affectsClause2.setTripId("TripA");
    alert2.getAllAffects().add(affectsClause2);
    alert2 = _service.createOrUpdateServiceAlert(alert2);
    ServiceAlertRecord alert3 = new ServiceAlertRecord();
    alert3.setAgencyId("1");
    alert3.setServiceAlertId("C");
    ServiceAlertsSituationAffectsClause affectsClause3 = new ServiceAlertsSituationAffectsClause();
    affectsClause3.setAgencyId("1");
    affectsClause3.setRouteId("RouteX");
    alert3.getAllAffects().add(affectsClause3);
    alert3 = _service.createOrUpdateServiceAlert(alert3);
    ServiceAlertRecord alert4 = new ServiceAlertRecord();
    alert4.setAgencyId("1");
    alert4.setServiceAlertId("D");
    ServiceAlertsSituationAffectsClause affectsClause4 = new ServiceAlertsSituationAffectsClause();
    affectsClause4.setAgencyId("1");
    affectsClause4.setRouteId("RouteX");
    affectsClause4.setDirectionId("1");
    alert4.getAllAffects().add(affectsClause4);
    alert4 = _service.createOrUpdateServiceAlert(alert4);
    /**
     * These alerts shouldn't match
     */
    ServiceAlertRecord alert5 = new ServiceAlertRecord();
    alert5.setAgencyId("1");
    alert5.setServiceAlertId("E");
    ServiceAlertsSituationAffectsClause affectsClause5 = new ServiceAlertsSituationAffectsClause();
    affectsClause5.setAgencyId("1");
    affectsClause5.setStopId("10021");
    affectsClause5.setTripId("TripA");
    alert5.getAllAffects().add(affectsClause5);
    alert5 = _service.createOrUpdateServiceAlert(alert5);
    ServiceAlertRecord alert6 = new ServiceAlertRecord();
    alert6.setAgencyId("1");
    alert6.setServiceAlertId("F");
    ServiceAlertsSituationAffectsClause affectsClause6 = new ServiceAlertsSituationAffectsClause();
    affectsClause6.setAgencyId("1");
    affectsClause6.setStopId("10020");
    affectsClause6.setTripId("TripB");
    alert6.getAllAffects().add(affectsClause6);
    alert6 = _service.createOrUpdateServiceAlert(alert6);
    ServiceAlertRecord alert7 = new ServiceAlertRecord();
    alert7.setAgencyId("1");
    alert7.setServiceAlertId("G");
    ServiceAlertsSituationAffectsClause affectsClause7 = new ServiceAlertsSituationAffectsClause();
    affectsClause7.setAgencyId("1");
    affectsClause7.setTripId("TripB");
    alert7.getAllAffects().add(affectsClause7);
    alert7 = _service.createOrUpdateServiceAlert(alert7);
    ServiceAlertRecord alert8 = new ServiceAlertRecord();
    alert8.setAgencyId("1");
    alert8.setServiceAlertId("H");
    ServiceAlertsSituationAffectsClause affectsClause8 = new ServiceAlertsSituationAffectsClause();
    affectsClause8.setAgencyId("1");
    affectsClause8.setRouteId("RouteY");
    alert8.getAllAffects().add(affectsClause8);
    alert8 = _service.createOrUpdateServiceAlert(alert8);
    ServiceAlertRecord alert9 = new ServiceAlertRecord();
    alert9.setAgencyId("1");
    alert9.setServiceAlertId("I");
    ServiceAlertsSituationAffectsClause affectsClause9 = new ServiceAlertsSituationAffectsClause();
    affectsClause9.setAgencyId("1");
    affectsClause9.setRouteId("RouteX");
    affectsClause9.setDirectionId("0");
    alert9.getAllAffects().add(affectsClause9);
    alert9 = _service.createOrUpdateServiceAlert(alert9);
    RouteEntryImpl route = route("RouteX");
    routeCollection("RouteX", route);
    StopEntryImpl stop = stop("10020", 47.0, -122.0);
    TripEntryImpl trip = trip("TripA");
    trip.setRoute(route);
    trip.setDirectionId("1");
    stopTime(0, stop, trip, time(8, 53), 0);
    BlockEntryImpl block = block("block");
    BlockConfigurationEntry blockConfig = blockConfiguration(block, serviceIds(lsids("a"), lsids()), trip);
    BlockTripInstance blockTripInstance = new BlockTripInstance(blockConfig.getTrips().get(0), new InstanceState(System.currentTimeMillis()));
    List<ServiceAlertRecord> alerts = _service.getServiceAlertsForVehicleJourney(System.currentTimeMillis(), blockTripInstance, new AgencyAndId("1", "1111"));
    assertEquals(3, alerts.size());
    assertTrue(alerts.contains(alert2));
    assertTrue(alerts.contains(alert3));
    assertTrue(alerts.contains(alert4));
}
Also used : InstanceState(org.onebusaway.transit_data_federation.services.blocks.InstanceState) BlockTripInstance(org.onebusaway.transit_data_federation.services.blocks.BlockTripInstance) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) RouteEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.RouteEntryImpl) BlockEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry) TripEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl) StopEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl) Test(org.junit.Test)

Example 7 with BlockEntryImpl

use of org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl in project onebusaway-application-modules by camsys.

the class ServiceAlertsServiceImplTest method testGetServiceAlertsForStopCall.

@Test
public void testGetServiceAlertsForStopCall() {
    /**
     * These alerts should match
     */
    ServiceAlertRecord alert1 = new ServiceAlertRecord();
    alert1.setAgencyId("1");
    alert1.setServiceAlertId("A");
    ServiceAlertsSituationAffectsClause affectsClause = new ServiceAlertsSituationAffectsClause();
    affectsClause.setAgencyId("1");
    affectsClause.setStopId("10020");
    affectsClause.setTripId("TripA");
    alert1.getAllAffects().add(affectsClause);
    alert1 = _service.createOrUpdateServiceAlert(alert1);
    ServiceAlertRecord alert2 = new ServiceAlertRecord();
    alert2.setAgencyId("1");
    alert2.setServiceAlertId("B");
    ServiceAlertsSituationAffectsClause affectsClause2 = new ServiceAlertsSituationAffectsClause();
    affectsClause2.setAgencyId("1");
    affectsClause2.setTripId("TripA");
    alert2.getAllAffects().add(affectsClause2);
    alert2 = _service.createOrUpdateServiceAlert(alert2);
    ServiceAlertRecord alert3 = new ServiceAlertRecord();
    alert3.setAgencyId("1");
    alert3.setServiceAlertId("C");
    ServiceAlertsSituationAffectsClause affectsClause3 = new ServiceAlertsSituationAffectsClause();
    affectsClause3.setAgencyId("1");
    affectsClause3.setRouteId("RouteX");
    alert3.getAllAffects().add(affectsClause3);
    alert3 = _service.createOrUpdateServiceAlert(alert3);
    ServiceAlertRecord alert4 = new ServiceAlertRecord();
    alert4.setAgencyId("1");
    alert4.setServiceAlertId("D");
    ServiceAlertsSituationAffectsClause affectsClause4 = new ServiceAlertsSituationAffectsClause();
    affectsClause4.setAgencyId("1");
    affectsClause4.setRouteId("RouteX");
    affectsClause4.setDirectionId("1");
    alert4.getAllAffects().add(affectsClause4);
    alert4 = _service.createOrUpdateServiceAlert(alert4);
    /**
     * These alerts shouldn't match
     */
    ServiceAlertRecord alert5 = new ServiceAlertRecord();
    alert5.setAgencyId("1");
    alert5.setServiceAlertId("E");
    ServiceAlertsSituationAffectsClause affectsClause5 = new ServiceAlertsSituationAffectsClause();
    affectsClause5.setAgencyId("1");
    affectsClause5.setStopId("10021");
    affectsClause5.setTripId("TripA");
    alert5.getAllAffects().add(affectsClause5);
    alert5 = _service.createOrUpdateServiceAlert(alert5);
    ServiceAlertRecord alert6 = new ServiceAlertRecord();
    alert6.setAgencyId("1");
    alert6.setServiceAlertId("F");
    ServiceAlertsSituationAffectsClause affectsClause6 = new ServiceAlertsSituationAffectsClause();
    affectsClause6.setAgencyId("1");
    affectsClause6.setStopId("10020");
    affectsClause6.setTripId("TripB");
    alert6.getAllAffects().add(affectsClause6);
    alert6 = _service.createOrUpdateServiceAlert(alert6);
    ServiceAlertRecord alert7 = new ServiceAlertRecord();
    alert7.setAgencyId("1");
    alert7.setServiceAlertId("G");
    ServiceAlertsSituationAffectsClause affectsClause7 = new ServiceAlertsSituationAffectsClause();
    affectsClause7.setAgencyId("1");
    affectsClause7.setTripId("TripB");
    alert7.getAllAffects().add(affectsClause7);
    alert7 = _service.createOrUpdateServiceAlert(alert7);
    ServiceAlertRecord alert8 = new ServiceAlertRecord();
    alert8.setAgencyId("1");
    alert8.setServiceAlertId("H");
    ServiceAlertsSituationAffectsClause affectsClause8 = new ServiceAlertsSituationAffectsClause();
    affectsClause8.setAgencyId("1");
    affectsClause8.setRouteId("RouteY");
    alert8.getAllAffects().add(affectsClause8);
    alert8 = _service.createOrUpdateServiceAlert(alert8);
    ServiceAlertRecord alert9 = new ServiceAlertRecord();
    alert9.setAgencyId("1");
    alert9.setServiceAlertId("I");
    ServiceAlertsSituationAffectsClause affectsClause9 = new ServiceAlertsSituationAffectsClause();
    affectsClause9.setAgencyId("1");
    affectsClause9.setRouteId("RouteX");
    affectsClause9.setDirectionId("0");
    alert9.getAllAffects().add(affectsClause9);
    alert9 = _service.createOrUpdateServiceAlert(alert9);
    RouteEntryImpl route = route("RouteX");
    routeCollection("RouteX", route);
    StopEntryImpl stop = stop("10020", 47.0, -122.0);
    TripEntryImpl trip = trip("TripA");
    trip.setRoute(route);
    trip.setDirectionId("1");
    stopTime(0, stop, trip, time(8, 53), 0);
    BlockEntryImpl block = block("block");
    BlockConfigurationEntry blockConfig = blockConfiguration(block, serviceIds(lsids("a"), lsids()), trip);
    BlockInstance blockInstance = new BlockInstance(blockConfig, System.currentTimeMillis());
    List<ServiceAlertRecord> alerts = _service.getServiceAlertsForStopCall(System.currentTimeMillis(), blockInstance, blockConfig.getStopTimes().get(0), new AgencyAndId("1", "1111"));
    assertEquals(4, alerts.size());
    assertTrue(alerts.contains(alert1));
    assertTrue(alerts.contains(alert2));
    assertTrue(alerts.contains(alert3));
    assertTrue(alerts.contains(alert4));
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) BlockInstance(org.onebusaway.transit_data_federation.services.blocks.BlockInstance) RouteEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.RouteEntryImpl) BlockEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry) TripEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl) StopEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl) Test(org.junit.Test)

Example 8 with BlockEntryImpl

use of org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl in project onebusaway-application-modules by camsys.

the class BlockTripInstanceLibraryTest method test.

@Test
public void test() {
    BlockEntryImpl block = UnitTestingSupport.block("block");
    TripEntryImpl tripA = UnitTestingSupport.trip("tripA");
    TripEntryImpl tripB = UnitTestingSupport.trip("tripB");
    UnitTestingSupport.stopTime(0, null, tripA, 0, 0);
    UnitTestingSupport.stopTime(0, null, tripB, 0, 0);
    ServiceIdActivation serviceIds = UnitTestingSupport.serviceIds("sid");
    BlockConfigurationEntry blockConfig = UnitTestingSupport.blockConfiguration(block, serviceIds, tripA, tripB);
    BlockInstance blockInstanceA = new BlockInstance(blockConfig, 123L);
    BlockTripInstance blockTripInstance = BlockTripInstanceLibrary.getBlockTripInstance(blockInstanceA, UnitTestingSupport.aid("tripA"));
    assertSame(tripA, blockTripInstance.getBlockTrip().getTrip());
    assertEquals(123L, blockTripInstance.getServiceDate());
    blockTripInstance = BlockTripInstanceLibrary.getBlockTripInstance(blockInstanceA, UnitTestingSupport.aid("tripB"));
    assertSame(tripB, blockTripInstance.getBlockTrip().getTrip());
    assertEquals(123L, blockTripInstance.getServiceDate());
    blockTripInstance = BlockTripInstanceLibrary.getBlockTripInstance(blockInstanceA, UnitTestingSupport.aid("tripC"));
    assertNull(blockTripInstance);
}
Also used : ServiceIdActivation(org.onebusaway.transit_data_federation.services.transit_graph.ServiceIdActivation) BlockEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry) TripEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl) Test(org.junit.Test)

Example 9 with BlockEntryImpl

use of org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl in project onebusaway-application-modules by camsys.

the class ArrivalAndDepartureServiceImplTest method getArrivalsAndDeparturesForStopInTimeRangeForCancelledTrip.

/**
 * Set up the BlockLocationServiceImpl for the test, using the given
 * timepointPredictions
 *
 * This method creates a normal route with a single trip and two stops in a block
 *
 * stop_id     trip_id    stop_sequence
 *    A           1             0
 *    B           1             1
 *
 * @param timepointPredictions real-time predictions to apply to the
 *          BlockLocationServiceImpl
 * @return a list of ArrivalAndDepartureInstances which is used to access
 *         predicted arrival/departure times for a stop, for comparison
 *         against the expected values
 */
private List<ArrivalAndDepartureInstance> getArrivalsAndDeparturesForStopInTimeRangeForCancelledTrip() {
    TargetTime target = new TargetTime(mCurrentTime, mCurrentTime);
    // Setup block
    BlockEntryImpl block = block("blockA");
    stopTime(0, mStopA, mTrip1, time(13, 30), time(13, 35), 1000);
    stopTime(1, mStopB, mTrip1, time(13, 45), time(13, 50), 2000);
    BlockConfigurationEntry blockConfig = blockConfiguration(block, serviceIds(lsids("sA"), lsids()), mTrip1);
    BlockStopTimeEntry bstAA = blockConfig.getStopTimes().get(0);
    BlockStopTimeEntry bstAB = blockConfig.getStopTimes().get(1);
    BlockStopTimeEntry bstBA = blockConfig.getStopTimes().get(0);
    // Setup block location instance for trip B
    BlockInstance blockInstance = new BlockInstance(blockConfig, mServiceDate);
    BlockLocation blockLocationB = new BlockLocation();
    blockLocationB.setActiveTrip(bstBA.getTrip());
    blockLocationB.setBlockInstance(blockInstance);
    blockLocationB.setClosestStop(bstBA);
    blockLocationB.setDistanceAlongBlock(400);
    blockLocationB.setInService(true);
    blockLocationB.setNextStop(bstAA);
    blockLocationB.setPredicted(false);
    blockLocationB.setScheduledDistanceAlongBlock(400);
    // Mock StopTimeInstance with time frame
    long stopTimeFrom = dateAsLong("2015-07-23 00:00");
    long stopTimeTo = dateAsLong("2015-07-24 00:00");
    StopTimeInstance sti1 = new StopTimeInstance(bstAB, blockInstance.getState());
    ArrivalAndDepartureInstance in1 = new ArrivalAndDepartureInstance(sti1);
    in1.setBlockLocation(blockLocationB);
    in1.setPredictedArrivalTime((long) (in1.getScheduledArrivalTime()));
    in1.setPredictedDepartureTime((long) (in1.getScheduledDepartureTime()));
    StopTimeInstance sti2 = new StopTimeInstance(bstBA, blockInstance.getState());
    ArrivalAndDepartureInstance in2 = new ArrivalAndDepartureInstance(sti2);
    in2.setBlockLocation(blockLocationB);
    Date fromTimeBuffered = new Date(stopTimeFrom - _blockStatusService.getRunningLateWindow() * 1000);
    Date toTimeBuffered = new Date(stopTimeTo + _blockStatusService.getRunningEarlyWindow() * 1000);
    Mockito.when(_stopTimeService.getStopTimeInstancesInTimeRange(mStopB, fromTimeBuffered, toTimeBuffered, EFrequencyStopTimeBehavior.INCLUDE_UNSPECIFIED)).thenReturn(Arrays.asList(sti1, sti2));
    // Create and add vehicle location record cache
    VehicleLocationRecordCacheImpl _cache = new VehicleLocationRecordCacheImpl();
    VehicleLocationRecord vlr = new VehicleLocationRecord();
    vlr.setBlockId(blockLocationB.getBlockInstance().getBlock().getBlock().getId());
    vlr.setTripId(mTrip1.getId());
    vlr.setTimepointPredictions(blockLocationB.getTimepointPredictions());
    vlr.setTimeOfRecord(mCurrentTime);
    vlr.setVehicleId(new AgencyAndId("1", "123"));
    vlr.setStatus(TransitDataConstants.STATUS_CANCELED);
    // Create ScheduledBlockLocation for cache
    ScheduledBlockLocation sbl = new ScheduledBlockLocation();
    sbl.setActiveTrip(blockLocationB.getActiveTrip());
    // Add data to cache
    _cache.addRecord(blockInstance, vlr, sbl, null);
    _blockLocationService.setVehicleLocationRecordCache(_cache);
    ScheduledBlockLocationServiceImpl scheduledBlockLocationServiceImpl = new ScheduledBlockLocationServiceImpl();
    _blockLocationService.setScheduledBlockLocationService(scheduledBlockLocationServiceImpl);
    // Call ArrivalAndDepartureService
    return _service.getArrivalsAndDeparturesForStopInTimeRange(mStopB, target, stopTimeFrom, stopTimeTo);
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) StopTimeInstance(org.onebusaway.transit_data_federation.model.StopTimeInstance) VehicleLocationRecordCacheImpl(org.onebusaway.transit_data_federation.impl.realtime.VehicleLocationRecordCacheImpl) TargetTime(org.onebusaway.transit_data_federation.model.TargetTime) ScheduledBlockLocation(org.onebusaway.transit_data_federation.services.blocks.ScheduledBlockLocation) BlockLocation(org.onebusaway.transit_data_federation.services.realtime.BlockLocation) Date(java.util.Date) ScheduledBlockLocation(org.onebusaway.transit_data_federation.services.blocks.ScheduledBlockLocation) BlockInstance(org.onebusaway.transit_data_federation.services.blocks.BlockInstance) VehicleLocationRecord(org.onebusaway.realtime.api.VehicleLocationRecord) ArrivalAndDepartureInstance(org.onebusaway.transit_data_federation.services.realtime.ArrivalAndDepartureInstance) ScheduledBlockLocationServiceImpl(org.onebusaway.transit_data_federation.impl.blocks.ScheduledBlockLocationServiceImpl) BlockEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)

Example 10 with BlockEntryImpl

use of org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl in project onebusaway-application-modules by camsys.

the class ArrivalAndDepartureServiceImplTest method getArrivalsAndDeparturesForLoopInTheMiddleOfRouteInTimeRangeByTimepointPredictionRecord.

/**
 * Set up the BlockLocationServiceImpl for the test, using the given
 * timepointPredictions
 *
 * This method creates a loop route with a single trip and four stops in a block
 * Stop B is visited twice in the middle of the route
 *
 * stop_id     trip_id    stop_sequence
 *    A           1             0
 *    B           1             1
 *    C           1             2
 *    B           1             3
 *    D           1             4
 *
 * @param timepointPredictions real-time predictions to apply to the
 *          BlockLocationServiceImpl
 * @return a list of ArrivalAndDepartureInstances which is used to access
 *         predicted arrival/departure times for a stop, for comparison
 *         against the expected values
 */
private List<ArrivalAndDepartureInstance> getArrivalsAndDeparturesForLoopInTheMiddleOfRouteInTimeRangeByTimepointPredictionRecord(List<TimepointPredictionRecord> timepointPredictions) {
    TargetTime target = new TargetTime(mCurrentTime, mCurrentTime);
    // Setup block
    BlockEntryImpl block = block("blockA");
    stopTime(0, mStopA, mTrip1, time(13, 30), time(13, 35), 1000);
    stopTime(1, mStopB, mTrip1, time(13, 45), time(13, 50), 2000);
    stopTime(2, mStopC, mTrip1, time(13, 55), time(14, 00), 2000);
    stopTime(3, mStopB, mTrip1, time(14, 05), time(14, 10), 2000);
    stopTime(4, mStopD, mTrip1, time(14, 15), time(14, 20), 2000);
    BlockConfigurationEntry blockConfig = blockConfiguration(block, serviceIds(lsids("sA"), lsids()), mTrip1);
    BlockStopTimeEntry bstAA = blockConfig.getStopTimes().get(0);
    BlockStopTimeEntry bstAB = blockConfig.getStopTimes().get(1);
    BlockStopTimeEntry bstAC = blockConfig.getStopTimes().get(2);
    BlockStopTimeEntry bstABB = blockConfig.getStopTimes().get(3);
    BlockStopTimeEntry bstAD = blockConfig.getStopTimes().get(4);
    // Setup block location instance for trip B
    BlockInstance blockInstance = new BlockInstance(blockConfig, mServiceDate);
    BlockLocation blockLocationB = new BlockLocation();
    blockLocationB.setActiveTrip(bstAA.getTrip());
    blockLocationB.setBlockInstance(blockInstance);
    blockLocationB.setClosestStop(bstAB);
    blockLocationB.setDistanceAlongBlock(400);
    blockLocationB.setInService(true);
    blockLocationB.setNextStop(bstAA);
    blockLocationB.setPredicted(false);
    blockLocationB.setScheduledDistanceAlongBlock(400);
    blockLocationB.setTimepointPredictions(timepointPredictions);
    // Mock StopTimeInstance with time frame
    long stopTimeFrom = dateAsLong("2015-07-23 00:00");
    long stopTimeTo = dateAsLong("2015-07-24 00:00");
    StopTimeInstance sti1 = new StopTimeInstance(bstAB, blockInstance.getState());
    ArrivalAndDepartureInstance in1 = new ArrivalAndDepartureInstance(sti1);
    in1.setBlockLocation(blockLocationB);
    in1.setPredictedArrivalTime((long) (in1.getScheduledArrivalTime()));
    in1.setPredictedDepartureTime((long) (in1.getScheduledDepartureTime()));
    StopTimeInstance sti2 = new StopTimeInstance(bstAA, blockInstance.getState());
    ArrivalAndDepartureInstance in2 = new ArrivalAndDepartureInstance(sti2);
    in2.setBlockLocation(blockLocationB);
    StopTimeInstance sti3 = new StopTimeInstance(bstAC, blockInstance.getState());
    ArrivalAndDepartureInstance in3 = new ArrivalAndDepartureInstance(sti3);
    in3.setBlockLocation(blockLocationB);
    StopTimeInstance sti4 = new StopTimeInstance(bstABB, blockInstance.getState());
    ArrivalAndDepartureInstance in4 = new ArrivalAndDepartureInstance(sti4);
    in4.setBlockLocation(blockLocationB);
    StopTimeInstance sti5 = new StopTimeInstance(bstAD, blockInstance.getState());
    ArrivalAndDepartureInstance in5 = new ArrivalAndDepartureInstance(sti5);
    in5.setBlockLocation(blockLocationB);
    Date fromTimeBuffered = new Date(stopTimeFrom - _blockStatusService.getRunningLateWindow() * 1000);
    Date toTimeBuffered = new Date(stopTimeTo + _blockStatusService.getRunningEarlyWindow() * 1000);
    Mockito.when(_stopTimeService.getStopTimeInstancesInTimeRange(mStopB, fromTimeBuffered, toTimeBuffered, EFrequencyStopTimeBehavior.INCLUDE_UNSPECIFIED)).thenReturn(Arrays.asList(sti1, sti2, sti3, sti4, sti5));
    // Create and add vehicle location record cache
    VehicleLocationRecordCacheImpl _cache = new VehicleLocationRecordCacheImpl();
    VehicleLocationRecord vlr = new VehicleLocationRecord();
    vlr.setBlockId(blockLocationB.getBlockInstance().getBlock().getBlock().getId());
    vlr.setTripId(mTrip1.getId());
    vlr.setTimepointPredictions(blockLocationB.getTimepointPredictions());
    vlr.setTimeOfRecord(mCurrentTime);
    vlr.setVehicleId(new AgencyAndId("1", "123"));
    // Create ScheduledBlockLocation for cache
    ScheduledBlockLocation sbl = new ScheduledBlockLocation();
    sbl.setActiveTrip(blockLocationB.getActiveTrip());
    // Add data to cache
    _cache.addRecord(blockInstance, vlr, sbl, null);
    _blockLocationService.setVehicleLocationRecordCache(_cache);
    ScheduledBlockLocationServiceImpl scheduledBlockLocationServiceImpl = new ScheduledBlockLocationServiceImpl();
    _blockLocationService.setScheduledBlockLocationService(scheduledBlockLocationServiceImpl);
    // Call ArrivalAndDepartureService
    return _service.getArrivalsAndDeparturesForStopInTimeRange(mStopB, target, stopTimeFrom, stopTimeTo);
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) StopTimeInstance(org.onebusaway.transit_data_federation.model.StopTimeInstance) VehicleLocationRecordCacheImpl(org.onebusaway.transit_data_federation.impl.realtime.VehicleLocationRecordCacheImpl) TargetTime(org.onebusaway.transit_data_federation.model.TargetTime) ScheduledBlockLocation(org.onebusaway.transit_data_federation.services.blocks.ScheduledBlockLocation) BlockLocation(org.onebusaway.transit_data_federation.services.realtime.BlockLocation) Date(java.util.Date) ScheduledBlockLocation(org.onebusaway.transit_data_federation.services.blocks.ScheduledBlockLocation) BlockInstance(org.onebusaway.transit_data_federation.services.blocks.BlockInstance) VehicleLocationRecord(org.onebusaway.realtime.api.VehicleLocationRecord) ArrivalAndDepartureInstance(org.onebusaway.transit_data_federation.services.realtime.ArrivalAndDepartureInstance) ScheduledBlockLocationServiceImpl(org.onebusaway.transit_data_federation.impl.blocks.ScheduledBlockLocationServiceImpl) BlockEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)

Aggregations

BlockEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl)43 TripEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl)34 BlockConfigurationEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)34 Test (org.junit.Test)33 BlockInstance (org.onebusaway.transit_data_federation.services.blocks.BlockInstance)25 StopEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl)16 VehicleLocationRecord (org.onebusaway.realtime.api.VehicleLocationRecord)15 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)11 TripUpdate (com.google.transit.realtime.GtfsRealtime.TripUpdate)9 BlockStopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)8 StopTimeUpdate (com.google.transit.realtime.GtfsRealtime.TripUpdate.StopTimeUpdate)7 TargetTime (org.onebusaway.transit_data_federation.model.TargetTime)7 BlockLocation (org.onebusaway.transit_data_federation.services.realtime.BlockLocation)7 Date (java.util.Date)6 StopTimeInstance (org.onebusaway.transit_data_federation.model.StopTimeInstance)6 ArrivalAndDepartureInstance (org.onebusaway.transit_data_federation.services.realtime.ArrivalAndDepartureInstance)6 ServiceIdActivation (org.onebusaway.transit_data_federation.services.transit_graph.ServiceIdActivation)6 ScheduledBlockLocation (org.onebusaway.transit_data_federation.services.blocks.ScheduledBlockLocation)5 BlockEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockEntry)5 BlockTripEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry)5