Search in sources :

Example 6 with TransitGraphImpl

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

the class TripEntriesFactoryTest method test.

@Test
public void test() {
    GtfsRelationalDao gtfsDao = Mockito.mock(GtfsRelationalDao.class);
    Agency agency = new Agency();
    agency.setId("1");
    agency.setTimezone("America/Los_Angeles");
    // gtfsDao.saveEntity(agency);
    Route route = new Route();
    route.setId(new AgencyAndId("1", "routeA"));
    route.setAgency(agency);
    Mockito.when(gtfsDao.getAllRoutes()).thenReturn(Arrays.asList(route));
    AgencyAndId shapeId = new AgencyAndId("1", "shapeId");
    Trip trip = new Trip();
    trip.setId(new AgencyAndId("1", "tripA"));
    trip.setRoute(route);
    trip.setServiceId(new AgencyAndId("1", "serviceId"));
    trip.setShapeId(shapeId);
    Mockito.when(gtfsDao.getTripsForRoute(route)).thenReturn(Arrays.asList(trip));
    Stop stopA = new Stop();
    stopA.setId(aid("stopA"));
    StopTime stA = new StopTime();
    stA.setId(100);
    stA.setArrivalTime(time(9, 00));
    stA.setDepartureTime(time(9, 05));
    stA.setStopSequence(100);
    stA.setStop(stopA);
    stA.setTrip(trip);
    Stop stopB = new Stop();
    stopB.setId(aid("stopB"));
    StopTime stB = new StopTime();
    stB.setId(101);
    stB.setArrivalTime(time(10, 00));
    stB.setDepartureTime(time(10, 05));
    stB.setStopSequence(102);
    stB.setStop(stopB);
    stB.setTrip(trip);
    Mockito.when(gtfsDao.getStopTimesForTrip(trip)).thenReturn(Arrays.asList(stA, stB));
    TransitGraphImpl graph = new TransitGraphImpl();
    graph.putStopEntry(stop("stopA", 47.672207391799056, -122.387855896286));
    graph.putStopEntry(stop("stopB", 47.66852277218285, -122.3853882639923));
    RouteEntryImpl routeEntry = route("routeA");
    graph.putRouteEntry(routeEntry);
    graph.initialize();
    ShapePointsFactory shapePointsFactory = new ShapePointsFactory();
    shapePointsFactory.addPoint(47.673840100841396, -122.38756621771239);
    shapePointsFactory.addPoint(47.668667271970484, -122.38756621771239);
    shapePointsFactory.addPoint(47.66868172192725, -122.3661729186096);
    ShapePoints shapePoints = shapePointsFactory.create();
    ShapePointHelper shapePointHelper = Mockito.mock(ShapePointHelper.class);
    Mockito.when(shapePointHelper.getShapePointsForShapeId(shapeId)).thenReturn(shapePoints);
    TripEntriesFactory factory = new TripEntriesFactory();
    factory.setGtfsDao(gtfsDao);
    factory.setShapePointHelper(shapePointHelper);
    factory.setUniqueService(new UniqueServiceImpl());
    StopTimeEntriesFactory stopTimeEntriesFactory = new StopTimeEntriesFactory();
    stopTimeEntriesFactory.setDistanceAlongShapeLibrary(new DistanceAlongShapeLibrary());
    factory.setStopTimeEntriesFactory(stopTimeEntriesFactory);
    factory.processTrips(graph);
    TripEntryImpl entry = graph.getTripEntryForId(trip.getId());
    assertEquals(trip.getId(), entry.getId());
    assertEquals(route.getId(), entry.getRoute().getId());
    assertEquals(lsid("serviceId"), entry.getServiceId());
    assertEquals(trip.getShapeId(), entry.getShapeId());
    assertEquals(2177.1, entry.getTotalTripDistance(), 0.1);
    List<StopTimeEntry> stopTimes = entry.getStopTimes();
    assertEquals(2, stopTimes.size());
    for (StopTimeEntry stopTime : stopTimes) {
        assertSame(entry, stopTime.getTrip());
    }
}
Also used : UniqueServiceImpl(org.onebusaway.transit_data_federation.bundle.tasks.UniqueServiceImpl) GtfsRelationalDao(org.onebusaway.gtfs.services.GtfsRelationalDao) Trip(org.onebusaway.gtfs.model.Trip) Agency(org.onebusaway.gtfs.model.Agency) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Stop(org.onebusaway.gtfs.model.Stop) ShapePointHelper(org.onebusaway.transit_data_federation.bundle.tasks.ShapePointHelper) RouteEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.RouteEntryImpl) TripEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl) ShapePoints(org.onebusaway.transit_data_federation.model.ShapePoints) ShapePointsFactory(org.onebusaway.transit_data_federation.model.ShapePointsFactory) StopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry) TransitGraphImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TransitGraphImpl) Route(org.onebusaway.gtfs.model.Route) StopTime(org.onebusaway.gtfs.model.StopTime) Test(org.junit.Test)

Example 7 with TransitGraphImpl

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

the class AgencyEntriesFactoryTest method testProcessAgencies.

@Test
public void testProcessAgencies() {
    GtfsRelationalDao gtfsDao = Mockito.mock(GtfsRelationalDao.class);
    Agency agencyA = new Agency();
    agencyA.setId("A");
    Agency agencyB = new Agency();
    agencyB.setId("B");
    Mockito.when(gtfsDao.getAllAgencies()).thenReturn(Arrays.asList(agencyA, agencyB));
    TransitGraphImpl graph = new TransitGraphImpl();
    AgencyEntriesFactory factory = new AgencyEntriesFactory();
    factory.setGtfsDao(gtfsDao);
    factory.setUniqueService(new UniqueServiceImpl());
    factory.processAgencies(graph);
    AgencyEntry agencyEntryA = graph.getAgencyForId("A");
    assertEquals("A", agencyEntryA.getId());
    AgencyEntry agencyEntryB = graph.getAgencyForId("B");
    assertEquals("B", agencyEntryB.getId());
    List<AgencyEntry> agencies = graph.getAllAgencies();
    assertEquals(2, agencies.size());
    assertTrue(agencies.contains(agencyEntryA));
    assertTrue(agencies.contains(agencyEntryB));
}
Also used : UniqueServiceImpl(org.onebusaway.transit_data_federation.bundle.tasks.UniqueServiceImpl) GtfsRelationalDao(org.onebusaway.gtfs.services.GtfsRelationalDao) Agency(org.onebusaway.gtfs.model.Agency) TransitGraphImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TransitGraphImpl) AgencyEntry(org.onebusaway.transit_data_federation.services.transit_graph.AgencyEntry) Test(org.junit.Test)

Example 8 with TransitGraphImpl

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

the class BlockEntriesFactoryTest method before.

@Before
public void before() {
    _factory = new BlockEntriesFactory();
    _blockConfigFactory = Mockito.mock(BlockConfigurationEntriesFactory.class);
    _factory.setBlockConfigurationEntriesFactory(_blockConfigFactory);
    _dao = Mockito.mock(GtfsRelationalDao.class);
    _factory.setGtfsDao(_dao);
    _graph = new TransitGraphImpl();
    _route = new Route();
    _route.setId(aid("route"));
    _routeEntry = UnitTestingSupport.route("route");
    Mockito.when(_dao.getAllRoutes()).thenReturn(Arrays.asList(_route));
}
Also used : GtfsRelationalDao(org.onebusaway.gtfs.services.GtfsRelationalDao) TransitGraphImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TransitGraphImpl) Route(org.onebusaway.gtfs.model.Route) Before(org.junit.Before)

Example 9 with TransitGraphImpl

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

the class RouteEntriesFactoryTest method testProcessRoutes.

@Test
public void testProcessRoutes() {
    GtfsRelationalDao gtfsDao = Mockito.mock(GtfsRelationalDao.class);
    Agency agency = new Agency();
    agency.setId("A");
    Route routeA = new Route();
    routeA.setAgency(agency);
    routeA.setId(new AgencyAndId("A", "routeA"));
    Route routeB = new Route();
    routeB.setAgency(agency);
    routeB.setId(new AgencyAndId("A", "routeB"));
    Mockito.when(gtfsDao.getAllRoutes()).thenReturn(Arrays.asList(routeA, routeB));
    TransitGraphImpl graph = new TransitGraphImpl();
    RouteEntriesFactory factory = new RouteEntriesFactory();
    factory.setGtfsDao(gtfsDao);
    factory.setUniqueService(new UniqueServiceImpl());
    factory.processRoutes(graph);
    RouteEntryImpl routeEntryA = graph.getRouteForId(routeA.getId());
    RouteEntryImpl routeEntryB = graph.getRouteForId(routeB.getId());
    List<RouteEntry> routes = graph.getAllRoutes();
    assertEquals(2, routes.size());
    assertTrue(routes.contains(routeEntryA));
    assertTrue(routes.contains(routeEntryB));
}
Also used : UniqueServiceImpl(org.onebusaway.transit_data_federation.bundle.tasks.UniqueServiceImpl) GtfsRelationalDao(org.onebusaway.gtfs.services.GtfsRelationalDao) RouteEntry(org.onebusaway.transit_data_federation.services.transit_graph.RouteEntry) Agency(org.onebusaway.gtfs.model.Agency) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) TransitGraphImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TransitGraphImpl) RouteEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.RouteEntryImpl) Route(org.onebusaway.gtfs.model.Route) Test(org.junit.Test)

Example 10 with TransitGraphImpl

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

the class StopEntriesFactoryTest method test.

@Test
public void test() {
    Stop stopA = new Stop();
    stopA.setId(new AgencyAndId("1", "stopA"));
    stopA.setCode("A");
    stopA.setDesc("Stop A Description");
    stopA.setLat(47.0);
    stopA.setLon(-122.0);
    stopA.setLocationType(0);
    stopA.setName("Stop A");
    Stop stopB = new Stop();
    stopB.setId(new AgencyAndId("1", "stopB"));
    stopB.setCode("B");
    stopB.setDesc("Stop B Description");
    stopB.setLat(47.1);
    stopB.setLon(-122.1);
    stopB.setLocationType(0);
    stopB.setName("Stop B");
    GtfsRelationalDao dao = Mockito.mock(GtfsRelationalDao.class);
    Mockito.when(dao.getAllStops()).thenReturn(Arrays.asList(stopA, stopB));
    StopEntriesFactory factory = new StopEntriesFactory();
    factory.setGtfsDao(dao);
    TransitGraphImpl graph = new TransitGraphImpl();
    AgencyEntryImpl agency = new AgencyEntryImpl();
    agency.setId("1");
    graph.putAgencyEntry(agency);
    graph.refreshAgencyMapping();
    factory.processStops(graph);
    StopEntryImpl stopEntryA = graph.getStopEntryForId(stopA.getId());
    assertEquals(stopA.getId(), stopEntryA.getId());
    assertEquals(stopA.getLat(), stopEntryA.getStopLat(), 0);
    assertEquals(stopA.getLon(), stopEntryA.getStopLon(), 0);
    StopEntryImpl stopEntryB = graph.getStopEntryForId(stopB.getId());
    assertEquals(stopB.getId(), stopEntryB.getId());
    assertEquals(stopB.getLat(), stopEntryB.getStopLat(), 0);
    assertEquals(stopB.getLon(), stopEntryB.getStopLon(), 0);
    List<StopEntry> stops = graph.getAllStops();
    assertEquals(2, stops.size());
    assertTrue(stops.contains(stopEntryA));
    assertTrue(stops.contains(stopEntryB));
    stops = agency.getStops();
    assertTrue(stops.contains(stopEntryA));
    assertTrue(stops.contains(stopEntryB));
}
Also used : GtfsRelationalDao(org.onebusaway.gtfs.services.GtfsRelationalDao) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Stop(org.onebusaway.gtfs.model.Stop) AgencyEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.AgencyEntryImpl) TransitGraphImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TransitGraphImpl) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) StopEntriesFactory(org.onebusaway.transit_data_federation.bundle.tasks.transit_graph.StopEntriesFactory) StopEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl) Test(org.junit.Test)

Aggregations

TransitGraphImpl (org.onebusaway.transit_data_federation.impl.transit_graph.TransitGraphImpl)13 Test (org.junit.Test)10 GtfsRelationalDao (org.onebusaway.gtfs.services.GtfsRelationalDao)8 Route (org.onebusaway.gtfs.model.Route)7 Agency (org.onebusaway.gtfs.model.Agency)6 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)5 Stop (org.onebusaway.gtfs.model.Stop)5 UniqueServiceImpl (org.onebusaway.transit_data_federation.bundle.tasks.UniqueServiceImpl)5 StopTime (org.onebusaway.gtfs.model.StopTime)4 Trip (org.onebusaway.gtfs.model.Trip)4 RouteEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.RouteEntryImpl)4 TripEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl)4 ShapePoints (org.onebusaway.transit_data_federation.model.ShapePoints)4 ShapePointsFactory (org.onebusaway.transit_data_federation.model.ShapePointsFactory)4 DistanceAlongShapeLibrary (org.onebusaway.transit_data_federation.bundle.tasks.transit_graph.DistanceAlongShapeLibrary)3 StopTimeEntriesFactory (org.onebusaway.transit_data_federation.bundle.tasks.transit_graph.StopTimeEntriesFactory)3 AgencyEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.AgencyEntryImpl)3 StopTimeEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.StopTimeEntryImpl)3 RouteEntry (org.onebusaway.transit_data_federation.services.transit_graph.RouteEntry)3 Before (org.junit.Before)2