Search in sources :

Example 1 with StopEntryImpl

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

the class GtfsRealtimeTripLibraryTest method test.

@Test
public void test() {
    FeedEntity tripUpdateEntityA = createTripUpdate("tripA", "stopA", 60, true);
    FeedEntity tripUpdateEntityB = createTripUpdate("tripB", "stopB", 120, true);
    FeedEntity tripUpdateEntityC = createTripUpdate("tripC", "stopA", 30, true);
    FeedEntity tripUpdateEntityD = createTripUpdate("tripD", "stopB", 90, true);
    FeedMessage.Builder tripUpdates = createFeed();
    tripUpdates.addEntity(tripUpdateEntityA);
    tripUpdates.addEntity(tripUpdateEntityB);
    tripUpdates.addEntity(tripUpdateEntityC);
    tripUpdates.addEntity(tripUpdateEntityD);
    TripEntryImpl tripA = trip("tripA");
    TripEntryImpl tripB = trip("tripB");
    TripEntryImpl tripC = trip("tripC");
    TripEntryImpl tripD = trip("tripD");
    StopEntryImpl stopA = stop("stopA", 0, 0);
    StopEntryImpl stopB = stop("stopB", 0, 0);
    stopTime(0, stopA, tripA, time(7, 30), 0.0);
    stopTime(1, stopB, tripB, time(8, 30), 0.0);
    stopTime(2, stopA, tripC, time(8, 30), 0.0);
    stopTime(3, stopB, tripD, time(9, 30), 0.0);
    Mockito.when(_entitySource.getTrip("tripA")).thenReturn(tripA);
    Mockito.when(_entitySource.getTrip("tripB")).thenReturn(tripB);
    Mockito.when(_entitySource.getTrip("tripC")).thenReturn(tripC);
    Mockito.when(_entitySource.getTrip("tripD")).thenReturn(tripD);
    BlockEntryImpl blockA = block("blockA");
    BlockEntryImpl blockB = block("blockB");
    BlockConfigurationEntry blockConfigA = blockConfiguration(blockA, serviceIds("s1"), tripA, tripB);
    BlockConfigurationEntry blockConfigB = blockConfiguration(blockB, serviceIds("s1"), tripC, tripD);
    BlockInstance blockInstanceA = new BlockInstance(blockConfigA, 0L);
    BlockInstance blockInstanceB = new BlockInstance(blockConfigB, 0L);
    Mockito.when(_blockCalendarService.getActiveBlocks(Mockito.eq(blockA.getId()), Mockito.anyLong(), Mockito.anyLong())).thenReturn(Arrays.asList(blockInstanceA));
    Mockito.when(_blockCalendarService.getActiveBlocks(Mockito.eq(blockB.getId()), Mockito.anyLong(), Mockito.anyLong())).thenReturn(Arrays.asList(blockInstanceB));
    FeedMessage.Builder vehiclePositions = createFeed();
    // FeedEntity.Builder vehiclePositionEntity = FeedEntity.newBuilder();
    // vehiclePositions.addEntity(vehiclePositionEntity);
    List<CombinedTripUpdatesAndVehiclePosition> groups = _library.groupTripUpdatesAndVehiclePositions(tripUpdates.build(), vehiclePositions.build());
    assertEquals(2, groups.size());
    Collections.sort(groups);
    CombinedTripUpdatesAndVehiclePosition group = groups.get(0);
    assertSame(blockA, group.block.getBlockInstance().getBlock().getBlock());
    assertEquals(2, group.tripUpdates.size());
    TripUpdate tripUpdate = group.tripUpdates.get(0);
    assertEquals("tripA", tripUpdate.getTrip().getTripId());
    tripUpdate = group.tripUpdates.get(1);
    assertEquals("tripB", tripUpdate.getTrip().getTripId());
    group = groups.get(1);
    assertSame(blockB, group.block.getBlockInstance().getBlock().getBlock());
    assertEquals(2, group.tripUpdates.size());
    tripUpdate = group.tripUpdates.get(0);
    assertEquals("tripC", tripUpdate.getTrip().getTripId());
    tripUpdate = group.tripUpdates.get(1);
    assertEquals("tripD", tripUpdate.getTrip().getTripId());
    VehicleLocationRecord record = _library.createVehicleLocationRecordForUpdate(groups.get(0));
    assertEquals(blockA.getId(), record.getBlockId());
    assertEquals(120, record.getScheduleDeviation(), 0.0);
    assertEquals(0L, record.getServiceDate());
    assertEquals(blockA.getId(), record.getVehicleId());
    record = _library.createVehicleLocationRecordForUpdate(groups.get(1));
    assertEquals(blockB.getId(), record.getBlockId());
    assertEquals(30, record.getScheduleDeviation(), 0.0);
    assertEquals(0L, record.getServiceDate());
    assertEquals(blockB.getId(), record.getVehicleId());
}
Also used : FeedMessage(com.google.transit.realtime.GtfsRealtime.FeedMessage) TripUpdate(com.google.transit.realtime.GtfsRealtime.TripUpdate) BlockInstance(org.onebusaway.transit_data_federation.services.blocks.BlockInstance) VehicleLocationRecord(org.onebusaway.realtime.api.VehicleLocationRecord) FeedEntity(com.google.transit.realtime.GtfsRealtime.FeedEntity) 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 2 with StopEntryImpl

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

the class GtfsRealtimeTripLibraryTest method testTprOnFutureTrip.

/**
 * This method tests that we propagate a time point prediction record
 * when it comes from a trip that hasn't started yet.
 *
 * Current time = 7:31. Trip update delay = 2 minutes
 *                  Schedule time    Real-time from feed
 * Stop A (trip A)  7:30             7:33
 * Stop A (trip B)  7:40             7:44
 */
@Test
public void testTprOnFutureTrip() {
    _library.setCurrentTime(time(7, 31) * 1000);
    TripEntryImpl tripA = trip("tripA");
    TripEntryImpl tripB = trip("tripB");
    StopEntryImpl stopA = stop("stopA", 0, 0);
    stopTime(0, stopA, tripA, time(7, 30), 0.0);
    stopTime(0, stopA, tripB, time(7, 40), 0.0);
    BlockEntryImpl blockA = block("blockA");
    BlockConfigurationEntry blockConfigA = blockConfiguration(blockA, serviceIds("s1"), tripA, tripB);
    BlockInstance blockInstanceA = new BlockInstance(blockConfigA, 0L);
    StopTimeUpdate.Builder stuA = stopTimeUpdateWithDepartureDelay("stopA", 180);
    TripUpdate.Builder tuA = tripUpdate("tripA", _library.getCurrentTime() / 1000, 120, stuA);
    StopTimeUpdate.Builder stuB = stopTimeUpdateWithDepartureDelay("stopA", 240);
    TripUpdate.Builder tuB = tripUpdate("tripB", _library.getCurrentTime() / 1000, 0, stuB);
    tuA.setVehicle(vehicle("bus1"));
    tuB.setVehicle(vehicle("bus1"));
    Mockito.when(_entitySource.getTrip("tripA")).thenReturn(tripA);
    Mockito.when(_entitySource.getTrip("tripB")).thenReturn(tripB);
    Mockito.when(_blockCalendarService.getActiveBlocks(Mockito.eq(blockA.getId()), Mockito.anyLong(), Mockito.anyLong())).thenReturn(Arrays.asList(blockInstanceA));
    VehicleLocationRecord record = vehicleLocationRecord(tuA, tuB);
    long tripADept = getPredictedDepartureTimeByStopIdAndTripId(record, "stopA", "tripA");
    assertEquals(tripADept, time(7, 33) * 1000);
    long tripBDept = getPredictedDepartureTimeByStopIdAndTripId(record, "stopA", "tripB");
    assertEquals(tripBDept, time(7, 44) * 1000);
}
Also used : TripUpdate(com.google.transit.realtime.GtfsRealtime.TripUpdate) BlockInstance(org.onebusaway.transit_data_federation.services.blocks.BlockInstance) StopTimeUpdate(com.google.transit.realtime.GtfsRealtime.TripUpdate.StopTimeUpdate) VehicleLocationRecord(org.onebusaway.realtime.api.VehicleLocationRecord) 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 3 with StopEntryImpl

use of org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl 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 4 with StopEntryImpl

use of org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl 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 5 with StopEntryImpl

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

the class RouteBeanServiceImplTest method testGetStopsForRoute.

@Test
public void testGetStopsForRoute() {
    AgencyAndId routeId = new AgencyAndId("1", "route");
    RouteEntryImpl route = new RouteEntryImpl();
    route.setId(new AgencyAndId("1", "raw_route"));
    List<RouteEntry> routes = Arrays.asList((RouteEntry) route);
    RouteCollectionEntryImpl routeCollection = new RouteCollectionEntryImpl();
    routeCollection.setId(routeId);
    routeCollection.setChildren(routes);
    route.setParent(routeCollection);
    Mockito.when(_transitGraphDao.getRouteCollectionForId(routeId)).thenReturn(routeCollection);
    RouteCollectionNarrative.Builder rcNarrative = RouteCollectionNarrative.builder();
    Mockito.when(_narrativeService.getRouteCollectionForId(routeId)).thenReturn(rcNarrative.create());
    StopEntryImpl stopA = stop("stopA", 47.0, -122.0);
    StopEntryImpl stopB = stop("stopB", 47.1, -122.1);
    StopEntryImpl stopC = stop("stopC", 47.2, -122.2);
    BlockEntryImpl blockA = block("blockA");
    TripEntryImpl tripA = trip("tripA", "sidA");
    TripEntryImpl tripB = trip("tripB", "sidA");
    tripA.setRoute(route);
    tripA.setDirectionId("0");
    tripB.setRoute(route);
    tripB.setDirectionId("1");
    route.setTrips(Arrays.asList((TripEntry) tripA, tripB));
    TripNarrative.Builder tnA = TripNarrative.builder();
    tnA.setTripHeadsign("Destination A");
    Mockito.when(_narrativeService.getTripForId(tripA.getId())).thenReturn(tnA.create());
    TripNarrative.Builder tnB = TripNarrative.builder();
    tnB.setTripHeadsign("Destination B");
    Mockito.when(_narrativeService.getTripForId(tripB.getId())).thenReturn(tnB.create());
    stopTime(0, stopA, tripA, time(9, 00), time(9, 00), 0);
    stopTime(1, stopB, tripA, time(9, 30), time(9, 30), 100);
    stopTime(2, stopC, tripA, time(10, 00), time(10, 00), 200);
    stopTime(3, stopC, tripB, time(11, 30), time(11, 30), 0);
    stopTime(4, stopA, tripB, time(12, 30), time(12, 30), 200);
    linkBlockTrips(blockA, tripA, tripB);
    List<BlockTripIndex> blockIndices = blockTripIndices(blockA);
    Mockito.when(_blockIndexService.getBlockTripIndicesForRouteCollectionId(routeId)).thenReturn(blockIndices);
    StopBean stopBeanA = getStopBean(stopA);
    StopBean stopBeanB = getStopBean(stopB);
    StopBean stopBeanC = getStopBean(stopC);
    List<AgencyAndId> stopIds = Arrays.asList(stopA.getId(), stopB.getId(), stopC.getId());
    Mockito.when(_routeService.getStopsForRouteCollection(routeId)).thenReturn(stopIds);
    Mockito.when(_stopBeanService.getStopForId(stopA.getId())).thenReturn(stopBeanA);
    Mockito.when(_stopBeanService.getStopForId(stopB.getId())).thenReturn(stopBeanB);
    Mockito.when(_stopBeanService.getStopForId(stopC.getId())).thenReturn(stopBeanC);
    AgencyAndId shapeId = new AgencyAndId("1", "shapeId");
    Set<AgencyAndId> shapeIds = new HashSet<AgencyAndId>();
    shapeIds.add(shapeId);
    tripA.setShapeId(shapeId);
    EncodedPolylineBean polyline = new EncodedPolylineBean();
    Mockito.when(_shapeBeanService.getMergedPolylinesForShapeIds(shapeIds)).thenReturn(Arrays.asList(polyline));
    // Setup complete
    StopsForRouteBean stopsForRoute = _service.getStopsForRoute(routeId);
    List<StopBean> stops = stopsForRoute.getStops();
    assertEquals(3, stops.size());
    assertSame(stopBeanA, stops.get(0));
    assertSame(stopBeanB, stops.get(1));
    assertSame(stopBeanC, stops.get(2));
    List<EncodedPolylineBean> polylines = stopsForRoute.getPolylines();
    assertEquals(1, polylines.size());
    assertSame(polyline, polylines.get(0));
    List<StopGroupingBean> groupings = stopsForRoute.getStopGroupings();
    assertEquals(1, groupings.size());
    StopGroupingBean grouping = groupings.get(0);
    assertEquals("direction", grouping.getType());
    List<StopGroupBean> groups = grouping.getStopGroups();
    assertEquals(2, groups.size());
    StopGroupBean groupA = groups.get(0);
    StopGroupBean groupB = groups.get(1);
    NameBean nameA = groupA.getName();
    assertEquals("destination", nameA.getType());
    assertEquals("Destination A", nameA.getName());
    List<String> stopIdsA = groupA.getStopIds();
    assertEquals(3, stopIdsA.size());
    assertEquals(ids(stopA.getId(), stopB.getId(), stopC.getId()), stopIdsA);
    NameBean nameB = groupB.getName();
    assertEquals("destination", nameB.getType());
    assertEquals("Destination B", nameB.getName());
    List<String> stopIdsB = groupB.getStopIds();
    assertEquals(2, stopIdsB.size());
    assertEquals(ids(stopC.getId(), stopA.getId()), stopIdsB);
}
Also used : RouteEntry(org.onebusaway.transit_data_federation.services.transit_graph.RouteEntry) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) StopGroupBean(org.onebusaway.transit_data.model.StopGroupBean) RouteEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.RouteEntryImpl) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) TripEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl) EncodedPolylineBean(org.onebusaway.geospatial.model.EncodedPolylineBean) BlockTripIndex(org.onebusaway.transit_data_federation.services.blocks.BlockTripIndex) HashSet(java.util.HashSet) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) RouteCollectionNarrative(org.onebusaway.transit_data_federation.model.narrative.RouteCollectionNarrative) StopEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl) RouteCollectionEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.RouteCollectionEntryImpl) StopGroupingBean(org.onebusaway.transit_data.model.StopGroupingBean) StopBean(org.onebusaway.transit_data.model.StopBean) BlockEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl) NameBean(org.onebusaway.transit_data.model.NameBean) TripNarrative(org.onebusaway.transit_data_federation.model.narrative.TripNarrative) Test(org.junit.Test)

Aggregations

StopEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl)33 Test (org.junit.Test)23 TripEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl)22 BlockEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl)16 StopTimeEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.StopTimeEntryImpl)12 BlockConfigurationEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)11 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)10 StopEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopEntry)7 ArrayList (java.util.ArrayList)6 BlockStopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)6 CoordinatePoint (org.onebusaway.geospatial.model.CoordinatePoint)5 Stop (org.onebusaway.gtfs.model.Stop)5 BlockInstance (org.onebusaway.transit_data_federation.services.blocks.BlockInstance)5 BlockTripEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry)5 XYPoint (org.onebusaway.geospatial.model.XYPoint)4 PointAndIndex (org.onebusaway.transit_data_federation.impl.shapes.PointAndIndex)4 StopNarrative (org.onebusaway.transit_data_federation.model.narrative.StopNarrative)4 FrequencyBlockTripIndex (org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockTripIndex)4 BlockEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockEntry)4 ServiceIdActivation (org.onebusaway.transit_data_federation.services.transit_graph.ServiceIdActivation)4