Search in sources :

Example 1 with StopEntriesFactory

use of org.onebusaway.transit_data_federation.bundle.tasks.transit_graph.StopEntriesFactory 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

Test (org.junit.Test)1 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)1 Stop (org.onebusaway.gtfs.model.Stop)1 GtfsRelationalDao (org.onebusaway.gtfs.services.GtfsRelationalDao)1 StopEntriesFactory (org.onebusaway.transit_data_federation.bundle.tasks.transit_graph.StopEntriesFactory)1 AgencyEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.AgencyEntryImpl)1 StopEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl)1 TransitGraphImpl (org.onebusaway.transit_data_federation.impl.transit_graph.TransitGraphImpl)1 StopEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopEntry)1