Search in sources :

Example 1 with RouteEntryImpl

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

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

use of org.onebusaway.transit_data_federation.impl.transit_graph.RouteEntryImpl 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)

Example 4 with RouteEntryImpl

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

the class UnitTestingSupport method route.

public static RouteEntryImpl route(String id) {
    RouteEntryImpl route = new RouteEntryImpl();
    route.setId(aid(id));
    return route;
}
Also used : RouteEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.RouteEntryImpl)

Example 5 with RouteEntryImpl

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

the class UnitTestingSupport method routeCollection.

public static RouteCollectionEntryImpl routeCollection(String id, RouteEntry... routes) {
    RouteCollectionEntryImpl route = new RouteCollectionEntryImpl();
    route.setId(aid(id));
    route.setChildren(Arrays.asList(routes));
    for (RouteEntry routeEntry : routes) {
        ((RouteEntryImpl) routeEntry).setParent(route);
    }
    return route;
}
Also used : RouteEntry(org.onebusaway.transit_data_federation.services.transit_graph.RouteEntry) RouteCollectionEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.RouteCollectionEntryImpl) RouteEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.RouteEntryImpl)

Aggregations

RouteEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.RouteEntryImpl)15 Test (org.junit.Test)9 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)9 RouteEntry (org.onebusaway.transit_data_federation.services.transit_graph.RouteEntry)7 Route (org.onebusaway.gtfs.model.Route)6 RouteCollectionEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.RouteCollectionEntryImpl)6 TripEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl)5 GtfsRelationalDao (org.onebusaway.gtfs.services.GtfsRelationalDao)4 UniqueServiceImpl (org.onebusaway.transit_data_federation.bundle.tasks.UniqueServiceImpl)4 TransitGraphImpl (org.onebusaway.transit_data_federation.impl.transit_graph.TransitGraphImpl)4 ArrayList (java.util.ArrayList)3 BlockEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl)3 StopEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl)3 RouteCollectionEntry (org.onebusaway.transit_data_federation.services.transit_graph.RouteCollectionEntry)3 TripEntry (org.onebusaway.transit_data_federation.services.transit_graph.TripEntry)3 Agency (org.onebusaway.gtfs.model.Agency)2 Trip (org.onebusaway.gtfs.model.Trip)2 AgencyEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.AgencyEntryImpl)2 RouteCollectionNarrative (org.onebusaway.transit_data_federation.model.narrative.RouteCollectionNarrative)2 BlockConfigurationEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)2